Repository navigation
Commit e45265e
ci(cli-tests): balance the CLI's Test Core slices by declared file weight, not equal file counts (#37073)
<!-- claude-projects-attribution: {"github_login":"huangyiirene"} -->
_Requested by **Irene** · [project
thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67x8Be2AAcUBhodBsvnWLd3Xs)_
Part of #36646
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户无感:只改合并队列里核心测试分片如何切分命令行工具的测试文件,产品行为不变。
- 属于合并队列提速:队列最慢的一成里,拖尾的总是同一个测试分片,本改动把它承担的那份测试切得更均匀。
- 出错只会让某个分片多跑或少跑一点时间,每个测试文件仍恰好跑一次(新测试钉住这一点);可直接撤回。
- 要你做的:无(另有一张已全绿的自动生成的分片耗时数据刷新拉取请求待席位合入,详见下方说明)。
## What changes
`@objectstack/cli` is the one package Test Core cuts below package
granularity (3 file-level slices, `OS_TEST_SHARD=k/3`). Its vitest
sequencer cut vitest's sha1 order into **equal file counts**. This PR
cuts it by **weight** instead: `planSlices()` (new
`packages/cli/vitest-slices.ts`) seeds the declaration readers into
slice 1/n as before, then places every other file heaviest first into
the lightest slice, a file weighing the `// test-budget:` its header
already declares (seconds / 1.25), or 1.6 s when it declares none.
**Why the producer is in `packages/cli`, not `scripts/ci/**`.** The
card's expected landing was Test Core's shard planning. The measurements
below put the tail inside one shard's CLI slice leg, and which files a
CLI slice holds is decided by the CLI's own vitest config
(`DeclarationReaderSequencer` in `packages/cli/vitest.config.ts`), not
by the planner: the planner only places "cli k/3" as an item at the
package's weight / 3. So the fix is at that producer. Files:
`packages/cli/vitest-slices.ts` (new, pure),
`packages/cli/vitest.config.ts` (the sequencer calls it),
`packages/cli/test/vitest-slices.test.ts` (new pin),
`packages/cli/tsconfig.test.json` (the new root module named in the test
program). No workflow, budget file, partitioner constant or shard count
is touched.
What does not change: the readers stay in slice 1/n (the partitioner's
self-test reads `DECLARATION_READER_SLICE` and the sequencer back,
green); the partitioner still weighs each slice at whole / 3; the
shard-timings generator decodes slices from the sha256 of
`OS_TEST_SHARD`, never from membership.
## The measured tail (before)
All readings: `objectstack-ai/objectstack`, green `merge_group` runs of
`ci.yml` created 2026-11-21T00:00Z .. 2026-11-24T15:20Z (620 runs; run
wall p50 21.6 min, p90 35.1 min).
- The 63 slowest (the top decile): the last matrix job to end was
**`Test Core (9/10)`** on **47 of 63**; `Test UI` shards 11 (all in runs
created 2026-11-22 05:47-05:49Z, where Test UI started 18-23 min into
the run), `Test Core (10/10)` 3, `Test Core (3/10)` 1, `Test Core
(6/10)` 1.
- `Test Core (9/10)` job median: **32.6 min** on the slow decile (n=52),
18.6 min on an evenly spaced 40-run sample of the rest (n=18). It starts
~2.5 min into the run (median start offset of the last-ending job, 2.6
min).
- Its two legs, serial, on three slow-decile logs (runs 45342138743,
45213635210, 45032942394): whole-package leg 13m56s / 13m22s / 13m22s,
then the **CLI slice 2/3 leg 17m59s / 17m20s / 17m18s**.
- The CLI's three slices are equal in files and not in seconds. Per-file
vitest durations from the three slice shards of five slow-decile runs,
summed per slice: 1171/2347/2164, 1748/2270/1638, 1786/2275/2115,
1589/2253/1418, 1373/2178/1692 s (runs 45342138743, 45213635210,
45032942394, 45116811975, 45383396882). Slice 2 is the heaviest on all
five.
## After
- **Planner replay (a prediction from measured per-file readings, not a
queue reading):** `planSlices()` itself, run over those five runs'
per-file readings with this tree's budget lines, puts the heaviest slice
at 2014, 2076, 2203, 1928, 1912 s against 2347, 2270, 2275, 2253, 2178
s: **-14.2%, -8.5%, -3.2%, -14.4%, -12.2%**, lower on every run. An even
split of the same seconds would be 1894/1885/2059/1753/1748 s; the
budgets are ceilings, so the split recovers part of that.
- **Queue reading after: NOT MEASURED** — it exists only once queue runs
carry this head. The before figure to compare against is the `Test Core
(9/10)` median above (32.6 min on the slow decile, 18.6 min on the
rest), and the slice leg 17.3-18.0 min.
- This PR alone is not shown to bring the p90 under 32 min, hence `Part
of`.
## Acceptance notes
- **The larger lever is the shard-timings dataset, and it is already a
green PR.** `scripts/test-shard-timings.json` was measured 2026-11-02;
the weekly refreshes of 11-09 and 11-16 were closed unmerged and the
11-23 one (#36637, generated, 25 checks green, 24 skipped, non-governed)
is open. Every slow-decile `Test Core (9/10)` log read carries the
planner's own DRIFT warning (2.10x, 2.00x, 2.01x measured vs predicted)
naming the refresh as the remedy. Planner prediction, not a reading:
replaying the full package list, the slowest shard's modelled tests step
(whole / 2.9 + slice) is 1293 s with today's placement and 1127 s with
#36637's placement, both on #36637's weights. Landing it is a seat act;
this PR does not carry or duplicate its bytes, and the two are
independent (this one changes which files a slice holds, that one which
packages sit beside it).
- Measured candidates that need a decision, reported on the card rather
than built here: running the CLI slice leg beside the whole leg instead
of after it (a workflow change); a fourth CLI slice (refused by the
partitioner's slice-count pin under its ruling); the spec shard (`Test
Core (3/10)`, 22.3 min slow-decile median) as the next floor.
- The ablation's first attempt stayed green: the first balance pins used
heavy files that sort first by path, where path-order greedy also
balances. A pin with the heavy file last in path order was added and the
second attempt went red as expected.
## Verification
Read first: `packages/cli/vitest-slices.ts` (`planSlices`: every file in
exactly one slice is the risk), then the `DeclarationReaderSequencer`
hunk of `packages/cli/vitest.config.ts`.
Two-minute check: `pnpm --filter @objectstack/cli exec vitest run
--project unit --maxWorkers=2 test/vitest-slices.test.ts` → 17 tests
pass, including the live-population partition at three slices.
<details><summary>Tests (head 96c83ea; unit layer at 9b0861a, the
only later commit adds one pin to the new test file)</summary>
- `pnpm --filter @objectstack/cli exec vitest run --project unit
--maxWorkers=2`: Test Files 444 passed (444), Tests 6342 passed (6342),
lock VERDICT command-exit 0. The `integration` layer is declared to CI
(no spawn entry or integration file in the diff).
- `test/vitest-slices.test.ts` at 96c83ea: 17 passed.
- `pnpm --filter @objectstack/cli typecheck` (tsc +
check:test-typecheck): exit 0 at 96c83ea.
- End to end through vitest itself: the unit project run as
`OS_TEST_SHARD=1/3`, `2/3`, `3/3` with a test-name filter matching
nothing reported 141 / 151 / 152 files, union 444, all distinct, the 5
declaration readers all in slice 1. (Suites failed to import there only
because that run had no built dependencies; membership is what was
read.)
</details>
<details><summary>Ablation (committed fix first, restore by HEAD
blob)</summary>
`node scripts/ablation-replace.mjs` on `packages/cli/vitest-slices.ts`,
replacing the heaviest-first sort with path order: mutation landed
(anchor 1 → 0, blob 8b98292 → 2f80d72879d2). Attempt 1 (before the
new pin): 16/16 green, recorded above as a pin gap. Attempt 2 at
96c83ea: `× places the heaviest file first even when it comes last in
path order`, `expected [ 9, 3 ] to deeply equal [ 6, 6 ]`, exit 1.
Restore: `git diff HEAD` empty, `git hash-object` equals the HEAD blob,
17/17 green after.
</details>
<details><summary>Gates</summary>
- `node scripts/pm/dispatch-gates.mjs --commands` at 9b0861a: 53
families, all run, each `:: exit 0` (`check:dual-build-cjs-loads` exited
3 on the first pass while the closure rebuild was fresh, 0 on the
re-run, recorded as 0); `--ran` reconciliation: "53 derived famil(ies)
accounted for — 53 run, 0 NOT-MEASURED (a DERIVED zero)".
- Re-run at 96c83ea for the test-file change:
check:cross-package-test-inputs, check:test-source-alias,
check:tier-file-adoption, check:cli-test-child-env, check:nul-bytes,
check:doc-authoring, check:issue-citations, all exit 0.
- `node scripts/partition-test-shards.mjs --self-test`: OK (reads the
CLI config's reader slice and sequencer back).
- No changeset: `packages/cli` publishes `dist`, README and CHANGELOG;
built `dist` has zero hits for `planSlices` with a positive control
(`SCAFFOLD_PNPM_RANGE` hits `dist/commands/create.d.ts`).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01J8VVAjMMU8pcMXmiLEMMG4)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent b90dcf4 commit e45265e
4 files changed
Lines changed: 340 additions & 36 deletions
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| |||
| 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 | + | |
0 commit comments