Skip to content

test(harness): open the scaffolded Workbench in a real browser (SP4, step 1) - #750

Merged
blove merged 15 commits into
mainfrom
blove/sp4-workbench-browser-gate
Sep 19, 2026
Merged

blove merged 15 commits into
mainfrom
blove/sp4-workbench-browser-gate

Conversation

@blove

@blove blove commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes the last open item of the Workbench arc: a seventh web assertion (W7) in the generated-app activation harness opens the scaffolded Workbench in headless Chromium — through the real CopilotKit runtime to the real B4 server, aimock behind it — sends a prompt, waits for the run to settle, and restores the thread after a reload. It reuses the journey helpers docs/brand/demo/capture.mjs already exports for the README recording, so the gate and the recording share one journey.

Spec: docs/superpowers/specs/2026-09-19-workbench-browser-gate-design.md · Plan: docs/superpowers/plans/2026-09-19-workbench-browser-gate.md.

Why now

npm create b4-app@latest is the advertised activation everywhere, and nothing in CI rendered the scaffolded Workbench: the harness's six web assertions are HTTP-only and the only research e2e runs against the example, asserting transport selection. The three historical "green tests, dead UI" defects (StrictMode useRef latch, connect predicate on the wrong server, array-form content hydrating blank) were all only visible on a rendered page; since then the template took CopilotKit 1.68→1.70 and 0.8.32–0.8.33 changed what the Workbench renders, with PRs merging on bot auto-approval while review credits are out.

Shape

  • No new job, runner, or test-id contract. W7 attaches to the app the harness has already scaffolded, installed, and booted; harness-verify gains one playwright install --with-deps chromium step and is already LANE_3 of the required validate aggregate.
  • The browser is injected, so the journey (test/harness/workbench-browser.ts) has 21 unit tests with a fake browser; the two audited workflow fixtures are regenerated for the new step (churn limited to harness-verify).
  • Fail closed, diagnosable. A missing Chromium fails in seconds via a preflight before the multi-minute scaffold. Any failure writes a full-page screenshot to the repo-relative artifacts/testing/ tree — the only path harness-verify uploads — and the activation test's wrapper error now carries the flattened cause chain, because vitest's JSON reporter drops { cause } (the first live failure showed only file paths).

Found by running it live, not by review

  • aimock matches userMessage as a substring (@copilotkit/aimock router.js:217, no requestTransform) and breaks ties by registration order. The README's DEMO_PROMPT is a prefix of the harness's SAFE_PROMPT, so the gate uses its own BROWSER_PROMPT and asserts at registration that no registered prompt is a proper substring of another. Corollary recorded in the plan: a mutation that appends to a prompt still matches and proves nothing — mutate the evidence.
  • The Workbench's hydrate probes on a new thread 404 by design (/api/b4/threads/:id/state, /pending_interrupts — W2 asserts that same 404) and Chromium logs them as console errors. The console-error check tolerates exactly a 404 on those two pathnames; a 500 there or a 404 anywhere else still fails.
  • restoreWorkbenchThread uses one string for both the rail row (the truncated 80-char title) and the transcript text, so gate prompts must be trimmed and ≤80 chars — checked before launch.

Verified

Lane (pnpm verify:harness:framework) green; activation test 215 s (pre-W7 measured range 174–230 s — W7's cost is inside run-to-run variance)
Mutation: wrong answer exit 1; message carries caused by: locator.waitFor: Timeout 120000ms … getByText('… (mutated)'); screenshot present at the uploaded path
Mutation: empty PLAYWRIGHT_BROWSERS_PATH fails in 0 s with Chromium is not installed … run: pnpm exec playwright install chromium — no skip
Unit workbench-browser.test.ts 21/21; flattenCause 7/7
Gates typecheck 0 · root lint 0 · workflow-contracts.test.mjs 166/166 · test:release-integrity 0 · check-docs 0

Conscious choice: --with-deps puts an apt-get in validate's required path for the first time. Kept for consistency with the three sibling browser lanes; the alternative (a missing shared library after a Playwright bump) fails deterministically with a worse message.

Risk register (first ten CI runs)

  • --with-deps is new exposure for validate — the three pre-existing playwright install --with-deps steps all live in jobs outside the required lanes; an apt mirror hiccup can now red validate.
  • The exact +3 journal delta has no tolerance. A CopilotKit reconnect, a StrictMode remount that re-issues, or a Next dev Fast Refresh mid-run changes the count and fails. That strictness is the point (it is what catches a double-run), and it is the most likely source of an early red.
  • Cold next dev compile of the shell route under openReadyWorkbench's 60 s budget on a 2-core runner; W1–W6 warm the API routes in the same session, not the page.
  • harness-verify headroom — first CI run on ubuntu-latest: 13.2 min against timeout-minutes: 30 (~12 min baseline; Chromium install + W7 cost ≈ 1 min).
  • New transitive coupling — the activation test now loads docs/brand/demo/capture.mjs's module graph; a breaking edit to the README-recording scenario reds harness-verify, not just media:readme:capture.
  • No retries, deliberately — a retry would re-run against a thread the first attempt persisted; a single flake is a hard red.
  • Hand-maintained mirrors nothing type-checks: capture.d.mts vs capture.mjs, and THREADS_STORAGE_KEY / MAX_THREAD_TITLE_LENGTH vs thread-source.ts — both verified against source in review.

Not covered (step 2)

The gated journey ("Trigger a permission prompt" → Allow once), the memory panel, and plan/subagent card assertions. Those are the spec's original list and may justify a test-ids contract; this lands first so the lane's CI cost is measured before widening it.

🤖 Generated with Claude Code

blove and others added 14 commits September 19, 2026 08:55
Promotes the README capture journey into a required CI assertion: a seventh
web check inside the generated-app activation harness drives the scaffolded
Workbench in headless Chromium against aimock, reusing the exported helpers
from docs/brand/demo/capture.mjs. No new job, runner, or test-id contract.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… step 1)

