2026-11-02 12:00:12 -08:00
// Page tests for User Preferences: its four tabs, the saved looks (highlight
// and theme), the Agents & models tab (the launcher's model menus and the
// person's agents) and Cleanup. Run with:
2026-10-18 15:39:24 -07:00
// node --test scripts/test-web-console-page-prefs.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-11-02 12:00:12 -08:00
import { pageSuite , openSession , textOf , drawn , styleOf , stylesOf } from "./page-test-helpers.mjs" ;
2026-10-18 15:39:24 -07:00
import { HOME , MODELS_DIR , backdate } from "./web-console-test-helpers.mjs" ;
import { formatBytes } from "../src/web-console/public/answers.js" ;
const suite = pageSuite ( test );
// A plan session on the person's turn: one text question and the agent listening.
const PLAN_QUESTION = {
items : [{ id : "q1" , kind : "text" , title : "What to call it" , body : "A short name for the export." }],
agent : { status : "waiting" },
};
// The console home's saved looks are shared by every session of this file, so
// each test starts with none and leaves none.
const LOOKS_FILE = path . join ( HOME , "looks.json" );
function noSavedLooks ( t ) {
fs . rmSync ( LOOKS_FILE , { force : true });
t . after (() => fs . rmSync ( LOOKS_FILE , { force : true }));
}
const root = ( s , attr ) => s . page . evaluate (( a ) => document . documentElement . getAttribute ( a ), attr );
// The highlight the page paints with: an inline override while it is not the default.
const accentVar = ( s ) => s . page . evaluate (() => document . documentElement . style . getPropertyValue ( "--accent" ));
const swatch = ( s , id ) => s . page . locator ( `#looks-swatches [data-accent=" ${ id } "]` );
// The page as the server first sends it, before any script has run: the saved
// theme and highlight are in the markup so a reload never flashes the defaults.
async function firstPaintAttrs ( s ) {
const html = await ( await s . context . request . get ( s . url )). text ();
const tag = html . match ( /<html\b[^>]*>/i )[ 0 ];
return { theme : tag . match ( /data-theme="([^"]*)"/ ) ? .[ 1 ] ?? null , accent : tag . match ( /data-looks-accent="([^"]*)"/ ) ? .[ 1 ] ?? null };
}
test ( "the violet highlight and dark theme chosen in preferences stick across a reload, and Back to default clears them" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
assert . equal ( await root ( s , "data-theme" ), null , "the theme starts on the system's" );
await s . page . click ( "#btn-looks" );
await s . page . locator ( "#looks-modal[open]" ). waitFor ();
await swatch ( s , "violet" ). click ();
await s . page . locator ( 'input[name="looks-theme"][value="dark"]' ). check ();
await s . page . waitForFunction (() => document . documentElement . getAttribute ( "data-theme" ) === "dark" );
assert . equal ( await swatch ( s , "violet" ). getAttribute ( "aria-pressed" ), "true" );
assert . equal ( await accentVar ( s ), "#a785e2" , "the dark violet is painted" );
// Saved on the server (looks.json), not only in this tab.
await s . page . waitForFunction ( async () => {
const saved = ( await ( await fetch ( "/looks" )). json ()). looks || {};
return saved . accent === "violet" && saved . theme === "dark" ;
});
await s . page . click ( "#looks-done" );
// What the server sends first, and what the page settles on, both keep the choice.
assert . deepEqual ( await firstPaintAttrs ( s ), { theme : "dark" , accent : "violet" }, "the first paint carries the saved looks" );
await s . page . reload ({ waitUntil : "domcontentloaded" });
await drawn ( s . page );
assert . equal ( await root ( s , "data-theme" ), "dark" , "the theme did not stick" );
await s . page . waitForFunction (() => document . documentElement . style . getPropertyValue ( "--accent" ) === "#a785e2" );
await s . page . click ( "#btn-looks" );
assert . equal ( await swatch ( s , "violet" ). getAttribute ( "aria-pressed" ), "true" , "the violet swatch is not the chosen one after a reload" );
assert . equal ( await s . page . locator ( 'input[name="looks-theme"][value="dark"]' ). isChecked (), true );
// Back to default returns both, here and for the next page.
await s . page . click ( "#looks-reset" );
await s . page . waitForFunction (() => ! document . documentElement . hasAttribute ( "data-theme" ));
assert . equal ( await accentVar ( s ), "" , "the chosen highlight is still painted" );
assert . equal ( await swatch ( s , "violet" ). getAttribute ( "aria-pressed" ), "false" );
assert . equal ( await s . page . locator ( 'input[name="looks-theme"][value="system"]' ). isChecked (), true );
await s . page . waitForFunction ( async () => {
const saved = ( await ( await fetch ( "/looks" )). json ()). looks || {};
return saved . theme === "system" && saved . accent !== "violet" ;
});
assert . deepEqual ( await firstPaintAttrs ( s ), { theme : null , accent : null }, "the first paint still carries the old looks" );
});
2026-11-02 12:00:12 -08:00
// The Agents & models tab: the summary table, its rows and the form Edit opens.
const AGENTS_FILE = path . join ( MODELS_DIR , "agents.json" );
const agentsTable = ( s ) => s . page . locator ( "#agents-table" );
const agentRow = ( s , key ) => s . page . locator ( `#agents-table tr[data-key=" ${ key } "]` );
const agentForm = ( s ) => s . page . locator ( "#agents-form" );
const formField = ( s , name ) => agentForm ( s ). getByRole ( "textbox" , { name , exact : true });
const formButton = ( s , name ) => agentForm ( s ). getByRole ( "button" , { name , exact : true });
const unsavedPrompt = ( s ) => s . page . locator ( "#prefs-unsaved" );
async function openAgentsTab ( s ) {
await s . page . click ( "#btn-looks" );
await s . page . click ( "#prefs-tab-agents" );
await agentRow ( s , "cli:claude" ). waitFor ();
}
// agents.json as the test starts it: none, or the entries given. Removed after.
function seedAgents ( t , agents ) {
fs . rmSync ( AGENTS_FILE , { force : true });
if ( agents ) {
fs . mkdirSync ( MODELS_DIR , { recursive : true });
fs . writeFileSync ( AGENTS_FILE , JSON . stringify ({ schema : 1 , agents }, null , 2 ));
}
t . after (() => fs . rmSync ( AGENTS_FILE , { force : true }));
}
test ( "Agents & models: the table lists Claude, Devin and Codex, and a model id typed in Codex's form is saved only on Save" , async ( t ) => {
2026-10-18 15:39:24 -07:00
noSavedLooks ( t );
2026-11-02 12:00:12 -08:00
seedAgents ( t );
2026-10-18 15:39:24 -07:00
// The file the launcher reads: put back as the suite had it (no file).
t . after (() => fs . rmSync ( path . join ( MODELS_DIR , "models.json" ), { force : true }));
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
2026-11-02 12:00:12 -08:00
await openAgentsTab ( s );
const keys = await agentsTable ( s ). locator ( "tbody tr[data-key]" ). evaluateAll (( rows ) => rows . map (( r ) => r . dataset . key ));
assert . deepEqual ( keys , [ "cli:claude" , "cli:devin" , "cli:codex" ]);
assert . equal ( await textOf ( agentRow ( s , "cli:codex" ). locator ( ".prefs-agents-name > span" ). first ()), "Codex" );
2026-10-18 15:39:24 -07:00
2026-11-02 12:00:12 -08:00
await s . page . getByRole ( "button" , { name : "Edit Codex" }). click ();
await agentForm ( s ). waitFor ();
assert . equal ( await agentsTable ( s ). isVisible (), false , "the form takes the table's place" );
await agentForm ( s ). locator ( ".prefs-agents-none" ). filter ({ hasText : /^No models ship for Codex yet/ }). waitFor ();
assert . equal ( await agentForm ( s ). locator ( ".models-row.locked" ). count (), 0 , "nothing comes with Plan2Code for Codex" );
await formButton ( s , "Add a model" ). click ();
const id = formField ( s , "Model id" );
2026-10-18 15:39:24 -07:00
await id . fill ( "gpt-test-codex-1" );
await id . press ( "Tab" );
2026-11-02 12:00:12 -08:00
await s . page . waitForTimeout ( 300 );
const before = await s . page . evaluate ( async () => ( await ( await fetch ( "/models" )). json ()). user );
assert . deepEqual ( before . codex , [], "nothing is saved before Save" );
assert . equal ( await agentForm ( s ). locator ( ".prefs-unsaved-badge" ). isVisible (), true );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".prefs-saved" ). filter ({ hasText : /^Saved\. Restart plan2code/ }). waitFor ();
2026-10-18 15:39:24 -07:00
const saved = await s . page . evaluate ( async () => ( await ( await fetch ( "/models" )). json ()). user );
assert . deepEqual ( saved . codex . map (( m ) => m . id ), [ "gpt-test-codex-1" ], "the id was not saved under Codex" );
assert . deepEqual ([ saved . claude , saved . devin ], [[], []], "the id leaked into another agent's menu" );
2026-11-02 12:00:12 -08:00
assert . equal ( await agentForm ( s ). locator ( ".prefs-unsaved-badge" ). isVisible (), false , "saved, nothing is unsaved" );
2026-10-18 15:39:24 -07:00
2026-11-02 12:00:12 -08:00
// The summary counts it on Codex's row, and so does a fresh page.
await formButton ( s , "Back to summary" ). click ();
assert . equal ( await s . page . evaluate (() => document . activeElement ? . getAttribute ( "aria-label" ) || document . activeElement ? . id ), "Edit Codex" , "focus comes back to the row just left" );
assert . match ( await textOf ( agentRow ( s , "cli:codex" ). locator ( ".prefs-agents-models" )), /^1: gpt-test-codex-1$/ );
2026-10-18 15:39:24 -07:00
await s . page . reload ({ waitUntil : "domcontentloaded" });
await drawn ( s . page );
2026-11-02 12:00:12 -08:00
await openAgentsTab ( s );
await s . page . getByRole ( "button" , { name : "Edit Codex" }). click ();
assert . equal ( await formField ( s , "Model id" ). inputValue (), "gpt-test-codex-1" );
2026-10-18 15:39:24 -07:00
});
2026-11-02 12:00:12 -08:00
test ( "Agents & models: a person adds an agent, tests its command, sees it after a reload, and deletes it" , async ( t ) => {
2026-10-25 21:26:08 -07:00
noSavedLooks ( t );
2026-11-02 12:00:12 -08:00
seedAgents ( t );
2026-10-25 21:26:08 -07:00
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
2026-11-02 12:00:12 -08:00
await openAgentsTab ( s );
assert . equal ( await agentsTable ( s ). locator ( 'tr[data-key^="agent:"]' ). count (), 0 , "no agents before one is added" );
2026-10-25 21:26:08 -07:00
await s . page . click ( "#agents-add" );
2026-11-02 12:00:12 -08:00
await agentForm ( s ). waitFor ();
assert . equal ( await agentForm ( s ). locator ( "details.prefs-agents-args" ). evaluate (( d ) => d . open ), true , "the arguments are open on a new agent" );
await formField ( s , "Name" ). fill ( "Test Agent" );
await formField ( s , "Command" ). fill ( "node" );
await formButton ( s , "Test" ). click ();
await agentForm ( s ). locator ( ".agent-test-result" ). filter ({ hasText : /^Found at / }). waitFor ();
assert . equal ( fs . existsSync ( AGENTS_FILE ), false , "Test never saves" );
2026-10-25 21:26:08 -07:00
2026-11-02 12:00:12 -08:00
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".prefs-saved" ). filter ({ hasText : /^Saved$/ }). waitFor ();
const saved = JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" ));
2026-10-25 21:26:08 -07:00
assert . equal ( saved . schema , 1 );
assert . deepEqual ( saved . agents . map (( a ) => [ a . id , a . name , a . command , a . prompt ]), [[ "test-agent" , "Test Agent" , "node" , "/plan2code" ]]);
2026-11-02 12:00:12 -08:00
assert . equal ( await agentForm ( s ). locator ( ".prefs-agents-delete" ). count (), 1 , "once saved it has Delete agent" );
2026-10-25 21:26:08 -07:00
await s . page . reload ({ waitUntil : "domcontentloaded" });
await drawn ( s . page );
2026-11-02 12:00:12 -08:00
await openAgentsTab ( s );
const row = agentRow ( s , "agent:test-agent" );
await row . locator ( ".prefs-badge.ok" ). waitFor ();
assert . equal ( await textOf ( row . locator ( ".prefs-badge" )), "Found" );
await s . page . getByRole ( "button" , { name : "Edit Test Agent" }). click ();
assert . equal ( await formField ( s , "Name" ). inputValue (), "Test Agent" );
assert . equal ( await agentForm ( s ). locator ( "details.prefs-agents-args" ). evaluate (( d ) => d . open ), false , "the arguments are folded on a saved agent" );
2026-10-25 21:26:08 -07:00
2026-11-02 12:00:12 -08:00
await formButton ( s , "Delete agent" ). click ();
await formButton ( s , "Yes, delete" ). click ();
await agentsTable ( s ). waitFor ();
assert . equal ( await agentsTable ( s ). locator ( 'tr[data-key^="agent:"]' ). count (), 0 );
assert . deepEqual ( JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents , []);
assert . equal ( await s . page . evaluate (() => document . activeElement ? . getAttribute ( "aria-label" ) || document . activeElement ? . id ), "agents-add" , "with its row gone, focus goes to Add agent" );
assert . equal ( await textOf ( s . page . locator ( "#agents-status" )), "Deleted." );
2026-10-25 21:26:08 -07:00
await s . page . click ( "#agents-add" );
2026-11-02 12:00:12 -08:00
assert . equal ( await s . page . locator ( "#agents-status" ). innerText (), "" , "opening a form clears Deleted." );
2026-10-25 21:26:08 -07:00
});
2026-11-02 12:00:12 -08:00
test ( "Agents & models: a new agent with only a name is not sent, its command is marked, and focus and text survive" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await openAgentsTab ( s );
await s . page . click ( "#agents-add" );
await formField ( s , "Name" ). fill ( "Focus Agent" );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".agent-error" ). filter ({ hasText : "Give it a name and a command first." }). waitFor ();
assert . equal ( fs . existsSync ( AGENTS_FILE ), false , "nothing is written" );
assert . equal ( await agentForm ( s ). locator ( 'input.invalid[data-field="command"]' ). count (), 1 , "the command field is marked" );
assert . equal ( await formField ( s , "Name" ). inputValue (), "Focus Agent" , "the typed name survives the redraw" );
assert . equal ( await s . page . evaluate (() => document . activeElement ? . textContent ), "Save" , "focus stays on Save" );
// The first good save assigns an id; the form stays open on it.
await formField ( s , "Command" ). fill ( "node" );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".prefs-saved" ). filter ({ hasText : /^Saved$/ }). waitFor ();
assert . equal ( JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents [ 0 ]. id , "focus-agent" );
assert . equal ( await textOf ( agentForm ( s ). locator ( ".prefs-agents-title" )), "Focus Agent" );
// A refused save marks the field the server names, and keeps what was typed.
await formField ( s , "Name" ). fill ( "" );
await formField ( s , "Start prompt" ). fill ( "/plan2code hi" );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".agent-error" ). filter ({ hasText : /name is missing/ }). waitFor ();
assert . equal ( await agentForm ( s ). locator ( 'input.invalid[data-field="name"]' ). count (), 1 );
assert . equal ( await formField ( s , "Start prompt" ). inputValue (), "/plan2code hi" );
assert . equal ( JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents [ 0 ]. name , "Focus Agent" , "a refused save writes nothing" );
});
test ( "Agents & models: a file holding entries the page could not read is only replaced after Save anyway" , async ( t ) => {
2026-10-25 21:26:08 -07:00
noSavedLooks ( t );
const text = JSON . stringify ({ schema : 2 , agents : [{ id : "future" , name : "Future" , command : "future" }] });
2026-11-02 12:00:12 -08:00
fs . mkdirSync ( MODELS_DIR , { recursive : true });
fs . writeFileSync ( AGENTS_FILE , text );
t . after (() => fs . rmSync ( AGENTS_FILE , { force : true }));
2026-10-25 21:26:08 -07:00
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
2026-11-02 12:00:12 -08:00
await openAgentsTab ( s );
2026-10-25 21:26:08 -07:00
await s . page . locator ( "#agents-status" ). filter ({ hasText : /schema 2/ }). waitFor ();
await s . page . click ( "#agents-add" );
2026-11-02 12:00:12 -08:00
assert . equal ( await formButton ( s , "Save anyway" ). count (), 0 , "no Save anyway before a save is tried" );
await formField ( s , "Name" ). fill ( "Mine" );
await formField ( s , "Command" ). fill ( "node" );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".agent-error" ). filter ({ hasText : /could not read/ }). first (). waitFor ();
assert . equal ( fs . readFileSync ( AGENTS_FILE , "utf8" ), text , "the refused save writes nothing" );
2026-10-25 21:26:08 -07:00
2026-11-02 12:00:12 -08:00
await formButton ( s , "Save anyway" ). click ();
await agentForm ( s ). locator ( ".prefs-saved" ). filter ({ hasText : /^Saved$/ }). waitFor ();
assert . equal ( await formButton ( s , "Save anyway" ). count (), 0 );
assert . deepEqual ( JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents . map (( a ) => a . id ), [ "mine" ]);
});
const TWO_AGENTS = [
{ id : "alpha" , name : "Alpha" , command : "alpha-cli" },
{ id : "beta" , name : "Beta" , command : "beta-cli" },
];
test ( "Agents & models: nothing reaches agents.json before Save" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t , TWO_AGENTS );
const before = fs . readFileSync ( AGENTS_FILE , "utf8" );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await openAgentsTab ( s );
await s . page . getByRole ( "button" , { name : "Edit Alpha" }). click ();
await formField ( s , "Command" ). fill ( "alpha-cli --edited" );
await formField ( s , "Command" ). press ( "Tab" );
await s . page . waitForTimeout ( 500 );
assert . equal ( fs . readFileSync ( AGENTS_FILE , "utf8" ), before , "agents.json is byte for byte unchanged" );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".prefs-saved" ). filter ({ hasText : /^Saved$/ }). waitFor ();
assert . equal ( JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents [ 0 ]. command , "alpha-cli --edited" );
});
test ( "Agents & models: a discarded edit never rides along with another agent's Save" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t , TWO_AGENTS );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await openAgentsTab ( s );
await s . page . getByRole ( "button" , { name : "Edit Alpha" }). click ();
await formField ( s , "Command" ). fill ( "alpha-cli --dropped" );
await formButton ( s , "Back to summary" ). click ();
await unsavedPrompt ( s ). waitFor ();
assert . equal ( await textOf ( s . page . locator ( "#prefs-unsaved-name" )), "Alpha" );
assert . equal ( await s . page . locator ( "#looks-modal .prefs-body" ). evaluate (( b ) => b . inert ), true , "the dialog behind the prompt is out of reach" );
await unsavedPrompt ( s ). getByRole ( "button" , { name : "Discard" , exact : true }). click ();
await agentsTable ( s ). waitFor ();
assert . equal ( await s . page . locator ( "#looks-modal .prefs-body" ). evaluate (( b ) => b . inert ), false );
assert . equal ( await s . page . evaluate (() => document . activeElement ? . getAttribute ( "aria-label" ) || document . activeElement ? . id ), "Edit Alpha" , "focus comes back to the row just left" );
await s . page . getByRole ( "button" , { name : "Edit Beta" }). click ();
await formField ( s , "Command" ). fill ( "beta-cli --kept" );
await formButton ( s , "Save" ). click ();
await agentForm ( s ). locator ( ".prefs-saved" ). filter ({ hasText : /^Saved$/ }). waitFor ();
const agents = JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents ;
assert . deepEqual ( agents . map (( a ) => [ a . id , a . command ]), [[ "alpha" , "alpha-cli" ], [ "beta" , "beta-cli --kept" ]]);
});
test ( "Agents & models: an unsaved edit asks first on Back, Close, Esc, a backdrop click and a tab switch" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t , TWO_AGENTS );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await openAgentsTab ( s );
const modal = s . page . locator ( "#looks-modal" );
const edit = async ( command ) => {
if ( ! ( await agentForm ( s ). isVisible ())) await s . page . getByRole ( "button" , { name : "Edit Alpha" }). click ();
await formField ( s , "Command" ). fill ( command );
};
const triggers = {
back : () => formButton ( s , "Back to summary" ). click (),
close : () => s . page . click ( "#looks-done" ),
esc : () => formField ( s , "Command" ). press ( "Escape" ),
backdrop : () => s . page . mouse . click ( 4 , 4 ),
tab : () => s . page . click ( "#prefs-tab-appearance" ),
};
for ( const [ name , leave ] of Object . entries ( triggers )) {
// Keep editing: the form and the draft stay.
await edit ( `alpha- ${ name } -kept` );
await leave ();
await unsavedPrompt ( s ). waitFor ();
assert . equal ( await s . page . evaluate (() => document . activeElement ? . id ), "prefs-unsaved-save" , ` ${ name } : Save has focus` );
await unsavedPrompt ( s ). getByRole ( "button" , { name : "Keep editing" }). click ();
await unsavedPrompt ( s ). waitFor ({ state : "hidden" });
assert . equal ( await modal . evaluate (( d ) => d . open ), true , ` ${ name } : the dialog stays open` );
assert . equal ( await formField ( s , "Command" ). inputValue (), `alpha- ${ name } -kept` , ` ${ name } : the draft stays` );
assert . equal ( await s . page . locator ( "#prefs-tab-agents" ). getAttribute ( "aria-selected" ), "true" );
}
const before = fs . readFileSync ( AGENTS_FILE , "utf8" );
// Discard drops the edit and goes on (here, Close).
await triggers . close ();
await unsavedPrompt ( s ). getByRole ( "button" , { name : "Discard" , exact : true }). click ();
await modal . waitFor ({ state : "hidden" });
assert . equal ( fs . readFileSync ( AGENTS_FILE , "utf8" ), before , "Discard writes nothing" );
// Save writes and goes on (here, a tab switch).
await openAgentsTab ( s );
await edit ( "alpha-saved" );
await triggers . tab ();
await unsavedPrompt ( s ). getByRole ( "button" , { name : "Save" , exact : true }). click ();
await s . page . locator ( '#prefs-tab-appearance[aria-selected="true"]' ). waitFor ();
assert . equal ( JSON . parse ( fs . readFileSync ( AGENTS_FILE , "utf8" )). agents [ 0 ]. command , "alpha-saved" );
});
test ( "Agents & models: Esc in the unsaved prompt keeps editing, and a Save that fails there stays and marks the field" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await openAgentsTab ( s );
await s . page . click ( "#agents-add" );
await formField ( s , "Name" ). fill ( "Half Agent" );
await s . page . click ( "#looks-done" );
await unsavedPrompt ( s ). waitFor ();
await s . page . keyboard . press ( "Escape" );
await unsavedPrompt ( s ). waitFor ({ state : "hidden" });
assert . equal ( await s . page . locator ( "#looks-modal" ). evaluate (( d ) => d . open ), true , "Esc in the prompt does not close the dialog" );
assert . equal ( await formField ( s , "Name" ). inputValue (), "Half Agent" , "the draft stays" );
// Save from the prompt with no command: nothing is sent, the dialog stays, focus is on the marked field.
await s . page . click ( "#looks-done" );
await unsavedPrompt ( s ). getByRole ( "button" , { name : "Save" , exact : true }). click ();
await unsavedPrompt ( s ). waitFor ({ state : "hidden" });
assert . equal ( await s . page . locator ( "#looks-modal" ). evaluate (( d ) => d . open ), true , "a failed Save keeps the dialog open" );
assert . equal ( fs . existsSync ( AGENTS_FILE ), false , "nothing is written" );
assert . equal ( await s . page . evaluate (() => document . activeElement ? . matches ( 'input.invalid[data-field="command"]' )), true , "focus is on the marked field" );
});
test ( "Agents & models: a command not on PATH is marked, and the orchestrator row has no Edit" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t , [{ id : "ghost" , name : "Ghost" , command : "plan2code-no-such-command-xyz" }]);
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await openAgentsTab ( s );
const badge = agentRow ( s , "agent:ghost" ). locator ( ".prefs-badge" );
await badge . filter ({ hasText : "Not found on PATH" }). waitFor ();
assert . equal ( await badge . evaluate (( b ) => b . classList . contains ( "missing" )), true );
const soon = agentsTable ( s ). locator ( "tr.prefs-agents-soon" );
assert . match ( await textOf ( soon ), /v3 orchestrator\s+Nothing to set yet\./ );
assert . equal ( await soon . getByRole ( "button" ). count (), 0 );
});
test ( "Agents & models: below 720 px the Models column is hidden and the form is one column" , async ( t ) => {
noSavedLooks ( t );
seedAgents ( t , TWO_AGENTS );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . setViewportSize ({ width : 600 , height : 800 });
await openAgentsTab ( s );
const cells = agentsTable ( s ). locator ( ".prefs-agents-models" );
const shown = [];
for ( let i = 0 ; i < ( await cells . count ()); i ++ ) shown . push ( await styleOf ( cells . nth ( i ), "display" ));
assert . ok ( shown . length > 0 && shown . every (( d ) => d === "none" ), `the Models cells are hidden: ${ shown } ` );
await s . page . getByRole ( "button" , { name : "Edit Alpha" }). click ();
const cols = await styleOf ( agentForm ( s ). locator ( ".prefs-agents-fields" ), "grid-template-columns" );
assert . equal ( cols . trim (). split ( /\s+/ ). length , 1 , `one column: ${ cols } ` );
2026-10-25 21:26:08 -07:00
});
2026-10-18 15:39:24 -07:00
test ( "Cleanup scans the console home and lists an old session folder with its size" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
// Made after the session opens: opening sweeps old sessions away. A session
// is old when nothing in it has been touched for 30 days.
const sid = "20250801-101010-aaaaaa" ;
const dir = path . join ( HOME , "sessions" , sid );
fs . mkdirSync ( dir , { recursive : true });
const state = path . join ( dir , "state.json" );
fs . writeFileSync ( state , "x" . repeat ( 3000 ));
backdate ( state );
backdate ( dir );
t . after (() => fs . rmSync ( dir , { recursive : true , force : true }));
await s . page . click ( "#btn-looks" );
2026-11-02 12:00:12 -08:00
await s . page . click ( "#prefs-tab-system" );
2026-10-18 15:39:24 -07:00
const list = s . page . locator ( "#cleanup-list" );
assert . equal ( await list . locator ( ".cleanup-row" ). count (), 0 , "Cleanup lists things before a scan" );
assert . equal ( await s . page . locator ( "#cleanup-delete" ). isHidden (), true , "Delete is offered before a scan" );
await s . page . click ( "#cleanup-scan" );
const row = list . locator ( ".cleanup-row" ). filter ({ hasText : sid });
await row . waitFor ();
assert . match ( await textOf ( row ), new RegExp ( `^Session ${ sid } ` ));
const size = await textOf ( row . locator ( ".cleanup-size" ));
assert . match ( size , /^\d/ , "the row names a size" );
assert . ok ( size === formatBytes ( 3000 ) || /^[\d.,]+\s*(kB|KB|MB|B)\b/ . test ( size ), `the size reads as a size: ${ size } ` );
assert . match ( await textOf ( list . locator ( ".cleanup-summary" )), /1 old session/ );
assert . match ( await textOf ( s . page . locator ( "#cleanup-status" )), /^Found \d+ items?\./ );
assert . equal ( await s . page . locator ( "#cleanup-delete" ). isVisible (), true , "Delete these is offered once something is found" );
// The scan only looks.
assert . equal ( fs . existsSync ( dir ), true , "a scan deleted the folder" );
// Closing preferences forgets the scan: a reopened dialog starts clean.
await s . page . click ( "#looks-done" );
await s . page . click ( "#btn-looks" );
2026-11-02 12:00:12 -08:00
await s . page . click ( "#prefs-tab-system" );
2026-10-18 15:39:24 -07:00
assert . equal ( await list . locator ( ".cleanup-row" ). count (), 0 , "the old scan is still listed" );
assert . equal ( await s . page . locator ( "#cleanup-delete" ). isHidden (), true );
});
2026-11-02 12:00:12 -08:00
/* ------------------------------------------------------------- the tabs */
const tabNames = async ( s ) => ( await s . page . locator ( "#prefs-tabs [role=tab] .prefs-tab-label" ). allInnerTexts ()). map (( x ) => x . trim ());
const selectedTab = ( s ) => s . page . evaluate (() => document . querySelector ( '#prefs-tabs [aria-selected="true"]' ) ? . id );
const focusedId = ( s ) => s . page . evaluate (() => document . activeElement ? . id );
const visiblePanels = ( s ) => s . page . evaluate (() => [... document . querySelectorAll ( "#prefs-panels [role=tabpanel]" )]. filter (( p ) => ! p . hidden ). map (( p ) => p . id ));
test ( "the gear opens User Preferences on Appearance, with four tabs in order and one panel shown" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . setViewportSize ({ width : 1000 , height : 800 });
await s . page . click ( "#btn-looks" );
await s . page . locator ( "#looks-modal[open]" ). waitFor ();
assert . deepEqual ( await tabNames ( s ), [ "Appearance" , "Agents & models" , "System" , "Sounds & activities" ]);
assert . equal ( await selectedTab ( s ), "prefs-tab-appearance" );
assert . equal ( await focusedId ( s ), "prefs-tab-appearance" , "focus is on the selected tab" );
assert . equal ( await s . page . locator ( '#prefs-tabs [tabindex="0"]' ). count (), 1 , "one tab in the tab order" );
assert . deepEqual ( await visiblePanels ( s ), [ "prefs-panel-appearance" ]);
assert . equal ( await s . page . locator ( "#prefs-tab-appearance" ). getAttribute ( "aria-controls" ), "prefs-panel-appearance" );
assert . equal ( await s . page . locator ( "#prefs-panel-appearance" ). getAttribute ( "aria-labelledby" ), "prefs-tab-appearance" );
assert . equal ( await textOf ( s . page . locator ( "#looks-done" )), "Close" , "the footer button no longer says Done" );
});
test ( "Preferences' tabs move with the arrow, Home and End keys, wrapping at the ends" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . click ( "#btn-looks" );
await s . page . locator ( "#looks-modal[open]" ). waitFor ();
const press = async ( key , want ) => {
await s . page . keyboard . press ( key );
assert . equal ( await selectedTab ( s ), want , ` ${ key } selects ${ want } ` );
assert . equal ( await focusedId ( s ), want , ` ${ key } focuses ${ want } ` );
assert . deepEqual ( await visiblePanels ( s ), [ want . replace ( "-tab-" , "-panel-" )]);
};
await press ( "ArrowDown" , "prefs-tab-agents" );
await press ( "ArrowRight" , "prefs-tab-system" );
await press ( "End" , "prefs-tab-sounds" );
await press ( "ArrowDown" , "prefs-tab-appearance" );
await press ( "ArrowUp" , "prefs-tab-sounds" );
await press ( "Home" , "prefs-tab-appearance" );
await press ( "ArrowLeft" , "prefs-tab-sounds" );
});
test ( "below 720 px the side list is a horizontal strip with no hints" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . setViewportSize ({ width : 1000 , height : 800 });
await s . page . click ( "#btn-looks" );
const list = s . page . locator ( "#prefs-tabs" );
const hint = s . page . locator ( "#prefs-tab-appearance .prefs-tab-hint" );
assert . equal ( await list . getAttribute ( "aria-orientation" ), "vertical" );
assert . equal ( await styleOf ( hint , "display" ), "block" , "hints show in the side list" );
assert . equal ( await styleOf ( list , "flex-direction" ), "column" );
await s . page . setViewportSize ({ width : 600 , height : 800 });
await s . page . waitForFunction (() => document . getElementById ( "prefs-tabs" ). getAttribute ( "aria-orientation" ) === "horizontal" );
assert . equal ( await styleOf ( hint , "display" ), "none" , "no hints in the strip" );
assert . deepEqual ( await stylesOf ( list , [ "flex-direction" , "overflow-x" ]), { "flex-direction" : "row" , "overflow-x" : "auto" });
await s . page . setViewportSize ({ width : 1000 , height : 800 });
await s . page . waitForFunction (() => document . getElementById ( "prefs-tabs" ). getAttribute ( "aria-orientation" ) === "vertical" );
});
test ( "Set up preferences on the dashboard opens on Appearance with agents and models loaded" , async ( t ) => {
fs . mkdirSync ( HOME , { recursive : true });
fs . writeFileSync ( LOOKS_FILE , JSON . stringify ({ looks : { welcomeSeen : true } }));
t . after (() => fs . rmSync ( LOOKS_FILE , { force : true }));
const file = path . join ( MODELS_DIR , "agents.json" );
fs . mkdirSync ( MODELS_DIR , { recursive : true });
fs . writeFileSync ( file , JSON . stringify ({ schema : 1 , agents : [{ id : "goose" , name : "Goose" , command : "goose" }] }));
t . after (() => fs . rmSync ( file , { force : true }));
const s = await openSession ( await suite . browser (), {
t ,
workflow : "dashboard" ,
payload : { menu : { note : "Nothing yet." }, agent : { status : "waiting" } },
});
const skip = s . page . getByRole ( "button" , { name : "Skip the intro" });
await skip . click ();
await skip . waitFor ({ state : "hidden" });
await s . page . getByRole ( "button" , { name : "Set up preferences" }). click ();
await s . page . locator ( "#looks-modal[open]" ). waitFor ();
assert . equal ( await selectedTab ( s ), "prefs-tab-appearance" );
await s . page . click ( "#prefs-tab-agents" );
const goose = s . page . locator ( '#agents-table tr[data-key="agent:goose"]' );
await goose . waitFor ();
assert . match ( await textOf ( goose . locator ( ".prefs-agents-name" )), /^Goose/ );
assert . equal ( await s . page . locator ( '#agents-table tr[data-key="cli:claude"]' ). count (), 1 , "the built-ins are listed" );
assert . doesNotMatch ( await s . page . locator ( "#agents-status" ). innerText (), /could not be loaded/ );
});
test ( "Back to default resets only the tab on screen, and is hidden on Agents & models and System" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . click ( "#btn-looks" );
await s . page . locator ( 'input[name="looks-theme"][value="dark"]' ). check ();
await swatch ( s , "violet" ). click ();
await s . page . click ( "#prefs-tab-sounds" );
await s . page . locator ( "#looks-sound" ). uncheck ();
await s . page . locator ( "#looks-activities" ). uncheck ();
await s . page . click ( "#prefs-tab-agents" );
assert . equal ( await s . page . locator ( "#looks-reset" ). isHidden (), true , "hidden on Agents & models" );
await s . page . click ( "#prefs-tab-system" );
assert . equal ( await s . page . locator ( "#looks-reset" ). isHidden (), true , "hidden on System" );
await s . page . click ( "#prefs-tab-appearance" );
await s . page . click ( "#looks-reset" );
await s . page . waitForFunction (() => ! document . documentElement . hasAttribute ( "data-theme" ));
assert . equal ( await swatch ( s , "violet" ). getAttribute ( "aria-pressed" ), "false" );
await s . page . click ( "#prefs-tab-sounds" );
assert . equal ( await s . page . locator ( "#looks-sound" ). isChecked (), false , "Appearance's reset left sounds off" );
assert . equal ( await s . page . locator ( "#looks-activities" ). isChecked (), false );
await s . page . click ( "#prefs-tab-appearance" );
await s . page . locator ( 'input[name="looks-theme"][value="dark"]' ). check ();
await s . page . click ( "#prefs-tab-sounds" );
await s . page . click ( "#looks-reset" );
await s . page . locator ( "#looks-sound:checked" ). waitFor ();
assert . equal ( await s . page . locator ( "#looks-activities" ). isChecked (), true );
assert . equal ( await root ( s , "data-theme" ), "dark" , "the sounds reset left the dark theme" );
await s . page . waitForFunction ( async () => {
const saved = ( await ( await fetch ( "/looks" )). json ()). looks || {};
return saved . sound === true && saved . hideActivities === false && saved . theme === "dark" ;
});
});
test ( "a theme change shows Saved level with the Theme legend, outside the fieldset's grid" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . click ( "#btn-looks" );
await s . page . locator ( 'input[name="looks-theme"][value="light"]' ). check ();
const mark = s . page . locator ( 'fieldset[data-section="theme"] .prefs-saved' );
await mark . filter ({ hasText : "Saved" }). waitFor ();
assert . equal ( await mark . getAttribute ( "role" ), "status" );
// Out of the fieldset's grid: the three choices still share one row.
assert . equal ( await styleOf ( mark , "position" ), "absolute" );
const tops = await s . page . locator ( 'fieldset[data-section="theme"] label' ). evaluateAll (( ls ) => ls . map (( l ) => l . offsetTop ));
assert . equal ( new Set ( tops ). size , 1 , `the theme choices sit on one row: ${ tops } ` );
});
test ( "a save the server refuses shows its error in the Saved mark's place, until a save lands" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
let refuse = true ;
await s . page . route ( "**/looks" , ( route ) =>
refuse && route . request (). method () === "POST"
? route . fulfill ({ status : 500 , contentType : "application/json" , body : JSON . stringify ({ error : "Disk is full." }) })
: route . continue ()
);
await s . page . click ( "#btn-looks" );
await s . page . locator ( 'input[name="looks-theme"][value="dark"]' ). check ();
const mark = s . page . locator ( 'fieldset[data-section="theme"] .prefs-saved' );
await mark . filter ({ hasText : "Disk is full." }). waitFor ();
assert . equal ( await mark . evaluate (( m ) => m . classList . contains ( "error" )), true );
refuse = false ;
await s . page . locator ( 'input[name="looks-theme"][value="light"]' ). check ();
await mark . filter ({ hasText : "Saved" }). waitFor ();
assert . equal ( await mark . evaluate (( m ) => m . classList . contains ( "error" )), false , "the error clears once a save lands" );
});
test ( "a Preferences tab is named by its label alone, with the hint as its description" , async ( t ) => {
noSavedLooks ( t );
const s = await openSession ( await suite . browser (), { t , workflow : "plan" , payload : PLAN_QUESTION });
await s . page . click ( "#btn-looks" );
for ( const name of [ "Appearance" , "Agents & models" , "System" , "Sounds & activities" ]) {
assert . equal ( await s . page . getByRole ( "tab" , { name , exact : true }). count (), 1 , `a tab named ${ name } ` );
}
const tab = s . page . locator ( "#prefs-tab-system" );
assert . equal ( await textOf ( s . page . locator ( "#" + ( await tab . getAttribute ( "aria-describedby" )))), "Cleanup, desktop app" );
});
// Read from the Subagents dialog at 1000 px before Preferences moved to tabs:
// it borrows Preferences' .looks classes, and must not change with them.
const SUBAGENTS_BEFORE = {
modal : { "max-width" : "none" , width : "900px" },
row : { display : "grid" , "grid-template-columns" : "repeat(2, minmax(0px, 1fr))" , "margin-top" : "0px" },
second : { "margin-top" : "0px" },
actions : { display : "flex" , "justify-content" : "flex-end" },
};
test ( "the Subagents dialog looks as it did before Preferences moved to tabs" , async ( t ) => {
const s = await openSession ( await suite . browser (), { t , workflow : "implement" , payload : { agent : { status : "working" , activity : "Task 1 of 2" } } });
await s . page . setViewportSize ({ width : 1000 , height : 800 });
const modal = s . page . locator ( "#subagents-modal" );
await s . page . locator ( "#btn-subagents" ). click ();
await modal . waitFor ();
const got = {
modal : await stylesOf ( modal , [ "max-width" , "width" ]),
row : await stylesOf ( modal . locator ( "fieldset.looks-row" ). first (), [ "display" , "grid-template-columns" , "margin-top" ]),
second : await stylesOf ( modal . locator ( "fieldset.modal-ranges" ). nth ( 1 ), [ "margin-top" ]),
actions : await stylesOf ( modal . locator ( ".modal-actions" ), [ "display" , "justify-content" ]),
};
if ( process . env . P2C_PRINT_SUBAGENTS ) console . log ( "SUBAGENTS " + JSON . stringify ( got ));
assert . deepEqual ( got , SUBAGENTS_BEFORE );
});