mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-12-05 08:15:41 -08:00
Fail the macOS smoke run when the dashboard frame never connects, and update the checklist
AI Assisted
This commit is contained in:
1 parent
a9e0bf49f0
commit
615e98e11e
10 files changed
+418
-3
No files matched your search
Executable
+32
@@ -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));
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user