Repository navigation
test(cli): split cli-bin into two files that share one build behind a lock directory - #26333
Merged
Merged
Conversation
… 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
… 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
Contributor
Author
席位核对 · ACCEPT · seat
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-10183was ruled out because its premise is stale (it is already one spawn, as recorded on #26255), andcli-binis split here.ui/packages/cli/src/__tests__/cli-bin.test.tsis the second-heaviest file in the Test UI timings (74.1 s intest-shard-timings.json). It ran 48 serial spawns of the built CLI on one worker, after abeforeAllthat builds@object-ui/typesand@object-ui/cliwheneverdist/is absent, which it is on every Test UI leg. It is now two files that share one build:cli-bin.surface.test.tsholds the read-only half: package identity,--version,--help, every subcommand's--help, thecheckanddoctordescriptions, and the documented flags. That is 24 tests.cli-bin.test.tskeeps the commands that write, refuse or validate:generate's andanalyze's retired flags, the retired commands,validateandinit. That is 24 tests.cliBin.tsis the new harness. It holdsCLI_BIN,PKG_PATH,run,treeandensureCliBuilt.ensureCliBuilttakes a lock before it checksdist/and builds. The lock is anmkdirSyncdirectory under the OS temp dir, keyed by the package path. The second file to arrive waits for the first build, then findsdist/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 thefinallythat 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.ensureCliBuilttakes an optionallockDirandwaitMsso 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 sameit/describetitles, 41 of 41 as an identical sorted list, and the sameexpect(count, 89 against 89. The diff is test-only: nosrcfile, no sdui record, no changeset.Before / after (from
ui/,--maxWorkers=2, underos-verify-lock, shared-box seconds)Cold means
packages/{types,cli}/distand theirtsconfig.tsbuildinforemoved first, which is the Test UI legs' state. Warm meansdist/present.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.The lock's liveness (added on review)
cli-bin.test.tsends withthe shared build lock (objectstack#25911). Both cases run afterbeforeAll, sodist/is present, and a build spawn that runs throws:ensureCliBuilttakes it over in under 5 s withwaitMs: 60_000, then releases it.waitMs: 600naming 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.tsfinds build spawns only in*.test.tsfiles, and resolves anenv:identifier only within the spawning file. So the twospawnSync(... 'build' ..., { env: BUILD_ENV })calls stay in each test file, and are passed toensureCliBuiltas closures. Each file declares its ownBUILD_ENV.cli-bin.test.tskeeps 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 incli-bin.test.ts") is updated to name both files. That is the PR's only edit outsidepackages/cli.The other comments that cite
cli-bin.test.tsstill hold, because that file still builds with tsup throughBUILD_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, andapp-generator.test.ts(theinitpins stay incli-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, afterpnpm --filter '@object-ui/cli^...' build: exit 0.eslinton the four changed files: 0 problems.node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack): 24 derived, 24 run, every one exit 0, and--ranreconciles as a derived zero. The firstcheck-comment-mask-corpusrun exited 1 with ENOENT: it walkedui/.objectui-tmp/tsc-gate-*, and apackages/clivitest 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