Repository navigation
Closed
Description
validateSpace (originally written for the CLI) and validateFile (originally written for the API) run the same pipeline over the whole space, then shape the output differently. Written as two parallel implementations, they duplicate logic and can drift apart.
Current state (as of #151)
Both functions read the space, check each node's type and schema, find duplicate titles, run validateGraph, build gating seeds and call evaluateSpaceRules.
validateSpace |
validateFile |
|
|---|---|---|
| Resolution | Takes a resolved SpaceContext |
Resolves the file to a space and label (resolveFileSpace), then builds its own context |
| Scope options | depth, readResult |
judgeTarget (judge only the file and the ancestor rules that can gate it) |
| Output | ValidationResult: every finding, grouped by kind |
FileValidationResult: one file, issues keyed and formatted, plus a gated: entry |
Duplication:
- The type check and schema validation are written twice.
- The gating seeds are derived differently:
validateFileruns the schema validator again on every node, whilevalidateSpacereuses itsnodeErrors. - "A file's result matches its entry in a full run" holds only because two pieces of code agree. The structure doesn't guarantee it.
- The CLI resolves a file's space twice: once to choose the space's judge, and again inside
validateFile.
Proposed shape
- Resolution at the edge. A file path becomes a space and label; a space name becomes a
SpaceContext; CLI flags become a judge. This mostly exists already:resolveFileSpace,createSpaceContext,judgeForRun. - One core. A single function checks a context's nodes and returns every finding by file. It takes
includeGated,ruleFilter,judgeand an optional judge target. - Two thin views.
validateSpace: read the space, applydepth, run the core.validateFile: run the core with the file as judge target, then project the result onto one file. The projection is a pure function.
validateFile(filePath, config, options) keeps its public signature: resolving a path is a reasonable convenience for editor integrations. There should be no behaviour change.
Related
- One rule engine: spaces without a hierarchy currently go through
validate-rules.ts, and spaces with one go throughgating.ts. Each has its own semantic loop, and they behave differently. For example, in a space without a hierarchy, a node that fails an expression rule silently skips its own semantic rules, while in a hierarchy that node's own semantic rules still run. This refactor is a natural place to settle that rule once.
Metadata
Metadata
Assignees
Labels
No labels
Activity