Plan: In-process service tests — a shared harness and three pilot suites

Status

Done (2026-11-17) — the shared in-process harness and three pilot suites are merged; 71 moved tests passed on their first car, and the measurement on #2302 shows in-process about 0.45 s slower per test.

Closes: #3119 (a child of #2302, which stays open for the bulk-port decision).
Tree: written against main.
Ruling (maintainer, 2026-11-17): harness plus three pilot suites, then measure and decide on the bulk port.

Erratum (2026-11-17): the keyed harness has 58 user files, not 42. The allow-all census also treats FixedScope as a hit, and it scopes a file by naming craig_test_lib::inproc or the module of a file that does, so the pilot file cases.rs, which uses AllowAll in four tests, must move those to the shipped engine or keep them in a file off the adapter.

Erratum (2026-11-17): the contract test also treats a service account’s sub specially: Keycloak generates it at realm import, so both tokens' values must be UUIDs and are not compared by value. iat, exp, jti and sid are compared by presence, and the lifespan exp - iat by value.

Erratum (2026-11-17): cases.rs held 17 tests on TestHarness and 12 already on the keyed harness, not 29 on TestHarness. The 17 move to the adapter; the 12 move unchanged to cases_keyed.rs, since they use an authorization double and a file naming the adapter is under the allow-all census. The adapter serves through the production server (ApiServer::serve_with_listener), not inproc::serve, because the router’s layers read the peer address that server attaches.

Erratum (2026-11-17): the placement and financial pilots merged in one train car, and the close-out is its own merge request after step 6, not part of it. No test in the three files had to stay on TestHarness, and none of the files was in a serialized group.

Context

  1. In craig-cases, craig-placement and craig-financial almost every test under tests/ is #[ignore = "requires devstack"] and drives the running stack through craig_test_lib::TestHarness (crates/craig-test-lib/src/harness.rs): Keycloak tokens, HTTP to the deployed service, the broker, every peer.

  2. services/craig-cases/tests/api/keyed_harness.rs already runs the real cases routes in-process over a database cloned from a template (crates/craig-test-lib/src/template_db.rs). It is not stack-free: it opens a RabbitMQ channel only to construct a craig_mq::Publisher for an axum extension (assemble_router_over), it mounts routes(..) without the auth middleware, and it injects Claims. No other service has one.

  3. No request handler of the three services uses that Publisher. Every extractor is Extension(_): Extension<Publisher> (about ten in craig-cases, one in craig-financial, none in craig-placement; step 1 counts them); events are staged to event_outbox in the handler’s transaction and published by the outbox worker.

  4. An in-process test still needs PostgreSQL (the postgres-test instance). So a train car gets no faster from this plan; the gain is a test a developer can run with only a database, and less load on the shared stack.

Design

D1. The router takes no publisher

In craig-cases, craig-placement and craig-financial the Publisher leaves the request router: the unused Extension<Publisher> extractors are deleted, routes(..) loses its publisher parameter and its .layer(Extension(publisher)), and RouterEnv.publisher goes where nothing else reads it. The outbox worker and the inbox consumers keep their publisher (lib.rs). No double is built: a value nobody reads is removed, not faked. The other services are not touched.

The same step gives the router a broker-free seam: each RouterEnv carries mq: craig_api::MqRequirement in place of mq_health: craig_api::MqHealth (whose only constructor needs a live connection). Production boot passes MqRequirement::Required(health), as build_router hard-codes today; the in-process adapter passes MqRequirement::NotApplicable, the value KeyedHarness already uses.

D2. craig_test_lib::inproc

A new module, behind the crate’s existing test-support surface (no new cargo feature), holding what is the same for every service:

  • ThrowawayDb: a database cloned from the service’s migration template (template_db::create_from_template), dropped on Drop, as KeyedHarness does today.

  • TestIssuer: mints RS256 tokens with craig-auth’s bundled test key (test_encoding_key, test_jwk_set, the test-fixtures feature craig-test-lib already enables) in the shape the devstack realm issues (issuer, audience, azp, roles claim path, the worker attributes), for the devstack’s named test users and service clients. It returns an AuthLayer whose JwksProvider holds the injected key and performs no fetch.

  • shipped_engine(jurisdiction): the real authorization engine over the shipped rulesets from the pinned config layer (lifted from keyed_harness.rs). The module offers no allow-all engine.

  • refusing_peer(): a base URL nothing listens on, for a peer client a suite must not reach. A test that needs a peer’s answer stays on the devstack.

  • serve(router) → base URL: binds 127.0.0.1:0 and serves the router, so a suite keeps its typed HTTP client and its test bodies.

  • outbox_events(pool, event_type): reads staged envelopes, for a test that asserted on a published event.

