Fail the macOS smoke run when the dashboard frame never connects, and update the checklist

AI Assisted
This commit is contained in:
Seth committed 2026-12-05 00:10:45 -08:00
1 parent a9e0bf49f0
commit 615e98e11e
10 files changed
+418 -3

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ Which checks cover which files, read by PR Prep and Test (`test-map.mjs read` ch
| Learning on the console | `src/web-console/learning.mjs`, `src/web-console/public/screens/learning-row.js`, `src/web-console/public/styles/learning.css` | `node scripts/node-test.mjs scripts/test-web-console-learning.mjs scripts/test-web-console-page-learning.mjs` | no |
| Review Loop on the console | `src/web-console/review-loop-setup.mjs`, `src/web-console/notes/review-loop.md`, `src/web-console/public/screens/review-loop-setup.js`, `src/web-console/public/loop-parts.js`, `src/web-console/public/review-loop-end.js` | `node scripts/node-test.mjs scripts/test-web-console-review-loop.mjs scripts/test-web-console-loop.mjs && npm run test:page -- scripts/test-web-console-page-review-loop.mjs` | no |
| Workflow prompts | `src/plan2code-*.md` | `node scripts/validate-char-count.js && node scripts/check-skill-table.mjs` | no |
| App smoke scripts | `plan2code-app/scripts/smoke-*.mjs` | `node scripts/node-test.mjs scripts/test-app-smoke-agent.mjs scripts/test-app-smoke-frame.mjs` | no |
| Desktop app | `plan2code-app/**` | `cd plan2code-app && cargo test` | no |
| Metrics | `plan2code-metrics/**` | `cd plan2code-metrics && npm test` | no |
| Bot | `plan2code-bot/**` | `cd plan2code-bot && npm test` | no |
+26
View File
@@ -178,6 +178,32 @@ jobs:
echo "plan2code-app exited within 5s (exit code $?); smoke test failed"
exit 1
fi
- name: Smoke-test the dashboard frame connects (macOS)
if: runner.os == 'macOS'
shell: bash
# A window whose dashboard frame never signs in still passes the alive check above
# (WebKit gives the frame no cookie, so macOS signs it in by a path prefix:
# takeFramePrefix in routes.mjs). Here the app autostarts
# scripts/smoke-agent.mjs, which opens a real console as an agent would, and
# scripts/smoke-frame.mjs waits up to 60s for that console's /health to count the
# frame as a browser. Runs only where the matrix has macOS: manual runs and pull
# requests labeled `full-matrix`.
run: |
project="$(mktemp -d)"
export PLAN2CODE_CONSOLE_HOME="$(mktemp -d)"
export PLAN2CODE_CONSOLE_DIR="$GITHUB_WORKSPACE/src/web-console"
export PLAN2CODE_APP_AGENT_BIN="$(pwd)/scripts/smoke-agent.mjs"
# No browser of the console's own, so only the app's frame can count as one.
export PLAN2CODE_NO_BROWSER=1
target/release/plan2code-app --project "$project" --agent claude &
pid=$!
status=0
node scripts/smoke-frame.mjs "$PLAN2CODE_CONSOLE_HOME" || status=$?
kill "$pid" 2>/dev/null || true
# The console is detached from the agent, so it outlives the app: stop it from the
# project folder it was opened in, under the same console home.
(cd "$project" && node "$PLAN2CODE_CONSOLE_DIR/console.mjs" stop --all) || true
exit "$status"
node-tests:
name: npm test (${{ matrix.os }})
+1 -1
View File
@@ -18,7 +18,7 @@
"pretest": "node scripts/fix-line-endings.mjs",
"test:fast": "node scripts/test-fast.mjs",
"test:page": "node scripts/run-page-tests.mjs",
"test": "node scripts/check-test-lanes.mjs && node scripts/validate-char-count.js && node install.js --build-skills && node scripts/check-versions.mjs && node scripts/check-doc-size.mjs && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/check-prompt-wording.mjs && node scripts/check-console-openings.mjs && node scripts/node-test.mjs scripts/test-agent-lookup.mjs scripts/test-agents-file.mjs scripts/test-app-meter.mjs scripts/test-browser-helper.mjs scripts/test-check-console-openings.mjs scripts/test-check-doc-size.mjs scripts/test-check-prompt-wording.mjs scripts/test-check-test-lanes.mjs scripts/test-check-versions.mjs scripts/test-console-stub.mjs scripts/test-console-wire-budgets.mjs scripts/test-getting-started.mjs scripts/test-git-repo.mjs scripts/test-install-bench.mjs scripts/test-install-e2e.mjs scripts/test-install-refs.mjs scripts/test-install-update.mjs scripts/test-launcher.mjs scripts/test-line-endings.mjs scripts/test-publish-install-refs.mjs scripts/test-script-changelog.mjs scripts/test-script-changes.mjs scripts/test-script-coverage.mjs scripts/test-script-dead-code.mjs scripts/test-script-deps.mjs scripts/test-script-finalize.mjs scripts/test-script-git.mjs scripts/test-script-lessons.mjs scripts/test-script-pathfinder.mjs scripts/test-script-pr-prep.mjs scripts/test-script-run-check.mjs scripts/test-script-test-commands.mjs scripts/test-script-test-map.mjs scripts/test-script-test-match.mjs scripts/test-script-ui-prototype.mjs scripts/test-script-xray.mjs scripts/test-set-version.mjs scripts/test-skill-scripts.mjs scripts/test-skill-test-runs.mjs scripts/test-spec-carry-page.mjs scripts/test-spec-carry.mjs scripts/test-standalone-check.mjs scripts/test-ui-prototype-page.mjs scripts/test-us-english.mjs scripts/test-web-console-agents-doc.mjs scripts/test-web-console-card-rows.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-diff-parse.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-git.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-learning.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-notepad.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-changes.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-frame.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-layout.mjs scripts/test-web-console-page-learning.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-review-loop.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-setup.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-pointers.mjs scripts/test-web-console-prototypes.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-relative-urls.mjs scripts/test-web-console-review-loop.mjs scripts/test-web-console-send-state.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-shape.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-source.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-state.mjs scripts/test-web-console-strengths.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-workspace.mjs",
"test": "node scripts/check-test-lanes.mjs && node scripts/validate-char-count.js && node install.js --build-skills && node scripts/check-versions.mjs && node scripts/check-doc-size.mjs && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node scripts/check-prompt-wording.mjs && node scripts/check-console-openings.mjs && node scripts/node-test.mjs scripts/test-agent-lookup.mjs scripts/test-agents-file.mjs scripts/test-app-meter.mjs scripts/test-app-smoke-agent.mjs scripts/test-app-smoke-frame.mjs scripts/test-browser-helper.mjs scripts/test-check-console-openings.mjs scripts/test-check-doc-size.mjs scripts/test-check-prompt-wording.mjs scripts/test-check-test-lanes.mjs scripts/test-check-versions.mjs scripts/test-console-stub.mjs scripts/test-console-wire-budgets.mjs scripts/test-getting-started.mjs scripts/test-git-repo.mjs scripts/test-install-bench.mjs scripts/test-install-e2e.mjs scripts/test-install-refs.mjs scripts/test-install-update.mjs scripts/test-launcher.mjs scripts/test-line-endings.mjs scripts/test-publish-install-refs.mjs scripts/test-script-changelog.mjs scripts/test-script-changes.mjs scripts/test-script-coverage.mjs scripts/test-script-dead-code.mjs scripts/test-script-deps.mjs scripts/test-script-finalize.mjs scripts/test-script-git.mjs scripts/test-script-lessons.mjs scripts/test-script-pathfinder.mjs scripts/test-script-pr-prep.mjs scripts/test-script-run-check.mjs scripts/test-script-test-commands.mjs scripts/test-script-test-map.mjs scripts/test-script-test-match.mjs scripts/test-script-ui-prototype.mjs scripts/test-script-xray.mjs scripts/test-set-version.mjs scripts/test-skill-scripts.mjs scripts/test-skill-test-runs.mjs scripts/test-spec-carry-page.mjs scripts/test-spec-carry.mjs scripts/test-standalone-check.mjs scripts/test-ui-prototype-page.mjs scripts/test-us-english.mjs scripts/test-web-console-agents-doc.mjs scripts/test-web-console-card-rows.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-diff-parse.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-git.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-learning.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-loop.mjs scripts/test-web-console-notepad.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-changes.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-frame.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-layout.mjs scripts/test-web-console-page-learning.mjs scripts/test-web-console-page-loop.mjs scripts/test-web-console-page-notepad.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-review-loop.mjs scripts/test-web-console-page-send.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-setup.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-pointers.mjs scripts/test-web-console-prototypes.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-relative-urls.mjs scripts/test-web-console-review-loop.mjs scripts/test-web-console-send-state.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-shape.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-source.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-state.mjs scripts/test-web-console-strengths.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-tones.mjs scripts/test-web-console-workspace.mjs",
"test:games": "node scripts/node-test.mjs scripts/test-web-console-activities-bounce-arcade.mjs scripts/test-web-console-activities-bounce-cars.mjs scripts/test-web-console-activities-bounce-game.mjs scripts/test-web-console-activities-bounce.mjs scripts/test-web-console-activities-flock.mjs scripts/test-web-console-activities-ghoul-arms.mjs scripts/test-web-console-activities-ghoul-banister.mjs scripts/test-web-console-activities-ghoul-bog.mjs scripts/test-web-console-activities-ghoul-bones.mjs scripts/test-web-console-activities-ghoul-bonestair.mjs scripts/test-web-console-activities-ghoul-bossintro.mjs scripts/test-web-console-activities-ghoul-carnival.mjs scripts/test-web-console-activities-ghoul-cart.mjs scripts/test-web-console-activities-ghoul-chapel.mjs scripts/test-web-console-activities-ghoul-dice.mjs scripts/test-web-console-activities-ghoul-ending.mjs scripts/test-web-console-activities-ghoul-eye.mjs scripts/test-web-console-activities-ghoul-frozen.mjs scripts/test-web-console-activities-ghoul-gameover.mjs scripts/test-web-console-activities-ghoul-graveyard.mjs scripts/test-web-console-activities-ghoul-grounds.mjs scripts/test-web-console-activities-ghoul-gurney.mjs scripts/test-web-console-activities-ghoul-hearse.mjs scripts/test-web-console-activities-ghoul-heart.mjs scripts/test-web-console-activities-ghoul-intro.mjs scripts/test-web-console-activities-ghoul-lantern.mjs scripts/test-web-console-activities-ghoul-marrow.mjs scripts/test-web-console-activities-ghoul-mat.mjs scripts/test-web-console-activities-ghoul-mine.mjs scripts/test-web-console-activities-ghoul-mower.mjs scripts/test-web-console-activities-ghoul-pew.mjs scripts/test-web-console-activities-ghoul-retry.mjs scripts/test-web-console-activities-ghoul-ride.mjs scripts/test-web-console-activities-ghoul-sanatorium.mjs scripts/test-web-console-activities-ghoul-sled.mjs scripts/test-web-console-activities-ghoul-story.mjs scripts/test-web-console-activities-ghoul-tray.mjs scripts/test-web-console-activities-ghoul-village.mjs scripts/test-web-console-activities-ghoul-wagon.mjs scripts/test-web-console-activities-ghoul.mjs scripts/test-web-console-activities-rapids.mjs scripts/test-web-console-activities.mjs scripts/test-web-console-page-activities.mjs"
},
"devDependencies": {
+1
View File
@@ -33,6 +33,7 @@ There is no dot while busy or once a finished step has nothing left to press; a
| `src-tauri/` | The Rust app |
| `ui/` | The app page (plain HTML, CSS and JavaScript, no framework) |
| `fake-agent/` | A stand-in agent program the tests run in a real pseudo-terminal |
| `scripts/` | `vendor.mjs` (copies the xterm files into `ui/vendor/`), and CI's macOS frame check: `smoke-agent.mjs`, a stand-in agent that opens a real console, and `smoke-frame.mjs`, which waits for the console's `/health` to count the app's frame |
| `package.json` | The app's own npm packages (xterm, the Tauri CLI). Separate from the repo root so the root and the console stay dependency-free |
## Build and run
+33 -2
View File
@@ -37,11 +37,26 @@ file directly after checking it against the release's checksum list.
- [ ] `plan2code --classic` runs the agent in the terminal with the app installed
- [ ] Linux only: with `DISPLAY` and `WAYLAND_DISPLAY` unset, `plan2code` runs the terminal flow
- [ ] The desktop shortcut opens the folder menu (Choose a folder first, recent folders under it) and then the app
- [ ] macOS: started from the desktop shortcut or `plan2code` in Terminal, the app's window opens in
front of Terminal, as the active app
- [ ] macOS: the first start is stopped by Gatekeeper, **Open Anyway** in System Settings (Privacy &
Security) lets it through, and `docs/desktop-app.md` describes what you saw
- [ ] macOS and Linux: start the app from the Dock, Finder or a `.desktop` file (not a terminal) on
a machine where Node is only on PATH through nvm, Homebrew or Volta: the first-run checklist
still finds Node and the installed CLIs, and the console and an agent still start
- [ ] macOS: the same from Finder with Node set up by nvm in `~/.zshrc` only (not `~/.zprofile`):
Node and the agent are still found. With Node and an agent on the login PATH instead
(Homebrew, or nvm in `~/.zprofile`), `~/.zshrc` is not read at start, only on Check again;
with Homebrew's Node there but the agent installed by npm under nvm in `~/.zshrc`, the agent
is still found at start. A hung `~/.zprofile`
delays the start by 3 s at most and a hung `~/.zshrc` by 2 s; only a slow `~/.zprofile`
followed by a hung `~/.zshrc` reaches 5 s
- [ ] macOS and Linux: when the installer puts the `plan2code` command in a folder that is not on
PATH, its closing steps say so and name the line to add and the startup file to add it to;
done as written, `plan2code` runs in a new terminal
- [ ] macOS: canceling the folder picker (the `plan2code` launcher's, or Workspace's add folder)
reads as a cancel; a picker that fails instead (an `osascript` error other than -128) shows
an error in the console, and makes the launcher ask for the folder path to be typed
- [ ] Windows: SmartScreen's **More info**, then **Run anyway**, lets it through, and
`docs/desktop-app.md` describes what you saw
- [ ] `plan2code update` updates the skills, the command and the app, including while the app is
@@ -55,6 +70,8 @@ file directly after checking it against the release's checksum list.
## The window (each system)
- [ ] The dashboard shows in the frame and the terminal panel is visible beneath it
- [ ] macOS: the frame signs in by itself (WebKit gives it no cookie, so the console moves it under
its own `/f/<key>/` path on `127.0.0.1`); a blank frame or a sign-in page in it is a failure
- [ ] Resizing the window keeps both usable; dragging the handle resizes the panel
- [ ] The bar shows the project folder; the permission note appears only while an agent started
with checks off is running, never otherwise
@@ -112,7 +129,9 @@ Do each of Claude Code, Devin and Codex for a few minutes:
- [ ] Pasting several lines
- [ ] A line with Unicode and emoji
- [ ] Select text in the terminal: it copies on its own; Ctrl+Shift+C (Windows, Linux) or Cmd+C
(macOS) copies the selection too; Ctrl+V / Cmd+V pastes
(macOS) copies the selection too; Ctrl+V (Windows, Linux) or Cmd+V (macOS) pastes
- [ ] macOS: Cmd+V pastes the text once, at once, with no **Paste** menu popping up first
- [ ] macOS: Ctrl+V reaches the agent instead of pasting (Claude Code pastes a copied image with it)
- [ ] Exiting the agent: the agent menu reads "ended" with the reason beside it, and New Session stays
just left of it
@@ -121,10 +140,22 @@ Do each of Claude Code, Devin and Codex for a few minutes:
- [ ] Start, then **New Session**: it confirms once, with Planny on a coffee break and no claim about unsaved
work, then a fresh agent starts on the same agent, model, effort and permission mode, and the
dashboard shows the pick-up chip with a brief that matches the session
- [ ] macOS and Linux: once New Session's dashboard shows, `ps -Ao pid,command | grep server.mjs` lists
the new console only; the old one stopped when the window moved on from it
- [ ] An agent that ends by itself leaves the app asking nothing until New Session or **Change agent**
(in the agent menu) is pressed; Change agent reopens the launch card with a real choice to make again
- [ ] Closing the window while an agent runs asks first, and "no" keeps the window open
- [ ] Cmd+Q on macOS asks the same
- [ ] macOS: Cmd+Q and the app menu's Quit ask the same while an agent works, in the window; Quit
from the Dock's menu quits at once with no question, and its cleanup still runs
- [ ] macOS: with another app in front, the window's close button asks in front of it, and one
click on Quit quits; Cmd+Q with the window minimized brings the window back with the question
- [ ] macOS and Linux: after each way of quitting (Cmd+Q, the app menu's Quit, closing the window,
a plain `kill` of the app, Ctrl+C or closing the terminal when the app's program was run from
one, and on macOS Quit from the Dock), with an agent running, nothing is left:
`ps -Ao pid,pgid,command | grep -E 'plan2code-app|server.mjs'` shows no app, no agent or
process of its group, and no console the agent opened. After an agent that ended by itself,
the same shows no app and no console it opened, while a process it left running in its
group on purpose (a backgrounded dev server) is still there
- [ ] Windows only: start a CLI installed through npm (a `.cmd` shim), then New Session; check Task
Manager and confirm no leftover `node.exe` (or the CLI's own process) is left running
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env node
// A stand-in agent for CI's smoke run of the built app (.github/workflows/app.yml).
// Point PLAN2CODE_APP_AGENT_BIN at this file. Like a real agent, it opens a web
// console dashboard, with the environment the app gave it, so the console
// announces itself to the window and the dashboard frame has something to
// connect to (smoke-frame.mjs then checks it did). The repo's fake-agent opens
// no console, so it cannot stand in for this.
//
// It needs PLAN2CODE_CONSOLE_DIR (the folder holding console.mjs), ignores the
// arguments the app passes a real agent, and then waits on its input until it
// closes. It starts nothing else: the console server is detached, and the
// smoke run stops it with `console.mjs stop --all`.
import { spawnSync } from 'node:child_process';
import { join } from 'node:path';
const consoleDir = process.env.PLAN2CODE_CONSOLE_DIR;
if (!consoleDir) {
console.error('smoke-agent: PLAN2CODE_CONSOLE_DIR is not set; it names the folder holding console.mjs');
process.exit(2);
}
const open = spawnSync(process.execPath, [join(consoleDir, 'console.mjs'), 'open', '--workflow', 'dashboard'], {
stdio: ['ignore', 'inherit', 'inherit'],
});
if (open.error || open.status !== 0) {
console.error(`smoke-agent: console.mjs open failed (${open.error ? open.error.message : `exit ${open.status}`})`);
process.exit(1);
}
console.log('smoke-agent: dashboard open; waiting on input');
process.stdin.resume();
process.stdin.on('end', () => process.exit(0));
+100
View File
@@ -0,0 +1,100 @@
// Checks the app's dashboard frame connected to its console, for CI's macOS smoke
// run (.github/workflows/app.yml). A window that comes up but never signs its
// frame in looks alive to a process check; the console's own browser count
// does not lie.
//
// node smoke-frame.mjs [<console home>] [--timeout-ms N]
//
// The console home defaults to PLAN2CODE_CONSOLE_HOME. Waits for a session
// handle there (runtime/<project hash>/<sid>.json), then polls that session's
// open GET /health until it counts a browser. Exit 0 once one connects; exit 1
// when the time (60 s by default, for both waits together) runs out, with the
// last answer printed; exit 2 for a usage error.
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { parseArgs } from 'node:util';
const POLL_MS = 500;
const REQUEST_MS = 2000;
let parsed;
try {
parsed = parseArgs({ allowPositionals: true, options: { 'timeout-ms': { type: 'string' } } });
} catch (err) {
usage(err.message);
}
const home = parsed.positionals[0] || process.env.PLAN2CODE_CONSOLE_HOME;
if (!home) usage('no console home: pass one, or set PLAN2CODE_CONSOLE_HOME');
const timeoutMs = Number(parsed.values['timeout-ms'] ?? 60000);
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) usage('--timeout-ms takes a positive number');
const deadline = Date.now() + timeoutMs;
let last = null;
while (Date.now() < deadline) {
// Read again each round: a reconnect can resume the session on a new port.
const handle = newestHandle(home);
if (handle) {
last = await health(handle);
if (last.body && last.body.sid === handle.sid && last.body.browsers >= 1) {
console.log(`smoke-frame: the dashboard frame connected (browsers ${last.body.browsers}, port ${handle.port})`);
process.exit(0);
}
}
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
}
if (!last) {
console.error(`smoke-frame: no session appeared under ${home} within ${timeoutMs} ms`);
} else {
console.error(`smoke-frame: no browser connected within ${timeoutMs} ms; last /health answer from port ${last.port}: ${last.text}`);
}
process.exit(1);
function usage(message) {
console.error(`smoke-frame: ${message}\nusage: node smoke-frame.mjs [<console home>] [--timeout-ms N]`);
process.exit(2);
}
// The most recently written session handle under the home, or null.
function newestHandle(consoleHome) {
const runtime = join(consoleHome, 'runtime');
let newest = null;
for (const hash of safeList(runtime)) {
for (const name of safeList(join(runtime, hash))) {
if (!name.endsWith('.json')) continue;
const file = join(runtime, hash, name);
try {
const handle = JSON.parse(readFileSync(file, 'utf8'));
const mtime = statSync(file).mtimeMs;
if (Number.isInteger(handle.port) && handle.sid && (!newest || mtime > newest.mtime)) newest = { ...handle, mtime };
} catch {
// Half written or removed between the listing and the read: the next round sees it whole.
}
}
}
return newest;
}
function safeList(dir) {
try {
return readdirSync(dir);
} catch {
return [];
}
}
// One /health answer: the raw text for the failure message, and the body when it parsed.
async function health(handle) {
try {
const res = await fetch(`http://127.0.0.1:${handle.port}/health`, { signal: AbortSignal.timeout(REQUEST_MS) });
const text = await res.text();
let body = null;
try {
body = JSON.parse(text);
} catch {
// Not JSON: kept as text for the message.
}
return { port: handle.port, text: `${res.status} ${text}`, body };
} catch (err) {
return { port: handle.port, text: `no answer (${err.message})`, body: null };
}
}
+109
View File
@@ -0,0 +1,109 @@
// Tests for plan2code-app/scripts/smoke-agent.mjs, the stand-in agent CI's
// macOS smoke run starts in place of a real agent CLI. Run with:
// node --test scripts/test-app-smoke-agent.mjs
//
// The stand-in has one job: open a real web console the way an agent would,
// so the app's dashboard frame has something to connect to. This runs it
// outside the app, under a throwaway console home, and checks a live session
// appears and the stand-in ends when its input closes.
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 { spawn, spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const AGENT = path.join(HERE, "../plan2code-app/scripts/smoke-agent.mjs");
const CONSOLE_DIR = path.join(HERE, "../src/web-console");
// The desktop app's own variables would have the console announce itself to
// a live window. Deleted from the spawned environment, never inherited.
const APP_VARS = ["PLAN2CODE_IN_APP", "PLAN2CODE_APP_TOKEN", "PLAN2CODE_APP_VERSION", "PLAN2CODE_APP_ANNOUNCE", "PLAN2CODE_EMBED_ORIGIN", "PLAN2CODE_CONSOLE_SID"];
function outsideAppEnv(extra) {
const env = { ...process.env, ...extra };
for (const name of APP_VARS) delete env[name];
return env;
}
// Every session handle under a console home: runtime/<project hash>/<sid>.json.
function handles(consoleHome) {
const runtime = path.join(consoleHome, "runtime");
if (!fs.existsSync(runtime)) return [];
return fs.readdirSync(runtime).flatMap((hash) =>
fs
.readdirSync(path.join(runtime, hash))
.filter((name) => name.endsWith(".json"))
.map((name) => JSON.parse(fs.readFileSync(path.join(runtime, hash, name), "utf8")))
);
}
async function waitFor(check, ms) {
const end = Date.now() + ms;
while (Date.now() < end) {
const value = check();
if (value) return value;
await new Promise((resolve) => setTimeout(resolve, 100));
}
return check();
}
function pidAlive(pid) {
try {
process.kill(pid, 0);
return true;
} catch (err) {
return err.code === "EPERM";
}
}
test("smoke agent: is an executable Node script with no dependencies", { skip: process.platform === "win32" }, () => {
const source = fs.readFileSync(AGENT, "utf8");
assert.ok(source.startsWith("#!/usr/bin/env node\n"), "starts with a node shebang");
assert.ok((fs.statSync(AGENT).mode & 0o111) !== 0, "has its executable bits set");
for (const [, name] of source.matchAll(/from\s+["']([^"']+)["']/g)) {
assert.ok(name.startsWith("node:"), `imports only Node built-ins, not ${name}`);
}
});
test("smoke agent: opens a live dashboard session, then ends when its input closes", async (t) => {
const consoleHome = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-smoke-agent-home-"));
const project = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-smoke-agent-project-"));
const env = outsideAppEnv({ PLAN2CODE_CONSOLE_HOME: consoleHome, PLAN2CODE_NO_BROWSER: "1", PLAN2CODE_CONSOLE_DIR: CONSOLE_DIR });
let agent;
t.after(() => {
if (agent && agent.exitCode === null) agent.kill("SIGKILL");
// --all stops this folder's sessions, so it runs from the project, under the same home.
spawnSync(process.execPath, [path.join(CONSOLE_DIR, "console.mjs"), "stop", "--all"], { cwd: project, env, timeout: 15000 });
fs.rmSync(consoleHome, { recursive: true, force: true });
fs.rmSync(project, { recursive: true, force: true });
});
agent = spawn(process.execPath, [AGENT, "--some-agent-flag"], { cwd: project, env, stdio: ["pipe", "pipe", "pipe"] });
let output = "";
agent.stdout.on("data", (chunk) => (output += chunk));
agent.stderr.on("data", (chunk) => (output += chunk));
const exited = new Promise((resolve) => agent.on("exit", (code) => resolve(code)));
const handle = await waitFor(() => handles(consoleHome)[0], 20000);
assert.ok(handle, `a session appeared under the console home; agent said: ${output}`);
const health = await (await fetch(`http://127.0.0.1:${handle.port}/health`)).json();
assert.equal(health.ok, true);
assert.equal(health.sid, handle.sid, "the port answers for this session");
const state = JSON.parse(fs.readFileSync(path.join(consoleHome, "sessions", handle.sid, "state.json"), "utf8"));
assert.equal(state.workflow, "dashboard");
// Still running until its input closes, like an agent waiting for the person.
assert.equal(agent.exitCode, null, "the stand-in waits on its input");
agent.stdin.end();
const code = await Promise.race([exited, new Promise((resolve) => setTimeout(() => resolve("timeout"), 10000))]);
assert.equal(code, 0, `the stand-in exits cleanly once its input closes; agent said: ${output}`);
// The console outlives the agent (it is detached), so the stop below is what ends it.
const stop = spawnSync(process.execPath, [path.join(CONSOLE_DIR, "console.mjs"), "stop", "--all"], { cwd: project, env, encoding: "utf8", timeout: 15000 });
assert.equal(stop.status, 0, stop.stderr);
assert.equal(await waitFor(() => !pidAlive(handle.pid), 10000), true, "the console server is gone after stop --all");
});
+113
View File
@@ -0,0 +1,113 @@
// Tests for plan2code-app/scripts/smoke-frame.mjs, the check CI's macOS smoke
// run uses to prove the app's dashboard frame connected to the console. Run with:
// node --test scripts/test-app-smoke-frame.mjs
//
// No app and no real console: a session handle under a throwaway console home
// points at a tiny local server whose /health answers with a browser count the
// test controls.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import http from "node:http";
import os from "node:os";
import path from "node:path";
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const SCRIPT = path.join(HERE, "../plan2code-app/scripts/smoke-frame.mjs");
const SID = "20261108-000000-abcdef";
// A /health server answering with `browsers()` for this session.
async function healthServer(browsers) {
const server = http.createServer((req, res) => {
if (req.url !== "/health") return res.writeHead(404).end();
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify({ ok: true, sid: SID, browsers: browsers(), rev: 1, phase: "unknown" }));
});
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
return server;
}
// A console home holding one session handle, the way server.mjs writes it.
function consoleHomeFor(port) {
const home = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-smoke-frame-home-"));
const dir = path.join(home, "runtime", "0123456789abcdef");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path.join(dir, `${SID}.json`), JSON.stringify({ v: 1, sid: SID, pid: process.pid, port, url: `http://127.0.0.1:${port}/` }));
return home;
}
function run(args, env = {}) {
return new Promise((resolve) => {
const child = spawn(process.execPath, [SCRIPT, ...args], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"] });
let output = "";
child.stdout.on("data", (chunk) => (output += chunk));
child.stderr.on("data", (chunk) => (output += chunk));
child.on("exit", (code) => resolve({ code, output }));
});
}
test("smoke frame: passes once /health counts a browser", async (t) => {
let asked = 0;
const server = await healthServer(() => (++asked < 3 ? 0 : 1));
const home = consoleHomeFor(server.address().port);
t.after(() => {
server.close();
fs.rmSync(home, { recursive: true, force: true });
});
const { code, output } = await run([home, "--timeout-ms", "10000"]);
assert.equal(code, 0, output);
assert.ok(asked >= 3, "it kept polling while no browser was connected");
assert.match(output, /connected/);
});
test("smoke frame: fails with the last answer printed when no browser ever connects", async (t) => {
const server = await healthServer(() => 0);
const home = consoleHomeFor(server.address().port);
t.after(() => {
server.close();
fs.rmSync(home, { recursive: true, force: true });
});
const { code, output } = await run([home, "--timeout-ms", "1500"]);
assert.equal(code, 1, output);
assert.match(output, /"browsers":0/, "the last /health answer is printed");
});
test("smoke frame: fails when no session ever appears, and reads the home from PLAN2CODE_CONSOLE_HOME", async (t) => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-smoke-frame-empty-"));
t.after(() => fs.rmSync(home, { recursive: true, force: true }));
const { code, output } = await run(["--timeout-ms", "1000"], { PLAN2CODE_CONSOLE_HOME: home });
assert.equal(code, 1, output);
assert.match(output, /no session/i);
});
test("smoke frame: refuses to run with no console home", async () => {
const env = { ...process.env };
delete env.PLAN2CODE_CONSOLE_HOME;
const result = await new Promise((resolve) => {
const child = spawn(process.execPath, [SCRIPT], { env, stdio: ["ignore", "pipe", "pipe"] });
let output = "";
child.stderr.on("data", (chunk) => (output += chunk));
child.on("exit", (code) => resolve({ code, output }));
});
assert.equal(result.code, 2, result.output);
});
test("smoke frame: the CI step keeps the console from opening a browser, so only the frame can count", () => {
// Inside the app the console opens no browser of its own. If the app's signal
// to it were lost, `open` would start the runner's browser, which signs in by
// cookie and would pass this check with the frame dead.
const workflow = fs.readFileSync(path.join(HERE, "../.github/workflows/app.yml"), "utf8");
const start = workflow.indexOf("- name: Smoke-test the dashboard frame connects (macOS)");
assert.ok(start >= 0, "the frame step is there");
// The step runs to the blank line that ends it.
const end = workflow.indexOf("\n\n", start);
const step = workflow.slice(start, end === -1 ? undefined : end);
assert.match(step, /\n\s+export PLAN2CODE_NO_BROWSER=1\n/, step);
assert.ok(step.indexOf("PLAN2CODE_NO_BROWSER") < step.indexOf("target/release/plan2code-app"), "set before the app starts");
});
+2
View File
@@ -3,6 +3,7 @@
"test-agent-lookup.mjs",
"test-agents-file.mjs",
"test-app-meter.mjs",
"test-app-smoke-frame.mjs",
"test-browser-helper.mjs",
"test-check-console-openings.mjs",
"test-check-doc-size.mjs",
@@ -53,6 +54,7 @@
"test-web-console-tones.mjs"
],
"skipFast": [
"test-app-smoke-agent.mjs",
"test-console-stub.mjs",
"test-console-wire-budgets.mjs",
"test-fast.mjs",