Skip to content

feat(scripts): one command sets up a live-test server in a worktree - #551

Merged
Jacksondr5 merged 22 commits into
j5/mainfrom
j5code/setup-agent-live-test
Oct 12, 2026
Merged

Jacksondr5 merged 22 commits into
j5/mainfrom
j5code/setup-agent-live-test

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Problem

An agent that needs to live-test J5 Code rebuilds the same rig by hand each time, and copies of real data have reached real repositories. Part of #546 (stage 2: the default mode of setup-agent-live-test).

What changed

node scripts/j5/setup-agent-live-test.ts, run from a worktree, builds a test home and starts a dev server on it. It then prints what only the script knows about the run: the pairing URL, ports, home and log paths, the one project to use, the default model, the personas and playbooks, the two hold-gate commands, and its own status, restart, stop and rebuild commands. How to test is the j5-live-test skill's job (#549) and is not repeated in the output.

The test home, the test repository and the logs live in the worktree's gitignored .j5code/live-test/:

  • test-repo/: a small TODO app with four commits, a node --test suite run with pnpm test (no dependencies, nothing to install), scripts/hold.sh (blocks until .hold-release exists in the test repository root, deletes it and exits; gives up after 540 s), and two playbooks. Its origin is a bare repository beside it, so "From origin/main" is true and pushes stay inside the directory.
  • home/: a J5 home whose only project is that repository. It holds 15 replayed Claude and Codex threads from upstream's provider replay kit (clocks set so they read as the last five hours), J5's delivery seed, two personas (haiku-helper, luna-helper; each names its pinned model first and the other cheap model as the required second route), and Claude Haiku 4.5 as the default model. No model is called; the build takes about 22 s.
  • server.json (the process group) and server.log.

The work is in three parts:

  1. Delivery seed. Its guard refused anything below ~/.j5code, which is where thread worktrees live. It now accepts a base directory inside a linked git worktree's own .j5code, and still refuses the shared home, a non-worktree directory below it, and a symlink out of the worktree's .j5code. The seed can also write into an existing project instead of creating a second one rooted at process.cwd().
  2. Generator (apps/server/src/j5/test-support/liveTestHome.ts, liveTestRepo.ts).
  3. Script (scripts/j5/setup-agent-live-test.ts): no argument starts, then status, restart, stop and rebuild (stop, delete .j5code/live-test, build and start).

Process safety:

  • The server is spawned detached from Node, so the child is its own group leader and its pid is the group id. The script records that pid and the process's start time.
  • T3CODE_PORT, T3CODE_HOST, J5CODE_HOME and J5CODE_SERVER_NAME are removed from its environment, and T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=false stops the dev server registering <worktree>/apps/server as a project.
  • The script signals that group only when its leader is still the process it spawned (same pid and start time) running from the worktree. That holds for a server that crashed or is still booting, so those can be stopped too. A live group that fails the check is reported, never signalled. Nothing is found by name.
  • "Running" additionally needs the listener on the port the server's log reports to be in the group and inside the worktree. Otherwise status says NOT SERVING and points at the log and restart.
  • Paths come from the worktree, never from the manifest. Every run refuses the main checkout, a .j5code that links out of the worktree, a .j5code that is the live home, a home or repository that has become a link out of the build, and a worktree path with a space or shell character. A server that comes up on another home, on port 5773 or on the inherited T3CODE_PORT is stopped.
  • A start returns within 90 seconds; a slow server is left running and reported.
  • Every pairing URL the script prints is freshly minted with the same scopes as the server's startup URL (AuthAdministrativeScopes); a test fails if the script's list drifts from the contracts.
  • Linux only: it reads /proc and calls ss.

