Skip to content

fix(test): stop pinning live-measured totals; assert instrument correctness three ways - #1327

Merged
mohidmakhdoomi merged 3 commits into
mainfrom
fix/1280-instrument-invariant-tests
Aug 1, 2026
Merged

fix(test): stop pinning live-measured totals; assert instrument correctness three ways#1327
mohidmakhdoomi merged 3 commits into
mainfrom
fix/1280-instrument-invariant-tests

Conversation

@waleedkadous

Copy link
Copy Markdown
Contributor

Stop pinning live-measured totals in the instrument tests

Routed from the architect after Spec 1307 hit this on day one.

The problem with the current form

The reproduction tests assert ALWAYS_ON_WORDS === 34231 against the real repo, so every
always-on edit by every project
fires them. 1307 handled it exactly right — causal check, then
a justified bump with the derivation preserved.

But the incentive it creates for the next project is bump-without-checking, which is the
regression the test exists to catch. The number moves for two different reasons — the instrument
broke, or the surface changed — and the test cannot distinguish them, so it delegates that
judgement to whoever is least placed to spend time on it.

Three layers replace it

None can be disturbed by a legitimate surface edit:

  1. Invariants over the live repo — the composition arithmetic, true at any surface size:
    ALWAYS_ON = SHARED + BUILDER_SPAWN[spir] + I × (HOT + PHASE mean), architect = SHARED + ARCHITECT, and PHASE_ITERS linearity.
  2. Absolute values on a synthetic fixture whose arithmetic a human can check by hand —
    SHARED 7, SPAWN 10, ALWAYS_ON 107. This pins the instrument's correctness without
    pinning the repo's content.
  3. Byte-assertion on the frozen baseline artifact — a historical record; editing it should
    be a deliberate act.

Why layer 2 isn't redundant — verified by mutation, not argued

Invariants have a blind spot: a component that is silently wrong still satisfies every internal
identity, because the wrong value propagates consistently.

Mutating the script to drop HOT from SHARED — a real instrument bug:

Layer Result under mutation
1 — invariants all three PASS
2 — fixture absolutes all three FAIL

Invariants alone would have shipped it. (The pre-existing T1 structural test also fires here,
but only because it pattern-matches the SHARED= source line — it would not catch a component
bug that resolves the wrong file.)

Verified in the other direction too

Adding 44 words to CLAUDE.md — the exact edit shape that fired the old assertion — keeps all
24 tests green. No unrelated builder is asked to bump a number they don't own.

Where live numbers go instead

Into the phase manifests and generated artifacts, where a human reads them as findings
rather than maintaining them as expectations.

Note

Branched off d42a061a. 1307's interim bump (34293/8661) is not on origin/main as of this
branch point — main still reads toBe(34231) — so there is no conflict to resolve here. If
that bump lands separately it will conflict with this file; happy to rebase.

main is red: 'honours PHASE_ITERS as a comparison constant' timed out at
vitest's 5000ms default on a loaded CI runner (5,690ms). This blocks green CI
for every open PR. Same class as #1302 (send-integration afterAll): tests that
shell out to real scripts do real work and need real budgets.

Not a flake - a latent failure. On an UNLOADED machine these tests take
3.9-4.0s against the 5s default, i.e. ~80% of budget before any contention.
The sibling 'emits byte-identical output twice' hit 4,576ms in the same CI run;
it was next.

Scope: 12 blocks in one file that invoke run() (11 tests + the beforeAll that
populates the shared measurement output). Identified by parsing the file for
blocks whose body calls run(), not by eyeballing. Non-shelling tests in the
same file are pure fs reads and keep the default budget - a timeout on a test
that cannot be slow is noise.

60_000 per the #1302 precedent. Nothing else in the diff.

Follow-up, deliberately NOT in this hotfix: the underlying cost is that
measure-prompt-surface.sh spawns python3 once per file for include expansion.
Making that a single pass would cut seconds off every invocation. Worth doing;
not worth coupling to an unblock-main commit.
…ctness three ways

The reproduction tests asserted ALWAYS_ON_WORDS === 34231 against the REAL
repo, so every always-on edit by every project fires them. Spec 1307 hit this on
day one and handled it correctly - causal check, then a justified bump. But the
incentive it creates for the NEXT project is bump-without-checking, which is the
regression the test exists to catch: the number moves for two different reasons
(the instrument broke / the surface changed) and the test cannot distinguish
them, so it delegates that judgement to whoever is least placed to spend time
on it.

