Add the agent-less setup page, a shared agent list and the split Agents & models tab

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-03 04:08:27 -08:00
1 parent c122332657
commit 33f1783979
55 files changed
+5453 -1345

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
{
"$comment": "The one agent lookup rule (src/web-console/agent-lookup.mjs findAgent) as cases both the Node suite (scripts/test-agent-lookup.mjs) and cargo test load. Each case makes temp folders named under `dirs` (a list of file names per folder), then calls findAgent(entry, env): `{name}` in env values, installDirs and `folder` expands to that folder's path. env: path, savedPath, npmBin, pathext, platform, home, vars (for %NAME% expansion). state is found | outside | missing; where is path | saved-path | npm | install-dir | null; file names the hit the found path must end with (null when missing).",
"cases": [
{
"name": "found on PATH",
"platform": "linux",
"entry": { "command": "goose", "installDirs": { "linux": ["{install}"] } },
"dirs": { "bin": ["goose"], "install": [] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "", "pathext": "", "home": "{home}" },
"state": "found",
"where": "path",
"folder": "{bin}",
"file": "goose"
},
{
"name": "found on Windows PATH through PATHEXT (.cmd)",
"platform": "win",
"entry": { "command": "goose" },
"dirs": { "bin": ["goose.cmd"] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "", "pathext": ".EXE;.CMD;.BAT" },
"state": "found",
"where": "path",
"folder": "{bin}",
"file": "goose.cmd"
},
{
"name": "found on Windows PATH through PATHEXT (.exe)",
"platform": "win",
"entry": { "command": "goose" },
"dirs": { "bin": ["goose.exe"] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "", "pathext": ".EXE;.CMD;.BAT" },
"state": "found",
"where": "path",
"folder": "{bin}",
"file": "goose.exe"
},
{
"name": "found only on the saved Windows PATH is outside",
"platform": "win",
"entry": { "command": "goose" },
"dirs": { "saved": ["goose.cmd"] },
"env": { "path": "{bin}", "savedPath": "{saved}", "npmBin": "", "pathext": ".EXE;.CMD;.BAT" },
"state": "outside",
"where": "saved-path",
"folder": "{saved}",
"file": "goose.cmd"
},
{
"name": "found only in npm's global folder is outside",
"platform": "linux",
"entry": { "command": "goose" },
"dirs": { "npm": ["goose"] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "{npm}", "pathext": "" },
"state": "outside",
"where": "npm",
"folder": "{npm}",
"file": "goose"
},
{
"name": "found only in an install folder is outside",
"platform": "linux",
"entry": { "command": "goose", "installDirs": { "linux": ["{install}"] } },
"dirs": { "install": ["goose"] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "{npm}", "pathext": "" },
"state": "outside",
"where": "install-dir",
"folder": "{install}",
"file": "goose"
},
{
"name": "an install folder with ~ expands against home",
"platform": "linux",
"entry": { "command": "goose", "installDirs": { "linux": ["~/toolbin"] } },
"dirs": { "home": ["toolbin/goose"] },
"env": { "path": "", "savedPath": "", "npmBin": "", "pathext": "", "home": "{home}" },
"state": "outside",
"where": "install-dir",
"folder": "{home}/toolbin",
"file": "goose"
},
{
"name": "an install folder with %NAME% expands against vars",
"platform": "win",
"entry": { "command": "goose", "installDirs": { "win": ["%TOOLS%\\bin"] } },
"dirs": { "tools": ["bin/goose.exe"] },
"env": { "path": "", "savedPath": "", "npmBin": "", "pathext": ".EXE;.CMD", "vars": { "TOOLS": "{tools}" } },
"state": "outside",
"where": "install-dir",
"folder": "{tools}/bin",
"file": "goose.exe"
},
{
"name": "a command carrying its own extension is tried as written",
"platform": "win",
"entry": { "command": "goose.cmd" },
"dirs": { "bin": ["goose.cmd"] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "", "pathext": ".EXE;.CMD;.BAT" },
"state": "found",
"where": "path",
"folder": "{bin}",
"file": "goose.cmd"
},
{
"name": "not found anywhere is missing",
"platform": "linux",
"entry": { "command": "goose", "installDirs": { "linux": ["{install}"] } },
"dirs": { "bin": [], "install": [] },
"env": { "path": "{bin}", "savedPath": "", "npmBin": "", "pathext": "" },
"state": "missing",
"where": null,
"folder": null,
"file": null
},
{
"name": "a command written as a full path is checked as a file",
"platform": "linux",
"entry": { "command": "{bin}/goose" },
"dirs": { "bin": ["goose"] },
"env": { "path": "", "savedPath": "", "npmBin": "", "pathext": "" },
"state": "found",
"where": "path",
"folder": "{bin}",
"file": "goose"
},
{
"name": "a PATH entry with a space still finds the command",
"platform": "linux",
"entry": { "command": "goose" },
"dirs": { "with space": ["goose"] },
"env": { "path": "{with space}", "savedPath": "", "npmBin": "", "pathext": "" },
"state": "found",
"where": "path",
"folder": "{with space}",
"file": "goose"
},
{
"name": "PATH wins over the saved PATH and npm",
"platform": "win",
"entry": { "command": "goose" },
"dirs": { "bin": ["goose.exe"], "saved": ["goose.exe"], "npm": ["goose.exe"] },
"env": { "path": "{bin}", "savedPath": "{saved}", "npmBin": "{npm}", "pathext": ".EXE;.CMD;.BAT" },
"state": "found",
"where": "path",
"folder": "{bin}",
"file": "goose.exe"
},
{
"name": "the saved PATH wins over npm and install folders",
"platform": "win",
"entry": { "command": "goose", "installDirs": { "win": ["{install}"] } },
"dirs": { "saved": ["goose.exe"], "npm": ["goose.exe"], "install": ["goose.exe"] },
"env": { "path": "", "savedPath": "{saved}", "npmBin": "{npm}", "pathext": ".EXE;.CMD;.BAT" },
"state": "outside",
"where": "saved-path",
"folder": "{saved}",
"file": "goose.exe"
},
{
"name": "npm wins over install folders",
"platform": "linux",
"entry": { "command": "goose", "installDirs": { "linux": ["{install}"] } },
"dirs": { "npm": ["goose"], "install": ["goose"] },
"env": { "path": "", "savedPath": "", "npmBin": "{npm}", "pathext": "" },
"state": "outside",
"where": "npm",
"folder": "{npm}",
"file": "goose"
}
]
}
+224 -1
View File
@@ -1,5 +1,5 @@
{
"$comment": "The rules of ~/.plan2code/agents.json (PLAN-DRAFT 4.4) as cases every reader's tests load: the console (src/web-console/agents.mjs), the launcher and the desktop app. files: `raw` is the file's text (null: no file); `warnings` lists substrings, each found in some warning, and an empty list means no warnings at all; entries are named agents[i], 0-based. buildArgs: `options` as passed (a missing prompt means the entry's own). ids: makeId(input, taken).",
"$comment": "The rules of ~/.plan2code/agents.json (PLAN-DRAFT 4.4) as cases every reader's tests load: the console (src/web-console/agents.mjs), the launcher and the desktop app. files: `raw` is the file's text (null: no file); `warnings` lists substrings, each found in some warning, and an empty list means no warnings at all; entries are named agents[i], 0-based. buildArgs: `options` as passed (a missing prompt means the entry's own); an argument exactly `{bypass}` or `{model}` expands to bypassArgs / modelArgs in place and suppresses the end-append for that flag. ids: makeId(input, taken).",
"files": [
{
"name": "no file",
@@ -1637,6 +1637,229 @@
"--yes-always"
]
},
{
"name": "{bypass} expands to bypassArgs in place when on",
"entry": {
"id": "devin",
"name": "Devin",
"command": "devin",
"args": [
"{bypass}",
"--",
"{prompt}"
],
"prompt": "/plan2code",
"bypassArgs": [
"--permission-mode",
"bypass"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"bypass": true
},
"args": [
"--permission-mode",
"bypass",
"--",
"/plan2code"
]
},
{
"name": "{bypass} drops out when off",
"entry": {
"id": "devin",
"name": "Devin",
"command": "devin",
"args": [
"{bypass}",
"--",
"{prompt}"
],
"prompt": "/plan2code",
"bypassArgs": [
"--permission-mode",
"bypass"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"bypass": false
},
"args": [
"--",
"/plan2code"
]
},
{
"name": "{model} expands to modelArgs in place when chosen",
"entry": {
"id": "devin",
"name": "Devin",
"command": "devin",
"args": [
"{model}",
"--",
"{prompt}"
],
"prompt": "/plan2code",
"bypassArgs": [
"--permission-mode",
"bypass"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"model": "opus",
"bypass": false
},
"args": [
"--model",
"opus",
"--",
"/plan2code"
]
},
{
"name": "{model} drops out with no model chosen",
"entry": {
"id": "devin",
"name": "Devin",
"command": "devin",
"args": [
"{model}",
"--",
"{prompt}"
],
"prompt": "/plan2code",
"bypassArgs": [
"--permission-mode",
"bypass"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"bypass": false
},
"args": [
"--",
"/plan2code"
]
},
{
"name": "Devin's shape: bypass and model ahead of the -- and the prompt",
"entry": {
"id": "devin",
"name": "Devin",
"command": "devin",
"args": [
"{bypass}",
"{model}",
"--",
"{prompt}"
],
"prompt": "/plan2code",
"bypassArgs": [
"--permission-mode",
"bypass"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"model": "swe-2-high",
"bypass": true
},
"args": [
"--permission-mode",
"bypass",
"--model",
"swe-2-high",
"--",
"/plan2code"
]
},
{
"name": "Codex's shape: bypass then model then the $-prompt",
"entry": {
"id": "codex",
"name": "Codex",
"command": "codex",
"args": [
"{bypass}",
"{model}",
"{prompt}"
],
"prompt": "$plan2code",
"bypassArgs": [
"--dangerously-bypass-approvals-and-sandbox"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"model": "gpt-5",
"bypass": true
},
"args": [
"--dangerously-bypass-approvals-and-sandbox",
"--model",
"gpt-5",
"$plan2code"
]
},
{
"name": "an entry holding neither placeholder keeps the appended order",
"entry": {
"id": "aider",
"name": "Aider",
"command": "aider",
"args": [
"{prompt}"
],
"prompt": "/plan2code",
"bypassArgs": [
"--yes-always"
],
"modelArgs": [
"--model",
"{model}"
],
"models": []
},
"options": {
"model": "sonnet",
"bypass": true
},
"args": [
"/plan2code",
"--model",
"sonnet",
"--yes-always"
]
},
{
"name": "placeholders are replaced as plain text",
"entry": {
+126
View File
@@ -0,0 +1,126 @@
// The one agent lookup rule (src/web-console/agent-lookup.mjs) against the
// shared cases every reader's tests load (scripts/fixtures/agent-lookup-cases.json),
// plus loadAgentList()'s file handling and the shipped src/launcher/agents.json.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { findAgent, loadAgentList } from "../src/web-console/agent-lookup.mjs";
import { normalizeAgents } from "../src/web-console/agents.mjs";
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const CASES = JSON.parse(fs.readFileSync(path.join(ROOT, "scripts", "fixtures", "agent-lookup-cases.json"), "utf8"));
// The .cmd cases check a shim's lookup; cmd's own current-folder rule must not
// color a temp-folder stat, so the switch is cleared for the whole suite.
const savedSwitch = process.env.NoDefaultCurrentDirectoryInExePath;
delete process.env.NoDefaultCurrentDirectoryInExePath;
/**
* The folders a case names, as real temp dirs with its files inside.
* `{name}` in a value expands to that folder's path.
*/
function stage(t, c) {
const base = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-lookup-"));
t.after(() => fs.rmSync(base, { recursive: true, force: true }));
const dirs = {};
for (const [name, files] of Object.entries(c.dirs || {})) {
const dir = path.join(base, name);
dirs[name] = dir;
for (const file of files) {
const target = path.join(dir, file);
fs.mkdirSync(path.dirname(target), { recursive: true });
fs.writeFileSync(target, "");
}
if (!files.length) fs.mkdirSync(dir, { recursive: true });
}
const fill = (value) =>
typeof value === "string"
? value.replace(/\{([^}]+)\}/g, (whole, name) => {
if (!(name in dirs)) {
const dir = path.join(base, name);
dirs[name] = dir;
return dir;
}
return dirs[name];
})
: value;
const env = {};
for (const [key, value] of Object.entries(c.env || {})) {
env[key] = value && typeof value === "object" ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, fill(v)])) : fill(value);
}
env.platform = c.platform;
const entry = JSON.parse(JSON.stringify(c.entry || {}), (key, value) => (typeof value === "string" ? fill(value) : value));
return { entry, env, fill };
}
for (const c of CASES.cases) {
test(`findAgent: ${c.name}`, (t) => {
const { entry, env, fill } = stage(t, c);
const got = findAgent(entry, env);
assert.equal(got.state, c.state, `state: ${JSON.stringify(got)}`);
assert.equal(got.where, c.where, `where: ${JSON.stringify(got)}`);
if (c.state === "missing") {
assert.equal(got.path, null);
assert.equal(got.folder, null);
return;
}
assert.ok(got.path && fs.statSync(got.path).isFile(), `path is a real file: ${JSON.stringify(got)}`);
if (c.file) assert.equal(path.basename(got.path), c.file);
if (c.folder) {
const want = path.normalize(fill(c.folder));
assert.equal(path.normalize(got.folder), want, `folder: ${JSON.stringify(got)}`);
}
});
}
test("the fixture covers every case it promises", () => {
const names = CASES.cases.map((c) => c.name);
for (const word of ["PATH", "PATHEXT", "saved", "npm", "install", "missing", "full path", "space"]) {
assert.ok(names.some((n) => n.includes(word)), `a case names ${word}`);
}
});
/* ------------------------------------------------------- loadAgentList */
function listDir(t, contents) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-agentlist-"));
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
if (contents !== undefined) fs.writeFileSync(path.join(dir, "agents.json"), contents);
return dir;
}
test("loadAgentList: a missing file gives empty lists and a warning, never a throw", (t) => {
const { builtins, templates, warnings } = loadAgentList({ dir: listDir(t) });
assert.deepEqual(builtins, []);
assert.deepEqual(templates, []);
assert.equal(warnings.length, 1);
assert.match(warnings[0], /missing/);
});
test("loadAgentList: bad JSON and a wrong schema warn and give nothing", (t) => {
const bad = loadAgentList({ dir: listDir(t, "{ nope") });
assert.deepEqual([bad.builtins, bad.templates], [[], []]);
assert.match(bad.warnings[0], /not valid JSON/);
const wrong = loadAgentList({ dir: listDir(t, JSON.stringify({ schema: 2, agents: [] })) });
assert.deepEqual([wrong.builtins, wrong.templates], [[], []]);
assert.match(wrong.warnings[0], /schema/);
});
test("loadAgentList: the shipped agents.json loads with 3 built-ins and 4 templates", () => {
const { builtins, templates, warnings } = loadAgentList({ dir: path.join(ROOT, "src", "launcher") });
assert.deepEqual(warnings, []);
assert.deepEqual(builtins.map((a) => a.id), ["claude", "devin", "codex"]);
assert.deepEqual(templates.map((a) => a.id), ["copilot", "opencode", "gemini", "pi"]);
});
test("every shipped template passes normalizeAgents() with no warnings", () => {
const { templates } = loadAgentList({ dir: path.join(ROOT, "src", "launcher") });
const { agents, warnings } = normalizeAgents(JSON.stringify({ schema: 1, agents: templates }));
assert.deepEqual(warnings, []);
assert.equal(agents.length, templates.length);
});
+13
View File
@@ -371,3 +371,16 @@ test("framed, an Activities game in full screen asks the app for the whole scree
await until(async () => (await told()).at(-1) === false, 5000);
assert.deepEqual(await told(), [true, false, true, false, true, false], "and so does a new question");
});
test("framed, the setup page's agent-found names the agent; unframed it says nothing", async (t) => {
const browser = await pages.browser();
const s = await openSession(browser, { t, workflow: "setup", env: { PLAN2CODE_IN_APP: "1" }, init: FAKE_APP_FRAME });
await s.page.evaluate(() => import("/app-bridge.js").then((m) => m.agentFound("claude")));
assert.deepEqual(await toApp(s, "agent-found"), [{ plan2code: "agent-found", id: "claude" }], "a named request with the found id");
const plain = await openSession(browser, { t, workflow: "setup" });
const unframed = await plain.page.evaluate(() =>
import("/app-bridge.js").then((m) => { m.agentFound("devin"); return m.framed(); })
);
assert.equal(unframed, false, "outside the app the message goes nowhere and does not throw");
});
+1 -1
View File
@@ -553,7 +553,7 @@ test("agents: no file is an empty list, a save is written whole and keeps unknow
fs.rmSync(file, { force: true });
const get = async () => (await fetch(baseUrl + "/agents", { headers: { cookie: cookieFor(baseUrl, token) } })).json();
assert.deepEqual(await get(), { agents: [], warnings: [] }, "no file");
assert.deepEqual(await get(), { agents: [], warnings: [], builtins: [], templates: [] }, "no file");
fs.mkdirSync(MODELS_DIR, { recursive: true });
fs.writeFileSync(file, "{ \"schema\": 1, \"agents\": [");
const broken = await get();
+80 -38
View File
@@ -85,19 +85,27 @@ test("the violet highlight and dark theme chosen in preferences stick across a r
assert.deepEqual(await firstPaintAttrs(s), { theme: null, accent: null }, "the first paint still carries the old looks");
});
// The Agents & models tab: the summary table, its rows and the form Edit opens.
// The Agents & models tab: the split's row list, its rows and the pane the
// pick opens the form in (the list stays on screen; there is no back page).
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 agentRow = (s, key) => agentsTable(s).locator(`.split-row[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 formPane = (s) => agentForm(s).locator(".prefs-agents-fields");
const unsavedPrompt = (s) => s.page.locator("#prefs-unsaved");
async function openAgentsTab(s) {
// The dialog's DOM survives a close, so the row, a stale form and even a
// stale empty pane can match before load() resolves. Wait on the fetch
// itself first; the empty pane only draws once it has.
const loaded = s.page.waitForResponse((r) => r.url().endsWith("/agents"));
await s.page.click("#btn-looks");
await s.page.click("#prefs-tab-agents");
await loaded;
await agentRow(s, "cli:claude").waitFor();
await agentForm(s).locator(".split-empty").waitFor();
}
// agents.json as the test starts it: none, or the entries given. Removed after.
@@ -117,41 +125,41 @@ test("Agents & models: the table lists Claude, Devin and Codex, and a model id t
t.after(() => fs.rmSync(path.join(MODELS_DIR, "models.json"), { force: true }));
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await openAgentsTab(s);
const keys = await agentsTable(s).locator("tbody tr[data-key]").evaluateAll((rows) => rows.map((r) => r.dataset.key));
const keys = await agentsTable(s).locator(".split-row[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");
assert.equal(await textOf(agentRow(s, "cli:codex").locator(".row-name")), "Codex");
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 formPane(s).waitFor();
assert.equal(await agentRow(s, "cli:codex").getAttribute("aria-current"), "true", "the picked row is marked; the list stays beside the form");
await agentForm(s).locator(".prefs-agents-none").filter({ hasText: /^No models ship for Codex yet/ }).waitFor();
assert.equal(await agentForm(s).locator(".models-row.locked").count(), 0, "nothing comes with Plan2Code for Codex");
await formButton(s, "Add a model").click();
const id = formField(s, "Model id");
await id.fill("gpt-test-codex-1");
await id.press("Tab");
await s.page.waitForTimeout(300);
await formField(s, "Model id").fill("gpt-test-codex-1");
await formButton(s, "Add a model").click();
await formField(s, "Model id").nth(1).fill("gpt-test-codex-2");
// Remove drops the row from the draft; it still reaches the file only on Save.
await agentForm(s).locator(".agent-row.model").first().getByRole("button", { name: "Remove" }).click();
assert.equal(await agentForm(s).locator(".agent-row.model").count(), 1, "the removed row is gone");
await agentForm(s).locator(".prefs-unsaved-badge").waitFor();
const before = await s.page.evaluate(async () => (await (await fetch("/models")).json()).user);
assert.deepEqual(before.codex, [], "nothing is saved before Save");
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), true);
await formButton(s, "Save").click();
await agentForm(s).locator(".prefs-saved").filter({ hasText: /^Saved\. Restart plan2code/ }).waitFor();
const saved = await s.page.evaluate(async () => (await (await fetch("/models")).json()).user);
assert.deepEqual(saved.codex.map((m) => m.id), ["gpt-test-codex-1"], "the id was not saved under Codex");
assert.deepEqual(saved.codex.map((m) => m.id), ["gpt-test-codex-2"], "only the kept model was saved under Codex");
assert.deepEqual([saved.claude, saved.devin], [[], []], "the id leaked into another agent's menu");
assert.equal(await agentForm(s).locator(".prefs-unsaved-badge").isVisible(), false, "saved, nothing is unsaved");
// 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$/);
assert.match(await textOf(agentRow(s, "cli:codex").locator(".row-models")), /^1: gpt-test-codex-2$/);
await s.page.reload({ waitUntil: "domcontentloaded" });
await drawn(s.page);
await openAgentsTab(s);
await s.page.getByRole("button", { name: "Edit Codex" }).click();
assert.equal(await formField(s, "Model id").inputValue(), "gpt-test-codex-1");
assert.equal(await formField(s, "Model id").inputValue(), "gpt-test-codex-2");
});
test("Agents & models: a person adds an agent, tests its command, sees it after a reload, and deletes it", async (t) => {
@@ -159,10 +167,10 @@ test("Agents & models: a person adds an agent, tests its command, sees it after
seedAgents(t);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await openAgentsTab(s);
assert.equal(await agentsTable(s).locator('tr[data-key^="agent:"]').count(), 0, "no agents before one is added");
assert.equal(await agentsTable(s).locator('.split-row[data-key^="agent:"]').count(), 0, "no agents before one is added");
await s.page.click("#agents-add");
await agentForm(s).waitFor();
await formPane(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");
@@ -189,12 +197,13 @@ test("Agents & models: a person adds an agent, tests its command, sees it after
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);
await row.waitFor({ state: "detached" });
assert.equal(await agentsTable(s).locator('.split-row[data-key^="agent:"]').count(), 0);
assert.deepEqual(JSON.parse(fs.readFileSync(AGENTS_FILE, "utf8")).agents, []);
assert.equal(await s.page.evaluate(() => document.activeElement?.getAttribute("aria-label") || document.activeElement?.id), "agents-add", "with its row gone, focus goes to Add agent");
assert.equal(await textOf(s.page.locator("#agents-status")), "Deleted.");
await s.page.click("#agents-add");
await formPane(s).waitFor();
assert.equal(await s.page.locator("#agents-status").innerText(), "", "opening a form clears Deleted.");
});
@@ -240,6 +249,7 @@ test("Agents & models: a file holding entries the page could not read is only re
await s.page.locator("#agents-status").filter({ hasText: /schema 2/ }).waitFor();
await s.page.click("#agents-add");
await formPane(s).waitFor();
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");
@@ -281,16 +291,17 @@ test("Agents & models: a discarded edit never rides along with another agent's S
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();
// Picking another row is the way out of a form; a dirty draft asks first.
await s.page.getByRole("button", { name: "Edit Beta" }).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();
await unsavedPrompt(s).waitFor({ state: "hidden" });
await formPane(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");
assert.equal(await textOf(agentForm(s).locator(".prefs-agents-title")), "Beta", "the pick the prompt asked about carries on");
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();
@@ -298,18 +309,20 @@ test("Agents & models: a discarded edit never rides along with another agent's S
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) => {
test("Agents & models: an unsaved edit asks first on a row pick, 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();
if (!(await agentForm(s).locator(".prefs-agents-title").filter({ hasText: "Alpha" }).count())) {
await s.page.getByRole("button", { name: "Edit Alpha" }).click();
}
await formField(s, "Command").fill(command);
};
const triggers = {
back: () => formButton(s, "Back to summary").click(),
row: () => s.page.getByRole("button", { name: "Edit Beta" }).click(),
close: () => s.page.click("#looks-done"),
esc: () => formField(s, "Command").press("Escape"),
backdrop: () => s.page.mouse.click(4, 4),
@@ -376,24 +389,53 @@ test("Agents & models: a command not on PATH is marked, and the orchestrator row
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");
const soon = agentsTable(s).locator(".split-row.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) => {
test("Agents & models: below 720 px the split stacks 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}`);
const cols = await styleOf(s.page.locator("#agents-split"), "grid-template-columns");
assert.equal(cols.trim().split(/\s+/).length, 1, `the split stacks: ${cols}`);
assert.equal(await styleOf(s.page.locator("#agents-table"), "overflow-y"), "auto", "the row list scrolls");
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}`);
const fields = await styleOf(agentForm(s).locator(".prefs-agents-fields"), "grid-template-columns");
assert.equal(fields.trim().split(/\s+/).length, 1, `one column: ${fields}`);
});
// The shipped bin/agents.json beside the user file: where starter templates
// come from. Removed after so the next test's list has none.
const SHIPPED_AGENTS_FILE = path.join(MODELS_DIR, "bin", "agents.json");
function seedShipped(t, agents) {
fs.mkdirSync(path.dirname(SHIPPED_AGENTS_FILE), { recursive: true });
fs.writeFileSync(SHIPPED_AGENTS_FILE, JSON.stringify({ schema: 1, agents }));
t.after(() => fs.rmSync(SHIPPED_AGENTS_FILE, { force: true }));
}
test("Agents & models: shipped templates offer a prefilled new-agent form", async (t) => {
noSavedLooks(t);
seedAgents(t);
seedShipped(t, [
{ id: "templar", name: "Templar", kind: "template", command: "templar", prompt: "/plan2code", args: ["{prompt}"], note: "A starter agent." },
]);
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await openAgentsTab(s);
await agentsTable(s).locator(".split-list-head", { hasText: "Or start from a template" }).waitFor();
const row = agentRow(s, "setup:Templar");
assert.match(await textOf(row), /Templar\s+templar/);
await row.click();
const use = agentForm(s).getByRole("button", { name: "Use this template", exact: true });
await use.waitFor();
assert.match(await textOf(agentForm(s)), /A starter agent\./);
await use.click();
await formPane(s).waitFor();
assert.equal(await formField(s, "Name").inputValue(), "Templar");
assert.equal(await formField(s, "Command").inputValue(), "templar");
});
test("Cleanup scans the console home and lists an old session folder with its size", async (t) => {
@@ -517,10 +559,10 @@ test("Set up preferences on the dashboard opens on Appearance with agents and mo
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"]');
const goose = s.page.locator('#agents-table .split-row[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.match(await textOf(goose.locator(".row-name")), /^Goose/);
assert.equal(await s.page.locator('#agents-table .split-row[data-key="cli:claude"]').count(), 1, "the built-ins are listed");
assert.doesNotMatch(await s.page.locator("#agents-status").innerText(), /could not be loaded/);
});
+402
View File
@@ -0,0 +1,402 @@
// Page tests for the agent-less setup page (`console.mjs open --workflow
// setup`, with or without --for-cli): the three found states and their way
// forward, the forCli ordering, Check again, Use it from here, a template
// becoming a custom agent, Start and its grace line, the /handover move, and
// the quiet chrome an agent-less session keeps. Run with:
// node --test scripts/test-web-console-page-setup.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. The found states are deterministic: a shipped agents.json
// written under MODELS_DIR/bin before the server starts, fake .cmd files (one
// file name is found on every OS), PATH pointed at a fixture dir, npm's
// global folder at an empty prefix and the saved Windows PATH switched off.
// That is the same recipe test-web-console-server.mjs's agentFixtures() uses.
//
// The page is the agents view's "setup" mount (agents-view.js on
// .setup-agents), a master-detail split: button.split-row[data-key] rows in
// [data-av="table"] on the left, the picked row's state and way forward
// (Start, Use it from here, the install lines, a template's Use) drawn as
// .setup-detail in [data-av="form"] on the right after the row is clicked.
// Row badges are drawn on first load; everything actionable wants the click.
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test from "node:test";
import assert from "node:assert/strict";
import { pageSuite, openSession, tempProject, textOf } from "./page-test-helpers.mjs";
import { cli, sessionUrl, readState, until, MODELS_DIR } from "./web-console-test-helpers.mjs";
const suite = pageSuite(test);
// The desktop-app markers a spawned console must never carry into these
// tests: test-web-console-server.mjs's NO_APP, plus the setup hand-over pair,
// which would turn a plain `open` into a hand-over of its own.
const NO_APP = {
PLAN2CODE_IN_APP: undefined,
PLAN2CODE_APP_TOKEN: undefined,
PLAN2CODE_APP_ANNOUNCE: undefined,
PLAN2CODE_EMBED_ORIGIN: undefined,
PLAN2CODE_CONSOLE_SID: undefined,
PLAN2CODE_APP_VERSION: undefined,
PLAN2CODE_SETUP_ANNOUNCE: undefined,
PLAN2CODE_SETUP_TOKEN: undefined,
};
const PATH_KEY = Object.keys(process.env).find((k) => k.toUpperCase() === "PATH") || "PATH";
const OS_KEY = process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux";
const SHIPPED_FILE = path.join(MODELS_DIR, "bin", "agents.json");
const USER_AGENTS_FILE = path.join(MODELS_DIR, "agents.json");
// The missing builtin's install lines, one list per OS; the server serves
// only this OS's. Windows carries a note so that part of the row is checked.
const INSTALL = {
win: [{ label: "PowerShell", run: "irm https://example.com/gone | iex", note: "Run it in an elevated shell." }],
mac: [{ label: "Terminal", run: "brew install gone-agent" }],
linux: [{ label: "Terminal", run: "apt install gone-agent" }],
};
// Fake commands and a shipped list that put one builtin in each state: two on
// PATH (for the --for-cli ordering), one only in its installDirs, one
// nowhere. `npmCommands` are bare names dropped into the fake npm global bin,
// where a custom agent's command reads as "outside". Everything is written
// before the session's server starts, and removed after the test.
function agentFixtures(t, { userAgents = [], npmCommands = [] } = {}) {
const base = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-setup-"));
const onPath = path.join(base, "onpath");
const outside = path.join(base, "outside");
const npmPrefix = path.join(base, "npm-prefix");
const npmBin = process.platform === "win32" ? npmPrefix : path.join(npmPrefix, "bin");
fs.mkdirSync(onPath, { recursive: true });
fs.mkdirSync(outside, { recursive: true });
fs.mkdirSync(npmBin, { recursive: true });
fs.writeFileSync(path.join(onPath, "found-one.cmd"), "@rem stand-in\r\n");
fs.writeFileSync(path.join(onPath, "found-two.cmd"), "@rem stand-in\r\n");
fs.writeFileSync(path.join(outside, "outer.cmd"), "@rem stand-in\r\n");
for (const name of npmCommands) fs.writeFileSync(path.join(npmBin, name), "@rem stand-in\r\n");
// The template's command is a path, so the agent its Save writes finds a file.
const templar = path.join(base, "templar.cmd");
fs.writeFileSync(templar, "@rem stand-in\r\n");
const shipped = {
schema: 1,
agents: [
{ id: "found-one", name: "Found One", kind: "builtin", command: "found-one.cmd" },
{ id: "found-two", name: "Found Two", kind: "builtin", command: "found-two.cmd" },
{
id: "outer",
name: "Outer Agent",
kind: "builtin",
command: "outer.cmd",
installDirs: { win: [outside], mac: [outside], linux: [outside] },
},
{
id: "gone",
name: "Gone Agent",
kind: "builtin",
command: "p2c-gone-xyz.cmd",
installUrl: "https://example.com/gone",
install: INSTALL,
},
{
id: "templar",
name: "Templar",
kind: "template",
command: templar,
prompt: "/plan2code",
args: ["{prompt}"],
note: "A starter agent.",
},
],
};
fs.mkdirSync(path.dirname(SHIPPED_FILE), { recursive: true });
fs.writeFileSync(SHIPPED_FILE, JSON.stringify(shipped));
if (userAgents.length) {
fs.writeFileSync(USER_AGENTS_FILE, JSON.stringify({ schema: 1, agents: userAgents }));
} else {
fs.rmSync(USER_AGENTS_FILE, { force: true });
}
t.after(() => {
fs.rmSync(SHIPPED_FILE, { force: true });
fs.rmSync(USER_AGENTS_FILE, { force: true });
fs.rmSync(base, { recursive: true, force: true });
});
const env = {
...NO_APP,
PLAN2CODE_NO_SAVED_PATH: "1",
npm_config_prefix: npmPrefix,
[PATH_KEY]: onPath + path.delimiter + (process.env[PATH_KEY] || ""),
};
return { base, onPath, outside, npmBin, templar, env };
}
// The split's left column and the detail pane. Rows are found by data-key
// ("setup:<id>" for builtins and custom agents, "setup:<template name>" for
// templates) rather than by name: a custom agent saved from a template shares
// the template's name, and only the key keeps them apart.
const table = (s) => s.page.locator('.setup-agents [data-av="table"]');
const rowByKey = (s, key) => table(s).locator(`button.split-row[data-key="setup:${key}"]`);
const pane = (s) => s.page.locator('.setup-agents [data-av="form"]');
const detail = (s) => pane(s).locator(".setup-detail");
const button = (s, name) => s.page.getByRole("button", { name, exact: true });
const checkAgain = (s) => s.page.locator(".setup-actions").getByRole("button", { name: "Check again", exact: true });
// Click a row and wait for the pane to draw that entry's .setup-detail: the
// .prefs-agents-title names the picked agent or template.
async function pick(s, key, name) {
await rowByKey(s, key).click();
const d = detail(s);
await d.locator(".prefs-agents-title").getByText(name, { exact: true }).waitFor();
return d;
}
test("the setup page renders found, outside and missing rows with their way forward", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
await s.page.locator(".setup-screen h2", { hasText: "No agent yet" }).waitFor();
assert.equal(await s.page.locator('.setup-stage [data-pose="setup"]').count(), 1, "Planny's setup pose");
await rowByKey(s, "gone").waitFor();
assert.equal(await s.page.locator('.setup-agents [data-av="intro"]').count(), 1, "the intro line");
assert.equal(await s.page.locator(".setup-agents .split").count(), 1, "the split layout");
assert.equal(await s.page.locator('.setup-agents [data-av="status"]').count(), 1, "the status line");
assert.equal(await table(s).locator("button.split-row").count(), 5, "the four builtin rows and the template");
// Nothing picked yet: the pane shows the empty text, and the row badges are
// already drawn with each entry's state.
assert.equal(await pane(s).locator(".split-empty").count(), 1, "the pane's empty text before a pick");
assert.equal(await rowByKey(s, "found-one").locator(".prefs-badge.ok").count(), 1);
assert.equal(await textOf(rowByKey(s, "found-one").locator(".prefs-badge")), "Found");
assert.equal(await textOf(rowByKey(s, "outer").locator(".prefs-badge")), "Found outside PATH");
assert.equal(await textOf(rowByKey(s, "gone").locator(".prefs-badge")), "Not found");
// On PATH: the Found badge, the resolved path, and Start.
const one = await pick(s, "found-one", "Found One");
assert.match(await textOf(one.locator(".setup-agent-line")), /found-one\.cmd/, "the resolved path");
assert.equal(await one.getByRole("button", { name: "Start with this agent", exact: true }).count(), 1);
// In an install dir but not on PATH: where it is, Use it from here, a PATH note.
const outer = await pick(s, "outer", "Outer Agent");
assert.equal(await textOf(outer.locator(".setup-agent-line .prefs-badge")), "Found outside PATH");
assert.match(await textOf(outer.locator(".setup-agent-line")), /Found at .+outer\.cmd, but not on PATH/);
assert.equal(await outer.getByRole("button", { name: "Use it from here", exact: true }).count(), 1);
assert.match(await textOf(outer.locator("p.help")), /add its folder to (your )?PATH/, "the do-it-yourself PATH note");
// Nowhere: the install lines with Copy buttons, and the Install page link.
const gone = await pick(s, "gone", "Gone Agent");
assert.equal(await textOf(gone.locator(".prefs-badge")), "Not found");
const steps = gone.locator(".setup-install");
const want = INSTALL[OS_KEY];
assert.equal(await steps.count(), want.length, "this OS's install lines");
for (const [i, step] of want.entries()) {
const d = steps.nth(i);
assert.equal(await textOf(d.locator("span").first()), step.label);
assert.equal(await textOf(d.locator("code")), step.run);
if (step.note) assert.ok((await textOf(d)).includes(step.note), "the install note");
assert.equal(await d.getByRole("button", { name: "Copy", exact: true }).count(), 1, "each line has Copy");
}
const installPage = gone.locator("a", { hasText: "Install page" });
assert.equal(await installPage.count(), 1);
assert.equal(await installPage.getAttribute("href"), "https://example.com/gone");
assert.equal(await installPage.getAttribute("target"), "_blank");
// The template head and row, its detail, and the two actions.
const head = table(s).locator(".split-list-head");
assert.equal(await head.count(), 1);
assert.match(await textOf(head), /Or start from a template/);
assert.match(await textOf(rowByKey(s, "Templar").locator(".row-name")), /Templar/);
const tpl = await pick(s, "Templar", "Templar");
assert.match(await textOf(tpl.locator("p.help")), /A starter agent\./);
assert.equal(await tpl.getByRole("button", { name: "Use this template", exact: true }).count(), 1);
assert.equal(await button(s, "Add agent").count(), 1);
assert.equal(await checkAgain(s).count(), 1);
});
test("a session opened --for-cli lists that agent first and offers only its Start", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", open: ["--for-cli", "found-two"], env: f.env });
await rowByKey(s, "gone").waitFor();
const rows = table(s).locator("button.split-row");
const keys = [];
for (let i = 0; i < (await rows.count()); i++) keys.push(await rows.nth(i).getAttribute("data-key"));
assert.deepEqual(
keys,
["setup:found-two", "setup:found-one", "setup:outer", "setup:gone", "setup:Templar"],
"the forCli builtin leads, the rest keep shipped order"
);
const two = await pick(s, "found-two", "Found Two");
assert.equal(await two.getByRole("button", { name: "Start with this agent", exact: true }).count(), 1, "the forCli agent can start");
const one = await pick(s, "found-one", "Found One");
assert.equal(await textOf(one.locator(".setup-agent-line .prefs-badge")), "Found");
assert.equal(
await one.getByRole("button", { name: "Start with this agent", exact: true }).count(),
0,
"another found agent is not offered"
);
});
test("Check again re-fetches the states and redraws a row that changed", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
const gone = await pick(s, "gone", "Gone Agent");
await gone.locator(".prefs-badge.missing").waitFor();
assert.equal(await textOf(gone.locator(".prefs-badge")), "Not found");
assert.equal(await gone.getByRole("button", { name: "Start with this agent" }).count(), 0);
// The command turns up on PATH between checks.
fs.writeFileSync(path.join(f.onPath, "p2c-gone-xyz.cmd"), "@rem stand-in\r\n");
await checkAgain(s).click();
const goneRow = rowByKey(s, "gone");
await goneRow.locator(".prefs-badge.ok").waitFor();
assert.equal(await textOf(goneRow.locator(".prefs-badge")), "Found");
// The picked row's pane re-drew with the new state too.
const again = detail(s);
await again.locator(".setup-agent-line .prefs-badge.ok").waitFor();
assert.equal(await again.getByRole("button", { name: "Start with this agent", exact: true }).count(), 1);
});
test("Use it from here writes the found location and the row becomes found", async (t) => {
const f = agentFixtures(t, { userAgents: [{ id: "mine", name: "Mine", command: "mine.cmd" }], npmCommands: ["mine.cmd"] });
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
const mine = rowByKey(s, "mine");
const before = await pick(s, "mine", "Mine");
await before.locator(".prefs-badge.missing").waitFor();
assert.equal(await textOf(before.locator(".prefs-badge")), "Found outside PATH");
await before.getByRole("button", { name: "Use it from here", exact: true }).click();
await mine.locator(".prefs-badge.ok").waitFor();
assert.equal(await textOf(mine.locator(".prefs-badge")), "Found");
const saved = JSON.parse(fs.readFileSync(USER_AGENTS_FILE, "utf8"));
assert.equal(saved.agents.length, 1);
assert.equal(saved.agents[0].command, path.join(f.npmBin, "mine.cmd"), "the command is where it was found");
// The picked pane re-drew: the now-found agent offers Start.
const after = detail(s);
await after.locator(".setup-agent-line .prefs-badge.ok").waitFor();
assert.equal(await after.getByRole("button", { name: "Start with this agent", exact: true }).count(), 1);
});
test("Use it from here on the --for-cli agent still offers Start", async (t) => {
// The materialized custom entry becomes the forCli target (a built-in's own
// id can never name a custom entry), so Start survives the swap.
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", open: ["--for-cli", "outer"], env: f.env });
const outer = await pick(s, "outer", "Outer Agent");
await outer.getByRole("button", { name: "Use it from here", exact: true }).waitFor();
await outer.getByRole("button", { name: "Use it from here", exact: true }).click();
// The saved copy lands in the list under its own id ("outer-agent"), and
// picking it shows the session's one Start moved onto it.
await rowByKey(s, "outer-agent").waitFor();
const savedRow = await pick(s, "outer-agent", "Outer Agent");
const starts = savedRow.getByRole("button", { name: "Start with this agent", exact: true });
await starts.waitFor();
assert.equal(await starts.count(), 1, "the saved agent keeps the session's one Start");
const one = await pick(s, "found-one", "Found One");
assert.equal(await one.getByRole("button", { name: "Start with this agent" }).count(), 0, "no other row's Start");
});
test("Use this template fills the shared form, and Save lands a found custom agent", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
await rowByKey(s, "gone").waitFor();
// The template's row sits under the "Or start from a template" head; its
// data-key keeps it apart from the same-named agent its Save will write.
const tpl = await pick(s, "Templar", "Templar");
await tpl.getByRole("button", { name: "Use this template", exact: true }).click();
const form = pane(s);
const name = form.locator('input[data-field="name"]');
await name.waitFor();
assert.equal(await name.inputValue(), "Templar");
assert.equal(await form.locator('input[data-field="command"]').inputValue(), f.templar);
assert.equal(await form.locator('input[data-field="prompt"]').inputValue(), "/plan2code");
await form.getByRole("button", { name: "Save", exact: true }).click();
await form.locator(".prefs-saved").filter({ hasText: "Saved" }).waitFor();
const saved = JSON.parse(fs.readFileSync(USER_AGENTS_FILE, "utf8"));
assert.equal(saved.schema, 1);
assert.deepEqual(
saved.agents.map((a) => [a.id, a.name, a.command]),
[["templar", "Templar", f.templar]],
"the template lands in agents.json"
);
// Back on the list the row is there as a custom agent: pick it (leaving a
// clean form is always free on this page) and its pane carries an Edit.
// Its state comes with the next fetch, which Check again is for.
const templar = rowByKey(s, "templar");
const again = await pick(s, "templar", "Templar");
assert.equal(await again.getByRole("button", { name: "Edit Templar", exact: true }).count(), 1, "a custom agent pane gets Edit");
await checkAgain(s).click();
await templar.locator(".prefs-badge.ok").waitFor();
assert.equal(await textOf(templar.locator(".prefs-badge")), "Found");
});
test("Start posts the __start action, the starting pane shows, then the grace line", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
const one = await pick(s, "found-one", "Found One");
await one.getByRole("button", { name: "Start with this agent", exact: true }).waitFor();
// Shorten the two-minute grace so its line is observable in a test, but keep
// it long enough that the hidden state is still checkable before it lands.
await s.page.evaluate(() => {
window.__P2C_SETUP_GRACE_MS = 400;
});
await one.getByRole("button", { name: "Start with this agent", exact: true }).click();
const starting = s.page.locator(".setup-starting");
await starting.waitFor();
assert.match(await textOf(starting.locator(".launch-title")), /^Starting Found One/);
// The pick is the session's result: the action the launcher's wait collects.
const resultPath = path.join(s.session, "result.json");
assert.equal(await until(() => fs.existsSync(resultPath), 5000), true, "result.json was written");
const result = JSON.parse(fs.readFileSync(resultPath, "utf8"));
assert.deepEqual(result.actions, [{ i: "__start", type: "start", agent: "found-one" }]);
// The hint starts hidden; a move that never comes earns it after the grace wait.
await s.page.waitForFunction(() => {
const n = document.querySelector(".setup-no-page");
return Boolean(n && n.hidden);
});
const noPage = starting.locator(".setup-no-page");
await noPage.waitFor({ state: "visible" });
assert.match(await textOf(noPage), /did not open a page\./);
});
test("a /handover post with the setup token moves the page to the new session", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
await rowByKey(s, "found-one").waitFor();
const otherDir = tempProject();
const other = cli(["open", "--workflow", "plan", "--no-open"], { cwd: otherDir, env: f.env });
t.after(() => cli(["stop", "--session", other.json.sid, "--force"], { cwd: otherDir }));
const target = sessionUrl(other.json.url);
const res = await fetch(`${sessionUrl(s.url).base}/handover`, {
method: "POST",
headers: {
"content-type": "application/json",
"x-plan2code-token": readState(s.session).setup.token,
connection: "close",
},
body: JSON.stringify({ url: other.json.url }),
});
assert.equal(res.status, 204);
// The sign-in link sets the session cookie and lands on the session's root.
await s.page.waitForURL((u) => u.origin === target.base && u.pathname === "/", { timeout: 15000 });
});
test("the setup page keeps no agent-silence UI: no adrift or offline lines, no Ask, top bar down to Help", async (t) => {
const f = agentFixtures(t);
const s = await openSession(await suite.browser(), { t, workflow: "setup", env: f.env });
await s.page.locator(".setup-screen").waitFor();
const check = async (when) => {
assert.match(await s.page.locator("#planny").getAttribute("class"), /\bis-setup\b/, `${when}: Planny's mood`);
assert.match(await textOf(s.page.locator("#agent-text")), /No agent yet\. Pick one below/, `${when}: the dock line`);
assert.equal(await s.page.locator("#banner").isHidden(), true, `${when}: no banner`);
assert.equal(await s.page.locator("#btn-about").isVisible(), true, `${when}: Help stays`);
const tabs = (await s.page.locator(".view-tab").allInnerTexts()).map((x) => x.trim());
assert.equal(tabs.some((x) => /ask|subagents/i.test(x)), false, `${when}: no Ask or Subagents tab (${tabs})`);
for (const id of ["meter-pill", "btn-activities", "btn-subagents", "btn-home", "btn-stop", "btn-brief", "btn-notepad"]) {
assert.equal(await s.page.locator("#" + id).isHidden(), true, `${when}: #${id} is hidden`);
}
};
await check("on load");
// A quiet stretch changes nothing: the silence states are switched off.
await s.page.waitForTimeout(1500);
await check("after a wait");
});
+404 -1
View File
@@ -43,6 +43,7 @@ import {
HANDOFFS_DIR,
HOME,
ENV,
MODELS_DIR,
cookieFor,
cli,
payload,
@@ -52,6 +53,7 @@ import {
sessionUrl,
readState,
sleep,
until,
} from "./web-console-test-helpers.mjs";
// Every page load used to fetch /state, then /looks, then open the stream,
@@ -551,7 +553,7 @@ test("User Preferences: wider, its body scrolls and the button bar stays put, wi
const actions = dialog[1].indexOf('<div class="modal-actions">');
assert.ok(body >= 0 && actions > body, "the fieldsets sit in .prefs-body, before the actions");
assert.ok(dialog[1].lastIndexOf("</fieldset>") < actions, "every fieldset is inside the scrolling body");
assert.match(css, /\.modal\.prefs \{ max-width: 880px; \}/);
assert.match(css, /\.modal\.prefs \{ width: min\(1080px, var\(--card-width\), calc\(100vw - 32px\)\); max-width: none; \}/);
assert.match(css, /\.prefs-body \{[^}]*overflow-y: auto/);
assert.match(css, /\.modal\.prefs \.modal-actions \{[^}]*flex: none/);
assert.match(html, /<dialog class="modal looks subagents" id="subagents-modal"/, "Subagents keeps its own classes");
@@ -919,3 +921,404 @@ test("/open-link takes an http or https link and refuses every other kind", asyn
cli(["stop", "--session", res.json.sid, "--force"]);
}
});
/* ------------------------- first-run agent setup (the setup workflow) ------------------------- */
// `open --workflow setup` is the agent-less page the launcher opens when no agent
// can run: the session state carries the hand-over the launcher's agent posts
// back to /handover, and `open` prints it for the launcher to read.
test("open --workflow setup records the hand-over data and prints it, and a plain resume keeps its token", () => {
const res = cli(["open", "--workflow", "setup", "--for-cli", "devin", "--no-open"], { env: NO_APP });
try {
const state = readState(res.json.session);
assert.equal(state.workflow, "setup");
assert.equal(state.setup.forCli, "devin");
assert.match(state.setup.token, /^[A-Za-z0-9_-]{10,}$/);
assert.ok(state.setup.created);
assert.deepEqual(res.json.setup, { url: res.json.url, token: state.setup.token });
assert.match(res.json.setup.url, /\/s\/[A-Za-z0-9_-]+\/$/, "the page's own sign-in link");
cli(["open", "--resume", res.json.sid, "--workflow", "setup", "--no-open"], { env: NO_APP });
assert.equal(readState(res.json.session).setup.token, state.setup.token, "a plain resume keeps the token the launcher's agent holds");
// A resume naming --for-cli is a new hand-over: a fresh token and target.
const retarget = cli(["open", "--resume", res.json.sid, "--workflow", "setup", "--for-cli", "codex", "--no-open"], { env: NO_APP });
const now = readState(res.json.session).setup;
assert.equal(now.forCli, "codex");
assert.notEqual(now.token, state.setup.token);
assert.equal(retarget.json.setup.token, now.token);
} finally {
cli(["stop", "--session", res.json.sid, "--force"]);
}
});
// The shipped and custom agent lists the setup page shows. Commands carry .cmd
// so one file name is found on every OS. The env points npm's global folder at
// a fixture dir and kills the saved PATH: a builtin goes "outside" through its
// installDirs, a custom agent through the npm folder (agentsGet looks custom
// commands up by name only, so installDirs never applies to them).
const NO_APP = {
PLAN2CODE_IN_APP: undefined,
PLAN2CODE_APP_TOKEN: undefined,
PLAN2CODE_APP_ANNOUNCE: undefined,
PLAN2CODE_EMBED_ORIGIN: undefined,
PLAN2CODE_CONSOLE_SID: undefined,
PLAN2CODE_APP_VERSION: undefined,
};
function agentFixtures(base) {
const outside = path.join(base, "outside");
fs.mkdirSync(outside);
fs.writeFileSync(path.join(outside, "testagent.cmd"), "@rem stand-in\r\n");
const onPath = path.join(base, "onpath.cmd");
fs.writeFileSync(onPath, "@rem stand-in\r\n");
// npm's global bin: the prefix itself on Windows, <prefix>/bin elsewhere.
const npmBin = process.platform === "win32" ? path.join(base, "npm-prefix") : path.join(base, "npm-prefix", "bin");
fs.mkdirSync(npmBin, { recursive: true });
const inNpm = path.join(npmBin, "agenttwo.cmd");
fs.writeFileSync(inNpm, "@rem stand-in\r\n");
const shipped = {
schema: 1,
agents: [
{
id: "testagent",
name: "Test Agent",
kind: "builtin",
command: "testagent.cmd",
prompt: "/plan2code",
args: ["{prompt}"],
bypassArgs: ["--yes"],
modelArgs: ["--model", "{model}"],
installUrl: "https://example.com/get",
install: {
win: [{ label: "PowerShell", run: "irm x | iex", note: "n" }],
mac: [{ label: "Terminal", run: "curl x" }],
linux: [],
},
installDirs: { win: [outside], mac: [outside], linux: [outside] },
},
{ id: "gone", name: "Gone Agent", kind: "builtin", command: "gone-agent-xyz.cmd" },
{ id: "templ", name: "Templ", kind: "template", command: "templ", prompt: "Use plan2code", args: ["{prompt}"], note: "a starter" },
],
};
const user = {
schema: 1,
agents: [
{ id: "myagent", name: "My Agent", command: onPath },
{ id: "agenttwo", name: "Agent Two", command: "agenttwo.cmd" },
],
};
const shippedFile = path.join(MODELS_DIR, "bin", "agents.json");
const userFile = path.join(MODELS_DIR, "agents.json");
fs.mkdirSync(path.dirname(shippedFile), { recursive: true });
fs.writeFileSync(shippedFile, JSON.stringify(shipped));
fs.writeFileSync(userFile, JSON.stringify(user));
return { outside, onPath, inNpm, shipped, shippedFile, userFile };
}
const AGENT_ENV = (base) => ({ PLAN2CODE_NO_SAVED_PATH: "1", npm_config_prefix: path.join(base, "npm-prefix"), ...NO_APP });
test("GET /agents reports found, outside and missing for the custom and shipped lists", async () => {
const base = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-agents-"));
const res = cli(["open", "--workflow", "setup", "--no-open"], { env: AGENT_ENV(base) });
try {
const f = agentFixtures(base);
const { base: url, cookie } = sessionUrl(res.json.url);
const got = await (await fetch(`${url}/agents`, { headers: { cookie, connection: "close" } })).json();
const mine = got.agents.find((a) => a.id === "myagent");
assert.deepEqual(
{ state: mine.state, path: mine.path, where: mine.where, folder: mine.folder },
{ state: "found", path: f.onPath, where: "path", folder: path.dirname(f.onPath) }
);
const two = got.agents.find((a) => a.id === "agenttwo");
assert.deepEqual({ state: two.state, path: two.path, where: two.where }, { state: "outside", path: f.inNpm, where: "npm" });
const testagent = got.builtins.find((b) => b.id === "testagent");
assert.deepEqual({ state: testagent.state, where: testagent.where }, { state: "outside", where: "install-dir" });
assert.equal(testagent.name, "Test Agent");
assert.equal(testagent.command, "testagent.cmd");
assert.equal(testagent.prompt, "/plan2code");
assert.deepEqual(testagent.args, ["{prompt}"]);
assert.deepEqual(testagent.bypassArgs, ["--yes"]);
assert.deepEqual(testagent.modelArgs, ["--model", "{model}"]);
assert.equal(testagent.installUrl, "https://example.com/get");
const OS_KEY = process.platform === "win32" ? "win" : process.platform === "darwin" ? "mac" : "linux";
assert.deepEqual(testagent.install, f.shipped.agents[0].install[OS_KEY], "only this OS's install steps");
const gone = got.builtins.find((b) => b.id === "gone");
assert.deepEqual(
{ state: gone.state, path: gone.path, where: gone.where, folder: gone.folder },
{ state: "missing", path: null, where: null, folder: null }
);
// Templates come back as the form fields only: no `kind`, no found state.
assert.deepEqual(got.templates, [{ id: "templ", name: "Templ", command: "templ", prompt: "Use plan2code", args: ["{prompt}"], note: "a starter" }]);
assert.deepEqual(got.warnings, []);
} finally {
cli(["stop", "--session", res.json.sid, "--force"]);
fs.rmSync(path.join(MODELS_DIR, "agents.json"), { force: true });
fs.rmSync(path.join(MODELS_DIR, "bin", "agents.json"), { force: true });
fs.rmSync(base, { recursive: true, force: true });
}
});
test("POST /agents/use-path writes findAgent's hit into agents.json, and only that", async () => {
const base = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-agents-"));
const res = cli(["open", "--workflow", "setup", "--no-open"], { env: AGENT_ENV(base) });
try {
const f = agentFixtures(base);
const { base: url, cookie } = sessionUrl(res.json.url);
const usePath = (body) =>
fetch(`${url}/agents/use-path`, {
method: "POST",
headers: { "content-type": "application/json", cookie, origin: url, connection: "close" },
body: JSON.stringify(body),
});
const readUser = () => JSON.parse(fs.readFileSync(f.userFile, "utf8"));
const missing = await usePath({ id: "gone" });
assert.equal(missing.status, 409, "not on PATH and nowhere else either");
assert.deepEqual(await missing.json(), { error: "not-found" });
const unknown = await usePath({ id: "nope" });
assert.equal(unknown.status, 404, "no such agent at all");
assert.deepEqual(await unknown.json(), { error: "not-found" });
// Already on PATH: a 200 and no write.
const before = fs.readFileSync(f.userFile, "utf8");
const found = await usePath({ id: "myagent" });
assert.equal(found.status, 200);
assert.deepEqual(await found.json(), { ok: true, id: "myagent", command: f.onPath });
assert.equal(fs.readFileSync(f.userFile, "utf8"), before);
// Off PATH ("outside"): the command becomes where it was found. A path in
// the body is never taken.
const outside = await usePath({ id: "agenttwo", command: "should-not-be-taken", path: "should-not-be-taken" });
assert.equal(outside.status, 200);
const wanted = f.inNpm;
assert.deepEqual(await outside.json(), { ok: true, id: "agenttwo", command: wanted });
assert.equal(readUser().agents.find((a) => a.id === "agenttwo").command, wanted);
// A built-in is materialized as a new custom entry under a generated id;
// the file's other entries stand.
const builtin = await usePath({ id: "testagent" });
assert.equal(builtin.status, 200);
const saved = await builtin.json();
assert.equal(saved.id, "test-agent", "makeId kebab-cases the name");
const created = readUser().agents.find((a) => a.id === "test-agent");
assert.equal(created.command, path.join(f.outside, "testagent.cmd"));
assert.equal(created.name, "Test Agent");
assert.equal(created.prompt, "/plan2code");
assert.equal(readUser().schema, 1);
assert.deepEqual(readUser().agents.map((a) => a.id), ["myagent", "agenttwo", "test-agent"]);
} finally {
cli(["stop", "--session", res.json.sid, "--force"]);
fs.rmSync(path.join(MODELS_DIR, "agents.json"), { force: true });
fs.rmSync(path.join(MODELS_DIR, "bin", "agents.json"), { force: true });
fs.rmSync(base, { recursive: true, force: true });
}
});
// The setup tab's move: another Plan2Code process POSTs the session's sign-in
// link here, the page's stream gets a `move` event and state.setup.moved is
// set. Only a setup session answers, only for the token `open` printed, and
// only a loopback console /s/ link is a legal destination.
test("POST /handover takes only the setup token and a console sign-in link, and moves the page", async () => {
const res = cli(["open", "--workflow", "setup", "--no-open"], { env: NO_APP });
const m = res.json.url.match(/^(http:\/\/127\.0\.0\.1:(\d+))\/s\/([^/]+)\//);
const cookie = cookieFor(m[1], m[3]);
const port = Number(m[2]);
const token = res.json.setup.token;
const handover = (body, headers = {}) =>
new Promise((resolve, reject) => {
const req = http.request(
{
host: "127.0.0.1",
port,
path: "/handover",
method: "POST",
headers: { "content-type": "application/json", "x-plan2code-token": token, connection: "close", ...headers },
},
(r) => {
const chunks = [];
r.on("data", (c) => chunks.push(c));
r.on("end", () => resolve({ status: r.statusCode, body: Buffer.concat(chunks).toString("utf8") }));
}
);
req.on("error", reject);
req.end(JSON.stringify(body));
});
const other = cli(["open", "--workflow", "plan", "--no-open"], { env: NO_APP });
try {
// No cookie at all: the hand-over has its own token, which is the point.
for (const headers of [{ "x-plan2code-token": "wrong-token" }, { "x-plan2code-token": "" }]) {
const no = await handover({ url: "http://127.0.0.1:9/s/abc/" }, headers);
assert.equal(no.status, 403, JSON.stringify(headers));
assert.deepEqual(JSON.parse(no.body), { error: "forbidden" });
}
for (const url of [
"https://127.0.0.1:9/s/abc/",
"http://example.com/s/abc/",
"http://127.0.0.1/s/abc/",
"http://127.0.0.1:9/x/abc/",
"http://127.0.0.1:9/s/a b/",
"javascript:alert(1)",
"",
42,
null,
]) {
const no = await handover({ url });
assert.equal(no.status, 400, JSON.stringify(url));
assert.deepEqual(JSON.parse(no.body), { error: "bad-url" });
}
// The stream sees the move the POST causes.
const events = new Promise((resolve, reject) => {
const req = http.request({ host: "127.0.0.1", port, path: "/events", headers: { cookie } }, (r) => {
let buf = "";
r.setEncoding("utf8");
r.on("data", (c) => (buf += c));
setTimeout(() => {
req.destroy();
resolve(buf);
}, 1500);
});
req.on("error", reject);
req.end();
});
await sleep(150); // the GET must land before the POST
const target = "http://localhost:9/s/NewAgent_1-2/";
const ok = await handover({ url: target });
assert.equal(ok.status, 204);
const stream = await events;
assert.ok(stream.includes(`event: move\ndata: ${JSON.stringify({ url: target })}`), stream);
const setup = readState(res.json.session).setup;
assert.equal(setup.moved.url, target);
assert.ok(setup.moved.at);
// A session that is not the setup page never answers, whatever the header.
const otherPort = Number(other.json.url.match(/^http:\/\/127\.0\.0\.1:(\d+)\//)[1]);
const notSetup = await new Promise((resolve, reject) => {
const req = http.request(
{
host: "127.0.0.1",
port: otherPort,
path: "/handover",
method: "POST",
headers: { "content-type": "application/json", "x-plan2code-token": token },
},
(r) => {
const chunks = [];
r.on("data", (c) => chunks.push(c));
r.on("end", () => resolve({ status: r.statusCode, body: Buffer.concat(chunks).toString("utf8") }));
}
);
req.on("error", reject);
req.end(JSON.stringify({ url: "http://127.0.0.1:9/s/abc/" }));
});
assert.equal(notSetup.status, 404);
assert.deepEqual(JSON.parse(notSetup.body), { error: "not-found" });
} finally {
cli(["stop", "--session", res.json.sid, "--force"]);
cli(["stop", "--session", other.json.sid, "--force"]);
}
});
// The other half of the hand-over: an agent opened under PLAN2CODE_SETUP_* posts
// its link to the setup console's /handover instead of opening a browser, and a
// refused post falls back to the browser with a note saying so.
test("an agent opened with the setup hand-over posts its link, and a refused post says so", async () => {
const setup = cli(["open", "--workflow", "setup", "--no-open"], { env: NO_APP });
const token = readState(setup.json.session).setup.token;
let agent;
try {
// setup.url is the setup session's own link; /handover resolves off it, so
// the running server answers. No --no-open: that flag is what skips this.
agent = cli(["open", "--workflow", "plan"], {
env: { ...NO_APP, PLAN2CODE_SETUP_ANNOUNCE: setup.json.setup.url, PLAN2CODE_SETUP_TOKEN: token },
});
assert.equal(agent.json.handover, true);
const moved = readState(setup.json.session).setup.moved;
assert.equal(moved.url, agent.json.url, "the setup session learned where its tab went");
const bad = cli(["open", "--workflow", "plan"], {
env: { ...NO_APP, PLAN2CODE_SETUP_ANNOUNCE: setup.json.setup.url, PLAN2CODE_SETUP_TOKEN: "wrong-token" },
});
try {
assert.equal("handover" in bad.json, false);
assert.match(bad.json.note, /Could not move the setup tab/);
} finally {
cli(["stop", "--session", bad.json.sid, "--force"]);
}
} finally {
if (agent) cli(["stop", "--session", agent.json.sid, "--force"]);
cli(["stop", "--session", setup.json.sid, "--force"]);
}
});
// The idle deadline is the only thing that stops an orphan server (server.mjs's
// comment says why it must not be optimized away); a setup session honors it too.
test("a setup session still stops on --idle-ms", async () => {
const res = cli(["open", "--workflow", "setup", "--idle-ms", "300", "--no-open"], { env: NO_APP });
try {
const events = path.join(res.json.session, "events.ndjson");
// The deadline is checked on a 20s tick, so the exit lands within a tick of the cap.
const gone = await until(() => fs.existsSync(events) && fs.readFileSync(events, "utf8").includes('"reason":"idle"'), 40000);
assert.ok(gone, "the server never recorded its idle exit");
} finally {
cli(["stop", "--session", res.json.sid, "--force"]);
}
});
// NFR-2: the launcher scrubs the app-window variables before spawning the setup
// console (test-launcher.mjs has the spawn half), so nothing can leak the page
// into an app window. Even with an announce URL left in the environment a
// console without the full signal never calls it; with the signal it does.
test("a setup console without the app signal never calls a leftover announce URL", async () => {
const calls = [];
const stub = http.createServer((req, res) => {
req.resume();
req.on("end", () => {
calls.push(`${req.method} ${req.url}`);
res.writeHead(req.url === "/session" ? 404 : 204).end();
});
});
await new Promise((r) => stub.listen(0, "127.0.0.1", r));
const announce = `http://127.0.0.1:${stub.address().port}`;
try {
const res = cli(["open", "--workflow", "setup", "--no-open"], { env: { ...NO_APP, PLAN2CODE_APP_ANNOUNCE: announce } });
try {
assert.equal(res.json.inApp, undefined);
assert.equal(res.json.announced, undefined);
assert.deepEqual(calls, [], "a stray announce URL alone is not the signal");
} finally {
cli(["stop", "--session", res.json.sid, "--force"]);
}
// With the full signal the same open announces, as the in-app tests cover.
// Spawned asynchronously: the announce endpoint lives in this process, so a
// blocking spawn would deadlock (the same reason test-in-app uses openAsync).
const inApp = await new Promise((resolve) => {
const child = spawn(
process.execPath,
[path.join(ROOT, "src", "web-console", "console.mjs"), "open", "--workflow", "setup", "--no-open"],
{
cwd: ROOT,
env: { ...ENV, ...NO_APP, PLAN2CODE_IN_APP: "1", PLAN2CODE_APP_ANNOUNCE: announce, PLAN2CODE_APP_TOKEN: "tok" },
windowsHide: true,
}
);
let out = "";
child.stdout.on("data", (c) => (out += c));
child.on("close", (status) => resolve({ status, json: JSON.parse(out.trim().split("\n").filter(Boolean).pop()) }));
});
try {
assert.equal(inApp.json.announced, true);
assert.ok(calls.some((c) => c.startsWith("POST /page")), JSON.stringify(calls));
} finally {
cli(["stop", "--session", inApp.json.sid, "--force"]);
}
} finally {
stub.close();
}
});
+8 -6
View File
@@ -555,9 +555,11 @@ test("console-launches.md and the dashboard prompt teach the handoff pick-up and
test("every module the page imports is actually served", async () => {
const dir = path.join(ROOT, "src", "web-console", "public");
const wanted = new Set(["app.js"]);
// The modules beside app.js and the screens under screens/, each import
// resolved from the file that makes it (a screen's "../state.js" is state.js).
const files = [...fs.readdirSync(dir).filter((f) => f.endsWith(".js")), ...fs.readdirSync(path.join(dir, "screens")).map((f) => `screens/${f}`)];
// The modules beside app.js and the screens under screens/ (subfolders too:
// screens/agents/ is a directory), each import resolved from the file that
// makes it (a screen's "../state.js" is state.js).
const screens = (abs, rel) => fs.readdirSync(abs, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? screens(path.join(abs, e.name), `${rel}${e.name}/`) : e.name.endsWith(".js") ? [`${rel}${e.name}`] : []);
const files = [...fs.readdirSync(dir).filter((f) => f.endsWith(".js")), ...screens(path.join(dir, "screens"), "screens/")];
for (const f of files) {
const src = fs.readFileSync(path.join(dir, f), "utf8");
for (const m of src.matchAll(/^\s*import\b[^"']*["'](\.\.?\/[^"']+)["']/gm)) wanted.add(path.posix.join(path.posix.dirname(f), m[1]));
@@ -651,9 +653,9 @@ test("the favicon is served as an SVG with a PNG fallback and the page points at
/* ---------------------------------------------------------------- help */
test("help: 20 tabs with unique ids", () => {
assert.equal(HELP_TABS.length, 20);
assert.equal(new Set(HELP_TABS.map((t) => t.id)).size, 20);
test("help: 21 tabs with unique ids", () => {
assert.equal(HELP_TABS.length, 21);
assert.equal(new Set(HELP_TABS.map((t) => t.id)).size, 21);
assert.ok(Object.isFrozen(HELP_TABS) && HELP_TABS.every((t) => Object.isFrozen(t)), "the tab list is frozen");
const ids = HELP_TABS.map((t) => t.id);
assert.equal(ids.indexOf("loop"), ids.indexOf("build") + 1, "Implementation Loop comes right after Watching a build");
+7 -4
View File
@@ -121,7 +121,10 @@ test("shape: the define-only check names a page file that touches the page at lo
// A screen reaches the rest of the page through ../state.js and the pure
// modules beside it, never through another screen: only core.js (the render
// loop, which draws every screen) imports screens, and only app.js (the
// entry) imports core.js. Each import that breaks that is named.
// entry) imports core.js. A screen's own components are not screens: files
// under a subdirectory of screens/ (screens/agents/) may be imported by the
// screen they serve and by each other, but never the other way, and never a
// top-level screen file. Each import that breaks that is named.
function pageImportProblems(pub) {
const problems = [];
for (const p of sourceFiles(pub).filter((f) => f.endsWith(".js") && (!f.includes("/") || f.startsWith("screens/")))) {
@@ -131,7 +134,7 @@ function pageImportProblems(pub) {
if (!spec.startsWith(".")) continue;
const target = path.posix.join(path.posix.dirname(p), spec);
if (target === "screens/core.js" && p !== "app.js") problems.push(`${p} imports ${spec}: only app.js imports core.js`);
else if (p.startsWith("screens/") && p !== "screens/core.js" && target.startsWith("screens/"))
else if (p.startsWith("screens/") && p !== "screens/core.js" && /^screens\/[^/]+\.js$/.test(target))
problems.push(`${p} imports ${spec}: a screen imports ../state.js and the modules beside it, never another screen`);
}
}
@@ -184,8 +187,8 @@ test("shape: no page module sets a style attribute from script", () => {
// and WORKSPACE_EDITS for /workspace/add, /edit and /remove. The git board has
// no routes of its own: its buttons are sends (`__git`), through /submit.
const ROUTE_ORDER = [
"/health", "/s/", "/", "SERVABLE", "/overview", "/handoff", "/version", "/state", "/events", "/draft",
"/looks", "/looks", "/subagents", "/pr-host", "/models", "/models", "/agents", "/agents", "/agents/test", "/cleanup", "/upload",
"/health", "/s/", "/handover", "/", "SERVABLE", "/overview", "/handoff", "/version", "/state", "/events", "/draft",
"/looks", "/looks", "/subagents", "/pr-host", "/models", "/models", "/agents", "/agents", "/agents/test", "/agents/use-path", "/cleanup", "/upload",
"/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab",
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/",
"/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/chat", "/chat/decision", "/workspace",
+24 -8
View File
@@ -17,6 +17,7 @@ import {
labelFor,
WORKFLOWS,
isWorkflow,
isAgentless,
} from "../src/web-console/public/skills.js";
import { CONSOLE_WORKFLOWS, SKILL_CATALOG, catalogEntry, launchVariant, START_POSES, WORKFLOW_LABEL, dashNoteKind, onInitialPick, startPose, startingHint } from "../src/web-console/public/answers.js";
import { LAUNCH_COUNTED, PROGRESS_WORKFLOWS } from "../src/web-console/public/meter.js";
@@ -60,7 +61,7 @@ test("every skill the console knows has one entry, the dashboard included", () =
const workflows = SKILLS.map((s) => s.workflow);
assert.deepEqual([...workflows].sort(), Object.keys(WORKFLOW_LABEL).sort());
assert.equal(new Set(workflows).size, workflows.length, "one entry per workflow");
assert.deepEqual(SKILLS.map((s) => s.command).sort(), [...CONSOLE_WORKFLOWS].sort());
assert.deepEqual(SKILLS.map((s) => s.command).filter(Boolean).sort(), [...CONSOLE_WORKFLOWS].sort());
// The cards come first, in the dashboard's order.
const carded = SKILLS.filter((s) => s.card);
assert.deepEqual(carded.map((s) => s.skill), SKILL_CATALOG.map((e) => e.skill));
@@ -76,6 +77,17 @@ test("every skill the console knows has one entry, the dashboard included", () =
test("the derived exports agree with each entry", () => {
for (const s of SKILLS) {
const w = s.workflow;
// The setup page is a workflow the launcher opens, not a skill an agent
// picks: it has no skill name, command or card for the exports to mirror.
if (s.agentless) {
for (const f of ["workflow", "label", "name"]) assert.ok(typeof s[f] === "string" && s[f].trim(), `${w}: ${f} must be filled in`);
assert.equal(s.skill, null, `${w}: agent-less has no skill`);
assert.equal(s.command, null, `${w}: agent-less has no command`);
assert.equal(s.card, null, `${w}: agent-less has no card`);
assert.equal(s.pose, startPose(w), `${w}: pose`);
assert.equal(s.metered, LAUNCH_COUNTED.has(w), `${w}: metered`);
continue;
}
for (const f of ["skill", "workflow", "label", "name"]) assert.ok(typeof s[f] === "string" && s[f].trim(), `${w}: ${f} must be filled in`);
assert.equal(s.command, "/" + s.skill, `${w}: command`);
assert.equal(s.label, WORKFLOW_LABEL[w], `${w}: label`);
@@ -177,9 +189,10 @@ function poseProblems(skills, drawn) {
return problems;
}
// Every workflow the console can open has its notes behind `console.mjs help`.
// Every skill workflow the console can open has its notes behind
// `console.mjs help`; agent-less pages are opened by the launcher, not picked.
function helpProblems(skills, topics) {
return skills.filter((s) => !Object.hasOwn(topics, s.workflow)).map((s) => `${s.skill} (${s.workflow}) has no help topic in console.mjs`);
return skills.filter((s) => !s.agentless && !Object.hasOwn(topics, s.workflow)).map((s) => `${s.skill} (${s.workflow}) has no help topic in console.mjs`);
}
// The skills with a card, plus the dashboard, are exactly what install.js builds.
@@ -302,7 +315,7 @@ test("docs: console.md's open step names every workflow", () => {
const m = text.match(/`<w>` is one of ([\s\S]*?)\. Launched from the dashboard/);
assert.ok(m, "console.md: the open step's `<w>` sentence is not where the test looks");
const said = [...m[1].matchAll(/`([^`]+)`/g)].map((x) => x[1]);
assert.deepEqual(listProblems("src/web-console/console.md", said, WORKFLOWS), []);
assert.deepEqual(listProblems("src/web-console/console.md", said, WORKFLOWS.filter((w) => !isAgentless(w))), []);
});
test("docs: the dashboard skill's launch table maps every skill to its workflow", () => {
@@ -313,7 +326,7 @@ test("docs: the dashboard skill's launch table maps every skill to its workflow"
const cells = line.split("|").map((c) => c.trim()).filter(Boolean);
for (let i = 0; i + 1 < cells.length; i += 2) pairs.push(`${cells[i]} -> ${cells[i + 1]}`);
}
const want = SKILLS.filter((s) => s.workflow !== "dashboard").map((s) => `${s.skill} -> ${s.workflow}`);
const want = SKILLS.filter((s) => s.skill && s.workflow !== "dashboard").map((s) => `${s.skill} -> ${s.workflow}`);
assert.deepEqual(listProblems("src/plan2code.md (A pick arrives)", pairs, want), []);
});
@@ -327,7 +340,7 @@ test("docs: the dashboard skill's reads-and-writes table has a row for every ski
if (m[1] === "3-implement(-review)") said.push("3-implement", "3-implement-review");
else said.push(m[1]);
}
const want = SKILLS.filter((s) => s.workflow !== "dashboard").map((s) => s.skill.replace(/^plan2code-/, ""));
const want = SKILLS.filter((s) => s.skill && s.workflow !== "dashboard").map((s) => s.skill.replace(/^plan2code-/, ""));
assert.deepEqual(listProblems("src/plan2code.md (What each skill reads and writes)", said, want), []);
});
@@ -336,8 +349,11 @@ test("docs: `console.mjs help` lists every workflow, in order", () => {
const m = out.match(/workflows: ([\s\S]*?)\n\s*\n/);
assert.ok(m, "console.mjs help prints no workflows: list");
const said = m[1].split(/[·\s]+/).filter(Boolean);
assert.deepEqual(listProblems("console.mjs help", said, WORKFLOWS), []);
assert.deepEqual(said, [...WORKFLOWS], "console.mjs help: the workflows are in skills.js order");
// The CLI's usage lists only the workflows an agent can pick: the agent-less
// setup page is opened by the launcher, never typed here (phase-2 note).
const listed = WORKFLOWS.filter((w) => !isAgentless(w));
assert.deepEqual(listProblems("console.mjs help", said, listed), []);
assert.deepEqual(said, [...listed], "console.mjs help: the workflows are in skills.js order");
});
// A count goes stale the day a skill is added; the docs say "every skill".
+24 -11
View File
@@ -401,19 +401,21 @@ test("help: the stuck tab is second, and openHelpOn only opens a tab that exists
assert.match(opener[1], /HELP_TABS\.some\(/, "openHelpOn only opens a tab that exists");
});
test("models: Codex is a model CLI on the server and the page, with its own row in the agents table", () => {
const server = fs.readFileSync(path.join(ROOT, "src", "web-console", "routes.mjs"), "utf8");
const app = publicSource("screens/agents-view.js");
test("models: the page's built-in rows match the shipped agent list's builtins", () => {
const app = publicSource("screens/agents/agents-data.js");
const list = (src) => JSON.parse(src.match(/const MODEL_CLIS = (\[[^\]]*\]);/)[1]);
assert.deepEqual(list(server), ["claude", "devin", "codex"]);
assert.deepEqual(list(app), list(server), "the page's rows match the server's lists");
// routes.mjs no longer carries a literal MODEL_CLIS: both sides read the
// builtin ids from the shipped agent list (agent-lookup.mjs).
const shipped = JSON.parse(fs.readFileSync(path.join(ROOT, "src", "launcher", "agents.json"), "utf8"));
const builtinIds = shipped.agents.filter((a) => a.kind === "builtin").map((a) => a.id);
assert.deepEqual(list(app), builtinIds, "the page's rows match the shipped builtins");
assert.ok(!/for \(const cli of \["claude", "devin"\]\)/.test(app), "no loop over a hard-coded pair");
assert.match(app, /\.\.\.MODEL_CLIS\.map\(\(cli\) => \(\{\s*key: "cli:" \+ cli,/, "the table draws a built-in row per MODEL_CLIS entry");
const names = app.match(/const BUILT_IN = \{([^}]*)\};/)[1];
for (const cli of list(app)) assert.match(names, new RegExp(`\\b${cli}: "`), `${cli} has a name in the table`);
assert.ok(!publicSource("index.html").includes("models-tab-"), "the separate Models toggles are gone");
const shipped = JSON.parse(fs.readFileSync(path.join(ROOT, "src", "launcher", "models.json"), "utf8"));
for (const cli of list(server)) assert.ok(Array.isArray(shipped[cli]), `the launcher's models.json has ${cli}`);
const models = JSON.parse(fs.readFileSync(path.join(ROOT, "src", "launcher", "models.json"), "utf8"));
for (const cli of list(app)) assert.ok(Array.isArray(models[cli]), `the launcher's models.json has ${cli}`);
});
test("getting started: the new help, status and finished-screen strings carry no em dash", () => {
@@ -486,13 +488,24 @@ test("prefs: the dialog is four tab panels in PREFS_TABS order, each section in
test("prefs: the new modules are served and preloaded, and Preferences' styles leave the shared classes alone", () => {
const html = publicSource("index.html");
for (const m of ["tabs.js", "prefs.js", "screens/prefs-dialog.js", "screens/agents-view.js"]) {
for (const m of [
"tabs.js",
"prefs.js",
"screens/prefs-dialog.js",
"screens/agents-view.js",
"screens/agents/agents-data.js",
"screens/agents/agents-list-editor.js",
"screens/agents/agents-summary.js",
"screens/agents/agents-form.js",
]) {
assert.ok(SERVABLE.has(m), `${m} is servable`);
assert.ok(html.includes(`rel="modulepreload" href="/${m}"`), `the page preloads ${m}`);
}
const css = publicSource("styles/prefs.css");
for (const cls of ["looks", "looks-row", "modal-ranges"]) {
assert.ok(!new RegExp(`\\.${cls}(?![\\w-])`).test(css), `prefs.css does not style .${cls} (the Subagents dialog shares it)`);
for (const sheet of ["styles/prefs.css", "styles/agents.css"]) {
const css = publicSource(sheet);
for (const cls of ["looks", "looks-row", "modal-ranges"]) {
assert.ok(!new RegExp(`\\.${cls}(?![\\w-])`).test(css), `${sheet} does not style .${cls} (the Subagents dialog shares it)`);
}
}
});