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
-
In craig-cases, craig-placement and craig-financial almost every test under
tests/is#[ignore = "requires devstack"]and drives the running stack throughcraig_test_lib::TestHarness(crates/craig-test-lib/src/harness.rs): Keycloak tokens, HTTP to the deployed service, the broker, every peer. -
services/craig-cases/tests/api/keyed_harness.rsalready 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 acraig_mq::Publisherfor an axum extension (assemble_router_over), it mountsroutes(..)without the auth middleware, and it injectsClaims. No other service has one. -
No request handler of the three services uses that
Publisher. Every extractor isExtension(_): Extension<Publisher>(about ten in craig-cases, one in craig-financial, none in craig-placement; step 1 counts them); events are staged toevent_outboxin the handler’s transaction and published by the outbox worker. -
An in-process test still needs PostgreSQL (the
postgres-testinstance). 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 onDrop, asKeyedHarnessdoes today. -
TestIssuer: mints RS256 tokens with craig-auth’s bundled test key (test_encoding_key,test_jwk_set, thetest-fixturesfeature 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 anAuthLayerwhoseJwksProviderholds the injected key and performs no fetch. -
shipped_engine(jurisdiction): the real authorization engine over the shipped rulesets from the pinned config layer (lifted fromkeyed_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: binds127.0.0.1:0and 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.
Scope and order
One merge request per step, each green alone.
-
D1 for the three services.
-
inproccore;KeyedHarnessrebuilt on it. -
TestIssuerand its realm contract test. -
craig-cases pilot.
-
craig-placement pilot.
-
craig-financial pilot; D4’s numbers; the plan closed.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
|
silent |
|
An in-process suite passes because authorization is not the shipped one. |
fail-open |
|
The test key verifies a token in a release binary. |
fail-open |
The key is reachable only through craig-auth’s |
A handler regains an |
fail-closed |
|
Production boot passes |
silent |
|
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 |
Throwaway databases leak on a panicking test and exhaust |
fail-closed |
|
Tests
| Category | Tests |
|---|---|
Contract |
|
Regression |
|
Ported suites |
The 83 pilot tests, assertions unchanged, run by the car as before. |
Unit |
|
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.adocbecauseroutes(..)andRouterEnvchange 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 --doneand the archive move.
Review log
| Round | Vendor | Resolved model | Verdict |
|---|---|---|---|
1 |
Anthropic |
claude-fable-5-2 |
FLAGS (1): no broker-free seam for |
2 |
gemini-4-carbon |
FLAGS (1): fixtures bound to the shared database, the |