Skip to content

Refactor validateSpace and validateFile into one core with two views #154

Closed

Description

@mindsocket

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: validateFile runs the schema validator again on every node, while validateSpace reuses its nodeErrors.
  • "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

  1. 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.
  2. One core. A single function checks a context's nodes and returns every finding by file. It takes includeGated, ruleFilter, judge and an optional judge target.
  3. Two thin views.
    • validateSpace: read the space, apply depth, 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 through gating.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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions