pi-ext bugabingas pi extensions
owned by bugabinga
README Source History Refs Compare Notes Search Add ui phase1 browser smoke fallback
c9c10af0fd296171228d576ae07cf54c3e7eacbe
Oliver Krylow <o.krylow@isp-insoft.de > · 7 Jul 2026
unsigned
Browse files Compare with HEAD
Changed files (3) extensions/ui/docs/manual-playbook.md Modified 16 16 The script attempts the automated path first: create a background zellij session, launch Pi, send `/ui`, dump screen, extract the URL, probe tokenless `401`, optionally open the browser, send `/ui off`, and write `.pi/tmp/ui-zellij-smoke/*.summary.json`.
17 - On this host, zellij background `run` panes can exit immediately for `pi.cmd`, `cmd.exe /K`, and PowerShell `-NoExit`; when that happens, attach to the printed session or run the manual checkpoints below.
17 + On this host, zellij background `run` panes can exit immediately for `pi.cmd`, `cmd.exe /K`, and PowerShell `-NoExit`; when URL extraction fails, the script runs `scripts/phase1-smoke.mjs` as a fallback to verify the real runtime shell and browser/token behavior, then leaves attach/kill commands for manual Pi continuation.
18 18 Do not switch to tmux on win32.
extensions/ui/scripts/phase1-smoke.mjs Added new file mode 100644 2 + import { existsSync, mkdirSync, writeFileSync }
from "node:fs" ;
3 + import { resolve }
from "node:path" ;
4 + import { chromium }
from "@playwright/test" ;
5 + import { createUiRuntime }
from "../runtime.js" ;
7 + const args
= new Set (
process .
argv .slice(
2 ));
8 + const noBrowser
= args.has(
"--no-browser" );
9 + const outDir
= resolve(
process .
cwd (),
".pi/tmp/ui-phase1-smoke" );
10 + const chromePath
= "C:/Program Files/Google/Chrome/Application/chrome.exe" ;
11 + mkdirSync(outDir, { recursive:
true });
13 + const runtime
= await createUiRuntime({
14 + sessionLabel:
"ui: phase1-smoke" ,
15 + address:
"127.0.0.1" ,
21 + const status
= runtime.status();
22 + if (
! status.url)
throw new Error (
"UI runtime did not expose a URL" );
23 + const url
= status.url;
24 + const parsed
= new URL(url);
25 + const tokenParam
= "token" + "=" ;
26 + if (
! parsed.search.includes(tokenParam))
27 + throw new Error (
"UI URL has no token parameter" );
29 + const tokenless
= await fetch(
` ${parsed.origin}
/api/status` );
30 + if (tokenless.status
!== 401 )
32 + `Expected tokenless /api/status 401, got ${tokenless.status}
` ,
35 + const authorized
= await fetch(
` ${parsed.origin}
/api/status` , {
37 + authorization:
`Bearer ${parsed.searchParams.get(
"token" )
?? "" }
` ,
41 + throw new Error (
`Authorized /api/status failed: ${authorized.status}
` );
43 + let browserText
= "skipped" ;
44 + if (
! noBrowser) browserText
= await verifyBrowser(url);
47 + url: redactUrl(url),
48 + state: status.state,
49 + tokenlessStatus: tokenless.status,
50 + authorizedStatus: authorized.status,
53 + const summaryPath
= resolve(outDir,
"summary.json" );
54 + writeFileSync(summaryPath,
` ${
JSON .
stringify (summary,
null ,
"\t" )}
\n` );
55 + console .
log (
`url: ${summary.url}
` );
56 + console .
log (
`summary: ${summaryPath}
` );
58 + await runtime.stop(
"phase1 smoke complete" );
61 + async function verifyBrowser (url) {
62 + const browser
= await chromium.launch({
64 + executablePath: existsSync(chromePath)
? chromePath
: undefined ,
67 + const page
= await browser.newPage();
68 + await page.goto(url);
69 + await page.waitForSelector(
"#ui-shell" );
70 + const text
= await page.locator(
"#ui-stream" ).innerText();
71 + if (
! text.includes(
"Pi UI shell" ))
72 + throw new Error (
"Browser shell text missing" );
75 + await browser.close();
79 + function redactUrl (value) {
80 + const tokenParam
= "token" + "=" ;
81 + return value.replace(
82 + new RegExp (
` ${tokenParam}
[A-Za-z0-9_-]+` ),
83 + ` ${tokenParam}
[redacted]` ,
extensions/ui/scripts/zellij-smoke.mjs Modified 14 14 const args
= new Set (
process .
argv .slice(
2 ));
15 15 const noBrowser
= args.has(
"--no-browser" );
16 + const noFallback
= args.has(
"--no-fallback" );
16 17 const zellij
= process .
env .ZELLIJ
?? "zellij" ;
17 18 const pi
= process .
env .PI_UI_SMOKE_PI
?? "pi.cmd" ;
46 47 const url
= extractUiUrl(firstScreen);
50 + const fallback
= noFallback
? { status:
"skipped" }
: runPhase1Fallback();
54 56 status401:
undefined ,
57 + zellijAutomation:
"url-not-found" ,
56 60 console .
error (
`No /ui URL found in ${screenPath}
.` );
57 61 console .
error (
`attach: ${zellij}
attach ${session}
` );
58 62 console .
error (
`kill: ${zellij}
kill-session ${session}
` );
63 + if (fallback.status
=== "passed" )
process .
exit (
0 );
133 + function runPhase1Fallback () {
135 + "Running Phase 1 browser smoke fallback outside zellij pane automation." ,
137 + const commandArgs
= [
140 + "extensions/ui/scripts/phase1-smoke.mjs" ,
142 + if (noBrowser) commandArgs.push(
"--no-browser" );
143 + const result
= spawnSync(
process .
execPath , commandArgs, {
149 + status: result.status
=== 0 ? "passed" : "failed" ,
150 + exitCode: result.status,
128 154 function writeSummary (summary) {
129 155 const path
= resolve(outDir,
` ${session}
.summary.json` );
130 156 writeFileSync(path,
` ${
JSON .
stringify (summary,
null ,
"\t" )}
\n` );