2026-10-18 15:39:24 -07:00
// 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" ;
2026-10-26 22:27:31 -07:00
import { pageSuite , openSession , tempProject , textOf , styleOf } from "./page-test-helpers.mjs" ;
2026-10-27 18:20:30 -07:00
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" ;
2026-11-12 10:59:09 -08:00
import { steadyColumns } from "../src/web-console/public/card-rows.js" ;
2026-10-18 15:39:24 -07:00
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
2026-10-26 06:36:46 -07:00
// still lit for it (only exploring, fixed and documented-or-later gray Plan
2026-10-18 15:39:24 -07:00
// 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$/ }) });
2026-10-26 06:36:46 -07:00
assert . equal ( await planCard . isEnabled (), true , "the Plan card is grayed for a drafted plan" );
2026-10-18 15:39:24 -07:00
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" );
2026-10-26 06:36:46 -07:00
// Switched off: the chip shows, labeled and dimmed, and still not picked.
2026-10-18 15:39:24 -07:00
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" );
2026-10-26 22:27:31 -07:00
const opacity = Number ( await styleOf ( bug , "opacity" ));
2026-10-18 15:39:24 -07:00
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" });
2026-10-26 06:36:46 -07:00
assert . equal ( await textOf ( del ), "Delete" , "a fixed bug's Delete is a labeled button" );
2026-10-25 12:46:33 -07:00
await del . click ({ force : true });
2026-10-18 15:39:24 -07:00
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" });
});
2026-11-13 23:28:59 -08:00
// A project holding an upgrade brief Update dependencies wrote for a ticked
// Warning (newest on disk, so the picker opens on it) and an older one Quick
// Task already applied and marked Done.
const UPGRADE_MENU = {
menu : { note : "An upgrade brief is waiting." , recommend : "plan2code-quick-task" , details : { "plan2code-quick-task" : "vite 7.1.2 to 8.0.1" } },
agent : { status : "waiting" },
};
function upgradeProject () {
const project = tempProject ({
"AGENTS.md" : "# AGENTS.md\n\nA small demo project.\n" ,
"specs/old-upgrade/UPGRADE-20261101.md" : "# Upgrade eslint 9.6.1 to 10.2.1\n\n**Status:** Done\n**Ecosystem:** npm\n" ,
"specs/vite-upgrade/UPGRADE-20261113.md" : "# Upgrade vite 7.1.2 to 8.0.1\n\n**Status:** Ready\n**Ecosystem:** npm\n" ,
});
const later = new Date ( Date . now () + 60_000 );
fs . utimesSync ( path . join ( project , "specs/vite-upgrade/UPGRADE-20261113.md" ), later , later );
return project ;
}
test ( "an upgrade brief shows as Upgrade ready with Quick Task and Plan lit, and Quick Task's launch carries it" , async ( t ) => {
const s = await openSession ( await suite . browser (), { t , workflow : "dashboard" , payload : UPGRADE_MENU , project : upgradeProject () });
const main = await toTheMenu ( s );
await hideUnavailable ( main , false );
const brief = chipFor ( main , "vite-upgrade" );
await brief . waitFor ();
assert . equal ( await brief . getAttribute ( "aria-current" ), "true" , "the picker opens on the waiting brief" );
assert . match ( await textOf ( brief ), /Upgrade ready/i , "the chip names its state" );
const quick = lightOf ( main , "/plan2code-quick-task" );
assert . equal ( await quick . isEnabled (), true , "Quick Task is lit" );
assert . equal ( await lightOf ( main , "/plan2code-1-plan" ). isEnabled (), true , "Plan is lit" );
assert . equal ( await lightOf ( main , "/plan2code-0-pathfinder" ). isDisabled (), true , "Pathfinder is grayed" );
assert . equal ( await lightOf ( main , "/plan2code-2-document" ). isDisabled (), true , "Document is grayed" );
await quick . click ();
await main . getByRole ( "button" , { name : "Start Quick task" }). click ();
const launch = collect ( s ). actions . find (( a ) => a . i === "__launch" );
assert . ok ( launch , "the send carries a launch" );
assert . deepEqual ({ skill : launch . skill , spec : launch . spec }, { skill : "plan2code-quick-task" , spec : "specs/vite-upgrade" });
});
test ( "a Done upgrade brief is hidden while unavailable workflows are, reads Upgrade done, and deletes after one confirm" , async ( t ) => {
const s = await openSession ( await suite . browser (), { t , workflow : "dashboard" , payload : UPGRADE_MENU , project : upgradeProject () });
const main = await toTheMenu ( s );
await hideUnavailable ( main , true );
await chipFor ( main , "vite-upgrade" ). waitFor ();
assert . equal ( await chipFor ( main , "old-upgrade" ). count (), 0 , "the done brief's chip is hidden while unavailable workflows are" );
await hideUnavailable ( main , false );
const done = chipFor ( main , "old-upgrade" );
await done . waitFor ();
assert . match ( await textOf ( done ), /Upgrade done/i , "the chip names its state" );
assert . equal ( await done . getAttribute ( "aria-current" ), "false" , "the done brief is not picked" );
const dialog = s . page . locator ( "#delete-modal" );
const del = main . getByRole ( "button" , { name : "Delete the spec old-upgrade" });
assert . equal ( await textOf ( del ), "Delete" , "a done brief's Delete is a labeled button" );
await del . click ({ force : true });
await dialog . waitFor ();
assert . match ( await textOf ( s . page . locator ( "#delete-warn" )), /The upgrade is done, so this only clears the brief/ );
assert . equal ( await s . page . locator ( "#delete-confirm" ). isHidden (), true , "no name step for a done brief" );
await s . page . locator ( "#delete-go" ). click ();
const action = collect ( s ). actions . find (( a ) => a . i === "__delete" );
assert . deepEqual ({ type : action ? . type , spec : action ? . spec }, { type : "delete" , spec : "specs/old-upgrade" });
});
2026-10-18 15:39:24 -07:00
// ---------------------------------------------------------------------------
// 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.
2026-10-26 06:36:46 -07:00
test ( "picking Start from scratch instead of a spec grays Document, and a launch then carries no spec" , async ( t ) => {
2026-10-18 15:39:24 -07:00
const s = await openSession ( await suite . browser (), { t , workflow : "dashboard" , payload : MENU , project : tempProject ( DRAFT_PROJECT ) });
const main = await toTheMenu ( s );
2026-11-02 12:00:12 -08:00
// A grayed card has to show to be checked, whatever an earlier test left.
await hideUnavailable ( main , false );
2026-10-18 15:39:24 -07:00
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" );
2026-11-09 22:09:05 -08:00
// 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" );
2026-10-18 15:39:24 -07:00
2026-10-26 06:36:46 -07:00
// From scratch there is no draft to document: the card grays.
2026-10-18 15:39:24 -07:00
await chipFor ( main , "Start from scratch" ). click ();
await pickedChip ( main , "Start from scratch" ). waitFor ();
2026-10-26 06:36:46 -07:00
assert . equal ( await document . isDisabled (), true , "Document is grayed with no spec picked" );
2026-11-09 22:09:05 -08:00
assert . ok ( await until (() => specTag . isHidden ()), "the top bar's spec name goes from scratch" );
2026-10-18 15:39:24 -07:00
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 ) } ` );
});
2026-11-09 22:09:05 -08:00
// 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 ) } ` );
});
2026-11-11 22:01:55 -08:00
test ( "the UI Prototype card sits in Useful any time with its screen icon, is lit with or without a spec, and launches with the picked 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-ui-prototype" );
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-ui-prototype$/ }). 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 ), /Prototype a screen/ , "it has its title" );
assert . equal ( await card . locator ( "use" ). getAttribute ( "href" ), "#ci-ui-prototype" , "its icon is the framed screen" );
assert . equal ( await s . page . locator ( "symbol#ci-ui-prototype" ). count (), 1 , "the screen 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 picked carries it: the save list starts there.
await card . click ();
await main . getByRole ( "button" , { name : "Start Prototype a screen" }). 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 , spec : launch . spec },
{ skill : "plan2code-ui-prototype" , workflow : "ui-prototype" , spec : "specs/demo" }
);
});
2026-10-26 21:44:38 -07:00
// 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" );
});
2026-10-18 15:39:24 -07:00
// 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 };
}
2026-10-25 12:46:52 -07:00
async function openHandoffMenu ( t , env ) {
2026-10-18 15:39:24 -07:00
const { project , made } = handoffProject ( t );
2026-10-25 12:46:52 -07:00
const s = await openSession ( await suite . browser (), { t , workflow : "dashboard" , payload : MENU , project , env });
2026-10-18 15:39:24 -07:00
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 );
2026-10-26 06:36:46 -07:00
assert . match ( await textOf ( chip ), /Handoff/i , "the chip is labeled Handoff" );
2026-10-18 15:39:24 -07:00
assert . equal ( await chip . getAttribute ( "aria-current" ), "false" , "a handoff is offered, not picked for you" );
2026-10-26 22:27:31 -07:00
assert . equal ( await styleOf ( chip , "borderTopStyle" ), "dashed" , "the chip's border is dashed" );
2026-10-18 15:39:24 -07:00
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 } ` );
});
2026-10-25 12:46:52 -07:00
// 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 ();
});
2026-10-18 15:39:24 -07:00
// 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" });
});
2026-11-10 10:19:33 -08:00
// Under the desktop app (PLAN2CODE_IN_APP=1) the banner shows too: the app
// cannot replace itself, so a new release is a terminal command there as well,
// and the modal says to run it outside the app and reopen the app.
test ( "under the app, the update banner shows and its steps are worded for the app" , async ( t ) => {
2026-10-25 12:46:52 -07:00
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 );
2026-11-10 10:19:33 -08:00
await main . getByRole ( "button" , { name : /UPDATE AVAILABLE · v99\.0\.0/ }). click ();
const modal = dash . page . locator ( "#update-modal" );
await modal . waitFor ();
await modal . getByText ( "a terminal outside the app" , { exact : false }). waitFor ();
await modal . getByText ( "close the app and open it again" , { exact : false }). waitFor ();
assert . equal ( await modal . locator ( "#update-command code" ). textContent (), "plan2code update" );
2026-10-25 12:46:52 -07:00
});
// 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" );
});
2026-10-18 15:39:24 -07:00
// 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" );
});
2026-10-27 18:20:30 -07:00
// 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" );
2026-11-09 08:08:43 -08:00
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" );
2026-11-12 10:35:30 -08:00
assert . equal ( await offersNote ( main , "Start from scratch" , "/plan2code-ui-prototype" ), true , "UI Prototype on Start fresh" );
assert . equal ( await offersNote ( main , "ready" , "/plan2code-ui-prototype" ), false , "UI Prototype on a picked spec" );
2026-10-27 18:20:30 -07:00
});
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 );
});
2026-11-12 10:35:30 -08:00
// The cards of a group as rows: each card's left edge and width, grouped by
2026-11-12 10:59:09 -08:00
// the top edge it sits at. Null while a redraw is replacing the cards (a card
// with no box), so `until` reads it as not settled yet.
2026-11-12 10:35:30 -08:00
async function cardRows ( grid ) {
const rows = new Map ();
for ( const card of await grid . locator ( ":scope > .dash-card" ). all ()) {
const box = await card . boundingBox ();
2026-11-12 10:59:09 -08:00
if ( ! box ) return null ;
2026-11-12 10:35:30 -08:00
const top = Math . round ( box . y );
if ( ! rows . has ( top )) rows . set ( top , []);
rows . get ( top ). push ({ x : Math . round ( box . x ), w : Math . round ( box . width ) });
}
return [... rows . keys ()]. sort (( a , b ) => a - b ). map (( k ) => rows . get ( k ));
}
test ( "every group keeps one card width and leaves no card alone on a row, at each Card width setting" , async ( t ) => {
const s = await openSession ( await suite . browser (), { t , workflow : "dashboard" , payload : MENU , project : tempProject ( DRAFT_PROJECT ) });
await s . page . setViewportSize ({ width : 2400 , height : 1000 });
const main = await toTheMenu ( s );
await hideUnavailable ( main , false );
const utilities = main
. locator ( "section.dash-group" )
. filter ({ has : s . page . locator ( "h3" , { hasText : /^Useful any time$/ }) })
. locator ( ".dash-grid" );
await utilities . waitFor ();
const count = await utilities . locator ( ":scope > .dash-card" ). count ();
assert . ok ( count >= 9 , `the utilities hold enough cards to wrap: ${ count } ` );
for ( const width of [ "narrow" , "comfortable" , "wide" , "ultrawide" ]) {
await s . page . evaluate (( w ) => ( document . documentElement . dataset . width = w ), width );
2026-11-12 10:59:09 -08:00
// What card-rows.js picks for this many cards at the grid's width: the
// first row holds that many, so a new utility card never breaks this.
let rows , want ;
2026-11-12 10:35:30 -08:00
const settled = await until ( async () => {
2026-11-12 10:59:09 -08:00
const box = await utilities . boundingBox ();
rows = box && ( await cardRows ( utilities ));
if ( ! rows ) return false ;
want = steadyColumns ( rows . flat (). length , Math . round ( box . width )). cols ;
return rows . length > 1 && rows [ 0 ]. length === want && rows . every (( r ) => r . length >= 2 ) && new Set ( rows . flat (). map (( c ) => c . w )). size === 1 ;
2026-11-12 10:35:30 -08:00
});
2026-11-12 10:59:09 -08:00
assert . ok ( settled , `at ${ width } , ${ want } across, every row holding two cards or more, all one width: ${ JSON . stringify ( rows ) } ` );
2026-11-12 10:35:30 -08:00
}
});