Skip to content

Refactor and document guard resolution system #15

@UniquePixels

Description

@UniquePixels

Context

Audit IDs: ARCH-2, SIMP-1, SIMP-2, SIMP-4

The guard system in `guards/index.ts` has several related improvements that should be done together since they all touch the same file:

ARCH-2: Document guard resolution algorithm

The `collectDeps()` / `resolveDeps()` / `resolveGuards()` pipeline is 168 lines of graph traversal with cycle detection. Add high-level JSDoc explaining the algorithm (depth-first traversal, deduplication, topological ordering). Analyze whether the algorithm can be simplified.

SIMP-1: Simplify resolveDeps dual-Set pattern

`resolveDeps` maintains two separate Sets (`seen` and `resolvedSet`) plus an array (`resolved`). A single `added` Set and the `resolved` array should be sufficient.

SIMP-2: Simplify createGuard metadata copy

Four separate `if` branches manually copy each optional field from `meta`. A filtered spread with `Object.freeze` would be more concise and maintainable.

SIMP-4: Remove or internalize runGuard

`runGuard` is exported but never imported by production code. It's a trivial passthrough (`return guard(input)`). Remove from public API or mark as internal.

Files

  • `src/core/guards/index.ts` (all changes)
  • `src/core/guards/index.test.ts` (test updates)

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode refactoring and simplification

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions