summaryrefslogtreecommitdiff
path: root/tests/brainstorm-server
AgeCommit message (Collapse)Author
2026-06-18test(deps): bump ws to ^8.21.0 in brainstorm-server testsJesse Vincent
Clears two dependabot alerts on the test harness's ws dependency: GHSA-96hv-2xvq-fx4p (high, memory-exhaustion DoS, fixed 8.21.0) and GHSA-58qx-3vcg-4xpx (medium, uninitialized memory disclosure, fixed 8.20.1). Test-only — the shipped brainstorm server hand-rolls its WebSocket framing and does not depend on ws. Suite passes (57/57).
2026-06-16fix: read Codex plugin version from manifest (PRI-2240)Drew Ritter
2026-06-16Add visual companion Prime Radiant brandingDrew Ritter
2026-06-16Fix companion stop metadata and token permissionsDrew Ritter
2026-06-16Harden Windows browser launcherDrew Ritter
2026-06-16Fix Windows lifecycle validationDrew Ritter
2026-06-16Fix companion test cleanup and argv assertionsDrew Ritter
2026-06-16Harden companion platform testsDrew Ritter
2026-06-16Fix companion lifecycle test ownership metadataDrew Ritter
2026-06-16Harden companion stop ownership proofDrew Ritter
2026-06-16Isolate companion fallback tokensDrew Ritter
2026-06-16Fix server test fallback cleanupDrew Ritter
2026-06-16Harden root screen containmentDrew Ritter
2026-06-16Harden companion Windows lifecycle coverageDrew Ritter
2026-06-16Harden brainstorm companion auth regressionsDrew Ritter
2026-06-16fix(brainstorm-server): fix auth-integration bugs from full-branch reviewJesse Vincent
A second adversarial review of the merged branch found that combining the session-key auth with the feature work created real bugs the (vacuous) tests missed: - [Critical] GET /files/ (empty name) resolved to CONTENT_DIR and crashed the process with uncaught EISDIR — newly reachable because the query-stripping refactor turns /files/?key=... into /files/. Reject non-regular-file names. - [High] --open opened a KEYLESS url, which the auth gate 403s — the headline feature landed on the error page. Open the keyed url. - [High] Same-port restart regenerated the token (port persisted, token not), so the open tab's old cookie 403'd and never reconnected — contradicting the documented promise. Persist the token (BRAINSTORM_TOKEN_FILE / .last-token) alongside the port. - [Medium] Token sat in world-readable server-info/server.log (0644 in /tmp). umask 077 in start-server.sh + mode 0600 on server-info/.last-token. - [Medium] touchActivity() ran before the auth check, so unauthenticated requests defeated the idle timeout. Count activity only after authorization. - [Low] COOKIE_NAME embedded the pre-fallback port; derive it from the actual bound port (also prevents a cross-server cookie-jar collision on fallback). Tests added/strengthened (previously passed vacuously): /files/ no-crash; the auto-open url carries the key and is reachable (200); restart reuses the same key not just the port; unauthenticated requests don't reset the idle clock. Full suite green (ws-protocol 32, helper 12, auth 13, server 29, lifecycle 8, stop-server 4); restart smoke confirms same port+key and old URL -> 200.
2026-06-16test(brainstorm-server): thread session key through tests after auth mergeJesse Vincent
Integrating the per-session-key auth onto the same branch as the dotfile and lifecycle work: two tests added after the auth commit opened WebSockets without a key (server.test.js dotfile-reload, lifecycle.test.js idle-shutdown), which the auth gate now resets. Pass ?key=/BRAINSTORM_TOKEN in both. Full suite green: ws-protocol 32, helper 12, auth 13, server 28, lifecycle 7, stop-server 4.
2026-06-16feat(brainstorm-server): gate every endpoint behind a per-session keyJesse Vincent
The companion server is reachable by any local browser tab (default loopback bind) and by any host that can route to it (remote --host bind). It served screens, files, and accepted event-injecting WebSocket connections with no authentication, so a malicious browser tab or a direct remote client could read brainstorm content or inject events that the agent reads as the user's input (prompt injection into a live session). Generate a per-session secret token, carry it in the served URL as ?key=, and mirror it into an HttpOnly SameSite=Strict per-port cookie on first load so same-origin subresources and the WebSocket handshake authenticate automatically. Every HTTP request and WebSocket upgrade now requires a valid key (query or cookie, constant-time compared); unauthenticated requests get a friendly 403 explaining they need the full URL. A secret authenticates the client uniformly across loopback, tunnel, and remote binds and defeats DNS rebinding, which a Host/Origin allowlist cannot. Also guard handleMessage against a null JSON payload that crashed the process. Tests: new auth.test.js (13 cases) covering the key on /, /files/*, and WS plus cookie bootstrap and the null-payload guard; server.test.js threads the key; ws-protocol.test.js + auth.test.js wired into npm test. Closes #1014 Refs #1110, #1553, #1504
2026-06-16fix(brainstorm-server): tie stop-server PID check to the session's portJesse Vincent
The node+server.cjs command match (from the adversarial review) still matched any unrelated node process running a file named server.cjs. When we recorded the bound port (state/server-info) and lsof is available, additionally require the PID to be the process actually LISTENING on this session's port — which rules out a different project's server.cjs / editor task runner that recycled the stale PID. Falls back to the command match when the port or lsof isn't available. Test: a 'node server.cjs' process not listening on the recorded port is spared. Refs #1703
2026-06-16fix(brainstorm-server): address adversarial review findingsJesse Vincent
From a two-reviewer adversarial pass: - [High] EADDRINUSE fallback clobbered the shared .last-port: onListen wrote the bound port unconditionally, so a fallback to a random port overwrote the preferred port another live session still owns — stranding that session's open tab forever. Now persist only when we bound the preferred port (not on fallback). The fallback test now asserts .last-port integrity (teeth-verified). - [Medium] maybeOpenBrowser ran the URL through a shell (exec + JSON.stringify), which does NOT neutralize $(...) in a url-host. Platform launchers now use execFile with the URL as an argv element (no shell). The operator-set BRAINSTORM_OPEN_CMD path stays shell-based (trusted input). - [Medium] --open was a silent no-op on native Windows (no win32 branch). Added. - [Medium] helper.js reconnect/status/tombstone had only substring-grep tests. Added behavioral tests driving the state machine against a mocked browser: Reconnecting+backoff (500->1000->2000), tombstone after the grace period, and reload-on-recovery. - [Low] status pill showed a false 'Connected' before the socket opened; now starts 'Connecting…' until onopen. Not changed (flagged): stop-server.sh's PID-ownership check still matches any 'node ... server.cjs' (narrow residual — a recycled PID onto an unrelated node server.cjs); robust fix needs fragile cross-platform process introspection.
2026-06-16feat(brainstorm-server): opt-in auto-open of the browser on the first screenJesse Vincent
When the user approves the visual companion, open their browser automatically the first time a screen is actually ready to show — rather than at startup (just the waiting page) or making them open the URL by hand. Opt-in and gated on approval: off unless BRAINSTORM_OPEN is set (start-server.sh --open, which the agent passes only after the user agrees to use the companion). Even then it fires once, and is skipped if a browser is already connected, on a non-loopback/remote bind, or when headless. Launcher is the platform default (open / xdg-open / WSL cmd.exe) or BRAINSTORM_OPEN_CMD; best-effort, never fatal. lifecycle.test.js: opens once on the first screen when approved; does NOT open without approval. Closes #755 Refs #759
2026-06-16feat(brainstorm-server): reuse the same port on session restartJesse Vincent
When the companion idle-shuts-down and the agent restarts it, a fresh random port meant the user's open browser tab pointed at a dead URL. Persist the bound port per project and prefer it on the next start, so the restarted server comes up on the same port and the open tab's reconnect just works. - start-server.sh exports BRAINSTORM_PORT_FILE=<project>/.superpowers/brainstorm/ .last-port for project sessions (not /tmp). - server.cjs prefers an explicit BRAINSTORM_PORT, else the recorded port, else random; writes the actually-bound port back; and on EADDRINUSE (preferred port still in use) falls back to a random port once instead of crashing. lifecycle.test.js: restart reuses the recorded port; a taken preferred port falls back to a random one without crashing. Refs #1237
2026-06-16feat(brainstorm-companion): resilient reconnect, live status, paused overlayJesse Vincent
The injected client reconnected on a fixed 1s timer with no feedback: if the laptop slept or the server restarted, the page showed 'Connected' over a dead socket and silently queued events. And when the server stopped, the user got a bare connection-refused with no explanation. helper.js now: - reconnects with exponential backoff (500ms, doubling, capped at 30s; reset on open), with an onerror->close handler, nulls the socket on close, and clears a pending timer before scheduling another; - drives the frame status pill Connected/Reconnecting/Disconnected via a --status-color custom property (frame-template.html); - after ~15s disconnected, shows a self-styled 'Companion paused' overlay (tombstone) explaining the companion stopped and will reconnect automatically; - on recovery from a tombstoned outage (e.g. server restarted on the same port) reloads to pick up the restarted server's current screen. The reconnect-backoff is an exported pure function; helper.test.js unit-tests it (doubling + cap progression) and asserts the status/tombstone/reconnect wiring. DOM behaviour is verified live. Refs #856, #1237
2026-06-16feat(brainstorm-server): 4h configurable idle timeout; close WS on shutdownJesse Vincent
The companion shut down after only 30 minutes idle — too short for real brainstorming, where a single question can sit far longer. And shutdown() never closed upgraded WebSocket sockets, so an open browser connection could keep the Node process alive after it was supposed to exit. - Default idle timeout raised to 4 hours, configurable via BRAINSTORM_IDLE_TIMEOUT_MS and start-server.sh --idle-timeout-minutes (validated positive integer). - Reported as idle_timeout_ms in the server-started JSON / server-info. - shutdown() now destroys all client sockets so the process exits even with an open WebSocket. - Watchdog check interval is configurable (BRAINSTORM_LIFECYCLE_CHECK_MS, default 60s) so the lifecycle can be tested without minute-long waits. Adds lifecycle.test.js (configured timeout reported; idle shutdown exits despite an open WS — teeth-verified; the start-server flag). Wires ws-protocol, lifecycle, and stop-server suites into npm test. Closes #1237 Refs #1689
2026-06-16fix(brainstorm-server): verify PID ownership before stoppingJesse Vincent
stop-server.sh read server.pid and SIGKILL'd that PID with no checks. After a reboot or PID wraparound the pid file can point at an unrelated, live process — which we would then kill. Verify the PID is actually our server (a running 'node ... server.cjs') before signalling it. If ownership can't be proven, fail closed: remove the stale pid file and report {status: stale_pid} without killing anything. Real servers still stop ({status: stopped}); a missing pid file still reports not_running. Adds stop-server.test.sh covering: an unrelated reused PID is left alone, a real server is stopped, and a missing pid file. Refs #1703
2026-06-16fix(brainstorm-server): ignore macOS resource-fork dotfilesJesse Vincent
On macOS (and ExFAT/SMB volumes) the OS writes ._<name>.html sidecar files holding binary resource-fork metadata. These end with .html, so they passed the content filter and could be picked as the newest screen — serving binary garbage to the browser instead of the mockup — or fetched via /files/. Skip dotfiles (leading '.') at all four sites that list or serve content: getNewestScreen, the /files/ endpoint, the known-files seed, and the fs.watch handler. Tests cover serving (/ and /files/) and the watch path (a ._ file must not trigger a reload). Refs #950
2026-06-16fix(brainstorming): cap websocket frame payloadsRahul
2026-06-16Align windows-lifecycle test with current brainstorm server layoutJesse Vincent
The test had drifted behind three server implementation changes and no longer ran against the actual server: - Server entrypoint renamed from server.js to server.cjs; the test still invoked node on server.js and failed with MODULE_NOT_FOUND. - Server state moved to a state/ subdirectory (state/server-info, state/server.pid); the test still waited on .server-info and wrote .server.pid at the session root. - Owner-PID startup validation now keeps the server running when the owner PID is dead at startup: it logs owner-pid-invalid, disables owner monitoring, and falls back to the idle timeout. The test still expected the server to self-terminate within 60s of a dead-at-startup owner. Update file/path references to match the current server, and rewrite the dead-at-startup test to assert the current behavior: server survives, log contains owner-pid-invalid, log does not contain a spurious "owner process exited" line. Verified locally: 9 passed, 0 failed, 3 skipped (Windows-only).
2026-06-16Phase D: cross-runtime tweaks (visual-companion, executing-plans, test)Jesse Vincent
Misc platform/runtime statements and adjacencies that don't fit the prose, config-ref, README-ordering, or tool-vocabulary buckets: - visual-companion frame template: rename CSS/HTML id #claude-content → #frame-content. The id is purely styling — nothing external references it. The brainstorm-server test that asserted the old string is updated in lockstep. - visual-companion launch instructions: add a Copilot CLI section alongside Claude Code, Codex, and Gemini CLI; combine the Claude Code (macOS / Linux) and (Windows) sections so heading style matches the other (non-OS-qualified) platforms. - visual-companion: "Use Write tool" → "Use your file-creation tool" for the cat/heredoc warning. The prohibition is what's load- bearing, not the tool name. - executing-plans/SKILL.md: list all subagent-capable runtimes (Claude Code, Codex CLI, Codex App, Copilot CLI, Gemini CLI) and point at the per-platform tool refs as the source of truth. - executing-plans/SKILL.md: relative path "using-superpowers/ references/" → "../using-superpowers/references/" to resolve correctly from the executing-plans/ directory. No bundled spec doc here — Phase D was scope-extension work that took place across rounds, with no standalone spec authored.
2026-03-25Separate brainstorm server content and state into peer directoriesJesse Vincent
The session directory now contains two peers: content/ (HTML served to the browser) and state/ (events, server-info, pid, log). Previously all files shared a single directory, making server state and user interaction data accessible over the /files/ HTTP route. Also fixes stale test assertion ("Waiting for Claude" → "Waiting for the agent"). Reported-By: 吉田仁
2026-03-25Revert "Move brainstorm server metadata to .meta/ subdirectory"Jesse Vincent
This reverts commit ab500dade6187cf78b9b263ecf4799ec3420d1ef.
2026-03-25Move brainstorm server metadata to .meta/ subdirectoryJesse Vincent
Metadata files (.server-info, .events, .server.pid, .server.log, .server-stopped) were stored in the same directory served over HTTP, making them accessible via the /files/ route. They now live in a .meta/ subdirectory that is not web-accessible. Also fixes a stale test assertion ("Waiting for Claude" → "Waiting for the agent"). Reported-By: 吉田仁
2026-03-17fix : resolve ESM/CommonJS module confict in brainstorming serversarbojitrana
2026-03-17fix: Windows brainstorm server lifecycle, restore execution choicejesse
- Skip OWNER_PID monitoring on Windows/MSYS2 where the PID namespace is invisible to Node.js, preventing server self-termination after 60s (#770) - Document run_in_background: true for Claude Code on Windows (#767) - Restore user choice between subagent-driven and inline execution after plan writing; subagent-driven is recommended but no longer mandatory - Add Windows lifecycle test script verified on Windows 11 VM - Note #723 (stop-server.sh reliability) as already fixed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11Add design spec and tests for zero-dep brainstorm serverJesse Vincent
Replace vendored node_modules (714 files) with a single server.js using only Node built-ins. Spec covers WebSocket protocol, HTTP serving, file watching, and static file serving. Tests written before implementation (TDD). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09Move brainstorm-server into skill directory per agentskills specJesse Vincent
Moves lib/brainstorm-server/ → skills/brainstorming/scripts/ so the brainstorming skill uses relative paths (scripts/start-server.sh) instead of ${CLAUDE_PLUGIN_ROOT}/lib/brainstorm-server/. This follows the agentskills.io specification for portable, cross-platform skills. Updates visual-companion.md references and test paths. All tests pass.
2026-03-06Add brainstorm server with WebSocket support, helpers, and testsJesse Vincent
WebSocket server for real-time browser communication during brainstorming sessions. Includes browser helper library for event capture, shell scripts for server lifecycle management with session isolation and persistent mockup storage, and integration tests. Co-Authored-By: Drew Ritter <drew@ritter.dev>