Skip to content

feat(cedar): dogwood CLI-gated validation split (#1659) - #1677

Merged
lex00 merged 2 commits into
mainfrom
dogwood/validation
Aug 10, 2026
Merged

lex00 merged 2 commits into
mainfrom
dogwood/validation

Conversation

@lex00

@lex00 lex00 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1659. Part of epic #1646, stacked on dogwood/dialect (#1658).

The cedar release shipped (chant-v0.44.8), so the hold is lifted and this is ready for review. Still based on dogwood/dialect (#1672) rather than main — rebased onto the new tip 223c2c03, clean, no conflicts, and the diff is unchanged from the drafted version. Merges after #1672.

What the split looks like now

The epic's decision, verbatim: "Everything answerable in TypeScript runs always and gates … Full .dw validation shells to dogwood validate when present and warns-and-skips when absent — an explicit, issue-linked exception, not a silent one."

The DWDC walls #1658 shipped are the always-on half. This adds the other half.

src/dogwood/cli.ts — the adapter

Locates a dogwood binary (explicit override → $CHANT_DOGWOOD_BINARY → cedar.dogwood.binary → PATH), runs validate and lower with --format json, and normalizes both JSON shapes into one result type. The sharp edges from the #1657 report are handled, not assumed away:

  • Exit codes identify nothing. Exit 2 covers a rejected policy set and clap's own unknown-flag usage error (the guide claims 1 for the latter; the binary spends 2). Nothing here branches on the code. The JSON on stdout decides, and a run that produced no JSON is unusable — reported as "the CLI could not be used", never as "your policy is bad". That is what keeps a flag rename in an upstream sync from failing builds.
  • Two JSON shapes. A type-check finding arrives in a ValidateReport ({passed, passed_without_warnings, errors[], warnings[]}); a fatal parse/macro/lowering error replaces the whole report with a flattened OpError plus related[]. Both parse.
  • --emit is not passed, since --format json ignores it and returns all three lowered artifacts regardless.
  • Labels stay byte offsets, because that is what upstream reports; an internal at line N column M tail is scrubbed the way wasm-helpers.ts already scrubs cedar-wasm's.

The contract was re-read from the pinned dogwood-cli/src/{ops,main,error}.rs rather than from the human text — the report structs are the integration surface, the renderer is the part a sync retunes.

The two checks

id severity what it does
DWDE010 error / warning / info Runs dogwood validate over each emitted bundle (policies + action schema + event schema + macros) and maps every diagnostic. Upstream warnings ride along at warning. A run that could not be made is warning, not error. With no binary: exactly one info advisory naming the binary, where chant looked, and #1659.
DWDE011 error / warning Runs dogwood lower --format json, feeds cedar_policies + cedar_schema to @cedar-policy/cedar-wasm validate(). type === "success" is asserted together with an empty validationErrors, and findings are sorted — the #1648 traps. Silent when lower did not run; DWDE010's advisory covers that once.

dogwood-helpers.ts plans the invocations once so the two checks never disagree about what they ran: a macro library is told from a policy set by structure (no permit/forbid head) rather than by filename, several libraries concatenate into the one file --macros accepts, and several .dwschema files mean several runs each naming its own schema instead of one picked silently.

Config

cedar.dogwood.binary joins the namespace, z.strictObject intact. It is honoured from chant.config.json; a chant.config.ts cannot be read from inside a post-synth check — check() is synchronous and loadChantConfigUpward is async and may evaluate project code in a sandboxed child — so CHANT_DOGWOOD_BINARY covers that case. Documented in place rather than pretended away.

Tests

Every case injects a runner, and the absent-binary case forces absence rather than hoping the machine has none, so a developer with dogwood built locally sees what CI sees. Fixtures cover a passing validate, a rejection, both JSON shapes, the exit-2 ambiguity, a spawn failure, the absent-binary advisory, and a lower+wasm round trip over a checked-in lowered artifact adapted from dogwood-policy/dogwood@5063bcc2 (Apache-2.0), dogwood-docs/examples/read_after_login. An opt-in describe.skipIf block exercises a real binary behind CHANT_DOGWOOD_E2E=1; nothing in gating depends on it.

Gates

  • tsc -p lexicons/cedar/tsconfig.build.json — clean
  • npm run build -w @intentius/chant-lexicon-cedar — clean
  • npx vitest run lexicons/cedar — 549 passed, 2 skipped (the opt-in pair), 33 files
  • npx tsx scripts/check-lexicons.ts — exit 0, cedar 21/21, no new untracked
  • npx tsx scripts/typecheck.ts — 85 known failures, no regressions
  • node scripts/depcheck.mjs — no undeclared runtime dependencies (the adapter uses node builtins only)
  • npx tsx scripts/generate-post-synth-barrels.ts — the committed barrel is byte-identical to the generated one (cedar now ships 16 checks)

Re-run in full after the rebase onto 223c2c03.

Deviations

  • A third advisory case. Policies emitted with no .cedarschema beside them also gets an info from DWDE010, because --policy-schema is not optional and a check that could not run should say so. Same shape as the absent-binary advisory, same issue link.
  • plugin.ts and serializer.ts are untouched — the new checks reach the plugin through the generated post-synth barrel and the audit catalog, so there was nothing to append.

The epic's split, built: everything answerable in TypeScript already runs
and gates under DWDC; full .dw validation shells to `dogwood validate`
when the binary is present and warns-and-skips with an issue-linked
advisory when it is not.

- src/dogwood/cli.ts adapts the CLI. Nothing branches on the exit code:
  exit 2 covers a rejected policy set and clap's own unknown-flag usage
  error alike, so the JSON on stdout decides and a run that produced none
  is "unusable", never "rejected". Both JSON shapes are parsed — the
  ValidateReport and the flattened OpError fatal channel — and internal
  line/column tails are scrubbed the way wasm-helpers already scrubs
  cedar-wasm's. `--emit` is not passed, since --format json ignores it.
- DWDE010 runs `dogwood validate` over each emitted bundle and maps
  diagnostics with their byte-offset labels; with no binary it emits
  exactly one info advisory naming the binary, where chant looked, and
  #1659.
- DWDE011 runs `dogwood lower --format json` and feeds cedar_policies +
  cedar_schema to @cedar-policy/cedar-wasm validate() — the #1648 traps
  apply, so success is asserted together with an empty, sorted
  validationErrors. Silent when lower did not run.
- cedar.dogwood.binary joins the config namespace (strictObject kept),
  with CHANT_DOGWOOD_BINARY covering the chant.config.ts case a
  synchronous post-synth check cannot read.
- Tests inject the runner throughout; a real binary is opt-in behind
  CHANT_DOGWOOD_E2E and gates nothing. The lowered fixture is adapted
  from dogwood-policy/dogwood@5063bcc (Apache-2.0), read_after_login.

Part of #1646

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ
@lex00
lex00 force-pushed the dogwood/validation branch from 7cd77c9 to 2c7d7da Compare August 10, 2026 20:46
@lex00
lex00 changed the base branch from dogwood/dialect to main August 10, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dogwood 3/6: validation split + lint walls

1 participant