Plan: Witness the keyed harness

Status

Done (2026-11-24) — the keyed harness mounts the authz witness under /v1 as production does, and the witness refused no handler; craig-cases routes with an unstamped 2xx went from 114 to 0 in the car’s coverage matrix, and the routes it lists as unproven from 14 to 0. The in-process adapters take peer origins; eight fault tests in craig-financial and craig-placement use them, and one craig-cases test drives the auto-link consumer directly. The IV-E route leg, the activation legs and the summed fan-out stay open on #3154.

Closes: #3160, on the last step. Relates to: #3154 (closed by the last step if every remaining item is covered or ruled infeasible with its reason), #2898 (closed; its report is this plan’s measure).
Tree: written against main at ea6cee163.
Rulings (maintainer, 2026-11-24): this plan is next; it covers whatever the witness surfaces; it scopes in every #3154 leg that is feasible.

Context

The authz witness (#2667) has two halves. craig_authz::witness::wrap(engine) counts each authorization decision a request makes. craig_api::authz_witness::middleware runs each request inside a fresh count, stamps authz-decisions: <n> on the response, and turns a 2xx with zero decisions on a non-exempt route into the typed 500 authz-unwired. ApiServer::router mounts the middleware and craig-bootstrap wraps the engine, both under the authz-witness feature, which the battery builds with (xtask/src/lanes.rs BATTERY_FEATURES).

Three of the four in-process adapters build their router through api::build_router, so through ApiServer::router: inproc_cases.rs, inproc_placement.rs, inproc_financial.rs. They are witnessed in the car today.

services/craig-cases/tests/api/keyed_harness.rs is the exception. assemble_router_over calls craig_cases::api::routes(..) directly, hands it the test’s engine unwrapped, and mounts no witness. The coverage matrix’s first authorization reading (car 18310223745, #2898) shows the cost:

  • 114 craig-cases routes have 2xx records with no stamp, all from suites on this harness;

  • 14 of them have no stamped 2xx from any other suite, so the battery never shows their handler consulted the engine over HTTP. The matrix prints those 14 on every car.

Two facts shape the design:

  • The harness router is not mounted like production. Suites reach it two ways: served (KeyedHarness::serve / serve_router, which nest it under /v1), and directly through keyed_harness::read / post / get_with_bearer with paths such as /cases/reports (no /v1). The witness matches a route by its mounted pattern, /v1 included, so a direct call would miss every exemption row.

  • The harness wires the IV-E surface client with no bearer (ServiceBearer::Absent), and the other adapters wire their peers to inproc::refusing_peer(). That is why #3154’s route-level fault legs were recorded as needing "a stoppable upstream": no in-process router can be pointed at a rules double that answers 503 or hangs.

Scope

In:

  1. The keyed harness mounts the witness and wraps its engine, and its router is mounted under /v1 for every caller.

  2. Every test the witness then fails is resolved: the handler gains its engine call, or the route gains a // authz: skip — <reason> exemption, or the test was wrong.

  3. The in-process adapters accept a rules origin, and the harness’s IV-E surface follows its screening wiring.

  4. The #3154 legs that become writable: see D4. The #3154 legs.

Out:

  • Whether policy refuses correctly. The witness shows a handler asked; the suites' own assertions show the answer.

  • craig-intake (no engine-checked route, #2899).

  • A gate on the matrix’s authz_unproven list. It stays a report; this plan empties it for craig-cases.

Design

D1. The harness is always witnessed, not only in the car

services/craig-cases/Cargo.toml gains two dev-dependency edges: craig-api with authz-witness and craig-bootstrap with authz-witness. Cargo’s resolver keeps dev-dependency features out of normal builds, and the release-artifact gate names a dev-dependency as the sanctioned way to reach a test-only feature. So every test build of craig-cases is witnessed, with or without the battery’s --features, and the harness needs no cfg.

Both edges are needed together: with only craig-api’s, inproc_cases.rs (the ApiServer path) would get the middleware and an unwrapped engine, and refuse every 2xx.

The same pair of edges is added to craig-placement and craig-financial, so a local run of their in-process suites is witnessed too. Their car behaviour does not change.

D2. One mount

assemble_router_over returns Router::new().nest("/v1", routes) with the witness layered on the routes inside the nest, the engine extension holding craig_authz::witness::wrap(authz), and the service name craig-cases, exactly the order ApiServer::router uses. serve_router stops nesting. The three direct helpers (read, post, get_with_bearer) prepend /v1 to a path that lacks it; the three suites that call oneshot themselves (upload_fixtures.rs, ncands_export.rs, and the harness) are edited by hand.

Why prepend in the helper and not rewrite each path: nineteen suite files spell /cases/… paths; a bulk rewrite of them is the larger and riskier edit, and the helper is the single funnel. The helper refuses a path that already starts with /v1/v1.

Alternative rejected: teach craig_api::authz_witness a mount prefix so an un-nested router can be witnessed. It would add a production parameter that only a test uses.

D3. A rules origin for the adapters

  • Keyed harness. ScreeningWiring holds no bearer today (from_options consumes opts.bearer; shared_with clones an existing harness’s clients). It gains a field ive: IveSurfaceClient, built exactly as safety is:

    • from_options: IveSurfaceClient::new(rules_client.clone(), opts.bearer.clone());

    • shared_with(h): h.ive.clone();

    • KeyedHarness gains pub ive: IveSurfaceClient beside safety, set where safety is set, so a test calls h.ive.verify_once(h.jurisdiction) before the determination route (without it the route answers 503 ive-surface-not-ready);

    • assemble_router_over puts wiring.ive in SurfaceClients.ive in place of the client it builds inline with ServiceBearer::Absent. The default wiring’s bearer is still Absent, so no existing suite moves.

  • The other adapters. Each gains one struct of peer origins and one constructor; boot() becomes boot_with(Peers::refusing()), so behaviour is unchanged for every existing suite:

    • inproc_placement.rs: pub struct Peers { pub rules: String, pub cases: String, pub security: String }, Peers::refusing() (every field inproc::refusing_peer()), InprocPlacement::boot_with(peers: Peers). The three origins replace the three refusing_peer() arguments of boot: the rules client’s, then api::OutboundClients::new’s `cases_base_url and security_base_url (services/craig-placement/src/api/assembly.rs).

    • inproc_financial.rs: pub struct Peers { pub rules: String, pub placement: String, pub cases: String }, Peers::refusing(), InprocFinancial::boot_with(peers: Peers); the origins feed PlacementClient::new, CasesClient::new and the rules client that refusing_rules() builds today.

    • inproc_cases.rs: pub struct Peers { pub rules: String, pub exchange: String }, Peers::refusing(), InprocCases::boot_with(peers: Peers); the origins replace the adapter’s two refusing_peer() values. A struct with named fields, not positional strings, so two origins cannot be transposed. No new trait.

  • The double is craig_test_lib::fault::s2s_stub (spawn_fault_server, spawn_hanging_server), which records each executed fault under its contested surface, or wiremock where a leg needs a scripted answer.

Erratum (2026-11-24, step 5): craig-financial’s Peers also carries principal (its placement and cases clients fail before sending without a service token), and guardianship and err_enrollment (both enrollment gates are off in an env-less boot). All three default to the old behaviour.

Erratum (2026-11-24, step 5): craig-placement’s legs drive the matching search, which reaches the facts read and the consult with no seeded row, in place of an activation; activation under a peer fault stays open on #3154. The craig-cases.rules-ive leg was not written: the keyed harness’s routes(..) carries no ExchangeClient extension (cases_service_routes layers it), and through InprocCases the route needs a service principal, a verified IV-E surface served by the rules double, and a craig-exchange double whose run carries the seeded household’s cohort hash (verify_cohort_bytes) before it reaches the consult. That is a fixture of its own, not a leg.

D4. The #3154 legs

Each leg is attempted in the order below. A leg is feasible when its route answers the stated refusal in-process with the double in place. A leg that is not is recorded on #3154 with what blocked it, in one sentence; it is not stubbed.

#3154 item Leg Adapter

craig-financial.placement (accepted gap)

subsidy create with craig-placement answering 503 and hung

InprocFinancial::boot_with, Peers.placement

craig-placement.cases (accepted gap)

activation with craig-cases answering 503 and hung

InprocPlacement::boot_with, Peers.cases

craig-financial.rules-eligibility

subsidy_create / subsidy_activate with craig-rules 503, hung, 429

InprocFinancial::boot_with, Peers.rules

craig-placement.rules-eligibility

an activation and a matching route with craig-rules 503 and hung

InprocPlacement::boot_with, Peers.rules

craig-cases.rules-ive

the determination route with craig-rules 503 and an unusable answer

keyed harness, D3

craig-cases.rules-engine

the auto-link consumer’s handler with hung evaluates

the consumer’s handler called directly over a throwaway DB

Known unknowns, each settled by its step’s first devstack run and not before: whether the IV-E determination route can reach its consult in-process without a craig-exchange double (it reads the screening witness first); whether the auto-link handler is callable without a broker. The summed fan-out of several entries on one request (rules-engine, second half) has no bound to assert and stays an open item on #3154.

Steps

Each step is one MR on the train. Steps 2 onward stack on step 1.

  1. Plan page. This file, the nav entry, the issue.

  2. Mount (D1, D2). The Cargo edges, the harness change, the helper change. Run the whole craig-cases suite on a devstack once and list every failure. The step’s MR lands only when the list is empty, so step 3’s work happens on this branch if the list is short (ten or fewer) and as stacked MRs below it, one per cause, if it is longer.

  3. What it surfaced. Per failing route: an engine call in the handler (with the handler’s existing 403 documented in its responses(…​)), or a // authz: skip — <reason> and cargo xtask baselines bless --only authz-exempt-routes, or a test fix. A handler change that alters a response gets a release note; a pre-existing defect that is not about authorization gets its own issue.

  4. Peer origins (D3). The three Peers structs with boot_with, and the harness’s ive client and handle; no new test. Every existing suite must pass unchanged, which is this step’s check.

  5. Legs (D4). One MR per service: craig-financial, craig-placement, craig-cases. Each new test is listed in xtask/baselines/contested-surfaces.toml on its surface.

  6. Close. Docs, the archive, the closing notes.

Risks

Risk Mode Mitigation

The witness refuses a 2xx in a suite whose handler is correct but whose route was reached without /v1, so an exempt route looks unwired

fail-closed

D2 mounts once; the test the_harness_matches_routes_as_production_does asserts an exempt route answers 2xx and a stamped header through both the served and the direct path

A dev-dependency feature leaks into a release graph

fail-closed

the release-artifact gate refuses any test-only-features pair reached by a normal edge; step 2 runs it (cargo xtask validate) and the car runs it

Step 2 surfaces many failures and the branch stalls

silent

the step’s rule above splits it; the count and the list are posted on the issue the day they are known

A handler "fixed" with an engine call under AllowAll passes while the shipped policy would refuse a legitimate caller

fail-closed

each handler change gets one test on the shipped engine (inproc::shipped_engine), happy and refused, not only the keyed suite

An exemption is added to silence the witness where the handler should have asked

fail-open

every new // authz: skip reason is listed in the step’s MR description and on the issue for the maintainer to overrule; none is added for a route that reads or writes a row a worker’s scope governs

boot_with makes a suite depend on a double’s timing

silent

the hung legs assert a lower bound (the budget) only, as the existing unit legs do; no upper bound on a shared host

A leg recorded as infeasible was feasible

silent

each such record names the call that blocked it, so a reader can check it

Tests

  • Regression (the case that would have caught it): the_harness_matches_routes_as_production_does (above), and a_keyed_harness_2xx_carries_the_decision_stamp: a request through the harness returns the authz-decisions header above zero on an engine-wired route. Both in keyed_harness.rs.

  • Regression, measured: after step 3 the car’s matrix line reads authz: 0 route(s) answered 2xx with no authorization decision recorded for craig-cases, and the count of craig-cases routes with unstamped 2xx records is zero (from coverage-matrix.json). Both are quoted on the issue from the merge car.

  • Contract: each handler that gains an engine call: a shipped-engine test for the admitted role and a refused one (403), and its OpenAPI responses(…​) lists 403.

  • Fault (D4): per leg, the refusal’s status, problem type and detail, that nothing was written, and one request to the double. Devstack-gated tests get their first run on luchs before the MR lands (ruling on #3093).

  • Red proof: for step 2, the witness layer is removed in the harness and both regression tests are shown to fail. For step 3, each added engine call is removed and its shipped-engine refused test is shown to fail.

  • No concurrency or property category applies: nothing here changes ordering or parsing.

Every always in this plan and the test that pins it: "the harness is always witnessed" → a_keyed_harness_2xx_carries_the_decision_stamp; "mounted exactly as production" → the_harness_matches_routes_as_production_does.

Delivery

  • Doc page: docs/modules/ROOT/pages/testing-reference.adoc, the keyed-harness section (the mount, the witness, the ive handle) and the in-process adapters' section (Peers, boot_with); docs/modules/ROOT/pages/operations/coverage-matrix.adoc loses the sentence that an in-process test mounts no witness.

  • CHANGELOG entry: none for the harness, the adapters or the tests (test-only). A changelog.d/<issue>.fixed.adoc fragment for each handler that gains an engine call in step 3, since its 2xx can become a 403.

  • Close: the plan’s issue closes with the last MR; #3154 gets a closing note that lists each item as covered (test name) or infeasible (reason), and closes only if none is left open; the plan is archived with its review log.

Erratum (2026-11-24, step 3): the step is empty. The whole craig-cases suite and the full battery ran under the witness with no authz-unwired refusal, so no handler gained an engine call, no exemption was added and no release note was due.

Erratum (2026-11-24, close): #3154 stays open. Its note lists what the step 5 legs cover and what they do not.

Review log

Round Vendor Resolved model Verdict

1

Anthropic (Vertex)

vertex-anthropic/claude-fable-5-2

FLAGS on the second question: the harness’s ScreeningWiring holds no bearer, and the peer origins had no signature. Both fixed in D3; the maintainer then approved the edited plan for implementation.

Edit this page · latest