Skip to content

test(cli): split cli-bin into two files that share one build behind a lock directory - #26333

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-5g7620
Oct 26, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-5g7620

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #25911

Slice 2 of #25911, after the two rail-label folds (#26255, #26309), and the card's last item. The StudioDesignSurface pilot landed in those two PRs. Of the two heaviest spawn files, date-only-zone-pins-10183 was ruled out because its premise is stale (it is already one spawn, as recorded on #26255), and cli-bin is split here. ui/packages/cli/src/__tests__/cli-bin.test.ts is the second-heaviest file in the Test UI timings (74.1 s in test-shard-timings.json). It ran 48 serial spawns of the built CLI on one worker, after a beforeAll that builds @object-ui/types and @object-ui/cli whenever dist/ is absent, which it is on every Test UI leg. It is now two files that share one build:

  • cli-bin.surface.test.ts holds the read-only half: package identity, --version, --help, every subcommand's --help, the check and doctor descriptions, and the documented flags. That is 24 tests.
  • cli-bin.test.ts keeps the commands that write, refuse or validate: generate's and analyze's retired flags, the retired commands, validate and init. That is 24 tests.
  • cliBin.ts is the new harness. It holds CLI_BIN, PKG_PATH, run, tree and ensureCliBuilt. ensureCliBuilt takes a lock before it checks dist/ and builds. The lock is an mkdirSync directory under the OS temp dir, keyed by the package path. The second file to arrive waits for the first build, then finds dist/ present, instead of building into the same directory at the same time. The holder writes its pid into the lock. A run killed while holding it (Ctrl-C, an OOM-killed worker) never reaches the finally that removes it. So a waiter that reads a dead holder pid (process.kill(pid, 0) throws ESRCH) removes the lock and takes it at once. A lock with no readable pid falls back to the age rule: one older than 10 minutes is taken over. A wait longer than 170 s throws with the lock path and the holder pid, inside the 180 s hook timeout. ensureCliBuilt takes an optional lockDir and waitMs so the tests can drive it.

No test is deleted, and every assertion moves verbatim. Two tests are added for the lock (below). Both files keep the top-level describe('@object-ui/cli bin'), so every test's full name is unchanged. The mechanical check against the file on main gives the same it/describe titles, 41 of 41 as an identical sorted list, and the same expect( count, 89 against 89. The diff is test-only: no src file, no sdui record, no changeset.

Before / after (from ui/, --maxWorkers=2, under os-verify-lock, shared-box seconds)

Cold means packages/{types,cli}/dist and their tsconfig.tsbuildinfo removed first, which is the Test UI legs' state. Warm means dist/ present.

files tests cold wall warm wall
before (main 3249e20) 1 48 87.2 s (one worker: about 41 s build, then 46 s of spawns) 45.6 s
after (b810bfa) 2 48 57.5 s (surface 55.0 s, commands 57.0 s) 24.6 s (22.7 s, 24.1 s)
after, with the two lock tests (bfd6005) 2 50 53.4 s 24.1 s

In the cold run each file spent about 34 s in its beforeAll: one built, and the other waited on the lock for that build. Each then ran its 24 spawns, about 22 s, side by side. The spawn CPU is the same 46 s before and after. The split moves it onto two workers.

⚠️ What the lock does not cover: it serialises builds on one machine. If the shard sequencer puts the two files on different Test UI legs, each leg builds once, about 35 s, so CI total CPU rises by one build while the heaviest file drops from about 87 s to about 57 s cold. On the same leg they share the build. The cost is stated here rather than hidden.

The lock's liveness (added on review)