Not in this PR (later stages of #546): --fresh, --peer, --for-dev, --base, the evidence upload script, and any skill or AGENTS.md text.

Live testing

Run on 2026-10-11 from this branch's worktree, through the Browser panel.

Exercised:

  • Cold build and start: 28 s. Process group holds all five dev-server processes; the only project in the database is the test repository; no path in a thread row points outside the build.
  • Paired with the printed URL. The sidebar shows the 15 replayed threads and the two seed threads under "Live test repo"; the first draft opens in that project on Claude Haiku 4.5.
  • One Claude Haiku 4.5 turn in a new thread, current checkout: edited README.md in the test repository, "1 changed file".
  • One Claude Haiku 4.5 turn in a new thread, New worktree: replied before the detach reached it; the worktree landed in home/worktrees/test-repo/.
  • One GPT-6-Luna turn in a new thread, New worktree: interrupted by the server about 4 s in (see below).
  • status, a repeated start (each prints a fresh pairing URL), restart (5 s; the browser stayed paired and earlier threads were still there), stop, stop when stopped, an unknown argument.
  • The printed pair --base-dir command mints a working URL.
  • Two overlapping starts: both waited and printed RUNNING; status in the first seconds of boot printed NOT SERVING.
  • A crashed server: I killed the server process under node --watch (the listener, confirmed in my group); status printed NOT SERVING and stop cleared the whole group.
  • rebuild, twice in a row.
  • A checkout with no node_modules: a plain "install first" message.
  • The hold gate on a repository where git does not trust file modes (found by CI): the script is now committed as executable.
  • Settings > Personas after the persona fix: both personas "Available", both playbooks listed with their steps and no warnings. The browser was paired with a minted (not startup) URL for this.
  • A browser paired in a clean incognito tab from a status URL opened Settings > Connections with "Create link", "Revoke others", "Add environment" and "Add peer" enabled.
  • Port 5773 was untouched throughout.

A tester (a peer agent in its own worktree, working only from the script's output) then used it cold. Its report is the artifact test-reports/setup-agent-live-test.md. Its verdict: the default current-checkout setup passes with no unresolved setup defect; its full matrix is marked FAIL for the three product and scope items listed below. It found and I fixed: the import crash with no node_modules, the rm -rf its harness refused (now rebuild), and persona files the library rejected. It exercised live:

  • All 15 replayed timelines and both seed timelines, Fleet, Inbox, Settings > Personas and both playbooks.
  • Haiku and Luna turns in the current checkout, each with a real diff.
  • A restart at rest, then a follow-up edit on an earlier thread.
  • A restart during a turn held by scripts/hold.sh, and a normal release with touch .hold-release.
  • A two-seat Crew on the two personas, and the two-step playbook to completion.
  • Stopping only the server process: status said NOT SERVING, stop emptied the group and freed both ports.
  • The refusal from an ordinary (non-worktree) checkout.

Not exercised live by anyone:

  • A Crew bound to the add-a-feature playbook from start to finish.
  • The 20 s SIGTERM timeout and SIGKILL fallback, and the 90 s start timeout.
  • The wrong-home and live-port refusals on a real server, and the live-home refusal against the real home (covered by tests on a fake layout).
  • macOS.

Found by the tester and not fixed here, because they are not the script's:

  • GPT Luna in "New worktree" mode edited its file and then stayed on "Thinking" for over three minutes (the fault below).
  • After a restart during a held turn, the timeline shows no final response and no interruption notice. A follow-up on the thread works. This is upstream's behaviour and is out of scope for J5.
  • The dev server writes Vite caches under the worktree's node_modules, outside .j5code. Provider CLIs write their own session and support files under ~/.claude, ~/.codex and /tmp. All test data, repositories and thread worktrees stay inside .j5code/live-test.

Open fault, not fixed here: in "New worktree" mode the first turn of a thread can be interrupted by the server. Right after the draft becomes a server thread, the web client's "default the worktree base" effect (BranchToolbarBranchSelector.tsx) sends a metadata update with branch: main, worktreePath: null, which clears the worktree the server just assigned and detaches the provider session ("Workspace changed."). It reproduced on 3 of 3 automated attempts here (two Haiku, one Luna). The live install does not show it, and why is not settled. The local bare origin is unrelated. The j5-live-test skill, not the script's output, carries the advice to take live turns in "Current checkout".

Upstream impact

No upstream-owned file is edited. New files are under apps/server/src/j5/ and scripts/j5/.

The generator imports upstream's replay kit (orchestration-v2/testkit/*, Adapters/*.testkit.ts, @t3tools/provider-testing) without changing it. replayFixture in liveTestHome.ts is adapted from the private runFixtureProvider in upstream's OrchestratorReplayFixtures.integration.test.ts (about 70 lines). It differs in using a file database, our project and cwd, a set clock, and no assertions. A request for upstream to export that seam is on the give-back backlog (#276).

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction (no UI change)
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR (none edited)
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md (none)
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md). A developer tool with one entry point; stop is the way out of start. Replays cover Claude and Codex only.
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them (the skill and AGENTS.md text are in docs(j5): agents live-test with one setup script, the Browser panel and a testing skill #549)

Tests: vp test run scripts/j5/setup-agent-live-test.test.ts apps/server/src/j5/test-support/liveTestHome.test.ts apps/server/src/j5/a2a/test-support/devDeliverySeed.test.ts (22 pass). Typecheck for apps/server and scripts, and lint on the touched files, are clean. No repo-wide checks were run.

Built with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

Jacksondr5 and others added 3 commits October 11, 2026 22:09
…an existing project

The seed refused any base directory below ~/.j5code, which is where thread
worktrees live, so a test home inside a worktree could not use it. It now
accepts a base directory inside a linked git worktree's own .j5code. It can
also write its threads into a project that already exists in the home,
instead of creating a second project rooted at the current directory.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Builds a small TODO-app repository with a local bare origin, and a J5 home
that holds only that project: replayed Claude and Codex threads from
upstream's provider replay kit, the delivery seed, two light personas and
Claude Haiku as the default model. No model is called.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
setup-agent-live-test builds the test home in the worktree's .j5code, starts
the dev server with the live server's variables removed, and prints the
ports, pairing URL, project and commands. stop, status and restart act only
on the process group it started, after confirming that group owns the port
from inside the worktree.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
j5-code Ready Ready Preview Oct 12, 2026 3:08am UTC

Request Review

…tory root

The gate takes no argument. It blocks until .hold-release exists in the main
checkout of the test repository, deletes it and exits, so a tester releases a
held turn with one touch and has nothing to clean up. The file is ignored.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The startup pairing URL works once, so the copy in the log is usually spent
by the time a tester asks again. status, and a start against a server that
is already running, now mint a new one from that server.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jacksondr5 and others added 2 commits October 11, 2026 22:16
…is missing

It imported its dependencies at the top, so a fresh worktree failed with
ERR_MODULE_NOT_FOUND before the script could say anything.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The output told agents to rm -rf the directory, which some harnesses refuse
to run. rebuild stops the server, deletes the directory the script already
confirmed is inside the worktree's .j5code, builds it again and starts.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…every run

Review fixes for #551:
- The home and repository paths come from the worktree, never from the
  manifest, and a home or repository that has become a link out of the build
  is refused before anything is started or a pairing URL is minted.
- A worktree path with a space or shell character is refused, since the
  paths are printed inside commands and read back from a log line.
- The two start-time refusals are one tested function.
- A repeated start waits for recovery before it returns.
- The start timeout is 90 seconds, under a two-minute shell timeout.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pped

The script identified its server only by the listener on its port, so a
server that crashed under node --watch, or was still booting, left a process
group no command would touch. It now records the group leader's start time
at spawn and treats the group as its own when that process is still the
leader and runs from the worktree. The port check only decides whether the
server is reported as running. A start returns within 90 seconds and leaves
a slow server running instead of killing it.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server keeps its database in <home>/userdata, so a link there reaches
another home's state even when <home> itself is a real directory.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jacksondr5 and others added 2 commits October 11, 2026 22:27
Each generated persona had one model route, and a persona must have exactly
two, so the library rejected both files and Settings showed none. Each now
names its pinned model first and the other cheap model second. The shape
test decodes the persona and playbook files the way the app does.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The startup URL carries the admin scopes Connections settings need, and a
minted one does not. The call that spawns the server prints the unused
startup URL; status and a repeated start still mint a fresh one.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…copes

A URL minted with pair has only the standard client scopes, so a tester
paired from status could not use Connections settings. The script now mints
every pairing URL it prints with the administrative scope set, and a test
fails if that set drifts from the contracts.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s called ours

A healthy listener in the recorded group was enough to classify the server
as running, so stop could signal a group whose leader was no longer the
process that was spawned. The leader's pid, start time and cwd are now
checked first, for every state that allows a signal, and a start that must
abandon its server classifies it before stopping it.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jacksondr5 and others added 2 commits October 11, 2026 22:33
Jacksondr5 and others added 2 commits October 11, 2026 22:46
Where git does not trust file modes (core.fileMode false, as on the CI
runner), git add recorded scripts/hold.sh as a plain file, so a thread's
worktree checked it out unable to run. The generator now records the
executable bit in the index itself.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… about the run

How to test lives in the j5-live-test skill, so the printed block drops its
testing guidance and keeps the pairing URL, ports, paths, project, default
model, personas, playbooks, hold gate commands and its own commands. The
test repository's README and playbook say pnpm test, to match this repo.

Part of #546.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — f90c1ba9 Deployed Oct 12, 2026 by vercel[bot]
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