Skip to content

Compose a WIT closure for a consumer, and gate it as a system - #230

Merged
avrabe merged 1 commit into
mainfrom
feat/export-wit-cmd
Oct 1, 2026
Merged

avrabe merged 1 commit into
mainfrom
feat/export-wit-cmd

Conversation

@avrabe

@avrabe avrabe commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

varve export-wit --package ns:name@ver --out D writes that package plus its
transitive closure into <ns>/<name>/<version>.wasm — the layout wkg's local
backend reads — from packages already in the verified store, offline. The
closure comes from the packages' own signed bytes, never from a list in
layer.toml. --registry NAME prints the wkg stanza rather than editing
anyone's configuration.

#229 deliberately stopped short of this: REQ-SYSTEST-002 clause 5 ratchets on
clap's export-* list, so the subcommand could not ship until a system gate
exercised it. That gate is the substance of this PR.

The gate

tools/systest/wit-export.sh deposits two separately-encoded binary WIT
packages as kind = "wit" payloads, signs them, installs, verifies, and
composes them.

What only a system run shows. The unit tests index packages from bytes
handed to them directly. Here the bytes cross deposit, signing, an OCI layout,
install and verification before anything decodes them — and the gate asserts
they come out byte-identical to the deposited fixtures. That is DD-036's
"copy, not a conversion" claim, and it is what makes the digest in the layer
and the digest on disk the same number.

The command is asked for acme:app@0.3.0 alone and must write
acme:base@2.0.0 beside it, because the app's own signed bytes say it imports
it. Two refusals close clause 4: a package the layer does not carry, and a
layer carrying the app but not its dependency — which must write nothing at
all, because a tree one package short parses far enough to fail inside
wit-bindgen with a message about an interface.

The gate was negative-controlled. witclosure::closure was mutated to
return only the root; the mutation was confirmed present in the rebuilt binary
(exported 1 package(s)), and the gate went red on the dependency it did not
write.

Three gate defects found on the way

All the same shape, and worth reading as a set.

  1. The docs gate kept a second list beside the match that parses each block.
    A documented wkg stanza was reported unclassified while the arm checking it
    ran. Whether a block reached a parser is now read from the match, so the
    two cannot drift.

  2. The first version of that stanza check was vacuous. It extracted the
    registry and root from the block, fed them back to wkg_stanza, and
    compared — which passes for any block of that shape. A negative control
    caught it. It now compares templates with both values blanked, so a
    change to the key path, the field name or the quoting fails. Controlled by
    renaming root to path in wkg_stanza and reading the verdict.

  3. Nothing noticed that ExportWit had been pasted inside ExportSdk's doc
    comment.
    export-wit --help described SDK relocation; export-sdk --help
    was blank. Every gate stayed green — the docs gate checks that a topic
    exists, which it did. every_subcommand_says_what_it_does closes it (blank
    is the signature of a stolen doc comment), controlled by deleting
    export-vsix's.

systest_sign_spec_and_pin is extracted from systest_make_layer so the new
gate signs its spec through the same code the self-host gate does, rather than
a second copy to keep in step with deposit-layer.yml.

A correction to DD-036, and a decision that is yours

DD-036 said "the export path emits WIT text", offered as part of the
mitigation for the auditability cost of signing a compiled package. It does
not, and I did not make it.
I have corrected the decision text rather than
leave it contradicting the code — but the correction is not a tidy one, because
of what #220 measured:

consumer wants served by this PR
wkg binary package tree yes
rules_wasm_component (wkg_wit_deps) a WKG registry yes
wit-bindgen wit/ source tree no
cargo-component wit/ source tree no
rules_wasm_component (vendored) local WIT files no

Three of the five consumers #220 measured want text, and this export does
not produce it. They can decode it themselves — wasm-tools component wit <file>, and wasm-tools is in the realm — but that is a step, not a path.

The decision is a dependency one and it is yours. wit-parser 0.259
carries no printer; WitPrinter lives in wit-component, which would add
wasm-encoder and wasm-metadata to the production trusted base in order to
produce a form varve does not sign. #229 recorded the decoding dependency as
deliberately read-only, and I am not reversing that on my own.

Three options, in the order I would take them:

  1. Leave it. Ship the binary layout; the three text consumers decode with
    wasm-tools. Cheapest, and honest — the docs topic now names exactly which
    tools this does not serve.
  2. Add --emit-wit, opt-in, binary still the artifact of record. Costs the
    wit-component dependency and its own system gate.
  3. Make the source tree the default for those three consumers. Largest
    change, and it re-opens DD-036's core choice rather than its mitigation.

I have taken (1) for this PR because it is the one that does not need you.
Say the word and I will do (2).

Traceability

VER-WIT-001 records the gate. REQ-WIT-001 moves to implemented, not
verified: the producer cannot yet plan a wit payload (the spec here is
written by hand, as it is for crates), and clause 5 — how a composed tree is
reached, copy or link — is REQ-WITREACH-001 and DD-036, deferred to v0.44.0.

🤖 Generated with Claude Code

https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu

`varve export-wit --package ns:name@ver --out D` writes that package plus its
transitive closure into `<ns>/<name>/<version>.wasm` — the layout `wkg`'s local
backend reads — from packages already in the verified store, offline. The
closure comes from the packages' own signed bytes, not from a list in
`layer.toml`. `--registry NAME` prints the wkg stanza rather than editing
anyone's configuration.

REQ-SYSTEST-002 clause 5 held the command back until a system gate exercised
it, which is the right order and is why this is a separate commit from #229.

tools/systest/wit-export.sh is that gate. Two separately-encoded binary WIT
packages are deposited as `kind = "wit"` payloads, signed, installed, verified,
and composed. What only a system run shows: the bytes cross deposit, signing,
an OCI layout, install and verification before anything decodes them, and they
come out BYTE-IDENTICAL to the fixtures — the "copy, not a conversion" claim of
DD-036, which is what makes the digest in the layer and the digest on disk the
same number. The command is asked for one package and must write the other
beside it. Two refusals close it: a package the layer does not carry, and a
layer carrying the app but not its dependency, which must write nothing at all.

The gate was negative-controlled: `closure` was mutated to return only the
root, the mutation was confirmed present in the rebuilt binary ("exported 1
package(s)"), and the gate went red on the dependency it did not write.

`systest_sign_spec_and_pin` is extracted from `systest_make_layer` so the new
gate signs its spec through the same code the self-host gate does, rather than
a second copy to keep in step with deposit-layer.yml.

THREE GATE DEFECTS FOUND ON THE WAY, all of the shape this repo keeps finding.

The docs gate kept a second list of markers beside the match that actually
parses each block, so a documented wkg stanza was reported unclassified while
the arm checking it ran. Whether a block reached a parser is now READ from the
match, and cannot drift from it.

The first version of that stanza check was vacuous: it extracted the registry
and root from the block, fed them back to `wkg_stanza`, and compared — which
passes for any block of that shape. A negative control caught it. It now
compares TEMPLATES with both values blanked, so a change to the key path, the
field name or the quoting fails; controlled by renaming `root` to `path` in
`wkg_stanza` and reading the verdict.

And nothing noticed that the `ExportWit` clap variant had been pasted INSIDE
`ExportSdk`'s doc comment, so `export-wit --help` described SDK relocation and
`export-sdk --help` was blank. Every gate stayed green: the docs gate checks a
TOPIC exists, which it did. `every_subcommand_says_what_it_does` closes it —
blank is the signature of a stolen doc comment — controlled by deleting
`export-vsix`'s.

DD-036 CORRECTED. It said the export path emits WIT text. It does not, and
the gap is not cosmetic: of the five consumers #220 measured, `wkg` and
`rules_wasm_component`'s `wkg_wit_deps` read this tree directly, while
`wit-bindgen`, `cargo-component` and the vendored Bazel path want a `wit/`
SOURCE tree. They can decode it with `wasm-tools`, which is in the realm, but
that is a step and not a path. Printing from varve means carrying `WitPrinter`
— `wit-parser` 0.259 has none, `wit-component` does — and so widening the
production trusted base to emit a form varve does not sign, against the
read-only decoding dependency #229 recorded. That is a dependency decision for
the maintainer, raised on the PR with the measurement. The decision text and
the docs topic now say what actually holds, including which tools this does
not serve.

VER-WIT-001 records the gate; REQ-WIT-001 moves to `implemented`. It is not
`verified`: the producer cannot yet PLAN a wit payload (the spec here is written
by hand, as it is for crates), and clause 5 — how a composed tree is REACHED —
is REQ-WITREACH-001 and DD-036, deferred to v0.44.0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019TNtfRjLNhEz82G2ggeeNu
@avrabe
avrabe enabled auto-merge (squash) October 1, 2026 05:46
@avrabe
avrabe merged commit f974e8c into main Oct 1, 2026
31 checks passed
@avrabe
avrabe deleted the feat/export-wit-cmd branch October 1, 2026 06:54
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.

1 participant