Skip to content

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

Merged
aRustyDev merged 1 commit into
mainfrom
fix/asset-model-situation-coverage
Nov 12, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
fix/asset-model-situation-coverage

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

model_asset_methods_match_the_reference_against_postgres (the model test of the asset methods against real Postgres, from #124) fails CI on a fair share of runs, and fails the pg-adapter job and with it gate. This makes it deterministic where it was flaky, and stronger.

Part of #44's asset stage (not closing anything).

The flake

The test ended with a check that its 24 random sequences had, among them, reached every one of 14 "situations" (AGENTS.md rule 8). Some need a chain of unlikely steps: a delete is one step in twenty, and mark-of-a-deleted-one then needs a mark of that very asset. The seed is random, so the check failed on many runs, each time for a different situation.

Observed on #128's CI (that PR changes nothing in this crate): 3 failures in 4 executions of the test.

Execution Missed situation
run 43131497472, attempt 1 mark-of-a-deleted-one
run 43131497472, attempt 2 passed
run 43133683716, attempt 1 marked-again
run 43133683716, attempt 2 cover-replaced

It passed on main's merge commits for #124 and #127. Nothing the model compares was ever wrong: it is the coverage assertion, not Postgres and not the adapter.

The fix

The assertion was wrong, not the code, so it is replaced by a stronger one that does not depend on chance (AGENTS.md rule 3):

  • pinned(): three short sequences that between them reach all 14 situations by construction (an asset read through another workspace, uploaded twice, public, deleted and marked; a grant spent, asked for again, with the wrong token and at exactly its expiry; a cover named from another workspace's asset, with someone else's asset left out, and replaced by another caller's).
  • They run first, through the same run_case against the same Postgres, and the test fails at once, naming the situation, if one is not reached.
  • 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.

Evidence (2026-11-11, a real Postgres container, local)

  • The test passes six times in a row; each run is its own process with its own seed. The pinned sequences alone reach all 14 situations.
  • Control (rule 8): with the last step of the third sequence removed, it fails with no pinned sequence gets to "cover-replaced".
  • cargo fmt --all --check and cargo clippy -p thrust-adapters-selfhosted --all-targets -- -D warnings: clean.
  • Only tests/assets/mod.rs changes (+58 −7).

Not done

The random run no longer asserts what it reached. If a situation should be reached by generation as well as by construction, the way is a model-only replay of sampled sequences (like model_asset_strategy_reaches_every_step_class does for the kinds of step), which means extracting the situations from run_case's interleaving of Postgres calls and the model; that is a larger change than a flake fix.

🤖 Generated with Claude Code

…truction, not by a random draw

`model_asset_methods_match_the_reference_against_postgres` ended with a check
that its 24 random sequences had, among them, reached every one of 14
"situations" (AGENTS.md rule 8: what the model must get to, or it proves less
than it seems to). Some situations need a chain of unlikely steps: a delete is
one step in twenty, and `mark-of-a-deleted-one` then needs a mark of that very
asset. The seed is random, so the check failed on a fair share of runs, each
time for a different situation: `mark-of-a-deleted-one`, `marked-again` and
`cover-replaced` in the three CI failures of one PR (#128, whose changes are
not in this crate), which passed on main's merge commits for #124 and #127.
Nothing the model compares was ever wrong in those runs.

The assertion was wrong, not the code, and it is replaced by a stronger one that
does not depend on chance (AGENTS.md rule 3): three pinned sequences, run first
through the same `run_case` against the same Postgres, 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.

Measured (2026-11-11, a real Postgres container): the test passes six times in
a row (each run draws its own seed), and reaches all 14 situations in the pinned
sequences alone. Control: with the last step of the third sequence removed, it
fails with `no pinned sequence gets to "cover-replaced"`.

Refs: #44
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit a20deba into main Nov 12, 2026
34 checks passed
@aRustyDev
aRustyDev deleted the fix/asset-model-situation-coverage branch November 12, 2026 02:18
aRustyDev added a commit that referenced this pull request Nov 17, 2026
…y a random draw (#280)

`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]>
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