From 684bb26dd7483322e84ad9f0ecba7ea6e011d533 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 09:37:30 -0800 Subject: [PATCH] Lab devices: a refusal names the device it refused lab-B refused its audio input every 5 s with "Device is not allowlisted", which didn't say which device. The allowlist was right: the BDSP AutoStory panel (and a few others) selected console A's capture audio (...USB Video:1112100:3), and both cards are listed as "USB Digital Audio". The refusal now names the kind and ID, decoding hex capture IDs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Devices/LabDeviceAccessQt.cpp | 25 ++++++++++++++++++- .../Devices/LabDeviceAccessQt_Tests.cpp | 13 ++++++++-- devtools/lab/DEVICE_OWNERSHIP.md | 7 ++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt.cpp b/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt.cpp index 6a710003ae..d420befadf 100644 --- a/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt.cpp +++ b/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt.cpp @@ -44,6 +44,29 @@ bool permitted(const LabDevicePolicy& policy, const LabDeviceIdentity& device){ return false; } +// Capture IDs are allowlisted as hex; show the readable ID beside it so a +// refusal names the device the settings selected. +std::string readable_capture_id(const std::string& hex){ + const bool is_hex = hex.size() % 2 == 0 && std::ranges::all_of(hex, [](char c){ + return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); + }); + if (!is_hex){ + return hex; + } + const QByteArray bytes = QByteArray::fromHex(QByteArray(hex.data(), (qsizetype)hex.size())); + return bytes.toStdString() + " (allowlist ID " + hex + ")"; +} + +std::string describe(const LabDeviceIdentity& device){ + switch (device.kind){ + case LabDeviceKind::SERIAL: return "Serial device " + device.id; + case LabDeviceKind::VIDEO: return "Video input " + readable_capture_id(device.id); + case LabDeviceKind::AUDIO: return "Audio input " + readable_capture_id(device.id); + case LabDeviceKind::PROFILE: return "Profile " + device.id; + } + return device.id; +} + std::string normalize_serial_path(std::string_view path){ if (path.starts_with("/dev/tty.")){ return "/dev/cu." + std::string(path.substr(9)); @@ -119,7 +142,7 @@ std::unique_ptr acquire_lab_device( const LabDevicePolicy& policy, std::string_view directory, const LabDeviceIdentity& device ){ if (!permitted(policy, device)){ - throw std::runtime_error("Device is not allowlisted for profile " + policy.profile + ". Nothing was opened."); + throw std::runtime_error(describe(device) + " is not allowlisted for profile " + policy.profile + ". Nothing was opened."); } if (!QDir().mkpath(text(directory))){ throw std::runtime_error("Cannot create shared device lease directory. Nothing was opened."); diff --git a/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt_Tests.cpp b/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt_Tests.cpp index 7cdd125946..83f5613e96 100644 --- a/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt_Tests.cpp +++ b/SerialPrograms/Source/CommonFramework/Devices/LabDeviceAccessQt_Tests.cpp @@ -31,6 +31,7 @@ struct PolicyInput{ struct PolicyExpectation{ int opens = 0; + std::string_view refusal = {}; // The refusal message starts with this. }; struct PolicyCase{ @@ -75,9 +76,11 @@ std::string check_serial(const SerialCase& test){ const PolicyCase POLICY_CASES[] = { {.input = {.name = "matching serial", .json = R"({"schema":1,"profile":"lab-B","serial":["10c4:ea60:B"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "10c4:ea60:B"}}, .expectation = {.opens = 1}}, - {.input = {.name = "wrong console serial", .json = R"({"schema":1,"profile":"lab-B","serial":["10c4:ea60:B"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "10c4:ea60:A"}}, .expectation = {}}, + {.input = {.name = "wrong console serial", .json = R"({"schema":1,"profile":"lab-B","serial":["10c4:ea60:B"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "10c4:ea60:A"}}, .expectation = {.refusal = "Serial device 10c4:ea60:A is not allowlisted for profile lab-B."}}, {.input = {.name = "camera allowed", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":["766964656f42"],"audio":[]})", .requested = {LabDeviceKind::VIDEO, "766964656f42"}}, .expectation = {.opens = 1}}, {.input = {.name = "audio allowed", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":[],"audio":["617564696f42"]})", .requested = {LabDeviceKind::AUDIO, "617564696f42"}}, .expectation = {.opens = 1}}, + // lab-B, 2026-11-08: a panel selected console A's audio input, and the refusal didn't say which device it was. + {.input = {.name = "wrong console audio", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":[],"audio":["617564696f42"]})", .requested = {LabDeviceKind::AUDIO, "617564696f41"}}, .expectation = {.refusal = "Audio input audioA (allowlist ID 617564696f41) is not allowlisted for profile lab-B."}}, {.input = {.name = "camera not audio", .json = R"({"schema":1,"profile":"lab-B","serial":[],"video":["same-id"],"audio":[]})", .requested = {LabDeviceKind::AUDIO, "same-id"}}, .expectation = {}}, {.input = {.name = "mismatched profile", .json = R"({"schema":1,"profile":"lab-A","serial":["port"],"video":[],"audio":[]})", .requested = {LabDeviceKind::SERIAL, "port"}}, .expectation = {}}, {.input = {.name = "missing policy", .json = "", .requested = {LabDeviceKind::SERIAL, "port"}}, .expectation = {}}, @@ -95,14 +98,20 @@ std::string check_policy(const PolicyCase& test){ return "Cannot create temporary lease directory."; } int opens = 0; + std::string refusal; try{ const auto policy = parse_lab_device_policy(test.input.json, "lab-B"); auto lease = acquire_lab_device(policy, directory.path().toStdString(), test.input.requested); opens++; // Scripted native open: no real port, camera or microphone exists. - }catch (const std::runtime_error&){} + }catch (const std::runtime_error& error){ + refusal = error.what(); + } if (opens != test.expectation.opens){ return "Expected opens " + std::to_string(test.expectation.opens) + "; read " + std::to_string(opens); } + if (!refusal.starts_with(test.expectation.refusal)){ + return "Expected a refusal starting \"" + std::string(test.expectation.refusal) + "\"; read \"" + refusal + "\""; + } return {}; } diff --git a/devtools/lab/DEVICE_OWNERSHIP.md b/devtools/lab/DEVICE_OWNERSHIP.md index a8f5afc19e..821a7e06fc 100644 --- a/devtools/lab/DEVICE_OWNERSHIP.md +++ b/devtools/lab/DEVICE_OWNERSHIP.md @@ -43,6 +43,13 @@ the corresponding original device ID; it does not use the hex string as a device selector. Do not use capture descriptions, friendly names or list positions. Audio output to speakers is outside this input-device policy. +A refusal names the kind and ID of the device the panel selected, e.g. +`Audio input AppleUSBAudioEngine:...:1112100:3 (allowlist ID 4170...) is not +allowlisted for profile lab-B`. That usually means the panel's settings pick the +other console's input, not that the allowlist is wrong: both capture cards are +listed as "USB Digital Audio", and only the ID tells them apart. Select the +other entry in that panel's audio dropdown. + This PR does not generate a policy from the currently selected panel: that could approve the very wrong-console binding we are preventing. Identity collection and confirming A/B assignments remain a deliberate setup step. Existing profiles,