Skip to content

test(core): reach the asset model's situations by construction, not by a random draw - #280

Merged
aRustyDev merged 1 commit into
mainfrom
test/core-assets-situations-by-construction
Nov 17, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
test/core-assets-situations-by-construction

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

model_assets_match_the_reference_over_any_sequence in thrust-core asserted, after its 256 random sequences, that among them they had reached every one of 17 "situations". That assertion is random by construction and failed hermetic once on a change that had nothing to do with it. This replaces it with sequences that reach every situation by construction, as #131 did for the twin of this test in the self-hosted adapters. Part of the asset stage's tests (#44); this PR closes nothing.

The failure

PR #215 (docs and the oracle corpus only), run 43813860948: crates/core/usecases/tests/assets.rs, no sequence got to "opened-in-project"; they got to {19 others}, the only failure of 4239 test cases. The model never disagreed with the code; the check asks the random draw to have reached something, and the draw did not.

How often, measured on the unchanged test

  • 3000 independent runs of the test's 256-case batch (each draws its own seed, as CI does): 1 would have failed the check, and the situation it missed was opened-in-project.
  • Per sequence, over 100,000 random sequences (a throwaway test, not in this PR): opened-in-project (a create, an upload, a confirm, an attach, and then an open by someone in the project) is reached by 3.4% of sequences. A batch of 256 misses it with probability (1 − 0.0344)²⁵⁶ = 1.3 × 10⁻⁴, about one run in 7,900. The next rarest, attached-some-left-out (5.5%), is missed once in 1.8 million runs, and every other situation is rarer still.
  • One failure in the weeks this test has run in CI is on the unlucky side of 1 in 7,900, not impossible; it is the situation the arithmetic names, and the check was wrong whatever its rate: it also did not run at all below 128 cases, so a mutation run with few cases had no coverage guard.

What changed

  • crates/core/usecases/tests/assets.rs: pinned() is three sequences that between them get to all 17 situations by construction (the lifecycle and its refusals; a project's cover opened by a member and refused to someone who is only in the workspace; the attaches). model_assets_match_the_reference_over_any_sequence runs them first through the same run_model, so each must agree with the model, and it fails at once, naming the situation, if they do not reach every one (no pinned sequence gets to "…"). The random sequences follow as before, to look for what no one thought to pin; what the run reached is printed (ASSET-MODEL-OBSERVATION) and no longer asserted. The cases >= 128 condition is gone: the pinned check does not depend on how many random cases a run asks for.
  • docs/src/testing/techniques/model-based.md: says so, in place of describing only the strategy's step-class control.
  • Nothing in src/; no test added or removed (the one test changes its body).

Controls (AGENTS.md rule 8), each one edit, made and reverted

  1. The step that opens the project's asset as a member (Open { AdminA, asset 0 }) removed from the second pinned sequence: the test fails with no pinned sequence gets to "opened-in-project", every time (it does not depend on a seed).
  2. open_asset planted to skip its access check, with PROPTEST_CASES=1 (one random case, so the random part cannot be what finds it): a pinned sequence fails with left "ok", right "no-access": Open { actor: OutsiderA, asset: 0 }.
  3. PROPTEST_CASES=4 (below the old 128 threshold, where the old check did not run): the test passes, and the pinned check still ran.

Verification

Not checked

  • cargo mutants over assets.rs (the planted bug above is one mutant, by hand).
  • The whole CI run.

Refs: #44

🤖 Generated with Claude Code

…y a random draw

`model_assets_match_the_reference_over_any_sequence` ended with a check that its 256 random sequences had, among them, reached
every one of 17 "situations" (AGENTS.md rule 8: what the model must get to, or it proves less than it seems to). The seed is
random, so the check failed on a share of runs, for the rarest situation: `opened-in-project` on #215 (run 43813860948, a change
to docs and the oracle corpus), the only failure of 4239 test cases. Nothing the model compares was wrong. #131 fixed the same defect in
the self-hosted adapters' twin of this test; this is the core's.

Measured on the unchanged test (2026-11-17): 3000 independent runs of the 256-case batch, 1 would have failed the check, and the
situation it missed was `opened-in-project`. Per sequence, over 100,000 random sequences, `opened-in-project` (a create, an upload,
a confirm, an attach, then an open by someone in the project) is reached by 3.4%, so a batch misses it with probability 1.3e-4,
about one run in 7,900. The next rarest, `attached-some-left-out` (5.5%), is missed once in 1.8 million runs; every other one is
rarer still. The check also did not run at all below 128 cases.

The assertion was wrong, not the code, and it is replaced by one that does not depend on chance (AGENTS.md rule 3): three pinned
sequences, run first through the same `run_model`, reach every situation by construction, and the test fails at once, naming the
situation, if they do not. The random sequences follow, as before, to look for what no one thought to pin; what the run reached is
printed (`ASSET-MODEL-OBSERVATION`) and no longer asserted. `docs/src/testing/techniques/model-based.md` says so.

Controls: with the step that opens the project's asset as a member removed from the second pinned sequence, the test fails with
`no pinned sequence gets to "opened-in-project"`; with `open_asset` planted to skip its access check and `PROPTEST_CASES=1`, a
pinned sequence fails (`left "ok", right "no-access": Open { actor: OutsiderA, asset: 0 }`), so the pinned part catches it alone;
with `PROPTEST_CASES=4` the test passes and the pinned check still runs. `cargo nextest run -p thrust-core`: 1611 passed.

Refs: #44
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev enabled auto-merge (squash) November 17, 2026 20:42
@aRustyDev
aRustyDev merged commit 15bcfb0 into main Nov 17, 2026
44 checks passed
@aRustyDev
aRustyDev deleted the test/core-assets-situations-by-construction branch November 17, 2026 20:51
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.

1 participant