Skip to content

fix: validate top module first - #12

Merged
bananaplain merged 4 commits into
mainfrom
fix/validate-top-module-first
Oct 13, 2026
Merged

bananaplain merged 4 commits into
mainfrom
fix/validate-top-module-first

Conversation

@bananaplain

@bananaplain bananaplain commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

When more than one module of a requires chain had an error, plain-parser check and codeplain --dry-run reported different first errors. Given top requiring middle, middle requiring base, and an undefined concept in both middle and base, plain-parser reported base's and codeplain middle's.

plain-parser validated each required module as the requires walk reached it, deepest first, and checked the top module's structure after the walk. On the other hand, codeplain checks the top module's structure before the walk and runs its remaining checks after it. It then validates each required module in a fresh parse, top-down, in listed order.

Change

  • validate_and_marshall_module is replaced by two functions, with no behaviour change:
    • validate_module_structure: required concepts defined, functional specs present and non-empty, implementation reqs present.
    • validate_and_build_module_tree: exported definitions merged, acceptance tests, linked resources, code variables, concept validation, marshalled tree.
  • The top module's structure is checked before the walk.
  • The walk parses and records each required module as a RequiredModule: parse result, the exports each receives, its own exports, code variables. Circular, fixed-order and parse errors are raised during the walk, as before.
  • After the top module, recorded modules are validated top-down in listed order, each once. Accept/reject, marshalled trees, and the deepest-first chain from parse_module_chain are unchanged. Each file is still read once.
  • New tests in tests/test_requires.py pin each ordering rule with two broken modules, an accepted chain listing one module twice (requires: [base, base]), a required module without functional specs, a top-module concept error reported before a required module's missing functional specs, and that each module's tree is built once, top module first.
  • Compared with codeplain origin/main on 10,000 random requires graphs: no differences in verdict, first error or tree. Before this change, 329 first errors differed.

Release

  • Ships as 0.1.4.
  • One fixture reports a different error than 0.1.3: requires/circular_requires_sub has missing implementation reqs and a circular require, and now reports the missing implementation reqs first, as codeplain does.
  • plain-forge users need uv tool upgrade plain-parser; plain-forge update does not upgrade it.

…ding

No behaviour changes. The structure checks (required concepts, functional
specs, implementation reqs) and the tree building (exports, acceptance
tests, linked resources, concepts) become separate functions so a caller
can run them at different points.
@bananaplain
bananaplain requested a review from hisenb3rg October 12, 2026 13:50
Check the top module's structure before the requires walk, record
required modules during the walk, then validate them top-down after the
top module. This is the order codeplain reports errors in, so a broken
chain now gives the same first error from `plain-parser check` and from
codeplain's `--dry-run`. Each module is still read once.
@bananaplain
bananaplain force-pushed the fix/validate-top-module-first branch from 8feefa4 to f23dd77 Compare October 12, 2026 14:45
@bananaplain
bananaplain force-pushed the fix/validate-top-module-first branch from f23dd77 to 4855684 Compare October 12, 2026 14:57
@bananaplain
bananaplain requested a review from zanjonke October 12, 2026 15:01

@hisenb3rg hisenb3rg left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@bananaplain
bananaplain merged commit 2cf5298 into main Oct 13, 2026
1 check passed
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.

2 participants