Skip to content

test(contract): move the work-item tests onto /api/v1 with API keys - #122

Merged
aRustyDev merged 2 commits into
mainfrom
refactor/contract-suite-off-slice
Nov 11, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
refactor/contract-suite-off-slice

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

Stage 1 of moving the contract suite off the slice's /api/_slice routes (one of the two things left of #58, with the utoipa schema diff). Ten tests of contract.rs now go through /api/v1 with an API key, instead of through the slice with a Bearer session, and answer as Plane does.

Part of #58 (not closing it).

The shape of the whole migration is the owner's choice of 2026-11-11: staged (move what has a replacement now; the slice routes that nothing replaces stay, named, until #44 delivers them), and the work-item tests go to /api/v1 with API keys (not the compat plane, which is deleted at ADR-0013 Phase 2). G-26 in docs/src/testing/status.md is the ledger.

What changed

  • crates/thrust-contract-tests/src/lib.rs: every fixture user has an API key (User.key, planted through /internal/seed, label FIXTURE_KEY_LABEL), and a small v1 client: v1_items, v1_item, v1_create, v1_create_ok, v1_list, v1_list_ok, v1_delete, and Issue (a wrapper over the JSON, for the few keys a test reads).
  • tests/contract.rs: unauthenticated_requests_are_rejected, create_allocates_monotonic_sequence_and_sort_order, list_returns_visible_items_newest_first (was ..._in_sequence_order), soft_delete_hides_rows_and_never_reuses_sequence_ids, cross_tenant_access_is_rejected_and_has_no_effect, non_members_and_guests_are_forbidden_to_write, external_id_is_unique_among_live_rows_only, concurrent_creates_never_duplicate_a_sequence_id, invalid_input_is_a_client_error, and the control of reset_requires_the_admin_token_and_a_refused_call_deletes_nothing. Each keeps its controls.
  • tests/auth/mod.rs: the two slice key tests that assert an exact listing count only the keys they made (made_here), because GET /api-keys lists the fixture's key like any other. budget/mod.rs, bench_scale.rs: a key field on the users they build by hand.
  • Docs: G-26 (the ledger), the contract-suite page, and a paragraph of by-change.md that said nothing is served under /api/v1.

What the tests say now (v1's answers, not the slice's)

A stranger and a project that is not there are a 403 (the slice said 404 and told them apart from a member who is not in the project); a list is newest first; the first work item of a state is at 65535 and the next 10000 after it (the slice: 10000 steps); a member deletes only what they made (403 Only admin or creator can delete the work item), a guest nothing; a taken external key is a 409 naming the work item; a bad body is a 400 in DRF's words; a missing key is a 401, a key that is not valid a 403 Given API token is not valid, and a session token is no key.

Things I left out on purpose, for you to check

  • scope=with_deleted and the 400 for an unknown scope go with the slice: /api/v1 has no view of a deleted row. Core still has the behaviour and its own tests; nothing tests it over HTTP now.
  • sort_order uniqueness under concurrent creates is no longer asserted. The pin reads the greatest sort_order before it inserts, so two creates at once can share a place; the sequence numbers are still checked to be unique and contiguous.
  • The fixture seeds no states. A v1 create works without one (it measured the same 65535), and the compat tests seed their own default state per project, which a default in the shared fixture replaced (one of them failed on it).

Evidence (2026-11-11, local)

  • scripts/contract.sh <target> main on native-memory, native-pg, worker-memory and worker-cf: 57 passed, 57 expected, on each (the count is unchanged: ten replaced by ten).
  • Controls (scripts/mutants.sh's mutants, run by hand for the two these tests answer for): ignore-tenant fails 6 tests, among them the migrated cross_tenant_access_is_rejected_and_has_no_effect; duplicate-sequence-number fails 6, among them the migrated create, list, soft-delete and concurrent-create tests.
  • cargo fmt --all --check and cargo clippy -p thrust-contract-tests --all-targets -- -D warnings: clean.
  • Not run locally: the other mutants (the tests that kill them are not touched here) and the whole scripts/mutants.sh; the mutants job runs them.

Not done (next stages, G-26)

Still on /api/_slice: sign-out and sign-out-everywhere, the session info, OIDC, API-key creation, listing and revocation (no route replaces them: the compat plane has sign-in, sign-up, the email check and the CSRF token only), the activity feeds, attachments, and the tests that use a slice work item as their vehicle: the model and the access matrices, the engine tests, 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 2 commits November 11, 2026 17:28
The contract suite tested work items through the slice's `/api/_slice` routes
with a Bearer session. Ten tests of `contract.rs` now go through `/api/v1`, with
the `X-Api-Key` that the fixture plants for every user (`User.key`), and answer
as Plane does: a stranger and a project that is not there are a 403, a list is
newest first, the first work item in a state (here, in none) is at 65535 and
the next 10000 after it, a member deletes only what they made, an external key that is taken is
a 409 naming the work item, a body that is wrong is a 400 in DRF's words, and a
key that is not valid is a 403 where a missing one is a 401. Each test keeps its
controls (the neighbouring refusal, the nothing-was-made check).

What the pin's list does not have goes with the slice's: a view of a deleted row
(`scope=with_deleted`), a 400 for an unknown scope, and unique `sort_order`
under concurrent creates (the pin reads the greatest one before it inserts, so
two creates at once can share a place; the test asserts the numbers only).

The fixture's key is labelled `FIXTURE_KEY_LABEL`, because the slice's
`GET /api-keys` lists it like any other: the two key tests that assert an exact
listing count only the keys they made (`made_here`). The fixture seeds no
states: a work item made through `/api/v1` has none, and the compat tests seed
their own default state, which a default in the shared fixture would replace.

The slice's routes stay, and so do the tests that no `/api/v1` or compat route
replaces yet (sessions, cookies, CSRF, OIDC, API-key management, attachments,
the activity feeds, the create limit) and those that use a slice work item as
their vehicle; the next stages take them.

Measured (2026-11-11): the main pass, 57 of 57, on native-memory, native-pg,
worker-memory and worker-cf. Controls: the `ignore-tenant` mutant fails the
migrated cross-tenant test (6 failures in all), and the
`duplicate-sequence-number` mutant fails the migrated create, list, soft-delete
and concurrent-create tests (6 in all).

Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d what is left

G-26 in the testing status is the ledger of the migration off `/api/_slice`
(staged, the owner's choice of 2026-11-11): what has moved, what stays on the
slice because no route replaces it yet, and what is not done. The contract-suite
page says which surface its work-item tests use, and `by-change.md` no longer
says that nothing is served under `/api/v1`.

Refs: #58
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