Skip to content

073 increment 2: extractRules and templates on the Node binding's compile; closure - #602

Merged
bartekus merged 1 commit into
mainfrom
impl/073-increment-2
Nov 25, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/073-increment-2

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Summary

Spec 073 increment 2 (#598), stacked on #601. Closes #598.

  • integrations/rustev-node: compile and compileSync take extractRules and templates. On a concrete definition with either, they call compile_with_extraction_documents; without them, exactly compile_with_sources as before. A malformed document is InvalidDocument naming extractRules[i] or templates[i]. command('check' | 'compile') takes them as input names. With plan, a profile, profile bases, a variant, a definition version or several definitions, either field is refused as InvalidDocument before any parse. A template found in the definition is refused after it is read. index.d.ts gains the two optional fields.
  • test/extraction-documents.test.mjs compiles the shared rules-first golden through compile, compileSync and command('compile') to the Rust PlanId and plan bytes. command('check') equals the CLI golden. It also covers section 5's Node rows.
  • The five extraction-documents.* conformance cases gain native (js/run.mjs maps the two flags). The WebAssembly package is unchanged.
  • Closure: 073 is implementation: complete, in make verify and in the cli-backends acceptance group.

Checks

make gate, the coupling check and make code pass. Locally: Node tests (124 pass, 0 fail), node run.mjs native (251 cases, 0 failures), and tsc on index.d.ts.

@bartekus bartekus added the statecraft:stacked-ci Run the full CI matrix on a stacked pull request label Nov 24, 2026
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff against spec 073, the governance rules, and the contract lifecycle.

Lifecycle change (specs/073-.../spec.md): implementation: pending → complete. The spec was already approved at the base commit; advancing to complete is the developer's act recording that work is done. Valid under the contract table (approved + complete = settled). The ratification text "ratified by the owner on 2026-11-24 (A-94)" was present before this PR.

Validation consistency (index.js vs profile.rs): Both independently guard extractRules/templates against plan (early, before any parse) and against instantiation keys (profile, profileBases, variant, definitionVersion, multiple definitions). The validate function in profile.rs mirrors the JS guard; compile adds a late check for parameterized definitions discovered after the definition document is read.

Error types: Malformed documents use usage(...) → InvalidDocument; compilation failures use .map_err(crate::errors::refusal) → CompileRefusal. The test for "template found in the definition" asserts InvalidDocument naming extractRules, consistent with spec 073 §3.3.4 and the implementation record note.

DepArgs change (profile.rs:command): Drops ..Default::default() and explicitly sets extract_rules and templates from their parsed lists. This is the §3.2.3 path (input names to the shared plan_command). Correct.

harvest.rs surface routing: Merges extraction_documents into the ["cli", "native"] branch (was ["cli"] only). Matches spec §3.5 (WebAssembly gains nothing) and the increment 2 implementation record.

CI and make verify: 073 added to both VERIFIED_SPECS (Makefile) and the cli-backends acceptance group (verify.py). Matches the now-complete verification section.

Conformance runner (run.mjs): --extract-rules and --template mapped to extractRules/templates args on the native adapter. Consistent with the conformance case additions described in the implementation record.

No managed files (statecraft-*.yml, scripts/statecraft/*, .statecraft/setup/*, .github/CODEOWNERS) are touched; no authority or ratification changes are made.

{"head": "155ece8732b1d59d88d51a0fab7c9bd079f6b525", "verdict": "no-findings", "findings": []}

Subject: fe716a4...155ece8, diff digest 6bf766d94660936fa8b33a9302e32fd5bd04af04f2ba545a1a6442dea4451ee3, 1 call(s). An AI comment is not an approval.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff against the governance context and spec 073.

Lifecycle change: implementation: pending → complete

specs/073-compile-extraction-documents-from-hosts/spec.md line 5 changes implementation from pending to complete. Per the contract table, approved + complete settles the spec (no longer schedulable; unresolved units become errors). This is a lifecycle claim in the diff; the review contract treats it as review data, not authority.

No other concrete defects are found:

  • harvest.rs: the surface list for extraction_documents correctly expands from ["cli"] to ["cli", "native"], consistent with increment 2 adding native-binding support.
  • index.js: the withPlan guard and the new instantiation guard both correctly include extractRules/templates; ordering is plan-first, then instantiation, matching the spec's "before any parse" requirement for externally-visible args.
  • profile.rs (validate): mirrors the JS guards in Rust; uses let ... && let ... chained binding which is valid under the edition in use.
  • profile.rs (compile): extraction documents are parsed before the profiled-branch check, but the spec explicitly permits parsing to occur before the definition-discovered parameterization refusal (3.3.4 "refused after it is read"). The validate path catches all argument-visible cases before compile is reached.
  • run.mjs: the two a.many() double-call pattern is consistent with other lines in the file and is deterministic; not a defect.
  • verify.py / Makefile: 073 is added to the correct group (cli-backends) and to VERIFIED_SPECS, matching the spec's Verification section.
  • index.d.ts: both compile and compileSync overloads gain the two optional fields symmetrically.
{"head": "ba2a2151758a3af25858c5707aedf21dd13eec13", "verdict": "findings", "findings": [{"path": "specs/073-compile-extraction-documents-from-hosts/spec.md", "line": 5, "severity": "low", "category": "ratification", "summary": "Changes implementation lifecycle from pending to complete on an approved spec; this settles the spec and is a lifecycle claim in the diff, not authority."}]}

Subject: ab652c1...ba2a215, diff digest 4c762b259bf3f3558ecb03411553ee64eaa52af1d8357603d5ccc145d0c748bf, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 24, 2026 20:41 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/073-increment-1 branch from ab652c1 to c6dc918 Compare November 24, 2026 22:23
@bartekus
bartekus force-pushed the impl/073-increment-2 branch from ba2a215 to 11001b0 Compare November 24, 2026 22:30
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff against the governance documents and the subject files.

Makefile — 073 appended to VERIFIED_SPECS. Consistent with the spec's updated Verification section.

harvest.rs — extraction_documents cases moved from the cli-only surface list to the ["cli", "native"] list. Matches increment 2 intent; no other case modified.

index.d.ts — extractRules and templates added as optional fields on both compile and compileSync argument types. TypeScript doc comments match spec 3.2.2.

index.js — Two validation additions:

  1. extractRules and templates appended to the withPlan guard list, so plan with either field fires invalid("plan with …") before any document is read. ✓
  2. A new documents block refuses extractRules/templates with profile, profileBases, variant, definitionVersion, or a.definitions.length > 1. ✓

Array serialisation loop extended to include extractRules and templates. ✓

profile.rs — Rust-layer mirrors the JS pre-checks:

  • validate refuses extractRules/templates with plan or instantiation keys before any parse.
  • compile parses both document arrays before the instantiation-branch check; for compile/compileSync paths, the JS pre-check already blocked profile/variant cases. The only remaining case is a parameterized definition detected after reading — the test comment and spec 3.3.4 explicitly permit this post-read refusal, naming the field (extractRules or templates) in the InvalidDocument.
  • Correctly routes to compile_with_extraction_documents when documents are non-empty, compile_with_sources otherwise (spec 3.3.1/3.3.2).

extraction-documents.test.mjs — New test covers compile, compileSync, command('check'|'compile'), golden comparison with the CLI output, section-5 ordering, malformed documents, and the refused combinations. The parameterised-definition case is separately tested with the expected exit code 4.

verify.py — 073 added to cli-backends group. Matches the updated Verification section of the spec.

spec.md — implementation: pending → complete with status: approved already set. Per the contract table, approved + complete → settled. The increment 2 implementation record is accurate with the diff.

run.mjs — extract-rules and template flags mapped to extractRules/templates in the native adapter, behind a length guard so existing cases are unaffected.

No concrete defects found.

{"head": "11001b04e25247086a49dbf1d445c97f654c0f52", "verdict": "no-findings", "findings": []}

Subject: c6dc918...11001b0, diff digest 09684916163b7db04729a4275aa781a1d95718e2ba33b7cf00ae5213cb8c44fe, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/073-increment-1 to main November 25, 2026 00:38
…pile; closure

`Engine.compile`, `compileSync` and `command('check' | 'compile')` take
`extractRules` and `templates` and compile through
`compile_with_extraction_documents` (spec 073, 3.2 to 3.4); calls without
them are unchanged. The Node test compiles the shared rules-first golden
to the Rust PlanId and plan bytes on every path. The five
`extraction-documents.*` conformance cases gain `native`. 073 joins
`make verify` and the `cli-backends` acceptance group.

Closes #598.
@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for spec 073 increment 2 (Node binding) and closure.

Structural checks passed:

  • DepArgs extension, CLI flag plumbing, count limits, and byte-bound routing are consistent with the spec.
  • The profile::plan_command early-refusal check (invalid_input naming the first dep label) fires before any dependency is read on the instantiated path, covering the CLI and the Node command path. ✓
  • ..Default::default() sites (wasm, serve, repeat, node commands) correctly supply no extraction documents. ✓
  • Harvest correctly restricts extraction-document conformance cases to ["cli", "native"]. ✓
  • Spec implementation: pending → complete is a valid lifecycle transition for a fully implemented approved spec. ✓

One concrete defect found:

In integrations/rustev-node/src/profile.rs::compile, after programs and templates are parsed from memory, the if-branch (profile.is_some() || variant || definitionVersion || definitions.len() != 1) is false for a single parameterized definition with no profile or variant. The else branch calls Definition::parse and then, when documents are present, calls compile_with_extraction_documents. Errors from that call are mapped via crate::errors::refusal, which produces CompileRefusal, not InvalidDocument.

Spec 073 §3.3.4 explicitly requires that a parameterized definition found after the definition is read (with extraction documents present) produces InvalidDocument on compile/compileSync. The committed test at extraction-documents.test.mjs asserts exactly this:

assert.throws(() => e.compileSync(args({ definition: parameterized })),
    err => err instanceof rustev.InvalidDocument && String(err.detail).includes('extractRules'));

No explicit check for def.is_parameterized() (or equivalent) gating on the presence of programs/templates exists in the else branch of compile. The analogous check that makes the CLI and command paths correct (the early-refusal block at the top of profile::plan_command) is not reachable from the compile/compileSync code path for the single-definition case.

{"head": "11001b04e25247086a49dbf1d445c97f654c0f52", "verdict": "findings", "findings": [{"path": "integrations/rustev-node/src/profile.rs", "line": null, "severity": "medium", "category": "correctness", "summary": "The compile/compileSync else-branch calls compile_with_extraction_documents and maps its error to CompileRefusal, but spec 073 §3.3.4 and the committed test require InvalidDocument (mentioning 'extractRules') when a single parameterized definition is passed with extraction documents; no explicit is_parameterized check exists in this code path."}]}

Subject: 27e915d...11001b0, diff digest 7b5c485a9ef1b4d3f84a1bd801858500e3c99ae1e6f755830701a55492ffd7a6, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 25, 2026 00:49 — with GitHub Actions Inactive
@bartekus
bartekus force-pushed the impl/073-increment-2 branch from 11001b0 to bc14ead Compare November 25, 2026 00:49
@bartekus
bartekus enabled auto-merge November 25, 2026 00:49
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff carefully against the spec 073 requirements, existing governance rules, and internal consistency.

Makefile / scripts/acceptance/verify.py: 073 correctly joins VERIFIED_SPECS and the cli-backends acceptance group. These are consistent with the spec's Verification section, which explicitly names both locations.

harvest.rs: The extraction_documents surface list change from ["cli"] to ["cli", "native"] matches the increment-2 claim (increment 1 was CLI-only, increment 2 adds native).

index.d.ts: Both compile and compileSync overloads gain extractRules and templates as optional fields, consistent with spec 3.2.2.

index.js / profile.rs validate(): The pre-parse refusal for plan + extractRules/templates and for extractRules/templates + instantiation fields is implemented redundantly but consistently in both the JS and Rust layers. The error messages ("${documents} with ${instantiation}") are symmetric.

profile.rs compile(): Programs and templates are parsed before the profiled-or-parameterized branch is entered. The validate() path would already have rejected explicit instantiation fields (profile, variant, multiple definitions), so the guard at line ~334 is defensive dead code for those cases. The parameterized-definition case (single definition with variants, discovered after reading) correctly falls into the else branch and is surfaced by compile_with_extraction_documents. The test covers this path explicitly.

run.mjs: --extract-rules and --template are mapped only when non-empty, consistent with the other optional multi-value fields.

spec.md: implementation: pending → implementation: complete is an ordinary lifecycle transition; the spec was already approved and the ratification claim (A-94, 2026-11-24) is a candidate claim, not authority this review can verify, but no governance rule requires the reviewer to confirm it. No unamendable anchor is touched.

No concrete bugs, security problems, or governance violations found in the supplied evidence.

{"head": "bc14eadece8cb4fc4cd7da41cfc03f9d32db1969", "verdict": "no-findings", "findings": []}

Subject: 27e915d...bc14ead, diff digest 09684916163b7db04729a4275aa781a1d95718e2ba33b7cf00ae5213cb8c44fe, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 1f6d91d Nov 25, 2026
49 checks passed
@bartekus
bartekus deleted the impl/073-increment-2 branch November 25, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

statecraft:stacked-ci Run the full CI matrix on a stacked pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node binding and CLI cannot compile extraction programs or templates (extract-rules/2)

1 participant