mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
720 lines
40 KiB
JavaScript
720 lines
40 KiB
JavaScript
// Page tests for the dashboard: a spec in the picker, a card picked and
|
|
// started, the launch send the agent collects, and its `resume` turning the
|
|
// page into the launched skill's starting screen. Run with:
|
|
// node --test scripts/test-web-console-page-dashboard.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 fs from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { pageSuite, openSession, tempProject, textOf, styleOf } from "./page-test-helpers.mjs";
|
|
import { cli, until, CONSOLE_CLI, HOME, JPEG } from "./web-console-test-helpers.mjs";
|
|
import { addImage, createTab, deleteTab, markTabSent, saveNote } from "../src/web-console/notepads.mjs";
|
|
|
|
const suite = pageSuite(test);
|
|
|
|
// A project that is set up (AGENTS.md) with one spec holding a Plan draft.
|
|
// A PLAN-DRAFT whose Status line says only "Draft" (no "Resume at Phase N")
|
|
// scans as `planned`, which the picker labels "Ready to document". Plan is
|
|
// still lit for it (only exploring, fixed and documented-or-later gray Plan
|
|
// out); Document is the state's own next step.
|
|
const DRAFT_PROJECT = {
|
|
"AGENTS.md": "# AGENTS.md\n\nA small demo project.\n",
|
|
"specs/demo/PLAN-DRAFT-20261017.md": "# Plan draft: demo\n\n**Status:** Draft\n\nA lunch vote for the team.\n",
|
|
};
|
|
|
|
// What a real agent posts on the dashboard (plan2code.md, "The menu"): its
|
|
// judgment on top of the scan, then it waits.
|
|
const MENU = {
|
|
menu: {
|
|
note: "One spec on disk, with a plan drafted.",
|
|
recommend: "plan2code-2-document",
|
|
details: { "plan2code-2-document": "Plan drafted" },
|
|
},
|
|
agent: { status: "waiting" },
|
|
};
|
|
|
|
// 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;
|
|
}
|
|
|
|
test("a Plan launch from the dashboard carries the picked spec, and its resume turns the page to Starting Plan", async (t) => {
|
|
const project = tempProject(DRAFT_PROJECT);
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project });
|
|
const main = await toTheMenu(s);
|
|
|
|
// The picker shows the spec with its state, and opens on it.
|
|
const chip = main.getByRole("button").filter({ hasText: /^demo/ });
|
|
await chip.waitFor();
|
|
// The state is drawn in capitals, so the match ignores case.
|
|
const chipText = await textOf(chip);
|
|
assert.match(chipText, /Ready to document/i, "the spec chip names its state");
|
|
assert.match(chipText, /plan drafted/, "the spec chip says how far it got");
|
|
assert.equal(await chip.getAttribute("aria-current"), "true", "the picker opens on the only spec");
|
|
|
|
// The Plan card is lit for this spec; picking it asks to confirm.
|
|
const planCard = main.getByRole("button").filter({ has: s.page.locator("code", { hasText: /^\/plan2code-1-plan$/ }) });
|
|
assert.equal(await planCard.isEnabled(), true, "the Plan card is grayed for a drafted plan");
|
|
await planCard.click();
|
|
await main.getByRole("button", { name: "Start Plan" }).click();
|
|
|
|
const got = collect(s);
|
|
assert.equal(got.type, "submit");
|
|
const launch = got.actions.find((a) => a.i === "__launch");
|
|
assert.ok(launch, `the send carries a launch: ${JSON.stringify(got.actions)}`);
|
|
assert.deepEqual(
|
|
{ i: launch.i, skill: launch.skill, workflow: launch.workflow, spec: launch.spec },
|
|
{ i: "__launch", skill: "plan2code-1-plan", workflow: "plan", spec: "specs/demo" }
|
|
);
|
|
|
|
// `resume` is the one command to run, naming the session, workflow and spec.
|
|
const head = `node "${CONSOLE_CLI}" `;
|
|
assert.ok(got.resume.startsWith(head), `resume runs this console: ${got.resume}`);
|
|
const args = got.resume.slice(head.length).split(" ");
|
|
assert.deepEqual(args, ["open", "--resume", s.sid, "--no-open", "--workflow", "plan", "--spec", "specs/demo"]);
|
|
|
|
// `skillFile` is offered only when the skill's SKILL.md sits beside the
|
|
// console's own folder, as in an install. Run from this repo's source tree
|
|
// (src/web-console/), that is a plan2code-1-plan/ folder next to the repo,
|
|
// which does not exist, so the send leaves it out (console-launches.md:
|
|
// "absent outside an install").
|
|
assert.equal("skillFile" in got, false, `a source-tree launch names no skillFile: ${got.skillFile}`);
|
|
|
|
// The agent runs `resume` first: the page leaves the menu for Plan's
|
|
// starting screen while the skill is read.
|
|
const r = cli(args, { cwd: s.project });
|
|
assert.equal(r.status, 0, `resume failed: ${r.stderr}`);
|
|
await main.getByRole("heading", { name: "Starting Plan" }).waitFor();
|
|
});
|
|
|
|
// A project holding one fixed bug (a diagnosis Quick Task marked Fixed) and
|
|
// one drafted plan. The fixed bug is touched last, so it is the newest spec on
|
|
// disk: the picker must still open on the plan, since a finished spec is never
|
|
// the default.
|
|
function fixedProject() {
|
|
const project = tempProject({
|
|
...DRAFT_PROJECT,
|
|
"specs/old-bug/DIAGNOSIS-20261017.md": "# Diagnosis: old bug\n\n**Status:** Fixed\n\nThe save button lost its handler.\n",
|
|
});
|
|
const later = new Date(Date.now() + 60_000);
|
|
fs.utimesSync(path.join(project, "specs/old-bug/DIAGNOSIS-20261017.md"), later, later);
|
|
return project;
|
|
}
|
|
|
|
// Past Planny's wake-up and, on this console home's first run, the Welcome,
|
|
// to the menu.
|
|
async function toTheMenu(s) {
|
|
const skip = s.page.getByRole("button", { name: "Skip the intro" });
|
|
await skip.click();
|
|
await skip.waitFor({ state: "hidden" });
|
|
const main = s.page.locator("#main");
|
|
const heading = main.getByRole("heading", { name: "What are we doing today?" });
|
|
await heading.waitFor();
|
|
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
|
|
if (await welcomeDone.isVisible()) {
|
|
await welcomeDone.click();
|
|
await welcomeDone.waitFor({ state: "hidden" });
|
|
}
|
|
return main;
|
|
}
|
|
|
|
// Sets the picker's "Hide unavailable workflows" switch. Looks are kept per
|
|
// console home, so each test sets the one it needs rather than trusting the
|
|
// default.
|
|
async function hideUnavailable(main, on) {
|
|
const box = main.getByRole("switch", { name: "Hide unavailable workflows" });
|
|
if ((await box.isChecked()) !== on) await main.getByText("Hide unavailable workflows").click();
|
|
assert.equal(await box.isChecked(), on);
|
|
}
|
|
|
|
const chipFor = (main, name) => main.getByRole("button").filter({ hasText: new RegExp(`^${name}`) });
|
|
|
|
test("a fixed bug is hidden while unavailable workflows are, dimmed when they show, and never the picker's default", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: fixedProject() });
|
|
const main = await toTheMenu(s);
|
|
|
|
// Hidden while the switch is on.
|
|
await hideUnavailable(main, true);
|
|
const demo = chipFor(main, "demo");
|
|
await demo.waitFor();
|
|
assert.equal(await demo.getAttribute("aria-current"), "true", "the picker opens on the plan, not the newer fixed bug");
|
|
assert.equal(await chipFor(main, "old-bug").count(), 0, "the fixed bug's chip is hidden while unavailable workflows are");
|
|
|
|
// Switched off: the chip shows, labeled and dimmed, and still not picked.
|
|
await hideUnavailable(main, false);
|
|
const bug = chipFor(main, "old-bug");
|
|
await bug.waitFor();
|
|
assert.match(await textOf(bug), /Bug fixed/i, "the chip names its state");
|
|
assert.doesNotMatch(await textOf(bug), /bug fixed\s+bug fixed/i, "the scan's detail does not repeat the label");
|
|
assert.equal(await bug.getAttribute("aria-current"), "false", "the fixed bug is not picked");
|
|
const opacity = Number(await styleOf(bug, "opacity"));
|
|
assert.ok(opacity < 1, `the fixed bug's chip is dimmed (opacity ${opacity})`);
|
|
assert.equal(await demo.getAttribute("aria-current"), "true", "the plan stays picked");
|
|
});
|
|
|
|
test("a fixed bug's Delete asks once with no name to type, while any other spec asks for its name", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: fixedProject() });
|
|
const main = await toTheMenu(s);
|
|
await hideUnavailable(main, false);
|
|
await chipFor(main, "old-bug").waitFor();
|
|
|
|
const dialog = s.page.locator("#delete-modal");
|
|
const go = s.page.locator("#delete-go");
|
|
const nameStep = s.page.locator("#delete-confirm");
|
|
|
|
// Any other spec: the first press only reveals the name step.
|
|
await main.getByRole("button", { name: "Delete the spec demo" }).click({ force: true });
|
|
await dialog.waitFor();
|
|
assert.equal(await textOf(go), "Delete this spec…");
|
|
await go.click();
|
|
await nameStep.waitFor();
|
|
assert.equal(await go.isDisabled(), true, "the final button waits for the name");
|
|
await s.page.keyboard.press("Escape");
|
|
await dialog.waitFor({ state: "hidden" });
|
|
|
|
// The fixed bug: a visible Delete, its own warning, and one press sends it.
|
|
const del = main.getByRole("button", { name: "Delete the spec old-bug" });
|
|
assert.equal(await textOf(del), "Delete", "a fixed bug's Delete is a labeled button");
|
|
await del.click({ force: true });
|
|
await dialog.waitFor();
|
|
assert.match(await textOf(s.page.locator("#delete-warn")), /The bug is fixed, so this only clears the write-up/);
|
|
assert.equal(await textOf(go), "Delete it");
|
|
assert.equal(await nameStep.isHidden(), true, "no name step for a fixed bug");
|
|
await go.click();
|
|
|
|
const got = collect(s);
|
|
assert.equal(await nameStep.isHidden(), true, "the name step never showed");
|
|
const action = got.actions.find((a) => a.i === "__delete");
|
|
assert.deepEqual({ type: action?.type, spec: action?.spec }, { type: "delete", spec: "specs/old-bug" });
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// The picker's switching, the first-open wake-up, handoffs, the update banner,
|
|
// the workspace scope, and the pose that carries a launch into the work.
|
|
|
|
const lightOf = (main, command) => main.getByRole("button").filter({ has: main.page().locator("code", { hasText: new RegExp(`^${command}$`) }) });
|
|
const pickedChip = (main, name) => main.locator('button[aria-current="true"]', { hasText: new RegExp(`^${name}`) });
|
|
|
|
// What a person would see break: picking another target leaves the launch
|
|
// aimed at the old spec, or the cards lit for it.
|
|
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");
|
|
// The top bar names the picked spec beside the meter, and drops it from scratch.
|
|
const specTag = main.page().locator("#spec-tag");
|
|
assert.ok(await until(async () => (await specTag.isVisible()) && (await specTag.textContent()) === "demo"), "the top bar names the spec demo");
|
|
|
|
// From scratch there is no draft to document: the card grays.
|
|
await chipFor(main, "Start from scratch").click();
|
|
await pickedChip(main, "Start from scratch").waitFor();
|
|
assert.equal(await document.isDisabled(), true, "Document is grayed with no spec picked");
|
|
assert.ok(await until(() => specTag.isHidden()), "the top bar's spec name goes from scratch");
|
|
assert.equal(await chipFor(main, "demo").getAttribute("aria-current"), "false");
|
|
|
|
// Back on the spec it is lit again; then from scratch once more to launch.
|
|
await chipFor(main, "demo").click();
|
|
await pickedChip(main, "demo").waitFor();
|
|
assert.equal(await document.isEnabled(), true, "Document is lit again for the spec");
|
|
await chipFor(main, "Start from scratch").click();
|
|
await pickedChip(main, "Start from scratch").waitFor();
|
|
await lightOf(main, "/plan2code-1-plan").click();
|
|
await main.getByRole("button", { name: "Start Plan" }).click();
|
|
const launch = collect(s).actions.find((a) => a.i === "__launch");
|
|
assert.equal(launch.skill, "plan2code-1-plan");
|
|
assert.ok(!launch.spec, `a launch from scratch names no spec: ${JSON.stringify(launch)}`);
|
|
});
|
|
|
|
// What a person would see break: the Dead Code card missing from Useful any
|
|
// time, drawn without its skull, grayed for want of a spec it never takes, or
|
|
// launching with the picked spec riding along.
|
|
test("the Dead Code card sits in Useful any time with its skull, is lit with or without a spec, and launches with 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);
|
|
await hideUnavailable(main, false);
|
|
const card = lightOf(main, "/plan2code-dead-code");
|
|
await card.waitFor();
|
|
|
|
const group = main.locator("section.dash-group").filter({ has: s.page.locator("h3", { hasText: /^Useful any time$/ }) });
|
|
assert.equal(await group.locator("code", { hasText: /^\/plan2code-dead-code$/ }).count(), 1, "the card is in the Useful any time group");
|
|
assert.match(await textOf(card), /Utility/i, "it wears the Utility chip (drawn in capitals)");
|
|
assert.match(await textOf(card), /Clear out dead code/, "it has its title");
|
|
assert.equal(await card.locator("use").getAttribute("href"), "#ci-dead-code", "its icon is the skull");
|
|
assert.equal(await s.page.locator("symbol#ci-dead-code").count(), 1, "the skull symbol is drawn in the icon sheet");
|
|
|
|
// Lit with no spec picked, and with one.
|
|
await chipFor(main, "Start from scratch").click();
|
|
await pickedChip(main, "Start from scratch").waitFor();
|
|
assert.equal(await card.isEnabled(), true, "lit with no spec picked");
|
|
await chipFor(main, "demo").click();
|
|
await pickedChip(main, "demo").waitFor();
|
|
assert.equal(await card.isEnabled(), true, "lit with a spec picked");
|
|
|
|
// A launch with the spec still picked names no spec: Dead Code takes none.
|
|
await card.click();
|
|
await main.getByRole("button", { name: "Start Clear out dead code" }).click();
|
|
const launch = collect(s).actions.find((a) => a.i === "__launch");
|
|
assert.ok(launch, "the send carries a launch");
|
|
assert.deepEqual({ skill: launch.skill, workflow: launch.workflow }, { skill: "plan2code-dead-code", workflow: "dead-code" });
|
|
assert.ok(!launch.spec, `a Dead Code launch names no spec: ${JSON.stringify(launch)}`);
|
|
});
|
|
|
|
// What a person would see break: a spec not documented yet offers nothing to
|
|
// read, or its Map and Plan draft tabs stay up for a spec that has an
|
|
// overview (or for no spec at all).
|
|
test("a spec not documented yet shows its Map and Plan draft as tabs, and a documented one shows only Overview", async (t) => {
|
|
const project = tempProject({
|
|
...DRAFT_PROJECT,
|
|
"specs/demo/pathfinder/map.md": "# Map: demo\n\n**Status:** Cleared\n\nWho votes for lunch.\n",
|
|
"specs/done/overview.md": "# Overview: done\n\nAll written up.\n",
|
|
"specs/done/phase-1.md": "- [ ] **Task 1.1:** x\n",
|
|
});
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project });
|
|
const main = await toTheMenu(s);
|
|
const tab = (name) => s.page.locator("#views .view-tab", { hasText: new RegExp(`^${name}$`) });
|
|
|
|
await chipFor(main, "demo").click();
|
|
await pickedChip(main, "demo").waitFor();
|
|
await tab("Map").waitFor();
|
|
await tab("Plan draft").waitFor();
|
|
assert.equal(await tab("Overview").count(), 0, "no overview.md, no Overview tab");
|
|
|
|
await tab("Plan draft").click();
|
|
await main.getByRole("heading", { name: "Plan draft", exact: true }).waitFor();
|
|
assert.match(await textOf(main), /specs\/demo\/PLAN-DRAFT-20261017\.md · read-only/);
|
|
assert.match(await textOf(main), /A lunch vote for the team\./);
|
|
await tab("Map").click();
|
|
await main.getByRole("heading", { name: "Map", exact: true }).waitFor();
|
|
assert.match(await textOf(main), /specs\/demo\/pathfinder\/map\.md · read-only/);
|
|
assert.match(await textOf(main), /Who votes for lunch\./);
|
|
|
|
// The documented spec trades both for its Overview, and the open Map tab,
|
|
// gone with them, sends the person home.
|
|
await tab("Dashboard").click();
|
|
await chipFor(main, "done").click();
|
|
await pickedChip(main, "done").waitFor();
|
|
await tab("Overview").waitFor();
|
|
assert.ok(
|
|
await until(async () => (await tab("Map").count()) === 0 && (await tab("Plan draft").count()) === 0),
|
|
"the Map and Plan draft tabs go"
|
|
);
|
|
|
|
await chipFor(main, "Start from scratch").click();
|
|
await pickedChip(main, "Start from scratch").waitFor();
|
|
assert.ok(await until(async () => (await tab("Overview").count()) === 0), "no spec, no spec tabs");
|
|
});
|
|
|
|
// What a person would see break: the intro cannot be skipped, or it replays
|
|
// on every reload of the same tab.
|
|
test("Skip the intro ends the first-open wake-up at once, and a reload of the tab does not play it again", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
|
const skip = s.page.getByRole("button", { name: "Skip the intro" });
|
|
await skip.waitFor();
|
|
await toTheMenu(s);
|
|
assert.equal(await skip.isVisible(), false);
|
|
|
|
await s.page.reload({ waitUntil: "domcontentloaded" });
|
|
await s.page.locator("#main").getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
|
assert.equal(await skip.isVisible(), false, "the intro does not play again in this tab");
|
|
});
|
|
|
|
// A project with no spec, only a handoff written for it (the Handoff skill's
|
|
// file pair under the test's own handoffs folder), removed with the test.
|
|
const HANDOFF_DOC = "# Handoff: Lunch vote\n\n## Next task\n\nWire the vote button to the tally.\n\n## Notes\n\nA long body line.\n";
|
|
function handoffProject(t) {
|
|
const project = tempProject({ "AGENTS.md": "# AGENTS.md\n\nA small demo project.\n" });
|
|
const made = cli(["handoff", "new", "--workflow", "quick-task", "--skill", "plan2code-quick-task", "--title", "Lunch vote"], { cwd: project }).json;
|
|
fs.writeFileSync(made.path, HANDOFF_DOC);
|
|
t.after(() => {
|
|
fs.rmSync(made.path, { force: true });
|
|
fs.rmSync(made.path.replace(/\.md$/, ".json"), { force: true });
|
|
});
|
|
return { project, made };
|
|
}
|
|
|
|
async function openHandoffMenu(t, env) {
|
|
const { project, made } = handoffProject(t);
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project, env });
|
|
const main = await toTheMenu(s);
|
|
const chip = chipFor(main, "Lunch vote");
|
|
await chip.waitFor();
|
|
return { s, main, chip, made };
|
|
}
|
|
|
|
// What a person would see break: a handoff is not offered when it is all the
|
|
// project has, or picking it still shows the skill cards beside the preview.
|
|
test("a handoff shows as a dashed Handoff chip even with no spec, and picking it swaps the cards for a preview of four buttons", async (t) => {
|
|
const { main, chip } = await openHandoffMenu(t);
|
|
assert.match(await textOf(chip), /Handoff/i, "the chip is labeled Handoff");
|
|
assert.equal(await chip.getAttribute("aria-current"), "false", "a handoff is offered, not picked for you");
|
|
assert.equal(await styleOf(chip, "borderTopStyle"), "dashed", "the chip's border is dashed");
|
|
assert.ok(await lightOf(main, "/plan2code-1-plan").isVisible(), "the cards show before a handoff is picked");
|
|
|
|
await chip.click();
|
|
assert.equal(await chip.getAttribute("aria-current"), "true");
|
|
await main.getByRole("heading", { name: "Lunch vote" }).waitFor();
|
|
assert.match(await textOf(main), /Wire the vote button to the tally\./, "the preview quotes the Next task");
|
|
for (const name of ["Pick it up here", "Read it all", "Copy for a new conversation", "Delete"]) {
|
|
assert.equal(await main.getByRole("button", { name, exact: true }).count(), 1, `the preview has ${name}`);
|
|
}
|
|
assert.equal(await lightOf(main, "/plan2code-1-plan").count(), 0, "the skill cards give way to the preview");
|
|
assert.equal(await main.getByRole("switch", { name: "Hide unavailable workflows" }).count(), 0, "and so does their toggle");
|
|
});
|
|
|
|
// What a person would see break: Pick it up here sends nothing, or sends more
|
|
// than the handoff's id.
|
|
test("Pick it up here sends a pickup naming the handoff, and the page turns to its launch screen", async (t) => {
|
|
const { s, main, chip, made } = await openHandoffMenu(t);
|
|
await chip.click();
|
|
await main.getByRole("button", { name: "Pick it up here" }).click();
|
|
const got = collect(s);
|
|
const pick = got.actions.find((a) => a.i === "__pickup");
|
|
assert.deepEqual({ type: pick?.type, handoff: pick?.handoff }, { type: "pickup", handoff: made.id });
|
|
assert.match(got.resume, /--workflow quick-task$/, "the CLI read the handoff's own workflow");
|
|
await main.getByRole("heading", { name: "Waking up Lunch vote" }).waitFor();
|
|
});
|
|
|
|
// What a person would see break: Read it all opens nothing, or Copy puts the
|
|
// wrong words on the clipboard.
|
|
test("Read it all opens the handoff's text, and Copy puts a prompt naming its file on the clipboard", async (t) => {
|
|
const { s, main, chip, made } = await openHandoffMenu(t);
|
|
await s.context.grantPermissions(["clipboard-read", "clipboard-write"], { origin: new URL(s.url).origin });
|
|
await chip.click();
|
|
|
|
await main.getByRole("button", { name: "Read it all" }).click();
|
|
const reader = s.page.locator("#handoff-modal");
|
|
await reader.getByText("A long body line.").waitFor();
|
|
await s.page.keyboard.press("Escape");
|
|
await reader.waitFor({ state: "hidden" });
|
|
|
|
const copy = main.getByRole("button", { name: "Copy for a new conversation" });
|
|
await copy.click();
|
|
await main.getByRole("button", { name: "Copied" }).waitFor();
|
|
const text = await s.page.evaluate(() => navigator.clipboard.readText());
|
|
assert.match(text, /^Read the handoff at .*\.md and carry on with its Next task\.$/);
|
|
assert.ok(text.includes(made.id), `the prompt names the handoff's file: ${text}`);
|
|
});
|
|
|
|
// Under the app, "a new conversation" is this console's own wording for what
|
|
// New Session does, so the handoff's copy button says "another session"
|
|
// instead, still naming the same clipboard prompt.
|
|
test("under the app, a handoff's copy button says Copy for another session, and still works", async (t) => {
|
|
const { s, main, chip } = await openHandoffMenu(t, { PLAN2CODE_IN_APP: "1" });
|
|
await s.context.grantPermissions(["clipboard-read", "clipboard-write"], { origin: new URL(s.url).origin });
|
|
await chip.click();
|
|
assert.equal(await main.getByRole("button", { name: "Copy for a new conversation" }).count(), 0, "no classic-mode wording under the app");
|
|
const copy = main.getByRole("button", { name: "Copy for another session" });
|
|
await copy.click();
|
|
await main.getByRole("button", { name: "Copied" }).waitFor();
|
|
await copy.waitFor();
|
|
});
|
|
|
|
// What a person would see break: Delete asks for a name, or sends a spec
|
|
// delete instead of the handoff's.
|
|
test("a handoff's Delete asks once in its own dialog and sends a delete naming the handoff", async (t) => {
|
|
const { s, main, chip, made } = await openHandoffMenu(t);
|
|
await chip.click();
|
|
await main.getByRole("button", { name: "Delete", exact: true }).click();
|
|
const dialog = s.page.locator("#delete-modal");
|
|
await dialog.waitFor();
|
|
assert.equal(await textOf(s.page.locator("#delete-title")), "Delete this handoff?");
|
|
assert.equal(await s.page.locator("#delete-warn-handoff").isVisible(), true, "the warning says where handoffs live");
|
|
assert.equal(await s.page.locator("#delete-confirm").isHidden(), true, "no name to type");
|
|
await s.page.locator("#delete-go").click();
|
|
const action = collect(s).actions.find((a) => a.i === "__delete");
|
|
assert.deepEqual({ type: action?.type, handoff: action?.handoff, spec: action?.spec }, { type: "delete", handoff: made.id, spec: undefined });
|
|
});
|
|
|
|
// A newer release on record, so a console that boots now has an update to
|
|
// announce (the check reads this file for an hour instead of asking the
|
|
// network). The file is put back as the suite had it.
|
|
function aNewerReleaseExists(t) {
|
|
const file = path.join(HOME, "update-check.json");
|
|
const before = fs.readFileSync(file, "utf8");
|
|
fs.writeFileSync(file, JSON.stringify({ checkedAt: Date.now(), latest: "99.0.0" }));
|
|
t.after(() => fs.writeFileSync(file, before));
|
|
}
|
|
|
|
// What a person would see break: the banner shows on a build's page, or the
|
|
// dashboard never offers it.
|
|
test("the update banner shows on the dashboard only, and its dismiss hides it", async (t) => {
|
|
aNewerReleaseExists(t);
|
|
const browser = await suite.browser();
|
|
const build = await openSession(browser, { t, workflow: "implement", payload: { agent: { status: "working", activity: "Task 1 of 1" } } });
|
|
const dash = await openSession(browser, { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
|
const main = await toTheMenu(dash);
|
|
const banner = main.getByRole("button", { name: /UPDATE AVAILABLE · v99\.0\.0/ });
|
|
await banner.waitFor();
|
|
// The build's server booted under the same record; a later frame has landed
|
|
// on its page by the time this text shows, and it still has no banner.
|
|
build.post({ agent: { status: "working", activity: "Task 1 of 1, one more look" } });
|
|
await build.page.getByText("Task 1 of 1, one more look").first().waitFor();
|
|
assert.equal(await build.page.getByText("UPDATE AVAILABLE").count(), 0, "a build's page has no banner");
|
|
|
|
await main.getByRole("button", { name: "Dismiss until next time" }).click();
|
|
await banner.waitFor({ state: "hidden" });
|
|
});
|
|
|
|
// Under the desktop app (PLAN2CODE_IN_APP=1) the app's own top bar already
|
|
// nags about a skills/app mismatch and updates in one click, so this banner
|
|
// (a copy-pasted shell command) must never show there, newer release or not.
|
|
test("under the app, the update banner never shows", async (t) => {
|
|
aNewerReleaseExists(t);
|
|
const dash = await openSession(await suite.browser(), {
|
|
t,
|
|
workflow: "dashboard",
|
|
payload: MENU,
|
|
project: tempProject(DRAFT_PROJECT),
|
|
env: { PLAN2CODE_IN_APP: "1" },
|
|
});
|
|
const main = await toTheMenu(dash);
|
|
await main.getByText("One spec on disk, with a plan drafted.").waitFor();
|
|
assert.equal(await main.getByText("UPDATE AVAILABLE").count(), 0, "no banner under the app");
|
|
});
|
|
|
|
// Same reasoning for the dashboard's own red-meter banner: under the app it
|
|
// must point at New Session, never at starting a new console session.
|
|
test("under the app, the dashboard's red-meter banner points at New Session", async (t) => {
|
|
const dash = await openSession(await suite.browser(), {
|
|
t,
|
|
workflow: "dashboard",
|
|
payload: MENU,
|
|
project: tempProject(DRAFT_PROJECT),
|
|
env: { PLAN2CODE_IN_APP: "1" },
|
|
});
|
|
const main = await toTheMenu(dash);
|
|
dash.post({ run: { event: "implement-phase", id: "phase-1", tasks: 30 } });
|
|
await main.getByText("Press New Session at the top of the window to start the agent fresh.").waitFor();
|
|
assert.equal(await main.getByText("Starting a new console session").count(), 0, "no classic-mode wording under the app");
|
|
});
|
|
|
|
// What a person would see break: two dashboard tabs of one session, on
|
|
// different picks, keep taking the workspace's folders back from each other.
|
|
test("two dashboard tabs on different picks leave the workspace scope with the last pick and ask for it no more", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
|
const mainA = await toTheMenu(s);
|
|
const second = await s.context.newPage();
|
|
second.on("pageerror", (e) => s.errors.push(e.message));
|
|
await second.goto(s.url, { waitUntil: "domcontentloaded" });
|
|
const mainB = await toTheMenu({ page: second });
|
|
const asks = { a: 0, b: 0 };
|
|
s.page.on("request", (r) => r.method() === "POST" && r.url().endsWith("/workspace/scope") && asks.a++);
|
|
second.on("request", (r) => r.method() === "POST" && r.url().endsWith("/workspace/scope") && asks.b++);
|
|
const scopeOf = () => s.page.evaluate(async () => (await (await fetch("/workspace?check=1", { cache: "no-store" })).json()).scope || "");
|
|
assert.equal(await scopeOf(), "specs/demo", "both tabs opened on the spec");
|
|
|
|
// The second tab moves to Start from scratch: its folders become the project's own.
|
|
await chipFor(mainB, "Start from scratch").click();
|
|
await pickedChip(mainB, "Start from scratch").waitFor();
|
|
assert.ok(await until(async () => (await scopeOf()) === ""), "the scope followed the second tab");
|
|
|
|
// The first tab keeps its pick and takes a frame from the agent after the change.
|
|
s.post({ menu: { ...MENU.menu, note: "A second look from the agent." } });
|
|
await mainA.getByText("A second look from the agent.").waitFor();
|
|
assert.equal(await pickedChip(mainA, "demo").count(), 1, "the first tab still has its own pick");
|
|
assert.equal(asks.a, 0, "the tab that did not move never asked for its own scope back");
|
|
assert.equal(asks.b, 1, "the tab that moved asked once");
|
|
assert.equal(await scopeOf(), "", "the scope stays with the last pick");
|
|
});
|
|
|
|
// What a person would see break: Planny is rebuilt on every screen change, so
|
|
// his animation restarts as the launch becomes the work.
|
|
test("the pose pane a launch shows is the very element the starting and waiting screens keep, and the waiting pane shows the agent's activity", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
|
const main = await toTheMenu(s);
|
|
await lightOf(main, "/plan2code-1-plan").click();
|
|
await main.getByRole("button", { name: "Start Plan" }).click();
|
|
|
|
// The launching screen, with its pose; mark that exact element.
|
|
const pane = s.page.locator("#main > [data-pose]");
|
|
await pane.waitFor();
|
|
const pose = await pane.getAttribute("data-pose");
|
|
await pane.evaluate((el) => (el.__sameElement = true));
|
|
|
|
// The agent resumes the session as Plan: the starting screen reuses the pane.
|
|
const got = collect(s);
|
|
const args = got.resume.slice(`node "${CONSOLE_CLI}" `.length).split(" ");
|
|
assert.equal(cli(args, { cwd: s.project }).status, 0);
|
|
await main.getByRole("heading", { name: "Starting Plan" }).waitFor();
|
|
assert.equal(await pane.getAttribute("data-pose"), pose, "the same pose carries into the starting screen");
|
|
assert.equal(await pane.evaluate((el) => el.__sameElement === true && el.isConnected), true, "the pane was kept, not rebuilt");
|
|
|
|
// The agent starts work and says what it is doing: the waiting screen shows it,
|
|
// still in the same pane.
|
|
s.post({ agent: { status: "working", activity: "Reading the plan draft" } });
|
|
await main.getByText("Reading the plan draft").waitFor();
|
|
assert.equal(await pane.evaluate((el) => el.__sameElement === true && el.isConnected), true, "the pane survives into the waiting screen");
|
|
s.post({ agent: { status: "working", activity: "Writing the first questions" } });
|
|
await main.getByText("Writing the first questions").waitFor();
|
|
assert.equal(await pane.evaluate((el) => el.__sameElement === true && el.isConnected), true, "and survives each state frame after it");
|
|
});
|
|
|
|
// What a person would see break: a quick-task build points at a Plan tab that
|
|
// does not open, or another skill's page gains a pointer it has no list for.
|
|
test("a quick-task build's waiting pane points at its Plan tab, and a plan session with the same tab gets no pointer", async (t) => {
|
|
const plan = { id: "plan", title: "Plan", blocks: [{ id: "steps", state: "settled", md: "## Steps\n\n- [ ] **1.** Wire the vote button" }] };
|
|
const working = { agent: { status: "working", activity: "Step 1 of 1" } };
|
|
const s = await openSession(await suite.browser(), { t, workflow: "quick-task", payload: { docs: [plan], ...working } });
|
|
const pane = s.page.locator("#main > .waiting-pane");
|
|
await pane.waitFor();
|
|
const jump = pane.getByRole("button", { name: "Plan", exact: true });
|
|
await jump.waitFor();
|
|
await jump.click();
|
|
await s.page.locator("#main").getByText("Wire the vote button").waitFor();
|
|
|
|
const other = await openSession(await suite.browser(), { t, workflow: "plan", payload: { docs: [plan], ...working } });
|
|
const otherPane = other.page.locator("#main > .waiting-pane");
|
|
await otherPane.waitFor();
|
|
assert.equal(await otherPane.getByRole("button", { name: "Plan", exact: true }).count(), 0, "a plan session has no live task list to point at");
|
|
});
|
|
|
|
// A project with a drafted plan (demo), a documented spec (ready) and one
|
|
// paused mid-build with a Plan change brief waiting (paused).
|
|
const NOTE_PROJECT = {
|
|
...DRAFT_PROJECT,
|
|
"specs/ready/overview.md": "# Overview\n\n## Phase Checklist\n\n- [ ] Phase 1: One\n",
|
|
"specs/ready/phase-1.md": "# Phase 1\n\n- [ ] **Task 1.1:** One\n",
|
|
"specs/paused/overview.md": "# Overview\n\n## Phase Checklist\n\n- [/] Phase 1: One\n",
|
|
"specs/paused/phase-1.md":
|
|
"# Phase 1\n\n- [x] **Task 1.1:** One\n- [ ] **Task 1.2:** Two\n\n## Notes\n\n### Paused 2026-10-27\n**Plan change:** add a phase first\n",
|
|
};
|
|
|
|
const noteSwitch = (main) => main.getByRole("checkbox", { name: "Start with a note from your Notebook" });
|
|
|
|
// Picks `chip` in the picker, opens `command`'s card and says whether its
|
|
// confirm pane offers the switch; Back returns to the menu.
|
|
async function offersNote(main, chip, command) {
|
|
await chipFor(main, chip).click();
|
|
await pickedChip(main, chip).waitFor();
|
|
const card = lightOf(main, command);
|
|
if (!(await card.isVisible()) || (await card.isDisabled())) return null;
|
|
await card.click();
|
|
await main.getByRole("button", { name: "Back" }).waitFor();
|
|
const shows = (await noteSwitch(main).count()) === 1;
|
|
await main.getByRole("button", { name: "Back" }).click();
|
|
await main.getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
|
return shows;
|
|
}
|
|
|
|
test("the Notebook switch shows on Start fresh for Pathfinder, Plan and Quick Task, and on Revise plan only with no brief waiting", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(NOTE_PROJECT) });
|
|
const main = await toTheMenu(s);
|
|
await hideUnavailable(main, false);
|
|
for (const command of ["/plan2code-0-pathfinder", "/plan2code-1-plan", "/plan2code-quick-task"]) {
|
|
assert.equal(await offersNote(main, "Start from scratch", command), true, `${command} on Start fresh`);
|
|
}
|
|
assert.equal(await offersNote(main, "demo", "/plan2code-1-plan"), false, "Plan on a picked spec");
|
|
assert.equal(await offersNote(main, "ready", "/plan2code-1b-revise-plan"), true, "Revise plan with no brief waiting");
|
|
assert.equal(await offersNote(main, "paused", "/plan2code-1b-revise-plan"), false, "Revise plan with a brief waiting");
|
|
assert.equal(await offersNote(main, "ready", "/plan2code-3-implement"), false, "Implement never");
|
|
assert.equal(await offersNote(main, "Start from scratch", "/plan2code-xray"), false, "a utility never");
|
|
assert.equal(await offersNote(main, "Start from scratch", "/plan2code-diagnose"), true, "Diagnose on Start fresh");
|
|
assert.equal(await offersNote(main, "ready", "/plan2code-diagnose"), true, "Diagnose on a picked spec");
|
|
});
|
|
|
|
test("the switch lists the Notebook's tabs beside a preview: an empty tab grayed, five ticks at most, a Long tab note, and + note: on the command", async (t) => {
|
|
const project = tempProject(DRAFT_PROJECT);
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project });
|
|
createTab(s.project, "Empty");
|
|
const big = createTab(s.project, "Big").id;
|
|
const small = createTab(s.project, "Small").id;
|
|
saveNote(s.project, big, "# Big idea\n\n" + "x".repeat(52 * 1024));
|
|
for (let i = 0; i < 7; i++) addImage(s.project, big, JPEG);
|
|
saveNote(s.project, small, "A small **idea**.");
|
|
markTabSent(s.project, small, { workflow: "plan" });
|
|
|
|
const main = await toTheMenu(s);
|
|
await chipFor(main, "Start from scratch").click();
|
|
await pickedChip(main, "Start from scratch").waitFor();
|
|
await lightOf(main, "/plan2code-0-pathfinder").click();
|
|
const toggle = noteSwitch(main);
|
|
assert.equal(await toggle.isChecked(), false, "off by default");
|
|
const cmd = main.locator(".confirm-cmd");
|
|
assert.equal(await cmd.locator(".confirm-cmd-note").isHidden(), true);
|
|
await toggle.check();
|
|
|
|
const tabs = main.locator(".confirm-note-tabs");
|
|
await tabs.locator(".confirm-note-tab").nth(2).waitFor();
|
|
const tab = (name) => tabs.locator(".confirm-note-tab", { has: s.page.locator(".confirm-note-tab-name", { hasText: new RegExp(`^${name}$`) }) });
|
|
assert.equal(await tab("Empty").isDisabled(), true, "an empty tab cannot be picked");
|
|
assert.ok(parseFloat(await styleOf(tab("Empty"), "opacity")) < 1, "and is grayed");
|
|
assert.equal(await tab("Big").isEnabled(), true);
|
|
assert.equal(await tab("Small").locator(".notepad-sent-badge").count(), 1, "a sent tab shows its badge");
|
|
assert.equal(await tab("Big").locator(".notepad-sent-badge").count(), 0);
|
|
|
|
// Small: its text, rendered, and no Long tab note.
|
|
await tab("Small").click();
|
|
const preview = main.locator(".confirm-note-preview");
|
|
await preview.locator("strong", { hasText: "idea" }).waitFor();
|
|
assert.equal(await preview.locator(".confirm-note-long").count(), 0);
|
|
assert.equal(await textOf(cmd.locator(".confirm-cmd-note")), "+ note: Small");
|
|
|
|
// Big: over 50 KB, seven pictures, the first five ticked.
|
|
await tab("Big").click();
|
|
await preview.locator(".md-h", { hasText: "Big idea" }).waitFor();
|
|
assert.match(await textOf(preview.locator(".confirm-note-long")), /^Long tab: /);
|
|
assert.equal(await textOf(cmd.locator(".confirm-cmd-note")), "+ note: Big");
|
|
const ticks = preview.locator(".confirm-note-pic input[type=checkbox]");
|
|
assert.equal(await ticks.count(), 7);
|
|
const states = async () => ticks.evaluateAll((bs) => bs.map((b) => (b.checked ? "x" : b.disabled ? "-" : "o")).join(""));
|
|
assert.equal(await states(), "xxxxx--", "the first five ticked, no more can be");
|
|
await ticks.nth(1).uncheck();
|
|
await until(async () => (await states()) === "xoxxxoo", 3000);
|
|
await ticks.nth(6).check();
|
|
await until(async () => (await states()) === "x-xxx-x", 3000);
|
|
|
|
// Off again: no note on the command line.
|
|
await noteSwitch(main).uncheck();
|
|
await until(async () => await cmd.locator(".confirm-cmd-note").isHidden(), 3000);
|
|
assert.equal(await tabs.count(), 0);
|
|
});
|
|
|
|
test("the switch reads the Notebook again when it closes, and starts off again after Back", async (t) => {
|
|
const s = await openSession(await suite.browser(), { t, workflow: "dashboard", payload: MENU, project: tempProject(DRAFT_PROJECT) });
|
|
const keep = createTab(s.project, "Keep").id;
|
|
const gone = createTab(s.project, "Gone").id;
|
|
saveNote(s.project, keep, "first words");
|
|
saveNote(s.project, gone, "soon deleted");
|
|
|
|
const main = await toTheMenu(s);
|
|
await chipFor(main, "Start from scratch").click();
|
|
await pickedChip(main, "Start from scratch").waitFor();
|
|
await lightOf(main, "/plan2code-1-plan").click();
|
|
await noteSwitch(main).check();
|
|
const tabs = main.locator(".confirm-note-tabs");
|
|
const tab = (name) => tabs.locator(".confirm-note-tab", { has: s.page.locator(".confirm-note-tab-name", { hasText: new RegExp(`^${name}$`) }) });
|
|
await tab("Keep").click();
|
|
const preview = main.locator(".confirm-note-preview");
|
|
await preview.getByText("first words").waitFor();
|
|
assert.equal(await preview.getAttribute("role"), "region");
|
|
|
|
// Changed in the Notebook while the pane is open: closing it reads again.
|
|
saveNote(s.project, keep, "second words");
|
|
deleteTab(s.project, gone);
|
|
await s.page.click("#btn-notepad");
|
|
await s.page.locator("#notepad-modal[open]").waitFor();
|
|
await s.page.click("#notepad-close");
|
|
await preview.getByText("second words").waitFor();
|
|
await until(async () => (await tab("Gone").count()) === 0, 5000);
|
|
assert.equal(await textOf(main.locator(".confirm-cmd-note")), "+ note: Keep", "the pick survives a read that still has its tab");
|
|
|
|
// Back, then the same card again: the switch is off and nothing is picked.
|
|
await main.getByRole("button", { name: "Back" }).click();
|
|
await main.getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
|
await lightOf(main, "/plan2code-1-plan").click();
|
|
assert.equal(await noteSwitch(main).isChecked(), false);
|
|
assert.equal(await main.locator(".confirm-cmd-note").isHidden(), true);
|
|
assert.equal(await tabs.count(), 0);
|
|
});
|