Skip to content

Let console-codegen take several spec files - #155

Draft
shellygr wants to merge 1 commit into
shelly/natspec-conf-pathfrom
shelly/codegen-multi-spec
Draft

Let console-codegen take several spec files#155
shellygr wants to merge 1 commit into
shelly/natspec-conf-pathfrom
shelly/codegen-multi-spec

Conversation

@shellygr

Copy link
Copy Markdown
Contributor

Stacked on #148 (shelly/natspec-conf-path) — retarget to master once that merges.

Why

InputData.specs is already a list and the workflow is plumbed for N specs, but the CLI mapped its triad to a one-element list, so nothing could hand it more than one. upload_input said as much: "The legacy CLI triad is single-spec; map it to a one-element specs list… The pipeline is plumbed for N specs."

There is a producer now. Natspec emits one spec per component — four for a modest contract — and each carries its own copy of the shared ERC20 ghost model. The two workarounds are both bad:

  • Merge by hand. On a real four-spec set the collisions were 3 ghosts (balanceByToken, allowanceByToken, sumWithdrawn), 8 definitions/functions (N, MIN_RECIPIENTS, balanceOfCVL, transferCVL, transferFromCVL, approveCVL, allowanceCVL, recordOutbound) and four separate methods blocks.
  • Run codegen per spec. Four unrelated implementations, each satisfying one component's rules and ignoring the others.

Change

spec_file becomes nargs="+":

console-codegen views.spec withdrawal.spec registry.spec IFoo.sol design.md

The three-argument form parses exactly as before, so existing invocations and scripts are unaffected.

vfs_path keys the specs downstream (audit's resume artifact indexes by it), so the naming is deliberate:

Invocation vfs_paths
one spec rules.spec — unchanged, so artifacts recorded by single-spec runs stay valid
several specs their file names (views.spec, withdrawal.spec, …)
several specs, colliding names refused, naming the offender

The collision case matters because distinct directories can hold same-named specs (core/vault.spec, periphery/vault.spec), and sharing a key would silently drop one. Refusing beats inventing a suffix the caller never asked for.

Tests

tests/test_codegen_multi_spec_input.py — 5 cases covering the parser (one spec, several specs) and the mapping (conventional name, file names, collision refused). pytest on this file plus #148's three → 11 passed.

The workflow is already plumbed for N specs (`InputData.specs`), but the CLI
mapped its triad to a one-element list, so there was no way to hand it more than
one -- as `upload_input`'s comment noted, no producer needed it at the time.

There is one now. Natspec emits one spec per component, four for a modest
contract, and each carries its own copy of the shared ERC20 ghost model. Merging
them by hand means reconciling duplicate ghosts, definitions and `methods`
blocks; running codegen once per spec instead yields four unrelated
implementations, each satisfying one component and ignoring the rest.

`spec_file` becomes `nargs="+"`. The three-argument form parses exactly as
before, so existing invocations are unaffected.

`vfs_path` keys the specs downstream (audit's resume artifact indexes by it), so
several specs are named after their files while a single spec keeps the
conventional `rules.spec` -- recorded artifacts from single-spec runs stay
valid. Two specs whose file names collide are refused by name rather than
silently sharing a key, which would drop one of them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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