Three layers replace it. None can be disturbed by a legitimate surface edit:

1. INVARIANTS over the live repo - the composition arithmetic, true at any
   surface size (ALWAYS_ON = SHARED + SPAWN + I x (HOT + PHASE mean); architect
   = SHARED + ARCHITECT; PHASE_ITERS linear).
2. ABSOLUTE values on a synthetic FIXTURE whose arithmetic a human can check by
   hand (SHARED 7, SPAWN 10, ALWAYS_ON 107). This pins the instrument's
   correctness WITHOUT pinning the repo's content.
3. BYTE-assertion on the frozen baseline artifact - a historical record, where
   editing it should be a deliberate act.

WHY LAYER 2 IS NOT REDUNDANT, verified by mutation rather than argued: dropping
HOT from SHARED (a real instrument bug) leaves every internal identity balanced,
because the wrong value propagates consistently. Under that mutation ALL THREE
INVARIANT TESTS PASS and all three fixture tests fail. Invariants alone would
have shipped it.

(The T1 structural test also fires on that particular mutation because it
pattern-matches the SHARED= source line - but that only catches mutations
touching that line, not a component bug that resolves the wrong file.)

Verified in the other direction too: adding 44 words to CLAUDE.md - the exact
edit shape that fired the old assertion - keeps all 24 tests green, so no
unrelated builder is asked to bump a number they do not own.

Live absolute numbers move to the phase manifests and generated artifacts, where
a human reads them as findings rather than maintaining them as expectations.
…fix/1280-instrument-invariant-tests

# Conflicts:
#	packages/codev/src/__tests__/spec-1280-measurement-instrument.test.ts
@waleedkadous

Copy link
Copy Markdown
Contributor Author

Merged #1321's timeout fix into this branch — it was carrying the same latent red

Self-review catch before this sat in the merge queue: this PR branched from d42a061a, which
predates #1321, so it inherited 10 unbudgeted script-shelling tests — the exact latent
5s-default failure that took main red in the first place. My three new layer-1/layer-2 tests
carried their own budgets, but the ten I did not touch did not.

Merged origin/hotfix/1280-test-timeouts (rather than duplicating the change) so that when
#1321 lands, shared ancestry keeps the merge clean instead of conflicting on a duplicated edit.

One conflict, resolved in favour of this PR: the hotfix carried a budgeted copy of
honours PHASE_ITERS as a comparison constant — a test this PR replaces with
PHASE_ITERS is a linear comparison constant under layer 1, which carries its own budget and
no longer pins 736 + 1396. Keeping the hotfix's copy would have reinstated a live-measured
literal, which is the thing this PR exists to remove.

Verified after resolution: zero unbudgeted shelling tests, zero conflict markers, 24 tests
green.

Merge order is unchanged — this still belongs behind #1321.

@mohidmakhdoomi mohidmakhdoomi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock main. Test-only change to spec-1280-measurement-instrument.test.ts: gives the script-shelling measurement tests explicit 60s budgets and reworks assertions to stop pinning live-measured totals. Verified green on CI (Tests + CLI Integration). Resolves the 5000ms timeout on 'honours PHASE_ITERS as a comparison constant' that has main red; supersedes #1321.

@mohidmakhdoomi
mohidmakhdoomi merged commit e6d2336 into main Aug 1, 2026
6 checks passed
waleedkadous added a commit that referenced this pull request Aug 1, 2026
 drop

Architect corrected their own report to 1280 (my baseline bump is on THIS
branch, not main) and flagged that #1327 replaces the absolute-pin tests with
invariants + synthetic fixture, making my bump unnecessary and conflicting.

VERIFIED rather than assumed, before the rebase: fetched
fix/1280-instrument-invariant-tests, confirmed the absolute pins are gone,
confirmed exactly one conflicting file, then swapped THEIR test file into this
worktree and ran it against this branch's docs — 24/24 pass unchanged. So
dropping my bump and taking theirs wholesale is safe, and I know that now
rather than discovering it mid-rebase. Backed my file up first; restored after.

Their new file names this case directly: the absolute form 'fires on every
always-on edit by every project — Spec 1307 hit it on day one, correctly
checked causality and bumped it. But the incentive it creates for the NEXT
project is bump-without-checking.' That is the design question I flagged rather
than decided, now fixed at its root by the project that owns it.

Consolidated all three pending merges into one table with what 'done' looks
like for each, because three separate queued merges is exactly where one gets
forgotten.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants