Files
skills/tests/test_hub_composer_ptt.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 d695bb2b58 feat(hub): grant split menu, radio redesign and answerable decision rows
The Grant bar becomes one split control: Select, or Grant N with a menu for Deny, Grant all green, the picked list, Clear and Direct mode; picked items turn pale green. The radio drops its filter flyout and gains three-state bells per row, a test per row including Speak, Auto or Morse on a second click, mute on the sender avatar and the agent profile, Cancel MAYDAY beside Send only while one is active, a Send menu with a test message and hold-to-record push-to-talk. Decision rows read as questions with their options; the signed answer is Decision <id> plus Answer: <answer>, and the card names its recipient.

Security: the passkey-signed answer carries no agent-written text, the inbox lists answerable rows only when their id fullmatches the TASK rule of the installed rasci.py (skill_scripts.task_pattern), and rasci.py, operator.py and hotfix.py check task slugs with fullmatch, so a trailing newline no longer passes.

Accepted MEDUSA findings after kvb-think-criticize: page-inbox.js:116 EXA006 (by design after the fix), page-inbox.js:125 EXA010, operator.py:173, 618 and 633 RP001, FT-TRIGGER-005 and RLHF-POISON-002, operator.py:639 MEX-SCAN-346, operator.py:968 MM-SCAN-058, operator.py:974 ACP-SCAN-028 (false positives).

🎯 Fix: 85 %
💥 Break: 10 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 77
🚦 Gate: ⛔ fix 85 % < 90, break 10 % > 5

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 19:28:37 +00:00

108 lines
4.0 KiB
Python

from __future__ import annotations
import json
import subprocess
import unittest
from hub_support import HUB
COMPOSER = HUB / "templates" / "page-composer.js"
PROBE = r"""
const fs = require("fs");
const vm = require("vm");
const code = fs.readFileSync(process.argv[1], "utf8");
const settle = async () => {
for (let round = 0; round < 20; round += 1) {
await new Promise((resolve) => setImmediate(resolve));
}
};
function rig() {
const timers = [];
const log = [];
const sandbox = {
TO_ONE: [], TO_ALL: [], state: {speech: {seconds: 30}}, Event: class {},
window: {setTimeout: (run) => timers.push(run) && timers.length, clearTimeout: (id) => {
timers[id - 1] = null;
}},
};
vm.runInNewContext(code, sandbox);
sandbox.startRecording = (parts) => log.push(`start ${parts.ptt || "click"}`);
sandbox.stopRecording = (parts) => log.push(`stop ${parts.ptt || "click"}`);
const handlers = {};
const record = {disabled: false, addEventListener: (kind, run) => {
(handlers[kind] = handlers[kind] || []).push(run);
}};
const parts = {record, recorder: null, ptt: "", hold: 0, swallow: false};
sandbox.holdToTalk(parts);
const fire = (kind, event) => (handlers[kind] || []).forEach((run) => run(event || {button: 0}));
const tick = () => timers.splice(0).forEach((run) => run && run());
return {sandbox, parts, fire, tick, log};
}
async function kept(ptt, heard) {
const {sandbox, parts} = rig();
let submits = 0;
Object.assign(sandbox, {
context: () => ({}), wavOf: async () => "wav", attachVoice: () => null, toast: () => null,
send: async () => ({ok: true, data: {id: "n1"}}), heardNote: async () => heard,
});
Object.assign(parts, {ptt, status: {textContent: ""}, text: {value: "", dispatchEvent: () => true, focus: () => null, form: {requestSubmit: () => {
submits += 1;
}}}});
await sandbox.keepRecording({size: 3}, parts);
await settle();
return {submits, ptt: parts.ptt, text: parts.text.value};
}
(async () => {
const quick = rig();
quick.fire("pointerdown");
quick.fire("pointerup");
quick.tick();
const tapped = {log: quick.log.splice(0), swallow: quick.parts.swallow};
const held = rig();
held.fire("pointerdown");
held.tick();
const holding = held.parts.ptt;
held.fire("pointerleave");
const released = {holding, log: held.log.splice(0), ptt: held.parts.ptt, swallow: held.parts.swallow};
const right = rig();
right.fire("pointerdown", {button: 2});
right.tick();
console.log(JSON.stringify({
tapped, released, right: right.log,
sent: await kept("released", {status: "done", text: "hello"}),
clicked: await kept("", {status: "done", text: "hello"}),
empty: await kept("released", {status: "done", text: ""}),
}));
})().catch((error) => {
console.error(error && error.stack || error);
process.exit(1);
});
"""
class TestHoldToTalk(unittest.TestCase):
@classmethod
def setUpClass(cls):
done = subprocess.run(["node", "-e", PROBE, str(COMPOSER)], capture_output=True, text=True, timeout=60, check=False)
if done.returncode != 0:
raise AssertionError(done.stderr[-4000:])
cls.data = json.loads(done.stdout)
def test_a_short_press_starts_nothing_and_leaves_the_click_to_toggle(self):
self.assertEqual(self.data["tapped"], {"log": [], "swallow": False})
def test_holding_records_and_releasing_stops_and_swallows_the_trailing_click(self):
self.assertEqual(self.data["released"], {"holding": "holding", "log": ["start holding", "stop released"], "ptt": "released", "swallow": True})
def test_only_the_primary_button_holds(self):
self.assertEqual(self.data["right"], [])
def test_a_held_recording_sends_its_transcript_and_a_clicked_one_waits_for_the_check(self):
self.assertEqual(self.data["sent"], {"submits": 1, "ptt": "", "text": "hello"})
self.assertEqual(self.data["clicked"], {"submits": 0, "ptt": "", "text": "hello"})
self.assertEqual(self.data["empty"]["submits"], 0)
if __name__ == "__main__":
unittest.main()