mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Update the web console server, screens, help, prefs and loop setup, with matching page and logic suites
AI Assisted
This commit is contained in:
1 parent
2468027a5a
commit
8e34bf1005
119 files changed
+9957
-3728
No files matched your search
@@ -164,16 +164,17 @@ const COMPARE_SHOTS = {
|
||||
open: async (page) => {
|
||||
await page.click("#btn-looks");
|
||||
await page.waitForSelector("#looks-modal[open]", { timeout: 10000 });
|
||||
await page.waitForSelector('#prefs-tab-appearance[aria-selected="true"]', { timeout: 10000 });
|
||||
},
|
||||
},
|
||||
// Preferences scrolled to Cleanup once its scan has answered.
|
||||
// Preferences on the System tab, once the Cleanup scan has answered.
|
||||
cleanup: {
|
||||
workflow: "plan",
|
||||
posts: ["cleanup"],
|
||||
open: async (page) => {
|
||||
await page.click("#btn-looks");
|
||||
await page.waitForSelector("#looks-modal[open]", { timeout: 10000 });
|
||||
await page.locator(".looks-cleanup").scrollIntoViewIfNeeded();
|
||||
await page.click("#prefs-tab-system");
|
||||
await page.click("#cleanup-scan");
|
||||
await page.waitForFunction(() => document.getElementById("cleanup-status").textContent.trim() !== "", null, { timeout: 15000 }).catch(() => {});
|
||||
},
|
||||
|
||||
@@ -68,7 +68,15 @@ export async function openSession(browser, { t, workflow, payload: first, projec
|
||||
};
|
||||
s.wait = (seconds = 10) => {
|
||||
const r = cli(["wait", "--session", s.sid, "--seconds", String(seconds)], { cwd });
|
||||
return { code: r.status, ...(r.json || {}) };
|
||||
// The wire carries only what an agent reads (reply, hop fields); what the
|
||||
// person sent whole stays in result.json, which a page test reads from there.
|
||||
let sent = {};
|
||||
if (r.status === 0) {
|
||||
try {
|
||||
sent = JSON.parse(fs.readFileSync(path.join(s.session, "result.json"), "utf8"));
|
||||
} catch {}
|
||||
}
|
||||
return { code: r.status, ...sent, ...(r.json || {}) };
|
||||
};
|
||||
// Whether the session's server still answers on its port.
|
||||
s.answers = async () => {
|
||||
@@ -83,7 +91,7 @@ export async function openSession(browser, { t, workflow, payload: first, projec
|
||||
s.stop = async () => {
|
||||
if (stopped) return;
|
||||
stopped = true;
|
||||
cli(["stop", "--session", s.sid], { cwd });
|
||||
cli(["stop", "--session", s.sid, "--force"], { cwd });
|
||||
if (s.context) await s.context.close().catch(() => {});
|
||||
await until(async () => !(await s.answers()), 5000);
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ script refuses `--compare` with an `--out` inside `docs/screenshots/`.
|
||||
| `delete.json` | The dashboard, behind the first step of a spec chip's Delete |
|
||||
| `help.json` | A Plan question, behind Help on its first tab |
|
||||
| `prefs.json` | A Plan question, behind User Preferences |
|
||||
| `cleanup.json` | A Plan question, behind User Preferences scrolled to Cleanup after a scan |
|
||||
| `cleanup.json` | A Plan question, behind User Preferences on the System tab after a Cleanup scan |
|
||||
| `workspace.json` | A Plan question, behind the Workspace panel with a second folder added (shot last: the console remembers the folder) |
|
||||
|
||||
`node scripts/capture-screenshots.mjs --compare --out <folder outside the repo>`
|
||||
@@ -14,11 +14,13 @@ import { spawn } from "node:child_process";
|
||||
// is exactly why this lives in its own file.
|
||||
import { STALE_MS } from "../src/web-console/public/answers.js";
|
||||
import {
|
||||
ASK_BUSY_MS,
|
||||
CHAT_LAST_WAIT_TEXT,
|
||||
CHAT_LIMIT_TEXT,
|
||||
CHAT_OFFLINE_TEXT,
|
||||
CHAT_WAITING_TEXT,
|
||||
CHAT_WORKING_TEXT,
|
||||
chatAnswering,
|
||||
chatOffline,
|
||||
chatView,
|
||||
contextOptions,
|
||||
@@ -83,7 +85,7 @@ test("stress: 200 posts interleaved with 200 chat messages lose no message from
|
||||
assert.equal(all.length, 200);
|
||||
assert.equal(new Set(all.map((e) => e.seq)).size, 200, "no seq handed out twice");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -149,7 +151,7 @@ test("the frame reports how far the agent has picked up the chat", async () => {
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 0);
|
||||
assert.equal((await chatFrame(s)).pickedUp, body.seq);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -300,13 +302,36 @@ test("chatOffline: finished, paused, a stale working agent (with quietMinutes),
|
||||
assert.equal(chatOffline({ agent: { status: "waiting", quietMinutes: 30 }, ...ago(4 * 60 * 1000) }), true, "quietMinutes only counts while working");
|
||||
});
|
||||
|
||||
// A message the agent picked up and has not answered yet: the agent is busy
|
||||
// with it, not gone, even though it has stopped pinging from `wait`.
|
||||
test("chatAnswering: a picked-up message with no reply after it, and nothing else", () => {
|
||||
const person = (seq, kind = "message") => ({ from: "person", kind, seq, text: "q" + seq });
|
||||
const reply = (re) => ({ from: "agent", id: "r" + re, re, md: "a" });
|
||||
assert.equal(chatAnswering(null), false, "no chat at all");
|
||||
assert.equal(chatAnswering({ messages: [person(2)], pickedUp: 1 }), false, "sent, not picked up yet");
|
||||
assert.equal(chatAnswering({ messages: [person(2)], pickedUp: 2 }), true, "picked up, no reply");
|
||||
assert.equal(chatAnswering({ messages: [person(2), reply(2)], pickedUp: 2 }), false, "answered");
|
||||
assert.equal(chatAnswering({ messages: [person(2), reply(2), person(3, "decision")], pickedUp: 3 }), true, "an approved edit in hand");
|
||||
assert.equal(chatAnswering({ messages: [person(2), reply(2), person(3)], pickedUp: 2 }), false, "a follow-up not picked up yet");
|
||||
});
|
||||
|
||||
test("chatOffline: an Ask message in hand holds off offline for ASK_BUSY_MS, then gives up", () => {
|
||||
const now = 10 * 60 * 60 * 1000;
|
||||
const ago = (ms) => ({ agentLastSeenMs: now - ms, now });
|
||||
assert.equal(ASK_BUSY_MS, 10 * 60 * 1000);
|
||||
assert.equal(chatOffline({ agent: { status: "waiting" }, answering: true, ...ago(9 * 60 * 1000) }), false, "busy with the Ask message");
|
||||
assert.equal(chatOffline({ agent: { status: "waiting" }, answering: true, ...ago(ASK_BUSY_MS + 1000) }), true, "quiet past the allowance");
|
||||
assert.equal(chatOffline({ agent: { status: "working" }, answering: true, ...ago(STALE_MS + 1000) }), false, "a working agent answering is not stale yet");
|
||||
assert.equal(chatOffline({ agent: { status: "working", quietMinutes: 20 }, answering: true, ...ago(15 * 60 * 1000) }), false, "a longer quiet allowance still wins");
|
||||
});
|
||||
|
||||
// The agent learns the chat from the console's docs and the help text alone,
|
||||
// so every name it has to type (the command, the reply field, the edit fields)
|
||||
// and every refusal the routes can give must actually be written there.
|
||||
test("the console docs, building.md and help teach the Quick question contract", () => {
|
||||
const dir = path.join(ROOT, "src", "web-console");
|
||||
const consoleMd = consoleDocs();
|
||||
for (const word of ["chat --session", "chat.replies", "proposal", "changed", "too-long", "limit", "offline", "stale"]) {
|
||||
for (const word of ["chat --session", "\"replies\"", "proposal", "changed", "limit", "stale"]) {
|
||||
assert.ok(consoleMd.includes(word), `the console docs must mention ${word}`);
|
||||
}
|
||||
assert.ok(fs.readFileSync(path.join(dir, "building.md"), "utf8").includes("chat --session"), "building.md must mention chat --session");
|
||||
@@ -320,16 +345,14 @@ test("the console docs, building.md and help teach the Quick question contract",
|
||||
test("the console docs teach the workspace and session meter contract", () => {
|
||||
const consoleMd = consoleDocs();
|
||||
const buildingMd = consoleDoc("building.md") + consoleDoc("notes/implement.md");
|
||||
for (const word of ["workspace", "pendingWorkspace", "folderIssue", "run", "pathfinder-question", "pathfinder-research", "pathfinder-chart", "AGENTS.md", "/add-dir"]) {
|
||||
for (const word of ["workspace", "folderIssue", "run", "pathfinder-question", "pathfinder-research", "pathfinder-chart", "AGENTS.md", "/add-dir"]) {
|
||||
assert.ok(consoleMd.includes(word), `the console docs must mention ${word}`);
|
||||
}
|
||||
for (const word of ["implement-phase", "implement-review-phase"]) {
|
||||
assert.ok(buildingMd.includes(word), `the build docs must mention ${word}`);
|
||||
}
|
||||
const section = consoleDoc("console-meter.md").match(/### Session meter\n([\s\S]*?)\n---/);
|
||||
assert.ok(section, "console-meter.md has a Session meter section");
|
||||
const list = section[1].match(/`event` is one of ([\s\S]*?)An unknown event/);
|
||||
assert.ok(list, "the Session meter section lists the events");
|
||||
const list = consoleDoc("console-meter.md").match(/- `event`: ([\s\S]*?)An unknown event/);
|
||||
assert.ok(list, "console-meter.md lists the events");
|
||||
const listed = [...list[1].matchAll(/`([a-z-]+)`/g)].map((m) => m[1]);
|
||||
assert.equal(new Set(listed).size, listed.length, "no event is listed twice");
|
||||
assert.deepEqual([...listed].sort(), Object.keys(WEIGHTS).sort(), "console-meter.md lists exactly the WEIGHTS events");
|
||||
|
||||
@@ -32,37 +32,32 @@ import {
|
||||
|
||||
/* ------------------------------------------- quick question: the contract */
|
||||
|
||||
// Every outcome `wait` had before the chat channel existed, pinned by exit
|
||||
// code and by its exact top-level keys. The only change allowed later is the
|
||||
// chat keys appearing beside them; anything else breaks an agent somewhere.
|
||||
const CHAT_KEYS = new Set(["chat", "pendingChat"]);
|
||||
// The workspace channel, allowed beside them the same way.
|
||||
const WORKSPACE_KEYS = new Set(["workspace", "pendingWorkspace"]);
|
||||
// Every outcome of wait, pinned by exit code and by its exact top-level keys.
|
||||
// The agent reads a trimmed line (spec "API Design (outputs)"): what the
|
||||
// person sent lives in result.json, so those fields are checked there.
|
||||
const pinKeys = (obj, expected, what) =>
|
||||
assert.deepEqual(
|
||||
Object.keys(obj).filter((k) => !CHAT_KEYS.has(k) && !WORKSPACE_KEYS.has(k)).sort(),
|
||||
[...expected].sort(),
|
||||
`${what}: top-level keys changed`
|
||||
);
|
||||
const RESULT_KEYS = ["type", "at", "sid", "rev", "actions", "reply", "consumedAt", "terminalLine"];
|
||||
const WAITING_KEYS = ["status", "sid", "elapsed", "answered", "total", "staged", "url", "message", "next", "terminalLine"];
|
||||
|
||||
assert.deepEqual(Object.keys(obj).filter((k) => k !== "terminalLine").sort(), [...expected].sort(), what + ": top-level keys changed");
|
||||
const RESULT_FILE = (s) => JSON.parse(fs.readFileSync(path.join(s.session, "result.json"), "utf8"));
|
||||
|
||||
test("wait's existing outcomes are pinned: submit, images, waiting, cancel, carried and server gone", async () => {
|
||||
const s = openSession();
|
||||
try {
|
||||
const waiting = cli(["wait", "--session", s.sid, "--seconds", "5"]);
|
||||
assert.equal(waiting.status, 10);
|
||||
assert.equal(waiting.json.status, "waiting");
|
||||
pinKeys(waiting.json, WAITING_KEYS, "exit 10");
|
||||
assert.equal(waiting.json.waiting, true);
|
||||
assert.equal(waiting.json.open, 1, "the required question still open");
|
||||
pinKeys(waiting.json, ["waiting", "open"], "exit 10");
|
||||
|
||||
assert.equal((await s.send("/submit", { actions: [{ i: "q1", type: "answer", kind: "choice", k: "A" }], reply: "Export format: a" })).status, 200);
|
||||
const sent = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(sent.status, 0);
|
||||
assert.equal(sent.json.type, "submit");
|
||||
pinKeys(sent.json, RESULT_KEYS, "exit 0 submit");
|
||||
assert.equal(sent.json.reply, "Export format: a");
|
||||
pinKeys(sent.json, ["reply"], "exit 0 submit");
|
||||
const kept = RESULT_FILE(s);
|
||||
for (const k of ["type", "at", "sid", "rev", "actions", "reply", "consumedAt"]) assert.ok(k in kept, "result.json keeps " + k);
|
||||
assert.equal(kept.type, "submit");
|
||||
|
||||
const up = await fetch(`${s.base}/upload`, {
|
||||
const up = await fetch(s.base + "/upload", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "image/jpeg", cookie: s.cookie, origin: s.base, connection: "close", "x-p2c-name": "a.png" },
|
||||
body: JPEG,
|
||||
@@ -74,8 +69,8 @@ test("wait's existing outcomes are pinned: submit, images, waiting, cancel, carr
|
||||
);
|
||||
const withImages = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(withImages.status, 0);
|
||||
assert.equal(withImages.json.actions[0].images.length, 1);
|
||||
pinKeys(withImages.json, RESULT_KEYS, "exit 0 with images");
|
||||
pinKeys(withImages.json, ["reply"], "exit 0 with images");
|
||||
assert.equal(RESULT_FILE(s).actions[0].images.length, 1, "result.json holds the image");
|
||||
|
||||
// Sent before any wait is running: the next wait hands it over at once.
|
||||
assert.equal((await s.send("/submit", { actions: [{ i: "q1", type: "answer", kind: "choice", k: "B" }], reply: "Export format: b" })).status, 200);
|
||||
@@ -83,20 +78,21 @@ test("wait's existing outcomes are pinned: submit, images, waiting, cancel, carr
|
||||
const carried = cli(["wait", "--session", s.sid, "--seconds", "30"]);
|
||||
assert.equal(carried.status, 0);
|
||||
assert.ok(Date.now() - t0 < 5000, "an uncollected result is delivered at once");
|
||||
pinKeys(carried.json, RESULT_KEYS, "exit 0 carried");
|
||||
assert.equal(carried.json.reply, "Export format: b");
|
||||
pinKeys(carried.json, ["reply"], "exit 0 carried");
|
||||
|
||||
assert.equal((await s.send("/cancel", {})).status, 200);
|
||||
const cancelled = cli(["wait", "--session", s.sid, "--seconds", "5"]);
|
||||
assert.equal(cancelled.status, 30);
|
||||
assert.equal(cancelled.json.type, "cancel");
|
||||
pinKeys(cancelled.json, RESULT_KEYS, "exit 30");
|
||||
assert.equal(RESULT_FILE(s).type, "cancel");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
const gone = cli(["wait", "--session", s.sid, "--seconds", "12"]);
|
||||
assert.equal(gone.status, 20);
|
||||
assert.equal(gone.json.status, "server-gone");
|
||||
pinKeys(gone.json, ["status", "sid", "message"], "exit 20");
|
||||
assert.equal(gone.json.gone, true);
|
||||
assert.ok(gone.json.fix.includes(s.sid));
|
||||
pinKeys(gone.json, ["gone", "fix"], "exit 20");
|
||||
});
|
||||
|
||||
/* --------------------------------------------- quick question: the channel */
|
||||
@@ -109,28 +105,27 @@ test("a chat message and a card send can both be pending, in either order, and w
|
||||
assert.equal((await ask(s, "Where does the export live?")).status, 200, "a pending card never blocks a question");
|
||||
const both = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(both.status, 0);
|
||||
assert.equal(both.json.type, "submit");
|
||||
assert.equal(both.json.actions[0].k, "A");
|
||||
assert.ok(both.json.chat.some((e) => e.kind === "message" && e.text === "Where does the export live?"));
|
||||
assert.equal(both.json.chat.length, 1, "chat travels as the seq numbers a reply needs");
|
||||
assert.equal(typeof both.json.chat[0], "number");
|
||||
assert.match(both.json.reply, /^Export format: a\n/);
|
||||
assert.match(both.json.reply, /^Quick question: Where does the export live\?$/m);
|
||||
assert.match(both.json.reply, /^Quick question \(\d+\): Where does the export live\?$/m);
|
||||
|
||||
assert.equal((await ask(s, "And the header row?")).status, 200);
|
||||
assert.equal((await s.send("/submit", EXPORT_A)).status, 200, "a pending question never blocks a card");
|
||||
const again = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(again.status, 0);
|
||||
assert.equal(again.json.type, "submit");
|
||||
assert.deepEqual(again.json.chat.map((e) => e.text), ["And the header row?"]);
|
||||
assert.equal(again.json.chat.length, 1);
|
||||
assert.match(again.json.reply, /Quick question \(\d+\): And the header row\?/);
|
||||
|
||||
assert.equal((await ask(s, "Just a question")).status, 200);
|
||||
const chatOnly = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(chatOnly.status, 0);
|
||||
assert.equal(chatOnly.json.type, "chat");
|
||||
assert.deepEqual(chatOnly.json.actions, []);
|
||||
assert.equal(chatOnly.json.reply, "Quick question: Just a question");
|
||||
assert.ok(chatOnly.json.terminalLine);
|
||||
assert.equal(chatOnly.json.chat.length, 1);
|
||||
assert.equal(chatOnly.json.reply, "Quick question (" + chatOnly.json.chat[0] + "): Just a question");
|
||||
assert.equal(chatOnly.json.type, undefined);
|
||||
assert.equal(chatOnly.json.actions, undefined);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -156,9 +151,9 @@ test("wait returns within 100 ms of a chat message landing", async () => {
|
||||
const answeredAt = Date.now();
|
||||
assert.ok((await printed) - answeredAt < 2000, "wait must hand the chat over well inside its 5 s poll");
|
||||
assert.equal(await exited, 0);
|
||||
assert.equal(safeJson(out).type, "chat");
|
||||
assert.match(safeJson(out).reply, /^Quick question \(\d+\): Quick one$/m);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -171,27 +166,27 @@ test("the chat command answers at once: 0 with entries, 10 with none, 20 when th
|
||||
assert.equal((await (await s.send("/ping", {})).json()).pendingChat, 1, "an uncollected question shows on the heartbeat");
|
||||
const got = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(got.status, 0);
|
||||
assert.ok(got.json.chat.some((e) => e.text === "Mid-build question"));
|
||||
assert.match(got.json.reply, /Quick question: Mid-build question/);
|
||||
assert.ok(got.json.terminalLine);
|
||||
assert.equal(got.json.chat.length, 1);
|
||||
assert.match(got.json.reply, /Quick question \(\d+\): Mid-build question/);
|
||||
const onDisk = JSON.parse(fs.readFileSync(path.join(s.session, "result.json"), "utf8"));
|
||||
assert.equal(onDisk.consumedAt, undefined, "the card send is still waiting for wait");
|
||||
assert.equal((await (await s.send("/ping", {})).json()).pendingChat, 0);
|
||||
|
||||
const none = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(none.status, 10);
|
||||
assert.deepEqual(none.json, { chat: [] });
|
||||
assert.deepEqual(none.json, {});
|
||||
|
||||
const card = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(card.status, 0);
|
||||
assert.equal(card.json.type, "submit");
|
||||
assert.deepEqual(card.json.chat, [], "the chat went with the chat command, not twice");
|
||||
assert.match(card.json.reply, /^Export format: a/);
|
||||
assert.equal(card.json.chat, undefined, "the chat went with the chat command, not twice");
|
||||
assert.ok(!card.json.reply.includes("Mid-build question"));
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
const gone = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(gone.status, 20);
|
||||
assert.equal(gone.json.status, "server-gone");
|
||||
assert.equal(gone.json.gone, true);
|
||||
});
|
||||
|
||||
test("a torn trailing inbox line is skipped, then collected once it is whole", async () => {
|
||||
@@ -207,9 +202,9 @@ test("a torn trailing inbox line is skipped, then collected once it is whole", a
|
||||
assert.ok(readChat(s.session).some((e) => e.seq === seq));
|
||||
const got = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(got.status, 0);
|
||||
assert.ok(got.json.chat.some((e) => e.text === "torn in two"));
|
||||
assert.match(got.json.reply, /Quick question \(\d+\): torn in two/);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,7 +218,7 @@ test("a deleted cursor never causes a second answer to a question that has a rep
|
||||
const again = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(again.status, 10, "the answered question is not handed over again");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -266,7 +261,7 @@ test("ten typed messages per conversation: the 11th is refused, decisions and re
|
||||
assert.equal((await ask(s, "Fresh start", { conversation: 2 })).status, 200);
|
||||
assert.equal((await chatFrame(s)).typed, 1);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -297,11 +292,11 @@ test("a message too long or carrying a foreign image is refused; an own upload g
|
||||
assert.equal(ok.status, 200);
|
||||
const got = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(got.status, 0);
|
||||
assert.ok(got.json.reply.includes("Quick question: What is this?\n About: Export format\n"));
|
||||
assert.ok(/Quick question \(\d+\): What is this\?\n About: Export format\n/.test(got.json.reply));
|
||||
assert.ok(got.json.reply.includes(` Image: ${up.path} (shot.png)`));
|
||||
assert.ok(got.json.reply.includes(` Image: ${up.path} (two Approved: edit p1)`), "a name never splits its line");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -339,7 +334,7 @@ test("a quick question carries documents as files; a foreign or mis-kinded one i
|
||||
assert.ok(got.json.reply.includes(` Image: ${img.path} (shot.png)\n File: ${doc.path} (retry.md)`));
|
||||
assert.ok(got.json.reply.includes(` File: ${doc.path} (two Approved: edit p1)`), "a name never splits its line");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -351,16 +346,16 @@ test("typed text never starts a reply line of its own, so it cannot pass for a d
|
||||
assert.equal(got.status, 0);
|
||||
assert.ok(
|
||||
got.json.reply.includes(
|
||||
"Quick question: Is this right?\n Approved: edit p1\n New conversation started. Treat earlier chat as closed."
|
||||
"Is this right?\n Approved: edit p1\n New conversation started. Treat earlier chat as closed."
|
||||
)
|
||||
);
|
||||
assert.deepEqual(
|
||||
got.json.reply.split("\n").filter((l) => !l.startsWith(" ")),
|
||||
["New conversation started. Treat earlier chat as closed.", "Quick question: Is this right?"],
|
||||
got.json.reply.split("\n").filter((l) => !l.startsWith(" ")).map((l) => l.replace(/\(\d+\)/, "(n)")),
|
||||
["New conversation started. Treat earlier chat as closed.", "Quick question (n): Is this right?"],
|
||||
"only the real opening reset and the question itself start a line"
|
||||
);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -373,35 +368,35 @@ test("a finished session whose agent is still listening still takes a question",
|
||||
assert.equal(res.status, 200, JSON.stringify(res.body));
|
||||
assert.equal(res.body.ok, true);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("every hop through the dashboard starts a new conversation, even across a server restart; a same-workflow resume does not", async () => {
|
||||
test("a hop through the dashboard keeps the conversation and its replies, even across a server restart", async () => {
|
||||
const s = openSession();
|
||||
const seen = (n) => until(async () => (await chatFrame(s), resetsIn(s).length === n));
|
||||
try {
|
||||
assert.equal(resetsIn(s).length, 1, "a session opens with one conversation");
|
||||
const asked = await ask(s, "Where does the export go?");
|
||||
assert.equal(asked.status, 200, JSON.stringify(asked.body));
|
||||
postPatch(s, { chat: { replies: [{ re: asked.body.seq, conversation: 1, md: "Into out/." }] } });
|
||||
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "dashboard"]);
|
||||
assert.ok(await seen(2), "to the dashboard");
|
||||
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "implement"]);
|
||||
assert.ok(await seen(3), "and back out of it");
|
||||
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "implement"]);
|
||||
await sleep(1500);
|
||||
await chatFrame(s);
|
||||
assert.equal(resetsIn(s).length, 3, "the same workflow again is not a hop");
|
||||
assert.deepEqual(resetsIn(s).map((e) => e.reason), ["start", "switch", "switch"]);
|
||||
const frame = await chatFrame(s);
|
||||
assert.equal(resetsIn(s).length, 1, "no hop starts a new conversation");
|
||||
assert.equal(frame.conversation, 1);
|
||||
assert.ok(JSON.stringify(frame).includes("Into out/."), "the agent's reply rides the hop");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
const back = cli(["open", "--resume", s.sid, "--no-open", "--workflow", "dashboard"]);
|
||||
try {
|
||||
const fresh = { ...s, ...sessionUrl(back.json.url) };
|
||||
assert.ok(await until(async () => (await chatFrame(fresh), resetsIn(s).length === 4)), "a fresh server still sees the hop");
|
||||
assert.equal(resetsIn(s).at(-1).workflow, "dashboard");
|
||||
assert.equal((await chatFrame(fresh)).conversation, 4);
|
||||
const frame = await chatFrame(fresh);
|
||||
assert.equal(resetsIn(s).length, 1, "a fresh server keeps it too");
|
||||
assert.equal(frame.conversation, 1);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -429,7 +424,7 @@ test("a reply proposing an edit under the running spec is refused; a valid reply
|
||||
const onDisk = readState(s.session);
|
||||
assert.deepEqual(onDisk.chat.replies.map((r) => r.id), ["r1"], "nothing was written");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -437,12 +432,48 @@ test("a reply proposing an edit under the running spec is refused; a valid reply
|
||||
// fenced block, so the agent has to be told when and how to write one.
|
||||
test("console-chat.md teaches the prompt block: when, what it holds, and not to open it with a command word", () => {
|
||||
const text = fs.readFileSync(path.join(ROOT, "src", "web-console", "console-chat.md"), "utf8");
|
||||
const section = text.split(/^## /m).find((s) => s.startsWith("Prompts to carry away"));
|
||||
assert.ok(section, "console-chat.md has no 'Prompts to carry away' section");
|
||||
const section = text.split(/^## /m).find((s) => s.startsWith("A prompt to carry away"));
|
||||
assert.ok(section, "console-chat.md has no 'A prompt to carry away' section");
|
||||
assert.match(section, /fenced block/);
|
||||
assert.match(section, /Copy/);
|
||||
assert.match(section, /paste it into the Ask tab/);
|
||||
assert.match(section, /paste into the Ask tab/);
|
||||
assert.match(section, /out of scope/);
|
||||
assert.match(section, /files to read/);
|
||||
assert.doesNotMatch(section, /\u2014/, "no em dash in the section");
|
||||
});
|
||||
|
||||
/* ------------------------------------- quick question: arrives once (FR-18) */
|
||||
|
||||
test("a Quick question arrives once: a numbered reply line, the seq in chat, no full entries, and a reply with re clears the warning", async () => {
|
||||
const s = openSession();
|
||||
try {
|
||||
const asked = await ask(s, "Where does the export live?");
|
||||
assert.equal(asked.status, 200);
|
||||
const seq = asked.body.seq;
|
||||
const got = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(got.status, 0);
|
||||
assert.ok(got.json.reply.endsWith(`Quick question (${seq}): Where does the export live?`), "the numbered line");
|
||||
assert.equal(got.json.reply.split("\n").filter((l) => l.startsWith("Quick question")).length, 1);
|
||||
assert.deepEqual(got.json.chat, [seq], "chat is the seq numbers a reply needs");
|
||||
assert.deepEqual(Object.keys(got.json).filter((k) => !["read", "terminalLine"].includes(k)).sort(), ["chat", "reply"], "no full chat entries or old fields");
|
||||
assert.equal(got.stdout.split(`Where does the export live?`).length - 1, 1, "the question text appears once in the output");
|
||||
|
||||
// Handed over and not answered: the next slice warns, naming the seq.
|
||||
const waiting = cli(["wait", "--session", s.sid, "--seconds", "5"]);
|
||||
assert.equal(waiting.status, 10);
|
||||
assert.deepEqual(waiting.json.unansweredChat, [seq]);
|
||||
assert.match(waiting.json.warning, new RegExp(`Quick questions ${seq} have no reply yet`));
|
||||
|
||||
// A reply with re: <seq> still validates and clears the warning.
|
||||
assert.equal(postPatch(s, { chat: { replies: [{ re: seq, conversation: 1, md: "In out/." }] } }).status, 0);
|
||||
const after = cli(["wait", "--session", s.sid, "--seconds", "5"]);
|
||||
assert.equal(after.status, 10);
|
||||
assert.equal(after.json.unansweredChat, undefined);
|
||||
assert.equal(after.json.warning, undefined);
|
||||
|
||||
// It is not handed over a second time.
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 10);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -65,7 +65,7 @@ test("helpers: a dashboard hop clears them, a same-workflow or paused resume kee
|
||||
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "implement"]);
|
||||
assert.equal("helpers" in readState(s.session), false, "and the hop back brings none");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ test("meter: a repeated run counts once, a bad one appends nothing, and neither
|
||||
assert.match(unknown.stderr, /run: unknown event "nap"/);
|
||||
const noId = postPatch(s, { run: { event: "plan" } }, { expectFail: true });
|
||||
assert.equal(noId.status, 3);
|
||||
assert.match(noId.stderr, /run: id required/);
|
||||
assert.match(noId.stderr, /run: needs an id/);
|
||||
const badTasks = postPatch(s, { run: { event: "implement-phase", id: "phase-1", tasks: 0 } }, { expectFail: true });
|
||||
assert.equal(badTasks.status, 3);
|
||||
assert.match(badTasks.stderr, /run: tasks must be a whole number/);
|
||||
@@ -108,7 +108,7 @@ test("meter: a repeated run counts once, a bad one appends nothing, and neither
|
||||
assert.equal("run" in state, false);
|
||||
assert.equal("folderIssue" in state, false);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -132,7 +132,7 @@ test("meter: open --file takes run and folderIssue as post does, scoped to the n
|
||||
assert.equal("run" in state, false);
|
||||
assert.equal("folderIssue" in state, false);
|
||||
} finally {
|
||||
cli(["stop", "--session", good.json.sid]);
|
||||
cli(["stop", "--session", good.json.sid, "--force"]);
|
||||
}
|
||||
const bad = cli(["open", "--no-open", "--file", payload("open-run-bad.json", { run: { event: "nap", id: "x" } })], { expectFail: true });
|
||||
assert.equal(bad.status, 3);
|
||||
@@ -151,7 +151,7 @@ test("meter: a folder issue shows in the frame's workspace.issues until the next
|
||||
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "implement"]);
|
||||
assert.deepEqual((await s.get("/workspace")).issues, [], "a new skill run starts clean");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -182,8 +182,8 @@ test("two sessions keep their own cookies: each server reads only the one named
|
||||
const crossed = b.cookie.replace(/^p2c_console_\d+/, `p2c_console_${new URL(a.base).port}`);
|
||||
assert.equal((await fetch(`${a.base}/state`, { headers: { cookie: crossed, connection: "close" } })).status, 403);
|
||||
} finally {
|
||||
cli(["stop", "--session", a.sid]);
|
||||
cli(["stop", "--session", b.sid]);
|
||||
cli(["stop", "--session", a.sid, "--force"]);
|
||||
cli(["stop", "--session", b.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -222,7 +222,7 @@ test("a post and a submit that overlap both survive: the state lock serializes t
|
||||
assert.equal(fs.existsSync(lock), false, "and the lock is let go");
|
||||
assert.equal(cli(["wait", "--session", s.sid, "--seconds", "5"]).status, 0);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -237,7 +237,7 @@ test("a lock left by a writer that died is broken rather than waited on for good
|
||||
assert.equal(readState(s.session).agent.status, "working");
|
||||
assert.equal(fs.existsSync(lock), false);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -256,7 +256,7 @@ test("stop never kills a live process that does not answer /health as ours", ()
|
||||
forged,
|
||||
JSON.stringify({ v: 1, sid: sidForged, pid: bystander.pid, port: 1, url: "http://127.0.0.1:1/", startedAt: new Date().toISOString() })
|
||||
);
|
||||
const res = cli(["stop", "--session", sidForged]);
|
||||
const res = cli(["stop", "--session", sidForged, "--force"]);
|
||||
assert.equal(res.json.stopped, 0);
|
||||
assert.equal(res.json.skippedStaleHandles, 1);
|
||||
assert.equal(fs.existsSync(forged), false, "the handle goes");
|
||||
@@ -285,11 +285,10 @@ test("open from a linked worktree seeds the workspace with the worktree, not the
|
||||
try {
|
||||
const res = cliIn(wt, ["open", "--workflow", "plan", "--no-open"]);
|
||||
sidOpened = res.json.sid;
|
||||
assert.deepEqual(res.json.workspace.folders.map((f) => f.path), [worktree]);
|
||||
const onDisk = JSON.parse(fs.readFileSync(path.join(res.json.session, WORKSPACE_FILE), "utf8"));
|
||||
assert.deepEqual(onDisk.folders.map((f) => f.path), [worktree], "workspace.json names the worktree");
|
||||
} finally {
|
||||
if (sidOpened) cliIn(wt, ["stop", "--session", sidOpened]);
|
||||
if (sidOpened) cliIn(wt, ["stop", "--session", sidOpened, "--force"]);
|
||||
// A stopped server can take a while to let go of its working directory on
|
||||
// Windows, and longer while other test files load the machine: under a
|
||||
// full-suite run this needed more than the 5s a 20x250ms retry gave it.
|
||||
@@ -302,8 +301,8 @@ test("open from a linked worktree seeds the workspace with the worktree, not the
|
||||
test("validate refuses a text pattern that does not compile, and post exits 3 on it", () => {
|
||||
const item = (pattern) => ({ items: [{ id: "t1", kind: "text", title: "Ticket number", pattern }] });
|
||||
assert.deepEqual(validate(item("^[A-Z]+-\\d+$")), []);
|
||||
assert.match(validate(item("([")).join("\n"), /"pattern" is not a valid JavaScript regular expression/);
|
||||
assert.match(validate(item(7)).join("\n"), /"pattern" must be a string/);
|
||||
assert.match(validate(item("([")).join("\n"), /pattern: is not a valid JavaScript regular expression/);
|
||||
assert.match(validate(item(7)).join("\n"), /pattern: must be a string/);
|
||||
|
||||
const s = openSession();
|
||||
try {
|
||||
@@ -313,7 +312,7 @@ test("validate refuses a text pattern that does not compile, and post exits 3 on
|
||||
assert.match(bad.stderr, /pattern/);
|
||||
assert.equal(fs.readFileSync(path.join(s.session, "state.json"), "utf8"), before, "nothing was written");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -342,7 +341,7 @@ test("wait reads --seconds 6s as six seconds, not as nothing", () => {
|
||||
assert.equal(res.status, 10);
|
||||
assert.ok(Date.now() - t0 >= 5000, "the slice ran its length");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -359,7 +358,7 @@ test("only open leaves the console-dir pointer; status, help and a bad command d
|
||||
assert.equal(fs.existsSync(pointer), false);
|
||||
const opened = cli(["open", "--no-open"], { env });
|
||||
assert.equal(fs.readFileSync(pointer, "utf8").trim(), path.join(ROOT, "src", "web-console"));
|
||||
cli(["stop", "--session", opened.json.sid], { env });
|
||||
cli(["stop", "--session", opened.json.sid, "--force"], { env });
|
||||
} finally {
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
@@ -424,7 +423,7 @@ test("every state-changing route refuses a foreign Origin, and nothing changes",
|
||||
assert.equal(own.status, 200);
|
||||
assert.deepEqual(await own.json(), { path: picked });
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(picked, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -517,7 +517,7 @@ test("git board host: the host draws the board only through drawGitBoard, and th
|
||||
test("git board docs: the agent prose, Help topic and readme describe the tabbed board", () => {
|
||||
const read = (p) => fs.readFileSync(new URL(p, import.meta.url), "utf8");
|
||||
const notes = read("../src/web-console/notes/git.md");
|
||||
const finishing = notes.slice(notes.indexOf("**Finishing**"));
|
||||
const finishing = notes.slice(notes.indexOf("**Finishing"));
|
||||
assert.ok(finishing.includes("Done with git"), "notes/git.md Finishing names Done with git");
|
||||
assert.ok(finishing.includes("cancel"), "notes/git.md Finishing cancels an open card");
|
||||
assert.ok(!finishing.includes('"settle": ["<id>"]'), "the cancel rule never settles a card nothing was sent to");
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
resumeCommand,
|
||||
SKILL_CATALOG,
|
||||
} from "../src/web-console/public/answers.js";
|
||||
import { SKILLS } from "../src/web-console/public/skills.js";
|
||||
import { FLOW_SKILLS as SKILLS } from "../src/web-console/public/skills.js";
|
||||
import { breakdownFrom, pointsFrom } from "../src/web-console/public/meter.js";
|
||||
import {
|
||||
BRANCH_TYPES,
|
||||
@@ -107,10 +107,10 @@ test("git: open --workflow git writes state.git, and a dashboard open writes non
|
||||
assert.equal(git.repo, true);
|
||||
assert.equal(git.head.branch, "main");
|
||||
assert.equal(git.refreshFailed, false);
|
||||
r.cli(["stop", "--session", opened.json.sid]);
|
||||
r.cli(["stop", "--session", opened.json.sid, "--force"]);
|
||||
const dash = r.open("--workflow", "dashboard");
|
||||
assert.equal("git" in readState(dash.json.session), false, "the dashboard gets a scan, not a board");
|
||||
r.cli(["stop", "--session", dash.json.sid]);
|
||||
r.cli(["stop", "--session", dash.json.sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -131,7 +131,7 @@ test("git: a reread post lands the card and a fresh state.git in one write", ()
|
||||
assert.equal(after.git.head.ahead, 1, "and the board moved with it");
|
||||
assert.ok(Date.parse(after.git.at) >= Date.parse(first.at));
|
||||
assert.equal("reread" in after, false, "reread never reaches the state");
|
||||
r.cli(["stop", "--session", sid]);
|
||||
r.cli(["stop", "--session", sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -155,7 +155,7 @@ test("git: refreshFailed is set by the agent and cleared by a newer FETCH_HEAD",
|
||||
assert.equal(readState(session).git.refreshFailed, false, "a newer FETCH_HEAD clears it");
|
||||
r.cli(["open", "--resume", sid, "--no-open", "--file", payload("git-open-fail.json", { reread: { refreshFailed: true } })]);
|
||||
assert.equal(readState(session).git.refreshFailed, true, "open --file carries the agent's flag too");
|
||||
r.cli(["stop", "--session", sid]);
|
||||
r.cli(["stop", "--session", sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -168,20 +168,20 @@ test("git: reread is refused off the git workflow or malformed, and a patch neve
|
||||
const before = fs.readFileSync(path.join(plan.session, "state.json"), "utf8");
|
||||
const off = r.cli(["post", "--session", plan.sid, "--file", payload("git-off.json", { reread: true, items: [gitCard] })]);
|
||||
assert.equal(off.status, 3);
|
||||
assert.match(off.stderr, /reread only goes with the git workflow/);
|
||||
assert.match(off.stderr, /reread: only goes with the git workflow/);
|
||||
assert.equal(fs.readFileSync(path.join(plan.session, "state.json"), "utf8"), before, "the state is unchanged");
|
||||
r.cli(["stop", "--session", plan.sid]);
|
||||
r.cli(["stop", "--session", plan.sid, "--force"]);
|
||||
|
||||
const { sid } = r.open("--workflow", "git").json;
|
||||
for (const bad of ["yes", { refreshFailed: "no" }, { refreshFailed: true, extra: 1 }, [], false]) {
|
||||
const res = r.cli(["post", "--session", sid, "--file", payload("git-bad.json", { reread: bad })]);
|
||||
assert.equal(res.status, 3, JSON.stringify(bad));
|
||||
assert.match(res.stderr, /reread must be true or \{ refreshFailed: true\|false \}/);
|
||||
assert.match(res.stderr, /reread: must be true or \{ refreshFailed: true\|false \}/);
|
||||
}
|
||||
const own = r.cli(["post", "--session", sid, "--file", payload("git-own.json", { git: { repo: true } })]);
|
||||
assert.equal(own.status, 3);
|
||||
assert.match(own.stderr, /state\.git is the console's own: post reread instead/);
|
||||
r.cli(["stop", "--session", sid]);
|
||||
assert.match(own.stderr, /git: is the console's own state; post reread instead/);
|
||||
r.cli(["stop", "--session", sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -206,7 +206,7 @@ test("git: resuming into Git hops like a dashboard launch, and leaving for the d
|
||||
assert.equal(board.git.head.branch, "main", "and the board has its data");
|
||||
r.cli(["open", "--resume", qt.sid, "--no-open", "--workflow", "dashboard"]);
|
||||
assert.equal("git" in readState(qt.session), false, "the dashboard does not keep the old board");
|
||||
r.cli(["stop", "--session", qt.sid]);
|
||||
r.cli(["stop", "--session", qt.sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -227,7 +227,7 @@ test("git: POST /pr-host saves to pr-hosts.json and refuses a bad kind or a non-
|
||||
const notGit = await sendTo(sessionUrl(plan.url), { host: "git.example.com", kind: "gitlab" });
|
||||
assert.equal(notGit.status, 400);
|
||||
assert.equal((await notGit.json()).error, "not-git");
|
||||
r.cli(["stop", "--session", plan.sid]);
|
||||
r.cli(["stop", "--session", plan.sid, "--force"]);
|
||||
|
||||
const g = r.open("--workflow", "git").json;
|
||||
const gs = sessionUrl(g.url);
|
||||
@@ -237,7 +237,7 @@ test("git: POST /pr-host saves to pr-hosts.json and refuses a bad kind or a non-
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(store, "utf8")), { "git.example.com": "gitlab" }, "saved lowercased, as it is looked up");
|
||||
assert.equal(fs.existsSync(path.join(r.repo, "pr-hosts.json")), false, "nothing under the project");
|
||||
assert.ok(PROTECTED_CONSOLE_FILES.has("pr-hosts.json"), "Cleanup never removes it");
|
||||
r.cli(["stop", "--session", g.sid]);
|
||||
r.cli(["stop", "--session", g.sid, "--force"]);
|
||||
} finally {
|
||||
fs.rmSync(store, { force: true });
|
||||
r.cleanup();
|
||||
@@ -275,7 +275,7 @@ test("git: commits on a run go only with git-commits, as a whole number", () =>
|
||||
const ok = r.cli(["post", "--session", sid, "--file", payload("git-c3.json", { run: { event: "git-commits", id: "z", commits: 2 } })]);
|
||||
assert.equal(ok.status, 0, ok.stderr);
|
||||
assert.ok(readLedger(session).some((e) => e.event === "git-commits" && e.commits === 2), "the count rides on the ledger line");
|
||||
r.cli(["stop", "--session", sid]);
|
||||
r.cli(["stop", "--session", sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -590,11 +590,11 @@ test("git: a board action round-trips as one __git action with its fields intact
|
||||
);
|
||||
const res = r.cli(["wait", "--session", opened.sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.deepEqual(res.json.actions, [{ i: "__git", type: "git", op: "switch", branch: "main" }]);
|
||||
assert.deepEqual(res.json.session, [{ i: "__git", op: "switch", branch: "main" }]);
|
||||
assert.equal(res.json.reply, "Switch to main.");
|
||||
const state = readState(opened.session);
|
||||
assert.ok(state.items.every((i) => i.id !== "__git"), "a board action must not become a question");
|
||||
r.cli(["stop", "--session", opened.sid]);
|
||||
r.cli(["stop", "--session", opened.sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
@@ -608,7 +608,7 @@ test("git: a board.describe post lands in state for the Create panel to read", a
|
||||
const opened = r.open("--workflow", "git").json;
|
||||
r.cli(["post", "--session", opened.sid, "--file", payload("board-describe.json", { board: { describe: "retry the push" } })]);
|
||||
assert.equal(readState(opened.session).board.describe, "retry the push");
|
||||
r.cli(["stop", "--session", opened.sid]);
|
||||
r.cli(["stop", "--session", opened.sid, "--force"]);
|
||||
} finally {
|
||||
r.cleanup();
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ async function withDashboard(fn) {
|
||||
try {
|
||||
return await fn({ sid: opened.json.sid, session: opened.json.session, get });
|
||||
} finally {
|
||||
run(["stop", "--session", opened.json.sid]);
|
||||
run(["stop", "--session", opened.json.sid, "--force"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,7 +411,7 @@ test("a dashboard open scans this checkout's handoffs and the folder; other work
|
||||
try {
|
||||
assert.equal(readStateOf(quick.json.session).scan, undefined, "no scan, so no handoffs, off the dashboard");
|
||||
} finally {
|
||||
run(["stop", "--session", quick.json.sid]);
|
||||
run(["stop", "--session", quick.json.sid, "--force"]);
|
||||
}
|
||||
} finally {
|
||||
fresh();
|
||||
@@ -472,7 +472,7 @@ test("a __pickup round trip prints the hop, marks the handoff used, and the next
|
||||
assert.equal(back.status, 0, back.stderr);
|
||||
assert.deepEqual(readStateOf(opened.json.session).scan.handoffs, [], "a used handoff is no longer listed");
|
||||
} finally {
|
||||
run(["stop", "--session", opened.json.sid]);
|
||||
run(["stop", "--session", opened.json.sid, "--force"]);
|
||||
}
|
||||
} finally {
|
||||
fresh();
|
||||
@@ -495,12 +495,12 @@ test("a __delete with a handoff round-trips like a spec delete: no resume, no sk
|
||||
assert.equal(res.status, 200);
|
||||
const got = run(["wait", "--session", opened.json.sid, "--seconds", "10"]);
|
||||
assert.equal(got.status, 0, got.stderr);
|
||||
assert.equal(got.json.actions[0].handoff, made.id);
|
||||
assert.equal(got.json.session[0].handoff, made.id);
|
||||
assert.equal(got.json.resume, undefined);
|
||||
assert.equal(got.json.skillFile, undefined);
|
||||
assert.equal(got.json.handoffFile, undefined);
|
||||
} finally {
|
||||
run(["stop", "--session", opened.json.sid]);
|
||||
run(["stop", "--session", opened.json.sid, "--force"]);
|
||||
}
|
||||
} finally {
|
||||
fresh();
|
||||
|
||||
@@ -29,7 +29,7 @@ test("another console's cookie beside ours does not lock this one out", async ()
|
||||
assert.equal(legacy.status, 403);
|
||||
await legacy.arrayBuffer();
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -145,7 +145,7 @@ test("a cancel that could not be written answers 500 and tells nobody", async ()
|
||||
fs.rmSync(blocker, { recursive: true, force: true });
|
||||
assert.equal((await s.send("/cancel", {})).status, 200, "and once it can land, it does");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -158,7 +158,7 @@ test("wait refuses a --seconds that is not a number instead of spinning", () =>
|
||||
assert.match(res.stderr, /--seconds must be a number/);
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,6 +223,6 @@ test("an image block outside the session's shots folder, or not an image, is ref
|
||||
assert.equal(res.status, 3);
|
||||
assert.match(res.stderr, /cannot also carry "md" or "file"/);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -112,7 +112,6 @@ test("under the app, open reuses the app's session, announces the page and launc
|
||||
});
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.sid, appSid, "the window's own session is reused, not a second console");
|
||||
assert.equal(res.json.reused, true);
|
||||
assert.equal(res.json.inApp, true);
|
||||
assert.equal(res.json.announced, true);
|
||||
assert.equal(app.seen.length, 1);
|
||||
@@ -123,7 +122,7 @@ test("under the app, open reuses the app's session, announces the page and launc
|
||||
assert.deepEqual(browser.calls(), [], "no browser is launched under the app");
|
||||
} finally {
|
||||
app.close();
|
||||
cli(["stop", "--session", appSid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", appSid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -140,7 +139,7 @@ test("under the app, a hop on the app's session keeps the same url and reports t
|
||||
assert.equal(app.seen[0].workflow, "pathfinder");
|
||||
} finally {
|
||||
app.close();
|
||||
cli(["stop", "--session", first.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", first.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -167,7 +166,7 @@ test("under the app, a wrong token is reported and the page is not sent to a bro
|
||||
assert.deepEqual(browser.calls(), []);
|
||||
} finally {
|
||||
app.close();
|
||||
cli(["stop", "--session", first.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", first.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -182,7 +181,7 @@ test("under the app, a session that is gone gets a fresh one and its address ann
|
||||
assert.equal(res.status, 0);
|
||||
assert.notEqual(res.json.sid, "20200101-000000-nothere");
|
||||
assert.equal(app.seen[0].url, res.json.url);
|
||||
cli(["stop", "--session", res.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", res.json.sid, "--force"], { cwd, expectFail: true });
|
||||
} finally {
|
||||
app.close();
|
||||
}
|
||||
@@ -204,8 +203,8 @@ test("two app windows never receive each other's pages", async () => {
|
||||
} finally {
|
||||
appA.close();
|
||||
appB.close();
|
||||
cli(["stop", "--session", a.json.sid], { cwd: cwdA, expectFail: true });
|
||||
cli(["stop", "--session", b.json.sid], { cwd: cwdB, expectFail: true });
|
||||
cli(["stop", "--session", a.json.sid, "--force"], { cwd: cwdA, expectFail: true });
|
||||
cli(["stop", "--session", b.json.sid, "--force"], { cwd: cwdB, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -225,7 +224,7 @@ test("without the signal, open still launches the browser and reports nothing ab
|
||||
assert.ok(calls.length >= 1, "the browser command ran");
|
||||
assert.match(calls[0], /^http:\/\/127\.0\.0\.1:\d+\/s\//);
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", res.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -243,8 +242,8 @@ test("the window's session, not the environment's, decides what open resumes", a
|
||||
assert.equal(app.seen[0].sid, live.json.sid);
|
||||
} finally {
|
||||
app.close();
|
||||
cli(["stop", "--session", stale.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", live.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", stale.json.sid, "--force"], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", live.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -264,7 +263,7 @@ test("with nothing shown in the window yet, open makes the first session and ann
|
||||
assert.equal(app.seen[0].url, res.json.url);
|
||||
await new Promise((r) => setTimeout(r, 700));
|
||||
assert.deepEqual(browser.calls(), [], "the first page goes to the app too, not a browser");
|
||||
cli(["stop", "--session", res.json.sid], { cwd, expectFail: true });
|
||||
cli(["stop", "--session", res.json.sid, "--force"], { cwd, expectFail: true });
|
||||
} finally {
|
||||
app.close();
|
||||
}
|
||||
@@ -324,10 +323,12 @@ test("the Desktop app group shows only in the app's frame, reflects the app's sa
|
||||
const browser = await pages.browser();
|
||||
const plain = await openSession(browser, { t, workflow: "implement", payload: ASKING });
|
||||
await plain.page.locator("#btn-looks").click();
|
||||
await plain.page.locator("#prefs-tab-system").click();
|
||||
assert.equal(await plain.page.locator("#looks-desktop").isVisible(), false, "not in a browser tab");
|
||||
|
||||
const s = await openSession(browser, { t, workflow: "implement", payload: ASKING, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
|
||||
await s.page.locator("#btn-looks").click();
|
||||
await s.page.locator("#prefs-tab-system").click();
|
||||
const box = s.page.locator("#looks-taskbar");
|
||||
assert.ok(await s.page.locator("#looks-desktop").isVisible(), "shown inside the app");
|
||||
assert.ok(await box.isChecked(), "on until the app says otherwise");
|
||||
@@ -352,3 +353,21 @@ test("the Desktop app group shows only in the app's frame, reflects the app's sa
|
||||
await box.check();
|
||||
assert.deepEqual(await toApp(s, "taskbar"), [{ plan2code: "taskbar", on: true }], "a named request with one boolean");
|
||||
});
|
||||
|
||||
test("framed, an Activities game in full screen asks the app for the whole screen, and gives it back on F, Esc and a new question", async (t) => {
|
||||
const s = await openSession(await pages.browser(), { t, workflow: "plan", payload: { agent: { status: "working", activity: "Reading" } }, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
|
||||
await s.page.click("#btn-activities");
|
||||
await s.page.locator('.activities-card[data-activity="snake"]').click();
|
||||
await s.page.locator("#activities-board").waitFor();
|
||||
const told = async () => (await toApp(s, "activities-full")).map((m) => m.on);
|
||||
await s.page.keyboard.press("f");
|
||||
assert.deepEqual(await told(), [true], "a named request with one boolean");
|
||||
await s.page.keyboard.press("f");
|
||||
await s.page.keyboard.press("f");
|
||||
await s.page.keyboard.press("Escape");
|
||||
assert.deepEqual(await told(), [true, false, true, false], "F and Esc each give it back");
|
||||
await s.page.keyboard.press("f");
|
||||
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who opens the export?" }], agent: { status: "waiting" } });
|
||||
await until(async () => (await told()).at(-1) === false, 5000);
|
||||
assert.deepEqual(await told(), [true, false, true, false, true, false], "and so does a new question");
|
||||
});
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
cookieFor,
|
||||
cli,
|
||||
payload,
|
||||
stopSession,
|
||||
BASE,
|
||||
backdate,
|
||||
readState,
|
||||
@@ -147,7 +148,7 @@ test("open --resume never discards an uncollected result", async () => {
|
||||
|
||||
test("open clears a result that was already collected", () => {
|
||||
const before = cli(["open", "--resume", sid, "--no-open"]);
|
||||
assert.equal(before.json.pendingResult, false);
|
||||
assert.ok(!before.json.pendingResult, "open prints pendingResult only when true");
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "3"]);
|
||||
assert.equal(res.status, 10, "a consumed result must not be handed over again");
|
||||
});
|
||||
@@ -186,6 +187,68 @@ test("open --resume takes a pause down, and only a pause", () => {
|
||||
cli(["post", "--session", sid, "--file", payload("fin-clear.json", { finish: null })]);
|
||||
});
|
||||
|
||||
// Continue here on a finished screen resumes into the SAME skill (Pathfinder
|
||||
// into Pathfinder), which is no hop. The old ending must still come down, or
|
||||
// its card freezes every question the new run asks. A question posted over a
|
||||
// standing ending clears it too, for an agent that forgot `finish: null`.
|
||||
test("a launch resume and a new question both take a real ending down", () => {
|
||||
const stateFile = path.join(session, "state.json");
|
||||
const readState = () => JSON.parse(fs.readFileSync(stateFile, "utf8"));
|
||||
const wf = readState().workflow;
|
||||
|
||||
cli(["post", "--session", sid, "--file", payload("fin-launch.json", {
|
||||
finish: { headline: "The map is charted", command: "/plan2code-0-pathfinder", dashboard: true },
|
||||
})]);
|
||||
cli(["open", "--resume", sid, "--no-open", "--workflow", wf]);
|
||||
assert.equal(readState().finish, undefined, "a launch resume into the same skill clears the ending");
|
||||
|
||||
cli(["post", "--session", sid, "--file", payload("fin-ask.json", {
|
||||
finish: { headline: "The map is charted", command: "/plan2code-0-pathfinder" },
|
||||
})]);
|
||||
cli(["post", "--session", sid, "--file", payload("ask-over-fin.json", {
|
||||
items: [{ id: "q-over-fin", kind: "text", title: "Next thing", body: "Asked after the ending." }],
|
||||
})]);
|
||||
assert.equal(readState().finish, undefined, "a new open question clears a standing ending");
|
||||
|
||||
// A patch that posts its own finish, even with items, keeps it.
|
||||
cli(["post", "--session", sid, "--file", payload("fin-with-item.json", {
|
||||
items: [{ id: "q-with-fin", kind: "notice", title: "Heads up", body: "Read only." }],
|
||||
finish: { headline: "All done", command: "/plan2code-0-pathfinder" },
|
||||
})]);
|
||||
assert.equal(readState().finish.headline, "All done", "a patch's own finish stays");
|
||||
|
||||
// Leave the session the way later tests expect to find it.
|
||||
cli(["post", "--session", sid, "--file", payload("fin-clear2.json", { finish: null })]);
|
||||
});
|
||||
|
||||
// A new question posted under an answered card's id used to merge into the
|
||||
// old card and stay answered, leaving the person a dead page. It is refused
|
||||
// with the fix named; a typo fix on the same title still goes through.
|
||||
test("a new question under an answered id is refused, a typo fix is not", () => {
|
||||
const stateFile = path.join(session, "state.json");
|
||||
const readState = () => JSON.parse(fs.readFileSync(stateFile, "utf8"));
|
||||
cli(["post", "--session", sid, "--file", payload("reuse-a.json", {
|
||||
items: [{ id: "q-reuse", kind: "choice", title: "Pick one", body: "Which?", options: [{ text: "A" }, { text: "B" }] }],
|
||||
})]);
|
||||
cli(["post", "--session", sid, "--file", payload("reuse-b.json", { items: [{ id: "q-reuse", status: "answered", answer: { k: "A" } }] })]);
|
||||
|
||||
const typo = cli(["post", "--session", sid, "--file", payload("reuse-typo.json", { items: [{ id: "q-reuse", title: "Pick one", body: "Which one?" }] })]);
|
||||
assert.equal(typo.status, 0, "a body fix under the same title is allowed");
|
||||
assert.equal(readState().items.find((i) => i.id === "q-reuse").status, "answered");
|
||||
|
||||
const reuse = cli(["post", "--session", sid, "--file", payload("reuse-new.json", {
|
||||
items: [{ id: "q-reuse", kind: "choice", title: "Something else", body: "A different question", options: [{ text: "X" }, { text: "Y" }] }],
|
||||
})], { expectFail: true });
|
||||
assert.equal(reuse.status, 3, "a new question under an old id is refused");
|
||||
assert.match(reuse.stderr, /already used for the answered question "Pick one"/);
|
||||
assert.match(reuse.stderr, /new id/);
|
||||
|
||||
const reopened = cli(["post", "--session", sid, "--file", payload("reuse-reopen.json", {
|
||||
items: [{ id: "q-reuse", status: "reopened", title: "Something else", body: "A different question" }],
|
||||
})]);
|
||||
assert.equal(reopened.status, 0, "an explicit reopen is allowed");
|
||||
});
|
||||
|
||||
// The dashboard hands its live session to the skill it launched: one
|
||||
// `open --resume` turns the page (workflow, title, spec) while reusing the
|
||||
// server. If the flags did not apply on resume, the launched skill would
|
||||
@@ -199,7 +262,7 @@ test("open --resume restates workflow, title and spec on the live session", () =
|
||||
const res = cli(["open", "--resume", sid, "--no-open", "--workflow", "implement", "--title", "Lunch vote: Phase 2", "--spec", "specs/lunch-vote"]);
|
||||
assert.equal(res.json.ok, true);
|
||||
assert.equal(res.json.sid, sid);
|
||||
assert.equal(res.json.reused, true, "the live server must be reused, not replaced");
|
||||
assert.ok(res.json.url.startsWith(baseUrl + "/"), "the live server must be reused, not replaced");
|
||||
|
||||
const state = JSON.parse(fs.readFileSync(path.join(session, "state.json"), "utf8"));
|
||||
assert.equal(state.workflow, "implement");
|
||||
@@ -243,7 +306,7 @@ test("open with no --workflow still opens a Pathfinder session", () => {
|
||||
assert.equal(res.json.ok, true);
|
||||
assert.equal(readState(res.json.session).workflow, "pathfinder");
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -625,10 +688,10 @@ test("stop leaves a process it cannot identify as ours alone", () => {
|
||||
/* ----------------------------------------------------------- lifecycle */
|
||||
|
||||
test("stop shuts the server down and wait then reports exit 20", () => {
|
||||
cli(["stop", "--session", sid]);
|
||||
cli(["stop", "--session", sid, "--force"]);
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "12"]);
|
||||
assert.equal(res.status, 20);
|
||||
assert.equal(res.json.status, "server-gone");
|
||||
assert.deepEqual(res.json, { gone: true, fix: `open --resume ${sid} --workflow <yours>` });
|
||||
});
|
||||
|
||||
// A 127.0.0.1 link is only the person's machine if the agent is on it too.
|
||||
@@ -641,7 +704,7 @@ test("open flags an environment where the link may not reach the person", () =>
|
||||
assert.equal(res.json.ok, true, "it still starts");
|
||||
assert.equal(res.json.remote, "SSH_CONNECTION");
|
||||
assert.match(res.json.note, /not necessarily theirs/);
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
});
|
||||
|
||||
test("the runtime dir is isolated by PLAN2CODE_CONSOLE_HOME", () => {
|
||||
@@ -665,7 +728,7 @@ test("resume brings the session back on a new port with state intact", async ()
|
||||
const looksRes = await fetch(m[1] + "/looks", { headers: { cookie: cookieFor(m[1], m[2]) } });
|
||||
assert.deepEqual((await looksRes.json()).looks, { theme: "dark", accent: "cobalt" });
|
||||
|
||||
cli(["stop", "--session", sid]);
|
||||
cli(["stop", "--session", sid, "--force"]);
|
||||
});
|
||||
|
||||
/* ------------------------------------------------- the page's own logic */
|
||||
@@ -858,7 +921,7 @@ test("a present finish command must be a non-empty string without a placeholder"
|
||||
expectFail: true,
|
||||
});
|
||||
assert.equal(res.status, 3);
|
||||
assert.match(res.stderr, /"finish\.command" must be a non-empty string, or left out when there is nothing to run/);
|
||||
assert.match(res.stderr, /finish\.command: must be a non-empty string, or left out when there is nothing to run/);
|
||||
}
|
||||
const tmpl = cli(
|
||||
[
|
||||
@@ -967,7 +1030,7 @@ test("a finish can carry the dashboard flag, and only as a boolean", () => {
|
||||
expectFail: true,
|
||||
});
|
||||
assert.equal(bad.status, 3);
|
||||
assert.match(bad.stderr, /"finish\.dashboard" must be true or false \(or left out: no dashboard button\)/);
|
||||
assert.match(bad.stderr, /finish\.dashboard: must be true or false \(or left out: no dashboard button\)/);
|
||||
});
|
||||
|
||||
// The Commit it now button is the same kind of opt-in.
|
||||
@@ -981,7 +1044,7 @@ test("a finish can carry the commit flag, and only as a boolean", () => {
|
||||
expectFail: true,
|
||||
});
|
||||
assert.equal(bad.status, 3);
|
||||
assert.match(bad.stderr, /"finish.commit" must be true or false/);
|
||||
assert.match(bad.stderr, /finish.commit: must be true or false/);
|
||||
});
|
||||
|
||||
// Taking the review up is the agent posting `"finish": null`: the session goes
|
||||
@@ -1044,3 +1107,65 @@ test("post refuses a misplaced templates flag with exit 3", () => {
|
||||
assert.equal(res.status, 3);
|
||||
assert.match(res.stderr, /only a text item can carry it/);
|
||||
});
|
||||
|
||||
/* ------------------------------------------- stop needs a finish (FR-12, FR-13) */
|
||||
|
||||
const healthOf = async (url) => {
|
||||
const m = url.match(/^(http:\/\/127\.0\.0\.1:\d+)\//);
|
||||
try {
|
||||
return (await fetch(m[1] + "/health")).status;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
test("stop with no finish posted exits 3 naming finish and --force, and leaves the server up", async () => {
|
||||
const opened = cli(["open", "--file", payload("stop-nofinish.json", BASE), "--no-open"]);
|
||||
try {
|
||||
const res = cli(["stop", "--session", opened.json.sid], { expectFail: true });
|
||||
assert.equal(res.status, 3);
|
||||
assert.match(res.stderr, /finish/);
|
||||
assert.match(res.stderr, /--force/);
|
||||
assert.equal(await healthOf(opened.json.url), 200, "the server still answers /health");
|
||||
} finally {
|
||||
cli(["stop", "--session", opened.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("stop stops a session once a finish is posted", async () => {
|
||||
const opened = cli(["open", "--file", payload("stop-finish.json", BASE), "--no-open"]);
|
||||
const res = stopSession(opened.json.sid);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.stopped, 1);
|
||||
assert.equal(await healthOf(opened.json.url), 0, "the server is gone");
|
||||
});
|
||||
|
||||
test("stop --force stops a session with no finish, and stop --all does so unchanged", async () => {
|
||||
const one = cli(["open", "--file", payload("stop-force.json", BASE), "--no-open"]);
|
||||
const forced = cli(["stop", "--session", one.json.sid, "--force"]);
|
||||
assert.equal(forced.status, 0);
|
||||
assert.equal(forced.json.stopped, 1);
|
||||
assert.equal(await healthOf(one.json.url), 0);
|
||||
|
||||
const two = cli(["open", "--file", payload("stop-all.json", BASE), "--no-open"]);
|
||||
const all = cli(["stop", "--all"]);
|
||||
assert.equal(all.status, 0);
|
||||
assert.ok(all.json.stopped >= 1, "--all needs no finish");
|
||||
assert.equal(await healthOf(two.json.url), 0);
|
||||
});
|
||||
|
||||
test("a finish posted while stopWarning is set is refused naming stopWarning, and passes once it is cleared", () => {
|
||||
const opened = cli(["open", "--file", payload("stopwarn.json", BASE), "--no-open"]);
|
||||
try {
|
||||
cli(["post", "--session", opened.json.sid, "--file", payload("stopwarn-set.json", { stopWarning: "Unsaved answers are lost." })]);
|
||||
const finish = { headline: "Paused: your answers are saved", command: "/plan2code-1-plan" };
|
||||
const refused = cli(["post", "--session", opened.json.sid, "--file", payload("stopwarn-finish.json", { finish })], { expectFail: true });
|
||||
assert.equal(refused.status, 3);
|
||||
assert.match(refused.stderr, /stopWarning/);
|
||||
const ok = cli(["post", "--session", opened.json.sid, "--file", payload("stopwarn-clear.json", { stopWarning: "", finish })]);
|
||||
assert.equal(ok.status, 0);
|
||||
assert.equal(ok.json.ok, true);
|
||||
} finally {
|
||||
cli(["stop", "--session", opened.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -576,12 +576,13 @@ test("chat lines list documents after images, and chatView carries files on sent
|
||||
const lines = chatReplyLines([
|
||||
{
|
||||
kind: "message",
|
||||
seq: 7,
|
||||
text: "Read these",
|
||||
images: [{ path: "/u/a.jpg", name: "a.png" }],
|
||||
files: [{ path: "/u/b.md", name: "b.md" }],
|
||||
},
|
||||
]);
|
||||
assert.equal(lines, "Quick question: Read these\n Image: /u/a.jpg (a.png)\n File: /u/b.md (b.md)");
|
||||
assert.equal(lines, "Quick question (7): Read these\n Image: /u/a.jpg (a.png)\n File: /u/b.md (b.md)");
|
||||
const view = chatView(
|
||||
{ conversation: 1, messages: [{ from: "person", kind: "message", seq: 1, text: "Read", files: [{ path: "/u/b.md", name: "b.md" }] }] },
|
||||
{ pendingSends: [{ tempId: "t", text: "More", files: [{ path: "/u/c.pdf", name: "c.pdf" }] }] }
|
||||
@@ -1498,22 +1499,22 @@ test("no starter steers the workflow: approve, skip, commit, run, execute, delet
|
||||
|
||||
test("validate: templates only as \"idea\", only on a text item", () => {
|
||||
const item = (extra) => ({ items: [{ id: "idea", kind: "text", title: "What's the idea?", ...extra }] });
|
||||
const message = 'item "idea" has "templates": only a text item can carry it, and its only value is "idea".';
|
||||
const message = 'item "idea" templates: only a text item can carry it, and its only value is "idea".';
|
||||
assert.deepEqual(validate(item({ templates: "idea" })), []);
|
||||
assert.deepEqual(validate(item({})), []);
|
||||
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], templates: "idea" })).includes(message));
|
||||
assert.ok(validate(item({ templates: "yes" })).includes(message));
|
||||
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], templates: "idea" })).some((p) => p.startsWith(message)));
|
||||
assert.ok(validate(item({ templates: "yes" })).some((p) => p.startsWith(message)));
|
||||
});
|
||||
|
||||
test("validate: fill only as \"note\", only on a text item", () => {
|
||||
const item = (extra) => ({ items: [{ id: "idea", kind: "text", title: "What's the idea?", ...extra }] });
|
||||
const message = 'item "idea" has "fill": only a text item can carry it, and its only value is "note".';
|
||||
const message = 'item "idea" fill: only a text item can carry it, and its only value is "note".';
|
||||
assert.deepEqual(validate(item({ fill: "note" })), []);
|
||||
assert.deepEqual(validate(item({ fill: "note", templates: "idea" })), []);
|
||||
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], fill: "note" })).includes(message));
|
||||
assert.ok(validate(item({ kind: "confirm", fill: "note" })).includes(message));
|
||||
assert.ok(validate(item({ fill: "idea" })).includes(message));
|
||||
assert.ok(validate(item({ fill: true })).includes(message));
|
||||
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], fill: "note" })).some((p) => p.startsWith(message)));
|
||||
assert.ok(validate(item({ kind: "confirm", fill: "note" })).some((p) => p.startsWith(message)));
|
||||
assert.ok(validate(item({ fill: "idea" })).some((p) => p.startsWith(message)));
|
||||
assert.ok(validate(item({ fill: true })).some((p) => p.startsWith(message)));
|
||||
});
|
||||
|
||||
test("attachmentName: slug of the original name, 8 characters of the upload id, the upload's own extension", () => {
|
||||
@@ -1748,7 +1749,7 @@ test("meter: a build post's headline.cleared reaches the ledger as progress", ()
|
||||
assert.equal(postPatch(s, { headline: { cleared: 7 }, run: { event: "implement-phase", id: "phase-1", tasks: 7 } }).status, 0);
|
||||
assert.equal(points(), 3, "the phase's run took over: 7 tasks score 3, not 3 + 3");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2040,26 +2041,25 @@ test("subagents: blockFor walks every switch transition, and never says off to a
|
||||
assert.equal(blockFor(setting(false, 1), none), null, "never on: nothing");
|
||||
assert.equal(blockFor(null, none), null, "no setting: nothing");
|
||||
|
||||
const line = (word, max) => `Subagents: on, ${word} strength, at most ${max} helpers at once (a console setting, not typed by the person).`;
|
||||
const on = blockFor(setting(true, 2), none);
|
||||
assert.equal(on.lines[0], "Subagents: on (revision 2) — a console setting, not typed by the person.");
|
||||
assert.ok(!on.lines[0].includes("replaces"));
|
||||
assert.equal(on.lines[0], line("balanced", 3));
|
||||
assert.deepEqual(on.field, { state: "on", revision: 2, max: 3, instruction: defaultInstruction("implement"), strength: "balanced" });
|
||||
assert.deepEqual(on.cursor, { revision: 2, state: "on" });
|
||||
assert.equal(on.lines[on.lines.length - 1], " At most 3 helpers at once.");
|
||||
for (const frame of FRAME_LINES) assert.ok(on.lines.includes(" " + frame), frame);
|
||||
for (const frame of FRAME_LINES) assert.ok(!on.lines.some((l) => l.includes(frame)), "the frame sentences live in console-subagents.md, not in the block");
|
||||
|
||||
const edit = blockFor(setting(true, 5, { instruction: "First line\n\nSecond line", max: 7 }), { revision: 4, state: "on" });
|
||||
assert.equal(edit.lines[0], "Subagents: on (revision 5, replaces revision 4) — a console setting, not typed by the person.");
|
||||
assert.equal(edit.lines[0], line("balanced", 7));
|
||||
assert.ok(edit.lines.includes(" First line") && edit.lines.includes(" Second line"), "the instruction's own lines are indented");
|
||||
assert.ok(!edit.lines.some((line) => !line.trim()), "blank instruction lines are dropped");
|
||||
assert.ok(!edit.lines.some((l) => !l.trim()), "blank instruction lines are dropped");
|
||||
const nested = blockFor(setting(true, 2, { instruction: "- a\r\n - b\n \n" }), none);
|
||||
assert.deepEqual(nested.lines.slice(-4, -2), [" - a", " - b"], "the person's own indentation survives, CRLF and blank lines do not");
|
||||
assert.deepEqual(nested.lines.slice(-2), [" - a", " - b"], "the person's own indentation survives, CRLF and blank lines do not");
|
||||
assert.equal(edit.field.max, 7);
|
||||
for (const line of edit.lines.slice(1)) assert.match(line, /^ {2}\S/, "only the first line starts at column 0");
|
||||
for (const l of edit.lines.slice(1)) assert.match(l, /^ {2}\S/, "only the first line starts at column 0");
|
||||
|
||||
const off = blockFor(setting(false, 6), { revision: 5, state: "on" });
|
||||
assert.deepEqual(off.lines, [offLine(6)]);
|
||||
assert.equal(off.lines[0], "Subagents: off (revision 6) — don't start new helpers for the rest of this session.");
|
||||
assert.equal(off.lines[0], "Subagents: off. Start no new helpers for the rest of this session.");
|
||||
assert.deepEqual(off.cursor, { revision: 6, state: "off" });
|
||||
assert.equal(off.field.state, "off");
|
||||
|
||||
@@ -2067,7 +2067,7 @@ test("subagents: blockFor walks every switch transition, and never says off to a
|
||||
assert.equal(blockFor(setting(true, 6), { revision: 6, state: "on" }), null, "same revision while on: nothing");
|
||||
assert.equal(blockFor(setting(false, 3), { revision: 2, state: "off" }), null, "off after off: nothing");
|
||||
|
||||
assert.equal(blockFor(setting(true, 6), none).lines[0], "Subagents: on (revision 6) — a console setting, not typed by the person.", "a reset cursor re-states on");
|
||||
assert.equal(blockFor(setting(true, 6), none).lines[0], line("balanced", 3), "a reset cursor re-states on");
|
||||
assert.equal(blockFor(setting(false, 6), none), null, "a reset cursor with it off: nothing");
|
||||
assert.equal(blockFor({ ...setting(true, 9), workflow: "document" }, none), null, "a workflow that does not offer it: nothing");
|
||||
});
|
||||
@@ -2378,3 +2378,194 @@ test("Notebook pick rules: an empty tab, the first five pictures ticked, and no
|
||||
assert.deepEqual(toggleNoteTick(four, "f"), ["a", "b", "d", "e", "f"], "untick one to tick another");
|
||||
assert.equal(NOTE_LONG_BYTES, 51200);
|
||||
});
|
||||
|
||||
/* ------------------------------------- the wire: defaults, patch reading, errors */
|
||||
|
||||
import { applyPatch, blankState } from "../src/web-console/patches.mjs";
|
||||
import { readPatch } from "../src/web-console/cmd-post-wait.mjs";
|
||||
import { openSession } from "./web-console-test-helpers.mjs";
|
||||
|
||||
const wireState = () => blankState({ sid: "x", project: "p", workflow: "plan" });
|
||||
const wireItem = (kind, options) => ({ id: "q1", kind, title: "Pick one", body: "Which?", ...(options ? { options } : {}) });
|
||||
|
||||
test("defaults: options with no k are lettered A, B, C on choice, multi and menu", () => {
|
||||
for (const kind of ["choice", "multi", "menu"]) {
|
||||
const next = applyPatch(wireState(), { items: [wireItem(kind, [{ text: "CSV" }, { text: "Excel" }, { text: "JSON" }])] });
|
||||
assert.deepEqual(next.items[0].options.map((o) => o.k), ["A", "B", "C"], kind);
|
||||
assert.deepEqual(validate(next), [], kind);
|
||||
}
|
||||
});
|
||||
|
||||
test("defaults: options that all carry a k keep it, and a mix is refused naming the item and options", () => {
|
||||
const next = applyPatch(wireState(), { items: [wireItem("choice", [{ k: "1", text: "CSV" }, { k: "9", text: "Excel" }])] });
|
||||
assert.deepEqual(next.items[0].options.map((o) => o.k), ["1", "9"]);
|
||||
assert.throws(
|
||||
() => applyPatch(wireState(), { items: [wireItem("choice", [{ k: "A", text: "CSV" }, { text: "Excel" }])] }),
|
||||
(e) => /item "q1" options:/.test(e.message) && /Like this:/.test(e.message)
|
||||
);
|
||||
});
|
||||
|
||||
test("defaults: a new item gets status, required and allowOther filled, and a given value is kept", () => {
|
||||
const next = applyPatch(wireState(), { items: [wireItem("choice", [{ text: "CSV" }]), { ...wireItem("text"), id: "q2", required: false, allowOther: false }] });
|
||||
const [a, b] = next.items;
|
||||
assert.equal(a.status, "open");
|
||||
assert.equal(a.required, true);
|
||||
assert.equal(a.allowOther, true);
|
||||
assert.deepEqual(a.thread, []);
|
||||
assert.equal(b.required, false);
|
||||
assert.equal(b.allowOther, false);
|
||||
});
|
||||
|
||||
test("readPatch: indented, minified, BOM and UTF-16 patches all read the same", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-readpatch-"));
|
||||
try {
|
||||
const patch = { title: "Café – résumé", items: [{ id: "q1", kind: "text", title: "Name" }] };
|
||||
const json = JSON.stringify(patch);
|
||||
const write = (name, buf) => {
|
||||
const p = path.join(dir, name);
|
||||
fs.writeFileSync(p, buf);
|
||||
return p;
|
||||
};
|
||||
const le = Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(json, "utf16le")]);
|
||||
const be = Buffer.concat([Buffer.from([0xfe, 0xff]), Buffer.from(json, "utf16le").swap16()]);
|
||||
for (const [name, buf] of [
|
||||
["minified.json", json],
|
||||
["indented.json", JSON.stringify(patch, null, 4)],
|
||||
["bom.json", "" + json],
|
||||
["le.json", le],
|
||||
["be.json", be],
|
||||
]) {
|
||||
assert.deepEqual(readPatch(write(name, buf)), { patch }, name);
|
||||
}
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("readPatch: a cut-off, a trailing comma and a missing brace name the line and column, show the spot and a caret", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-readpatch-"));
|
||||
try {
|
||||
const read = (text) => {
|
||||
const p = path.join(dir, "p.json");
|
||||
fs.writeFileSync(p, text);
|
||||
return readPatch(p);
|
||||
};
|
||||
const cases = {
|
||||
"a cut-off write": '{"title":"Audit export","items":[{"id":"q1","kind":"te',
|
||||
"a trailing comma": '{"title":"Audit",\n"items":[],\n}',
|
||||
"a missing brace": '{"title":"Audit","agent":{"status":"waiting"}',
|
||||
};
|
||||
for (const [what, text] of Object.entries(cases)) {
|
||||
const { error, patch } = read(text);
|
||||
assert.equal(patch, undefined, what);
|
||||
const lines = error.split("\n");
|
||||
assert.match(lines[0], /^line \d+, column \d+: \S/, `${what}: ${error}`);
|
||||
assert.equal(lines.length, 3, `${what}: the message, the excerpt, the caret`);
|
||||
assert.match(lines[2], /^ *\^$/, `${what}: a caret under the spot`);
|
||||
assert.ok(lines[1].length > 0 && lines[1].length <= 61, `${what}: an excerpt around the spot`);
|
||||
}
|
||||
const comma = read(cases["a trailing comma"]).error;
|
||||
assert.match(comma, /^line 3, column 1:/, "the trailing comma is reported on the closing brace's line");
|
||||
const cut = read(cases["a cut-off write"]).error;
|
||||
assert.match(cut, /^line 1, column \d+:/);
|
||||
assert.ok(cut.split("\n")[1].includes('"kind":"te'), "the excerpt shows where the write stopped");
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("readPatch: empty input and a JSON array each get their own message", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-readpatch-"));
|
||||
try {
|
||||
const read = (text) => {
|
||||
const p = path.join(dir, "p.json");
|
||||
fs.writeFileSync(p, text);
|
||||
return readPatch(p).error;
|
||||
};
|
||||
const empty = read(" \n");
|
||||
const array = read("[1,2]");
|
||||
const nul = read("null");
|
||||
assert.match(empty, /empty/);
|
||||
assert.match(array, /one JSON object/);
|
||||
assert.match(array, /an array/);
|
||||
assert.match(nul, /null/);
|
||||
assert.notEqual(empty, array);
|
||||
assert.match(readPatch(path.join(dir, "missing.json")).error, /no such file/);
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// Each rule break names the item id, the field and a "Like this:" fragment.
|
||||
// The fragment is applied to the patch by `fix`, and the result must pass.
|
||||
test("rule breaks name the item and field, and their Like this: passes validate() when applied", () => {
|
||||
const withFragment = (problem) => {
|
||||
const at = problem.indexOf("Like this: ");
|
||||
assert.ok(at > 0, `a Like this: in ${problem}`);
|
||||
return JSON.parse(problem.slice(at + "Like this: ".length));
|
||||
};
|
||||
const cases = [
|
||||
{
|
||||
what: "an unknown kind",
|
||||
patch: { items: [{ id: "q1", kind: "nope", title: "Pick one", body: "Which?" }] },
|
||||
start: /^item "q1" kind:/,
|
||||
fix: (p, like) => Object.assign(p.items[0], like),
|
||||
},
|
||||
{
|
||||
what: "an option with label",
|
||||
patch: { items: [{ id: "q1", kind: "choice", title: "Pick one", body: "Which?", options: [{ label: "CSV" }, { text: "Excel" }] }] },
|
||||
start: /^item "q1" options:/,
|
||||
fix: (p, like) => (p.items[0].options[0] = like),
|
||||
},
|
||||
{
|
||||
what: "two recommended options",
|
||||
patch: { items: [{ id: "q1", kind: "choice", title: "Pick one", body: "Which?", options: [{ text: "CSV", recommended: true }, { text: "Excel", recommended: true }] }] },
|
||||
start: /^item "q1" options:/,
|
||||
fix: (p, like) => (p.items[0].options = like),
|
||||
},
|
||||
{
|
||||
what: "a finish with a placeholder",
|
||||
patch: { finish: { headline: "Done", command: "/plan2code-<x>" } },
|
||||
start: /^finish\.command:/,
|
||||
fix: (p, like) => Object.assign(p.finish, like.finish),
|
||||
},
|
||||
];
|
||||
for (const { what, patch, start, fix } of cases) {
|
||||
const problems = validate(applyPatch(wireState(), structuredClone(patch)));
|
||||
assert.equal(problems.length, 1, `${what}: ${JSON.stringify(problems)}`);
|
||||
assert.match(problems[0], start, what);
|
||||
const fixed = structuredClone(patch);
|
||||
fix(fixed, withFragment(problems[0]));
|
||||
assert.deepEqual(validate(applyPatch(wireState(), fixed)), [], `${what}: the Like this: passes`);
|
||||
}
|
||||
|
||||
// An unanswered note: the person wrote in a thread and the patch settles without replying.
|
||||
const note = { ...wireItem("choice", [{ k: "A", text: "CSV" }]), thread: [{ who: "user", text: "Why?" }], submitted: { k: "A", at: "2026-01-01T00:00:00.000Z" } };
|
||||
const base = { ...wireState(), items: [note] };
|
||||
const stuck = validate(applyPatch(base, { settle: ["q1"] }));
|
||||
assert.equal(stuck.length, 1);
|
||||
assert.match(stuck[0], /^item "q1" thread:/);
|
||||
const like = withFragment(stuck[0]);
|
||||
assert.deepEqual(validate(applyPatch(base, { settle: ["q1"], items: [{ id: "q1", thread: like.thread.map((t) => ({ ...t, text: "Because." })) }] })), []);
|
||||
});
|
||||
|
||||
test("a refused patch leaves state.json byte for byte as it was", () => {
|
||||
const s = openSession();
|
||||
try {
|
||||
const file = path.join(s.session, "state.json");
|
||||
const before = fs.readFileSync(file);
|
||||
const refused = [
|
||||
{ items: [{ id: "q9", kind: "nope", title: "Pick one", body: "Which?" }] },
|
||||
{ items: [{ id: "q9", kind: "choice", title: "Pick one", body: "Which?", options: [{ k: "A", text: "x" }, { text: "y" }] }] },
|
||||
{ finish: { headline: "Done", command: "/plan2code-<x>" } },
|
||||
];
|
||||
for (const patch of refused) {
|
||||
const res = postPatch(s, patch, { expectFail: true });
|
||||
assert.equal(res.status, 3, JSON.stringify(patch));
|
||||
assert.match(res.stderr, /Like this:/);
|
||||
assert.ok(fs.readFileSync(file).equals(before), "state.json is untouched");
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,625 @@
|
||||
// Web console tests: the Implementation Loop's console side. Run with:
|
||||
// node --test scripts/test-web-console-loop.mjs
|
||||
//
|
||||
// Three groups, one per piece of the contract (src/web-console/notes/loop.md):
|
||||
// 1. the `open --loop` gate and the lock it stamps on a session,
|
||||
// 2. the `loopOutcome`, `loopEnd` and `handledBy` rules of the patch validator,
|
||||
// 3. the `loop-setup.json` store and its `/loop-setup` route.
|
||||
//
|
||||
// Shared setup (a per-process console home, the CLI runner, fixtures) lives in
|
||||
// web-console-test-helpers.mjs. Every child process here gets an explicit
|
||||
// environment with the desktop app's variables removed, so a test run from
|
||||
// inside the app behaves as one run from a terminal.
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { applyPatch, blankState, validate } from "../src/web-console/patches.mjs";
|
||||
import { ROOT, CONSOLE_CLI, ENV, HOME, cli, readState, sessionUrl, payload } from "./web-console-test-helpers.mjs";
|
||||
|
||||
const APP_VARS = ["PLAN2CODE_IN_APP", "PLAN2CODE_EMBED_ORIGIN", "PLAN2CODE_APP_ANNOUNCE", "PLAN2CODE_APP_TOKEN", "PLAN2CODE_CONSOLE_SID"];
|
||||
|
||||
// The console CLI with the app's variables gone, plus whatever `extra` sets.
|
||||
function run(args, { cwd = ROOT, extra = {} } = {}) {
|
||||
const env = { ...ENV };
|
||||
for (const key of APP_VARS) delete env[key];
|
||||
const res = spawnSync(process.execPath, [CONSOLE_CLI, ...args], { env: { ...env, ...extra }, encoding: "utf8", cwd });
|
||||
const line = String(res.stdout).trim().split("\n").filter((l) => l.startsWith("{")).pop();
|
||||
let json = null;
|
||||
try {
|
||||
json = line ? JSON.parse(line) : null;
|
||||
} catch {}
|
||||
return { status: res.status, stderr: String(res.stderr), stdout: String(res.stdout), json };
|
||||
}
|
||||
|
||||
const IN_APP = { PLAN2CODE_IN_APP: "1" };
|
||||
|
||||
const tempProject = (name) => fs.mkdtempSync(path.join(HOME, `${name}-`));
|
||||
const sessionsDir = path.join(HOME, "sessions");
|
||||
const sessionCount = () => (fs.existsSync(sessionsDir) ? fs.readdirSync(sessionsDir).length : 0);
|
||||
|
||||
// Opens a session in a fresh project; the caller stops it.
|
||||
function openLoop(workflow = "implement", name = "loop") {
|
||||
const cwd = tempProject(name);
|
||||
const res = run(["open", "--workflow", workflow, "--loop", "--no-open"], { cwd, extra: IN_APP });
|
||||
assert.equal(res.status, 0, res.stderr);
|
||||
const stop = () => cli(["stop", "--session", res.json.sid, "--force"], { cwd, expectFail: true });
|
||||
return { cwd, sid: res.json.sid, session: res.json.session, url: res.json.url, stop };
|
||||
}
|
||||
|
||||
const post = (s, obj) => run(["post", "--session", s.sid, "--file", payload(`loop-post-${Date.now()}-${Math.random().toString(16).slice(2)}.json`, obj)], { cwd: s.cwd });
|
||||
|
||||
/* ---------------------------------------------------------- 7.5: the gate */
|
||||
|
||||
test("open --loop is refused with one line and exit 3 when the desktop app's signal is unset", () => {
|
||||
const cwd = tempProject("gate-off");
|
||||
const before = sessionCount();
|
||||
for (const extra of [{}, { PLAN2CODE_IN_APP: "0" }]) {
|
||||
const res = run(["open", "--workflow", "implement", "--loop", "--no-open"], { cwd, extra });
|
||||
assert.equal(res.status, 3, `exit 3 with ${JSON.stringify(extra)}`);
|
||||
assert.equal(res.stderr.trim().split("\n").length, 1, "a one-line reason");
|
||||
assert.match(res.stderr, /Loop mode runs only inside the Plan2Code desktop app\./);
|
||||
assert.equal(res.stdout.trim(), "", "nothing is printed on stdout");
|
||||
}
|
||||
assert.equal(sessionCount(), before, "no session folder was made");
|
||||
});
|
||||
|
||||
test("open --loop under the app locks the session: loop { driving: true } in state.json", () => {
|
||||
for (const workflow of ["implement", "implement-review"]) {
|
||||
const s = openLoop(workflow, `gate-on-${workflow}`);
|
||||
try {
|
||||
const state = readState(s.session);
|
||||
assert.deepEqual(state.loop, { driving: true });
|
||||
assert.equal(state.workflow, workflow);
|
||||
assert.equal("loopOutcome" in state, false);
|
||||
assert.equal("loopEnd" in state, false);
|
||||
} finally {
|
||||
s.stop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("open --loop goes only with Implement or Implement + Review: any other workflow, or none, exits 2", () => {
|
||||
const cwd = tempProject("gate-wf");
|
||||
const before = sessionCount();
|
||||
for (const args of [["--workflow", "plan"], ["--workflow", "dashboard"], []]) {
|
||||
const res = run(["open", ...args, "--loop", "--no-open"], { cwd, extra: IN_APP });
|
||||
assert.equal(res.status, 2, `exit 2 for ${args.join(" ") || "no workflow"}`);
|
||||
assert.match(res.stderr, /--loop goes only with --workflow implement or --workflow implement-review/);
|
||||
}
|
||||
assert.equal(sessionCount(), before, "no session folder was made");
|
||||
});
|
||||
|
||||
test("a later open --resume without --loop clears the lock and the loop's cards; --loop locks it again", () => {
|
||||
const s = openLoop("implement", "resume");
|
||||
try {
|
||||
const card = {
|
||||
id: "fixes",
|
||||
kind: "multi",
|
||||
title: "Which to fix",
|
||||
options: [{ k: "1", text: "One" }, { k: "2", text: "Two" }],
|
||||
status: "answered",
|
||||
answer: { ks: ["1"] },
|
||||
handledBy: "loop",
|
||||
};
|
||||
const posted = post(s, { items: [card] });
|
||||
assert.equal(posted.status, 0, posted.stderr);
|
||||
assert.equal(readState(s.session).items[0].handledBy, "loop");
|
||||
|
||||
const plain = run(["open", "--resume", s.sid, "--no-open"], { cwd: s.cwd });
|
||||
assert.equal(plain.status, 0, plain.stderr);
|
||||
const unlocked = readState(s.session);
|
||||
assert.equal("loop" in unlocked, false, "the lock is gone");
|
||||
assert.equal(unlocked.items.length, 1, "the card stays as a record");
|
||||
assert.equal("handledBy" in unlocked.items[0], false, "but it is no longer the loop's");
|
||||
assert.equal(post(s, { agent: { status: "waiting" } }).status, 0, "the unlocked session takes an ordinary post");
|
||||
|
||||
const again = run(["open", "--resume", s.sid, "--workflow", "implement", "--loop", "--no-open"], { cwd: s.cwd, extra: IN_APP });
|
||||
assert.equal(again.status, 0, again.stderr);
|
||||
assert.deepEqual(readState(s.session).loop, { driving: true });
|
||||
} finally {
|
||||
s.stop();
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------- 7.6: loopOutcome, loopEnd, handledBy */
|
||||
|
||||
// A loop session's state, with the patch applied as `post` would: applyPatch
|
||||
// may throw (who may send it, how often), then validate() lists the rest.
|
||||
const loopState = (extra = {}) => ({ ...blankState({ sid: "s", workflow: "implement", project: "p" }), loop: { driving: true }, ...extra });
|
||||
function tryPatch(state, patch) {
|
||||
let next;
|
||||
try {
|
||||
next = applyPatch(state, patch);
|
||||
} catch (e) {
|
||||
return { next: null, problems: [e.message] };
|
||||
}
|
||||
return { next, problems: validate(next) };
|
||||
}
|
||||
|
||||
const goodOutcome = () => ({
|
||||
phase: 2,
|
||||
result: "passed",
|
||||
reason: null,
|
||||
summary: "Built the setup screen; 6 of 6 tasks",
|
||||
tests: { ran: true, passed: true, summary: "14 pass" },
|
||||
review: {
|
||||
ran: true,
|
||||
recheck: true,
|
||||
left: { critical: 0, warning: 0, suggestion: 2 },
|
||||
fixed: [{ level: "warning", title: "Close the file handle", file: "src/z.js" }],
|
||||
unfixed: [{ level: "suggestion", title: "Name the timer", file: "src/x.js" }],
|
||||
},
|
||||
tasks: { blocked: [], assumed: ["2.4"] },
|
||||
conflicts: [],
|
||||
decisions: ["Kept the old route so existing callers still work"],
|
||||
subject: "Add the loop setup screen",
|
||||
});
|
||||
const withTriage = (skipped) => {
|
||||
const o = goodOutcome();
|
||||
o.review.triage = { ran: true, skipped };
|
||||
return o;
|
||||
};
|
||||
const skip = (extra = {}) => ({ level: "warning", title: "Rename the helper", file: "src/y.js", reason: "Outside this phase's tasks", ...extra });
|
||||
|
||||
test("a valid loopOutcome is stored in a loop session, with and without a triage block", () => {
|
||||
const plain = tryPatch(loopState(), { loopOutcome: goodOutcome() });
|
||||
assert.deepEqual(plain.problems, []);
|
||||
assert.deepEqual(plain.next.loopOutcome, goodOutcome());
|
||||
|
||||
const triaged = tryPatch(loopState(), { loopOutcome: withTriage([skip(), skip({ level: "suggestion", title: "Name the timer" })]) });
|
||||
assert.deepEqual(triaged.problems, []);
|
||||
assert.equal(triaged.next.loopOutcome.review.triage.skipped.length, 2);
|
||||
|
||||
const empty = tryPatch(loopState(), { loopOutcome: withTriage([]) });
|
||||
assert.deepEqual(empty.problems, [], "a triage that skipped nothing is a valid, empty list");
|
||||
|
||||
const failed = goodOutcome();
|
||||
Object.assign(failed, { result: "failed", reason: "tests" });
|
||||
assert.deepEqual(tryPatch(loopState(), { loopOutcome: failed }).problems, [], "a failed outcome carries a reason");
|
||||
});
|
||||
|
||||
test("each bad loopOutcome field is refused with a message naming it", () => {
|
||||
const cases = [
|
||||
["a bad result", (o) => (o.result = "done"), /loopOutcome\.result must be/],
|
||||
["a reason on a passed outcome", (o) => (o.reason = "tests"), /loopOutcome\.reason must be null when the phase passed/],
|
||||
["a failed outcome with no reason", (o) => Object.assign(o, { result: "failed", reason: null }), /loopOutcome\.reason must be one of/],
|
||||
["a failed outcome with an unknown reason", (o) => Object.assign(o, { result: "failed", reason: "sulking" }), /loopOutcome\.reason must be one of/],
|
||||
["a negative left.warning", (o) => (o.review.left.warning = -1), /loopOutcome\.review\.left\.warning must be a non-negative integer/],
|
||||
["a fractional left.critical", (o) => (o.review.left.critical = 1.5), /loopOutcome\.review\.left\.critical must be a non-negative integer/],
|
||||
[
|
||||
"51 unfixed entries",
|
||||
(o) => (o.review.unfixed = Array.from({ length: 51 }, (_, i) => ({ level: "suggestion", title: `Finding ${i}` }))),
|
||||
/loopOutcome\.review\.unfixed can hold at most 50 entries/,
|
||||
],
|
||||
["no fixed list", (o) => delete o.review.fixed, /loopOutcome\.review\.fixed must be an array/],
|
||||
["a fixed entry at an unknown level", (o) => (o.review.fixed[0].level = "nit"), /loopOutcome\.review\.fixed\[0\]\.level must be one of/],
|
||||
["a fixed entry with no title", (o) => (o.review.fixed[0].title = " "), /loopOutcome\.review\.fixed\[0\]\.title must be a non-empty one-line string/],
|
||||
["51 fixed entries", (o) => (o.review.fixed = Array.from({ length: 51 }, (_, i) => ({ level: "suggestion", title: `Finding ${i}` }))), /loopOutcome\.review\.fixed can hold at most 50 entries/],
|
||||
["no decisions list", (o) => delete o.decisions, /loopOutcome\.decisions must be an array/],
|
||||
["a two-line decision", (o) => (o.decisions = ["one\ntwo"]), /loopOutcome\.decisions\[0\] must be one line of 1 to 200 characters/],
|
||||
["a 201-character decision", (o) => (o.decisions = ["x".repeat(201)]), /loopOutcome\.decisions\[0\] must be one line/],
|
||||
["51 decisions", (o) => (o.decisions = Array.from({ length: 51 }, (_, i) => `Decision ${i}`)), /loopOutcome\.decisions can hold at most 50 entries/],
|
||||
["an unfixed entry at an unknown level", (o) => (o.review.unfixed[0].level = "nit"), /loopOutcome\.review\.unfixed\[0\]\.level must be one of/],
|
||||
["a two-line subject", (o) => (o.subject = "Add the screen\nand more"), /loopOutcome\.subject must be one line of 1 to 100 characters/],
|
||||
["a 101-character subject", (o) => (o.subject = "a".repeat(101)), /loopOutcome\.subject must be one line of 1 to 100 characters/],
|
||||
["an empty subject", (o) => (o.subject = ""), /loopOutcome\.subject must be one line/],
|
||||
["a forbidden completion marker in the summary", (o) => (o.summary = "All done, PHASE_COMPLETE"), /loopOutcome\.summary: contains a loop completion marker \(PHASE_COMPLETE\)/],
|
||||
["a task id that is not like 2.4", (o) => (o.tasks.assumed = ["two"]), /loopOutcome\.tasks\.assumed must be an array of task ids/],
|
||||
["a missing tests object", (o) => delete o.tests, /loopOutcome\.tests must be an object/],
|
||||
["a non-integer phase", (o) => (o.phase = 0), /loopOutcome\.phase must be a positive integer/],
|
||||
["a triage skip at a bad level", (o) => (o.review.triage = { ran: true, skipped: [skip({ level: "major" })] }), /loopOutcome\.review\.triage\.skipped\[0\]\.level must be one of/],
|
||||
["a triage skip with no reason", (o) => (o.review.triage = { ran: true, skipped: [skip({ reason: undefined })] }), /loopOutcome\.review\.triage\.skipped\[0\]\.reason must be one line of 1 to 200/],
|
||||
["a 201-character triage reason", (o) => (o.review.triage = { ran: true, skipped: [skip({ reason: "r".repeat(201) })] }), /loopOutcome\.review\.triage\.skipped\[0\]\.reason must be one line of 1 to 200/],
|
||||
[
|
||||
"51 triage skips",
|
||||
(o) => (o.review.triage = { ran: true, skipped: Array.from({ length: 51 }, (_, i) => skip({ title: `Finding ${i}` })) }),
|
||||
/loopOutcome\.review\.triage\.skipped can hold at most 50 entries/,
|
||||
],
|
||||
["a triage with no ran flag", (o) => (o.review.triage = { skipped: [] }), /loopOutcome\.review\.triage\.ran must be true or false/],
|
||||
["a triage that is not an object", (o) => (o.review.triage = "yes"), /loopOutcome\.review\.triage must be an object/],
|
||||
];
|
||||
for (const [what, mutate, expected] of cases) {
|
||||
const outcome = goodOutcome();
|
||||
mutate(outcome);
|
||||
const { problems } = tryPatch(loopState(), { loopOutcome: outcome });
|
||||
assert.ok(problems.some((p) => expected.test(p)), `${what}: expected ${expected}, got ${JSON.stringify(problems)}`);
|
||||
}
|
||||
|
||||
// The boundaries themselves are fine.
|
||||
const edge = goodOutcome();
|
||||
edge.subject = "a".repeat(100);
|
||||
edge.review.unfixed = Array.from({ length: 50 }, (_, i) => ({ level: "suggestion", title: `Finding ${i}` }));
|
||||
edge.review.triage = { ran: true, skipped: Array.from({ length: 50 }, (_, i) => skip({ title: `Finding ${i}`, reason: "r".repeat(200) })) };
|
||||
assert.deepEqual(tryPatch(loopState(), { loopOutcome: edge }).problems, [], "100 characters, 50 entries and 200 characters are the limits, not over them");
|
||||
});
|
||||
|
||||
test("loopOutcome is refused outside a loop session and a second time", () => {
|
||||
const unlocked = loopState();
|
||||
delete unlocked.loop;
|
||||
assert.match(tryPatch(unlocked, { loopOutcome: goodOutcome() }).problems.join("\n"), /loopOutcome: is only accepted in a loop session/);
|
||||
|
||||
const first = tryPatch(loopState(), { loopOutcome: goodOutcome() });
|
||||
assert.deepEqual(first.problems, []);
|
||||
const second = tryPatch(first.next, { loopOutcome: goodOutcome() });
|
||||
assert.match(second.problems.join("\n"), /loopOutcome: was already posted for this session/);
|
||||
assert.deepEqual(tryPatch(first.next, { agent: { status: "waiting" } }).problems, [], "the stored outcome does not block later posts");
|
||||
|
||||
assert.match(tryPatch(loopState(), { loop: { driving: true } }).problems.join("\n"), /loop: is set by open --loop, not by a patch/, "a patch cannot lock a session itself");
|
||||
});
|
||||
|
||||
test("a loopOutcome through post is stored in state.json, and refused with exit 3 and the field named", () => {
|
||||
const s = openLoop("implement-review", "outcome-post");
|
||||
try {
|
||||
const bad = goodOutcome();
|
||||
bad.subject = "a".repeat(101);
|
||||
const refused = post(s, { loopOutcome: bad });
|
||||
assert.equal(refused.status, 3);
|
||||
assert.match(refused.stderr, /loopOutcome\.subject must be one line of 1 to 100 characters/);
|
||||
assert.equal("loopOutcome" in readState(s.session), false, "nothing was written");
|
||||
|
||||
const stored = post(s, { loopOutcome: withTriage([skip()]) });
|
||||
assert.equal(stored.status, 0, stored.stderr);
|
||||
assert.deepEqual(readState(s.session).loopOutcome, withTriage([skip()]));
|
||||
|
||||
const again = post(s, { loopOutcome: goodOutcome() });
|
||||
assert.equal(again.status, 3);
|
||||
assert.match(again.stderr, /already posted/);
|
||||
} finally {
|
||||
s.stop();
|
||||
}
|
||||
});
|
||||
|
||||
test("a loopOutcome through post is refused outside a loop session", () => {
|
||||
const cwd = tempProject("outcome-plain");
|
||||
const opened = run(["open", "--workflow", "implement", "--no-open"], { cwd });
|
||||
assert.equal(opened.status, 0, opened.stderr);
|
||||
try {
|
||||
const res = post({ sid: opened.json.sid, cwd }, { loopOutcome: goodOutcome() });
|
||||
assert.equal(res.status, 3);
|
||||
assert.match(res.stderr, /loopOutcome: is only accepted in a loop session/);
|
||||
} finally {
|
||||
cli(["stop", "--session", opened.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
|
||||
const goodEnd = (extra = {}) => ({
|
||||
kind: "stopped",
|
||||
line: "Stopped at phase 2: a Critical finding was skipped",
|
||||
phases: [{ n: 1, name: "Setup", commit: "abc1234", unfixed: 0, retries: 0 }],
|
||||
uncommitted: ["src/x.js"],
|
||||
can: ["resume", "fix"],
|
||||
...extra,
|
||||
});
|
||||
const EVIDENCE = { id: "evidence", title: "What happened", blocks: [{ id: "b1", md: "The phase stopped on a skipped Critical." }] };
|
||||
|
||||
test("loopEnd: a valid stopped with an evidence doc in the same patch is stored", () => {
|
||||
const withDoc = tryPatch(loopState(), { docs: [EVIDENCE], loopEnd: goodEnd({ evidence: "evidence" }) });
|
||||
assert.deepEqual(withDoc.problems, []);
|
||||
assert.equal(withDoc.next.loopEnd.evidence, "evidence");
|
||||
assert.equal(withDoc.next.docs[0].id, "evidence");
|
||||
|
||||
const finished = tryPatch(loopState(), { loopEnd: goodEnd({ kind: "finished", can: ["finalize"] }) });
|
||||
assert.deepEqual(finished.problems, [], "evidence is optional");
|
||||
|
||||
const replaced = tryPatch(withDoc.next, { loopEnd: goodEnd({ line: "A later word replaces the earlier" }) });
|
||||
assert.deepEqual(replaced.problems, [], "a later loopEnd replaces the earlier");
|
||||
assert.equal(replaced.next.loopEnd.line, "A later word replaces the earlier");
|
||||
});
|
||||
|
||||
test("loopEnd: an unknown evidence id, a push in can, and the other bad fields are refused, each named", () => {
|
||||
const cases = [
|
||||
["an unknown evidence id", goodEnd({ evidence: "nope" }), /loopEnd\.evidence must be the id of a doc on the page/],
|
||||
["a push in can", goodEnd({ can: ["resume", "push"] }), /loopEnd\.can must be an array with entries from resume, fix, finalize/],
|
||||
["a bad kind", goodEnd({ kind: "paused" }), /loopEnd\.kind must be "stopped" or "finished"/],
|
||||
["a two-line line", goodEnd({ line: "one\ntwo" }), /loopEnd\.line must be one line/],
|
||||
["an absolute uncommitted path", goodEnd({ uncommitted: ["/etc/passwd"] }), /loopEnd\.uncommitted must be an array of relative paths/],
|
||||
["an uncommitted path that climbs out", goodEnd({ uncommitted: ["../x"] }), /loopEnd\.uncommitted must be an array of relative paths/],
|
||||
["a bad decision count", goodEnd({ phases: [{ n: 1, name: "Setup", commit: "abc1234", unfixed: 0, retries: 0, assumed: -1 }] }), /loopEnd\.phases\[0\]\.assumed must be a non-negative integer/],
|
||||
["a bad commit hash", goodEnd({ phases: [{ n: 1, name: "Setup", commit: "zzz", unfixed: 0, retries: 0 }] }), /loopEnd\.phases\[0\]\.commit must be a short hex hash or null/],
|
||||
["a forbidden completion marker in line", goodEnd({ line: "TASK_COMPLETE" }), /loopEnd\.line: contains a loop completion marker/],
|
||||
];
|
||||
for (const [what, end, expected] of cases) {
|
||||
const { problems } = tryPatch(loopState(), { loopEnd: end });
|
||||
assert.ok(problems.some((p) => expected.test(p)), `${what}: expected ${expected}, got ${JSON.stringify(problems)}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("handledBy: \"loop\" is accepted in a loop session and refused outside one or with any other value", () => {
|
||||
const card = (extra = {}) => ({
|
||||
id: "fixes",
|
||||
kind: "multi",
|
||||
title: "Which to fix",
|
||||
options: [{ k: "1", text: "One" }, { k: "2", text: "Two" }],
|
||||
status: "answered",
|
||||
answer: { ks: ["1"] },
|
||||
handledBy: "loop",
|
||||
...extra,
|
||||
});
|
||||
const ok = tryPatch(loopState(), { items: [card()] });
|
||||
assert.deepEqual(ok.problems, []);
|
||||
assert.equal(ok.next.items[0].handledBy, "loop");
|
||||
|
||||
const unlocked = loopState();
|
||||
delete unlocked.loop;
|
||||
const outside = tryPatch(unlocked, { items: [card()] });
|
||||
assert.ok(outside.problems.some((p) => /item "fixes" handledBy: is only valid in a loop session/.test(p)), JSON.stringify(outside.problems));
|
||||
|
||||
const other = tryPatch(loopState(), { items: [card({ handledBy: "app" })] });
|
||||
assert.ok(other.problems.some((p) => /item "fixes" handledBy: can only be "loop"/.test(p)), JSON.stringify(other.problems));
|
||||
|
||||
assert.deepEqual(tryPatch(unlocked, { items: [card({ handledBy: undefined })] }).problems, [], "no handledBy is an ordinary card anywhere");
|
||||
});
|
||||
|
||||
/* ------------------------------------ 7.7: the loop-setup.json store, routes */
|
||||
|
||||
const LOOP_SETUP_PATH = path.join(HOME, "loop-setup.json");
|
||||
const LOOP_SETUP_URL = pathToFileURL(path.join(ROOT, "src", "web-console", "loop-setup.mjs")).href;
|
||||
|
||||
// Runs `fn(m, args)` in a child process with this file's console home, where m
|
||||
// is loop-setup.mjs. The module fixes its file at import time from
|
||||
// PLAN2CODE_CONSOLE_HOME, which this process cannot set early enough. `fn`
|
||||
// must be self-contained: it is sent as source text. Returns its JSON result.
|
||||
function inStore(fn, args = {}) {
|
||||
const env = { ...ENV };
|
||||
for (const key of APP_VARS) delete env[key];
|
||||
const code =
|
||||
`const m = await import(${JSON.stringify(LOOP_SETUP_URL)});` +
|
||||
`const out = await (${fn.toString()})(m, ${JSON.stringify(args)});` +
|
||||
"console.log(JSON.stringify(out));";
|
||||
const res = spawnSync(process.execPath, ["--input-type=module", "-e", code], { env, encoding: "utf8", cwd: ROOT });
|
||||
assert.equal(res.status, 0, res.stderr);
|
||||
return JSON.parse(String(res.stdout).trim().split("\n").pop());
|
||||
}
|
||||
|
||||
const projectA = path.join(HOME, "store-project-a");
|
||||
const projectB = path.join(HOME, "store-project-b");
|
||||
|
||||
test("loop-setup: a new project reads as the defaults with remembered false, and nothing is written", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore((m, { project }) => ({ setup: m.readLoopSetup(project), defaults: m.LOOP_DEFAULTS }), { project: projectA });
|
||||
assert.deepEqual(got.setup, { ...got.defaults, remembered: false });
|
||||
assert.equal(got.setup.fixMode, "smart");
|
||||
assert.equal(got.setup.onQuestion, "guess");
|
||||
assert.deepEqual(got.setup.fix, ["critical", "warning", "suggestion"]);
|
||||
assert.equal(got.setup.silenceMinutes, 20);
|
||||
assert.equal(got.setup.notifyUrl, "", "no web address is called by default");
|
||||
assert.equal(got.setup.notifyKind, "query");
|
||||
assert.equal(got.setup.notifyParam, "message");
|
||||
assert.equal(fs.existsSync(LOOP_SETUP_PATH), false, "reading never creates the file");
|
||||
});
|
||||
|
||||
test("loop-setup: a save reads back per project, keeps another project's entry, and smart round-trips", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const saved = inStore(
|
||||
(m, { a, b }) => {
|
||||
const base = { ...m.LOOP_DEFAULTS, fix: [...m.LOOP_DEFAULTS.fix] };
|
||||
const forA = { ...base, fixMode: "levels", review: false, fix: ["critical"], onQuestion: "guess", quickCheck: "npm run build", silenceMinutes: 7 };
|
||||
const forB = { ...base, fixMode: "smart", afterLast: "run-finalize", retryOnce: false };
|
||||
m.saveLoopSetup(a, forA);
|
||||
const returnedB = m.saveLoopSetup(b, forB);
|
||||
return { forA, forB, returnedB, readA: m.readLoopSetup(a), readB: m.readLoopSetup(b), readC: m.readLoopSetup(a + "-other") };
|
||||
},
|
||||
{ a: projectA, b: projectB }
|
||||
);
|
||||
// A read also carries the save time.
|
||||
const { saved: savedA, ...readA } = saved.readA;
|
||||
const { saved: savedB, ...readB } = saved.readB;
|
||||
assert.match(savedA, /^\d{4}-\d{2}-\d{2}T/);
|
||||
assert.match(savedB, /^\d{4}-\d{2}-\d{2}T/);
|
||||
assert.deepEqual(readA, { ...saved.forA, remembered: true });
|
||||
assert.deepEqual(readB, { ...saved.forB, remembered: true });
|
||||
assert.equal(saved.readB.fixMode, "smart", "smart round-trips");
|
||||
assert.equal(saved.readA.fixMode, "levels");
|
||||
assert.deepEqual(saved.returnedB, saved.readB, "a save returns what a read gives");
|
||||
assert.equal(saved.readC.remembered, false, "an unsaved project still reads as new");
|
||||
|
||||
const file = JSON.parse(fs.readFileSync(LOOP_SETUP_PATH, "utf8"));
|
||||
assert.equal(file.schema, 1);
|
||||
assert.equal(Object.keys(file.projects).length, 2, "one entry per project");
|
||||
for (const entry of Object.values(file.projects)) assert.match(entry.saved, /^\d{4}-\d{2}-\d{2}T/);
|
||||
|
||||
// A second save for A replaces A's entry and leaves B's alone.
|
||||
const again = inStore(
|
||||
(m, { a, b }) => {
|
||||
const { saved, remembered, ...entry } = m.readLoopSetup(a);
|
||||
m.saveLoopSetup(a, { ...entry, fixMode: "smart" });
|
||||
return { a: m.readLoopSetup(a), b: m.readLoopSetup(b) };
|
||||
},
|
||||
{ a: projectA, b: projectB }
|
||||
);
|
||||
assert.equal(again.a.fixMode, "smart");
|
||||
assert.equal(again.a.quickCheck, "npm run build", "the rest of A's entry is as saved");
|
||||
assert.deepEqual(again.b, saved.readB, "B is untouched");
|
||||
});
|
||||
|
||||
|
||||
const WORKSPACE_URL = pathToFileURL(path.join(ROOT, "src", "web-console", "workspace.mjs")).href;
|
||||
|
||||
test("loop-setup: an entry saved before fixMode existed reads as levels", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore(
|
||||
async (m, { project, workspace }) => {
|
||||
const fs = await import("node:fs");
|
||||
const { foldKey } = await import(workspace);
|
||||
const { fixMode, ...legacy } = { ...m.LOOP_DEFAULTS, fix: ["warning"], saved: "2026-01-01T00:00:00.000Z" };
|
||||
fs.writeFileSync(m.LOOP_SETUP_FILE, JSON.stringify({ schema: 1, projects: { [foldKey(project)]: legacy } }));
|
||||
const stored = JSON.parse(fs.readFileSync(m.LOOP_SETUP_FILE, "utf8")).projects[foldKey(project)];
|
||||
return { read: m.readLoopSetup(project), onDisk: "fixMode" in stored };
|
||||
},
|
||||
{ project: projectA, workspace: WORKSPACE_URL }
|
||||
);
|
||||
assert.equal(got.onDisk, false, "the stored entry has no fixMode");
|
||||
assert.equal(got.read.remembered, true);
|
||||
assert.equal(got.read.fixMode, "levels", "an older entry keeps fixing by level, not the new default");
|
||||
assert.deepEqual(got.read.fix, ["warning"], "the saved fields are kept");
|
||||
});
|
||||
|
||||
test("loop-setup: good web addresses save, with a bad name allowed only while no address is set", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore(
|
||||
(m, { project }) => {
|
||||
const base = { ...m.LOOP_DEFAULTS, fix: [...m.LOOP_DEFAULTS.fix] };
|
||||
const good = ["http://example.com", "https://example.com/hook?x=1#top", "HTTPS://EXAMPLE.COM/a%20b", "http://127.0.0.1:8080/"].map((notifyUrl) => m.saveLoopSetup(project, { ...base, notifyUrl, notifyParam: "msg_1.a-b~c" }).notifyUrl);
|
||||
const hidden = m.saveLoopSetup(project, { ...base, notifyUrl: "", notifyParam: "a b" });
|
||||
const kinds = ["discord", "slack", "teams", "google-chat"].map((notifyKind) => m.saveLoopSetup(project, { ...base, notifyKind, notifyUrl: "https://example.com/x", notifyParam: "a b" }).notifyKind);
|
||||
return { good, hidden, kinds };
|
||||
},
|
||||
{ project: projectA }
|
||||
);
|
||||
assert.equal(got.good.length, 4);
|
||||
assert.equal(got.hidden.notifyUrl, "");
|
||||
assert.deepEqual(got.kinds, ["discord", "slack", "teams", "google-chat"], "a chat service ignores the hidden name");
|
||||
});
|
||||
|
||||
test("loop-setup: a bad field throws with the problem named and leaves the file unchanged", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const cases = [
|
||||
["silenceMinutes: 0", { silenceMinutes: 0 }, /"silenceMinutes" must be a whole number from 1 to 60/],
|
||||
["silenceMinutes: 61", { silenceMinutes: 61 }, /"silenceMinutes"/],
|
||||
...["example.com", "ftp://example.com", "javascript:alert(1)", "https:/example.com", "https://", "https://me:secret@example.com/", "https://exa mple.com", "https://example.com/é", "https://example.com/\nx", `https://e.com/${"x".repeat(2000)}`].map((notifyUrl) => [`notifyUrl: ${notifyUrl.slice(0, 30)}`, { notifyUrl }, /"notifyUrl" must be an http or https web address/]),
|
||||
["notifyUrl as a number", { notifyUrl: 5 }, /"notifyUrl"/],
|
||||
["notifyKind: carrier-pigeon", { notifyKind: "carrier-pigeon" }, /"notifyKind" must be one of query, discord, slack, teams, google-chat, json/],
|
||||
["a JSON field name with a space", { notifyKind: "json", notifyUrl: "https://example.com/", notifyParam: "a b" }, /"notifyParam"/],
|
||||
...["", "a b", "a=b", "a&b", "a%20b", "é", "x".repeat(65)].map((notifyParam) => [`notifyParam: ${notifyParam.slice(0, 10)}`, { notifyUrl: "https://example.com/", notifyParam }, /"notifyParam" must be 1 to 64 letters/]),
|
||||
["onQuestion: later", { onQuestion: "later" }, /"onQuestion" must be one of pause, stop, guess/],
|
||||
["an unknown key", { surprise: true }, /"surprise" is not a setup field/],
|
||||
["a two-line quickCheck", { quickCheck: "npm run build\nrm -rf x" }, /"quickCheck" must be one line of at most 500 characters/],
|
||||
["a 501-character quickCheck", { quickCheck: "x".repeat(501) }, /"quickCheck"/],
|
||||
["fixMode: sometimes", { fixMode: "sometimes" }, /"fixMode" must be one of levels, smart/],
|
||||
["a repeated fix level", { fix: ["critical", "critical"] }, /"fix" must list distinct levels/],
|
||||
["review as a string", { review: "yes" }, /"review" must be true or false/],
|
||||
["afterLast: never", { afterLast: "never" }, /"afterLast" must be one of offer-finalize, run-finalize/],
|
||||
];
|
||||
|
||||
const attempt = () =>
|
||||
inStore(
|
||||
(m, { project, list }) =>
|
||||
list.map(([what, change]) => {
|
||||
try {
|
||||
m.saveLoopSetup(project, { ...m.LOOP_DEFAULTS, fix: [...m.LOOP_DEFAULTS.fix], ...change });
|
||||
return { what, threw: false };
|
||||
} catch (e) {
|
||||
return { what, threw: true, message: e.message, problems: e.problems };
|
||||
}
|
||||
}),
|
||||
{ project: projectA, list: cases.map(([what, change]) => [what, change]) }
|
||||
);
|
||||
const check = (results) => {
|
||||
for (const [i, [what, , expected]] of cases.entries()) {
|
||||
assert.equal(results[i].threw, true, `${what} is refused`);
|
||||
assert.match(results[i].message, /^the loop setup is not valid: /);
|
||||
assert.match(results[i].message, expected, what);
|
||||
assert.ok(Array.isArray(results[i].problems) && results[i].problems.length >= 1);
|
||||
}
|
||||
};
|
||||
|
||||
// First with no file at all: a refusal must not create one.
|
||||
check(attempt());
|
||||
assert.equal(fs.existsSync(LOOP_SETUP_PATH), false, "no file was created by a refused save");
|
||||
|
||||
// Then with a good entry on file: the bytes stay as they were.
|
||||
inStore((m, { project }) => m.saveLoopSetup(project, { ...m.LOOP_DEFAULTS, fix: ["warning"], quickCheck: "npm run lint" }), { project: projectA });
|
||||
const before = fs.readFileSync(LOOP_SETUP_PATH, "utf8");
|
||||
check(attempt());
|
||||
assert.equal(fs.readFileSync(LOOP_SETUP_PATH, "utf8"), before, "the file is byte for byte unchanged");
|
||||
|
||||
// A non-object and a partial entry are refused too.
|
||||
const odd = inStore(
|
||||
(m, { project }) =>
|
||||
[null, [], "x", { review: true }].map((entry) => {
|
||||
try {
|
||||
m.saveLoopSetup(project, entry);
|
||||
return { threw: false };
|
||||
} catch (e) {
|
||||
return { threw: true, message: e.message };
|
||||
}
|
||||
}),
|
||||
{ project: projectA }
|
||||
);
|
||||
assert.ok(odd.every((r) => r.threw), "a non-object or a partial entry is refused");
|
||||
assert.match(odd[0].message, /must be an object/);
|
||||
assert.match(odd[3].message, /"fixMode" must be one of/);
|
||||
assert.equal(fs.readFileSync(LOOP_SETUP_PATH, "utf8"), before);
|
||||
});
|
||||
|
||||
test("loop-setup: GET /loop-setup lists the phases left for a spec and refuses anything but specs/<name>", async () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const cwd = tempProject("route");
|
||||
fs.mkdirSync(path.join(cwd, "specs", "demo"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(cwd, "specs", "demo", "overview.md"),
|
||||
[
|
||||
"# Demo",
|
||||
"",
|
||||
"## Phase Checklist",
|
||||
"",
|
||||
"- [x] **Phase 1:** Setup - [phase-1.md](phase-1.md)",
|
||||
"- [ ] **Phase 2:** Build the screen - [phase-2.md](phase-2.md)",
|
||||
"- [/] **Phase 3:** Ship it - [phase-3.md](phase-3.md)",
|
||||
"",
|
||||
"## Notes",
|
||||
"",
|
||||
"- [ ] Phase 9: not in the checklist",
|
||||
"",
|
||||
].join("\n")
|
||||
);
|
||||
fs.mkdirSync(path.join(cwd, "specs", "empty"), { recursive: true });
|
||||
fs.writeFileSync(path.join(cwd, "package.json"), JSON.stringify({ scripts: { build: "tsc", lint: "eslint ." } }));
|
||||
|
||||
const opened = run(["open", "--workflow", "implement", "--no-open"], { cwd });
|
||||
assert.equal(opened.status, 0, opened.stderr);
|
||||
const { base, cookie } = sessionUrl(opened.json.url);
|
||||
const get = async (query) => {
|
||||
const res = await fetch(`${base}/loop-setup${query}`, { headers: { cookie, connection: "close" } });
|
||||
return { status: res.status, body: await res.json() };
|
||||
};
|
||||
const send = (body) =>
|
||||
fetch(`${base}/loop-setup`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json", cookie, origin: base, connection: "close" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
try {
|
||||
const bare = await get("");
|
||||
assert.equal(bare.status, 200);
|
||||
assert.equal(bare.body.remembered, false);
|
||||
assert.equal(bare.body.fixMode, "smart");
|
||||
assert.equal("phasesLeft" in bare.body, false, "without a spec, only the setup");
|
||||
|
||||
const demo = await get("?spec=specs/demo");
|
||||
assert.equal(demo.status, 200);
|
||||
assert.deepEqual(demo.body.phasesLeft, [{ n: 2, name: "Build the screen" }, { n: 3, name: "Ship it" }]);
|
||||
assert.equal(demo.body.suggestedQuickCheck, "npm run build");
|
||||
assert.equal(demo.body.remembered, false);
|
||||
|
||||
assert.deepEqual((await get("?spec=specs/empty")).body.phasesLeft, [], "no overview.md, nothing to build");
|
||||
assert.deepEqual((await get("?spec=specs/missing")).body.phasesLeft, []);
|
||||
|
||||
for (const spec of ["../x", "specs/../x", "specs/a/b", "specs/.hidden", "/etc", "specs", "specs/", "specs%2F..%2Fx"]) {
|
||||
const refused = await get(`?spec=${spec}`);
|
||||
assert.equal(refused.status, 400, `spec=${spec} is refused`);
|
||||
assert.match(refused.body.error, /spec must be a folder directly under specs\//);
|
||||
}
|
||||
|
||||
// Saving through the route, then reading it back in a new request.
|
||||
const save = await send({ review: true, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "stop", afterLast: "offer-finalize", quickCheck: "", notifyKind: "query", notifyUrl: "https://example.com/hook", notifyParam: "msg", retryOnce: true, silenceMinutes: 30 });
|
||||
assert.equal(save.status, 200, await save.clone().text());
|
||||
const after = await get("?spec=specs/demo");
|
||||
assert.equal(after.body.remembered, true);
|
||||
assert.equal(after.body.fixMode, "smart");
|
||||
assert.equal(after.body.silenceMinutes, 30);
|
||||
assert.equal(after.body.notifyUrl, "https://example.com/hook");
|
||||
assert.equal(after.body.notifyParam, "msg");
|
||||
|
||||
const refusedSave = await send({ silenceMinutes: 0 });
|
||||
assert.equal(refusedSave.status, 400);
|
||||
assert.ok((await refusedSave.json()).problems.some((p) => /"silenceMinutes"/.test(p)));
|
||||
assert.equal((await get("")).body.silenceMinutes, 30, "a refused save changed nothing");
|
||||
} finally {
|
||||
cli(["stop", "--session", opened.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
@@ -779,7 +779,7 @@ test("two folders get two notepads through their own sessions", async (t) => {
|
||||
// live process sits in: stop both, and wait until neither answers, before
|
||||
// cleaning up (stop returns before the process has gone).
|
||||
t.after(async () => {
|
||||
for (const [cwd, sid] of sids) cliIn(cwd, ["stop", "--session", sid]);
|
||||
for (const [cwd, sid] of sids) cliIn(cwd, ["stop", "--session", sid, "--force"]);
|
||||
const gone = async ({ base }) => {
|
||||
try {
|
||||
await fetch(`${base}/health`, { signal: AbortSignal.timeout(1000) });
|
||||
@@ -1204,7 +1204,7 @@ test("the sweeps at open leave a 60-day-old notepad untouched", async () => {
|
||||
assert.equal(readNotepad(folder).text, "kept for months");
|
||||
assert.equal(readNotepad(folder).images.length, 1);
|
||||
assert.equal(fs.statSync(noteFile).mtimeMs, before, "not even touched");
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
removeNotepad(notepadKey(folder));
|
||||
});
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { pageSuite, openSession, itemCard, textOf } from "./page-test-helpers.mjs";
|
||||
import { reportedHelper } from "./web-console-test-helpers.mjs";
|
||||
import { readChat } from "../src/web-console/inbox.mjs";
|
||||
|
||||
const suite = pageSuite(test);
|
||||
|
||||
@@ -31,6 +32,13 @@ const PNG = Buffer.from(
|
||||
function collect(s) {
|
||||
const got = s.wait(10);
|
||||
assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code}): ${got.message || ""}`);
|
||||
// The wire hands over the Quick questions' seq numbers; the entries stay in the
|
||||
// session's chat log, so the tests read them from there.
|
||||
if (Array.isArray(got.chat)) {
|
||||
const seqs = new Set(got.chat);
|
||||
got.chat = readChat(s.session).filter((e) => seqs.has(e.seq));
|
||||
got.type ||= "chat";
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
@@ -65,7 +73,7 @@ test("a Quick question typed in Ask reaches the agent under chat, and the agent'
|
||||
const [asked, ...more] = messages(got);
|
||||
assert.equal(more.length, 0, "one question, one message");
|
||||
assert.equal(asked.text, "Where does the export live?");
|
||||
assert.match(got.reply, /^Quick question: Where does the export live\?$/m);
|
||||
assert.match(got.reply, /^Quick question \(\d+\): Where does the export live\?$/m);
|
||||
// The question is in the pane, and the box is empty for the next one.
|
||||
await s.page.locator(".ask-row.person").getByText("Where does the export live?").waitFor();
|
||||
assert.equal(await s.page.locator("#ask-input").inputValue(), "");
|
||||
|
||||
@@ -616,6 +616,27 @@ test("Something else in your own words replaces the pick, and picking an option
|
||||
assert.deepEqual(answerTo(got, "c1"), { text: "A shared drive" });
|
||||
});
|
||||
|
||||
// What a person sees break: a stray pick on a one-answer question can only be
|
||||
// swapped for another, never taken back, or Clear shows on a card already sent.
|
||||
test("Clear on a one-answer question takes back the pick and the words, and a sent card has no Clear", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
|
||||
const card = await ask(s, { id: "c1", kind: "choice", title: "Where", body: "Where?", options: [opt("A", "Email"), opt("B", "Slack")] });
|
||||
const clear = card.getByRole("button", { name: "Clear your answer to this question" });
|
||||
await card.getByRole("radio", { name: "Something else, in your own words" }).check();
|
||||
await card.locator("textarea.other-text").fill("A shared drive");
|
||||
await clear.click();
|
||||
await s.page.waitForFunction(() => !document.querySelector("#main .card.is-staged"));
|
||||
assert.equal(await card.locator("textarea.other-text").inputValue(), "", "the words go too");
|
||||
await card.getByLabel("Slack").check();
|
||||
await clear.click();
|
||||
await s.page.waitForFunction(() => !document.querySelector("#main .card.is-staged"));
|
||||
assert.equal(await card.locator("input[type=radio]:checked").count(), 0, "no pick is left");
|
||||
await card.getByLabel("Email").check();
|
||||
await s.page.click("#btn-send");
|
||||
await card.getByText(/Plan2Code is working on it|Waiting for Plan2Code to pick this up/).waitFor();
|
||||
assert.equal(await clear.count(), 0, "a sent card cannot be cleared");
|
||||
});
|
||||
|
||||
// What a person sees break: a note typed on a card is dropped by the verdict,
|
||||
// or is lost when the verdict comes first.
|
||||
test("a note's comment field rides along with the answer, typed before or after the pick", async (t) => {
|
||||
|
||||
@@ -207,6 +207,8 @@ const pickedChip = (main, name) => main.locator('button[aria-current="true"]', {
|
||||
test("picking Start from scratch instead of a spec grays Document, and a launch then carries no spec", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
||||
const main = await toTheMenu(s);
|
||||
// A grayed card has to show to be checked, whatever an earlier test left.
|
||||
await hideUnavailable(main, false);
|
||||
const document = lightOf(main, "/plan2code-2-document");
|
||||
await pickedChip(main, "demo").waitFor();
|
||||
assert.equal(await document.isEnabled(), true, "Document is lit for the drafted spec");
|
||||
|
||||
@@ -20,7 +20,7 @@ import { GONE_AFTER_MS } from "../src/web-console/public/screens/core.js";
|
||||
// The agent's side of `stop`, leaving the browser context open (s.stop()
|
||||
// closes it, which would hide what the page does next).
|
||||
async function stopServer(s) {
|
||||
cli(["stop", "--session", s.sid], { cwd: s.project });
|
||||
cli(["stop", "--session", s.sid, "--force"], { cwd: s.project });
|
||||
assert.ok(await until(async () => !(await s.answers()), 5000), "the server still answers after stop");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
// Page tests for the Implementation Loop's setup screen. The dashboard card
|
||||
// that opens it only shows inside the desktop app, so these open the screen
|
||||
// through its own module, then drive the real page. Run with:
|
||||
// node --test scripts/test-web-console-page-loop.mjs
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { pageSuite, openSession, tempProject, textOf } from "./page-test-helpers.mjs";
|
||||
|
||||
const suite = pageSuite(test);
|
||||
|
||||
const PROJECT = {
|
||||
"AGENTS.md": "# AGENTS.md\n\nA small demo project.\n",
|
||||
"specs/ready/overview.md": "# Overview\n\n## Phase Checklist\n\n- [ ] Phase 1: One\n- [ ] Phase 2: Two\n",
|
||||
"specs/ready/phase-1.md": "# Phase 1\n\n- [ ] **Task 1.1:** One\n",
|
||||
"specs/ready/phase-2.md": "# Phase 2\n\n- [ ] **Task 2.1:** Two\n",
|
||||
};
|
||||
|
||||
const MENU = { menu: { note: "Ready when you are." }, agent: { status: "waiting" } };
|
||||
|
||||
async function openSetup(t) {
|
||||
const browser = await suite.browser();
|
||||
const s = await openSession(browser, { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||||
// Past Planny's wake-up and, on a first run, the Welcome.
|
||||
const skip = s.page.getByRole("button", { name: "Skip the intro" });
|
||||
await skip.click();
|
||||
await skip.waitFor({ state: "hidden" });
|
||||
await s.page.locator("#main").getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
||||
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
|
||||
if (await welcomeDone.isVisible()) {
|
||||
await welcomeDone.click();
|
||||
await welcomeDone.waitFor({ state: "hidden" });
|
||||
}
|
||||
await s.page.evaluate(async () => {
|
||||
const m = await import(new URL("screens/loop-setup.js", document.baseURI).href);
|
||||
await m.openLoopSetup({ dir: "specs/ready" });
|
||||
});
|
||||
await s.page.locator("#loop-start").waitFor();
|
||||
return s;
|
||||
}
|
||||
|
||||
test("the setup lists each phase on its own line, in the agreed order of fields and radios", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const left = s.page.locator(".loop-fact dd").first();
|
||||
assert.equal(await textOf(left), "Phase 1: One\nPhase 2: Two");
|
||||
|
||||
const labels = await s.page.locator(".loop-label").allInnerTexts();
|
||||
assert.deepEqual(labels, [
|
||||
"Review",
|
||||
"Fix findings",
|
||||
"When a phase asks something",
|
||||
"After the last phase",
|
||||
"Send a notification",
|
||||
"Quick check",
|
||||
"If a phase crashes or goes quiet",
|
||||
"Commit",
|
||||
]);
|
||||
const radios = (name) => s.page.locator(`input[name="${name}"]`).evaluateAll((all) => all.map((r) => [r.id, r.checked]));
|
||||
assert.deepEqual(await radios("fixmode"), [["loop-fixmode-smart", true], ["loop-fixmode-levels", false]]);
|
||||
assert.deepEqual(await radios("onquestion"), [["loop-onquestion-guess", true], ["loop-onquestion-pause", false], ["loop-onquestion-stop", false]]);
|
||||
});
|
||||
|
||||
test("the web address field shows the name only beside an address, warns while typing and saves", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const url = s.page.locator("#loop-notify-url");
|
||||
const param = s.page.locator("#loop-notify-param");
|
||||
const warn = s.page.locator(".loop-field", { hasText: "Send a notification" }).locator(".loop-warn");
|
||||
|
||||
assert.equal(await url.inputValue(), "");
|
||||
assert.equal(await param.isVisible(), false, "no address, no name to set");
|
||||
assert.equal(await warn.isVisible(), false);
|
||||
|
||||
await url.fill("example.com");
|
||||
assert.match(await textOf(warn), /must start with http:\/\/ or https:\/\//);
|
||||
await url.fill("https://me:secret@example.com/");
|
||||
assert.match(await textOf(warn), /Leave out any user name or password/);
|
||||
await url.fill("https://example.com/hook?team=a");
|
||||
assert.equal(await warn.isVisible(), false);
|
||||
assert.equal(await param.isVisible(), true);
|
||||
assert.equal(await param.inputValue(), "message", "the default name");
|
||||
|
||||
await param.fill("a b");
|
||||
assert.match(await textOf(warn), /letters, digits/);
|
||||
await param.fill("msg");
|
||||
assert.equal(await warn.isVisible(), false);
|
||||
|
||||
// What Start would send; Start itself waits on facts only the app gives.
|
||||
const saved = await s.page.evaluate(async () => {
|
||||
const { page } = await import(new URL("state.js", document.baseURI).href);
|
||||
const res = await fetch("/loop-setup", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(page.loopSetup.form),
|
||||
});
|
||||
return { status: res.status, body: await res.json() };
|
||||
});
|
||||
assert.equal(saved.status, 200, JSON.stringify(saved.body));
|
||||
const reread = await s.page.evaluate(async () => (await fetch("/loop-setup")).json());
|
||||
assert.equal(reread.notifyUrl, "https://example.com/hook?team=a");
|
||||
assert.equal(reread.notifyParam, "msg");
|
||||
assert.equal(reread.remembered, true);
|
||||
});
|
||||
|
||||
// Stands a real window in for the app that frames the page, listening to what
|
||||
// the page tells it; `answer` then replies the way the app's window does.
|
||||
async function frameInFakeApp(s) {
|
||||
await s.page.evaluate(() => {
|
||||
const frame = document.createElement("iframe");
|
||||
frame.hidden = true;
|
||||
document.body.appendChild(frame);
|
||||
const app = frame.contentWindow;
|
||||
window.__told = [];
|
||||
app.postMessage = (message) => window.__told.push(message);
|
||||
Object.defineProperty(window, "parent", { value: app, configurable: true });
|
||||
});
|
||||
return (data) =>
|
||||
s.page.evaluate((message) => {
|
||||
window.dispatchEvent(new MessageEvent("message", { source: window.parent, data: message }));
|
||||
}, data);
|
||||
}
|
||||
|
||||
test("Cancel in the app's confirm leaves Start ready to press again; a real start locks it", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const answer = await frameInFakeApp(s);
|
||||
const start = s.page.locator("#loop-start");
|
||||
const asked = () => s.page.evaluate(() => window.__told.filter((m) => m.plan2code === "loop-start").length);
|
||||
await answer({ plan2code: "loop-facts", facts: { permissionMode: "skip", promptSupport: true } });
|
||||
await s.page.waitForFunction(() => !document.getElementById("loop-start").disabled);
|
||||
|
||||
await start.click();
|
||||
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "loop-start"));
|
||||
await s.page.getByText("Waiting for the app's confirm...").waitFor();
|
||||
assert.equal(await start.isDisabled(), true, "no second confirm while one is open");
|
||||
|
||||
await answer({ plan2code: "loop-start-result", ok: true, started: false, error: null });
|
||||
await s.page.getByText("Waiting for the app's confirm...").waitFor({ state: "hidden" });
|
||||
assert.equal(await start.isDisabled(), false, "pressing Cancel gives the button back");
|
||||
assert.doesNotMatch(await textOf(s.page.locator(".loop-start")), /The loop is starting/);
|
||||
|
||||
await start.click();
|
||||
await s.page.waitForFunction(() => window.__told.filter((m) => m.plan2code === "loop-start").length === 2);
|
||||
assert.equal(await asked(), 2, "and it asks the app again");
|
||||
|
||||
await answer({ plan2code: "loop-start-result", ok: true, started: true, error: null });
|
||||
await s.page.getByText("The loop is starting...").waitFor();
|
||||
assert.equal(await start.isDisabled(), true);
|
||||
});
|
||||
|
||||
test("Send a test saves what is on screen, names nothing to the app, and shows what the app answered", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const answer = await frameInFakeApp(s);
|
||||
const button = s.page.locator("#loop-notify-test");
|
||||
const url = s.page.locator("#loop-notify-url");
|
||||
const told = () => s.page.evaluate(() => window.__told.filter((m) => m.plan2code === "loop-notify-test"));
|
||||
const line = s.page.locator(".loop-test p");
|
||||
|
||||
assert.equal(await button.isDisabled(), true, "nothing to test yet");
|
||||
await url.fill("example.com");
|
||||
assert.equal(await button.isDisabled(), true, "not an address yet");
|
||||
await url.fill("https://hooks.slack.com/services/T/B/x");
|
||||
assert.equal(await button.isDisabled(), false);
|
||||
|
||||
await button.click();
|
||||
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "loop-notify-test"));
|
||||
assert.deepEqual(await told(), [{ plan2code: "loop-notify-test" }], "no address in the message");
|
||||
const saved = await s.page.evaluate(async () => (await fetch("/loop-setup")).json());
|
||||
assert.equal(saved.notifyUrl, "https://hooks.slack.com/services/T/B/x", "saved before the app was asked");
|
||||
assert.equal(saved.notifyKind, "slack");
|
||||
assert.match(await line.innerText(), /Waiting for the app's confirm/);
|
||||
assert.equal(await button.isDisabled(), true, "one test at a time");
|
||||
|
||||
await answer({ plan2code: "loop-notify-test-result", ok: false, sent: false, error: "The test was not sent: it answered 404" });
|
||||
await s.page.locator(".loop-test p.loop-error").waitFor();
|
||||
assert.equal(await line.innerText(), "The test was not sent: it answered 404");
|
||||
assert.equal(await url.inputValue(), "https://hooks.slack.com/services/T/B/x", "the redraw kept the address");
|
||||
|
||||
await s.page.locator("#loop-notify-test").click();
|
||||
await line.getByText("Waiting").waitFor();
|
||||
await answer({ plan2code: "loop-notify-test-result", ok: true, sent: true, error: null });
|
||||
await line.getByText("Check that the message arrived").waitFor();
|
||||
|
||||
await s.page.locator("#loop-notify-url").fill("https://hooks.slack.com/services/T/B/y");
|
||||
assert.equal(await line.count(), 0, "a changed address forgets what the test said");
|
||||
|
||||
// Cancel in the app's confirm: nothing to report.
|
||||
await s.page.locator("#loop-notify-test").click();
|
||||
await line.getByText("Waiting").waitFor();
|
||||
await answer({ plan2code: "loop-notify-test-result", ok: true, sent: false, error: null });
|
||||
await s.page.waitForFunction(() => !document.querySelector(".loop-test p"));
|
||||
assert.equal(await s.page.locator("#loop-notify-test").isDisabled(), false);
|
||||
});
|
||||
|
||||
test("a pasted webhook picks its own kind, a chat service hides the name, and a kind chosen by hand stays", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const kind = s.page.locator("#loop-notify-kind");
|
||||
const url = s.page.locator("#loop-notify-url");
|
||||
const param = s.page.locator("#loop-notify-param");
|
||||
|
||||
assert.equal(await kind.inputValue(), "query");
|
||||
for (const [address, expected] of [
|
||||
["https://discord.com/api/webhooks/1/abc", "discord"],
|
||||
["https://hooks.slack.com/services/T/B/x", "slack"],
|
||||
["https://chat.googleapis.com/v1/spaces/A/messages?key=k", "google-chat"],
|
||||
["https://prod-1.westus.logic.azure.com/workflows/x", "teams"],
|
||||
]) {
|
||||
await kind.selectOption("query");
|
||||
await s.page.evaluate(async () => {
|
||||
const { page } = await import(new URL("state.js", document.baseURI).href);
|
||||
page.loopSetup.notifyKindChosen = false;
|
||||
});
|
||||
await url.fill(address);
|
||||
assert.equal(await kind.inputValue(), expected, address);
|
||||
assert.equal(await param.isVisible(), false, "the service fixes the field");
|
||||
}
|
||||
|
||||
// The person's own choice wins over what the address looks like.
|
||||
await kind.selectOption("query");
|
||||
await url.fill("https://discord.com/api/webhooks/2/def");
|
||||
assert.equal(await kind.inputValue(), "query");
|
||||
assert.equal(await param.isVisible(), true);
|
||||
|
||||
await kind.selectOption("json");
|
||||
assert.equal(await s.page.locator('label:has(#loop-notify-param) span').innerText(), "JSON field name for the message");
|
||||
await kind.selectOption("slack");
|
||||
assert.equal(await url.getAttribute("placeholder"), "https://hooks.slack.com/services/...");
|
||||
|
||||
const saved = await s.page.evaluate(async () => {
|
||||
const { page } = await import(new URL("state.js", document.baseURI).href);
|
||||
const res = await fetch("/loop-setup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(page.loopSetup.form) });
|
||||
return res.status;
|
||||
});
|
||||
assert.equal(saved, 200);
|
||||
assert.equal((await s.page.evaluate(async () => (await fetch("/loop-setup")).json())).notifyKind, "slack");
|
||||
});
|
||||
|
||||
test("the finish card counts each kind of decision per phase and opens on the full report", async (t) => {
|
||||
const s = await openSetup(t);
|
||||
const seen = await s.page.evaluate(async () => {
|
||||
const m = await import(new URL("screens/ending.js", document.baseURI).href);
|
||||
const card = m.renderLoopEnd({
|
||||
kind: "finished",
|
||||
line: "All 1 phases built",
|
||||
phases: [{ n: 2, name: "API", commit: "abc1234", unfixed: 3, retries: 1, fixed: 4, skipped: 2, left: 1, assumed: 5, decisions: 6 }],
|
||||
uncommitted: [],
|
||||
can: ["finalize"],
|
||||
});
|
||||
return {
|
||||
head: [...card.querySelectorAll("th")].map((c) => c.textContent),
|
||||
row: [...card.querySelectorAll("td")].map((c) => c.textContent),
|
||||
};
|
||||
});
|
||||
assert.deepEqual(seen.head, ["Phase", "Commit", "Fixed", "Not fixed", "Left open", "Assumed", "Other decisions", "Retries"]);
|
||||
assert.deepEqual(seen.row.slice(0, 1), ["Phase 2: API"]);
|
||||
assert.deepEqual(seen.row.slice(2), ["4", "2", "1", "5", "6", "1"]);
|
||||
});
|
||||
|
||||
// A real loop session: `open --loop` under the app's signal stamps the lock.
|
||||
async function openLoopPage(t) {
|
||||
return openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "implement",
|
||||
open: ["--loop"],
|
||||
env: { PLAN2CODE_IN_APP: "1" },
|
||||
payload: { title: "demo: Phase 1", headline: { stage: "Build", cleared: 9, total: 11 }, agent: { status: "working", activity: "Task 10 of 11" } },
|
||||
project: tempProject(PROJECT),
|
||||
});
|
||||
}
|
||||
|
||||
test("a loop at work tells the person they have nothing to do, and Send comes back when a question waits", async (t) => {
|
||||
const s = await openLoopPage(t);
|
||||
const foot = s.page.locator(".footer");
|
||||
const send = s.page.locator("#btn-send");
|
||||
await s.page.waitForFunction(() => document.querySelector(".footer")?.classList.contains("is-loop-idle"));
|
||||
assert.equal(await send.isVisible(), false, "no Send to suggest there is something to send");
|
||||
assert.equal(await s.page.locator("#footer-summary").isVisible(), false);
|
||||
assert.equal(await textOf(s.page.locator("#progress-text")), "9 of 11 tasks in this phase");
|
||||
assert.match(await textOf(s.page.locator("#main")), /The loop is running this phase by itself, so you don't need to do anything/);
|
||||
|
||||
s.post({ items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }], agent: { status: "waiting" } });
|
||||
await s.page.waitForFunction(() => !document.querySelector(".footer").classList.contains("is-loop-idle"));
|
||||
assert.equal(await send.isVisible(), true, "the person has something to do now");
|
||||
assert.equal((await foot.getAttribute("class")).includes("is-loop-idle"), false);
|
||||
});
|
||||
|
||||
test("an ordinary build keeps its Send, its count and its words", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "implement",
|
||||
payload: { title: "demo: Phase 1", headline: { stage: "Build", cleared: 9, total: 11 }, agent: { status: "working", activity: "Task 10 of 11" } },
|
||||
project: tempProject(PROJECT),
|
||||
});
|
||||
await s.page.locator("#progress-text").getByText("9 of 11 done").waitFor();
|
||||
assert.equal(await s.page.locator("#btn-send").isVisible(), true);
|
||||
assert.equal((await s.page.locator(".footer").getAttribute("class")).includes("is-loop-idle"), false);
|
||||
assert.match(await textOf(s.page.locator("#main")), /If Plan2Code needs you, the question appears here on its own/);
|
||||
});
|
||||
|
||||
test("a phase that has reported says the loop is checking it, not that it is starting", async (t) => {
|
||||
const s = await openLoopPage(t);
|
||||
s.post({
|
||||
agent: { status: "waiting" },
|
||||
loopOutcome: {
|
||||
phase: 1,
|
||||
result: "failed",
|
||||
reason: "tests",
|
||||
summary: "One test fails",
|
||||
tests: { ran: true, passed: false, summary: "1 fail" },
|
||||
review: { ran: true, recheck: false, left: { critical: 0, warning: 0, suggestion: 0 }, fixed: [], unfixed: [] },
|
||||
tasks: { blocked: [], assumed: [] },
|
||||
conflicts: [],
|
||||
decisions: [],
|
||||
subject: "Add a thing",
|
||||
},
|
||||
});
|
||||
await s.page.getByRole("heading", { name: "The loop is checking this phase" }).waitFor();
|
||||
assert.doesNotMatch(await textOf(s.page.locator("#main")), /starting this phase/);
|
||||
});
|
||||
|
||||
test("a loop phase still starting says the loop is starting it, and promises no approval prompt", async (t) => {
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "implement",
|
||||
open: ["--loop"],
|
||||
env: { PLAN2CODE_IN_APP: "1" },
|
||||
project: tempProject(PROJECT),
|
||||
});
|
||||
await s.page.getByRole("heading", { name: "The loop is starting this phase" }).waitFor();
|
||||
assert.doesNotMatch(await textOf(s.page.locator("#main")), /pause for approvals/);
|
||||
});
|
||||
@@ -190,7 +190,7 @@ test("typing Markdown styles it in place, saves within two seconds, and survives
|
||||
assert.equal(await shows(s, expected), expected, "a reload shows the saved note");
|
||||
|
||||
// A server restart (the agent's open --resume) keeps it too.
|
||||
cli(["stop", "--session", s.sid], { cwd: s.project });
|
||||
cli(["stop", "--session", s.sid, "--force"], { cwd: s.project });
|
||||
await until(async () => !(await s.answers()), 5000);
|
||||
const resumed = cli(["open", "--resume", s.sid, "--no-open", "--workflow", "plan"], { cwd: s.project }).json;
|
||||
s.url = resumed.url;
|
||||
@@ -1113,6 +1113,7 @@ test("User Preferences, Cleanup offers a month-old notepad by its folder and rem
|
||||
t.after(() => fs.rmSync(notepadFolder(other), { recursive: true, force: true }));
|
||||
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.click("#prefs-tab-system");
|
||||
await s.page.click("#cleanup-scan");
|
||||
const list = s.page.locator("#cleanup-list");
|
||||
const row = list.locator(".cleanup-row").filter({ hasText: "Notebook for" });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Page tests for User Preferences: the saved looks (highlight and theme), the
|
||||
// launcher's model menus and the Cleanup tab. Run with:
|
||||
// Page tests for User Preferences: its four tabs, the saved looks (highlight
|
||||
// and theme), the Agents & models tab (the launcher's model menus and the
|
||||
// person's agents) and Cleanup. Run with:
|
||||
// node --test scripts/test-web-console-page-prefs.mjs
|
||||
//
|
||||
// Each test drives the real console in a real Chrome or Edge through
|
||||
@@ -10,7 +11,7 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { pageSuite, openSession, textOf, drawn } from "./page-test-helpers.mjs";
|
||||
import { pageSuite, openSession, textOf, drawn, styleOf, stylesOf } from "./page-test-helpers.mjs";
|
||||
import { HOME, MODELS_DIR, backdate } from "./web-console-test-helpers.mjs";
|
||||
import { formatBytes } from "../src/web-console/public/answers.js";
|
||||
|
||||
@@ -84,148 +85,315 @@ test("the violet highlight and dark theme chosen in preferences stick across a r
|
||||
assert.deepEqual(await firstPaintAttrs(s), { theme: null, accent: null }, "the first paint still carries the old looks");
|
||||
});
|
||||
|
||||
test("the launcher's model menus have Claude, Devin and Codex tabs, and a model id typed on the Codex tab is saved", async (t) => {
|
||||
// The Agents & models tab: the summary table, its rows and the form Edit opens.
|
||||
const AGENTS_FILE = path.join(MODELS_DIR, "agents.json");
|
||||
const agentsTable = (s) => s.page.locator("#agents-table");
|
||||
const agentRow = (s, key) => s.page.locator(`#agents-table tr[data-key="${key}"]`);
|
||||
const agentForm = (s) => s.page.locator("#agents-form");
|
||||
const formField = (s, name) => agentForm(s).getByRole("textbox", { name, exact: true });
|
||||
const formButton = (s, name) => agentForm(s).getByRole("button", { name, exact: true });
|
||||
const unsavedPrompt = (s) => s.page.locator("#prefs-unsaved");
|
||||
|
||||
async function openAgentsTab(s) {
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.click("#prefs-tab-agents");
|
||||
await agentRow(s, "cli:claude").waitFor();
|
||||
}
|
||||
|
||||
// agents.json as the test starts it: none, or the entries given. Removed after.
|
||||
function seedAgents(t, agents) {
|
||||
fs.rmSync(AGENTS_FILE, { force: true });
|
||||
if (agents) {
|
||||
fs.mkdirSync(MODELS_DIR, { recursive: true });
|
||||
fs.writeFileSync(AGENTS_FILE, JSON.stringify({ schema: 1, agents }, null, 2));
|
||||
}
|
||||
t.after(() => fs.rmSync(AGENTS_FILE, { force: true }));
|
||||
}
|
||||
|
||||
test("Agents & models: the table lists Claude, Devin and Codex, and a model id typed in Codex's form is saved only on Save", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
// The file the launcher reads: put back as the suite had it (no file).
|
||||
t.after(() => fs.rmSync(path.join(MODELS_DIR, "models.json"), { force: true }));
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
const tabs = s.page.getByRole("group", { name: "Which agent" });
|
||||
for (const name of ["Claude", "Devin", "Codex"]) assert.equal(await tabs.getByRole("button", { name, exact: true }).count(), 1, `a ${name} tab`);
|
||||
const pressed = async () => (await tabs.locator('button[aria-pressed="true"]').allInnerTexts()).map((x) => x.trim());
|
||||
assert.deepEqual(await pressed(), ["Claude"], "the menus open on Claude");
|
||||
await openAgentsTab(s);
|
||||
const keys = await agentsTable(s).locator("tbody tr[data-key]").evaluateAll((rows) => rows.map((r) => r.dataset.key));
|
||||
assert.deepEqual(keys, ["cli:claude", "cli:devin", "cli:codex"]);
|
||||
assert.equal(await textOf(agentRow(s, "cli:codex").locator(".prefs-agents-name > span").first()), "Codex");
|
||||
|
||||
await tabs.getByRole("button", { name: "Codex", exact: true }).click();
|
||||
assert.deepEqual(await pressed(), ["Codex"]);
|
||||
await s.page.click("#models-add");
|
||||
const id = s.page.locator("#models-user").getByRole("textbox", { name: "Model id" });
|
||||
await s.page.getByRole("button", { name: "Edit Codex" }).click();
|
||||
await agentForm(s).waitFor();
|
||||
assert.equal(await agentsTable(s).isVisible(), false, "the form takes the table's place");
|
||||
await agentForm(s).locator(".prefs-agents-none").filter({ hasText: /^No models ship for Codex yet/ }).waitFor();
|
||||
assert.equal(await agentForm(s).locator(".models-row.locked").count(), 0, "nothing comes with Plan2Code for Codex");
|
||||
|
||||
await formButton(s, "Add a model").click();
|
||||
const id = formField(s, "Model id");
|
||||
await id.fill("gpt-test-codex-1");
|
||||
await id.press("Tab");
|
||||
await s.page.locator("#models-status").filter({ hasText: /^Saved\./ }).waitFor();
|
||||
await s.page.waitForTimeout(300);
|
||||
const before = await s.page.evaluate(async () => (await (await fetch("/models")).json()).user);
|
||||
assert.deepEqual(before.codex, [], "nothing is saved before Save");
|
||||
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), true);
|
||||
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved\. Restart plan2code/ }).waitFor();
|
||||
const saved = await s.page.evaluate(async () => (await (await fetch("/models")).json()).user);
|
||||
assert.deepEqual(saved.codex.map((m) => m.id), ["gpt-test-codex-1"], "the id was not saved under Codex");
|
||||
assert.deepEqual([saved.claude, saved.devin], [[], []], "the id leaked into another agent's menu");
|
||||
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), false, "saved, nothing is unsaved");
|
||||
|
||||
// Back on Claude the typed id is not listed; on Codex it is, after a reload.
|
||||
await tabs.getByRole("button", { name: "Claude", exact: true }).click();
|
||||
assert.equal(await s.page.locator("#models-user .models-row").count(), 0);
|
||||
// The summary counts it on Codex's row, and so does a fresh page.
|
||||
await formButton(s, "Back to summary").click();
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label") || document.activeElement?.id), "Edit Codex", "focus comes back to the row just left");
|
||||
assert.match(await textOf(agentRow(s, "cli:codex").locator(".prefs-agents-models")), /^1: gpt-test-codex-1$/);
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.locator("#models-tab-codex").click();
|
||||
await s.page.locator("#models-user").getByRole("textbox", { name: "Model id" }).waitFor();
|
||||
assert.equal(await s.page.locator("#models-user").getByRole("textbox", { name: "Model id" }).inputValue(), "gpt-test-codex-1");
|
||||
await openAgentsTab(s);
|
||||
await s.page.getByRole("button", { name: "Edit Codex" }).click();
|
||||
assert.equal(await formField(s, "Model id").inputValue(), "gpt-test-codex-1");
|
||||
});
|
||||
|
||||
test("Agents: a person adds an agent, tests its command, sees it saved after a reload, and deletes it", async (t) => {
|
||||
test("Agents & models: a person adds an agent, tests its command, sees it after a reload, and deletes it", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const file = path.join(MODELS_DIR, "agents.json");
|
||||
fs.rmSync(file, { force: true });
|
||||
t.after(() => fs.rmSync(file, { force: true }));
|
||||
seedAgents(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
const list = s.page.locator("#agents-list");
|
||||
assert.equal(await list.locator(".agent-card").count(), 0, "no agents before one is added");
|
||||
await openAgentsTab(s);
|
||||
assert.equal(await agentsTable(s).locator('tr[data-key^="agent:"]').count(), 0, "no agents before one is added");
|
||||
|
||||
await s.page.click("#agents-add");
|
||||
const card = list.locator(".agent-card").last();
|
||||
await card.getByRole("textbox", { name: "Name", exact: true }).fill("Test Agent");
|
||||
await card.getByRole("textbox", { name: "Command", exact: true }).fill("node");
|
||||
await card.getByRole("textbox", { name: "Command", exact: true }).press("Tab");
|
||||
await s.page.locator("#agents-status").filter({ hasText: /^Saved./ }).waitFor();
|
||||
await agentForm(s).waitFor();
|
||||
assert.equal(await agentForm(s).locator("details.prefs-agents-args").evaluate((d) => d.open), true, "the arguments are open on a new agent");
|
||||
await formField(s, "Name").fill("Test Agent");
|
||||
await formField(s, "Command").fill("node");
|
||||
await formButton(s, "Test").click();
|
||||
await agentForm(s).locator(".agent-test-result").filter({ hasText: /^Found at / }).waitFor();
|
||||
assert.equal(fs.existsSync(AGENTS_FILE), false, "Test never saves");
|
||||
|
||||
await card.getByRole("button", { name: "Test", exact: true }).click();
|
||||
await card.locator(".agent-test-result").filter({ hasText: /^Found at / }).waitFor();
|
||||
|
||||
const saved = JSON.parse(fs.readFileSync(file, "utf8"));
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
const saved = JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8"));
|
||||
assert.equal(saved.schema, 1);
|
||||
assert.deepEqual(saved.agents.map((a) => [a.id, a.name, a.command, a.prompt]), [["test-agent", "Test Agent", "node", "/plan2code"]]);
|
||||
|
||||
// A second agent with the same name is refused on its own card and field.
|
||||
await s.page.click("#agents-add");
|
||||
const second = list.locator(".agent-card").nth(1);
|
||||
await second.getByRole("textbox", { name: "Command", exact: true }).fill("x");
|
||||
await second.getByRole("textbox", { name: "Name", exact: true }).fill("TEST AGENT");
|
||||
await second.getByRole("textbox", { name: "Name", exact: true }).press("Tab");
|
||||
await list.locator(".agent-card").nth(1).locator(".agent-error").filter({ hasText: /already used/ }).waitFor();
|
||||
assert.equal(await list.locator(".agent-card").nth(1).locator('input.invalid[data-field="name"]').count(), 1, "the name field is marked");
|
||||
assert.equal(JSON.parse(fs.readFileSync(file, "utf8")).agents.length, 1, "a refused save writes nothing");
|
||||
assert.equal(await agentForm(s).locator(".prefs-agents-delete").count(), 1, "once saved it has Delete agent");
|
||||
|
||||
await s.page.reload({ waitUntil: "domcontentloaded" });
|
||||
await drawn(s.page);
|
||||
await s.page.click("#btn-looks");
|
||||
await list.locator(".agent-card").first().waitFor();
|
||||
assert.equal(await list.locator(".agent-card").count(), 1);
|
||||
assert.equal(await list.locator(".agent-card").first().getByRole("textbox", { name: "Name", exact: true }).inputValue(), "Test Agent");
|
||||
await openAgentsTab(s);
|
||||
const row = agentRow(s, "agent:test-agent");
|
||||
await row.locator(".prefs-badge.ok").waitFor();
|
||||
assert.equal(await textOf(row.locator(".prefs-badge")), "Found");
|
||||
await s.page.getByRole("button", { name: "Edit Test Agent" }).click();
|
||||
assert.equal(await formField(s, "Name").inputValue(), "Test Agent");
|
||||
assert.equal(await agentForm(s).locator("details.prefs-agents-args").evaluate((d) => d.open), false, "the arguments are folded on a saved agent");
|
||||
|
||||
await list.locator(".agent-card").first().getByRole("button", { name: "Delete", exact: true }).click();
|
||||
await list.locator(".agent-card").first().getByRole("button", { name: "Yes, delete" }).click();
|
||||
await s.page.waitForFunction(() => document.querySelectorAll("#agents-list .agent-card").length === 0);
|
||||
await s.page.locator("#agents-status").filter({ hasText: /^Saved./ }).waitFor();
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(file, "utf8")).agents, []);
|
||||
});
|
||||
|
||||
test("Agents: a new card's first field is not saved alone, and a redraw keeps focus and what was typed", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const file = path.join(MODELS_DIR, "agents.json");
|
||||
fs.rmSync(file, { force: true });
|
||||
t.after(() => fs.rmSync(file, { force: true }));
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
const list = s.page.locator("#agents-list");
|
||||
await formButton(s, "Delete agent").click();
|
||||
await formButton(s, "Yes, delete").click();
|
||||
await agentsTable(s).waitFor();
|
||||
assert.equal(await agentsTable(s).locator('tr[data-key^="agent:"]').count(), 0);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents, []);
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label") || document.activeElement?.id), "agents-add", "with its row gone, focus goes to Add agent");
|
||||
assert.equal(await textOf(s.page.locator("#agents-status")), "Deleted.");
|
||||
await s.page.click("#agents-add");
|
||||
const card = list.locator(".agent-card").last();
|
||||
const name = card.getByRole("textbox", { name: "Name", exact: true });
|
||||
const command = card.getByRole("textbox", { name: "Command", exact: true });
|
||||
|
||||
await name.fill("Focus Agent");
|
||||
await name.press("Tab");
|
||||
await s.page.waitForTimeout(300);
|
||||
assert.equal(await list.locator(".agent-error").count(), 0, "a name alone is not sent, so nothing is refused");
|
||||
assert.equal(fs.existsSync(file), false, "and nothing is written");
|
||||
assert.equal(await command.evaluate((el) => el === document.activeElement), true, "Tab lands on Command");
|
||||
|
||||
// The first good save assigns an id and redraws every card: focus stays where Tab put it.
|
||||
await command.fill("node");
|
||||
await command.press("Tab");
|
||||
await s.page.locator("#agents-status").filter({ hasText: /^Saved./ }).waitFor();
|
||||
assert.equal(JSON.parse(fs.readFileSync(file, "utf8")).agents[0].id, "focus-agent");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.textContent), "Add an argument", "focus survives the redraw");
|
||||
|
||||
// A refused save redraws too: the field being typed in keeps its text, and leaving it saves it.
|
||||
const prompt = list.locator(".agent-card").last().getByRole("textbox", { name: "Start prompt", exact: true });
|
||||
await name.fill("");
|
||||
await prompt.click();
|
||||
await prompt.fill("/plan2code hi");
|
||||
await list.locator(".agent-error").filter({ hasText: /name is missing/ }).waitFor();
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Start prompt");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.value), "/plan2code hi");
|
||||
assert.equal(await s.page.locator("#agents-status").innerText(), "", "opening a form clears Deleted.");
|
||||
});
|
||||
|
||||
test("Agents: a file holding entries the page could not read is only replaced after Save anyway", async (t) => {
|
||||
test("Agents & models: a new agent with only a name is not sent, its command is marked, and focus and text survive", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.click("#agents-add");
|
||||
await formField(s, "Name").fill("Focus Agent");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".agent-error").filter({ hasText: "Give it a name and a command first." }).waitFor();
|
||||
assert.equal(fs.existsSync(AGENTS_FILE), false, "nothing is written");
|
||||
assert.equal(await agentForm(s).locator('input.invalid[data-field="command"]').count(), 1, "the command field is marked");
|
||||
assert.equal(await formField(s, "Name").inputValue(), "Focus Agent", "the typed name survives the redraw");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.textContent), "Save", "focus stays on Save");
|
||||
|
||||
// The first good save assigns an id; the form stays open on it.
|
||||
await formField(s, "Command").fill("node");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
assert.equal(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents[0].id, "focus-agent");
|
||||
assert.equal(await textOf(agentForm(s).locator(".prefs-agents-title")), "Focus Agent");
|
||||
|
||||
// A refused save marks the field the server names, and keeps what was typed.
|
||||
await formField(s, "Name").fill("");
|
||||
await formField(s, "Start prompt").fill("/plan2code hi");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".agent-error").filter({ hasText: /name is missing/ }).waitFor();
|
||||
assert.equal(await agentForm(s).locator('input.invalid[data-field="name"]').count(), 1);
|
||||
assert.equal(await formField(s, "Start prompt").inputValue(), "/plan2code hi");
|
||||
assert.equal(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents[0].name, "Focus Agent", "a refused save writes nothing");
|
||||
});
|
||||
|
||||
test("Agents & models: a file holding entries the page could not read is only replaced after Save anyway", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const file = path.join(MODELS_DIR, "agents.json");
|
||||
fs.mkdirSync(MODELS_DIR, { recursive: true });
|
||||
const text = JSON.stringify({ schema: 2, agents: [{ id: "future", name: "Future", command: "future" }] });
|
||||
fs.writeFileSync(file, text);
|
||||
t.after(() => fs.rmSync(file, { force: true }));
|
||||
fs.mkdirSync(MODELS_DIR, { recursive: true });
|
||||
fs.writeFileSync(AGENTS_FILE, text);
|
||||
t.after(() => fs.rmSync(AGENTS_FILE, { force: true }));
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
await openAgentsTab(s);
|
||||
await s.page.locator("#agents-status").filter({ hasText: /schema 2/ }).waitFor();
|
||||
assert.equal(await s.page.locator("#agents-replace").isVisible(), false, "no Save anyway before a save is tried");
|
||||
|
||||
await s.page.click("#agents-add");
|
||||
const card = s.page.locator("#agents-list .agent-card").last();
|
||||
await card.getByRole("textbox", { name: "Name", exact: true }).fill("Mine");
|
||||
await card.getByRole("textbox", { name: "Command", exact: true }).fill("node");
|
||||
await card.getByRole("textbox", { name: "Command", exact: true }).press("Tab");
|
||||
await s.page.locator("#agents-status").filter({ hasText: /could not read/ }).waitFor();
|
||||
assert.equal(fs.readFileSync(file, "utf8"), text, "the refused save writes nothing");
|
||||
assert.equal(await formButton(s, "Save anyway").count(), 0, "no Save anyway before a save is tried");
|
||||
await formField(s, "Name").fill("Mine");
|
||||
await formField(s, "Command").fill("node");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".agent-error").filter({ hasText: /could not read/ }).first().waitFor();
|
||||
assert.equal(fs.readFileSync(AGENTS_FILE, "utf8"), text, "the refused save writes nothing");
|
||||
|
||||
await s.page.locator("#agents-replace").click();
|
||||
await s.page.locator("#agents-status").filter({ hasText: /^Saved./ }).waitFor();
|
||||
assert.equal(await s.page.locator("#agents-replace").isVisible(), false);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(file, "utf8")).agents.map((a) => a.id), ["mine"]);
|
||||
await formButton(s, "Save anyway").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
assert.equal(await formButton(s, "Save anyway").count(), 0);
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents.map((a) => a.id), ["mine"]);
|
||||
});
|
||||
|
||||
const TWO_AGENTS = [
|
||||
{ id: "alpha", name: "Alpha", command: "alpha-cli" },
|
||||
{ id: "beta", name: "Beta", command: "beta-cli" },
|
||||
];
|
||||
|
||||
test("Agents & models: nothing reaches agents.json before Save", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const before = fs.readFileSync(AGENTS_FILE, "utf8");
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
await formField(s, "Command").fill("alpha-cli --edited");
|
||||
await formField(s, "Command").press("Tab");
|
||||
await s.page.waitForTimeout(500);
|
||||
assert.equal(fs.readFileSync(AGENTS_FILE, "utf8"), before, "agents.json is byte for byte unchanged");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
assert.equal(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents[0].command, "alpha-cli --edited");
|
||||
});
|
||||
|
||||
test("Agents & models: a discarded edit never rides along with another agent's Save", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
await formField(s, "Command").fill("alpha-cli --dropped");
|
||||
await formButton(s, "Back to summary").click();
|
||||
await unsavedPrompt(s).waitFor();
|
||||
assert.equal(await textOf(s.page.locator("#prefs-unsaved-name")), "Alpha");
|
||||
assert.equal(await s.page.locator("#looks-modal .prefs-body").evaluate((b) => b.inert), true, "the dialog behind the prompt is out of reach");
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Discard", exact: true }).click();
|
||||
await agentsTable(s).waitFor();
|
||||
assert.equal(await s.page.locator("#looks-modal .prefs-body").evaluate((b) => b.inert), false);
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label") || document.activeElement?.id), "Edit Alpha", "focus comes back to the row just left");
|
||||
|
||||
await s.page.getByRole("button", { name: "Edit Beta" }).click();
|
||||
await formField(s, "Command").fill("beta-cli --kept");
|
||||
await formButton(s, "Save").click();
|
||||
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved$/ }).waitFor();
|
||||
const agents = JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents;
|
||||
assert.deepEqual(agents.map((a) => [a.id, a.command]), [["alpha", "alpha-cli"], ["beta", "beta-cli --kept"]]);
|
||||
});
|
||||
|
||||
test("Agents & models: an unsaved edit asks first on Back, Close, Esc, a backdrop click and a tab switch", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
const modal = s.page.locator("#looks-modal");
|
||||
const edit = async (command) => {
|
||||
if (!(await agentForm(s).isVisible())) await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
await formField(s, "Command").fill(command);
|
||||
};
|
||||
const triggers = {
|
||||
back: () => formButton(s, "Back to summary").click(),
|
||||
close: () => s.page.click("#looks-done"),
|
||||
esc: () => formField(s, "Command").press("Escape"),
|
||||
backdrop: () => s.page.mouse.click(4, 4),
|
||||
tab: () => s.page.click("#prefs-tab-appearance"),
|
||||
};
|
||||
for (const [name, leave] of Object.entries(triggers)) {
|
||||
// Keep editing: the form and the draft stay.
|
||||
await edit(`alpha-${name}-kept`);
|
||||
await leave();
|
||||
await unsavedPrompt(s).waitFor();
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.id), "prefs-unsaved-save", `${name}: Save has focus`);
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Keep editing" }).click();
|
||||
await unsavedPrompt(s).waitFor({ state: "hidden" });
|
||||
assert.equal(await modal.evaluate((d) => d.open), true, `${name}: the dialog stays open`);
|
||||
assert.equal(await formField(s, "Command").inputValue(), `alpha-${name}-kept`, `${name}: the draft stays`);
|
||||
assert.equal(await s.page.locator("#prefs-tab-agents").getAttribute("aria-selected"), "true");
|
||||
}
|
||||
const before = fs.readFileSync(AGENTS_FILE, "utf8");
|
||||
|
||||
// Discard drops the edit and goes on (here, Close).
|
||||
await triggers.close();
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Discard", exact: true }).click();
|
||||
await modal.waitFor({ state: "hidden" });
|
||||
assert.equal(fs.readFileSync(AGENTS_FILE, "utf8"), before, "Discard writes nothing");
|
||||
|
||||
// Save writes and goes on (here, a tab switch).
|
||||
await openAgentsTab(s);
|
||||
await edit("alpha-saved");
|
||||
await triggers.tab();
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Save", exact: true }).click();
|
||||
await s.page.locator('#prefs-tab-appearance[aria-selected="true"]').waitFor();
|
||||
assert.equal(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents[0].command, "alpha-saved");
|
||||
});
|
||||
|
||||
test("Agents & models: Esc in the unsaved prompt keeps editing, and a Save that fails there stays and marks the field", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
await s.page.click("#agents-add");
|
||||
await formField(s, "Name").fill("Half Agent");
|
||||
|
||||
await s.page.click("#looks-done");
|
||||
await unsavedPrompt(s).waitFor();
|
||||
await s.page.keyboard.press("Escape");
|
||||
await unsavedPrompt(s).waitFor({ state: "hidden" });
|
||||
assert.equal(await s.page.locator("#looks-modal").evaluate((d) => d.open), true, "Esc in the prompt does not close the dialog");
|
||||
assert.equal(await formField(s, "Name").inputValue(), "Half Agent", "the draft stays");
|
||||
|
||||
// Save from the prompt with no command: nothing is sent, the dialog stays, focus is on the marked field.
|
||||
await s.page.click("#looks-done");
|
||||
await unsavedPrompt(s).getByRole("button", { name: "Save", exact: true }).click();
|
||||
await unsavedPrompt(s).waitFor({ state: "hidden" });
|
||||
assert.equal(await s.page.locator("#looks-modal").evaluate((d) => d.open), true, "a failed Save keeps the dialog open");
|
||||
assert.equal(fs.existsSync(AGENTS_FILE), false, "nothing is written");
|
||||
assert.equal(await s.page.evaluate(() => document.activeElement?.matches('input.invalid[data-field="command"]')), true, "focus is on the marked field");
|
||||
});
|
||||
|
||||
test("Agents & models: a command not on PATH is marked, and the orchestrator row has no Edit", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, [{ id: "ghost", name: "Ghost", command: "plan2code-no-such-command-xyz" }]);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await openAgentsTab(s);
|
||||
const badge = agentRow(s, "agent:ghost").locator(".prefs-badge");
|
||||
await badge.filter({ hasText: "Not found on PATH" }).waitFor();
|
||||
assert.equal(await badge.evaluate((b) => b.classList.contains("missing")), true);
|
||||
const soon = agentsTable(s).locator("tr.prefs-agents-soon");
|
||||
assert.match(await textOf(soon), /v3 orchestrator\s+Nothing to set yet\./);
|
||||
assert.equal(await soon.getByRole("button").count(), 0);
|
||||
});
|
||||
|
||||
test("Agents & models: below 720 px the Models column is hidden and the form is one column", async (t) => {
|
||||
noSavedLooks(t);
|
||||
seedAgents(t, TWO_AGENTS);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.setViewportSize({ width: 600, height: 800 });
|
||||
await openAgentsTab(s);
|
||||
const cells = agentsTable(s).locator(".prefs-agents-models");
|
||||
const shown = [];
|
||||
for (let i = 0; i < (await cells.count()); i++) shown.push(await styleOf(cells.nth(i), "display"));
|
||||
assert.ok(shown.length > 0 && shown.every((d) => d === "none"), `the Models cells are hidden: ${shown}`);
|
||||
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
|
||||
const cols = await styleOf(agentForm(s).locator(".prefs-agents-fields"), "grid-template-columns");
|
||||
assert.equal(cols.trim().split(/\s+/).length, 1, `one column: ${cols}`);
|
||||
});
|
||||
|
||||
test("Cleanup scans the console home and lists an old session folder with its size", async (t) => {
|
||||
@@ -243,6 +411,7 @@ test("Cleanup scans the console home and lists an old session folder with its si
|
||||
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
||||
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.click("#prefs-tab-system");
|
||||
const list = s.page.locator("#cleanup-list");
|
||||
assert.equal(await list.locator(".cleanup-row").count(), 0, "Cleanup lists things before a scan");
|
||||
assert.equal(await s.page.locator("#cleanup-delete").isHidden(), true, "Delete is offered before a scan");
|
||||
@@ -262,6 +431,201 @@ test("Cleanup scans the console home and lists an old session folder with its si
|
||||
// Closing preferences forgets the scan: a reopened dialog starts clean.
|
||||
await s.page.click("#looks-done");
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.click("#prefs-tab-system");
|
||||
assert.equal(await list.locator(".cleanup-row").count(), 0, "the old scan is still listed");
|
||||
assert.equal(await s.page.locator("#cleanup-delete").isHidden(), true);
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------- the tabs */
|
||||
|
||||
const tabNames = async (s) => (await s.page.locator("#prefs-tabs [role=tab] .prefs-tab-label").allInnerTexts()).map((x) => x.trim());
|
||||
const selectedTab = (s) => s.page.evaluate(() => document.querySelector('#prefs-tabs [aria-selected="true"]')?.id);
|
||||
const focusedId = (s) => s.page.evaluate(() => document.activeElement?.id);
|
||||
const visiblePanels = (s) => s.page.evaluate(() => [...document.querySelectorAll("#prefs-panels [role=tabpanel]")].filter((p) => !p.hidden).map((p) => p.id));
|
||||
|
||||
test("the gear opens User Preferences on Appearance, with four tabs in order and one panel shown", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.setViewportSize({ width: 1000, height: 800 });
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.locator("#looks-modal[open]").waitFor();
|
||||
assert.deepEqual(await tabNames(s), ["Appearance", "Agents & models", "System", "Sounds & activities"]);
|
||||
assert.equal(await selectedTab(s), "prefs-tab-appearance");
|
||||
assert.equal(await focusedId(s), "prefs-tab-appearance", "focus is on the selected tab");
|
||||
assert.equal(await s.page.locator('#prefs-tabs [tabindex="0"]').count(), 1, "one tab in the tab order");
|
||||
assert.deepEqual(await visiblePanels(s), ["prefs-panel-appearance"]);
|
||||
assert.equal(await s.page.locator("#prefs-tab-appearance").getAttribute("aria-controls"), "prefs-panel-appearance");
|
||||
assert.equal(await s.page.locator("#prefs-panel-appearance").getAttribute("aria-labelledby"), "prefs-tab-appearance");
|
||||
assert.equal(await textOf(s.page.locator("#looks-done")), "Close", "the footer button no longer says Done");
|
||||
});
|
||||
|
||||
test("Preferences' tabs move with the arrow, Home and End keys, wrapping at the ends", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.locator("#looks-modal[open]").waitFor();
|
||||
const press = async (key, want) => {
|
||||
await s.page.keyboard.press(key);
|
||||
assert.equal(await selectedTab(s), want, `${key} selects ${want}`);
|
||||
assert.equal(await focusedId(s), want, `${key} focuses ${want}`);
|
||||
assert.deepEqual(await visiblePanels(s), [want.replace("-tab-", "-panel-")]);
|
||||
};
|
||||
await press("ArrowDown", "prefs-tab-agents");
|
||||
await press("ArrowRight", "prefs-tab-system");
|
||||
await press("End", "prefs-tab-sounds");
|
||||
await press("ArrowDown", "prefs-tab-appearance");
|
||||
await press("ArrowUp", "prefs-tab-sounds");
|
||||
await press("Home", "prefs-tab-appearance");
|
||||
await press("ArrowLeft", "prefs-tab-sounds");
|
||||
});
|
||||
|
||||
test("below 720 px the side list is a horizontal strip with no hints", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.setViewportSize({ width: 1000, height: 800 });
|
||||
await s.page.click("#btn-looks");
|
||||
const list = s.page.locator("#prefs-tabs");
|
||||
const hint = s.page.locator("#prefs-tab-appearance .prefs-tab-hint");
|
||||
assert.equal(await list.getAttribute("aria-orientation"), "vertical");
|
||||
assert.equal(await styleOf(hint, "display"), "block", "hints show in the side list");
|
||||
assert.equal(await styleOf(list, "flex-direction"), "column");
|
||||
await s.page.setViewportSize({ width: 600, height: 800 });
|
||||
await s.page.waitForFunction(() => document.getElementById("prefs-tabs").getAttribute("aria-orientation") === "horizontal");
|
||||
assert.equal(await styleOf(hint, "display"), "none", "no hints in the strip");
|
||||
assert.deepEqual(await stylesOf(list, ["flex-direction", "overflow-x"]), { "flex-direction": "row", "overflow-x": "auto" });
|
||||
await s.page.setViewportSize({ width: 1000, height: 800 });
|
||||
await s.page.waitForFunction(() => document.getElementById("prefs-tabs").getAttribute("aria-orientation") === "vertical");
|
||||
});
|
||||
|
||||
test("Set up preferences on the dashboard opens on Appearance with agents and models loaded", async (t) => {
|
||||
fs.mkdirSync(HOME, { recursive: true });
|
||||
fs.writeFileSync(LOOKS_FILE, JSON.stringify({ looks: { welcomeSeen: true } }));
|
||||
t.after(() => fs.rmSync(LOOKS_FILE, { force: true }));
|
||||
const file = path.join(MODELS_DIR, "agents.json");
|
||||
fs.mkdirSync(MODELS_DIR, { recursive: true });
|
||||
fs.writeFileSync(file, JSON.stringify({ schema: 1, agents: [{ id: "goose", name: "Goose", command: "goose" }] }));
|
||||
t.after(() => fs.rmSync(file, { force: true }));
|
||||
const s = await openSession(await suite.browser(), {
|
||||
t,
|
||||
workflow: "dashboard",
|
||||
payload: { menu: { note: "Nothing yet." }, agent: { status: "waiting" } },
|
||||
});
|
||||
const skip = s.page.getByRole("button", { name: "Skip the intro" });
|
||||
await skip.click();
|
||||
await skip.waitFor({ state: "hidden" });
|
||||
await s.page.getByRole("button", { name: "Set up preferences" }).click();
|
||||
await s.page.locator("#looks-modal[open]").waitFor();
|
||||
assert.equal(await selectedTab(s), "prefs-tab-appearance");
|
||||
await s.page.click("#prefs-tab-agents");
|
||||
const goose = s.page.locator('#agents-table tr[data-key="agent:goose"]');
|
||||
await goose.waitFor();
|
||||
assert.match(await textOf(goose.locator(".prefs-agents-name")), /^Goose/);
|
||||
assert.equal(await s.page.locator('#agents-table tr[data-key="cli:claude"]').count(), 1, "the built-ins are listed");
|
||||
assert.doesNotMatch(await s.page.locator("#agents-status").innerText(), /could not be loaded/);
|
||||
});
|
||||
|
||||
test("Back to default resets only the tab on screen, and is hidden on Agents & models and System", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.locator('input[name="looks-theme"][value="dark"]').check();
|
||||
await swatch(s, "violet").click();
|
||||
await s.page.click("#prefs-tab-sounds");
|
||||
await s.page.locator("#looks-sound").uncheck();
|
||||
await s.page.locator("#looks-activities").uncheck();
|
||||
|
||||
await s.page.click("#prefs-tab-agents");
|
||||
assert.equal(await s.page.locator("#looks-reset").isHidden(), true, "hidden on Agents & models");
|
||||
await s.page.click("#prefs-tab-system");
|
||||
assert.equal(await s.page.locator("#looks-reset").isHidden(), true, "hidden on System");
|
||||
|
||||
await s.page.click("#prefs-tab-appearance");
|
||||
await s.page.click("#looks-reset");
|
||||
await s.page.waitForFunction(() => !document.documentElement.hasAttribute("data-theme"));
|
||||
assert.equal(await swatch(s, "violet").getAttribute("aria-pressed"), "false");
|
||||
await s.page.click("#prefs-tab-sounds");
|
||||
assert.equal(await s.page.locator("#looks-sound").isChecked(), false, "Appearance's reset left sounds off");
|
||||
assert.equal(await s.page.locator("#looks-activities").isChecked(), false);
|
||||
|
||||
await s.page.click("#prefs-tab-appearance");
|
||||
await s.page.locator('input[name="looks-theme"][value="dark"]').check();
|
||||
await s.page.click("#prefs-tab-sounds");
|
||||
await s.page.click("#looks-reset");
|
||||
await s.page.locator("#looks-sound:checked").waitFor();
|
||||
assert.equal(await s.page.locator("#looks-activities").isChecked(), true);
|
||||
assert.equal(await root(s, "data-theme"), "dark", "the sounds reset left the dark theme");
|
||||
await s.page.waitForFunction(async () => {
|
||||
const saved = (await (await fetch("/looks")).json()).looks || {};
|
||||
return saved.sound === true && saved.hideActivities === false && saved.theme === "dark";
|
||||
});
|
||||
});
|
||||
|
||||
test("a theme change shows Saved level with the Theme legend, outside the fieldset's grid", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.locator('input[name="looks-theme"][value="light"]').check();
|
||||
const mark = s.page.locator('fieldset[data-section="theme"] .prefs-saved');
|
||||
await mark.filter({ hasText: "Saved" }).waitFor();
|
||||
assert.equal(await mark.getAttribute("role"), "status");
|
||||
// Out of the fieldset's grid: the three choices still share one row.
|
||||
assert.equal(await styleOf(mark, "position"), "absolute");
|
||||
const tops = await s.page.locator('fieldset[data-section="theme"] label').evaluateAll((ls) => ls.map((l) => l.offsetTop));
|
||||
assert.equal(new Set(tops).size, 1, `the theme choices sit on one row: ${tops}`);
|
||||
});
|
||||
|
||||
test("a save the server refuses shows its error in the Saved mark's place, until a save lands", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
let refuse = true;
|
||||
await s.page.route("**/looks", (route) =>
|
||||
refuse && route.request().method() === "POST"
|
||||
? route.fulfill({ status: 500, contentType: "application/json", body: JSON.stringify({ error: "Disk is full." }) })
|
||||
: route.continue()
|
||||
);
|
||||
await s.page.click("#btn-looks");
|
||||
await s.page.locator('input[name="looks-theme"][value="dark"]').check();
|
||||
const mark = s.page.locator('fieldset[data-section="theme"] .prefs-saved');
|
||||
await mark.filter({ hasText: "Disk is full." }).waitFor();
|
||||
assert.equal(await mark.evaluate((m) => m.classList.contains("error")), true);
|
||||
refuse = false;
|
||||
await s.page.locator('input[name="looks-theme"][value="light"]').check();
|
||||
await mark.filter({ hasText: "Saved" }).waitFor();
|
||||
assert.equal(await mark.evaluate((m) => m.classList.contains("error")), false, "the error clears once a save lands");
|
||||
});
|
||||
|
||||
test("a Preferences tab is named by its label alone, with the hint as its description", async (t) => {
|
||||
noSavedLooks(t);
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
|
||||
await s.page.click("#btn-looks");
|
||||
for (const name of ["Appearance", "Agents & models", "System", "Sounds & activities"]) {
|
||||
assert.equal(await s.page.getByRole("tab", { name, exact: true }).count(), 1, `a tab named ${name}`);
|
||||
}
|
||||
const tab = s.page.locator("#prefs-tab-system");
|
||||
assert.equal(await textOf(s.page.locator("#" + (await tab.getAttribute("aria-describedby")))), "Cleanup, desktop app");
|
||||
});
|
||||
|
||||
// Read from the Subagents dialog at 1000 px before Preferences moved to tabs:
|
||||
// it borrows Preferences' .looks classes, and must not change with them.
|
||||
const SUBAGENTS_BEFORE = {
|
||||
modal: { "max-width": "none", width: "900px" },
|
||||
row: { display: "grid", "grid-template-columns": "repeat(2, minmax(0px, 1fr))", "margin-top": "0px" },
|
||||
second: { "margin-top": "0px" },
|
||||
actions: { display: "flex", "justify-content": "flex-end" },
|
||||
};
|
||||
|
||||
test("the Subagents dialog looks as it did before Preferences moved to tabs", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 2" } } });
|
||||
await s.page.setViewportSize({ width: 1000, height: 800 });
|
||||
const modal = s.page.locator("#subagents-modal");
|
||||
await s.page.locator("#btn-subagents").click();
|
||||
await modal.waitFor();
|
||||
const got = {
|
||||
modal: await stylesOf(modal, ["max-width", "width"]),
|
||||
row: await stylesOf(modal.locator("fieldset.looks-row").first(), ["display", "grid-template-columns", "margin-top"]),
|
||||
second: await stylesOf(modal.locator("fieldset.modal-ranges").nth(1), ["margin-top"]),
|
||||
actions: await stylesOf(modal.locator(".modal-actions"), ["display", "justify-content"]),
|
||||
};
|
||||
if (process.env.P2C_PRINT_SUBAGENTS) console.log("SUBAGENTS " + JSON.stringify(got));
|
||||
assert.deepEqual(got, SUBAGENTS_BEFORE);
|
||||
});
|
||||
@@ -14,6 +14,7 @@ import path from "node:path";
|
||||
import { pageSuite, openSession, itemCard, drawn, textOf, tempProject } from "./page-test-helpers.mjs";
|
||||
import { cli, until } from "./web-console-test-helpers.mjs";
|
||||
import { STOP_HANDOFF_REPLY, HOME_REPLY } from "../src/web-console/public/answers.js";
|
||||
import { CHAT_OFFLINE_TEXT } from "../src/web-console/public/chat.js";
|
||||
// How long the page waits without contact before it calls itself offline:
|
||||
// the page's own constant, so this file never drifts from it.
|
||||
import { GONE_AFTER_MS } from "../src/web-console/public/screens/core.js";
|
||||
@@ -34,7 +35,7 @@ const PLAN_QUESTION = {
|
||||
// The agent's side of `stop`, leaving the browser context open (s.stop()
|
||||
// closes it, which would hide what the page does next).
|
||||
async function stopServer(s) {
|
||||
cli(["stop", "--session", s.sid], { cwd: s.project });
|
||||
cli(["stop", "--session", s.sid, "--force"], { cwd: s.project });
|
||||
assert.ok(await until(async () => !(await s.answers()), 5000), "the server still answers after stop");
|
||||
}
|
||||
|
||||
@@ -578,6 +579,33 @@ test("answers a working agent has not collected bring up the saved-and-waiting l
|
||||
assert.equal(await whatToCheck(s).count(), 1, "the line carries What to check");
|
||||
});
|
||||
|
||||
// The agent picked up an Ask message and is answering it, so it is not in
|
||||
// `wait` to collect a card sent meanwhile. That is busy, not gone: the line
|
||||
// says so for ten minutes of silence before the not running help shows.
|
||||
test("a card sent while the agent answers an Ask message says it is answering, and not running only after ten minutes", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", clock: true, payload: PLAN_QUESTION });
|
||||
await s.page.locator("nav").getByRole("button", { name: "Ask", exact: true }).click();
|
||||
await s.page.locator("#ask-input").fill("What does the export include?");
|
||||
await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click();
|
||||
const got = s.wait(10);
|
||||
assert.equal(got.code, 0, `the Ask message was not handed over (wait exit ${got.code})`);
|
||||
await s.page.locator("#views").getByRole("button", { name: /^Questions/ }).click();
|
||||
await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export");
|
||||
await s.page.click("#btn-send");
|
||||
await lineSays(s, /^Plan2Code is answering your Ask message\./);
|
||||
await s.page.clock.fastForward(70_000);
|
||||
await lineSays(s, /^Plan2Code is answering your Ask message\./);
|
||||
await s.page.clock.fastForward(8 * 60_000);
|
||||
await lineSays(s, /^Plan2Code is answering your Ask message\./);
|
||||
// The Ask tab agrees: still answering, not "No agent available".
|
||||
await s.page.locator("nav").getByRole("button", { name: "Ask", exact: true }).click();
|
||||
await s.page.locator("#ask-input").waitFor();
|
||||
assert.ok(!(await s.page.locator("body").innerText()).includes(CHAT_OFFLINE_TEXT), "the Ask tab went offline while the agent was answering");
|
||||
await s.page.clock.fastForward(2 * 60_000);
|
||||
await lineSays(s, /^Plan2Code is not running\. Your answers are saved and waiting for it\./);
|
||||
await s.page.waitForFunction((t) => document.body.innerText.includes(t), CHAT_OFFLINE_TEXT, { timeout: 10000 });
|
||||
});
|
||||
|
||||
// A failed Send says why at once, rather than one line for every cause and
|
||||
// the real state only showing once the page's own timers catch up.
|
||||
test("a Send that finds the server gone says so at once, with the reconnect help", async (t) => {
|
||||
@@ -851,7 +879,13 @@ test("every finished shape shows Before you close this with its three rows, and
|
||||
assert.ok(!text.includes("—"), `${headline}: the guide carries an em dash`);
|
||||
}
|
||||
// With a stop warning up, a pause's command starts the work again.
|
||||
s.post({ stopWarning: "Answers since the last save will not be kept." });
|
||||
// The console now refuses a post that leaves both a finish and a stop warning up,
|
||||
// so the state the page can still be handed is written straight into the
|
||||
// session's state file.
|
||||
const statePath = path.join(s.session, "state.json");
|
||||
const withWarning = JSON.parse(fs.readFileSync(statePath, "utf8"));
|
||||
withWarning.stopWarning = "Answers since the last save will not be kept.";
|
||||
fs.writeFileSync(statePath, JSON.stringify(withWarning));
|
||||
await closeGuide(s).getByText(/The command above starts it again\./).waitFor();
|
||||
assert.equal(await s.page.locator("#btn-home").isVisible(), false, "a finished screen carries its own way back");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
// Web console tests, the pointers: which topic file the console names, and when.
|
||||
// Run with: node --test scripts/test-web-console-pointers.mjs
|
||||
//
|
||||
// The card leaves a topic out and the console's own output names its file at
|
||||
// the moment it is due (`read`), once per session per topic and again after a
|
||||
// resume. Shared setup lives in web-console-test-helpers.mjs.
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { POINTER_FILES, duePointers, pointersForSend, rememberPointers, resetPointers } from "../src/web-console/pointers.mjs";
|
||||
import {
|
||||
HOME,
|
||||
ROOT,
|
||||
cli,
|
||||
openSession,
|
||||
postPatch,
|
||||
readState,
|
||||
tempFolder,
|
||||
waitOnce,
|
||||
addFolder,
|
||||
ask,
|
||||
} from "./web-console-test-helpers.mjs";
|
||||
|
||||
const WEB = path.join(ROOT, "src", "web-console");
|
||||
const file = (name) => path.join(WEB, name);
|
||||
const SUBAGENTS_STORE = path.join(HOME, "subagents.json");
|
||||
|
||||
// A fresh session, a send made as the page makes it, and the one `wait` that
|
||||
// collects it: the `read` that wait printed.
|
||||
const fresh = (extra = {}) => openSession(extra);
|
||||
async function send(s, actions) {
|
||||
const res = await s.send("/submit", { actions, reply: "sent from the page" });
|
||||
assert.equal(res.status, 200, `the page's send was accepted: ${res.status}`);
|
||||
return waitOnce(s.sid, 10);
|
||||
}
|
||||
const finishUp = (s) => postPatch(s, { finish: { headline: "Done", command: "/plan2code" } });
|
||||
const done = (s) => cli(["stop", "--session", s.sid, "--force"]);
|
||||
|
||||
/* ------------------------------------------- every moment names its file */
|
||||
|
||||
test("pointer: __commit names console-finish.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const { code, out } = await send(s, [{ i: "__commit", type: "commit" }]);
|
||||
assert.equal(code, 0);
|
||||
assert.deepEqual(out.read, [file("console-finish.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: __dashboard with a finish up names console-finish.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
finishUp(s);
|
||||
const { out } = await send(s, [{ i: "__dashboard", type: "dashboard" }]);
|
||||
assert.deepEqual(out.read, [file("console-finish.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: __stop names console-stop.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const { out } = await send(s, [{ i: "__stop", type: "stop" }]);
|
||||
assert.deepEqual(out.read, [file("console-stop.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: __stop with a handoff names console-stop.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const { out } = await send(s, [{ i: "__stop", type: "stop", handoff: true }]);
|
||||
assert.deepEqual(out.read, [file("console-stop.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: __dashboard with no finish up names console-stop.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const { out } = await send(s, [{ i: "__dashboard", type: "dashboard" }]);
|
||||
assert.deepEqual(out.read, [file("console-stop.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: the first post carrying docs names console-docs.md on post's own line", () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const first = postPatch(s, { docs: [{ id: "map", title: "Map", blocks: [{ id: "b1", state: "settled", md: "## One" }] }] });
|
||||
assert.deepEqual(first.json.read, [file("console-docs.md")]);
|
||||
assert.equal(first.json.ok, true);
|
||||
const plain = postPatch(s, { agent: { status: "working" } });
|
||||
assert.equal(plain.json.read, undefined, "a post with no docs names nothing");
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: the first Quick question names console-chat.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
assert.equal((await ask(s, "What does this do?")).status, 200);
|
||||
const { code, out } = waitOnce(s.sid, 10);
|
||||
assert.equal(code, 0);
|
||||
assert.deepEqual(out.read, [file("console-chat.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: a Workspace change names console-workspace.md", async () => {
|
||||
const s = fresh();
|
||||
const extra = tempFolder();
|
||||
try {
|
||||
assert.equal((await addFolder(s, { path: extra })).status, 200);
|
||||
const { out } = await send(s, [{ i: "q1", type: "answer", kind: "choice", k: "A" }]);
|
||||
assert.match(out.reply, /Workspace:/);
|
||||
assert.ok(out.read.includes(file("console-workspace.md")));
|
||||
} finally {
|
||||
done(s);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: a Subagents change names console-subagents.md", async () => {
|
||||
fs.rmSync(SUBAGENTS_STORE, { force: true });
|
||||
const s = fresh({ workflow: "implement" });
|
||||
try {
|
||||
const set = await s.send("/subagents", { on: false, instruction: null, max: 3 });
|
||||
assert.equal(set.status, 200);
|
||||
const { out } = await send(s, [{ i: "q1", type: "answer", kind: "choice", k: "A" }]);
|
||||
assert.match(out.reply, /Subagents: off/);
|
||||
assert.ok(out.read.includes(file("console-subagents.md")));
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: __review names building-review.md", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const { out } = await send(s, [{ i: "__review", type: "review" }]);
|
||||
assert.deepEqual(out.read, [file("building-review.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer: a review card answered with a verdict names building-review.md", async () => {
|
||||
const s = fresh({ workflow: "implement" });
|
||||
try {
|
||||
postPatch(s, {
|
||||
docs: [{ id: "report", title: "Report", blocks: [{ id: "b1", state: "settled", md: "## Report" }] }],
|
||||
items: [
|
||||
{
|
||||
id: "signoff",
|
||||
kind: "review",
|
||||
title: "Approve this phase",
|
||||
doc: "report",
|
||||
verdicts: [
|
||||
{ id: "review", label: "Review the code first" },
|
||||
{ id: "approve", label: "Approve" },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const { out } = await send(s, [{ i: "signoff", type: "answer", kind: "review", verdict: "review" }]);
|
||||
assert.deepEqual(out.read, [file("building-review.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------------- the memory rules */
|
||||
|
||||
test("pointer memory: the same moment a second time prints no read", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const first = await send(s, [{ i: "__stop", type: "stop" }]);
|
||||
assert.deepEqual(first.out.read, [file("console-stop.md")]);
|
||||
// The page is back on the person's turn after the agent posts again.
|
||||
postPatch(s, { items: [{ id: "q2", kind: "text", title: "Anything else", body: "Say it." }] });
|
||||
const second = await send(s, [{ i: "__stop", type: "stop" }]);
|
||||
assert.equal(second.out.read, undefined, "console-stop.md was named once already");
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer memory: it lives in pointers.json in the session folder, never in state.json", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
await send(s, [{ i: "__stop", type: "stop" }]);
|
||||
const saved = JSON.parse(fs.readFileSync(path.join(s.session, "pointers.json"), "utf8"));
|
||||
assert.deepEqual(saved.printed, ["stop"]);
|
||||
assert.ok(!JSON.stringify(readState(s.session)).includes("pointers"), "state.json has no pointer key");
|
||||
const frame = await (await fetch(`${s.base}/state`, { headers: { cookie: s.cookie, connection: "close" } })).text();
|
||||
assert.ok(!frame.includes("pointers"), "the page's frame never carries pointers");
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer memory: open --resume starts the reading over", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
assert.deepEqual((await send(s, [{ i: "__stop", type: "stop" }])).out.read, [file("console-stop.md")]);
|
||||
const back = cli(["open", "--resume", s.sid, "--workflow", "pathfinder", "--no-open"]);
|
||||
assert.equal(back.json.sid, s.sid);
|
||||
assert.equal(fs.existsSync(path.join(s.session, "pointers.json")), false, "a resume forgets what was printed");
|
||||
postPatch(s, { items: [{ id: "q3", kind: "text", title: "Once more", body: "Say it." }] });
|
||||
const again = await send(s, [{ i: "__stop", type: "stop" }]);
|
||||
assert.deepEqual(again.out.read, [file("console-stop.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
test("pointer memory: two moments due at once print both, each once", async () => {
|
||||
const s = fresh();
|
||||
try {
|
||||
const { out } = await send(s, [
|
||||
{ i: "__review", type: "review" },
|
||||
{ i: "__stop", type: "stop" },
|
||||
]);
|
||||
assert.deepEqual(out.read, [file("building-review.md"), file("console-stop.md")]);
|
||||
} finally {
|
||||
done(s);
|
||||
}
|
||||
});
|
||||
|
||||
/* ------------------------------------------- the pure part, with no server */
|
||||
|
||||
const noFlags = { workspaceChanged: false, subagentsChanged: false };
|
||||
|
||||
test("pointersForSend: the whole table", () => {
|
||||
const withFinish = { finish: { headline: "Done" }, items: [] };
|
||||
const empty = { items: [] };
|
||||
const act = (...as) => ({ actions: as });
|
||||
assert.deepEqual(pointersForSend(act({ i: "__commit" }), empty, noFlags), ["finish"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "__dashboard" }), withFinish, noFlags), ["finish"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "__dashboard" }), empty, noFlags), ["stop"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "__stop" }), empty, noFlags), ["stop"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "__stop", handoff: true }), empty, noFlags), ["stop"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "__review" }), empty, noFlags), ["review"]);
|
||||
const reviewCard = { items: [{ id: "signoff", kind: "review" }] };
|
||||
assert.deepEqual(pointersForSend(act({ i: "signoff", type: "answer", verdict: "review" }), reviewCard, noFlags), ["review"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "signoff", type: "answer", answer: { verdict: "approve" } }), reviewCard, noFlags), ["review"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "signoff", type: "answer" }), reviewCard, noFlags), [], "a review card with no verdict names nothing");
|
||||
assert.deepEqual(pointersForSend(act({ i: "q1", type: "answer", verdict: "x" }), { items: [{ id: "q1", kind: "choice" }] }, noFlags), []);
|
||||
assert.deepEqual(pointersForSend({}, empty, noFlags, [{ kind: "message", seq: 1 }]), ["chat"]);
|
||||
assert.deepEqual(pointersForSend({}, empty, noFlags, [{ kind: "decision", seq: 1 }]), [], "only a typed message names the chat file");
|
||||
assert.deepEqual(pointersForSend({}, empty, { workspaceChanged: true, subagentsChanged: true }), ["workspace", "subagents"]);
|
||||
assert.deepEqual(pointersForSend(act({ i: "__stop" }, { i: "__stop" }), empty, noFlags), ["stop"], "a topic appears once");
|
||||
assert.deepEqual(pointersForSend(null, null, null), []);
|
||||
});
|
||||
|
||||
test("duePointers, rememberPointers and resetPointers keep one memory per session folder", () => {
|
||||
const dir = fs.mkdtempSync(path.join(HOME, "pointers-"));
|
||||
try {
|
||||
assert.deepEqual(duePointers(dir, ["stop", "chat"]), [file("console-stop.md"), file("console-chat.md")]);
|
||||
rememberPointers(dir, ["stop", "not-a-topic"]);
|
||||
assert.deepEqual(duePointers(dir, ["stop", "chat"]), [file("console-chat.md")], "printed topics drop out");
|
||||
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(dir, "pointers.json"), "utf8")).printed, ["stop"], "an unknown topic is never recorded");
|
||||
fs.writeFileSync(path.join(dir, "pointers.json"), "{ not json");
|
||||
assert.deepEqual(duePointers(dir, ["stop"]), [file("console-stop.md")], "an unreadable memory reads as nothing printed");
|
||||
rememberPointers(dir, ["chat"]);
|
||||
resetPointers(dir);
|
||||
assert.deepEqual(duePointers(dir, ["stop", "chat"]), [file("console-stop.md"), file("console-chat.md")]);
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("every pointer file exists beside the console", () => {
|
||||
for (const name of Object.values(POINTER_FILES)) assert.ok(fs.existsSync(file(name)), `${name} exists`);
|
||||
});
|
||||
@@ -50,7 +50,7 @@ test("settle: true records the send wait handed over, never a later one still un
|
||||
assert.equal(items.find((i) => i.id === "q1").status, "answered");
|
||||
assert.equal(items.find((i) => i.id === "q2").status, "open", "q2's send is not the agent's yet");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -90,7 +90,7 @@ test("a notice never takes one of the three question slots", () => {
|
||||
|
||||
test("agent.status is working or waiting, nothing else", () => {
|
||||
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), agent: { status: "sleeping" } };
|
||||
assert.ok(validate(state).some((p) => p.includes('"agent.status"')));
|
||||
assert.ok(validate(state).some((p) => p.startsWith("agent.status:")));
|
||||
});
|
||||
|
||||
test("an approved sign-off does not stop the next phase asking for its own", () => {
|
||||
@@ -114,7 +114,7 @@ test("an unanswered note blocks a settle that ignores it", () => {
|
||||
};
|
||||
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), items: [withNote] };
|
||||
const next = applyPatch(state, { settle: ["q1"] });
|
||||
assert.ok(validate(next).some((p) => p.includes('item "q1" has an unanswered note')));
|
||||
assert.ok(validate(next).some((p) => p.includes('item "q1" thread: has an unanswered note')));
|
||||
});
|
||||
|
||||
test("adding a thread reply in the same patch clears the note and allows the settle", () => {
|
||||
@@ -170,7 +170,7 @@ test("post --file reads a patch PowerShell wrote: a UTF-8 BOM, or UTF-16", () =>
|
||||
assert.equal(runCli(["post", "--session", s.sid, "--file", u16]).status, 0);
|
||||
assert.equal(readState(s.session).agent.activity, "From UTF-16");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -180,10 +180,10 @@ test("wait and stop find a session's server from any folder, not only its projec
|
||||
try {
|
||||
const waited = runCli(["wait", "--session", s.sid, "--seconds", "1"], { cwd: elsewhere });
|
||||
assert.notEqual(waited.status, 20, "the server is alive: " + waited.stdout);
|
||||
const stopped = runCli(["stop", "--session", s.sid], { cwd: elsewhere });
|
||||
const stopped = runCli(["stop", "--session", s.sid, "--force"], { cwd: elsewhere });
|
||||
assert.equal(JSON.parse(stopped.stdout).stopped, 1, stopped.stdout);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(elsewhere, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -208,7 +208,7 @@ test("keep refuses a --from file outside the project, and keeps one copy per upl
|
||||
fs.rmSync(path.join(ROOT, spec), { recursive: true, force: true });
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -293,7 +293,7 @@ test("a patch that is valid JSON but not one object is refused (exit 2), never m
|
||||
}
|
||||
assert.ok(!("0" in readState(s.session)), "no junk keys in the state");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -80,14 +80,14 @@ test("the page carries its first state, title and badge, so the first paint need
|
||||
assert.ok(html.includes('<span class="badge" id="badge">Building</span>'));
|
||||
assert.ok(html.includes("Starting Implement"), "the static starting screen names the skill");
|
||||
assert.ok(html.includes('rel="modulepreload" href="/app.js"'));
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
});
|
||||
|
||||
test("open without --title names the session after the project folder", () => {
|
||||
const res = cli(["open", "--workflow", "pathfinder", "--no-open"]);
|
||||
const state = JSON.parse(fs.readFileSync(path.join(res.json.session, "state.json"), "utf8"));
|
||||
assert.equal(state.title, path.basename(ROOT));
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
});
|
||||
|
||||
// A saved dark theme and accent used to flash the default light accent for as
|
||||
@@ -110,7 +110,7 @@ test("saved looks are painted by the server before any script runs", async () =>
|
||||
assert.ok(!css.includes(`data-looks-accent="${DEFAULT_ACCENT}"`), "the default needs no rule");
|
||||
const boot = JSON.parse(html.match(/id="boot">([\s\S]*?)<\/script>/)[1]);
|
||||
assert.equal(boot.looks.accent, "violet");
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
} finally {
|
||||
if (before) fs.writeFileSync(looksFile, before);
|
||||
else fs.rmSync(looksFile, { force: true });
|
||||
@@ -129,7 +129,7 @@ test("static assets revalidate with an ETag instead of downloading again", async
|
||||
await first.arrayBuffer();
|
||||
const again = await fetch(m[1] + "/app.js", { headers: { cookie, "if-none-match": etag } });
|
||||
assert.equal(again.status, 304);
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
});
|
||||
|
||||
// The page drew from the inline state; the stream's opening frame would only
|
||||
@@ -173,7 +173,7 @@ test("the stream skips its opening frame only when the page already has that exa
|
||||
await sleep(1200);
|
||||
const still = await (await fetch(m[1] + "/state", { headers: { cookie } })).json();
|
||||
assert.doesNotMatch(await firstChunk(still.have), /event: state/, "the page's own key: skipped");
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
});
|
||||
|
||||
// `open` binds the port and sends the browser before the server has booted.
|
||||
@@ -227,7 +227,7 @@ test("the card-width presets validate a saved width and fall back to comfortable
|
||||
assert.equal(DEFAULT_CARD_WIDTH, "comfortable");
|
||||
assert.deepEqual(
|
||||
Object.values(CARD_WIDTHS).map((w) => w.px),
|
||||
[720, 880, 1080]
|
||||
[720, 880, 1080, 1440]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -360,6 +360,8 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
const kept = [
|
||||
file("looks.json"),
|
||||
file("workspaces.json"),
|
||||
file("loop-setup.json"),
|
||||
file("loop-reports.json"),
|
||||
file("subagents.json"),
|
||||
file("pr-hosts.json"),
|
||||
file("console-dir"),
|
||||
@@ -375,7 +377,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
const stale = staleScratch(dir, Date.now(), SESSION_MAX_AGE_MS).sort();
|
||||
assert.deepEqual(stale, ["helper.mjs", "p2.json"]);
|
||||
assert.deepEqual(
|
||||
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "subagents.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
|
||||
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "loop-reports.json", "subagents.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
|
||||
["helper.mjs", "p2.json"]
|
||||
);
|
||||
for (const p of removable) assert.equal(fs.existsSync(p), false, p);
|
||||
@@ -383,6 +385,8 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
|
||||
assert.deepEqual([...PROTECTED_CONSOLE_FILES].sort(), [
|
||||
"console-dir",
|
||||
"looks.json",
|
||||
"loop-reports.json",
|
||||
"loop-setup.json",
|
||||
"pr-hosts.json",
|
||||
"subagents.json",
|
||||
"update-check.json",
|
||||
@@ -662,7 +666,7 @@ test("GET /overview serves the session's spec, and on the dashboard only a scann
|
||||
assert.equal((await get(d, "?spec=specs/c")).status, 204, "no overview.md yet");
|
||||
assert.equal((await get(d, "?spec=specs/c&file=nope")).status, 204);
|
||||
} finally {
|
||||
for (const s of sids) cliIn(root, ["stop", "--session", s]);
|
||||
for (const s of sids) cliIn(root, ["stop", "--session", s, "--force"]);
|
||||
fs.rmSync(base, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -683,32 +687,28 @@ test("open records worktree and branch, and wakes only a freshly opened dashboar
|
||||
cli(["open", "--resume", dash.json.sid, "--no-open"]);
|
||||
assert.equal("wake" in readState(dash.json.session), false);
|
||||
} finally {
|
||||
cli(["stop", "--session", dash.json.sid]);
|
||||
cli(["stop", "--session", dash.json.sid, "--force"]);
|
||||
}
|
||||
|
||||
const plan = cli(["open", "--workflow", "plan", "--no-open"]);
|
||||
assert.equal("wake" in readState(plan.json.session), false);
|
||||
cli(["stop", "--session", plan.json.sid]);
|
||||
cli(["stop", "--session", plan.json.sid, "--force"]);
|
||||
});
|
||||
|
||||
test("open reports a month-old session under swept and removes it after printing", async () => {
|
||||
const quiet = cli(["open", "--workflow", "plan", "--no-open"]);
|
||||
assert.equal("swept" in quiet.json, false, "nothing old, nothing reported");
|
||||
cli(["stop", "--session", quiet.json.sid]);
|
||||
|
||||
test("open removes a month-old session without printing it", async () => {
|
||||
const oldSid = "20250101-101010-abcdef";
|
||||
const oldDir = path.join(HOME, "sessions", oldSid);
|
||||
fs.mkdirSync(oldDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(oldDir, "state.json"), "{}");
|
||||
backdate(path.join(oldDir, "state.json"));
|
||||
const res = cli(["open", "--workflow", "plan", "--no-open"]);
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
assert.deepEqual(res.json.swept.sessions, [oldSid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
assert.equal("swept" in res.json, false, "the sweep is housekeeping, not output");
|
||||
for (let i = 0; i < 20 && fs.existsSync(oldDir); i++) await new Promise((r) => setTimeout(r, 100));
|
||||
assert.equal(fs.existsSync(oldDir), false);
|
||||
});
|
||||
|
||||
test("open reports a month-old handoff under swept.handoffs and removes both its files", async () => {
|
||||
test("open removes a month-old handoff and both its files without printing them", async () => {
|
||||
const id = "2025-01-01-0900-handoff";
|
||||
fs.mkdirSync(HANDOFFS_DIR, { recursive: true });
|
||||
const files = [path.join(HANDOFFS_DIR, id + ".md"), path.join(HANDOFFS_DIR, id + ".json")];
|
||||
@@ -716,24 +716,23 @@ test("open reports a month-old handoff under swept.handoffs and removes both its
|
||||
fs.writeFileSync(files[1], "{}");
|
||||
for (const f of files) backdate(f);
|
||||
const res = cli(["open", "--workflow", "plan", "--no-open"]);
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
assert.deepEqual(res.json.swept.handoffs, [id]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
assert.equal("swept" in res.json, false, "the sweep is housekeeping, not output");
|
||||
for (let i = 0; i < 20 && files.some((f) => fs.existsSync(f)); i++) await new Promise((r) => setTimeout(r, 100));
|
||||
assert.deepEqual(files.filter((f) => fs.existsSync(f)), []);
|
||||
});
|
||||
|
||||
test("post and wait hand back the terminal line; the collected result on disk does not carry it", async () => {
|
||||
test("open prints the terminal line; post and wait leave it out until it changes; the collected result on disk does not carry it", async () => {
|
||||
const res = cli(["open", "--file", payload("tl.json", BASE), "--no-open"]);
|
||||
const s = sessionUrl(res.json.url);
|
||||
try {
|
||||
const posted = cli(["post", "--session", res.json.sid, "--file", payload("tl2.json", { agent: { status: "waiting" } })]);
|
||||
assert.equal(posted.json.terminalLine, terminalLine(res.json.url));
|
||||
assert.equal(res.json.terminalLine, terminalLine(res.json.url));
|
||||
assert.equal("terminalLine" in posted.json, false, "unchanged, so not repeated");
|
||||
|
||||
const waiting = cli(["wait", "--session", res.json.sid, "--seconds", "5"]);
|
||||
assert.equal(waiting.status, 10);
|
||||
assert.equal(waiting.json.message, "Waiting on your answer in the web console");
|
||||
assert.match(waiting.json.next, /run this same wait command again/);
|
||||
assert.equal(waiting.json.terminalLine, terminalLine(res.json.url));
|
||||
assert.deepEqual(waiting.json, { waiting: true, open: 1 });
|
||||
|
||||
const sent = await fetch(`${s.base}/submit`, {
|
||||
method: "POST",
|
||||
@@ -743,7 +742,8 @@ test("post and wait hand back the terminal line; the collected result on disk do
|
||||
assert.equal(sent.status, 200);
|
||||
const done = cli(["wait", "--session", res.json.sid, "--seconds", "10"]);
|
||||
assert.equal(done.status, 0);
|
||||
assert.equal(done.json.terminalLine, terminalLine(res.json.url));
|
||||
assert.equal("terminalLine" in done.json, false);
|
||||
assert.equal(done.json.reply, "Export format: a");
|
||||
const onDisk = JSON.parse(fs.readFileSync(path.join(res.json.session, "result.json"), "utf8"));
|
||||
assert.equal("terminalLine" in onDisk, false);
|
||||
assert.ok(onDisk.consumedAt);
|
||||
@@ -752,25 +752,24 @@ test("post and wait hand back the terminal line; the collected result on disk do
|
||||
assert.equal(js.status, 200);
|
||||
assert.match(js.headers.get("content-type"), /javascript/);
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("notes/quick-task.md has a quick-task build tick the Plan tab's steps live", () => {
|
||||
const md = fs.readFileSync(path.join(ROOT, "src", "web-console", "notes", "quick-task.md"), "utf8");
|
||||
const section = md.slice(md.indexOf("## Quick task (`quick-task`)"), md.indexOf("## Stop requests during a build"));
|
||||
assert.ok(!section.includes('"title": "Build progress"'), "no separate progress tab");
|
||||
assert.match(section, /post after every step/i);
|
||||
assert.ok(section.includes('{ "id": "steps", "state": "settled", "md": "## Steps\\n\\n- [ ] **1.**'), "the plan's Steps start as a checklist");
|
||||
assert.ok(section.includes('"docs": [{ "id": "plan", "blocks": [\n { "id": "steps"'), "a step post reposts the plan's steps block, its version moving by itself");
|
||||
const section = md;
|
||||
assert.ok(!section.includes('"title":"Build progress"'), "no separate progress tab");
|
||||
assert.match(section, /After each step/);
|
||||
assert.ok(section.includes('{"id":"steps","state":"settled","md":"## Steps\\n\\n- [ ] **1.**'), "the plan's Steps start as a checklist");
|
||||
assert.ok(section.includes('"docs":[{"id":"plan","blocks":[{"id":"steps"'), "a step post reposts the plan's steps block, its version moving by itself");
|
||||
assert.ok(section.includes("- [x] **1.** Step one"));
|
||||
});
|
||||
|
||||
test("notes/quick-task.md has the finished quick task offer Back to the dashboard as well as the review", () => {
|
||||
const md = fs.readFileSync(path.join(ROOT, "src", "web-console", "notes", "quick-task.md"), "utf8");
|
||||
const section = md.slice(md.indexOf("## Quick task (`quick-task`)"));
|
||||
const bullet = section.slice(section.indexOf("**The finish after the build:**"), section.indexOf("**Escalated / aborted:**"));
|
||||
assert.ok(bullet.includes('"dashboard": true'));
|
||||
const bullet = md.slice(md.indexOf("**Finish after the build:**"), md.indexOf("**Escalated / aborted:**"));
|
||||
assert.ok(bullet.includes('"dashboard":true'));
|
||||
assert.ok(bullet.includes("Review it now"));
|
||||
});
|
||||
|
||||
@@ -795,7 +794,7 @@ test("an image block under the session's shots folder round-trips, and /shots/ s
|
||||
const jargon = { docs: [{ id: "shown", blocks: [{ id: "s1", image: "shots/home-page.png", alt: "Grilling the home page" }] }] };
|
||||
const refused = cli(["post", "--session", res.json.sid, "--file", payload("shots-jargon.json", jargon)], { expectFail: true });
|
||||
assert.equal(refused.status, 3);
|
||||
assert.match(refused.stderr, /alt text contains internal vocabulary/);
|
||||
assert.match(refused.stderr, /alt: contains internal vocabulary/);
|
||||
// A changed picture or caption is a new version of the doc.
|
||||
const before = readState(res.json.session).docs.find((d) => d.id === "shown").version;
|
||||
const recaption = { docs: [{ id: "shown", blocks: [{ id: "s1", image: "shots/home-page.png", alt: "The home page, after the fix" }] }] };
|
||||
@@ -826,7 +825,7 @@ test("an image block under the session's shots folder round-trips, and /shots/ s
|
||||
assert.equal(await raw(p), 404, p);
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -864,7 +863,7 @@ test("/app.css is the style files joined in CSS_ORDER with the accent rules last
|
||||
await own.arrayBuffer();
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -884,7 +883,7 @@ test("the built skills tree serves the same /app.css as the source console", asy
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(await res.text(), asset("app.css").body.toString("utf8"));
|
||||
} finally {
|
||||
execFileSync(process.execPath, [path.join(built, "console.mjs"), "stop", "--session", json.sid], { env: ENV, cwd: ROOT });
|
||||
execFileSync(process.execPath, [path.join(built, "console.mjs"), "stop", "--session", json.sid, "--force"], { env: ENV, cwd: ROOT });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -917,6 +916,6 @@ test("/open-link takes an http or https link and refuses every other kind", asyn
|
||||
});
|
||||
assert.notEqual(foreign.status, 200, "another site's page cannot open links through the console");
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
cli(["stop", "--session", res.json.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -33,6 +33,10 @@ import {
|
||||
import { CHAT_LIMIT, CHAT_MAX_CHARS } from "../src/web-console/public/chat.js";
|
||||
import { ACCENTS, CARD_WIDTHS, SOUND_EVENTS, soundKey, soundPrefs } from "../src/web-console/public/palette.js";
|
||||
import { HELP_TABS, helpTabFor, helpKeyTarget } from "../src/web-console/public/help.js";
|
||||
import { tabKeyTarget } from "../src/web-console/public/tabs.js";
|
||||
import { PREFS_TABS, prefsOpenTab, prefsResetScope } from "../src/web-console/public/prefs.js";
|
||||
import { DEFAULT_LOOKS, looks, resetLooks } from "../src/web-console/public/looks.js";
|
||||
import { ROLE_NOT_SET } from "../src/web-console/public/starters.js";
|
||||
import { RED_AT, YELLOW_AT } from "../src/web-console/public/meter.js";
|
||||
import { REMOTE_FOLD } from "../src/web-console/public/git-board.js";
|
||||
import { readLedger, SESSION_MAX_AGE_MS, sweepUploads, UPLOAD_MAX_AGE_MS } from "../src/web-console/sessions.mjs";
|
||||
@@ -122,11 +126,14 @@ test("the page is served with a CSP that forbids inline script", async () => {
|
||||
assert.ok(csp.includes("media-src 'self'"));
|
||||
});
|
||||
|
||||
// result.json keeps the whole send; the agent's output carries only `reply`,
|
||||
// the `__` session actions and the hop fields.
|
||||
const sentActions = () => JSON.parse(fs.readFileSync(path.join(session, "result.json"), "utf8")).actions;
|
||||
|
||||
test("wait returns 10 with a progress summary while nobody has answered", () => {
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "5"]);
|
||||
assert.equal(res.status, 10);
|
||||
assert.equal(res.json.status, "waiting");
|
||||
assert.equal(res.json.total, 1);
|
||||
assert.deepEqual(res.json, { waiting: true, open: 1 }, "nothing else rides on a quiet slice");
|
||||
});
|
||||
|
||||
test("a submit round-trips to the agent with the literal reply token", async () => {
|
||||
@@ -136,9 +143,11 @@ test("a submit round-trips to the agent with the literal reply token", async ()
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.type, "submit");
|
||||
assert.equal(res.json.reply, "Export format: b");
|
||||
assert.equal(res.json.actions[0].k, "B");
|
||||
for (const dropped of ["type", "at", "sid", "rev", "consumedAt", "actions"]) assert.equal(res.json[dropped], undefined, `${dropped} stays in result.json`);
|
||||
const kept = JSON.parse(fs.readFileSync(path.join(session, "result.json"), "utf8"));
|
||||
assert.equal(kept.type, "submit");
|
||||
assert.equal(kept.actions[0].k, "B");
|
||||
});
|
||||
|
||||
test("a collected answer is written to the meter ledger once, and a button press is not", async () => {
|
||||
@@ -176,8 +185,8 @@ test("a brief request round-trips with a range the playbook can read", async ()
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].type, "brief");
|
||||
assert.equal(res.json.actions[0].range, "since 2026-09-15");
|
||||
assert.equal(res.json.session[0].i, "__brief");
|
||||
assert.equal(res.json.session[0].range, "since 2026-09-15");
|
||||
assert.match(res.json.reply, /since 2026-09-15/);
|
||||
|
||||
// `__brief` is not an item, so nothing on the board may have been touched.
|
||||
@@ -195,7 +204,7 @@ test("a review request round-trips without touching any question", async () => {
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].i, "__review");
|
||||
assert.equal(res.json.session[0].i, "__review");
|
||||
assert.equal(res.json.reply, REVIEW_REPLY);
|
||||
const state = JSON.parse(fs.readFileSync(path.join(session, "state.json"), "utf8"));
|
||||
assert.ok(state.items.every((i) => i.id !== "__review"), "a review request must not become a question");
|
||||
@@ -212,9 +221,10 @@ test("a launch request round-trips with the skill the dashboard resumes as", asy
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].i, "__launch");
|
||||
assert.equal(res.json.actions[0].skill, "plan2code-3-implement");
|
||||
assert.equal(res.json.actions[0].workflow, "implement");
|
||||
assert.equal(res.json.session[0].i, "__launch");
|
||||
assert.equal(res.json.session[0].skill, "plan2code-3-implement");
|
||||
assert.equal(res.json.session[0].workflow, "implement");
|
||||
assert.match(res.json.resume, /--no-open --workflow implement$/);
|
||||
const state = JSON.parse(fs.readFileSync(path.join(session, "state.json"), "utf8"));
|
||||
assert.ok(state.items.every((i) => i.id !== "__launch"), "a launch must not become a question");
|
||||
});
|
||||
@@ -228,7 +238,7 @@ test("a launch sent from a finished screen carries the resume for the next skill
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].i, "__launch");
|
||||
assert.equal(res.json.session[0].i, "__launch");
|
||||
assert.match(res.json.resume, /--no-open --workflow document --spec specs\/lunch-vote$/);
|
||||
});
|
||||
|
||||
@@ -263,8 +273,8 @@ test("a delete request round-trips with the spec folder and no resume", async ()
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].i, "__delete");
|
||||
assert.equal(res.json.actions[0].spec, "specs/lunch-vote");
|
||||
assert.equal(res.json.session[0].i, "__delete");
|
||||
assert.equal(res.json.session[0].spec, "specs/lunch-vote");
|
||||
assert.equal(res.json.resume, undefined);
|
||||
assert.equal(res.json.skillFile, undefined);
|
||||
const state = JSON.parse(fs.readFileSync(path.join(session, "state.json"), "utf8"));
|
||||
@@ -289,7 +299,7 @@ test("a dashboard request round-trips and the session resumes as the dashboard",
|
||||
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.deepEqual(res.json.actions, [{ i: "__dashboard", type: "dashboard" }]);
|
||||
assert.deepEqual(res.json.session, [{ i: "__dashboard" }]);
|
||||
assert.equal(res.json.reply, DASHBOARD_REPLY);
|
||||
const after = readState();
|
||||
assert.ok(after.items.every((i) => i.id !== "__dashboard"), "a dashboard request must not become a question");
|
||||
@@ -409,11 +419,8 @@ test("a stop request carries the staged answers, reaches the agent as a send, an
|
||||
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "5"]);
|
||||
assert.equal(res.status, 0, "a stop is a send, not a cancel");
|
||||
assert.deepEqual(
|
||||
res.json.actions.map((a) => a.type),
|
||||
["answer", "stop"],
|
||||
"the answers and the stop arrive together"
|
||||
);
|
||||
assert.deepEqual(res.json.session, [{ i: "__stop" }], "the stop arrives whole, the answer in reply");
|
||||
assert.match(res.json.reply, /^Export format: b/, "the staged answer arrives with it");
|
||||
assert.equal((await ping()).pendingStop, false);
|
||||
});
|
||||
|
||||
@@ -430,7 +437,7 @@ test("a handoff stop keeps its flag, reports as a stop until collected, and name
|
||||
assert.equal((await ping()).pendingStop, true, "an uncollected handoff stop shows on the heartbeat");
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "5"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].handoff, true, "the flag reaches the agent");
|
||||
assert.equal(res.json.session[0].handoff, true, "the flag reaches the agent");
|
||||
assert.equal(res.json.handoffSkill, undefined, "no built skill beside the source tree");
|
||||
assert.equal((await ping()).pendingStop, false);
|
||||
});
|
||||
@@ -453,7 +460,8 @@ test("a mid-workflow way home carries the staged answers and resumes as the dash
|
||||
assert.equal(res.status, 200);
|
||||
const got = cli(["wait", "--session", sid, "--seconds", "5"]);
|
||||
assert.equal(got.status, 0, "the way home is a send, not a cancel");
|
||||
assert.deepEqual(got.json.actions.map((a) => a.type), ["answer", "dashboard"], "the answers and the way home arrive together");
|
||||
assert.deepEqual(got.json.session, [{ i: "__dashboard" }], "the way home arrives whole, the answer in reply");
|
||||
assert.match(got.json.reply, /^Export format: a/, "the staged answer arrives with it");
|
||||
assert.ok(got.json.reply.endsWith(HOME_REPLY));
|
||||
|
||||
cli(["open", "--resume", sid, "--no-open", "--workflow", "dashboard"]);
|
||||
@@ -520,12 +528,11 @@ test("the way home cannot be mistaken for a brief request", () => {
|
||||
test("console-stop.md, building.md and the dashboard prompt teach the mid-workflow way home", () => {
|
||||
const read = (...p) => fs.readFileSync(path.join(ROOT, ...p), "utf8");
|
||||
const stopMd = read("src", "web-console", "console-stop.md");
|
||||
assert.ok(stopMd.includes("## Back to the dashboard, mid-workflow"));
|
||||
assert.ok(stopMd.includes(HOME_REPLY), "console-stop.md quotes the reply line the agent will see");
|
||||
assert.match(stopMd, /No `finish` and no `stop` in between/);
|
||||
assert.ok(stopMd.includes("## Stop with a handoff"));
|
||||
assert.ok(stopMd.includes("## `__dashboard` with no finish up (home, mid-workflow)"));
|
||||
assert.match(stopMd, /No `finish` and no `stop`: the menu is the ending/);
|
||||
assert.ok(stopMd.includes("## `__stop` with a handoff"));
|
||||
for (const word of ["handoff new", "--from-stop", "handoffSkill"]) assert.ok(stopMd.includes(word), `console-stop.md names ${word}`);
|
||||
assert.match(read("src", "web-console", "console.md"), /`__stop` \(plain, or with `handoff: true`\), `__dashboard` \(no finish up\) \| `console-stop\.md`/, "console.md's action table sends a handoff stop and a mid-workflow __dashboard there");
|
||||
assert.match(read("src", "web-console", "console.md"), /`__stop`, `__dashboard`[^\n]*covered by the topic file `read` names/, "the card hands a stop and a dashboard press to the topic file its pointer names");
|
||||
assert.ok(read("src", "web-console", "building.md").includes("mid-build `__dashboard`"));
|
||||
assert.ok(read("src", "plan2code.md").includes("mid-workflow from the top bar's triangle"));
|
||||
});
|
||||
@@ -536,7 +543,7 @@ test("console-launches.md and the dashboard prompt teach the handoff pick-up and
|
||||
for (const word of ["__pickup", "handoffFile", "delete-handoff", "handoffsDir", "fallback"]) {
|
||||
assert.ok(launches.includes(word), `console-launches.md names ${word}`);
|
||||
}
|
||||
assert.ok(launches.includes("handoffs, handoffsDir"), "console-launches.md lists the scan fields");
|
||||
assert.ok(launches.includes("handoffs,handoffsDir"), "console-launches.md lists the scan fields");
|
||||
const prompt = read("src", "plan2code.md");
|
||||
for (const word of ["__pickup", "delete-handoff"]) assert.ok(prompt.includes(word), `src/plan2code.md names ${word}`);
|
||||
});
|
||||
@@ -644,12 +651,14 @@ test("the favicon is served as an SVG with a PNG fallback and the page points at
|
||||
/* ---------------------------------------------------------------- help */
|
||||
|
||||
|
||||
test("help: 19 tabs with unique ids", () => {
|
||||
assert.equal(HELP_TABS.length, 19);
|
||||
assert.equal(new Set(HELP_TABS.map((t) => t.id)).size, 19);
|
||||
test("help: 20 tabs with unique ids", () => {
|
||||
assert.equal(HELP_TABS.length, 20);
|
||||
assert.equal(new Set(HELP_TABS.map((t) => t.id)).size, 20);
|
||||
assert.ok(Object.isFrozen(HELP_TABS) && HELP_TABS.every((t) => Object.isFrozen(t)), "the tab list is frozen");
|
||||
const ids = HELP_TABS.map((t) => t.id);
|
||||
assert.equal(ids.indexOf("git"), ids.indexOf("build") + 1, "The git board comes right after Watching a build");
|
||||
assert.equal(ids.indexOf("loop"), ids.indexOf("build") + 1, "Implementation Loop comes right after Watching a build");
|
||||
assert.equal(HELP_TABS[ids.indexOf("loop")].label, "Implementation Loop");
|
||||
assert.equal(ids.indexOf("git"), ids.indexOf("loop") + 1, "The git board comes right after Implementation Loop");
|
||||
assert.equal(HELP_TABS[ids.indexOf("git")].label, "The git board");
|
||||
assert.equal(helpTabFor({ workflow: "git" }), "git");
|
||||
assert.equal(ids.indexOf("activities"), ids.indexOf("ask") + 1, "Activities comes right after Ask a quick question");
|
||||
@@ -789,6 +798,64 @@ test("help: helpKeyTarget moves, wraps and jumps", () => {
|
||||
assert.equal(helpKeyTarget("a", 3, n), -1);
|
||||
});
|
||||
|
||||
test("tabs: tabKeyTarget is Help's key rule, shared under both names", () => {
|
||||
assert.equal(helpKeyTarget, tabKeyTarget, "help.js re-exports the shared function");
|
||||
const n = 4;
|
||||
for (const [key, from, to] of [["ArrowDown", 3, 0], ["ArrowRight", 1, 2], ["ArrowUp", 0, 3], ["ArrowLeft", 2, 1], ["Home", 2, 0], ["End", 0, 3]]) {
|
||||
assert.equal(tabKeyTarget(key, from, n), to, `${key} from ${from}`);
|
||||
}
|
||||
assert.equal(tabKeyTarget("Enter", 1, n), -1);
|
||||
});
|
||||
|
||||
test("prefs: four tabs in order, each section in exactly one", () => {
|
||||
assert.deepEqual(PREFS_TABS.map((t) => t.id), ["appearance", "agents", "system", "sounds"]);
|
||||
assert.deepEqual(PREFS_TABS.map((t) => t.label), ["Appearance", "Agents & models", "System", "Sounds & activities"]);
|
||||
for (const t of PREFS_TABS) assert.ok(t.hint, `${t.id} has a hint`);
|
||||
const sections = PREFS_TABS.flatMap((t) => t.sections);
|
||||
assert.equal(new Set(sections).size, sections.length, "no section sits in two tabs");
|
||||
assert.deepEqual(PREFS_TABS[0].sections, ["theme", "width", "accent", "role"], "Appearance in its order");
|
||||
});
|
||||
|
||||
test("prefs: the dialog opens on the tab asked for, else Appearance", () => {
|
||||
for (const t of PREFS_TABS) assert.equal(prefsOpenTab(t.id), t.id);
|
||||
for (const asked of [undefined, "", "nope", "Appearance"]) assert.equal(prefsOpenTab(asked), "appearance", String(asked));
|
||||
});
|
||||
|
||||
test("prefs: Back to default resets Appearance or Sounds & activities only, and nothing on the other two", () => {
|
||||
assert.deepEqual(prefsResetScope("appearance"), ["theme", "width", "accent", "role"]);
|
||||
const sounds = prefsResetScope("sounds");
|
||||
assert.deepEqual(sounds, ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), "hideActivities", "activitySounds", "gameMusic"]);
|
||||
for (const key of [...prefsResetScope("appearance"), ...sounds]) {
|
||||
if (key !== "role") assert.ok(Object.hasOwn(DEFAULT_LOOKS, key), `${key} has a default`);
|
||||
}
|
||||
assert.equal(prefsResetScope("agents"), null);
|
||||
assert.equal(prefsResetScope("system"), null);
|
||||
assert.equal(prefsResetScope("nope"), null);
|
||||
});
|
||||
|
||||
test("looks: resetLooks(keys) changes only those keys, and the role is marked as asked", () => {
|
||||
const before = { ...looks };
|
||||
try {
|
||||
Object.assign(looks, { theme: "dark", width: "wide", accent: "violet", role: "pm", sound: false, soundQuestion: false, hideActivities: true, activityBestSnake: 7, lastActivity: "snake" });
|
||||
resetLooks(prefsResetScope("appearance"));
|
||||
assert.equal(looks.theme, DEFAULT_LOOKS.theme);
|
||||
assert.equal(looks.width, DEFAULT_LOOKS.width);
|
||||
assert.equal(looks.accent, DEFAULT_LOOKS.accent);
|
||||
assert.equal(looks.role, ROLE_NOT_SET, "cleared but marked as asked");
|
||||
assert.equal(looks.sound, false, "sounds untouched by Appearance");
|
||||
assert.equal(looks.hideActivities, true);
|
||||
resetLooks(prefsResetScope("sounds"));
|
||||
assert.equal(looks.sound, true);
|
||||
assert.equal(looks.soundQuestion, true);
|
||||
assert.equal(looks.hideActivities, false);
|
||||
assert.equal(looks.activityBestSnake, 7, "best scores stay");
|
||||
assert.equal(looks.lastActivity, "snake", "the last pick stays");
|
||||
} finally {
|
||||
for (const key of Object.keys(looks)) delete looks[key];
|
||||
Object.assign(looks, before);
|
||||
}
|
||||
});
|
||||
|
||||
// A constant's value from source text, for files the test cannot import. Only
|
||||
// products of integer literals are accepted, so nothing is ever evaluated.
|
||||
const productOf = (expr) =>
|
||||
@@ -957,7 +1024,7 @@ test("a send refuses comment images that are too many or not this session's uplo
|
||||
assert.equal(ok.status, 200);
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0, "collected, so the tests after this start with no send in flight");
|
||||
assert.equal(res.json.actions[0].images.length, 2);
|
||||
assert.equal(sentActions()[0].images.length, 2);
|
||||
});
|
||||
|
||||
test("a note with two images reaches the agent with both absolute paths, in the action and the reply", async () => {
|
||||
@@ -971,7 +1038,7 @@ test("a note with two images reaches the agent with both absolute paths, in the
|
||||
assert.equal(ok.status, 200);
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
const note = res.json.actions.find((x) => x.type === "comment");
|
||||
const note = sentActions().find((x) => x.type === "comment");
|
||||
assert.deepEqual(note.images, [
|
||||
{ path: a.path, name: "first.png" },
|
||||
{ path: b.path, name: "second.png" },
|
||||
@@ -1157,7 +1224,7 @@ test("a send takes documents as files, counts them with images, and keeps each k
|
||||
assert.equal(ok.status, 200);
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
const note = res.json.actions.find((x) => x.type === "comment");
|
||||
const note = sentActions().find((x) => x.type === "comment");
|
||||
assert.deepEqual(note.images, [i1, i2]);
|
||||
assert.deepEqual(note.files, [d1, d2, d3]);
|
||||
assert.match(res.json.reply, /^Note on Export format: \(attachments only\)$/m);
|
||||
@@ -1400,7 +1467,7 @@ test("a changelog request from a finished screen carries the resume into the cha
|
||||
});
|
||||
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.actions[0].i, "__changelog");
|
||||
assert.equal(res.json.session[0].i, "__changelog");
|
||||
assert.match(res.json.resume, /--no-open --workflow changelog$/);
|
||||
const state = JSON.parse(fs.readFileSync(path.join(session, "state.json"), "utf8"));
|
||||
assert.ok(state.items.every((i) => i.id !== "__changelog"), "a changelog request must not become a question");
|
||||
@@ -1420,7 +1487,7 @@ test("a thread reply in another shape is lifted into { who, text }, and an empty
|
||||
"aliases lifted, and the echoed note is not shown twice");
|
||||
assert.equal(thread[1].md, undefined);
|
||||
assert.equal(thread[1].from, undefined);
|
||||
assert.throws(() => applyPatch(base, { items: [{ id: "n1", thread: [{ who: "agent" }] }] }), /thread entry has no "text"/);
|
||||
assert.throws(() => applyPatch(base, { items: [{ id: "n1", thread: [{ who: "agent" }] }] }), /an entry has no "text"/);
|
||||
assert.throws(() => applyPatch(base, { items: [{ id: "n1", thread: [{ who: "agent", md: " " }] }] }), /no "text"/);
|
||||
});
|
||||
|
||||
@@ -1431,3 +1498,98 @@ test("the page reads older { from, md } thread entries", () => {
|
||||
assert.equal(threadText({ who: "agent", text: "Now." }), "Now.");
|
||||
assert.equal(threadText({ who: "agent" }), "");
|
||||
});
|
||||
|
||||
/* --------------------------------- output shape at each exit code (FR-1 to FR-3) */
|
||||
|
||||
test("the shape of every exit: 0 for an answer and a launch, 10, 30, 3 and 2", async (t) => {
|
||||
const opened = cli(["open", "--file", payload("shape-open.json", BASE), "--no-open"]);
|
||||
const s = opened.json;
|
||||
// open names the link; the very next post and wait do not repeat it.
|
||||
assert.equal(typeof s.terminalLine, "string");
|
||||
assert.ok(s.terminalLine.length > 0);
|
||||
const m = s.url.match(/^(http:\/\/127\.0\.0\.1:\d+)\/s\/([^/]+)\//);
|
||||
const sendTo = (pathname, body) =>
|
||||
fetch(m[1] + pathname, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json", cookie: cookieFor(m[1], m[2]), connection: "close" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
try {
|
||||
await t.test("post prints only ok and open, no terminalLine", () => {
|
||||
const res = cli(["post", "--session", s.sid, "--file", payload("shape-post.json", { headline: { stage: "Working" } })]);
|
||||
assert.deepEqual(Object.keys(res.json).sort(), ["ok", "open"]);
|
||||
});
|
||||
|
||||
await t.test("exit 10 is {waiting, open} and nothing else", () => {
|
||||
const res = cli(["wait", "--session", s.sid, "--seconds", "5"]);
|
||||
assert.equal(res.status, 10);
|
||||
assert.deepEqual(res.json, { waiting: true, open: 1 });
|
||||
});
|
||||
|
||||
await t.test("exit 0 for an answer: reply only, the rest stays in result.json", async () => {
|
||||
assert.equal((await sendTo("/submit", { actions: [{ i: "q1", type: "answer", kind: "choice", k: "B" }], reply: "Export format: b" })).status, 200);
|
||||
const res = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.deepEqual(res.json, { reply: "Export format: b" });
|
||||
const kept = JSON.parse(fs.readFileSync(path.join(s.session, "result.json"), "utf8"));
|
||||
for (const k of ["type", "at", "sid", "rev", "consumedAt", "actions"]) assert.ok(k in kept, `result.json keeps ${k}`);
|
||||
});
|
||||
|
||||
await t.test("exit 0 for a launch carries the session action whole, with resume", async () => {
|
||||
const send = { actions: [{ i: "__launch", type: "launch", skill: "plan2code-3-implement", workflow: "implement" }], reply: "Start Implement." };
|
||||
assert.equal((await sendTo("/submit", send)).status, 200);
|
||||
const res = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.session[0].i, "__launch");
|
||||
assert.match(res.json.resume, /--no-open --workflow implement$/);
|
||||
assert.equal(res.json.actions, undefined);
|
||||
assert.equal(res.json.terminalLine, undefined, "the link is not repeated");
|
||||
});
|
||||
|
||||
await t.test("exit 30 for a cancel", async () => {
|
||||
await sendTo("/cancel", {});
|
||||
const res = cli(["wait", "--session", s.sid, "--seconds", "5"]);
|
||||
assert.equal(res.status, 30);
|
||||
});
|
||||
|
||||
await t.test("exit 3 names the item id, the field and a way to do it right", () => {
|
||||
const bad = { items: [{ id: "bad1", kind: "choice", title: "Pick", options: [{ k: "A", label: "x" }] }] };
|
||||
const res = cli(["post", "--session", s.sid, "--file", payload("shape-bad.json", bad)], { expectFail: true });
|
||||
assert.equal(res.status, 3);
|
||||
assert.equal(res.stdout.trim(), "");
|
||||
assert.match(res.stderr, /bad1/);
|
||||
assert.match(res.stderr, /options/);
|
||||
assert.match(res.stderr, /Like this:/);
|
||||
});
|
||||
|
||||
await t.test("exit 2 gives the line, column and a caret for a cut-off patch", () => {
|
||||
const file = path.join(HOME, "shape-cut.json");
|
||||
fs.writeFileSync(file, '{\n "headline": { "stage": "Working"\n');
|
||||
const res = cli(["post", "--session", s.sid, "--file", file], { expectFail: true });
|
||||
assert.equal(res.status, 2);
|
||||
assert.match(res.stderr, /line \d+, column \d+/);
|
||||
assert.match(res.stderr, /\^/);
|
||||
});
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("exit 20 is {gone, fix} naming the session, and a resume to a restarted server prints the link again", () => {
|
||||
const opened = cli(["open", "--file", payload("shape-gone.json", BASE), "--no-open"]);
|
||||
const sid2 = opened.json.sid;
|
||||
assert.equal(typeof opened.json.terminalLine, "string");
|
||||
cli(["stop", "--session", sid2, "--force"]);
|
||||
const gone = cli(["wait", "--session", sid2, "--seconds", "5"]);
|
||||
assert.equal(gone.status, 20);
|
||||
assert.deepEqual(gone.json, { gone: true, fix: `open --resume ${sid2} --workflow <yours>` });
|
||||
const again = cli(["open", "--resume", sid2, "--no-open"]);
|
||||
try {
|
||||
assert.notEqual(again.json.url, opened.json.url, "a restart has a new link");
|
||||
assert.equal(typeof again.json.terminalLine, "string", "the new link is printed again");
|
||||
const post = cli(["post", "--session", sid2, "--file", payload("shape-after.json", { headline: { stage: "Working" } })]);
|
||||
assert.equal(post.json.terminalLine, undefined, "and not again on the next post");
|
||||
} finally {
|
||||
cli(["stop", "--session", sid2, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -189,7 +189,7 @@ const ROUTE_ORDER = [
|
||||
"/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab",
|
||||
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/",
|
||||
"/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/chat", "/chat/decision", "/workspace",
|
||||
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/cancel", "/ping", "/bye",
|
||||
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/cancel", "/ping", "/bye",
|
||||
];
|
||||
|
||||
test("shape: routes.mjs lists every URL the server answers, in order", () => {
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
SKILLS,
|
||||
SKILLS as EVERY_ENTRY,
|
||||
FLOW_SKILLS as SKILLS,
|
||||
skillFor,
|
||||
skillByName,
|
||||
isBuild,
|
||||
@@ -298,7 +299,7 @@ function sectionOf(text, heading) {
|
||||
|
||||
test("docs: console.md's open step names every workflow", () => {
|
||||
const text = readSrc("web-console", "console.md");
|
||||
const m = text.match(/where `<w>` is one of ([\s\S]*?)\. Get it right/);
|
||||
const m = text.match(/`<w>` is one of ([\s\S]*?)\. Launched from the dashboard/);
|
||||
assert.ok(m, "console.md: the open step's `<w>` sentence is not where the test looks");
|
||||
const said = [...m[1].matchAll(/`([^`]+)`/g)].map((x) => x[1]);
|
||||
assert.deepEqual(listProblems("src/web-console/console.md", said, WORKFLOWS), []);
|
||||
@@ -399,3 +400,20 @@ test("helper-strength.md ships in the seven skills that start helpers, and in no
|
||||
"plan2code-review",
|
||||
]);
|
||||
});
|
||||
|
||||
// The Implementation Loop is a card the desktop app offers, not a skill: it
|
||||
// has no workflow, so no list built from the workflows may hold it.
|
||||
test("the app-only Implementation Loop entry stays out of every workflow list", () => {
|
||||
const loop = EVERY_ENTRY.find((s) => s.appOnly);
|
||||
assert.ok(loop, "skills.js has an appOnly entry");
|
||||
assert.equal(loop.skill, "plan2code-loop");
|
||||
assert.equal(loop.workflow, null);
|
||||
assert.deepEqual(EVERY_ENTRY.filter((s) => s.appOnly).length, 1);
|
||||
assert.ok(!SKILLS.includes(loop), "FLOW_SKILLS leaves it out");
|
||||
assert.ok(!WORKFLOWS.includes(null) && !isWorkflow("plan2code-loop") && !isWorkflow(null));
|
||||
assert.equal(skillByName("plan2code-loop"), null);
|
||||
assert.ok(!CONSOLE_WORKFLOWS.includes(loop.command), "no console page is offered for it");
|
||||
assert.ok(!SKILL_CATALOG.some((e) => e.skill === loop.skill), "the dashboard does not draw it yet");
|
||||
assert.ok(!("null" in WORKFLOW_LABEL));
|
||||
assert.deepEqual([...loop.states], ["documented", "building"]);
|
||||
});
|
||||
@@ -15,6 +15,8 @@ import path from "node:path";
|
||||
import { cardAvailability, SKILL_CATALOG } from "../src/web-console/public/answers.js";
|
||||
import { SKILLS } from "../src/web-console/public/skills.js";
|
||||
import { HELP_TABS } from "../src/web-console/public/help.js";
|
||||
import { PREFS_TABS } from "../src/web-console/public/prefs.js";
|
||||
import { SERVABLE } from "../src/web-console/static.mjs";
|
||||
import { FAVICON_BODY, FAVICON_COLORS, faviconState, faviconSvg } from "../src/web-console/public/favicon.js";
|
||||
import {
|
||||
CACHE_MS,
|
||||
@@ -245,7 +247,7 @@ test("update check: the frame carries update only when a newer release is cached
|
||||
}
|
||||
assert.deepEqual(await get("/version"), { version: REPO_VERSION, latest });
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid], { env });
|
||||
cli(["stop", "--session", res.json.sid, "--force"], { env });
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
@@ -294,8 +296,8 @@ test("sign-off: approve leads show, and the approve button wears the accent", ()
|
||||
const doc = (f) => fs.readFileSync(path.join(ROOT, "src", "web-console", f), "utf8");
|
||||
for (const f of ["notes/implement.md", "building-review.md"]) {
|
||||
const text = doc(f);
|
||||
const approve = text.indexOf('{ "id": "approve", "label": "Approve this phase" }');
|
||||
const show = text.indexOf('{ "id": "show", "label": "Show me it working" }');
|
||||
const approve = text.indexOf('{"id":"approve","label":"Approve this phase"}');
|
||||
const show = text.indexOf('{"id":"show","label":"Show me it working"}');
|
||||
assert.ok(approve > 0 && show > approve, `${f} lists Approve this phase before Show me it working`);
|
||||
}
|
||||
assert.match(joinedCss(), /\.btn\.is-approve\s*\{[^}]*border-color:\s*var\(--accent\)/, "is-approve borders in the accent");
|
||||
@@ -399,18 +401,17 @@ test("help: the stuck tab is second, and openHelpOn only opens a tab that exists
|
||||
assert.match(opener[1], /HELP_TABS\.some\(/, "openHelpOn only opens a tab that exists");
|
||||
});
|
||||
|
||||
test("models: Codex is a model CLI on the server and the page, with its own tab", () => {
|
||||
test("models: Codex is a model CLI on the server and the page, with its own row in the agents table", () => {
|
||||
const server = fs.readFileSync(path.join(ROOT, "src", "web-console", "routes.mjs"), "utf8");
|
||||
const app = publicSource("screens/looks.js");
|
||||
const html = publicSource("index.html");
|
||||
const app = publicSource("screens/agents-view.js");
|
||||
const list = (src) => JSON.parse(src.match(/const MODEL_CLIS = (\[[^\]]*\]);/)[1]);
|
||||
assert.deepEqual(list(server), ["claude", "devin", "codex"]);
|
||||
assert.deepEqual(list(app), list(server), "the page's tabs match the server's lists");
|
||||
assert.deepEqual(list(app), list(server), "the page's rows match the server's lists");
|
||||
assert.ok(!/for \(const cli of \["claude", "devin"\]\)/.test(app), "no loop over a hard-coded pair");
|
||||
const labels = { claude: "Claude", devin: "Devin", codex: "Codex" };
|
||||
for (const cli of list(app)) {
|
||||
assert.match(html, new RegExp(`id="models-tab-${cli}"[^>]*>${labels[cli]}</button>`), `${cli} has a tab`);
|
||||
}
|
||||
assert.match(app, /\.\.\.MODEL_CLIS\.map\(\(cli\) => \(\{\s*key: "cli:" \+ cli,/, "the table draws a built-in row per MODEL_CLIS entry");
|
||||
const names = app.match(/const BUILT_IN = \{([^}]*)\};/)[1];
|
||||
for (const cli of list(app)) assert.match(names, new RegExp(`\\b${cli}: "`), `${cli} has a name in the table`);
|
||||
assert.ok(!publicSource("index.html").includes("models-tab-"), "the separate Models toggles are gone");
|
||||
const shipped = JSON.parse(fs.readFileSync(path.join(ROOT, "src", "launcher", "models.json"), "utf8"));
|
||||
for (const cli of list(server)) assert.ok(Array.isArray(shipped[cli]), `the launcher's models.json has ${cli}`);
|
||||
});
|
||||
@@ -467,3 +468,58 @@ test("no agent CLI module imports notepads.mjs, directly or through a module it
|
||||
assert.ok(dep.names && dep.names.every((n) => n === "staleNotepads" || n === "removeNotepad"), `Cleanup takes only staleNotepads and removeNotepad, not ${dep.names}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("prefs: the dialog is four tab panels in PREFS_TABS order, each section in the one panel that lists it", () => {
|
||||
const html = publicSource("index.html");
|
||||
const dialog = html.match(/<dialog class="modal looks prefs" id="looks-modal"[^>]*>([\s\S]*?)<\/dialog>/)[1];
|
||||
assert.match(dialog, /<div id="prefs-tabs" class="prefs-tabs" role="tablist"/, "a tablist for the tabs");
|
||||
const panels = [...dialog.matchAll(/<section class="prefs-panel" data-tab="([^"]+)">([\s\S]*?)<\/section>/g)];
|
||||
assert.deepEqual(panels.map((m) => m[1]), PREFS_TABS.map((t) => t.id), "one panel per tab, in order");
|
||||
const everywhere = [...dialog.matchAll(/data-section="([^"]+)"/g)].map((m) => m[1]);
|
||||
assert.equal(new Set(everywhere).size, everywhere.length, "no section appears twice");
|
||||
for (const [, id, body] of panels) {
|
||||
const inPanel = [...body.matchAll(/data-section="([^"]+)"/g)].map((m) => m[1]);
|
||||
const listed = PREFS_TABS.find((t) => t.id === id).sections;
|
||||
assert.deepEqual(inPanel, [...listed], `${id} holds ${listed.join(", ")} in that order`);
|
||||
}
|
||||
});
|
||||
|
||||
test("prefs: the new modules are served and preloaded, and Preferences' styles leave the shared classes alone", () => {
|
||||
const html = publicSource("index.html");
|
||||
for (const m of ["tabs.js", "prefs.js", "screens/prefs-dialog.js", "screens/agents-view.js"]) {
|
||||
assert.ok(SERVABLE.has(m), `${m} is servable`);
|
||||
assert.ok(html.includes(`rel="modulepreload" href="/${m}"`), `the page preloads ${m}`);
|
||||
}
|
||||
const css = publicSource("styles/prefs.css");
|
||||
for (const cls of ["looks", "looks-row", "modal-ranges"]) {
|
||||
assert.ok(!new RegExp(`\\.${cls}(?![\\w-])`).test(css), `prefs.css does not style .${cls} (the Subagents dialog shares it)`);
|
||||
}
|
||||
});
|
||||
|
||||
test("prefs: Help and the readme name every tab and section, and the dialog's unused fieldset classes stay gone", () => {
|
||||
const prefs = helpTemplate().match(/<section class="help-panel" data-tab="prefs">([\s\S]*?)<\/section>/)[1];
|
||||
// The help topic writes "&" as "&". Each section is named in bold, so a
|
||||
// tab label such as "Sounds & activities" does not count for "Sounds".
|
||||
const helpText = prefs.replace(/&/g, "&");
|
||||
const sections = ["Theme", "Card width", "Highlight color", "Role", "Models", "Agents", "Cleanup", "Desktop app", "Sounds", "Activities"];
|
||||
for (const name of [...PREFS_TABS.map((t) => t.label), ...sections]) {
|
||||
assert.ok(helpText.includes(`<strong>${name}</strong>`), `the prefs help topic names ${name}`);
|
||||
}
|
||||
// Only the readme's own User Preferences section counts, up to the next "## " heading.
|
||||
const readme = fs.readFileSync(path.join(ROOT, ".readme", "web-console.md"), "utf8");
|
||||
const start = readme.indexOf("\n## User Preferences\n");
|
||||
assert.ok(start >= 0, ".readme/web-console.md has a User Preferences section");
|
||||
const end = readme.indexOf("\n## ", start + 1);
|
||||
const section = readme.slice(start, end < 0 ? undefined : end);
|
||||
for (const heading of ["### Agents & models", "### System"]) {
|
||||
assert.ok(section.includes(`\n${heading}\n`), `the readme's User Preferences section has ${heading}`);
|
||||
}
|
||||
for (const name of [...PREFS_TABS.map((t) => t.label), "Models", "Agents", "Desktop app"]) {
|
||||
// In bold, as a table cell or a paragraph's lead-in ("**Models.**").
|
||||
assert.ok(section.includes(`**${name}**`) || section.includes(`**${name}.**`), `the readme's User Preferences section names ${name}`);
|
||||
}
|
||||
const html = publicSource("index.html");
|
||||
for (const cls of ["looks-models", "looks-agents", "looks-role", "looks-accents", "looks-cleanup"]) {
|
||||
assert.ok(!new RegExp(`class="[^"]*\\b${cls}\\b[^"]*"`).test(html), `index.html has no .${cls} left`);
|
||||
}
|
||||
});
|
||||
@@ -10,6 +10,7 @@
|
||||
// web-console-test-helpers.mjs; see the comment at its top.
|
||||
|
||||
import test from "node:test";
|
||||
import { POINTER_FILES } from "../src/web-console/pointers.mjs";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
@@ -63,7 +64,7 @@ test("a collected send marks the agent working and drops the last stretch's acti
|
||||
assert.equal(agent.activity, undefined);
|
||||
assert.ok(agent.since, "the CLI stamps the time");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,7 +75,7 @@ test("a Quick question alone never marks the agent working", async () => {
|
||||
assert.equal(waitFor(s).status, 0);
|
||||
assert.equal(readState(s.session).agent.status, "waiting", "chat rides its own channel");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -89,7 +90,7 @@ test("post --wait posts, then waits in the same command", async () => {
|
||||
const lines = res.stdout.trim().split("\n").map((l) => JSON.parse(l));
|
||||
assert.equal(lines.length, 2, "the post's line, then the wait's");
|
||||
assert.equal(lines[0].ok, true);
|
||||
assert.equal(lines[1].status, "waiting");
|
||||
assert.deepEqual(lines[1], { waiting: true, open: 1 });
|
||||
assert.ok(Date.now() - started >= 4500, "it really waited the slice");
|
||||
assert.equal(readState(s.session).title, "Posted then waited");
|
||||
|
||||
@@ -98,7 +99,7 @@ test("post --wait posts, then waits in the same command", async () => {
|
||||
assert.equal(got.status, 0, "a waiting send comes straight back");
|
||||
assert.equal(got.json.reply, "Export format: a");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -115,7 +116,7 @@ test("a rejected post --wait exits 3 at once and never waits", () => {
|
||||
const bad = cli(["post", "--session", s.sid, "--file", payload("pw-ok.json", {}), "--wait", "soon"], { expectFail: true });
|
||||
assert.equal(bad.status, 2, "a slice that is no number is bad usage");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -126,7 +127,7 @@ test("a wait slice ends on time: a health check in flight never holds the proces
|
||||
assert.equal(waitFor(s, 6).status, 10);
|
||||
assert.ok(Date.now() - started < 9000, `took ${Date.now() - started}ms`);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -193,7 +194,7 @@ test("a doc block with a file takes its text from disk; select tasks keeps the t
|
||||
p.run(["post", "--session", opened.sid, "--file", payload("fd-3.json", { docs: [{ id: "phasefile", refresh: true }] })]);
|
||||
assert.equal(readState(opened.session).docs.find((d) => d.id === "phasefile").version, 2, "an unchanged file is not a new version");
|
||||
} finally {
|
||||
p.run(["stop", "--session", opened.sid]);
|
||||
p.run(["stop", "--session", opened.sid, "--force"]);
|
||||
p.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -223,9 +224,9 @@ test("a doc block's file must exist, be inside the project, and select only take
|
||||
const fresh = p.run(["open", "--no-open", "--workflow", "implement", "--file", payload("fd-open.json", { docs: [{ id: "phasefile", title: "phase-1.md", blocks: [{ id: "body", file: "specs/lunch/phase-1.md" }] }] })]);
|
||||
assert.equal(fresh.status, 0, fresh.stderr);
|
||||
assert.ok(readState(fresh.json.session).docs[0].blocks[0].md.startsWith("# Phase 1"), "open --file reads files too");
|
||||
p.run(["stop", "--session", fresh.json.sid]);
|
||||
p.run(["stop", "--session", fresh.json.sid, "--force"]);
|
||||
} finally {
|
||||
p.run(["stop", "--session", opened.sid]);
|
||||
p.run(["stop", "--session", opened.sid, "--force"]);
|
||||
fs.rmSync(outside, { force: true });
|
||||
p.cleanup();
|
||||
}
|
||||
@@ -308,7 +309,9 @@ test("settle and a defaulted reply id go through post end to end", async () => {
|
||||
assert.equal((await s.send("/submit", { actions: [{ i: "q1", type: "answer", kind: "choice", k: "B" }], reply: "Question q1: B" })).status, 200);
|
||||
assert.equal(waitFor(s).status, 0);
|
||||
assert.equal((await ask(s, "Why?")).status, 200);
|
||||
const msg = waitFor(s).json.chat.find((e) => e.kind === "message");
|
||||
const seqs = waitFor(s).json.chat;
|
||||
assert.equal(seqs.length, 1, "chat arrives as the seq numbers a reply needs");
|
||||
const msg = { seq: seqs[0], conversation: 1 };
|
||||
const res = postPatch(s, { settle: true, chat: { replies: [{ re: msg.seq, conversation: msg.conversation, md: "Because." }] } });
|
||||
assert.equal(res.status, 0, res.stderr);
|
||||
const state = readState(s.session);
|
||||
@@ -318,7 +321,7 @@ test("settle and a defaulted reply id go through post end to end", async () => {
|
||||
assert.equal(state.items.find((i) => i.id === "q2").status, "open");
|
||||
assert.equal(state.chat.replies[0].id, `r${msg.seq}`);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -375,7 +378,7 @@ test("a pick-up comes with the stored skill's resume command, handoffFile, and f
|
||||
assert.equal(bad.handoffFile, undefined);
|
||||
assert.equal(bad.fallback, true);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(worktree, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -402,7 +405,7 @@ test("a launch, a dashboard press, Commit it now and Update CHANGELOG first each
|
||||
assert.equal((await s.send("/submit", EXPORT_A)).status, 200);
|
||||
assert.equal(waitFor(s).json.resume, undefined, "an answer is no hop");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -436,7 +439,7 @@ test("the built skills name the skill file to follow after a hop", async () => {
|
||||
const stopped = run(["wait", "--session", opened.sid, "--seconds", "10"]).json;
|
||||
assert.equal(stopped.handoffSkill, path.join(ROOT, "skills", "plan2code-handoff", "SKILL.md"), "a handoff stop in a built skill names the Handoff skill file");
|
||||
} finally {
|
||||
run(["stop", "--session", opened.sid]);
|
||||
run(["stop", "--session", opened.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -449,17 +452,19 @@ test("the built skills name the skill file to follow after a hop", async () => {
|
||||
// and the skills point at is real, and the core stays small.
|
||||
const DOC_REF = /`((?:console-[a-z-]+|building(?:-review)?|console|notes\/[a-z-]+)\.md)`|<D>\/((?:console-[a-z-]+|building(?:-review)?|console|notes\/[a-z-]+)\.md)/g;
|
||||
|
||||
test("every doc console.md's index names exists, prints through help, and every topic file is indexed", () => {
|
||||
test("every doc the card or a pointer names exists, prints through help, and every topic file is reachable", () => {
|
||||
const core = consoleDoc("console.md");
|
||||
const index = core.slice(core.indexOf("## What to read, and when"), core.indexOf("## Starting it"));
|
||||
const named = new Set([...index.matchAll(/`([a-z/-]+\.md)`/g)].map((m) => m[1]));
|
||||
const index = core.slice(core.indexOf("## Read when"));
|
||||
const named = new Set([...index.matchAll(/`([a-z/<>-]+.md)`/g)].map((m) => m[1]));
|
||||
const pointed = new Set(Object.values(POINTER_FILES));
|
||||
for (const file of consoleDocFiles().filter((f) => f !== "console.md" && !f.startsWith("notes/"))) {
|
||||
assert.ok(named.has(file), `console.md's index names ${file}`);
|
||||
assert.ok(named.has(file) || pointed.has(file), `${file} is named in the card's Read when table or by a pointer`);
|
||||
}
|
||||
for (const file of named) {
|
||||
if (file.includes("<")) continue;
|
||||
assert.ok(fs.existsSync(path.join(WEB_CONSOLE_DIR, file)), `${file} exists`);
|
||||
}
|
||||
for (const file of pointed) assert.ok(fs.existsSync(path.join(WEB_CONSOLE_DIR, file)), `pointer file ${file} exists`);
|
||||
const topics = cli(["help", "topics"]).json.topics;
|
||||
for (const [topic, file] of Object.entries(topics)) {
|
||||
assert.ok(fs.existsSync(path.join(WEB_CONSOLE_DIR, file)), `help ${topic} -> ${file} exists`);
|
||||
@@ -547,7 +552,7 @@ test("post --wait with no number takes the slice from --seconds", () => {
|
||||
assert.equal(res.status, 10);
|
||||
assert.ok(Date.now() - started < 12000, `took ${Date.now() - started}ms, not the default 240s`);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -566,7 +571,7 @@ test("a file block's own words are never refused by the prose scan, but typed te
|
||||
assert.equal(block.file, undefined, "typed text over a file block stops it being one");
|
||||
assert.equal(post("bait-5.json", [{ id: "summary", refresh: true }]).status, 3, "so a refresh finds nothing to re-read");
|
||||
} finally {
|
||||
p.run(["stop", "--session", opened.sid]);
|
||||
p.run(["stop", "--session", opened.sid, "--force"]);
|
||||
p.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -583,7 +588,7 @@ test("a file named again without select is the whole file, on every refresh", ()
|
||||
assert.equal(block.select, undefined);
|
||||
assert.ok(block.md.startsWith("# Phase 1"), "the whole file, not the task lines");
|
||||
} finally {
|
||||
p.run(["stop", "--session", opened.sid]);
|
||||
p.run(["stop", "--session", opened.sid, "--force"]);
|
||||
p.cleanup();
|
||||
}
|
||||
});
|
||||
@@ -603,7 +608,7 @@ test("collecting a send restarts the working clock and keeps a build's quietMinu
|
||||
assert.equal(agent.quietMinutes, 20, "the build's patience survives the question");
|
||||
assert.ok(Date.parse(agent.since) > Date.parse(opened), "a fresh working turn, not the session's age");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -614,7 +619,7 @@ test("a wait with nothing open leaves a working agent working", () => {
|
||||
assert.equal(waitFor(s, 5).status, 10);
|
||||
assert.equal(readState(s.session).agent.status, "working", "research subagents still out: the page keeps saying so");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -630,9 +635,9 @@ test("post --file - reads the patch from stdin, UTF-8 and a BOM included", () =>
|
||||
assert.equal(waited.status, 10, "stdin and --wait together");
|
||||
const bad = run("not json");
|
||||
assert.equal(bad.status, 2);
|
||||
assert.match(bad.stderr, /could not read --file - as one JSON object/);
|
||||
assert.match(bad.stderr, /line 1, column 2/);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -667,10 +672,11 @@ test("collecting a send puts the phase back to collecting", async () => {
|
||||
assert.equal(readState(s.session).phase, "submitted", "waiting to be picked up");
|
||||
assert.equal(waitFor(s).status, 0);
|
||||
assert.equal(readState(s.session).phase, "collecting");
|
||||
assert.equal(postPatch(s, { settle: true }).json.phase, "collecting", "and post says so");
|
||||
assert.equal(postPatch(s, { settle: true }).status, 0);
|
||||
assert.equal(readState(s.session).phase, "collecting", "and a post leaves it there");
|
||||
assert.equal(readState(s.session).agent.handled, undefined, "no dead fields on a fresh agent block");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -682,11 +688,11 @@ test("a run of resets reaches the agent as one line", async () => {
|
||||
assert.equal((await ask(s, "Hello?", { conversation: 3 })).status, 200);
|
||||
const res = waitFor(s);
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(res.json.chat.filter((e) => e.kind === "reset").length, 1, JSON.stringify(res.json.chat));
|
||||
assert.equal(res.json.chat.length, 1, "only the question needs a reply: " + JSON.stringify(res.json.chat));
|
||||
assert.equal(res.json.reply.match(/New conversation started/g).length, 1);
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 10, "the cursor moved past every reset");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -706,7 +712,7 @@ test("a finish ends the working stretch, and resuming a pause starts a fresh one
|
||||
const told = applyPatch({ agent: { status: "working" } }, { finish: { headline: "Done" }, agent: { status: "working" } });
|
||||
assert.equal(told.agent.status, "working", "a status the patch says still wins");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -46,6 +46,12 @@ test("state: the rest of the shared state starts as app.js always started it", (
|
||||
meterFrame: null,
|
||||
updateFrame: null,
|
||||
inApp: false,
|
||||
loop: null,
|
||||
loopSetup: null,
|
||||
loopFacts: null,
|
||||
loopNotifyTest: null,
|
||||
loopStart: null,
|
||||
loopAction: null,
|
||||
subagentsFrame: null,
|
||||
overview: { key: null, files: {} },
|
||||
wake: null,
|
||||
|
||||
@@ -70,15 +70,19 @@ test("subagents: a change reaches the next pickup once, last in reply, edits nam
|
||||
assert.equal((await addFolder(s, { path: extra })).status, 200);
|
||||
const first = await submitAndWait(s);
|
||||
assert.equal(first.status, 0);
|
||||
assert.deepEqual(first.json.subagents, { state: "on", revision: rev, max: 3, instruction: defaultInstruction("implement"), strength: "balanced" });
|
||||
assert.equal("subagents" in first.json, false, "no structured subagents object on the wire");
|
||||
assert.equal("workspace" in first.json, false, "no structured workspace object on the wire");
|
||||
const reply = first.json.reply;
|
||||
const at = (re) => reply.search(re);
|
||||
assert.ok(at(/^Export format: a$/m) === 0, reply);
|
||||
assert.ok(at(/^Quick question:/m) > 0, reply);
|
||||
assert.ok(at(/^Workspace:/m) > at(/^Quick question:/m), reply);
|
||||
assert.ok(at(/^Quick question \(/m) > 0, reply);
|
||||
assert.ok(at(/^Workspace:/m) > at(/^Quick question \(/m), reply);
|
||||
assert.ok(at(/^Subagents:/m) > at(/^Workspace:/m), reply);
|
||||
assert.match(reply, new RegExp(`^Subagents: on \\(revision ${rev}\\) — a console setting, not typed by the person\\.$`, "m"));
|
||||
assert.ok(reply.endsWith("\n At most 3 helpers at once."), "the block goes last");
|
||||
assert.equal(subagentLines(reply)[0], "Subagents: on, balanced strength, at most 3 helpers at once (a console setting, not typed by the person).");
|
||||
assert.ok(reply.endsWith("\n " + defaultInstruction("implement").split("\n").pop().trim()), "the block goes last, ending on the instruction");
|
||||
for (const old of ["revision", "Helper strength:", "At most 3 helpers", "Report each helper", "Match each helper"]) {
|
||||
assert.ok(!reply.includes(old), "the old frame sentence is gone: " + old);
|
||||
}
|
||||
assert.deepEqual(subagentLines(reply).length, 1, "one block");
|
||||
assert.deepEqual(readSubagentCursor(s.session), { revision: rev, state: "on" });
|
||||
|
||||
@@ -89,10 +93,9 @@ test("subagents: a change reaches the next pickup once, last in reply, edits nam
|
||||
const edited = await setSubagents(s, { ...ON3, max: 5 });
|
||||
assert.equal(edited.body.setting.revision, rev + 1);
|
||||
const third = await submitAndWait(s);
|
||||
assert.equal(third.json.subagents.revision, rev + 1);
|
||||
assert.equal(third.json.subagents.max, 5);
|
||||
assert.equal("subagents" in third.json, false);
|
||||
assert.deepEqual(subagentLines(third.json.reply), [
|
||||
`Subagents: on (revision ${rev + 1}, replaces revision ${rev}) — a console setting, not typed by the person.`,
|
||||
"Subagents: on, balanced strength, at most 5 helpers at once (a console setting, not typed by the person).",
|
||||
]);
|
||||
|
||||
const same = await setSubagents(s, { ...ON3, max: 5 });
|
||||
@@ -103,13 +106,10 @@ test("subagents: a change reaches the next pickup once, last in reply, edits nam
|
||||
const off = await setSubagents(s, { ...ON3, on: false, max: 5 });
|
||||
assert.equal(off.body.setting.revision, rev + 2, "off is a revision of its own");
|
||||
const fourth = await submitAndWait(s);
|
||||
assert.equal(fourth.json.subagents.state, "off");
|
||||
assert.deepEqual(subagentLines(fourth.json.reply), [
|
||||
`Subagents: off (revision ${rev + 2}) — don't start new helpers for the rest of this session.`,
|
||||
]);
|
||||
assert.deepEqual(subagentLines(fourth.json.reply), ["Subagents: off. Start no new helpers for the rest of this session."]);
|
||||
assert.equal("subagents" in (await submitAndWait(s)).json, false, "off is said once");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -118,28 +118,26 @@ test("subagents: never on means never a line, and chat hands a pending block ove
|
||||
// A project that saved "off" starts its next session off and untold.
|
||||
const first = subagentsSession();
|
||||
assert.equal((await setSubagents(first, { on: false, instruction: null, max: 4 })).status, 200);
|
||||
cli(["stop", "--session", first.sid]);
|
||||
cli(["stop", "--session", first.sid, "--force"]);
|
||||
const s = subagentsSession({}, { keepStore: true });
|
||||
try {
|
||||
const off = await setSubagents(s, { on: false, instruction: null, max: 4 });
|
||||
assert.equal(off.status, 200);
|
||||
const got = await submitAndWait(s);
|
||||
assert.equal("subagents" in got.json, false);
|
||||
assert.deepEqual(subagentLines(got.json.reply), [], "off is never said to an agent not told on");
|
||||
assert.deepEqual(subagentLines(got.json.reply ?? ""), [], "off is never said to an agent not told on");
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 10);
|
||||
|
||||
assert.equal((await setSubagents(s, { on: true, instruction: "Split by file.", max: 4 })).status, 200);
|
||||
const chat = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(chat.status, 0);
|
||||
assert.deepEqual(chat.json.chat, []);
|
||||
assert.equal(chat.json.subagents.state, "on");
|
||||
assert.equal(chat.json.subagents.instruction, "Split by file.");
|
||||
assert.match(chat.json.reply, /^Subagents: on \(revision \d+\)/);
|
||||
assert.equal(chat.json.chat, undefined, "no question, no chat key");
|
||||
assert.equal("subagents" in chat.json, false);
|
||||
assert.match(chat.json.reply, /^Subagents: on, balanced strength, at most 4 helpers at once/);
|
||||
assert.match(chat.json.reply, /^ {2}Split by file\.$/m);
|
||||
assert.ok(chat.json.terminalLine);
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 10, "then nothing");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -149,16 +147,16 @@ test("subagents: a resume re-states an on setting once, says nothing when off, a
|
||||
const rev = (await setSubagents(s, ON3)).body.setting.revision;
|
||||
const resumed = cli(["open", "--resume", s.sid, "--no-open"]);
|
||||
assert.equal(resumed.json.ok, true);
|
||||
assert.deepEqual(resumed.json.subagents, { state: "on", revision: rev, max: 3, instruction: defaultInstruction("implement"), strength: "balanced" });
|
||||
assert.equal(subagentLines(resumed.json.reply)[0], `Subagents: on (revision ${rev}) — a console setting, not typed by the person.`);
|
||||
assert.equal("subagents" in resumed.json, false, "no structured object on the wire");
|
||||
assert.equal(subagentLines(resumed.json.reply)[0], "Subagents: on, balanced strength, at most 3 helpers at once (a console setting, not typed by the person).");
|
||||
assert.equal(readSubagentCursor(s.session).revision, rev, "open stamped the cursor");
|
||||
assert.ok(resumed.json.reply.split("\n").every((l, i) => i === 0 || l.startsWith(" ")), "only the block's lines");
|
||||
assert.equal("subagents" in (await submitAndWait(s)).json, false, "the next pickup carries nothing");
|
||||
|
||||
// The print happened but the cursor write did not: the block comes again.
|
||||
fs.writeFileSync(path.join(s.session, "subagents-cursor.json"), JSON.stringify({ revision: 0, state: "none" }));
|
||||
const again = await submitAndWait(s);
|
||||
assert.equal(again.json.subagents.state, "on");
|
||||
assert.deepEqual(subagentLines(again.json.reply), [`Subagents: on (revision ${rev}) — a console setting, not typed by the person.`]);
|
||||
assert.deepEqual(subagentLines(again.json.reply), ["Subagents: on, balanced strength, at most 3 helpers at once (a console setting, not typed by the person)."]);
|
||||
assert.deepEqual(readSubagentCursor(s.session), { revision: rev, state: "on" });
|
||||
|
||||
assert.equal((await setSubagents(s, { ...ON3, on: false })).status, 200);
|
||||
@@ -167,7 +165,7 @@ test("subagents: a resume re-states an on setting once, says nothing when off, a
|
||||
assert.equal("reply" in quiet.json, false);
|
||||
assert.equal("subagents" in (await submitAndWait(s)).json, false, "nor does the next pickup");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -176,7 +174,7 @@ test("subagents: a dashboard launch into implement hears implement's saved setti
|
||||
try {
|
||||
assert.equal((await setSubagents(seed, ON3)).status, 200);
|
||||
} finally {
|
||||
cli(["stop", "--session", seed.sid]);
|
||||
cli(["stop", "--session", seed.sid, "--force"]);
|
||||
}
|
||||
const s = consoleSession(["--workflow", "dashboard"]);
|
||||
try {
|
||||
@@ -184,15 +182,15 @@ test("subagents: a dashboard launch into implement hears implement's saved setti
|
||||
const launched = cli(["open", "--resume", s.sid, "--no-open", "--workflow", "implement"]);
|
||||
// On the launch itself, not at a later pickup: a skill may do its main
|
||||
// work before it ever collects anything.
|
||||
assert.equal(launched.json.subagents?.state, "on", "the launch's own open output carries the block");
|
||||
assert.match(launched.json.reply, /^Subagents: on \(revision \d+\)/);
|
||||
assert.match(launched.json.reply, /^Subagents: on, balanced strength/m, "the launch's own open output carries the block");
|
||||
assert.equal("subagents" in launched.json, false);
|
||||
// open consumed the subagents block and advanced the cursor before it
|
||||
// printed, so chat has nothing left to hand over.
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 10, "never both");
|
||||
const view = await s.get("/state");
|
||||
assert.deepEqual([view.subagents.offered, view.subagents.supported, view.subagents.on], [true, true, true]);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -203,7 +201,7 @@ test("subagents: the setting survives a restart at the same revision and starts
|
||||
const saved = await setSubagents(s, { on: true, instruction: "Split by file.", max: 7 });
|
||||
assert.equal(saved.status, 200);
|
||||
const rev = saved.body.setting.revision;
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
const resumed = cli(["open", "--resume", s.sid, "--no-open"]);
|
||||
const frame = await (
|
||||
await fetch(`${sessionUrl(resumed.json.url).base}/state`, { headers: { cookie: sessionUrl(resumed.json.url).cookie, connection: "close" } })
|
||||
@@ -218,8 +216,8 @@ test("subagents: the setting survives a restart at the same revision and starts
|
||||
const fresh = await frameSubagents(next);
|
||||
assert.deepEqual([fresh.on, fresh.instruction, fresh.max], [true, "Split by file.", 7], "a new session in the same project starts there");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
if (next) cli(["stop", "--session", next.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
if (next) cli(["stop", "--session", next.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -238,7 +236,7 @@ test("subagents: a save that matches this session still becomes the project's se
|
||||
c = subagentsSession({}, { keepStore: true });
|
||||
assert.equal((await frameSubagents(c)).on, true, "the next session starts from the person's latest pick");
|
||||
} finally {
|
||||
for (const s of [a, b, c]) if (s) cli(["stop", "--session", s.sid]);
|
||||
for (const s of [a, b, c]) if (s) cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -268,8 +266,8 @@ test("subagents: a workflow without the switch refuses it, bad bodies name the f
|
||||
fs.rmSync(path.join(s.session, "subagents-setting.json"), { force: true });
|
||||
assert.equal("subagents" in (await submitAndWait(s)).json, false);
|
||||
} finally {
|
||||
cli(["stop", "--session", doc.sid]);
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", doc.sid, "--force"]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -282,15 +280,15 @@ test("subagents: a strength-only change reaches the agent once, with its profile
|
||||
assert.equal(thrifty.body.setting.revision, before + 1, "a strength alone is a change");
|
||||
assert.equal(thrifty.body.setting.strength, "thrifty");
|
||||
const picked = await submitAndWait(s);
|
||||
assert.equal(picked.json.subagents.strength, "thrifty");
|
||||
assert.ok(picked.json.reply.endsWith(["", STRENGTH_LINES.thrifty, "At most 3 helpers at once."].join("\n ")), picked.json.reply);
|
||||
assert.equal("subagents" in picked.json, false);
|
||||
assert.deepEqual(subagentLines(picked.json.reply), ["Subagents: on, thrifty strength, at most 3 helpers at once (a console setting, not typed by the person)."]);
|
||||
assert.equal((await frameSubagents(s)).strength, "thrifty");
|
||||
|
||||
const again = await setSubagents(s, { ...ON3, strength: "thrifty" });
|
||||
assert.equal(again.body.setting.revision, before + 1, "the same strength again bumps nothing");
|
||||
assert.equal("subagents" in (await submitAndWait(s)).json, false);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -307,12 +305,12 @@ test("subagents: a setting saved before strength existed reads as balanced and b
|
||||
strip(path.join(s.session, "subagents-setting.json"), (setting) => [setting]);
|
||||
const rev = JSON.parse(fs.readFileSync(path.join(s.session, "subagents-setting.json"), "utf8")).revision;
|
||||
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
const resumed = sessionUrl(cli(["open", "--resume", s.sid, "--no-open"]).json.url);
|
||||
const frame = (await (await fetch(`${resumed.base}/state`, { headers: { cookie: resumed.cookie, connection: "close" } })).json()).subagents;
|
||||
assert.deepEqual([frame.max, frame.strength, frame.revision], [4, "balanced", rev], "an upgrade alone bumps nothing");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -320,11 +318,12 @@ test("subagents: every strength renders its own profile line, and a missing one
|
||||
const base = { revision: 1, max: 3, instruction: "Split by file." };
|
||||
for (const strength of STRENGTHS) {
|
||||
const lines = onLines({ ...base, strength });
|
||||
assert.equal(lines[lines.length - 2], " " + STRENGTH_LINES[strength], strength);
|
||||
assert.equal(lines.filter((l) => l.includes("Helper strength:")).length, 1, strength);
|
||||
const word = strength;
|
||||
assert.equal(lines[0], `Subagents: on, ${word} strength, at most 3 helpers at once (a console setting, not typed by the person).`, strength);
|
||||
assert.equal(lines.filter((l) => l.includes("Helper strength:")).length, 0, "the old profile sentence is gone: " + strength);
|
||||
}
|
||||
assert.equal(new Set(STRENGTHS.map((k) => STRENGTH_LINES[k])).size, STRENGTHS.length, "four different lines");
|
||||
assert.equal(onLines(base).at(-2), " " + STRENGTH_LINES.balanced);
|
||||
assert.equal(new Set(STRENGTHS.map((k) => onLines({ ...base, strength: k })[0])).size, STRENGTHS.length, "four different lines");
|
||||
assert.equal(onLines(base)[0], onLines({ ...base, strength: "balanced" })[0], "a missing strength is balanced");
|
||||
});
|
||||
|
||||
/* ------------------------------------------ subagents: helper reports */
|
||||
@@ -356,7 +355,7 @@ test("helpers: post merges them by id, a real helper supersedes working alone, a
|
||||
assert.equal(postPatch(s, { helpers: [reportedHelper("h1")] }).status, 0);
|
||||
assert.deepEqual(readState(s.session).helpers.map((h) => h.id), ["h1"], "a real helper removes the working-alone marker");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -372,11 +371,11 @@ test("helpers: every malformed report exits 3 naming the helper, and nothing is
|
||||
["81-char title", [reportedHelper("h3", { title: "t".repeat(81) })], /helper "h3": title must be at most 80 characters/],
|
||||
["401-char ask", [reportedHelper("h3", { ask: "a".repeat(401) })], /helper "h3": ask must be at most 400 characters/],
|
||||
["201-char result", [reportedHelper("h3", { state: "done", result: "r".repeat(201) })], /helper "h3": result must be at most 200 characters/],
|
||||
["completion marker", [reportedHelper("h3", { state: "done", result: "PHASE_COMPLETE" })], /helper "h3" result contains a loop completion marker/],
|
||||
["metrics bait", [reportedHelper("h3", { title: "Risk 3" })], /helper "h3" title contains "Risk 3"/],
|
||||
["not an array", { id: "h3" }, /"helpers" must be an array/],
|
||||
["null entry", [null], /"helpers" entries must be objects/],
|
||||
["string entry", ["h3"], /"helpers" entries must be objects/],
|
||||
["completion marker", [reportedHelper("h3", { state: "done", result: "PHASE_COMPLETE" })], /helper "h3" result: contains a loop completion marker/],
|
||||
["metrics bait", [reportedHelper("h3", { title: "Risk 3" })], /helper "h3" title: contains "Risk 3"/],
|
||||
["not an array", { id: "h3" }, /helpers: must be an array/],
|
||||
["null entry", [null], /helpers: entries must be objects/],
|
||||
["string entry", ["h3"], /helpers: entries must be objects/],
|
||||
];
|
||||
for (const [name, helpers, re] of cases) {
|
||||
const res = postPatch(s, { helpers }, { expectFail: true });
|
||||
@@ -385,7 +384,7 @@ test("helpers: every malformed report exits 3 naming the helper, and nothing is
|
||||
assert.equal(fs.readFileSync(statePath, "utf8"), before, `${name}: nothing written`);
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -409,7 +408,7 @@ test("helpers: a reported strength and effort are kept, other values exit 3 nami
|
||||
assert.equal(postPatch(s, { helpers: [reportedHelper("h3")] }).status, 0, "a helper without the fields still posts");
|
||||
assert.deepEqual(readState(s.session).helpers.map((h) => h.id), ["h1", "h3"]);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -423,7 +422,7 @@ test("docs: a doc's version never goes back; the same version again is fine, and
|
||||
const before = fs.readFileSync(statePath, "utf8");
|
||||
const stale = postPatch(s, doc(1, "- [ ] Task 4.1"), { expectFail: true });
|
||||
assert.equal(stale.status, 3);
|
||||
assert.match(stale.stderr, /doc "phase" is at version 7 on the page; this patch sends version 1/);
|
||||
assert.match(stale.stderr, /doc "phase" version: the page is at version 7; this patch sends 1/);
|
||||
assert.equal(fs.readFileSync(statePath, "utf8"), before, "nothing written");
|
||||
assert.equal(postPatch(s, doc(8, "- [ ] Task 5.1")).status, 0, "a higher version goes through");
|
||||
assert.equal(postPatch(s, { docs: [{ id: "phase", blocks: [{ id: "tasks", state: "settled", md: "- [x] Task 5.1" }] }] }).status, 0, "a patch with no version is not checked");
|
||||
@@ -432,15 +431,14 @@ test("docs: a doc's version never goes back; the same version again is fine, and
|
||||
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "implement"]);
|
||||
assert.equal(postPatch(s, doc(1, "- [ ] Task 1.1")).status, 0, "after a hop the doc starts fresh");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("docs: a second phase in one build session goes through as notes/implement.md teaches it", () => {
|
||||
const md = fs.readFileSync(path.join(ROOT, "src", "web-console", "notes", "implement.md"), "utf8");
|
||||
assert.match(md, /A later phase in the same session posts the same two docs/);
|
||||
assert.match(md, /versions move up by themselves/);
|
||||
assert.match(md, /Leave\s+`version` out/);
|
||||
assert.match(md, /A later phase posts the same two docs/);
|
||||
assert.match(fs.readFileSync(path.join(ROOT, "src", "web-console", "console-docs.md"), "utf8"), /`version`: moves by itself when content changes and never goes back; leave it out/);
|
||||
const taught = consoleSession(["--workflow", "implement"]);
|
||||
try {
|
||||
// As taught: no version anywhere, and the second phase simply goes through.
|
||||
@@ -459,7 +457,7 @@ test("docs: a second phase in one build session goes through as notes/implement.
|
||||
[["phase", "Phase 2 tasks", 3], ["phasefile", "phase-2.md", 3]]
|
||||
);
|
||||
} finally {
|
||||
cli(["stop", "--session", taught.sid]);
|
||||
cli(["stop", "--session", taught.sid, "--force"]);
|
||||
}
|
||||
// An explicit version still never goes back.
|
||||
const s = consoleSession(["--workflow", "implement"]);
|
||||
@@ -482,6 +480,24 @@ test("docs: a second phase in one build session goes through as notes/implement.
|
||||
[["phase", "Phase 2 tasks", 3], ["phasefile", "phase-2.md", 3]]
|
||||
);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("subagents: a change arrives as reply lines only, carrying state, strength and limit and none of the old frame sentences", async () => {
|
||||
const s = subagentsSession();
|
||||
try {
|
||||
assert.equal((await setSubagents(s, { on: true, instruction: "Split by file.", max: 6, strength: "thrifty" })).status, 200);
|
||||
const got = await submitAndWait(s);
|
||||
assert.equal(got.status, 0);
|
||||
assert.equal("subagents" in got.json, false, "no subagents object");
|
||||
assert.equal("workspace" in got.json, false, "no workspace object");
|
||||
assert.deepEqual(subagentLines(got.json.reply), ["Subagents: on, thrifty strength, at most 6 helpers at once (a console setting, not typed by the person)."]);
|
||||
assert.ok(got.json.reply.endsWith("\n Split by file."), "the person's instruction follows, indented");
|
||||
for (const old of ["revision", "Helper strength:", "Hand independent", "Report each helper", "If your tools cannot"]) {
|
||||
assert.ok(!got.json.reply.includes(old), "no old frame sentence: " + old);
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,344 @@
|
||||
// Web console tests, the activities' sound engine: every chiptune track readable and playable, every tone and hum named once across tones.js and the games' own sound files, every spec well formed, every one playable through a stand-in AudioContext, hums held only while asked for, and every name a game's source asks for one that exists.
|
||||
// Run with: node --test scripts/test-web-console-tones.mjs
|
||||
//
|
||||
// No browser: a stub AudioContext records what each sound builds.
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { HUM_TABLES, TONE_TABLES, hum, humNames, hushTones, tone, toneNames } from "../src/web-console/public/tones.js";
|
||||
import { looks } from "../src/web-console/public/looks.js";
|
||||
import { compileTrack, hushMusic, music, musicNames, noteFreq } from "../src/web-console/public/music.js";
|
||||
import { MUSIC_TABLES } from "../src/web-console/public/tones.js";
|
||||
import { REGIONS, ROAD_MUSIC } from "../src/web-console/public/activities/drive.js";
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const GAMES = path.join(ROOT, "src/web-console/public/activities");
|
||||
|
||||
const WAVES = new Set(["sine", "triangle", "square", "sawtooth"]);
|
||||
const NOISES = new Set(["noise", "pink", "brown"]);
|
||||
const FILTERS = new Set(["lowpass", "highpass", "bandpass"]);
|
||||
|
||||
// A stand-in context: counts the sources each sound starts and stops, and
|
||||
// keeps every gain node with the ramps asked of it.
|
||||
function stubAudio() {
|
||||
const made = { oscillators: 0, noises: 0, started: 0, stopped: 0, filters: 0, gains: [] };
|
||||
const param = () => ({
|
||||
value: 0,
|
||||
ramps: [],
|
||||
setValueAtTime(v, t) { this.ramps.push({ kind: "set", v, t }); },
|
||||
exponentialRampToValueAtTime(v, t) { this.ramps.push({ kind: "exp", v, t }); },
|
||||
linearRampToValueAtTime(v, t) { this.ramps.push({ kind: "linear", v, t }); },
|
||||
setTargetAtTime(v, t) { this.ramps.push({ kind: "target", v, t }); },
|
||||
cancelScheduledValues() {},
|
||||
});
|
||||
const node = (extra = {}) => ({ connect() {}, disconnect() {}, ...extra });
|
||||
const source = (kind) => node({
|
||||
frequency: param(),
|
||||
start() { made.started += 1; },
|
||||
stop() { made.stopped += 1; },
|
||||
kind,
|
||||
});
|
||||
class Ctx {
|
||||
state = "running";
|
||||
// Two seconds pass between reads, so every sound has ended before the next.
|
||||
#clock = 0;
|
||||
get currentTime() { return (this.#clock += 2); }
|
||||
sampleRate = 8000;
|
||||
destination = node();
|
||||
resume() { return Promise.resolve(); }
|
||||
createOscillator() { made.oscillators += 1; return source("osc"); }
|
||||
createBufferSource() { made.noises += 1; return source("noise"); }
|
||||
createBuffer(_, length) { const data = new Float32Array(length); return { getChannelData: () => data }; }
|
||||
createGain() { const g = node({ gain: param() }); made.gains.push(g); return g; }
|
||||
createBiquadFilter() { made.filters += 1; return node({ frequency: param(), Q: param(), type: "" }); }
|
||||
createDynamicsCompressor() { return node({ threshold: param(), knee: param(), ratio: param(), attack: param(), release: param() }); }
|
||||
}
|
||||
return { Ctx, made };
|
||||
}
|
||||
|
||||
// tones.js keeps the first context it makes, so the whole file shares one.
|
||||
const AUDIO = stubAudio();
|
||||
|
||||
const partsOf = (spec) => (spec.layers ? spec.layers : spec.notes ? spec.notes.map(() => spec) : [spec]);
|
||||
|
||||
test("every tone and hum is named once across tones.js and every game's sound file", () => {
|
||||
const seen = new Map();
|
||||
for (const tables of [TONE_TABLES, HUM_TABLES]) {
|
||||
for (const table of tables) {
|
||||
for (const name of Object.keys(table)) {
|
||||
assert.ok(!seen.has(name), `${name} is defined twice`);
|
||||
seen.set(name, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(toneNames().length > 100, "the kit and the old blips");
|
||||
assert.ok(humNames().includes("car"), "and the hums");
|
||||
});
|
||||
|
||||
test("every tone is well formed: a known wave or noise, a sane length, a filter of a known kind", () => {
|
||||
for (const name of toneNames()) {
|
||||
const spec = TONE_TABLES.find((t) => Object.hasOwn(t, name))[name];
|
||||
assert.ok(Object.isFrozen(spec), `${name} is frozen`);
|
||||
for (const p of partsOf(spec)) {
|
||||
assert.ok(WAVES.has(p.type) || (spec.layers && NOISES.has(p.type)), `${name}: ${p.type} is a wave, or a noise in a layered tone`);
|
||||
assert.ok(p.seconds > 0 && p.seconds + (p.delay || 0) <= 1.2, `${name} is over within 1.2 s`);
|
||||
if (WAVES.has(p.type)) assert.ok(p.notes ? p.notes.every((f) => f > 0) : p.from > 0 && p.to > 0, `${name} has its pitches`);
|
||||
if (p.filter) assert.ok(FILTERS.has(p.filter.type) && p.filter.from > 0, `${name}'s filter is known`);
|
||||
if (p.gain !== undefined) assert.ok(p.gain > 0 && p.gain <= 1, `${name}'s part gain is a share`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("every hum is well formed: parts or noise, a positive peak, quiet enough to sit under the page", () => {
|
||||
for (const name of humNames()) {
|
||||
const spec = HUM_TABLES.find((t) => Object.hasOwn(t, name))[name];
|
||||
assert.ok((spec.parts && spec.parts.length) || spec.noise, `${name} makes a sound`);
|
||||
for (const p of spec.parts || []) assert.ok(WAVES.has(p.type) && p.freq > 0, `${name}'s parts are waves`);
|
||||
if (spec.noise) assert.ok(NOISES.has(spec.noise.color), `${name}'s noise is a known color`);
|
||||
if (spec.filter) assert.ok(FILTERS.has(spec.filter.type) && spec.filter.freq > 0, `${name}'s filter is known`);
|
||||
assert.ok(spec.peak > 0 && spec.peak <= 0.08, `${name} peaks at most as loud as a blip`);
|
||||
}
|
||||
});
|
||||
|
||||
test("every tone plays through a full AudioContext, one source per part, and never throws", () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx, made } = AUDIO;
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
looks.sound = true;
|
||||
for (const name of toneNames()) {
|
||||
const spec = TONE_TABLES.find((t) => Object.hasOwn(t, name))[name];
|
||||
const before = made.oscillators + made.noises;
|
||||
tone(name, 0.7, 1.2);
|
||||
const vibratos = partsOf(spec).filter((p) => p.vibrato && WAVES.has(p.type)).length;
|
||||
assert.equal(made.oscillators + made.noises - before, partsOf(spec).length + vibratos, `${name} starts a source per part`);
|
||||
}
|
||||
looks.sound = false;
|
||||
const before = made.oscillators + made.noises;
|
||||
tone("explode");
|
||||
assert.equal(made.oscillators + made.noises, before, "Play sounds off: silence");
|
||||
} finally {
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("a hum starts once, follows each call without starting more, and goes quiet when hushed or Play sounds is off", async () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx, made } = AUDIO;
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
looks.sound = true;
|
||||
hushTones();
|
||||
const start = made.started;
|
||||
hum("you", "car", 0.5, 1);
|
||||
const one = made.started - start;
|
||||
assert.ok(one >= 3, "the car's oscillators, its noise and its pulse");
|
||||
for (let i = 0; i < 10; i++) hum("you", "car", 0.6, 1 + i / 10);
|
||||
assert.equal(made.started - start, one, "revving it starts nothing new");
|
||||
hum("rival", "car", 0.3, 1);
|
||||
assert.equal(made.started - start, one * 2, "a second id is its own voice");
|
||||
hum("you", "toycar", 0.3, 1);
|
||||
assert.ok(made.stopped >= one, "a new name restarts the voice");
|
||||
const stoppedBefore = made.stopped;
|
||||
hushTones();
|
||||
assert.ok(made.stopped > stoppedBefore, "hushed");
|
||||
hum("again", "nope");
|
||||
looks.sound = false;
|
||||
const s = made.started;
|
||||
hum("you", "car");
|
||||
assert.equal(made.started, s, "Play sounds off: no hum");
|
||||
looks.sound = true;
|
||||
hum("held", "wind");
|
||||
const st = made.stopped;
|
||||
await new Promise((r) => setTimeout(r, 320));
|
||||
assert.ok(made.stopped > st, "a hum not asked for again fades by itself");
|
||||
} finally {
|
||||
hushTones();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("every tone or hum a game's source names is one the engine has", () => {
|
||||
const tones = new Set(toneNames());
|
||||
const hums = new Set(humNames());
|
||||
for (const file of fs.readdirSync(GAMES).filter((f) => f.endsWith(".js") && !f.endsWith("-sfx.js"))) {
|
||||
const source = fs.readFileSync(path.join(GAMES, file), "utf8");
|
||||
for (const m of source.matchAll(/\btone\(\s*"(\w+)"/g)) assert.ok(tones.has(m[1]), `${file}: tone "${m[1]}" exists`);
|
||||
for (const m of source.matchAll(/\bhum\([^,()]+,\s*"(\w+)"/g)) assert.ok(hums.has(m[1]), `${file}: hum "${m[1]}" exists`);
|
||||
}
|
||||
});
|
||||
|
||||
/* ---------------------------------------------------------------- music */
|
||||
|
||||
const trackOf = (name) => MUSIC_TABLES.find((t) => Object.hasOwn(t, name))[name];
|
||||
|
||||
test("music: notes read as their pitch, sharps and flats included", () => {
|
||||
assert.equal(noteFreq("A4"), 440);
|
||||
assert.ok(Math.abs(noteFreq("C#5") - 554.37) < 0.01);
|
||||
assert.equal(noteFreq("Db5"), noteFreq("C#5"));
|
||||
assert.ok(Math.abs(noteFreq("A3") - 220) < 1e-9);
|
||||
assert.ok(Number.isNaN(noteFreq("H2")));
|
||||
});
|
||||
|
||||
test("music: every track reads, with known waves, shares for gains and a start for each voice", () => {
|
||||
assert.ok(musicNames().length >= 1, "at least one track");
|
||||
for (const name of musicNames()) {
|
||||
const track = trackOf(name);
|
||||
const song = compileTrack(track);
|
||||
assert.ok(song.length >= 16, `${name} runs a bar at least`);
|
||||
for (const [v, voice] of Object.entries(track.voices)) {
|
||||
assert.ok(voice.kit || ["pulse", "triangle", "sine", "square", "sawtooth"].includes(voice.wave), `${name}.${v} has a known wave`);
|
||||
assert.ok((voice.gain ?? 1) > 0 && (voice.gain ?? 1) <= 1, `${name}.${v}'s gain is a share`);
|
||||
assert.ok((voice.from ?? 0) >= 0 && (voice.from ?? 0) <= 1, `${name}.${v} comes in between 0 and 1`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("music: a track that does not read is turned away", () => {
|
||||
const ok = { bpm: 120, voices: { a: { wave: "pulse" } }, patterns: { A: { a: "A4 - . C5" } }, order: ["A"] };
|
||||
assert.equal(compileTrack(ok).length, 4);
|
||||
assert.throws(() => compileTrack({ ...ok, bpm: 900 }), /bpm/);
|
||||
assert.throws(() => compileTrack({ ...ok, patterns: { A: { a: "A4 - . Z9" } } }), /not a note/);
|
||||
assert.throws(() => compileTrack({ ...ok, voices: { a: { wave: "pulse" }, b: { kit: true } }, patterns: { A: { a: "A4 - . C5", b: "k ." } } }), /steps/);
|
||||
assert.throws(() => compileTrack({ ...ok, voices: { a: { wave: "pulse" }, b: { kit: true } }, patterns: { A: { a: "A4 - . C5", b: "k . x ." } } }), /not a drum/);
|
||||
assert.throws(() => compileTrack({ ...ok, order: ["B"] }), /missing pattern/);
|
||||
const arp = compileTrack({ ...ok, patterns: { A: { a: "A3^037 - - ." } } });
|
||||
assert.equal(arp.patterns.A.lines.a[0].freqs.length, 3, "an arpeggio cycles three notes");
|
||||
assert.equal(arp.patterns.A.lines.a[0].len, 3, "held for three steps");
|
||||
});
|
||||
|
||||
test("music: a track plays notes while asked for, quiets when hushed, and stays silent while Play sounds is off", () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx, made } = AUDIO;
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
looks.sound = true;
|
||||
const name = musicNames()[0];
|
||||
const before = made.started;
|
||||
music(name, 1);
|
||||
assert.ok(made.started > before, "notes booked at once");
|
||||
music("nope", 1);
|
||||
hushMusic();
|
||||
looks.sound = false;
|
||||
const quiet = made.started;
|
||||
music(name, 1);
|
||||
assert.equal(made.started, quiet, "Play sounds off: no music");
|
||||
} finally {
|
||||
hushMusic();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("music: plays through its own gentle compressor (as on the prototype pages), never the sounds' harder one", () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx } = AUDIO;
|
||||
const proto = Ctx.prototype;
|
||||
const was = { gain: proto.createGain };
|
||||
const buses = [];
|
||||
// Each node remembers what it is connected to.
|
||||
const wired = (n) => Object.assign(n, { to: [], connect(x) { n.to.push(x); } });
|
||||
proto.createGain = function () { const g = wired(was.gain.call(this)); buses.push(g); return g; };
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
hushMusic();
|
||||
looks.sound = true;
|
||||
music(musicNames()[0], 1);
|
||||
// The compressor is made once per context, maybe before this test, so
|
||||
// it is found through the track's bus rather than by being watched.
|
||||
const isComp = (x) => x && x.threshold && x.ratio;
|
||||
const bus = buses.find((g) => g.to.some(isComp));
|
||||
assert.ok(bus, "the track's bus feeds a compressor");
|
||||
const comp = bus.to.find(isComp);
|
||||
assert.equal(comp.threshold.value, -14, "the prototype pages' threshold, not the sounds' -20");
|
||||
assert.equal(comp.ratio.value, 4);
|
||||
} finally {
|
||||
hushMusic();
|
||||
proto.createGain = was.gain;
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("music: a new track crossfades in over seconds while the last keeps playing, and a hush cuts both", () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx, made } = AUDIO;
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
looks.sound = true;
|
||||
const [first, second] = musicNames();
|
||||
hushMusic();
|
||||
const mark = made.gains.length;
|
||||
music(first, 1);
|
||||
const firstBus = made.gains.slice(mark).find((g) => g.gain.ramps.some((r) => r.kind === "linear" && r.v > 0.1));
|
||||
const at = made.gains.length;
|
||||
music(second, 1);
|
||||
const out = firstBus.gain.ramps.at(-1);
|
||||
const from = firstBus.gain.ramps.at(-2);
|
||||
assert.equal(out.kind, "linear", "the last track ramps down, not cut");
|
||||
assert.ok(out.v < 0.001 && out.t - from.t >= 2, "over seconds");
|
||||
const secondBus = made.gains[at];
|
||||
const up = secondBus.gain.ramps.find((r) => r.kind === "linear");
|
||||
assert.ok(up.v > 0.1 && up.t - secondBus.gain.ramps[0].t >= 2, "the new track ramps up over the same seconds");
|
||||
hushMusic();
|
||||
assert.equal(secondBus.gain.ramps.at(-1).kind, "target", "a hush fades the new track at once");
|
||||
} finally {
|
||||
hushMusic();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("music: every track a game's source asks for is one the sequencer has", () => {
|
||||
const tracks = new Set(musicNames());
|
||||
for (const file of fs.readdirSync(GAMES).filter((f) => f.endsWith(".js") && !f.endsWith("-sfx.js"))) {
|
||||
const source = fs.readFileSync(path.join(GAMES, file), "utf8");
|
||||
for (const m of source.matchAll(/\bmusic\(\s*"(\w+)"/g)) assert.ok(tracks.has(m[1]), `${file}: track "${m[1]}" exists`);
|
||||
}
|
||||
});
|
||||
|
||||
test("music: the volume scales the track's level, a change glides there, and a volume of 0 plays nothing", () => {
|
||||
const saved = { sound: looks.sound, ctor: globalThis.AudioContext };
|
||||
const { Ctx, made } = AUDIO;
|
||||
globalThis.AudioContext = Ctx;
|
||||
try {
|
||||
looks.sound = true;
|
||||
const [first, second] = musicNames();
|
||||
hushMusic();
|
||||
const peak = (volume) => {
|
||||
hushMusic();
|
||||
const mark = made.gains.length;
|
||||
music(first, 1, volume);
|
||||
return made.gains.slice(mark).find((g) => g.gain.ramps.some((r) => r.kind === "linear" && r.v > 0.01));
|
||||
};
|
||||
const full = peak(1).gain.ramps.find((r) => r.kind === "linear").v;
|
||||
const bus = peak(0.5);
|
||||
assert.ok(Math.abs(bus.gain.ramps.find((r) => r.kind === "linear").v - full / 2) < 1e-9, "half the volume, half the level");
|
||||
music(first, 1, 0.25);
|
||||
const glide = bus.gain.ramps.at(-1);
|
||||
assert.equal(glide.kind, "target", "a slider move glides");
|
||||
assert.ok(Math.abs(glide.v - full / 4) < 1e-9, "to the new level");
|
||||
hushMusic();
|
||||
const quiet = made.started;
|
||||
music(second, 1, 0);
|
||||
assert.equal(made.started, quiet, "a volume of 0: nothing booked");
|
||||
} finally {
|
||||
hushMusic();
|
||||
looks.sound = saved.sound;
|
||||
globalThis.AudioContext = saved.ctor;
|
||||
}
|
||||
});
|
||||
|
||||
test("music: every Sunset Drive road has a song, and every song is a real track", () => {
|
||||
const tracks = new Set(musicNames());
|
||||
assert.deepEqual(Object.keys(ROAD_MUSIC).sort(), Object.keys(REGIONS).sort(), "a song for every road");
|
||||
for (const [road, name] of Object.entries(ROAD_MUSIC)) {
|
||||
assert.ok(Object.hasOwn(REGIONS, road), `road ${road} exists`);
|
||||
assert.ok(tracks.has(name), `${road}: track "${name}" exists`);
|
||||
}
|
||||
});
|
||||
@@ -47,7 +47,8 @@ test("workspace: a folder added on the dashboard survives dashboard → plan →
|
||||
const s = consoleSession(["--workflow", "dashboard"]);
|
||||
const extra = tempFolder();
|
||||
try {
|
||||
assert.deepEqual(s.opened.workspace.folders, [{ name: defaultName(ROOT), path: ROOT, original: true }]);
|
||||
assert.equal("workspace" in s.opened, false, "open prints the folder list only with more than one folder");
|
||||
assert.deepEqual(wsFile(s).folders.map((f) => [f.name, f.path, f.original]), [[defaultName(ROOT), ROOT, true]]);
|
||||
const added = await addFolder(s, { path: extra, description: " the design notes " });
|
||||
assert.equal(added.status, 200);
|
||||
assert.equal(added.body.name, defaultName(extra));
|
||||
@@ -85,10 +86,10 @@ test("workspace: a folder added on the dashboard survives dashboard → plan →
|
||||
);
|
||||
assert.equal(meterView(readLedger(fresh.session)).points, 0);
|
||||
} finally {
|
||||
cli(["stop", "--session", fresh.sid]);
|
||||
cli(["stop", "--session", fresh.sid, "--force"]);
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -122,7 +123,7 @@ test("workspace: a spec starts from the project's list, then stands alone, and t
|
||||
assert.deepEqual(again.folders.map((f) => f.path), [ROOT, shared, specOnly], "the spec's own list comes back");
|
||||
assert.equal((await s.send("/workspace/scope", { spec: "../elsewhere" })).status, 400);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(shared, { recursive: true, force: true });
|
||||
fs.rmSync(specOnly, { recursive: true, force: true });
|
||||
}
|
||||
@@ -138,7 +139,7 @@ test("workspace: open --spec starts on that spec's list, a posted specDir takes
|
||||
await addFolder(s, { path: shared });
|
||||
await s.send("/workspace/scope", { spec: "specs/demo" });
|
||||
await addFolder(s, { path: specOnly });
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
|
||||
other = consoleSession(["--workflow", "implement", "--spec", "specs/demo"], { keepRemembered: true });
|
||||
assert.deepEqual(other.opened.workspace.folders.map((f) => f.path), [ROOT, shared, specOnly]);
|
||||
@@ -159,7 +160,7 @@ test("workspace: open --spec starts on that spec's list, a posted specDir takes
|
||||
assert.ok(rememberedFor(""), "the project's list is kept");
|
||||
assert.equal(cli(["forget"], { expectFail: true }).status, 2);
|
||||
} finally {
|
||||
for (const x of [s, other, planned]) if (x) cli(["stop", "--session", x.sid]);
|
||||
for (const x of [s, other, planned]) if (x) cli(["stop", "--session", x.sid, "--force"]);
|
||||
fs.rmSync(shared, { recursive: true, force: true });
|
||||
fs.rmSync(specOnly, { recursive: true, force: true });
|
||||
}
|
||||
@@ -202,7 +203,7 @@ test("workspace: add resolves from the session's folder and refuses a file, a mi
|
||||
assert.deepEqual(wsFile(s).folders.map((f) => f.id), ["f0", "f1", "f2"], "refusals changed nothing");
|
||||
assert.deepEqual(wsFile(s).changes.map((c) => [c.kind, c.version]), [["added", 1], ["added", 2]]);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(quoted, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -246,7 +247,7 @@ test("workspace: the original can be renamed and described but never removed; ot
|
||||
assert.deepEqual(wsFile(s).folders.map((f) => f.id), ["f0"]);
|
||||
assert.equal(wsFile(s).changes.at(-1).kind, "removed");
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -271,7 +272,7 @@ test("workspace: browse returns the picked folder, or canceled, and is hidden wh
|
||||
assert.equal(hidden.status, 404);
|
||||
assert.deepEqual(await hidden.json(), { reason: "no-picker" });
|
||||
} finally {
|
||||
for (const s of [echo, cancel, remote]) cli(["stop", "--session", s.sid]);
|
||||
for (const s of [echo, cancel, remote]) cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(picked, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -300,7 +301,7 @@ test("workspace: a folder deleted on disk is marked missing once, and found agai
|
||||
"the launch alone marked the folder missing"
|
||||
);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(gone, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -316,13 +317,15 @@ test("workspace: a change never ends a wait slice, rides on the next send exactl
|
||||
await sleep(1500);
|
||||
assert.equal((await addFolder(s, { path: extra })).status, 200);
|
||||
assert.equal(await exited, 10, "the change alone did not end the slice");
|
||||
assert.equal(safeJson(out).pendingWorkspace, 1);
|
||||
const slice = safeJson(out);
|
||||
assert.equal(slice.waiting, true);
|
||||
assert.equal("pendingWorkspace" in slice, false, "the slice line no longer reports the pending change");
|
||||
|
||||
const name = defaultName(extra);
|
||||
assert.equal((await s.send("/submit", EXPORT_A)).status, 200);
|
||||
const first = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(first.status, 0);
|
||||
assert.deepEqual(first.json.workspace.map((c) => [c.kind, c.name]), [["added", name]]);
|
||||
assert.equal("workspace" in first.json, false, "a change arrives as a reply line only");
|
||||
assert.match(first.json.reply, /^Export format: a\n/);
|
||||
assert.match(first.json.reply, new RegExp(`^Workspace: added @${name} — `, "m"));
|
||||
assert.equal(readWorkspaceCursor(s.session), 1);
|
||||
@@ -337,9 +340,11 @@ test("workspace: a change never ends a wait slice, rides on the next send exactl
|
||||
fs.writeFileSync(path.join(s.session, "workspace-cursor.json"), JSON.stringify({ version: 0 }));
|
||||
assert.equal((await s.send("/submit", EXPORT_A)).status, 200);
|
||||
const again = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.deepEqual(again.json.workspace.map((c) => c.name), [name]);
|
||||
assert.equal("workspace" in again.json, false);
|
||||
assert.equal(again.json.reply.split("\n").filter((l) => l.startsWith("Workspace:")).length, 1, "the change comes again as one line");
|
||||
assert.ok(again.json.reply.includes("@" + name));
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -351,13 +356,30 @@ test("workspace: chat hands over a workspace change on its own, then has nothing
|
||||
assert.equal((await addFolder(s, { path: extra })).status, 200);
|
||||
const got = cli(["chat", "--session", s.sid]);
|
||||
assert.equal(got.status, 0);
|
||||
assert.deepEqual(got.json.chat, []);
|
||||
assert.deepEqual(got.json.workspace.map((c) => c.kind), ["added"]);
|
||||
assert.equal(got.json.chat, undefined, "no question, no chat key");
|
||||
assert.equal("workspace" in got.json, false, "reply lines only");
|
||||
assert.match(got.json.reply, /^Workspace: added @/);
|
||||
assert.ok(got.json.terminalLine);
|
||||
assert.equal(got.json.reply.split("\n").length, 1);
|
||||
assert.equal(cli(["chat", "--session", s.sid]).status, 10);
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid]);
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("workspace: a change arrives as a Workspace line in reply only, never as a workspace object", async () => {
|
||||
const s = openSession();
|
||||
const extra = tempFolder();
|
||||
try {
|
||||
assert.equal((await addFolder(s, { path: extra })).status, 200);
|
||||
assert.equal((await s.send("/submit", EXPORT_A)).status, 200);
|
||||
const got = cli(["wait", "--session", s.sid, "--seconds", "10"]);
|
||||
assert.equal(got.status, 0);
|
||||
assert.equal("workspace" in got.json, false);
|
||||
assert.equal("pendingWorkspace" in got.json, false);
|
||||
assert.match(got.json.reply, new RegExp(`^Workspace: added @${defaultName(extra)}`, "m"));
|
||||
} finally {
|
||||
cli(["stop", "--session", s.sid, "--force"]);
|
||||
fs.rmSync(extra, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -109,6 +109,28 @@ export function safeJson(s) {
|
||||
}
|
||||
}
|
||||
|
||||
// One wait slice of a session, parsed: { code, out } where out is the last
|
||||
// stdout line as JSON (null when it is not). Exit 10 and 20 are results here,
|
||||
// not failures.
|
||||
export function waitOnce(sid, seconds = 5, opts) {
|
||||
const res = cli(["wait", "--session", sid, "--seconds", String(seconds)], opts);
|
||||
return { code: res.status, out: res.json, stdout: res.stdout, stderr: res.stderr };
|
||||
}
|
||||
|
||||
// The last non-empty line of a command's stdout: `post --wait` prints the
|
||||
// post's line, then the wait's.
|
||||
export const lastLine = (stdout) => String(stdout).trim().split("\n").filter(Boolean).pop() ?? "";
|
||||
|
||||
// End one session the way an agent must: a finish first, then stop. A test
|
||||
// that only wants a session gone for cleanup may pass --force to stop instead.
|
||||
export function stopSession(sid, opts) {
|
||||
postFinish(sid, opts);
|
||||
return cli(["stop", "--session", sid], opts);
|
||||
}
|
||||
function postFinish(sid, opts) {
|
||||
cli(["post", "--session", sid, "--file", payload(`finish-${sid}.json`, { finish: { headline: "Test done" } })], opts);
|
||||
}
|
||||
|
||||
export function payload(file, obj) {
|
||||
const p = path.join(HOME, file);
|
||||
fs.writeFileSync(p, JSON.stringify(obj));
|
||||
|
||||
Reference in new issue
Block a user