Repository navigation
Commit 3ae7c6f
test(cli): split cli-bin into two files that share one build behind a lock directory (#26333)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi93kH3NmKTNuUFhcMmaWEDak)_
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.
1 parent 40f5c6e commit 3ae7c6f
4 files changed
Lines changed: 466 additions & 220 deletions
File tree
- ui
- packages/cli/src/__tests__
- scripts/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
0 commit comments