Plan: canopy config check checks a configuration working copy (#3384)

Status: Done (2026-11-15) — four units as planned, with six errata; the boot check is #3404 and the configuration-repository pipeline job #3405
Closes: #3384
Epic: &167
Issues: #3384 (parent) · #3401 U1 (w5) · #3402 U2 (w3) · #3403 U3 (w3) · #3270 U4 (w2); follow-ups #3404 (the boot check) and #3405 (the configuration-repository pipeline job)
Branches: refactor/pack-check-library, refactor/pack-check-citations, feat/cli-config-check, docs/onboarding-config-check

This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.

Erratum (2026-11-15): the library has no TOML parse of its own. xtask had none to move, and adding one would be a new rule; a pack's TOML files are parsed by the checks that read them.

Erratum (2026-11-15): the boundary test of U3 names canopy-db, canopy-mq, lapin and the service crates, not sqlx. canopy-common depends on sqlx unconditionally, so canopy-cli linked it before this plan (#3414).

Erratum (2026-11-15): the boundary test of U3 is a unit test in canopy-cli (tools/canopy-cli/src/dependency_boundary.rs), not tests/dependency_boundary_test.rs, and reads cargo metadata, not cargo tree: the tests/ targets run on the car in an image with cargo-nextest and no cargo.

Erratum (2026-11-15): the CLI replays a pack's fixtures against the stack's decisions (the pack's copy of a name, else the federal one), not the pack's alone: a pack's fixtures describe federal decisions under its values too. The federal commit line is as designed, read from .git without running git.

Erratum (2026-11-15): beside findings the command prints notes, which fail nothing: no fixture directory, a fixture not replayed, a stale citation. Without them a clean result would hide that no fixture ran.

Erratum (2026-11-15): the CLI reads a fixture's packs against the pack's jurisdiction, not its directory name. Matched by directory, a fixture listing its own pack was skipped whenever the working copy's directory had another name, and the check passed without running it.

Context

Every xtask command that reads a pack finds layers through layer_dirs (xtask/src/config_layers.rs), which lists two roots: target/config/<layer>/current, published from config-sources.lock, and fixtures/config/. A clone of a configuration repository that the lock does not pin is in neither, so canopy cannot check it. canopy-config-texas is in that position today: its own scripts/check.py is the only check it has, and nothing on canopy’s side has confirmed its merges.

Three maintainer rulings of 2026-11-14 shape the answer:

  • xtask is a developer helper and performs no production function.

  • canopy-cli is the tool an operator uses; it stays an API client (ADR-007) and may also carry offline file checks. Jobs that need a database or key material go to a separate canopy-admin (#3399), not here.

  • canopy config check proves the pack’s own content. Proving that every service boots on the pack is a follow-up (#3404), because the nine parameter loaders live in service crates and #655 and #2210 will rewrite two of them.

What exists, and where:

  • Compile and fixture replay: check in xtask/src/cmd/rules.rs compiles every top-level *.json decision of every layer through zen-engine, as one set of layers rather than a stack, and replays fixtures from crates/canopy-test-lib/fixtures/rulesets (through canopy_zen_exact on a tokio runtime). It prints the overrides each layer manifest declares; it does not refuse an undeclared one.

  • The undeclared-override refusal: admit_replacement in services/canopy-rules/src/engine.rs (a service crate), applied when canopy-rules loads a stack. Today only a booting service enforces it.

  • The federal-constant refusal: refuse_pack_copies in crates/canopy-common/src/federal_constants.rs.

  • The citation audit: run_audit in xtask/src/cmd/policy.rs, over canopy_policy::citation, reading compliance/federal-options/*.toml and compliance/adr-031-citation-orphan-allowlist.toml from the canopy tree, with a --max-staleness-days flag (default 365). The orphan allowlist’s entries are a family and a key, with no layer: nine citations whose value lives in JDM rule content or service code.

  • The paired SNAP clocks: xtask/src/cmd/processing_days_lint.rs, which also resolves service YAML tiers under config/.

  • canopy-cli: every command but completion opens a session (dispatch, tools/canopy-cli/src/main.rs). tools/canopy-cli/tests/cli_reference_drift_test.rs holds canopy --help to docs/modules/ROOT/pages/tooling/canopy-cli.adoc.

Scope

In scope:

  • A library crate, crates/canopy-pack-check, holding the checks below; xtask’s verbs and canopy-cli both call it.

  • canopy config check <pack-dir> --federal <federal-dir>: offline, with no session.

  • ADR-007 Amendment 5: canopy-cli may carry offline file checks; it links no database, message-queue or service crate, and a test holds that.

  • jurisdiction-onboarding.adoc rewritten around the command, as its own unit: the last page of #3270, which has waited on this command.

Out of scope:

  • The boot check (each service’s parameter loader on the pack): #3404, after #655 and #2210.

  • rules lint-inputs and scenarios audit for a working copy: both read canopy-tree data that names canopy’s own layers (compliance/adr-011-ruleset-input-allowlist.toml, compliance/scenario-inventory/). They stay car-only; the pin’s car runs them.

  • A job in the configuration-repository pipeline template: it needs a released canopy image, and no tag is cut yet (#3355). Follow-up #3405.

  • The other production verbs in xtask (#3399).

  • Any change to what a check accepts. The checks move; their rules do not.

Design

The library

canopy-pack-check discovers no layer: every function takes the directories it reads as arguments. So the same code serves xtask (which passes the layers layer_dirs found) and the CLI (which passes the federal directory and the working copy). Each function returns typed findings (the check, the file, a message) and prints nothing; callers render.

Two kinds of function, because xtask checks a set of unrelated layers and the CLI checks one stack:

Per layer directory (xtask calls these for each layer; the CLI for the pack):

  1. Parse. Every .json and .toml in the layer parses.

  2. Compile. Every top-level *.json decision compiles through zen-engine (moved from xtask/src/cmd/rules.rs).

  3. Fixture replay. Each fixture in a given fixture directory is replayed against its compiled decision. xtask passes crates/canopy-test-lib/fixtures/rulesets as now; the CLI passes the pack’s own fixtures/rulesets/ (the config plan’s 2026-11-07 erratum put a pack’s fixtures in its repository).

  4. Federal constants. refuse_pack_copies (unchanged, in canopy-common) over a pack’s jurisdiction.toml.

  5. Citations. The canopy_policy::citation audit of jurisdiction.toml against citations.toml, with the staleness limit as an argument. The federal option keys and the orphan allowlist are compiled into the library from compliance/federal-options/*.toml and compliance/adr-031-citation-orphan-allowlist.toml with include_str!, so a binary enforces the lists of its own version and a working copy is audited exactly as the car audits a pinned pack. xtask stops reading the two from disk.

  6. Paired clocks. The pack half of the processing-days check: [snap.issuance] against [shared.application_processing] in one jurisdiction.toml. The YAML-tier half stays in xtask, which owns config/.

Per stack (an ordered list of layer directories, lowest precedence first):

  1. Overrides. A decision that replaces one of a lower layer is listed under overrides in the replacing layer’s manifest. admit_replacement moves from canopy-rules into the library and canopy-rules calls it there, so the service and the check share one rule. The CLI runs it on federal then pack. xtask’s rules check does not call it: its behaviour is unchanged, and the pinned packs' stacks are refused, as today, by canopy-rules booting on the car.

The library depends on canopy-config, canopy-policy, canopy-common, canopy-zen-exact, zen-engine, tokio, serde, serde_json and toml: all workspace dependencies already, so no new external dependency is added. Through it canopy-cli gains zen-engine and canopy-zen-exact.

The command

canopy config check <pack-dir> --federal <federal-dir> [--max-staleness-days <n>]
  • Output follows canopy-cli’s existing global --format table|json (output::Format); no new format flag. --max-staleness-days defaults to 365, as xtask policy audit does.

  • It opens no session and reads no profile: dispatch handles it beside completion, before Session::open.

  • The stack is federal (the --federal directory), then the pack. Both are read as plain directories; no signature is verified, and the output says so in its first line, naming both paths.

  • Exit status: 0 with no finding, 1 with any finding, 2 when a directory cannot be read or is not a layer. Every finding is printed; the run does not stop at the first.

  • It refuses (exit 2) a <pack-dir> whose canopy-config.toml is missing or does not declare layer = "jurisdiction", and a --federal directory that carries a jurisdiction.toml. This is the command’s rule, not the library’s: canopy’s fixture layers carry other manifests and are checked by xtask.

Until a release exists, a pack author runs it from a canopy checkout (cargo run -p canopy-cli — config check …). The service image already ships the binary at /app/canopy; the pipeline-template follow-up uses that once a tag is cut.

xtask after the move

cargo xtask rules check, policy audit and rules processing-days keep their names, flags, output and car lines; each builds its stack from layer_dirs and calls the library. No lint is added or removed, so GATE_LINES, STEPS, BUILD_GATES, the .lints block and the validate stage count do not change.

Units (weights by complexity) — U1 → U2 → U3 → U4

U1 (w5) — the library, with compile, overrides and fixture replay (#3401)

Files: crates/canopy-pack-check/ (new: Cargo.toml, src/lib.rs, src/compile.rs, src/overrides.rs, src/replay.rs, src/report.rs), Cargo.toml (workspace member and dependency), xtask/src/cmd/rules.rs, xtask/Cargo.toml, services/canopy-rules/src/engine.rs, services/canopy-rules/Cargo.toml, docs/modules/ROOT/pages/shared-crates.adoc.

Parse, compile and fixture replay move from xtask; the override rule moves from canopy-rules. xtask rules check calls the per-layer functions and canopy-rules calls the override function. Tests: regression, the existing tests of xtask rules check (a planted bad decision, a failing fixture) and of canopy-rules' engine (declared and undeclared replacement) stay green over the library; a library test of the override function on a two-layer stack, declared and undeclared; contract, the finding shape; property, compile returns a finding and does not panic on arbitrary JSON bytes.

U2 (w3) — citations, federal constants and paired clocks (#3402)

Files: crates/canopy-pack-check/src/{citations,federal_constants,clocks}.rs (with include_str! of each compliance/federal-options/*.toml and of compliance/adr-031-citation-orphan-allowlist.toml), xtask/src/cmd/policy.rs, xtask/src/cmd/processing_days_lint.rs.

Tests: regression, xtask policy audit and rules processing-days keep their existing tests green over the library; a test that the files compiled in are exactly the files under compliance/federal-options/ (so a new file cannot be forgotten).

U3 (w3) — canopy config check; closes #3384 (#3403)

Files: tools/canopy-cli/src/main.rs, tools/canopy-cli/src/cmd/config.rs (new), tools/canopy-cli/Cargo.toml, tools/canopy-cli/tests/config_check_test.rs (new), tools/canopy-cli/tests/dependency_boundary_test.rs (new), docs/modules/ROOT/pages/adrs/adr-007-cli-api-ui-parity.adoc (Amendment 5), docs/modules/ROOT/pages/tooling/canopy-cli.adoc, docs/modules/ROOT/pages/local-dev.adoc, CHANGELOG.adoc.

Tests, driving the built binary on temporary layer directories copied from fixtures/config/test-federal and fixtures/config/test-min:

  • regression: a clean pair exits 0; each planted defect (a decision that does not compile, an undeclared override, a restated federal constant, an uncited key, a failing fixture, disagreeing clocks) exits 1 and names the file; two defects are both reported.

  • contract: --format json output against a typed struct; the exit statuses 0, 1 and 2 (2 for a missing directory, a pack without a jurisdiction manifest, a federal directory with a jurisdiction.toml).

  • regression, "opens no session": the command succeeds with XDG_CONFIG_HOME (which config::config_dir honours on every OS) set to an empty temporary directory and no profile, and leaves that directory empty.

  • regression, the ADR-007 boundary: dependency_boundary_test runs cargo tree -p canopy-cli -e normal --offline and fails if the output names sqlx, lapin, canopy-db, canopy-mq or any services/ crate.

  • the existing cli_reference_drift_test covers the documentation row.

U4 (w2) — onboarding page; closes #3270

Files: docs/modules/ROOT/pages/jurisdiction-onboarding.adoc.

The page still tells an author to copy fixtures/config/default to rulesets/{slug} and run xtask audits against it. It is rewritten around a configuration repository and canopy config check. Docs only; no test.

Risks

Risk Mode Mitigation

A check behaves differently after the move, so the car accepts a pack it refused before

fail-open

Each xtask verb keeps its existing tests over the library; U1 and U2 change no rule, and the car runs the same lines against the pinned packs

The CLI passes a pack that a service refuses at boot (a loader-only rule)

fail-open

Stated in the command’s output and docs: a clean check is not a boot proof; the pin’s car is the gate. The boot-check follow-up (#3404) closes it

The compiled-in federal option keys drift from compliance/federal-options/

silent

U2’s test compares the compiled list with the files

An author checks against a stale federal clone

silent

The first output line names the federal directory and, when it is a git checkout, its commit

The override rule moved out of canopy-rules is called differently by the service

fail-open

canopy-rules' existing engine tests for declared and undeclared replacement stay, now over the library

canopy-cli grows a path to a database or service crate through the new dependency

fail-closed

U3’s dependency_boundary_test fails the unit lane when canopy-cli’s dependency tree names one; ADR-007 Amendment 5 states the rule

The compiled-in orphan allowlist admits, for another pack, a citation key it should not

fail-open

The nine entries are keys whose value canopy’s own code or shared JDM content holds; the car audits pinned packs with the same list today, so nothing loosens

Verification

  1. After U1 and U2: the car’s rules check, policy audit, policy audit --source federal and rules processing-days lines pass unchanged on the pinned federal and Georgia layers.

  2. After U3: canopy config check on a clone of canopy-config-georgia at its pinned commit, with a clone of canopy-config-federal, exits 0; on canopy-config-texas it reports whatever it finds, sent to the Texas agent on rules.

  3. The planted-defect tests of U3 pass on the car.

Documentation Updates

  • tooling/canopy-cli.adoc — the config check row and a section on offline commands (canonical page)

  • adrs/adr-007-cli-api-ui-parity.adoc — Amendment 5

  • jurisdiction-onboarding.adoc — rewritten around the command (U4); closes #3270

  • local-dev.adoc — the pack author’s loop

  • shared-crates.adoc — canopy-pack-check

  • CHANGELOG.adoc — an entry under == Unreleased in each unit’s MR

  • Close: U3’s MR says Closes #3384 and U4’s Closes #3270; the plan’s Status is set to Done and the merge SHA noted on #3384

Review log

  • 2026-11-14 — round one (claude) and round two (gemini) both flagged the draft; the plan was revised for the orphan allowlist (compiled in rather than dropped), canopy-cli’s existing --format, the replay’s real dependencies (canopy-zen-exact, tokio), the staleness flag, the per-layer versus per-stack split (xtask checks unrelated layers; only the CLI checks a stack), the onboarding page as its own unit, and the session and dependency-boundary tests. Approved by the maintainer as revised.

Edit this page · default