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 checkproves 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:
checkinxtask/src/cmd/rules.rscompiles every top-level*.jsondecision of every layer through zen-engine, as one set of layers rather than a stack, and replays fixtures fromcrates/canopy-test-lib/fixtures/rulesets(throughcanopy_zen_exacton a tokio runtime). It prints the overrides each layer manifest declares; it does not refuse an undeclared one. -
The undeclared-override refusal:
admit_replacementinservices/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_copiesincrates/canopy-common/src/federal_constants.rs. -
The citation audit:
run_auditinxtask/src/cmd/policy.rs, overcanopy_policy::citation, readingcompliance/federal-options/*.tomlandcompliance/adr-031-citation-orphan-allowlist.tomlfrom the canopy tree, with a--max-staleness-daysflag (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 underconfig/. -
canopy-cli: every command but
completionopens a session (dispatch,tools/canopy-cli/src/main.rs).tools/canopy-cli/tests/cli_reference_drift_test.rsholdscanopy --helptodocs/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.adocrewritten 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-inputsandscenarios auditfor 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):
-
Parse. Every
.jsonand.tomlin the layer parses. -
Compile. Every top-level
*.jsondecision compiles through zen-engine (moved fromxtask/src/cmd/rules.rs). -
Fixture replay. Each fixture in a given fixture directory is replayed against its compiled decision. xtask passes
crates/canopy-test-lib/fixtures/rulesetsas now; the CLI passes the pack’s ownfixtures/rulesets/(the config plan’s 2026-11-07 erratum put a pack’s fixtures in its repository). -
Federal constants.
refuse_pack_copies(unchanged, in canopy-common) over a pack’sjurisdiction.toml. -
Citations. The
canopy_policy::citationaudit ofjurisdiction.tomlagainstcitations.toml, with the staleness limit as an argument. The federal option keys and the orphan allowlist are compiled into the library fromcompliance/federal-options/*.tomlandcompliance/adr-031-citation-orphan-allowlist.tomlwithinclude_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. -
Paired clocks. The pack half of the processing-days check:
[snap.issuance]against[shared.application_processing]in onejurisdiction.toml. The YAML-tier half stays in xtask, which ownsconfig/.
Per stack (an ordered list of layer directories, lowest precedence first):
-
Overrides. A decision that replaces one of a lower layer is listed under
overridesin the replacing layer’s manifest.admit_replacementmoves 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’srules checkdoes 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-daysdefaults to 365, asxtask policy auditdoes. -
It opens no session and reads no profile:
dispatchhandles it besidecompletion, beforeSession::open. -
The stack is
federal(the--federaldirectory), 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>whosecanopy-config.tomlis missing or does not declarelayer = "jurisdiction", and a--federaldirectory that carries ajurisdiction.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 jsonoutput 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 ajurisdiction.toml). -
regression, "opens no session": the command succeeds with
XDG_CONFIG_HOME(whichconfig::config_dirhonours on every OS) set to an empty temporary directory and no profile, and leaves that directory empty. -
regression, the ADR-007 boundary:
dependency_boundary_testrunscargo tree -p canopy-cli -e normal --offlineand fails if the output namessqlx,lapin,canopy-db,canopy-mqor anyservices/crate. -
the existing
cli_reference_drift_testcovers 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 |
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 |
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
-
After U1 and U2: the car’s
rules check,policy audit,policy audit --source federalandrules processing-dayslines pass unchanged on the pinned federal and Georgia layers. -
After U3:
canopy config checkon 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 onrules. -
The planted-defect tests of U3 pass on the car.
Documentation Updates
-
tooling/canopy-cli.adoc— theconfig checkrow 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== Unreleasedin each unit’s MR -
Close: U3’s MR says
Closes #3384and U4’sCloses #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.