Each service adds a thin adapter in its own tests/ (its build_router arguments, its migrator, its reference data): the real build_router(..) of src/api/assembly.rs, with the auth middleware mounted. craig-cases' KeyedHarness is rebuilt on the shared core and loses its broker connection; its 42 user files keep compiling through its existing functions. KeyedHarness keeps its existing AllowAll re-export for those files until the bulk port; the allow-all census of § Risks reads the three pilot files and the three adapters, and names keyed_harness.rs as its one exemption.

D3. The pilots

One file per service moves from TestHarness to the in-process adapter, keeping every test and assertion. Test bodies change only where they obtain a client, a token or a pool: fixtures that take a &mut TestHarness or open the shared service database (for example owned_pending_payment and financial_pool() in craig-financial’s payment_fixtures.rs) gain an in-process form over the adapter’s client and its ThrowawayDb pool. The files: services/craig-cases/tests/api/cases.rs (29 tests), services/craig-placement/tests/api/foster_homes.rs (37), services/craig-financial/tests/api/request_claims_financial.rs (17). A test in those files that needs the broker, a peer’s answer or the rules service stays on TestHarness and is listed in the merge request. The tests keep #[ignore = "requires devstack"]: postgres-test is part of the devstack, and a database-only lane is a decision for after the measurement.

D4. Measurement

Posted on #2302 after the pilots merge: for each pilot file, wall time on the stack before and in-process after (same host, three runs each); the count of max-threads = 1 nextest groups before and after; how many tests of each file could not move and why. That is the input to the bulk-port decision.

D5. Out of scope

The bulk port (about 1,300 tests), a database-only CI lane, a new ignore reason, and any service beyond the three.

Scope and order

One merge request per step, each green alone.

  1. D1 for the three services.

  2. inproc core; KeyedHarness rebuilt on it.

  3. TestIssuer and its realm contract test.

  4. craig-cases pilot.

  5. craig-placement pilot.

  6. craig-financial pilot; D4’s numbers; the plan closed.

Risks

Risk Mode Mitigation

TestIssuer tokens drift from what the realm issues, so in-process tests pass on claims production never sees.

silent

the_test_issuer_mints_the_claims_the_realm_issues (devstack): for each named user and client, the decoded claims of a TestIssuer token equal those of a real Keycloak token, ignoring only iat, exp, jti, sid and the signature.

An in-process suite passes because authorization is not the shipped one.

fail-open

inproc exposes only shipped_engine; no_inproc_suite_uses_an_allow_all_engine (source census) fails on an allow-all engine in a file that uses inproc.

The test key verifies a token in a release binary.

fail-open

The key is reachable only through craig-auth’s test-fixtures feature; cargo xtask release-artifact-gate already forbids that feature in release graphs and stays green.

A handler regains an Extension<Publisher> extractor, which compiles and fails at request time with no layer behind it.

fail-closed

no_request_handler_extracts_a_publisher, an in-crate source census in each of the three services over its src/api; the request fails 500 before any write if one slips through.

Production boot passes MqRequirement::NotApplicable, so readiness stops watching the broker.

silent

only_tests_declare_the_broker_not_applicable: the same census fails on NotApplicable in non-test source of the three services.

A ported test silently stops covering a cross-service effect it used to cover.

silent

A test moves only if it reads nothing but its own service’s responses and database; anything else stays on TestHarness, listed per file. Assertions on a published event read the staged envelope through outbox_events.

Throwaway databases leak on a panicking test and exhaust postgres-test.

fail-closed

ThrowawayDb drops on Drop, as today; the existing template pre-warm and scratch sweep are reused.

Tests

Category Tests

Contract

the_test_issuer_mints_the_claims_the_realm_issues (devstack-gated).

Regression

no_inproc_suite_uses_an_allow_all_engine; no_request_handler_extracts_a_publisher and only_tests_declare_the_broker_not_applicable (one in-crate census per service); a_token_from_another_key_is_refused_in_process (401 through the mounted middleware); a_refusing_peer_fails_the_call_and_not_the_test_setup.

Ported suites

The 83 pilot tests, assertions unchanged, run by the car as before.

Unit

ThrowawayDb create and drop; serve binds an ephemeral port; outbox_events returns staged envelopes in order.

Every new test gets a red proof. Devstack-gated tests are written and compiled locally and run by the train car.

Delivery

  • Canonical page: docs/modules/ROOT/pages/testing-reference.adoc (the in-process tier: what it needs, what it may not use, how a suite adopts it).

  • CHANGELOG entry: none for tests and test support; step 1 adds changelog.d/3119.changed.adoc because routes(..) and RouterEnv change for code that assembles those routers.

  • Close: the child issue closes on step 6 with the merge SHA and the measurement posted on #2302; then cargo xtask plan-lint --done and the archive move.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

claude-fable-5-2

FLAGS (1): no broker-free seam for mq_health; "cannot compile" was wrong; folded.

2

Google

gemini-4-carbon

FLAGS (1): fixtures bound to the shared database, the AllowAll re-export, per-service census; folded. Approved by the maintainer in plan mode, 2026-11-17.

Edit this page · latest