Six tasks: capture.mjs type declarations, an injected-browser journey helper
with five unit tests, W7 wired into the activation test, the harness-verify
Chromium step, a local acceptance run with two mutations proving the gate
binds and fails closed, and the PR.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The activation harness will drive the scaffolded Workbench through the same
journey the README recording uses. test/tsconfig.json has no allowJs, so the
.mjs helpers need a declaration file to be importable from TypeScript.

Named the file capture.d.mts, not capture.d.ts: TypeScript only resolves a
declaration for an .mjs module from a matching .d.mts sibling under
moduleResolution Bundler, confirmed by rerunning typecheck against each name.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…wser

Open the scaffolded Workbench, send a prompt, wait for the run to settle,
read the persisted thread id, reload and restore the thread, and fail on any
console or page error. The browser is a dependency so the ordering, the
fail-closed paths, and the screenshot-on-failure are unit-tested without
Chromium.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Task 1 found that a .d.ts sibling does not type a .mjs import under
moduleResolution Bundler; only .d.mts does. Update the plan and spec so
Task 3's scenario declaration is created with the right extension.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…s constants

- Attach collected console/page errors to the failure that triggered the
  screenshot (cause chain), instead of dropping them when restoration or any
  other step throws.
- Match the persisted thread's title against the Workbench's own
  normalisation (trim + MAX_TITLE_LENGTH truncation from thread-source.ts)
  instead of the raw prompt, and make a missing-id failure diagnosable: which
  case happened (absent key / invalid JSON / non-array / no match / non-string
  id) and, when relevant, the titles that were actually found.
- Extract findPersistedThreadId as a pure, exported, unit-tested function;
  the page.evaluate callback is now a thin localStorage.getItem wrapper with
  no closures, and JSON.parse is guarded so malformed storage never throws.
- Stop casting the fake chromium to `never` in the test: type it against
  WorkbenchBrowserDeps["chromium"] so a new required member on the deps
  interface fails the fake at typecheck, not silently.
- Fix capture.d.mts: restoreWorkbenchThread resolves { stateUrl }, not void;
  note that nothing type-checks this file against the .mjs, so signature
  changes there must be mirrored here by hand.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…sation

thread-source.ts stores threads newest-first, so the loop's last-match-wins
reassignment resolved the OLDEST thread with the prompt's title. Take the
first match instead, and cover the title normalisation (trim + 80-char
truncation) with a prompt long enough for it not to be an identity.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…mium

The seventh web assertion opens the generated web client in a real browser,
sends the README demo prompt through the CopilotKit runtime to the B4 server,
waits for the run to settle, and restores the thread after a reload. Fails
closed on a missing browser, a missing persisted thread, or any console error.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…t live run

aimock matches userMessage as a substring, so the demo prompt (a prefix of
SAFE_PROMPT) is replaced by a dedicated gate prompt with a collision guard;
the designed 404 hydrate probes are allowlisted; the screenshot moves to the
uploaded artifacts tree; the wrapper error carries the cause chain; the
missing-browser check runs before the scaffold.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…bes, aborts, prompts, and CI artifacts

The gate now tolerates exactly the two hydrate probes' 404s on a new thread
(a 500 on them or a 404 elsewhere still fails), honours the harness lifecycle
signal, rejects a prompt the thread rail could never round-trip, and writes its
screenshot where harness-verify uploads from. W7 stops borrowing the README
demo scenario — aimock matches userMessage as a substring, so DEMO_PROMPT being
a prefix of SAFE_PROMPT was a latent collision that only registration order
hid; W7 now has its own prompt, and a guard fails fast on the next such pair.
The wrapper flattens its cause chain into the message so the JSON reporter
carries the real failure into CI.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Adds the Playwright Chromium install before the harness lanes and re-audits the two workflow-entrypoint fixtures for the new step.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
aimock matches userMessage as a substring, so an appended prompt still matches
its fixture and the appended-prompt mutation passes. The binding mutation is a
wrong answer, which the restore step must fail to find.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Sep 19, 2026 5:20pm UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

The spec's journey step and its mutation still named DEMO_PROMPT and the
inert wrong-prompt mutation; the plan's self-review claimed a scenario.d.mts
that Task 3 removed. Record the executed design.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@blove
blove marked this pull request as ready for review September 19, 2026 17:20

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@blove
blove merged commit 3a26d1a into main Sep 19, 2026
31 of 33 checks passed
@blove
blove deleted the blove/sp4-workbench-browser-gate branch September 19, 2026 19:51

This branch was successfully deployed

1 active and 1 inactive deployments
Preview — 64fa1413 Deployed Sep 19, 2026 by vercel[bot]
vercel-preview — 64fa1413 Deployed Sep 19, 2026 by blove via vercel-native #2116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant