Repository navigation
test(core): reach the asset model's situations by construction, not by a random draw - #280
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
model_assets_match_the_reference_over_any_sequenceinthrust-coreasserted, after its 256 random sequences, that among them they had reached every one of 17 "situations". That assertion is random by construction and failedhermeticonce 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
opened-in-project.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.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_sequenceruns them first through the samerun_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. Thecases >= 128condition 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.src/; no test added or removed (the one test changes its body).Controls (AGENTS.md rule 8), each one edit, made and reverted
Open { AdminA, asset 0 }) removed from the second pinned sequence: the test fails withno pinned sequence gets to "opened-in-project", every time (it does not depend on a seed).open_assetplanted to skip its access check, withPROPTEST_CASES=1(one random case, so the random part cannot be what finds it): a pinned sequence fails withleft "ok", right "no-access": Open { actor: OutsiderA, asset: 0 }.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
cargo nextest run -p thrust-core: 1611 passed, none leaky.cargo fmt --check; clippy for the workspace,thrust-api-v1with its feature, and the Worker's and the edge's wasm32 targets;cargo metadata --locked.depsjob (which moved intolint.ymlwith ci: move the guards and the Rust lint into lint.yml, the fourth called workflow (migration M4) #269; compared with my local list mechanically, the one difference being CI's download of actionlint).Not checked
cargo mutantsoverassets.rs(the planted bug above is one mutant, by hand).Refs: #44
🤖 Generated with Claude Code