Merge branch 'main' into web-search

# Conflicts:
#	web/src/app.js
#	web/src/protocol.js
#	web/src/repository.js
#	web/styles.css
#	web/test/repository.test.mjs
#	web/test/ui-smoke.mjs
This commit is contained in:
2026-10-19 04:44:54 +01:00
9 changed files with 1536 additions and 9 deletions
+260
View File
@@ -0,0 +1,260 @@
// Pure unit tests for the run-level action helpers (R11–R14): the pending human
// decision extracted from a waiting step (with the pinned-graph fallback), the
// option/target wording, the cancel/retry eligibility, the deliberate-confirm
// draft rule and the verbatim Android copy. No server, no DOM.
import { test } from "node:test";
import assert from "node:assert/strict";
import {
ACTION_FAILED_OK,
ACTION_FAILED_TITLE,
CANCEL_CONFIRM,
CANCEL_DIALOG_MESSAGE,
DECISION_ACTION,
DECISION_CANCEL,
DECISION_CARD_TITLE,
DECISION_CONFIRM,
DECISION_SENDING,
DISMISS_KEEP,
DecisionDraft,
FEEDBACK_LABEL,
RESTART_CONFIRM,
RESTART_DIALOG_MESSAGE,
RETRY_CONFIRM,
RETRY_DIALOG_MESSAGE,
canCancel,
canRetry,
cancelDialogTitle,
decisionCardMeta,
decisionSheetMeta,
decisionSheetTitle,
decisionTargetLabel,
humanOptions,
lastWaitingStep,
optionTargetText,
pendingDecision,
retryDialogTitle,
retryModes,
retryRequestKey,
restartDialogTitle,
waitingOptions,
waitingPrompt,
} from "../src/actions.js";
/** A run with the fields pendingDecision reads; overridable per test. */
function run(overrides = {}) {
return {
id: 42,
title: "",
name: "Pipe",
status: "waiting",
current_stage: "review",
executing: false,
steps: [],
...overrides,
};
}
test("lastWaitingStep finds the last waiting step, null when none is waiting", () => {
const steps = [
{ stage: "plan", status: "completed" },
{ stage: "review", status: "waiting" },
{ stage: "review", status: "waiting" },
];
assert.equal(lastWaitingStep(steps)?.stage, "review");
assert.equal(lastWaitingStep(steps), steps[2]);
assert.equal(lastWaitingStep([{ stage: "plan", status: "completed" }]), null);
assert.equal(lastWaitingStep([]), null);
assert.equal(lastWaitingStep(undefined), null);
});
test("waitingPrompt returns the recorded instructions, else empty", () => {
assert.equal(waitingPrompt({ prompt: "Choose a path." }), "Choose a path.");
assert.equal(waitingPrompt({ prompt: 7 }), "");
assert.equal(waitingPrompt({}), "");
assert.equal(waitingPrompt(null), "");
});
test("waitingOptions keeps string entries in recorded order, dropping malformed and blank", () => {
assert.deepEqual(waitingOptions({ options: ["approve", "reject"] }), ["approve", "reject"]);
assert.deepEqual(waitingOptions({ options: ["a", 3, null, " ", "b"] }), ["a", "b"]);
assert.deepEqual(waitingOptions({ options: "approve" }), []);
assert.deepEqual(waitingOptions({}), []);
});
test("humanOptions are a stage's non-error edges, sorted", () => {
assert.deepEqual(humanOptions({ publish: "#success", error: "#failure", revise: "review" }), [
"publish",
"revise",
]);
assert.deepEqual(humanOptions({}), []);
assert.deepEqual(humanOptions(undefined), []);
});
test("decisionTargetLabel resolves declared edges and is blank otherwise", () => {
assert.equal(decisionTargetLabel("publish", "publish"), "publish");
assert.equal(decisionTargetLabel("publish", "#"), "SUCCESS");
assert.equal(decisionTargetLabel("error", "#"), "FAILURE");
assert.equal(decisionTargetLabel("approve", ""), "");
assert.equal(decisionTargetLabel("approve", null), "");
assert.equal(decisionTargetLabel("approve", undefined), "");
assert.equal(optionTargetText("publish"), "→ publish");
assert.equal(optionTargetText(""), "");
assert.equal(optionTargetText(null), "");
});
test("pendingDecision returns null unless the run is waiting", () => {
assert.equal(pendingDecision(null), null);
assert.equal(pendingDecision(run({ status: "failed" })), null);
assert.equal(pendingDecision(run({ status: "running", executing: true })), null);
assert.equal(pendingDecision(run({ status: "succeeded" })), null);
});
test("pendingDecision yields the recorded options in author order and the verbatim prompt", () => {
const decision = pendingDecision(
run({
title: "Review the plan",
current_stage: "review",
steps: [
{ stage: "plan", status: "completed" },
{
stage: "review",
status: "waiting",
output: { prompt: "Ship it or revise it?", options: ["revise", "approve"] },
},
],
graph: {
stages: [
{
key: "review",
prompt: "graph prompt",
edges: { approve: "publish", revise: "review", error: "#failure" },
},
],
},
}),
);
assert.deepEqual(decision.options.map((o) => o.key), ["revise", "approve"]);
assert.equal(decision.instructions, "Ship it or revise it?");
assert.equal(decision.stageKey, "review");
assert.equal(decision.runId, 42);
assert.equal(decision.runLabel, "Review the plan");
assert.deepEqual(decision.options, [
{ key: "revise", target: "review" },
{ key: "approve", target: "publish" },
]);
});
test("pendingDecision falls back to the pinned graph's sorted non-error edges", () => {
const decision = pendingDecision(
run({
current_stage: "review",
steps: [{ stage: "", status: "waiting", output: {} }],
graph: {
stages: [
{ key: "review", prompt: "Graph instructions.", edges: { publish: "#success", error: "#failure", revise: "review" } },
],
},
}),
);
assert.deepEqual(decision.options.map((o) => o.key), ["publish", "revise"]);
assert.equal(decision.instructions, "Graph instructions.");
assert.equal(decision.stageKey, "review");
});
test("pendingDecision keeps a recorded option whose edge is not declared, with a blank target", () => {
const decision = pendingDecision(
run({
steps: [{ stage: "review", status: "waiting", output: { options: ["approve", "legacy"] } }],
graph: { stages: [{ key: "review", edges: { approve: "publish" } }] },
}),
);
assert.deepEqual(decision.options, [
{ key: "approve", target: "publish" },
{ key: "legacy", target: "" },
]);
});
test("pendingDecision is null when no option can be derived", () => {
assert.equal(
pendingDecision(run({ steps: [{ stage: "review", status: "waiting", output: {} }], graph: { stages: [] } })),
null,
);
});
test("DecisionDraft: a blank selection cannot submit and selecting never sends", () => {
const blank = new DecisionDraft();
assert.equal(blank.canSubmit, false);
const selected = blank.select("approve");
assert.equal(selected.canSubmit, true);
assert.equal(selected.selected, "approve");
// Selecting is pure: the original draft is untouched and no side effect fires.
assert.equal(blank.selected, null);
assert.equal(blank.canSubmit, false);
// Feedback is carried verbatim and never changes the submit rule.
const withFeedback = selected.withFeedback(" looks good ");
assert.equal(withFeedback.feedback, " looks good ");
assert.equal(withFeedback.canSubmit, true);
assert.equal(new DecisionDraft(" ").canSubmit, false);
});
test("canCancel is true only while executing; canRetry only for a failed, idle run", () => {
assert.equal(canCancel(run({ executing: true })), true);
assert.equal(canCancel(run({ executing: false })), false);
assert.equal(canCancel(null), false);
assert.equal(canRetry(run({ status: "failed", executing: false })), true);
assert.equal(canRetry(run({ status: "failed", executing: true })), false);
assert.equal(canRetry(run({ status: "succeeded", executing: false })), false);
assert.equal(canRetry(run({ status: "waiting", executing: false })), false);
assert.equal(canRetry(null), false);
assert.equal(canRetry(undefined), false);
});
test("retryModes offers resume and restart for a retryable run, nothing otherwise", () => {
assert.deepEqual(retryModes(run({ status: "failed" })), ["resume", "restart"]);
assert.deepEqual(retryModes(run({ status: "succeeded" })), []);
assert.deepEqual(retryModes(run({ status: "failed", executing: true })), []);
});
test("retryRequestKey is unique, prefixed and within the server's 128-character bound", () => {
const key = retryRequestKey(440, 1_700_000_000_000, () => 0.5);
assert.match(key, /^web-retry-440-1700000000000-/);
assert.ok(key.length <= 128, `key too long: ${key.length}`);
assert.notEqual(
retryRequestKey(440, 1, () => 0.1),
retryRequestKey(440, 1, () => 0.2),
);
});
test("the decision/action copy matches the Android sources verbatim", () => {
assert.equal(DECISION_CARD_TITLE, "Waiting for your decision");
assert.equal(DECISION_ACTION, "Decide");
assert.equal(FEEDBACK_LABEL, "Feedback (optional)");
assert.equal(DECISION_CANCEL, "Cancel");
assert.equal(DECISION_CONFIRM, "Confirm decision");
assert.equal(DECISION_SENDING, "Sending…");
assert.equal(cancelDialogTitle(440), "Cancel run 440?");
assert.equal(CANCEL_DIALOG_MESSAGE, "This asks the server to stop the active run.");
assert.equal(CANCEL_CONFIRM, "Cancel run");
assert.equal(retryDialogTitle(440), "Retry run 440?");
assert.equal(
RETRY_DIALOG_MESSAGE,
"Only failed runs can be retried. The server starts a new run from the same input.",
);
assert.equal(RETRY_CONFIRM, "Retry");
assert.equal(DISMISS_KEEP, "Keep");
assert.equal(RESTART_CONFIRM, "Restart from start");
assert.ok(RESTART_DIALOG_MESSAGE.includes("replays the whole pipeline"));
assert.ok(RESTART_DIALOG_MESSAGE.includes("instead of resuming the failed stage"));
assert.equal(restartDialogTitle(440), "Restart run 440?");
assert.equal(ACTION_FAILED_TITLE, "Action failed");
assert.equal(ACTION_FAILED_OK, "OK");
});
test("the decision card and sheet meta/title render the app's exact shapes", () => {
const decision = { runId: 12, runLabel: "Ship it", stageKey: "review" };
assert.equal(decisionCardMeta(decision), "review · run 12 · Ship it");
assert.equal(decisionSheetTitle(decision.stageKey), "Decide review");
assert.equal(decisionSheetMeta(decision), "run 12 · Ship it");
});
+87
View File
@@ -144,3 +144,90 @@ test("search surfaces an explicit server error with the server's own text", asyn
message: "unknown command: search",
});
});
/** The run detail a run.action reply carries in these tests. */
const RUN_DETAIL = { id: 440, status: "failed" };
test("decideRun sends exactly {type:'decide_run',run_id,option,feedback} and returns the run detail", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run", run_detail: RUN_DETAIL });
const detail = await repo.decideRun(440, { stage: "review", option: "approve", feedback: " yes " });
assert.deepEqual(lastFrame(ws), {
type: "decide_run",
run_id: 440,
stage: "review",
option: "approve",
feedback: "yes",
});
assert.deepEqual(detail, RUN_DETAIL);
});
test("decideRun omits a blank stage and blank feedback", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run", run_detail: RUN_DETAIL });
await repo.decideRun(12, { stage: " ", option: "publish", feedback: " " });
assert.deepEqual(lastFrame(ws), { type: "decide_run", run_id: 12, option: "publish" });
});
test("cancelRun sends exactly {type:'cancel_run',run_id} and returns the run detail", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run", run_detail: RUN_DETAIL });
const detail = await repo.cancelRun(440);
assert.deepEqual(lastFrame(ws), { type: "cancel_run", run_id: 440 });
assert.deepEqual(detail, RUN_DETAIL);
});
test("retryRun always sends request_key and omits retry_mode for the default resume", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run_started", run_detail: RUN_DETAIL });
await repo.retryRun(440, { requestKey: "key-1" });
assert.deepEqual(lastFrame(ws), { type: "retry_run", run_id: 440, request_key: "key-1" });
});
test("retryRun sends retry_mode only for an explicit restart", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run_started", run_detail: RUN_DETAIL });
await repo.retryRun(440, { mode: "restart", requestKey: "key-2" });
assert.deepEqual(lastFrame(ws), {
type: "retry_run",
run_id: 440,
request_key: "key-2",
retry_mode: "restart",
});
});
test("setRunTitle sends exactly {type:'set_run_title',run_id,title} and returns the run detail", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run", run_detail: RUN_DETAIL });
const detail = await repo.setRunTitle(440, "New title");
assert.deepEqual(lastFrame(ws), { type: "set_run_title", run_id: 440, title: "New title" });
assert.deepEqual(detail, RUN_DETAIL);
});
test("each run action rejects a server error envelope instead of returning a detail", async () => {
const calls = [
(repo) => () => repo.decideRun(440, { option: "approve" }),
(repo) => () => repo.cancelRun(440),
(repo) => () => repo.retryRun(440, { requestKey: "key-3" }),
(repo) => () => repo.setRunTitle(440, ""),
];
for (const makeCall of calls) {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "a title with usable text is required" });
await assert.rejects(makeCall(repo), {
name: "ProtocolError",
message: "a title with usable text is required",
});
}
});
test("a run action throws when the reply has no run detail", async () => {
const { repo, ws } = connected();
ws.reply = (frame) => ({ id: frame.id, type: "run" });
await assert.rejects(() => repo.cancelRun(7), ProtocolError);
});
+215
View File
@@ -90,6 +90,17 @@ async function openRunDetail(runId) {
await page.waitForSelector(row, { timeout: 20000 });
await page.click(row);
await page.waitForSelector(".detail .detail-tabs", { timeout: 20000 });
// The tabstrip already exists from the previously opened run, so it is not
// proof this run's detail loaded. Wait for this run's own identity line
// (`run {id} · …`) before returning, or the next assertion can read the
// previous run's actions.
await eventually(
() =>
page.evaluate(
`document.querySelector(".run-detail .run-identity")?.textContent?.startsWith("run ${runId} ") ?? false`,
),
{ timeout: 20000, what: `run ${runId}'s detail to load` },
);
return;
} catch (error) {
if (attempt === 1) throw error;
@@ -1709,6 +1720,210 @@ try {
});
console.log(" Close search cleared the query and kept the view; Escape also closed the field");
// R13/R14: the run-level actions on run 440 (failed, not executing). The
// Retry action is offered; Cancel is not. The Retry confirm and its secondary
// Restart-from-start confirm are captured and dismissed with Keep — no run is
// started here. The rename field is captured pre-filled, then a blank rename is
// actually sent: the live server refuses it without mutating anything, so the
// shared Action-failed dialog shows the server's own reason.
step("R13/R14: run 440 (failed) — Retry eligibility, restart confirm and the rename field");
// The search block above leaves the routed detail (a Pipelines detail) on
// screen; R13/R14 needs the Runs list rendered before it can open run 440.
await page.clickText("nav.tabs button.tab", "Runs");
await page.waitForSelector(".list.runs .run-row", { timeout: 25000 });
await openRunDetail(440);
const actions440 = await page.evaluate(`(() => ({
retry: !!document.querySelector(".run-detail .run-actions .retry-run"),
cancel: !!document.querySelector(".run-detail .run-actions .cancel-run"),
}))()`);
if (!actions440.retry) throw new Error("run 440 (failed, not executing) offered no Retry action");
if (actions440.cancel) throw new Error("run 440 (not executing) must not offer a Cancel action");
shots.push(await page.screenshot(`${out}/35-run-440-run-actions.png`));
step("R13: the Retry confirm — resume is the default, Restart from start is secondary");
await page.click(".run-detail .run-actions .retry-run");
await page.waitForSelector(".confirm-dialog.confirm-retry", { timeout: 15000 });
const retryDialog = await page.evaluate(`(() => ({
title: document.querySelector(".confirm-retry .confirm-title")?.textContent ?? "",
message: document.querySelector(".confirm-retry .confirm-message")?.textContent ?? "",
confirm: document.querySelector(".confirm-retry .confirm-accept")?.textContent ?? "",
dismiss: document.querySelector(".confirm-retry .confirm-dismiss")?.textContent ?? "",
secondary: document.querySelector(".confirm-retry .confirm-secondary")?.textContent ?? "",
}))()`);
if (retryDialog.title !== "Retry run 440?") throw new Error(`retry title: ${retryDialog.title}`);
if (retryDialog.message !== "Only failed runs can be retried. The server starts a new run from the same input.") {
throw new Error(`retry message: ${retryDialog.message}`);
}
if (retryDialog.confirm !== "Retry") throw new Error(`retry confirm: ${retryDialog.confirm}`);
if (retryDialog.dismiss !== "Keep") throw new Error(`retry dismiss: ${retryDialog.dismiss}`);
if (retryDialog.secondary !== "Restart from start") {
throw new Error(`retry secondary: ${retryDialog.secondary}`);
}
console.log(` retry dialog: "${retryDialog.title}" — ${retryDialog.message}`);
shots.push(await page.screenshot(`${out}/36-run-440-retry-confirm.png`));
step("R13: the Restart-from-start confirm states the whole-pipeline replay");
await page.click(".confirm-retry .confirm-secondary");
await page.waitForSelector(".confirm-dialog.confirm-restart", { timeout: 15000 });
const restartDialog = await page.evaluate(`(() => ({
title: document.querySelector(".confirm-restart .confirm-title")?.textContent ?? "",
message: document.querySelector(".confirm-restart .confirm-message")?.textContent ?? "",
confirm: document.querySelector(".confirm-restart .confirm-accept")?.textContent ?? "",
dismiss: document.querySelector(".confirm-restart .confirm-dismiss")?.textContent ?? "",
}))()`);
if (restartDialog.title !== "Restart run 440?") throw new Error(`restart title: ${restartDialog.title}`);
if (!restartDialog.message.includes("replays the whole pipeline")) {
throw new Error(`restart message does not state the whole-pipeline replay: ${restartDialog.message}`);
}
if (!restartDialog.message.includes("instead of resuming the failed stage")) {
throw new Error(`restart message does not contrast with resume: ${restartDialog.message}`);
}
if (restartDialog.confirm !== "Restart from start") {
throw new Error(`restart confirm: ${restartDialog.confirm}`);
}
if (restartDialog.dismiss !== "Keep") throw new Error(`restart dismiss: ${restartDialog.dismiss}`);
console.log(` restart dialog: "${restartDialog.title}" — ${restartDialog.message}`);
shots.push(await page.screenshot(`${out}/37-run-440-restart-confirm.png`));
step("R13: dismissing the dialog with Keep sends nothing");
await page.click(".confirm-restart .confirm-dismiss");
await eventually(() => page.evaluate(`!document.querySelector(".confirm-dialog")`), {
timeout: 5000,
what: "the confirm dialog to close",
});
step("R14: the rename field is pre-filled with the current title");
await page.click(".run-detail .rename-open");
await page.waitForSelector(".run-detail .rename-input", { timeout: 15000 });
const renameValue = await page.evaluate(
`document.querySelector(".run-detail .rename-input")?.value ?? ""`,
);
if (!renameValue) throw new Error("the rename field was not pre-filled with the current title");
console.log(` rename field pre-filled with: ${JSON.stringify(renameValue)}`);
shots.push(await page.screenshot(`${out}/38-run-440-rename-field.png`));
step("Action failed: a refused rename shows the server's exact reason");
await page.fill(".run-detail .rename-input", "");
await page.click(".run-detail .rename-save");
await page.waitForSelector(".action-failed", { timeout: 15000 });
const actionFailed = await page.evaluate(`(() => ({
title: document.querySelector(".action-failed .action-failed-title")?.textContent ?? "",
message: document.querySelector(".action-failed .action-failed-message")?.textContent ?? "",
ok: document.querySelector(".action-failed .action-failed-ok")?.textContent ?? "",
}))()`);
if (actionFailed.title !== "Action failed") throw new Error(`action-failed title: ${actionFailed.title}`);
if (actionFailed.ok !== "OK") throw new Error(`action-failed ok: ${actionFailed.ok}`);
if (actionFailed.message !== "a title with usable text is required") {
throw new Error(`action-failed message is not the server's own reason: ${actionFailed.message}`);
}
console.log(` action failed: "${actionFailed.title}" — ${actionFailed.message}`);
shots.push(await page.screenshot(`${out}/39-run-440-action-failed.png`));
await page.click(".action-failed .action-failed-ok");
await eventually(() => page.evaluate(`!document.querySelector(".action-failed")`), {
timeout: 5000,
what: "the Action-failed dialog to close",
});
// Leave the rename field without changing anything.
await page.click(".run-detail .rename-cancel");
// R12: the Cancel confirm on an executing run. Shown and dismissed with Keep —
// no cancel_run is sent (a real cancel is unsafe against a shared live run).
step("R12: the Cancel confirm on an executing run (shown, not executed)");
const cancelRunId = await page.evaluate(`(() => {
const row = [...document.querySelectorAll(".list.runs .run-row")].find((n) => n.querySelector(".chip-running"));
const meta = row?.querySelector(".run-row-meta[data-run-id]");
return meta ? Number(meta.getAttribute("data-run-id")) : null;
})()`);
if (cancelRunId == null) {
console.log(" -- no executing run available; skipped the Cancel confirm capture");
} else {
await openRunDetail(cancelRunId);
const cancelOffered = await page.evaluate(
`!!document.querySelector(".run-detail .run-actions .cancel-run")`,
);
if (!cancelOffered) {
console.log(` -- run ${cancelRunId} stopped before the Cancel action could be shown`);
} else {
await page.click(".run-detail .run-actions .cancel-run");
await page.waitForSelector(".confirm-dialog.confirm-cancel", { timeout: 15000 });
const cancelDialog = await page.evaluate(`(() => ({
title: document.querySelector(".confirm-cancel .confirm-title")?.textContent ?? "",
message: document.querySelector(".confirm-cancel .confirm-message")?.textContent ?? "",
confirm: document.querySelector(".confirm-cancel .confirm-accept")?.textContent ?? "",
dismiss: document.querySelector(".confirm-cancel .confirm-dismiss")?.textContent ?? "",
}))()`);
if (cancelDialog.title !== `Cancel run ${cancelRunId}?`) {
throw new Error(`cancel title: ${cancelDialog.title}`);
}
if (cancelDialog.message !== "This asks the server to stop the active run.") {
throw new Error(`cancel message: ${cancelDialog.message}`);
}
if (cancelDialog.confirm !== "Cancel run") throw new Error(`cancel confirm: ${cancelDialog.confirm}`);
if (cancelDialog.dismiss !== "Keep") throw new Error(`cancel dismiss: ${cancelDialog.dismiss}`);
console.log(` cancel dialog (run ${cancelRunId}, not executed): "${cancelDialog.title}" — ${cancelDialog.message}`);
shots.push(await page.screenshot(`${out}/40-run-${cancelRunId}-cancel-confirm.png`));
await page.click(".confirm-cancel .confirm-dismiss");
await eventually(() => page.evaluate(`!document.querySelector(".confirm-dialog")`), {
timeout: 5000,
what: "the Cancel dialog to close",
});
}
}
// R11: the decision card/sheet, only when the live server actually has a run
// waiting on a person with recorded options. There is normally none (a human
// stage blocks a run until a person answers), so this stays a best-effort
// capture rather than a failure; the model is unit-tested in actions.test.mjs.
step("R11: the human-decision card/sheet (only when a waiting run is present)");
const waitingRunId = await page.evaluate(`(() => {
const row = [...document.querySelectorAll(".list.runs .run-row")].find((n) => n.querySelector(".chip-waiting"));
const meta = row?.querySelector(".run-row-meta[data-run-id]");
return meta ? Number(meta.getAttribute("data-run-id")) : null;
})()`);
if (waitingRunId == null) {
console.log(" -- no waiting run available; skipped the decision card/sheet capture (R11 stays partial)");
} else {
await openRunDetail(waitingRunId);
await page.waitForSelector(".run-detail .decision-card", { timeout: 15000 });
const cardText = await page.evaluate(`(() => ({
title: document.querySelector(".decision-card .decision-card-title")?.textContent ?? "",
meta: document.querySelector(".decision-card .decision-card-meta")?.textContent ?? "",
action: document.querySelector(".decision-card .decision-open")?.textContent ?? "",
}))()`);
if (cardText.title !== "Waiting for your decision") throw new Error(`card title: ${cardText.title}`);
if (cardText.action !== "Decide") throw new Error(`card action: ${cardText.action}`);
console.log(` decision card (run ${waitingRunId}): ${cardText.title} — ${cardText.meta}`);
shots.push(await page.screenshot(`${out}/41-run-${waitingRunId}-decision-card.png`));
await page.click(".decision-card .decision-open");
await page.waitForSelector(".decision-sheet .decision-option", { timeout: 15000 });
const sheet = await page.evaluate(`(() => ({
title: document.querySelector(".decision-sheet-title")?.textContent ?? "",
meta: document.querySelector(".decision-sheet-meta")?.textContent ?? "",
label: document.querySelector(".decision-field-label")?.textContent ?? "",
options: [...document.querySelectorAll(".decision-sheet .decision-option-key")].map((n) => n.textContent),
confirmDisabled: document.querySelector(".decision-confirm")?.disabled ?? null,
}))()`);
if (sheet.label !== "Feedback (optional)") throw new Error(`sheet feedback label: ${sheet.label}`);
if (sheet.confirmDisabled !== true) {
throw new Error("Confirm decision must be disabled until an option is selected");
}
console.log(` decision sheet (run ${waitingRunId}): ${sheet.title} — ${sheet.meta}; options ${sheet.options.join(", ")}`);
shots.push(await page.screenshot(`${out}/42-run-${waitingRunId}-decision-sheet.png`));
// Selecting an option enables the confirm but sends nothing.
await page.click(".decision-sheet .decision-option");
await eventually(
() => page.evaluate(`document.querySelector(".decision-confirm")?.disabled === false`),
{ timeout: 5000, what: "the confirm to enable after selecting an option" },
);
shots.push(await page.screenshot(`${out}/43-run-${waitingRunId}-decision-selected.png`));
// Dismiss with Cancel: no decide_run is sent for a real waiting run here.
await page.click(".decision-sheet .decision-cancel");
await eventually(() => page.evaluate(`!document.querySelector(".decision-sheet")`), {
timeout: 5000,
what: "the decision sheet to close",
});
}
console.log("\nUI SMOKE PASS");
for (const shot of shots) console.log(` ${shot}`);
} catch (error) {