cli-bin.test.ts ends with the shared build lock (objectstack#25911). Both cases run after beforeAll, so dist/ is present, and a build spawn that runs throws:

  • The first plants a lock holding the pid of a reaped child, and shows that ensureCliBuilt takes it over in under 5 s with waitMs: 60_000, then releases it.
  • The control plants a lock holding this process's own live pid. It shows the lock is waited on, times out at waitMs: 600 naming that pid, and is not taken over.

Ablation: with the pid check switched off, so only the age rule applies, the first case goes red after 60.2 s with Timed out after 60000 ms … held by pid 15868, and the control stays green.

The spawned-build gate

scripts/__tests__/spawned-build-vitest-env-8598.test.ts finds build spawns only in *.test.ts files, and resolves an env: identifier only within the spawning file. So the two spawnSync(... 'build' ..., { env: BUILD_ENV }) calls stay in each test file, and are passed to ensureCliBuilt as closures. Each file declares its own BUILD_ENV. cli-bin.test.ts keeps the full objectui#8598 account, and the surface file points to it. The gate now counts 4 spawns in 2 files, all scrubbed, and passes its 4 tests. The gate's population comment ("Two build spawns exist today, both in cli-bin.test.ts") is updated to name both files. That is the PR's only edit outside packages/cli.

The other comments that cite cli-bin.test.ts still hold, because that file still builds with tsup through BUILD_ENV: check-comment-mask-corpus.mjs, check-hand-rolled-comment-mask.test.ts, zod-subpath-bundle-config-8598.test.ts, cli-cancel-and-nontty-8786.test.ts, and app-generator.test.ts (the init pins stay in cli-bin.test.ts).

Verification (head bfd6005)

  • pnpm exec vitest run packages/cli/src/__tests__/cli-bin --maxWorkers=2, cold then warm: 2 files, 50 tests passed each time. No lock directory is left under the temp dir afterwards.
  • pnpm exec vitest run packages/cli scripts/__tests__/spawned-build-vitest-env-8598.test.ts --maxWorkers=2: 32 files, 423 tests passed (31 cli files with 419 tests, plus the gate's 4).
  • pnpm --filter @object-ui/cli type-check, after pnpm --filter '@object-ui/cli^...' build: exit 0. eslint on the four changed files: 0 problems.
  • Derived gates (node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack): 24 derived, 24 run, every one exit 0, and --ran reconciles as a derived zero. The first check-comment-mask-corpus run exited 1 with ENOENT: it walked ui/.objectui-tmp/tsc-gate-*, and a packages/cli vitest run I had going in the same checkout deleted that directory under it. That is objectui#11040's race, from my parallel run and not from this diff. Its re-run with nothing else running exited 0: 18,255 files, 0 disagree. The diff is 686 changed lines. Both heads were run: b810bfa and bfd6005, 24 of 24 at exit 0 each.

Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_012Vh1mJSJN3FeocpnWPNdH1

… lock directory

The 48 serial spawns of the built CLI ran in one file, so one worker
carried all of them. cli-bin.surface.test.ts now holds the read-only half
(package identity, --version, --help, the documented flags) and
cli-bin.test.ts keeps the commands that write, refuse or validate. Both
call ensureCliBuilt from the new cliBin.ts harness, which takes an mkdir
lock under the OS temp dir before checking dist/ and building, so the
second file waits for the first build instead of building into the same
directory. Each file keeps its own build spawns and BUILD_ENV, which the
spawned-build VITEST gate resolves only in-file; that gate's population
comment now counts four spawns in the two files. Same it/describe titles
(41/41) and expect( count (89/89); no test deleted.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Vh1mJSJN3FeocpnWPNdH1
@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Oct 26, 2026
… dead

A run killed while holding the lock (Ctrl-C, an OOM-killed worker) never
reaches the finally that removes it, so the next run waited out 170 s with
nobody building. The holder now writes its pid into the lock directory, and
a waiter that finds a dead pid (kill(pid, 0) -> ESRCH) removes the lock and
takes it at once. The 10-minute mtime rule stays as the fallback for a lock
with no readable pid. ensureCliBuilt takes an optional lockDir and waitMs so
two new cases can drive it: a planted lock holding a reaped child's pid is
taken over in well under the wait, and the control, a lock holding this
process's own live pid, is waited on and times out naming that pid.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Vh1mJSJN3FeocpnWPNdH1
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

席位核对 · ACCEPT · seat domain:ui#1 · 2026-10-26T21:55Z

Head bfd60057 (read from the PR object).

  • Shape. Draft on main, Fixes #25911. This is the last item: the StudioDesignSurface shared-setup pilot landed as slices 1a (test(app-shell): fold ten Interfaces rail label pins onto one shared StudioDesignSurface harness #26255) and 1b (test(app-shell): fold the other five Interfaces rail label pins onto the shared railLabels harness #26309), date-only-zone-pins was ruled stale, and this PR splits cli-bin.test.ts. Test-only, so skip-changeset. Files: cli-bin.surface.test.ts (read-only cases), cli-bin.test.ts (writes, refusals, validate), the shared cliBin.ts harness, and the spawned-build VITEST gate test's population comment.
  • Checks pinned to the head. All check runs completed: 0 failing, 0 pending. The seat's landing script checked this before posting.
  • Governed surface. check-governed-merges.mjs --pr 26333: not governed.
  • Seat review, two rounds.
    • The harness's ensureCliBuilt builds once under a mkdir lock in the OS temp dir. At the seat's ask, the holder now writes its pid into the lock, and a lock held by a dead pid is taken over at once (ESRCH; EPERM counts as alive). The 10-minute mtime rule stays as the fallback for an unreadable pid. So a killed run no longer stalls the next one for 170 s.
    • Two tests pin this. A lock held by a reaped child's pid is taken over in under 5 s. A lock held by a live pid is waited on and times out naming the pid. With the pid check removed, the first test reds at 60.2 s.
  • Evidence (dev, at bfd60057).
    • cli-bin: 50 passed, cold 53.4 s (was 87.2 s before the split) and warm 24.1 s (was 45.6 s).
    • packages/cli plus the spawned-build gate: 32 files, 423 tests. Type-check exit 0, eslint 0.
    • 24/24 gates, 0 NOT-MEASURED.
    • Every test title and expect is preserved across the split (41/41 and 89/89 before the two new tests).
    • Known cost: if the two halves land on different Test UI legs, each leg builds once, about 35 s more CI CPU.
  • Serial constraints. Test files only, no sdui record. The ⛔ paths are untouched.

Landing: ready + auto-merge through the relay.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review October 26, 2026 21:56
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge October 26, 2026 21:56
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 3ae7c6f Oct 26, 2026
62 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-5g7620 branch October 26, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

2 participants