Skip to content

test(contract): a generated model and access table for /api/v1's work items - #128

Merged
aRustyDev merged 5 commits into
mainfrom
refactor/contract-v1-model
Nov 12, 2026
Merged

aRustyDev merged 5 commits into
mainfrom
refactor/contract-v1-model

Conversation

@aRustyDev

@aRustyDev aRustyDev commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

What

Stage 2b of moving the contract suite off the slice (G-26 in docs/src/testing/status.md is the ledger; stages 1 and 2a were #122 and #125). /api/v1 had hand-written contract tests and the oracle, and no generated test over HTTP on the four targets. This adds one: a model and an access table for /api/v1's work items, over API keys, in tests/v1_model/.

Part of #58 (not closing it).

It is new, not a move: the slice's model (tests/model/) is a spec of the slice (bearer actors, attachments, activity checkpoints, with_deleted), half of it has no replacement route, and it stays for what nothing replaces. Both models run until the slice goes.

What it is

A finding the first run showed

With the project's own slug alone, the ignore-tenant mutant failed the table and not the model: it changes membership() only when the slug does not match the project's workspace, and a stranger and a non-member are the same 403 in v1. So the generator names another slug now and then (Slug::Other and Unknown, one draw in five). With that, the model and the table both fail the mutant.

Evidence (2026-11-11, local)

Not done (G-26)

What stays on the slice until a route replaces it: sign-out and sign-out-everywhere, the session info, OIDC, API-key management, the activity feeds, attachments, and the tests that use a slice work item as their vehicle (the slice's model and table, the outbox, redelivery, sweeper and panic tests, the create limit, the cookie and CSRF tests, the bench). Then the slice's routes, SLICE_PREFIX, the test that shows the prefix is gone, and the core, port and adapter code that only the slice used.

🤖 Generated with Claude Code

aRustyDev and others added 4 commits November 11, 2026 19:46
… items

The contract suite's model (`tests/model/`) is a spec of the slice: bearer
actors, attachments, activity checkpoints and `with_deleted`. `/api/v1` had
hand-written contract tests and the oracle, and no generated test over HTTP on
the four targets. `tests/v1_model/` is one, with an API key per caller.

- `model_v1_work_items_over_http_match_the_reference_model` (`main` pass):
  random sequences of create, delete, detail and list (a page of one to three,
  and the second page by the cursor the answer names) by seven kinds of caller,
  in two tenants, a project that does not exist and, now and then, a slug that
  is not the project's workspace's. The model is the pin's rules written out: a
  missing key is a 401 and a key that is not valid a 403; a stranger, a project
  that is not there, a wrong slug and a guest who writes are one 403 (checked
  before the body, so a guest's bad body is a 403); a member deletes only what
  they made and a project admin any; a bad name is a 400 in DRF's words; a
  taken external key is a 409 naming the work item; sequence numbers rise and
  are never reused, with at most one gap per failed create; `sort_order` is
  65535 and then 10000 after the greatest live one; a list is newest first.
- `sweeper_model_v1_outbox_holds_one_event_per_change_and_nothing_more`
  (`sweeper` pass, fast path off): the same sequences, with the outbox depth
  read after every request, so a request that writes an event it should not, or
  none it should, shows. `/api/v1` has no activity feed, so what the consumer
  does with an event stays with the slice's model.
- `model_v1_strategy_reaches_every_step_class`: the generator coverage control,
  28 classes.
- `matrix::every_actor_project_and_route_gets_the_status_of_the_v1_access_table`:
  every caller x slug x project x route (315 requests), and afterwards both
  projects hold exactly the work items the table predicts.

`EXPECT_MAIN` is 60 and `EXPECT_SWEEPER` 3 (they were 57 and 2), and so are the
counts of `stage2-contract.sh`, which are 54 and 3 for a deployed Worker.

Measured (2026-11-11): the main pass, 60 of 60, and the sweeper pass, 3 of 3, on
native-memory, native-pg, worker-memory and worker-cf. A key makes at most 60
requests a minute (the pass's `/api/v1` limit) and a sequence at most two per
operation plus the two reads that end it, so no case reaches it.

Controls: with the project's own slug alone, the `ignore-tenant` mutant failed
the table and not the model (a stranger and a non-member are one 403 in v1), so
the generator names another slug now and then; with that, the model and the
table both fail it. A `sort_order` rule off by one fails the model alone. An
outbox rule that counts a conflict as an event fails the sweeper test (at 200
sequences; at the default 8 a given run may not draw a conflict, as with the
slice's model). A page generator that never pages fails the coverage control,
naming `ListedPage` and `ListedSecondPage`. `duplicate-sequence-number` fails
the model.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
G-26 says what stage 2b built and the controls it was shown with, and that the
slice's model and access table stay for what nothing replaces (the activity
feeds, attachments, `with_deleted` and what the queue consumer does with an
event). G-8 and the contract-suite page describe the new tests, the pass
counts and the deployed-Worker count, which was stale.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`EXPECT_MAIN` is 63: main's 60 (the compat tests of #124 and #127) and this
branch's three. The deployed-Worker count of `stage2-contract.sh` is 57 (the
six `oidc_` tests are skipped there), and the docs say so. The one conflict was
that line of `scripts/contract.sh`.

Measured on native-memory after the merge: the main pass 63 of 63, the sweeper
pass 3 of 3.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`EXPECT_MAIN` is 65: main's 62 (the compat tests of #124, #127 and #130) and this
branch's three. The deployed-Worker count of `stage2-contract.sh` is 59 (the six
`oidc_` tests are skipped there), and the docs say so. The one conflict was that
line of `scripts/contract.sh`, as at the last merge.

Measured on native-memory after the merge: the main pass 65 of 65, the sweeper
pass 3 of 3.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev added a commit that referenced this pull request Nov 12, 2026
…truction, not by a random draw (#131)

`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 d53d196 into main Nov 12, 2026
34 checks passed
@aRustyDev
aRustyDev deleted the refactor/contract-v1-model branch November 12, 2026 03:17
aRustyDev added a commit that referenced this pull request Nov 15, 2026
…tests (#172)

* test(contract): port the slice's OIDC checks that the compat tests lacked

Step 5d of moving off /api/_slice: the slice's OIDC pair (`GET /api/_slice/auth/oidc/start` and `/callback`) has a Plane-shaped replacement since #163 (`GET /auth/oidc/` and `/auth/oidc/callback/`, D-040), so the pair and its six `oidc_` tests can go. #163's `compat_oidc_*` tests already cover most of what the six assert (login completes, the link decides by subject, a tampered, unknown, missing, refused or replayed state, the five ID-token tamperings, no verified email, no provisioning, a deactivated user by email and by link). Five assertions of the six were in no compat test, and deleting the six without them would lose real coverage, so they come first, while the slice route still exists to compare with. No test is added: they go into the two existing compat tests, so the main pass stays 73 of 73.

Ported:
- The OIDC session's cookies carry the attributes of a password sign-in's (Secure, HttpOnly, SameSite=Lax, Path=/, no Domain, Max-Age 30 days), a 64-hex session token and a 32-hex CSRF value. Before this, the hermetic test held Secure, HttpOnly, Lax, Path and Domain, and nothing held Max-Age for the OIDC callback.
- A different subject with another account's verified email is a different login and goes to that account (the control for "the subject decides").
- The email is matched like a password sign-in's: case and padding do not matter.
- A subject that is already linked does not get around the verified-email rule (a different code path from the three unlinked cases).
- The mock identity provider refuses an exchange whose PKCE verifier is not the challenge's (the control that shows the target's own verifier is what makes the logins work).

Controls, each a temporary mutation of one file that was reverted (the tree was clean again after each, checked), each run through the native-memory main pass. The compat test named failed at the ported assertion, read from its panic message:
- The callback's cookies live half as long: `compat_oidc_login_completes...` fails at "30 days" (Max-Age 1296000).
- The provider's email is not normalized: `compat_oidc_login_completes...` fails because the padded-email login is refused (the panic is in the helper's "a session cookie"; that login is the only one whose email is not already normalized).
- The link is made on the issuer and not the subject: `compat_oidc_login_completes...` fails at "a different subject is a different login" (and `compat_oidc_every_refusal...` fails too, earlier, because the memory adapter's links are shared by every test of the run).
- The verified-email rule is applied only to an identity not yet linked: `compat_oidc_every_refusal...` fails at "a linked subject with an unverified email" (the slice's own test failed too).
- The mock accepts any PKCE verifier: `compat_oidc_login_completes...` fails because the exchange answered 200 and not 400.

Checked: native-memory main 73 of 73 with the ports in. Not run here: the other three targets (CI runs them).

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* refactor(api): delete the slice's OIDC routes and their six contract tests

Step 5d of moving off /api/_slice. #163 put Plane's routes (`GET /auth/oidc/` and `/auth/oidc/callback/`, D-040) over the same core `oidc_start` and `oidc_callback`, with `compat_oidc_*` contract tests, so the slice's pair has a Plane-shaped replacement and the owner's standing decision of 2026-11-11 applies: it goes. The previous commit ported what the six `oidc_` tests held that the compat tests did not.

Deleted:
- `GET /api/_slice/auth/oidc/start` and `/callback`, their handlers and the callback's query struct (thrust-api), and the two unused imports they leave; the two entries of `slice_auth_routes()` (so `the_slice_routes_are_gone_from_the_reserved_v1_prefix` walks 5 routes there, no longer 7) and its `no_redirect` comment.
- The six `oidc_` tests of `tests/auth/mod.rs` and their helpers (`begin`, `finish`, `assert_logged_in`, `assert_refused`, `unique_sub`, the mock-IdP import). `EXPECT_MAIN` is 67.

Changed:
- `scripts/contract.sh` registers the mock identity provider's redirect URI as `<origin>/auth/oidc/callback/`, the app's callback (D-040 says a deployment must register that one), where it was the slice's callback. The compat tests send the browser to the URL the mock hands back, and assert that it is the app's callback, so the registration is no longer a path the target happens not to look at. No deployment has a provider (G-35), so no registration moves.
- A hole found by running the mutants: G-35 records that `mutant_oidc_state_reusable` was killed at contract level only by the slice's replay test. The compat route tells a used state and a used code alike (5301) and the mock refuses a reused code too, so with the six gone the `oidc-state-reusable` row of `scripts/mutants.sh` survived: the main pass was 67 of 67 with the mutant built in. The compat refusal test now replays a used state with a second, fresh code for the same login (the mock's `authorize` can be called twice on one Location); only the used state can refuse that code, and the mutant is killed there.
- Comments and docs that named the slice's pair: flows/app.md (the route rows, the OIDC paragraph, which now describes the compat routes and their redirects with `error_code`, and the error table's OIDC cases and 502 row), contract-suite.md, defect-matrix.md (X24 names the compat tests and the three mutants), status.md (G-12, G-26 with the step and its controls, G-35's note on the state mutant), the compat OIDC module's header and the stage2 script's comment.

Not changed: `scripts/stage2-contract.sh` still expects 59 for its `main` set. It skips every `oidc_` test, so the set does not change here; the list of that set is 61 on main today, so the 59 was already out of date before this commit (set at #128). It is a guard of a manual run against a deployed Worker, and what it should now say needs a run there.

Checked on this tree:
- native-memory main 67 of 67, sweeper 3 of 3, csrfoff 6 of 6, engine 4 of 4; worker-memory main 67 of 67; worker-cf main 67 of 67 (both again after the replay assertion went in).
- clippy `--workspace --all-targets -D warnings` and `cargo fmt --all --check` clean; every script of CI's `deps` job and its self-tests pass; `sh -n` of `contract.sh` and `stage2-contract.sh` under dash in Ubuntu 24.04, with a deliberately broken script that fails the check.

Controls (temporary, restored and checked):
- The OIDC pair back in `slice_auth_routes()`: `the_slice_routes_are_gone_from_the_reserved_v1_prefix` fails ("GET /api/_slice/auth/oidc/start: not mounted (404)"), so the routes are gone and the list would notice.
- The three OIDC rows of `scripts/mutants.sh`, on native-memory main with the slice tests gone: `mutant_unverified_email` and `mutant_oidc_failure_redirect_no_code` fail `compat_oidc_every_refusal...` (exit 101); `mutant_oidc_state_reusable` passed 67 of 67 before the replay assertion, and fails `compat_oidc_every_refusal...` at "a fresh code for a state that is used" after it.

Not run here: native-pg (CI runs it) and a deploy.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(scripts): stage2's main pass counts 61 tests, not 59

`scripts/stage2-contract.sh main` ends with a guard: when `cargo test` exits 0 and the passed count is not `EXPECT`, it exits 5 ("exit 0 but passed count != expected"), so that a filter that selects nothing cannot report green. `EXPECT` for `main` was 59, set at #128. The set its filters select is 61: #151 added two tests (`compat_change_password_is_for_a_session_and_not_for_an_api_key` and `compat_change_password_refuses_in_planes_order_changes_nothing_then_swaps_it_and_ends_every_session`), and nothing in CI runs this script (it needs a deployed Worker, by hand), so nothing noticed. A correct run against a Worker would have failed at the guard.

Found while finishing step 5d, which does not change this set (the script skips every `oidc_` test, before and after). Measured, not assumed: for each pass of the script, the number of tests its own filters select (`cargo test -p thrust-contract-tests --test <binary> -- --list --format terse`, the `: test` lines), next to the `EXPECT` it holds. Before: `main` 61 listed, 59 expected, flagged as differing. After: all thirteen passes agree (main 61, csrfoff 6, worker 1, bindings 3, cron 1, crontrigger 1, sweeper 3, panic 1, blast 1, email 1, engine 4, budget 1, ratelimit 1). Only `main` was wrong.

The two extra tests were found by listing the test names of the suite at #128 and of today's `main` set: the change-password pair is new; `v1_requests_are_rate_limited_per_key` is also not in the old list but is the create-limit test renamed at stage 4 (#142), so it is not an addition.

Changed:
- `EXPECT` for `main`, 59 to 61, and the header's "59 tests", with a comment in the script that says how to derive the number again and what went wrong this time.
- `docs/src/testing/techniques/contract-suite.md`: the two places that quote the count (59, and a 31 from the spike's time) say 61 and name what the pass skips.
- G-26 in `docs/src/testing/status.md` records it.

Checked: `sh -n` of the script under dash in Ubuntu 24.04, with a deliberately broken script that fails the check; the thirteen counts above.

Not run: the script itself against a Worker (it needs a deployed one). The 61 ties out against the runs of this PR: `main` is 67 tests, the script skips three `oidc_` and three `operator_` tests, and all 67 passed on `worker-cf` and on `worker-memory`. A run against a deployed Worker is what shows that all 61 pass there, and what shows whether either change-password test needs something a deployed Worker lacks.

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

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