Files
skills/tests/e2e/cdp.mjs
T
Kevin Veen-BirkenbachandClaude Opus 5.5 2722cda1b5 feat(hub): requirements 023 to 031 and line comments on grant-time code
023 box heads: one head band per box under its top border; in widget mode
its controls join the widget title band.
024 Match card content: merge cards show their diff (the runner previews a
review's tree against its worktree HEAD), every card carries legal and
architecture scores, the null under command cards is gone.
025 Radio speak card: no hint text, a rounder flowing card, a MAYDAY toggle
beside push to talk.
026 widget zoom: zoom a widget's content by keyboard and the context menu.
027 slash skill suggestions: every field that messages agents suggests
skills after a slash, from a skills index the tree timer writes.
028 Resources accounts: an Accounts panel (provider, renewal, resets, usage
and remaining, host-local, emails never in git) and panel checkboxes.
029 Controls layout: Rules and Groups pages laid out.
030 Yes/No answers as buttons, and nothing hides: rows the runner cannot
run stay greyed with the reason.
031 mic in fields.
Line comments (operator 2026-11-24): wherever code waits for a grant
(Waits on Operator, the stream, the review overlay) selected lines or a
right-clicked row take a comment that marks its lines and collects on the
card; Deny opens with them as the reason and Call preselected, Grant sends
them after the signed grant as one post. Requirement 003 decision 4 and
its contract follow.

Tests are written for every requirement and run once on this head.

🎯 Fix: 80 %
💥 Break: 20 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: ~95 %
🏆 Score: 61
🚦 Gate: ⛔ fix 80 % < 90, break 20 % > 5; security ~95 % < 100: ask the operator before the commit

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 01:22:03 +00:00

122 lines
6.2 KiB
JavaScript

import {spawn} from "node:child_process";
import {mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs";
import {tmpdir} from "node:os";
import {join} from "node:path";
// Args: <chromium binary> <plan.json>; the plan lists steps {width, height, url, wait, keys, drag, probe, shot, media, gesture},
// keys being real key presses (Enter, Tab, ArrowLeft, ArrowRight) on the focused element before the probe, drag
// [[x, y], [x, y]] a real left mouse drag between two viewport points after the keys, and gesture running the probe with a
// user activation like a click, an optional init, the text of a function every new document runs before its own scripts,
// and an optional authenticator {credentialId, privateKey, rpId}: base64 id and PKCS#8 key of a passkey the page may sign with.
// Prints {results, errors}: one probe value per step and every uncaught page exception.
const [binary, planFile] = process.argv.slice(2);
const plan = JSON.parse(readFileSync(planFile, "utf8"));
const profile = mkdtempSync(join(tmpdir(), "cdp-"));
// --no-sandbox: the agent sandbox already forbids the user namespaces Chromium's own sandbox needs.
// --enable-unsafe-swiftshader: without a GPU, headless Chromium gives WebGL only through SwiftShader, which it no longer enables by itself.
// --ignore-certificate-errors: the https station fixtures use a throwaway self-signed certificate.
const flags = ["--headless", "--no-sandbox", "--disable-gpu", "--use-angle=swiftshader", "--enable-unsafe-swiftshader", "--ignore-certificate-errors", "--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream", "--no-first-run", "--no-default-browser-check", "--hide-scrollbars", `--user-data-dir=${profile}`, "--remote-debugging-port=0", "about:blank"];
const browser = spawn(binary, flags, {stdio: ["ignore", "ignore", "pipe"]});
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const KEYS = {Enter: [13, "\r"], Tab: [9, ""], ArrowLeft: [37, ""], ArrowRight: [39, ""]};
const address = await new Promise((resolve, reject) => {
let text = "";
const timer = setTimeout(() => reject(new Error(`no DevTools address: ${text.slice(-500)}`)), 30000);
browser.stderr.on("data", (chunk) => {
text += chunk;
const found = /DevTools listening on (ws:\/\/\S+)/.exec(text);
if (found) {
clearTimeout(timer);
resolve(found[1]);
}
});
browser.on("exit", (code) => reject(new Error(`browser exited with ${code}: ${text.slice(-500)}`)));
});
const socket = new WebSocket(address);
await new Promise((resolve, reject) => {
socket.onopen = resolve;
socket.onerror = reject;
});
const waiting = new Map();
const errors = [];
let next = 0;
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.method === "Runtime.exceptionThrown") {
const details = data.params.exceptionDetails;
errors.push(details.exception ? details.exception.description : details.text);
}
if (data.id && waiting.has(data.id)) {
const {resolve, reject} = waiting.get(data.id);
waiting.delete(data.id);
if (data.error) {
reject(new Error(JSON.stringify(data.error)));
} else {
resolve(data.result);
}
}
};
function send(method, params, sessionId) {
next += 1;
const id = next;
socket.send(JSON.stringify({id, method, params, ...(sessionId ? {sessionId} : {})}));
return new Promise((resolve, reject) => waiting.set(id, {resolve, reject}));
}
const results = [];
try {
const {targetId} = await send("Target.createTarget", {url: "about:blank"});
const {sessionId} = await send("Target.attachToTarget", {targetId, flatten: true});
const page = (method, params) => send(method, params, sessionId);
await page("Runtime.enable", {});
if (plan.init) {
await page("Page.enable", {});
await page("Page.addScriptToEvaluateOnNewDocument", {source: `(${plan.init})();`});
}
if (plan.authenticator) {
await page("WebAuthn.enable", {enableUI: false});
const {authenticatorId} = await page("WebAuthn.addVirtualAuthenticator", {options: {protocol: "ctap2", transport: "internal", hasResidentKey: true, hasUserVerification: true, isUserVerified: true, automaticPresenceSimulation: true}});
await page("WebAuthn.addCredential", {authenticatorId, credential: {signCount: 0, ...plan.authenticator, isResidentCredential: false}});
}
for (const step of plan.steps) {
await page("Emulation.setDeviceMetricsOverride", {width: step.width, height: step.height, deviceScaleFactor: 1, mobile: false});
await page("Emulation.setEmulatedMedia", {features: step.media || []});
if (step.url) {
await page("Page.navigate", {url: step.url});
}
await sleep(step.wait);
for (const key of step.keys || []) {
const [code, text] = KEYS[key];
await page("Input.dispatchKeyEvent", {type: "keyDown", key, code: key, windowsVirtualKeyCode: code, text});
await page("Input.dispatchKeyEvent", {type: "keyUp", key, code: key, windowsVirtualKeyCode: code});
await sleep(250);
}
if (step.drag) {
const [[x0, y0], [x1, y1]] = step.drag;
await page("Input.dispatchMouseEvent", {type: "mouseMoved", x: x0, y: y0});
await page("Input.dispatchMouseEvent", {type: "mousePressed", x: x0, y: y0, button: "left", buttons: 1, clickCount: 1});
await page("Input.dispatchMouseEvent", {type: "mouseMoved", x: x1, y: y1, button: "left", buttons: 1});
await page("Input.dispatchMouseEvent", {type: "mouseReleased", x: x1, y: y1, button: "left", buttons: 0, clickCount: 1});
await sleep(250);
}
let value = null;
if (step.probe) {
const {result, exceptionDetails} = await page("Runtime.evaluate", {expression: step.probe, awaitPromise: true, returnByValue: true, userGesture: Boolean(step.gesture)});
value = exceptionDetails ? {error: exceptionDetails.exception ? exceptionDetails.exception.description : exceptionDetails.text} : result.value;
}
if (step.shot) {
const {data} = await page("Page.captureScreenshot", {format: "png"});
writeFileSync(step.shot, Buffer.from(data, "base64"));
}
results.push(value);
}
} finally {
socket.close();
browser.kill();
rmSync(profile, {recursive: true, force: true, maxRetries: 10, retryDelay: 200});
}
console.log(JSON.stringify({results, errors}));