Files
civitai__civitai/scripts/ci
Zachary Lowden 4ede37c9c5 ci: re-pin BASE_TESTS to 37,857 — the unit shard gate is red on main (#4621)
* ci: re-pin BASE_TESTS to 37,857 — the unit shard gate is red on main

`scripts/ci/assert-shard-ran.mjs` pins `BASE_TESTS = 22157`, measured
2026-08-25. The suite has since grown to 37,857 executed across 1,626
files, so shards 3 and 4 exceed the derived ceiling of 9,971 and the
job fails with every test passing.

This is red on `main`, not just on PRs: runs 33900980756, 33901008291
and 33901251166 all fail the same two shards on unrelated commits. A
permanently-red gate trains people to click through, so it is re-pinned
rather than worked around.

Re-measured from run 33900980756: 7177 + 5769 + 14724 + 10187 = 37,857.

Cause (2) confirmed against cause (1) by the script's own discriminator:
the four counts are unequal proportionate shares (2.55x spread) and each
shard ran ~4 min against a ~10.4 min full suite. `--shard` failing to
reach vitest would instead give four near-identical full-suite counts at
full-suite runtime.

Also corrects two claims in the comment that are no longer true and that
are the stated justification for the 0.3 / 1.8 multipliers:

  - imbalance was "~5% off the mean"; the heaviest shard is now +55%
  - ceiling headroom was "~1.7x"; it is now 1.16x

vitest shards by file, so a few test-dense files skew a shard badly and
the next one trips the ceiling well before suite growth would. Recorded
in the comment: if this reds again on a green suite, balance the shards
rather than raising the number again.

Verified: the new band [2839, 17036] admits all four current shards, and
still rejects a collapsed shard (0, 99) and a shard that ran the whole
suite (37857).

* ci: make the shard-gate tests follow BASE_TESTS instead of restating it

CI caught what the previous commit missed: re-pinning BASE_TESTS turned
`Unit tests (3)` and `(4)` green but broke `Unit tests (1)`, because
scripts/__tests__/assert-shard-ran.test.ts carried a SECOND copy of the
constant — `const BASE_TESTS = 22157`, under a comment saying it was
"kept in step with BASE_TESTS in the script". Kept in step by convention,
which is what failed. Three boundary tests asserted a stale band while
the script itself was correct.

The test now reads the constant out of the script source. Parsing rather
than importing is deliberate: the script is a CLI that reads process.argv
and calls process.exit at module scope, so an import would execute it. The
regex throws a named error if the constant is renamed, so that fails loudly
instead of silently falling back to a default.

Also fixes the third failing test, which read `const count = 3000` under a
comment claiming it was "computed rather than hardcoded so it follows
BASE_TESTS". It did not follow it. When BASE_TESTS moved the interesting
region slid from 1662..3324 to 4259..5679 and 3000 fell out of it. It is
now derived from the two bounds, with an assertion that the region is
non-empty so a multiplier change fails loudly rather than silently picking
a midpoint that satisfies neither bound.

Validated rather than assumed:
  - constant moved to 50000  -> 14/14 still pass (the tests follow it)
  - constant renamed         -> throws the named error, 1 file failed
  - restored                 -> byte-clean, 14/14 pass

* ci: retrigger preview checks (empty)
2026-09-04 16:18:02 -05:00
..