Files
plan2code/scripts/test-web-console-page-session.mjs
T
2026-11-03 03:59:50 -08:00

1092 lines
65 KiB
JavaScript

// Page tests for how a session ends and comes back: the finished screen and
// its buttons, Stop and Stop with a handoff, and a page that loses its server
// and finds it again after a resume. Run with:
// node --test scripts/test-web-console-page-session.mjs
//
// Each test drives the real console in a real Chrome or Edge through
// scripts/page-test-helpers.mjs: one browser for the file, a fresh console
// session per test.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { pageSuite, openSession, itemCard, drawn, textOf, tempProject , fillBox, boxValue} 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";
const suite = pageSuite(test);
// The banner the page raises when it loses its server mid-session.
const LOST_CONTACT = /Lost contact with Plan2Code\. Nothing you have typed is lost\./;
// A plan session on the person's turn, the way an agent opens one: one text
// question and the agent listening.
const PLAN_QUESTION = {
items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name for the export." }],
agent: { status: "waiting" },
};
// 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, "--force"], { cwd: s.project });
assert.ok(await until(async () => !(await s.answers()), 5000), "the server still answers after stop");
}
// The one send `wait` hands the agent; fails the test when nothing arrived.
function collect(s) {
const got = s.wait(10);
assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code}): ${got.message || ""}`);
return got;
}
// Local helper: checks `fn` keeps returning true for `ms`. A sleep would
// prove nothing; this fails the moment the page shows what it must not.
async function holds(fn, ms) {
const end = Date.now() + ms;
while (Date.now() < end) {
if (!(await fn())) return false;
await new Promise((r) => setTimeout(r, 100));
}
return true;
}
test("the finished screen shows the next command with --web, copies it, turns Send off, and Back to the dashboard reaches the agent", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.context.grantPermissions(["clipboard-read", "clipboard-write"], { origin: new URL(s.url).origin });
s.post({
settle: true,
finish: {
headline: "The plan is written",
body: "Everything is under `specs/audit-export/`. Read `PLAN.md` first.",
command: "/plan2code-2-document",
dashboard: true,
},
});
const main = s.page.locator("#main");
await main.getByRole("heading", { name: "The plan is written" }).waitFor();
const shown = main.locator("code").filter({ hasText: /^\/plan2code-2-document --web$/ });
assert.equal(await shown.count(), 1, "the command is shown once, with --web appended");
// The Copy that belongs to this command: the innermost block holding both,
// whatever wraps them.
// (`has` is matched inside each candidate, so these start from the page.)
const code = s.page.locator("code").filter({ hasText: /^\/plan2code-2-document --web$/ });
const copy = s.page.getByRole("button", { name: "Copy", exact: true });
await main.locator("*", { has: code }).filter({ has: copy }).last().getByRole("button", { name: "Copy", exact: true }).click();
await s.page.waitForFunction(async () => (await navigator.clipboard.readText()) === "/plan2code-2-document --web");
assert.equal(await s.page.evaluate(() => navigator.clipboard.readText()), "/plan2code-2-document --web");
assert.equal(await s.page.locator("#btn-send").isDisabled(), true, "Send is still on after the finish");
await main.getByRole("button", { name: "Back to the dashboard" }).click();
const got = collect(s);
assert.equal(got.type, "submit");
assert.deepEqual(
got.actions.map(({ i, type }) => ({ i, type })),
[{ i: "__dashboard", type: "dashboard" }]
);
});
// What a person sees break: no Continue here on a finish that names a skill, one
// beside a git command or a pause, one at the red meter level, or a press that
// reaches the agent as anything but the dashboard's own launch.
test("Continue here shows beside a skill's next step while the meter is not red and sends a launch with the skill and spec", async (t) => {
const browser = await suite.browser();
const next = { headline: "The plan is documented", command: "/plan2code-3-implement specs/audit-export/overview.md", dashboard: true };
const s = await openSession(browser, { t, workflow: "document", payload: { agent: { status: "working", activity: "Writing" } } });
s.post({ finish: next });
const main = s.page.locator("#main");
const go = main.getByRole("button", { name: "Continue here" });
await go.waitFor();
assert.equal(await go.count(), 1);
await go.click();
const got = collect(s);
assert.deepEqual(got.actions, [
{ i: "__launch", type: "launch", skill: "plan2code-3-implement", workflow: "implement", spec: "specs/audit-export" },
]);
assert.equal(got.reply, "Start Implement (/plan2code-3-implement) for specs/audit-export, right here in this session.");
// The hop's resume is the dashboard's: the skill's workflow and the spec.
assert.match(got.resume, /--workflow implement --spec specs\/audit-export$/);
await main.getByRole("button", { name: "Starting the next step…" }).waitFor();
assert.equal(await main.getByRole("button", { name: "Back to the dashboard" }).isDisabled(), true, "one press locks the other buttons");
// No skill to continue into: a git command, or a pause.
const git = await openSession(browser, { t, workflow: "quick-task", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
git.post({ finish: { headline: "Quick task done", command: "git add -A && git commit -m x -m y", dashboard: true } });
await git.page.locator("#main").getByRole("heading", { name: "Quick task done" }).waitFor();
assert.equal(await git.page.getByRole("button", { name: "Continue here" }).count(), 0, "a git command is not a skill");
const paused = await openSession(browser, { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
paused.post({ finish: { headline: "Paused at Phase 2", command: "/plan2code-3-implement specs/audit-export/overview.md" } });
await paused.page.locator("#main").getByRole("heading", { name: "Paused at Phase 2" }).waitFor();
assert.equal(await paused.page.getByRole("button", { name: "Continue here" }).count(), 0, "a pause is not continued");
});
test("Update CHANGELOG first shows beside Commit it now only when the finish asks for it, and sends __changelog", async (t) => {
const browser = await suite.browser();
const base = { headline: "Quick task done", command: "git add -A && git commit -m x -m y", commit: true, dashboard: true };
const plain = await openSession(browser, { t, workflow: "quick-task", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
plain.post({ finish: base });
await plain.page.locator("#main").getByRole("button", { name: "Commit it now" }).waitFor();
assert.equal(await plain.page.getByRole("button", { name: "Update CHANGELOG first" }).count(), 0, "no flag, no button");
const s = await openSession(browser, { t, workflow: "quick-task", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
s.post({ finish: { ...base, changelog: true } });
const main = s.page.locator("#main");
const go = main.getByRole("button", { name: "Update CHANGELOG first" });
await go.waitFor();
assert.equal(await main.getByRole("button", { name: "Commit it now" }).count(), 1);
await go.click();
assert.deepEqual(collect(s).actions.map(({ i, type }) => ({ i, type })), [{ i: "__changelog", type: "changelog" }]);
await main.getByRole("button", { name: "Opening Changelog…" }).waitFor();
assert.equal(await main.getByRole("button", { name: "Commit it now" }).isDisabled(), true, "one press locks the other buttons");
});
// Pressed, then left: the agent's turn had ended, so nothing collects the
// press. The line stops promising it is opening and offers continue instead.
test("a finished screen's press that nothing collects says Plan2Code is not running, with continue as a button under the app", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "quick-task",
clock: true,
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
init: FAKE_APP_FRAME,
});
s.post({ finish: { headline: "Quick task done", command: "git add -A && git commit -m x -m y", commit: true, changelog: true, dashboard: true } });
const main = s.page.locator("#main");
await main.getByRole("button", { name: "Update CHANGELOG first" }).click();
await lineSays(s, /^Opening Changelog…/);
await s.page.clock.fastForward(200_000);
await lineSays(s, /^Plan2Code is not running\. Your choice is saved/);
assert.match(await s.page.locator("#planny").getAttribute("class"), /\bis-adrift\b/);
const press = s.page.locator("#agent-text .agent-key-btn");
assert.equal(await press.textContent(), "continue");
await press.click();
await until(async () => (await toApp(s, "agent-continue")).length === 1, 5000);
});
test("Continue here is hidden once the session meter is red, and the command and fresh-session advice stay", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
// Ten points: a thirty-task phase scores ten, the red level.
s.post({ run: { event: "implement-phase", id: "phase-1", tasks: 30 } });
await s.page.locator("#meter-pill[data-level='red']").waitFor();
s.post({ finish: { headline: "Phase 1 is done", command: "/plan2code-3-implement specs/audit-export/overview.md", dashboard: true } });
const main = s.page.locator("#main");
await main.getByRole("heading", { name: "Phase 1 is done" }).waitFor();
assert.equal(await main.getByRole("button", { name: "Continue here" }).count(), 0, "Continue here at red");
assert.ok(await main.locator("code").filter({ hasText: /^\/plan2code-3-implement specs\/audit-export\/overview\.md --web$/ }).count(), "the command stays");
assert.equal(await closeGuide(s).count(), 1, "the fresh-session advice stays");
});
// Under the desktop app (PLAN2CODE_IN_APP=1) the fresh-session advice in the
// meter's popover and the dashboard's red banner must point at the app's own
// New Session, never a command to copy into a terminal that is not there:
// the popover's is a button filled with the user's highlight color.
test("under the app, the meter popover and the dashboard's red banner point at New Session, not a command", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
});
s.post({ run: { event: "implement-phase", id: "phase-1", tasks: 30 } });
const pill = s.page.locator("#meter-pill[data-level='red']");
await pill.waitFor();
await pill.click();
const fresh = s.page.locator("#meter-fresh");
const press = fresh.getByRole("button", { name: "Start a New Session" });
await press.waitFor();
assert.equal(await fresh.locator(".meter-fresh-text").count(), 0, "the button is the whole note, no sentence around it");
// The page's highlight, resolved the same way the button's fill is.
const [fill, highlight] = await press.evaluate((n) => {
const probe = document.createElement("i");
probe.style.color = "var(--accent)";
n.append(probe);
const color = getComputedStyle(probe).color;
probe.remove();
return [getComputedStyle(n).backgroundColor, color];
});
assert.equal(fill, highlight, "filled with the user's highlight color");
assert.equal(await fresh.locator("code").count(), 0, "no command to copy under the app");
});
// The desktop app's frame, as the page sees it: a parent that keeps every
// message posted to it, for the test to read back.
const FAKE_APP_FRAME = () => {
window.__toApp = [];
Object.defineProperty(window, "parent", { configurable: true, get: () => ({ postMessage: (m) => window.__toApp.push(m) }) });
};
const toApp = (s, kind) => s.page.evaluate((k) => window.__toApp.filter((m) => m.plan2code === k), kind);
test("under the app, the meter popover's Start a New Session button asks the app for its New Session", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
init: FAKE_APP_FRAME,
});
s.post({ run: { event: "implement-phase", id: "phase-1", tasks: 30 } });
const pill = s.page.locator("#meter-pill[data-level='red']");
await pill.waitFor();
await pill.click();
await s.page.locator("#meter-fresh").getByRole("button", { name: "Start a New Session" }).click();
await until(async () => (await toApp(s, "new-session")).length === 1, 5000);
assert.deepEqual(await toApp(s, "new-session"), [{ plan2code: "new-session" }], "a named request, nothing else in it");
});
// A menu option the agent marks `fresh` (Pathfinder's "Start fresh") is a clean
// start: under the app it reads Start New Session and sending it asks the app
// for its New Session; any other option, and the classic console, do not.
const FRESH_MENU = {
items: [
{
id: "q1",
kind: "menu",
title: "Next step",
body: "Continue here, or start fresh?",
command: "/plan2code-0-pathfinder specs/x/pathfinder",
options: [
{ k: "1", text: "Row-count ceiling" },
{ k: "2", text: "Start fresh", fresh: true },
],
},
],
agent: { status: "waiting" },
};
test("under the app, a fresh menu option reads Start New Session, and picking another option starts nothing", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "pathfinder", payload: FRESH_MENU, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
assert.equal(await s.page.getByRole("radio", { name: /Start New Session/ }).count(), 1, "the app's wording");
assert.equal(await s.page.getByText("Start fresh", { exact: true }).count(), 0, "replaces the classic one");
await s.page.getByRole("radio", { name: /Row-count ceiling/ }).check();
await s.page.click("#btn-send");
await s.page.locator("#btn-send:has-text('Send to Plan2Code')").waitFor();
assert.equal((await toApp(s, "new-session")).length, 0, "another option starts nothing");
});
test("under the app, picking the fresh menu option and sending it posts new-session", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "pathfinder", payload: FRESH_MENU, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
await s.page.getByRole("radio", { name: /Start New Session/ }).check();
await s.page.click("#btn-send");
await until(async () => (await toApp(s, "new-session")).length === 1, 5000);
assert.deepEqual(await toApp(s, "new-session"), [{ plan2code: "new-session" }], "a named request, nothing else in it");
});
test("outside the app, a fresh menu option keeps its own wording and starts no session", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "pathfinder", payload: FRESH_MENU });
assert.equal(await s.page.getByRole("radio", { name: /Start New Session/ }).count(), 0);
await s.page.getByRole("radio", { name: /Start fresh/ }).check();
await s.page.click("#btn-send");
await s.page.locator("#btn-send:has-text('Send to Plan2Code')").waitFor();
});
test("under the app, a finish with a skill command offers Start a New Session; outside it does not", async (t) => {
const inApp = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
init: FAKE_APP_FRAME,
});
inApp.post({ finish: { headline: "A skill next", command: "/plan2code-4-finalize" } });
await inApp.page.getByRole("heading", { name: "A skill next" }).waitFor();
await inApp.page.getByRole("button", { name: "Start a New Session" }).click();
await until(async () => (await toApp(inApp, "new-session")).length === 1, 5000);
const plain = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
plain.post({ finish: { headline: "A skill next", command: "/plan2code-4-finalize" } });
await plain.page.getByRole("heading", { name: "A skill next" }).waitFor();
assert.equal(await plain.page.getByRole("button", { name: "Start a New Session" }).count(), 0);
});
test("under the app, the not running line's continue is a button that asks the app to type it, and the page hands the app its highlight", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
clock: true,
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }], agent: { status: "waiting" } },
env: { PLAN2CODE_IN_APP: "1" },
init: FAKE_APP_FRAME,
});
const looks = await toApp(s, "looks");
assert.ok(looks.length >= 1, "the page told the app its highlight");
assert.deepEqual(looks.at(-1).accent, ["#619fe5", "#1a2533", "#0c1117", "#3d5978"], "the default highlight, in its dark shades");
await s.page.clock.fastForward(200_000);
await lineSays(s, /^Plan2Code is not running right now\./);
const press = s.page.locator("#agent-text .agent-key-btn");
assert.equal(await press.textContent(), "continue");
await press.click();
await until(async () => (await toApp(s, "agent-continue")).length === 1, 5000);
assert.ok(await press.isDisabled(), "held off, so a double press does not type it twice");
});
// The app's webview opens no new windows, so a link off the page asks the
// console to open it in the default browser instead, and says where to paste
// it when that fails.
const FEEDBACK_URL = "https://github.com/jparkerweb/plan2code/issues/new/choose";
test("under the app, a link off the page goes to the default browser through the console, not a new window", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
const asked = [];
await s.page.route("**/open-link", async (route) => {
asked.push(route.request().postDataJSON());
await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify({ ok: true, url: FEEDBACK_URL }) });
});
let popups = 0;
s.page.context().on("page", () => popups++);
await s.page.locator("#btn-feedback").click();
await until(async () => asked.length === 1, 5000);
assert.deepEqual(asked, [{ url: FEEDBACK_URL }]);
await new Promise((r) => setTimeout(r, 300));
assert.equal(popups, 0, "no window opened inside the app");
});
test("under the app, a link the console cannot open is shown to paste into a browser", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION, env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
await s.page.route("**/open-link", (route) => route.fulfill({ status: 500, contentType: "application/json", body: "{}" }));
await s.page.locator("#btn-feedback").click();
await s.page.waitForFunction((u) => document.getElementById("banner").textContent.includes(u), FEEDBACK_URL, { timeout: 5000 });
assert.match(await s.page.locator("#banner").innerText(), /paste it into your browser/i);
});
test("outside the app, a link off the page opens as a plain link, with no detour through the console", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
let asked = 0;
await s.page.route("**/open-link", (route) => {
asked++;
return route.fulfill({ status: 200, contentType: "application/json", body: "{}" });
});
const popup = s.page.context().waitForEvent("page", { timeout: 5000 });
await s.page.locator("#btn-feedback").click();
await (await popup).close();
assert.equal(asked, 0);
});
test("outside the app, the not running line's continue stays a word to type", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
clock: true,
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }], agent: { status: "waiting" } },
});
await s.page.clock.fastForward(200_000);
await lineSays(s, /^Plan2Code is not running right now\./);
assert.equal(await s.page.locator("#agent-text .agent-key-btn").count(), 0);
assert.equal(await s.page.locator("#agent-text strong.agent-key").textContent(), "continue");
});
test("Stop session, confirmed, sends __stop with no handoff", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.click("#btn-stop");
await s.page.locator("#stop-go").click();
const got = collect(s);
assert.equal(got.type, "submit");
const stop = got.actions.find((a) => a.i === "__stop");
assert.deepEqual(stop, { i: "__stop", type: "stop" });
});
test("Stop with a handoff sends __stop with handoff, and the paused finish and stop that follow end on the paused screen, not an error", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.click("#btn-stop");
const handoff = s.page.locator("#stop-handoff");
assert.equal(await handoff.isVisible(), true, "the handoff choice is offered off the dashboard");
await handoff.click();
const got = collect(s);
assert.equal(got.type, "submit");
const stop = got.actions.find((a) => a.i === "__stop");
assert.deepEqual(stop, { i: "__stop", type: "stop", handoff: true });
// What the agent does next (console-stop.md): a paused finish without
// --wait and no dashboard, then `stop`.
s.post({
settle: true,
finish: {
headline: "Paused at the naming question",
body: "Your place is saved, and a handoff is waiting on the dashboard. The naming question is still open.",
command: "/plan2code-1-plan",
},
});
const main = s.page.locator("#main");
await main.getByRole("heading", { name: "Paused at the naming question" }).waitFor();
await stopServer(s);
// The page needs GONE_AFTER_MS without contact before it would call the
// server lost. Through that window and past it, the paused screen stays.
const settled = async () =>
!LOST_CONTACT.test(await s.page.locator("#banner").innerText()) &&
!(await s.page.locator("#planny").getAttribute("class")).includes("is-gone");
assert.ok(await holds(settled, GONE_AFTER_MS + 3000), "the page raised a lost-contact state after a paused finish");
assert.match(await main.innerText(), /Session paused/i);
assert.match(await textOf(s.page.locator("#agent-text")), /^Paused\./);
assert.ok(await main.locator("code").filter({ hasText: /^\/plan2code-1-plan --web$/ }).count(), "the resume command is gone");
});
// Someone who presses Stop and steps away comes back to an answer: the
// wrapping-up dialog turns into Done once the stop lands and stays up until
// it is closed, rather than quietly going away.
test("the wrapping-up dialog says Done when the stop lands, and stays until closed", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.click("#btn-stop");
await s.page.locator("#stop-go").click();
const dlg = s.page.locator("#stopping-modal");
await dlg.waitFor();
assert.equal(await s.page.locator("#stopping-title").textContent(), "Wrapping up");
assert.doesNotMatch(await dlg.innerText(), /close the (window|tab)/i, "no advice to close the page mid-stop");
collect(s);
s.post({ settle: true, finish: { headline: "Paused at the naming question", body: "Your place is saved.", command: "/plan2code-1-plan" } });
await s.page.locator("#main").getByRole("heading", { name: "Paused at the naming question" }).waitFor();
await s.page.locator("#stopping-title").getByText("Done", { exact: true }).waitFor();
assert.equal(await s.page.locator("#stop-steps li.is-done").count(), 3, "every step ticked");
assert.ok(await holds(async () => dlg.isVisible(), 2000), "Done stays up on its own");
await s.page.locator("#stopping-hide").getByText("Close", { exact: true }).click();
await dlg.waitFor({ state: "hidden" });
});
test("a page that loses its server goes offline, and after a resume it shows the session again with the unsent answer still typed", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
const field = () => itemCard(s.page, "q1").locator(".md-host, input[type=text]").first();
await fillBox(field(), "audit-export");
// Typed, not sent: the page mirrors it to the server's draft.json, which
// is what a page on a new port reads back (localStorage is per origin).
const draftFile = path.join(s.session, "draft.json");
assert.ok(
await until(() => fs.existsSync(draftFile) && fs.readFileSync(draftFile, "utf8").includes("audit-export"), 5000),
"the typed answer never reached the server's draft"
);
await stopServer(s);
await s.page.waitForFunction(() => document.getElementById("planny").classList.contains("is-gone"), null, {
timeout: GONE_AFTER_MS + 10000,
});
assert.match(await textOf(s.page.locator("#agent-text")), /^Not connected\. Your answers are saved\./);
assert.match(await s.page.locator("#banner").innerText(), LOST_CONTACT);
assert.equal(await s.page.locator("#btn-send").isDisabled(), true, "Send is on with no server");
const resumed = cli(["open", "--resume", s.sid, "--workflow", "plan", "--no-open"], { cwd: s.project }).json;
assert.ok(resumed && resumed.url, "the resume printed no url");
await s.page.goto(resumed.url, { waitUntil: "domcontentloaded" });
await drawn(s.page);
await itemCard(s.page, "q1").getByText("What to call it").first().waitFor();
assert.equal(await boxValue(field()), "audit-export", "the unsent answer was lost across the resume");
assert.equal(await s.page.locator("#planny").evaluate((n) => n.classList.contains("is-gone")), false);
});
// The status line beside Planny, and its "What to check" button when it has
// one. The button opens Help on the stuck tab.
const statusLine = (s) => s.page.locator("#agent-text");
const whatToCheck = (s) => statusLine(s).getByRole("button", { name: "What to check" });
async function lineSays(s, re) {
await s.page.waitForFunction((src) => new RegExp(src).test(document.getElementById("agent-text").textContent), re.source, { timeout: 10000 });
return textOf(statusLine(s));
}
test("the quiet, not running and not connected lines offer What to check, opening Help on the stuck tab, and the plain lines do not", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
clock: true,
payload: { headline: { stage: "Phase 1", cleared: 0, total: 3 }, agent: { status: "working", activity: "Task 1 of 3: the reader" } },
});
// Working, and heard from just now: the plain working line.
await lineSays(s, /Task 1 of 3: the reader/);
assert.equal(await whatToCheck(s).count(), 0, "the working line is plain");
// Quiet for 30 s: the approval hint, with the button.
await s.page.clock.fastForward(40_000);
await lineSays(s, /waiting on an approval in your terminal/);
assert.equal(await whatToCheck(s).count(), 1, "the approval hint carries What to check");
// Quiet for two minutes: still working, and the button stays.
await s.page.clock.fastForward(100_000);
await lineSays(s, /^Still working on it\./);
assert.equal(await whatToCheck(s).count(), 1, "the quiet working line carries What to check");
// Back to real time, and the agent asks something: the person's turn is plain.
await s.page.clock.setSystemTime(Date.now());
s.post({ items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }], agent: { status: "waiting" } });
await lineSays(s, /^Your turn: 1 question waiting\./);
assert.equal(await whatToCheck(s).count(), 0, "the your-turn line is plain");
// Nobody listening for three minutes: not running, with the button.
await s.page.clock.fastForward(200_000);
await lineSays(s, /^Plan2Code is not running right now\./);
assert.equal(await whatToCheck(s).count(), 1, "the not running line carries What to check");
await whatToCheck(s).click();
await s.page.locator("#help-modal[open]").waitFor();
assert.equal(await s.page.locator("#help-tab-stuck").getAttribute("aria-selected"), "true", "Help opened on the stuck tab");
await s.page.keyboard.press("Escape");
await s.page.locator("#help-modal[open]").waitFor({ state: "detached" });
// Answered and sent, never collected, and nobody listening: the saved line.
await s.page.clock.setSystemTime(Date.now());
s.post({ agent: { status: "waiting" } });
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-send");
await lineSays(s, /^Sent\. Waiting for Plan2Code\./);
assert.equal(await whatToCheck(s).count(), 0, "the sent line is plain");
await s.page.clock.fastForward(200_000);
await lineSays(s, /^Plan2Code is not running\. Your answers are saved and waiting for it\./);
assert.equal(await whatToCheck(s).count(), 1, "the saved-and-waiting line carries What to check");
// No server at all: not connected, with the button.
await stopServer(s);
for (let i = 0; i < 20 && !(await s.page.locator("#planny.is-gone").count()); i++) {
await s.page.clock.fastForward(GONE_AFTER_MS);
await new Promise((r) => setTimeout(r, 250));
}
await lineSays(s, /^Not connected\. Your answers are saved\./);
assert.equal(await whatToCheck(s).count(), 1, "the not connected line carries What to check");
});
// An agent sitting in `wait` pings every five seconds and collects a send at
// once, so answers still uncollected after a minute of its silence mean
// nothing is listening: the wake-up help shows then, not after three minutes.
test("answers a waiting agent never collects bring up the saved-and-waiting line after a minute of silence, not before", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", clock: true, payload: PLAN_QUESTION });
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-send");
await lineSays(s, /^Sent\. Waiting for Plan2Code\./);
await s.page.clock.fastForward(30_000);
await lineSays(s, /^Sent\. Waiting for Plan2Code\./);
await s.page.clock.fastForward(40_000);
await lineSays(s, /^Plan2Code is not running\. Your answers are saved and waiting for it\./);
assert.equal(await whatToCheck(s).count(), 1, "the line carries What to check");
});
// An agent that asked and carried on working collects at its next `wait`, so
// a minute is no proof against it; three minutes of silence is, whatever
// longer quiet allowance it gave itself before it went.
test("answers a working agent has not collected bring up the saved-and-waiting line after three minutes, not its long quiet allowance", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement", clock: true, payload: PLAN_QUESTION });
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-send");
await lineSays(s, /^Sent\. Waiting for Plan2Code\./);
// Its last word before it went quiet: working, with half an hour to spare.
s.post({ agent: { status: "working", activity: "Task 1 of 3: the reader", quietMinutes: 30 } });
await lineSays(s, /Task 1 of 3: the reader/);
await s.page.clock.fastForward(70_000);
await lineSays(s, /Task 1 of 3: the reader/);
await s.page.clock.fastForward(130_000);
await lineSays(s, /^Plan2Code is not running\. Your answers are saved and waiting for it\./);
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 fillBox(s.page.locator("#ask-input"), "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 fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "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) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await stopServer(s);
await s.page.click("#btn-send");
await s.page.waitForFunction(() => document.getElementById("planny").classList.contains("is-gone"), null, { timeout: 3000 });
assert.match(await s.page.locator("#banner").innerText(), LOST_CONTACT);
assert.match(await textOf(statusLine(s)), /^Not connected\. Your answers are saved\./);
assert.equal(await whatToCheck(s).count(), 1, "the not connected line carries What to check");
});
test("a Send the server refuses shows the server's reason", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.route("**/submit", (route) =>
route.fulfill({ status: 500, contentType: "application/json", body: JSON.stringify({ error: "the disk is full" }) })
);
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-send");
await s.page.waitForFunction(() => /the disk is full/.test(document.getElementById("banner").textContent), null, { timeout: 3000 });
assert.match(await s.page.locator("#banner").innerText(), /Nothing was lost/);
});
test("a Send the server refuses as too large says to remove an attachment, not to try the same send again", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.route("**/submit", (route) =>
route.fulfill({ status: 413, contentType: "application/json", body: JSON.stringify({ error: "too large" }) })
);
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-send");
await s.page.waitForFunction(() => /remove an attachment/.test(document.getElementById("banner").textContent), null, { timeout: 3000 });
assert.doesNotMatch(await s.page.locator("#banner").innerText(), /try Send again/);
});
test("a Send lost on the way, with the server still up, says the console is there and to send again", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.route("**/submit", (route) => route.abort());
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-send");
await s.page.waitForFunction(() => /console is still up/.test(document.getElementById("banner").textContent), null, { timeout: 3000 });
assert.equal(await s.page.locator("#planny").evaluate((n) => n.classList.contains("is-gone")), false, "not called gone");
});
test("an answered finish offer comes back unanswered on a later finish, once the first finish has gone", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
const finishWith = (headline) => s.post({ finish: { headline, command: "/plan2code-3-implement specs/audit-export/overview.md", dashboard: true } });
const main = s.page.locator("#main");
finishWith("Phase 1 is done");
await main.getByRole("heading", { name: "Phase 1 is done" }).waitFor();
await main.getByRole("button", { name: "Back to the dashboard" }).click();
assert.deepEqual(collect(s).actions.map(({ i }) => i), ["__dashboard"]);
await lineSays(s, /^Opening the dashboard…/);
// The agent takes the press somewhere that clears the finish, and a later
// phase ends: that finish starts with its own offer unanswered.
s.post({ finish: null, agent: { status: "working", activity: "Task 1 of 1" } });
await lineSays(s, /Task 1 of 1/);
finishWith("Phase 2 is done");
await main.getByRole("heading", { name: "Phase 2 is done" }).waitFor();
await lineSays(s, /^Done\. Head back to the dashboard, or close this tab\./);
assert.equal(await main.getByRole("button", { name: "Back to the dashboard" }).count(), 1, "the later finish offers the way back again");
});
test("a finished session never puts a sent answer back on its form", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await fillBox(itemCard(s.page, "q1").locator(".md-host"), "audit-export");
await s.page.click("#btn-send");
collect(s);
// Collected and left open, then the session ends: nothing more can be sent,
// so the answer stays sent rather than coming back to edit. It would show
// once the finish goes away (a review taken up), as an answer ready to send.
s.post({ finish: { headline: "The plan is written", command: "/plan2code-2-document" }, agent: { status: "waiting" } });
await s.page.locator("#main").getByRole("heading", { name: "The plan is written" }).waitFor();
s.post({ finish: null, agent: { status: "waiting" } });
await s.page.locator("#main").getByRole("heading", { name: "The plan is written" }).waitFor({ state: "detached" });
const q1 = s.page.locator("#sidebar").getByRole("button", { name: /What to call it/ });
await q1.click();
await itemCard(s.page, "q1").waitFor();
const mark = q1.locator(".rail-mark");
assert.notEqual(await mark.getAttribute("title"), "ready to send", "the sent answer came back on the form");
const box = itemCard(s.page, "q1").locator(".md-host");
assert.notEqual((await box.count()) ? await boxValue(box) : "", "audit-export", "the sent answer is back in its box");
});
test("the footer keeps its workspace label on the dashboard, and the label opens the Workspace dialog", async (t) => {
const project = tempProject();
const name = path.basename(project);
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", project });
// Past Planny's wake-up and, on this console home's first run, the Welcome.
await s.page.getByRole("button", { name: "Skip the intro" }).click();
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" });
const foot = s.page.locator("footer.footer");
const where = s.page.locator("#footer-where");
await where.waitFor();
// The dashboard drops the summary and Send, never the label.
assert.equal(await foot.evaluate((f) => f.classList.contains("is-dash")), true, "the dashboard's footer is marked is-dash");
assert.equal(await s.page.locator("#footer-summary").isVisible(), false, "the summary shows on the dashboard");
assert.equal(await s.page.locator("#btn-send").isVisible(), false, "Send shows on the dashboard");
assert.match(await textOf(where), new RegExp(`^${name}`), "the label names the project");
assert.equal(await where.getAttribute("title"), "Open workspace");
assert.match(await where.getAttribute("aria-label"), new RegExp(`^Open workspace: ${name}`));
// A click opens the Workspace dialog on the session's folders; leaving the
// label leaves it as it was (no copied state to undo).
await where.click();
await s.page.locator("#workspace-modal[open]").waitFor();
assert.match(await textOf(s.page.locator("#workspace-list")), new RegExp(name));
await s.page.keyboard.press("Escape");
await s.page.locator("#workspace-modal[open]").waitFor({ state: "detached" });
await s.page.locator("body").click({ position: { x: 5, y: 5 } });
assert.match(await textOf(where), new RegExp(`^${name}`), "the label changed after a click away");
});
test("a workflow page uses its modules: the full footer, the session meter, @ suggestions and the tab icon", async (t) => {
const project = tempProject();
const name = path.basename(project);
const s = await openSession(await suite.browser(), { t, workflow: "plan", project, payload: PLAN_QUESTION });
// Off the dashboard the footer is whole (workspace.js names the label).
assert.equal(await s.page.locator("footer.footer").evaluate((f) => f.classList.contains("is-dash")), false);
assert.equal(await s.page.locator("#btn-send").isVisible(), true);
// meter.js: the pill shows once a frame carries the meter.
await s.page.locator("#meter-pill").waitFor();
assert.ok((await textOf(s.page.locator("#meter-words"))).length, "the meter pill has no words");
// mentions.js: an @ in a text box offers the workspace's folders.
// The @ list is the workspace frame, which can land after the page draws;
// the footer has one label per width tier once it has.
await s.page.waitForFunction(() => (document.getElementById("footer-where").dataset.key || "").includes("\n"));
const box = itemCard(s.page, "q1").locator(".md-host");
const ed = box.locator(".cm-content");
await ed.click();
await ed.pressSequentially("See @");
await s.page.locator("#mention-pop").waitFor();
assert.match(await textOf(s.page.locator("#mention-pop")), new RegExp(name));
// favicon.js: the person's move puts a bar on the tab icon.
await s.page.waitForFunction(() => document.querySelector('link[rel="icon"][type="image/svg+xml"]').href.startsWith("data:image/svg+xml"));
});
// The dashboard, past Planny's wake-up and the first-run Welcome.
async function pastTheIntro(s) {
const skip = s.page.getByRole("button", { name: "Skip the intro" });
await skip.click();
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" });
}
// What a person sees break: a handoff offered where there is nothing to hand off.
test("the stop dialog offers a handoff in a workflow and one plain Stop on the dashboard", async (t) => {
const plan = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "waiting" }, items: PLAN_QUESTION.items } });
await plan.page.click("#btn-stop");
const modal = plan.page.locator("#stop-modal");
await modal.waitFor();
assert.match(await textOf(modal), /Stop with a handoff/);
assert.match(await textOf(modal.locator("#stop-go")), /Just stop and save/);
const dash = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: { agent: { status: "waiting" } } });
await pastTheIntro(dash);
await dash.page.click("#btn-stop");
await dash.page.locator("#stop-modal").waitFor();
assert.equal(await dash.page.locator("#stop-handoff").isVisible(), false, "the dashboard offers a handoff");
assert.match(await textOf(dash.page.locator("#stop-go")), /Stop\s+Ends the console session\./);
assert.doesNotMatch(await textOf(dash.page.locator("#stop-modal")), /Stop with a handoff/);
});
// What the agent would misread: a handoff stop that carries the plain stop's words.
test("Stop with a handoff sends its own reply line beside the stop, and a plain stop sends another", async (t) => {
const handoff = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "waiting" }, items: PLAN_QUESTION.items } });
await handoff.page.click("#btn-stop");
await handoff.page.locator("#stop-handoff").click();
const got = collect(handoff);
assert.deepEqual(got.actions.find((a) => a.i === "__stop"), { i: "__stop", type: "stop", handoff: true });
assert.ok(got.reply.includes(STOP_HANDOFF_REPLY), `the handoff stop's words: ${got.reply}`);
const plain = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "waiting" }, items: PLAN_QUESTION.items } });
await plain.page.click("#btn-stop");
await plain.page.locator("#stop-go").click();
const sent = collect(plain);
assert.equal(sent.actions.find((a) => a.i === "__stop").handoff, undefined);
assert.ok(!sent.reply.includes(STOP_HANDOFF_REPLY), "a plain stop asked for a handoff");
});
// A finish that offers a review, a commit and the dashboard, on a build.
const OFFERS = { headline: "Quick task done", command: "/plan2code-5-git", review: true, commit: true, dashboard: true };
const closeGuide = (s) => s.page.getByRole("region", { name: "Before you close this" });
// What a person sees break: "Safe to close" printed under "Review requested", or the review offer coming back after a reload.
test("Before you close this shows while a review is on offer, goes while it is asked, and the asked offer stays locked after a reload", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "quick-task", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
s.post({ finish: OFFERS });
const main = s.page.locator("#main");
const reviewNow = main.getByRole("button", { name: "Review it now" });
await reviewNow.waitFor();
assert.equal(await closeGuide(s).count(), 1, "a review only on offer must not hide the guide");
assert.match(await textOf(main), /The review is optional\./);
await reviewNow.click();
const got = collect(s);
assert.deepEqual(got.actions.map(({ i, type }) => ({ i, type })), [{ i: "__review", type: "review" }]);
await main.getByRole("button", { name: "Review requested…" }).waitFor();
assert.equal(await closeGuide(s).count(), 0, "the guide shows while a review is starting");
assert.equal(await main.getByRole("button", { name: "No thanks, I am done" }).count(), 0);
// The press is remembered: the buttons do not come back on a reload.
await s.page.reload({ waitUntil: "domcontentloaded" });
await drawn(s.page);
await main.getByRole("button", { name: "Review requested…" }).waitFor();
assert.equal(await main.getByRole("button", { name: "Review it now" }).count(), 0);
assert.equal(await closeGuide(s).count(), 0, "the guide came back on a reload");
});
// What a person sees break: the guide missing while a commit or the dashboard
// is starting (it would say "start a new one" under "Opening Git"), or missing
// once they said they are done or the server is gone.
test("Before you close this goes while a commit or the dashboard is starting, and stays once they are done or the server is gone", async (t) => {
const browser = await suite.browser();
const finishPage = async (opts) => {
const s = await openSession(browser, { t, workflow: "quick-task", ...opts, payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
s.post({ finish: OFFERS });
await s.page.locator("#main").getByRole("heading", { name: "Quick task done" }).waitFor();
assert.equal(await closeGuide(s).count(), 1, "a plain finish shows the guide");
return s;
};
const cases = [
["Commit it now", "__commit", "Opening Git…", 0],
["Back to the dashboard", "__dashboard", "Opening the dashboard…", 0],
["No thanks, I am done", "__done", null, 1],
];
for (const [button, id, asked, guides] of cases) {
const s = await finishPage({});
await s.page.locator("#main").getByRole("button", { name: button }).click();
assert.deepEqual(collect(s).actions.map((a) => a.i), [id]);
if (asked) await s.page.locator("#main").getByRole("button", { name: asked }).waitFor();
assert.equal(await closeGuide(s).count(), guides, `the guide after ${button}`);
}
// A review asked, then the server gone: nothing is starting any more.
const gone = await finishPage({ clock: true });
await gone.page.locator("#main").getByRole("button", { name: "Review it now" }).click();
collect(gone);
assert.equal(await closeGuide(gone).count(), 0);
await stopServer(gone);
for (let i = 0; i < 20 && !(await gone.page.locator("#planny.is-gone").count()); i++) {
await gone.page.clock.fastForward(GONE_AFTER_MS);
await new Promise((r) => setTimeout(r, 250));
}
await closeGuide(gone).waitFor();
});
// What a person sees break: a finished screen with no Before you close this,
// a pause that promises the wrong thing, or the guide's own text going wrong.
test("every finished shape shows Before you close this with its three rows, and a pause names the resume command", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
const main = s.page.locator("#main");
const shapes = [
["A skill next", { command: "/plan2code-4-finalize" }, /A new session starts from clean context/, /Paste the command above in the new session, or start from the dashboard with \/plan2code\./],
["A terminal command next", { command: "git status" }, /A new session starts from clean context/, /Run the command above in your terminal, then start the next step/],
["Nothing left", {}, /A new session starts from clean context/, /In the new session, start from the dashboard with \/plan2code\./],
["Paused here", { command: "/plan2code-3-implement specs/x/overview.md" }, /Your saved place is picked up by the resume command above\./, /Paste the command above/],
];
for (const [headline, rest, fresh, carry] of shapes) {
s.post({ finish: { headline, ...rest } });
await main.getByRole("heading", { name: headline }).waitFor();
const guide = closeGuide(s);
assert.equal(await guide.count(), 1, `${headline}: one guide`);
assert.equal(await guide.locator("li").count(), 3, `${headline}: three rows`);
const text = await textOf(guide);
for (const label of ["Before you close this", "Safe to close", "Start fresh", "Carry on"]) assert.ok(text.includes(label), `${headline}: says "${label}"`);
assert.match(text, fresh, `${headline}: the Start fresh sentence`);
assert.match(text, carry, `${headline}: the Carry on sentence`);
assert.ok(!text.includes("—"), `${headline}: the guide carries an em dash`);
}
// With a stop warning up, a pause's command starts the work again.
// 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");
});
// Under the app the same three rows point at the app's own controls instead:
// New Session for "Start fresh", the top bar's dashboard button for "Carry
// on", and no stray command to copy into a shell that is not there.
test("under the app, Before you close this points at New Session, and never at a \"new conversation\" that does not exist there", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
});
const main = s.page.locator("#main");
s.post({ finish: { headline: "A skill next", command: "/plan2code-4-finalize" } });
await main.getByRole("heading", { name: "A skill next" }).waitFor();
const guide = closeGuide(s);
const text = await textOf(guide);
assert.ok(text.includes("Press New Session at the top of the window to start the agent fresh."), "Start fresh points at New Session");
assert.ok(text.includes("Paste the command above into the terminal panel, or start from the dashboard with /plan2code."), "Carry on names the terminal panel");
assert.ok(!text.includes("new session") && !text.includes("new conversation"), "no classic-mode wording under the app");
// The extra "To start something else..." paragraph a classic finish also
// shows is left out here: the row above already says it once.
assert.equal(await main.getByText("To start something else, run").count(), 0, "no second mention of the same command");
// Nothing left to run: the all-done shape still offers the command (the
// app's terminal panel is a real terminal the agent runs in, so pasting it
// there works), worded for the one panel rather than a new conversation.
s.post({ finish: { headline: "AGENTS.md is updated" } });
await main.getByText(/paste .* into the terminal panel below/).waitFor();
assert.ok(await main.locator("code").filter({ hasText: /^\/plan2code --web$/ }).count(), "the command is still offered");
// The live dashboard button's own note, under it, also points at New
// Session instead of typing `/clear` by hand.
s.post({ finish: { headline: "A skill next, with a live dashboard offer", command: "/plan2code-4-finalize", dashboard: true } });
await main.getByRole("button", { name: "Back to the dashboard" }).waitFor();
assert.ok(await main.getByText("press New Session at the top of the window for a clean start instead").count(), "the dashboard note points at New Session");
assert.equal(await main.getByText("type `/clear`", { exact: false }).count(), 0, "no hand-typed /clear under the app");
});
// Once the console server itself is gone (not just finished), the review and
// dashboard offers' own "new conversation" fallback text must say the same:
// paste into the terminal panel, under the app, and never claim a command is
// needed to reconnect, since the app's own bar already does that on its own.
test("under the app, a gone session's review and dashboard fallbacks name the terminal panel, and reconnect needs no command", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "quick-task",
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
clock: true,
});
s.post({ finish: OFFERS });
await s.page.locator("#main").getByRole("heading", { name: "Quick task done" }).waitFor();
await s.page.locator("#main").getByRole("button", { name: "Review it now" }).click();
collect(s);
await stopServer(s);
for (let i = 0; i < 20 && !(await s.page.locator("#planny.is-gone").count()); i++) {
await s.page.clock.fastForward(GONE_AFTER_MS);
await new Promise((r) => setTimeout(r, 250));
}
const main = s.page.locator("#main");
await main.getByText(/paste this into the terminal panel/i).first().waitFor();
assert.equal(await main.getByText(/new conversation/i).count(), 0, "no classic-mode wording under the app");
await main.getByText("Plan2Code will try to reconnect the console on its own; if it cannot, the app's bar offers Reconnect the console.").waitFor();
assert.equal(await main.getByText(/run this in a new conversation/i).count(), 0, "no stray reconnect command under the app");
});
// What a person sees break: the triangle leaving answers behind, or sending a
// finish-style stop instead of the way home.
test("the top bar's back triangle asks first, then sends __dashboard with the typed answers and the home reply", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
await s.page.click("#btn-home");
const modal = s.page.locator("#home-modal");
await modal.waitFor();
assert.match(await textOf(modal), /Leave this workflow\?/);
assert.match(await textOf(modal.locator("#home-blurb")), /The answer you have ready goes with it\./);
await modal.locator("#home-cancel").click();
await modal.waitFor({ state: "hidden" });
assert.equal(s.wait(1).code === 0, false, "Cancel sent something");
await s.page.click("#btn-home");
await modal.locator("#home-go").click();
const got = collect(s);
assert.deepEqual(got.actions.map(({ i, type }) => ({ i, type })), [{ i: "q1", type: "answer" }, { i: "__dashboard", type: "dashboard" }]);
assert.ok(got.reply.includes("audit-export") && got.reply.endsWith(HOME_REPLY), `the reply carries the answer, then the home line: ${got.reply}`);
await s.page.waitForFunction(() => document.getElementById("btn-home").disabled);
});
// What a person sees break: Commit it now, or Changelog's commit offer, hops
// into Git without the dashboard, and the board opens over the last skill's
// staged answer, its selected question and its open tab.
test("a hop into Git from another skill starts the page clean: nothing staged, nothing selected, the questions view", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "changelog",
payload: {
items: [{ id: "q1", kind: "choice", title: "Which version", body: "The next version number.",
options: [{ k: "A", text: "A patch release" }, { k: "B", text: "A minor release" }] }],
docs: [{ id: "notes", title: "Release notes", blocks: [{ id: "b1", md: "## Draft\n\nTwo fixes." }] }],
agent: { status: "waiting" },
},
});
// The page's own state, from the module app.js loaded (same URL, same instance).
const local = () =>
s.page.evaluate(async () => {
const { page } = await import("/state.js");
return { workflow: page.S.workflow, staged: page.local.staged, selected: page.selected, view: page.view };
});
await itemCard(s.page, "q1").getByText("A minor release").click();
await s.page.locator(".view-tab", { hasText: "Release notes" }).click();
const before = await local();
assert.deepEqual(Object.keys(before.staged), ["q1"], "the answer was never staged");
assert.equal(before.selected, "q1");
assert.notEqual(before.view, "questions", "the Release notes tab never opened");
const draftFile = path.join(s.session, "draft.json");
assert.ok(await until(() => fs.existsSync(draftFile) && fs.readFileSync(draftFile, "utf8").includes('"q1"'), 5000), "the staged answer never reached the draft");
// What Commit it now and Changelog's commit offer run.
cli(["open", "--resume", s.sid, "--no-open", "--workflow", "git"], { cwd: s.project });
await s.page.waitForFunction(async () => (await import("/state.js")).page.S.workflow === "git", null, { timeout: 10000 });
// Long enough for the page's draft push (600 ms after a save) to have run.
await new Promise((r) => setTimeout(r, 1500));
const after = await local();
assert.deepEqual(after.staged, {}, `the page kept the last skill's staged answer: ${JSON.stringify(after.staged)}`);
assert.equal(after.selected, null, `the page kept the last skill's selection: ${after.selected}`);
assert.equal(after.view, "questions", `the page kept the last skill's tab: ${after.view}`);
const stored = await s.page.evaluate((key) => JSON.parse(localStorage.getItem(key) || "{}").staged || {}, `p2c-console:${s.sid}`);
assert.deepEqual(stored, {}, "the browser's copy kept the staged answer");
const draft = fs.existsSync(draftFile) ? JSON.parse(fs.readFileSync(draftFile, "utf8")) : {};
assert.deepEqual(draft.staged || {}, {}, "the server's draft kept the staged answer");
});
// What a person sees break: Back to default in Preferences does nothing.
test("Back to default in Preferences returns the theme to follow the system and clears the chosen look", async (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 s.page.waitForFunction(() => document.documentElement.getAttribute("data-theme") === "dark");
await s.page.click("#looks-reset");
await s.page.waitForFunction(() => !document.documentElement.hasAttribute("data-theme"));
assert.equal(await s.page.locator('input[name="looks-theme"][value="system"]').isChecked(), true, "the system choice is ticked again");
});
// What a person sees break: during a build the waiting pane's "follow along"
// link must open the phase file tab (phase-N.md), which carries the same task
// list plus the rest of the file. An older install's tasks doc arriving
// beside it does not take the link back.
test("the build's waiting link opens the phase file tab and prefers it over an old tasks list", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: {
headline: { stage: "Phase 3: API endpoints", cleared: 5, total: 11 },
docs: [{ id: "phasefile", title: "phase-3.md", blocks: [{ id: "body", state: "settled", md: "# Phase 3: API endpoints\n\n- [x] **Task 3.1:** Register the routes\n- [ ] **Task 3.2:** Add paging" }] }],
agent: { status: "working", activity: "Task 6 of 11: deleting a task" },
},
});
const main = s.page.locator("#main");
const jump = main.locator("button.waiting-jump", { hasText: "phase-3.md" });
await jump.waitFor();
s.post({ docs: [{ id: "phase", title: "Phase 3 tasks", blocks: [{ id: "tasks", state: "settled", md: "- [x] **Task 3.1:** Register the routes" }] }] });
await jump.waitFor();
await jump.click();
await s.page.locator(".view-tab[aria-current='true']", { hasText: "phase-3.md" }).waitFor();
await main.getByRole("heading", { name: "Phase 3: API endpoints" }).waitFor();
});
// What a person sees break: a build still on the old contract keeps its link;
// the posted tasks list opens its own tab.
test("a build still on the old contract keeps its waiting link on the tasks list", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: {
headline: { stage: "Phase 3: API endpoints", cleared: 5, total: 11 },
docs: [{ id: "phase", title: "Phase 3 tasks", blocks: [{ id: "tasks", state: "settled", md: "- [x] **Task 3.1:** Register the routes" }] }],
agent: { status: "working", activity: "Task 6 of 11: deleting a task" },
},
});
const jump = s.page.locator("#main").locator("button.waiting-jump", { hasText: "Phase 3 tasks" });
await jump.waitFor();
await jump.click();
await s.page.locator(".view-tab[aria-current='true']", { hasText: "Phase 3 tasks" }).waitFor();
});
// Planny's own spoken line said "close this tab": under the app there is no
// tab, only the one window.
test("under the app, Planny's finished line says to close the window, not the tab", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 1" } },
env: { PLAN2CODE_IN_APP: "1" },
});
s.post({ finish: { headline: "All done", dashboard: true } });
await s.page.locator("#main").getByRole("heading", { name: "All done" }).waitFor();
const line = await lineSays(s, /close this window/);
assert.doesNotMatch(line, /close this tab/, "no classic-mode wording under the app");
});