Skip to content

Fix Architecture Violations reporting the inverse of reality#64

Merged
braedonsaunders merged 8 commits into
braedonsaunders:mainfrom
abk1969:layer-violation-direction-fix
Jul 13, 2026
Merged

Fix Architecture Violations reporting the inverse of reality#64
braedonsaunders merged 8 commits into
braedonsaunders:mainfrom
abk1969:layer-violation-direction-fix

Conversation

@abk1969

@abk1969 abk1969 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

CodeFlow's "Architecture Violations" detector (Parser.detectLayerViolations) reported the exact inverse of reality: healthy downward dependencies (a service using a foundational util) were flagged as violations, while genuine upward violations (a util reaching into a service) were silently missed. On a real project this surfaced as a wall of false "utils should not import from services" entries — one per caller of each shared module.

Root cause

The connection graph uses a documented convention (index.html, the Connection format comment): {source: fileDefiningFn, target: fileCallingFn}source is the file that defines the called function (depended-upon), target is the file that calls it (the importer). detectLayerViolations read this backwards, treating source as the importer. Verified against the real analyzer in both directions: a healthy service → util dependency produced a false positive, and a genuine util → service violation produced nothing.

What changed

  • Direction fix (primary): detectLayerViolations now treats target as the importer, matching the documented convention. Healthy downward deps no longer flag; genuine upward violations are correctly reported with accurate from/to attribution.
  • Test-file exclusion (companion): the direction fix, combined with correct test-folder classification (below), would newly flag test files — which legitimately depend on every layer — as violators. Test files are excluded from the importer side using isArchitectureTestFile(path) || importerLayer === 'test'. Both classifiers are needed: isArchitectureTestFile covers *.test/*.spec files outside a tests/ dir; the test layer covers Python test_*.py, conftest.py, and test*-prefixed folders.
  • detectLayer leading-slash tolerance (secondary): every folder pattern required a leading slash, so root-level layer folders (services/, ui/, lib/) never matched and fell through to utils. Normalized by prepending / to the path. No new folder vocabulary added.
  • Coupling label correction (tertiary): the "Highly Coupled" issue was described "Files imported by 8+ others" (fan-in), but the metric counts fan-out (files a file imports). Corrected the description only — no behavioral change.

Each fix is backed by a test in the new tests/layer-violation-direction.test.mjs (VM-harness pattern matching tests/codeflow-golden.test.mjs).

Design doc: docs/superpowers/specs/2026-07-12-layer-violation-direction-design.md
Plan: docs/superpowers/plans/2026-07-12-layer-violation-direction.md

Known limitations (out of scope)

  • No change to how the conns graph is built or to the {source, target} convention — other consumers (graph rendering, circular detection) rely on it; only the misreading consumer was fixed.
  • detectLayer folder vocabulary is unchanged beyond leading-slash tolerance (e.g. next.config.mjs with a dot, or a bare db/ folder, still fall through to utils).
  • Config (level 5) and VBA modules (level 5) importers reaching into a much higher layer remain flagged — niche, plausibly real smells, left as-is rather than expanding the exclusion speculatively.
  • The coupling metric blends function-call edges (fan-out) and markdown-link edges (fan-in); the corrected label describes the dominant function-call case.

Test plan

  • node --test from repo root — 42/42 pass (all pre-existing tests unchanged + 6 new in tests/layer-violation-direction.test.mjs)
  • tests/codeflow-golden.test.mjs and tests/architecture-diagram.test.mjs stay green, unmodified (the repo has no root-level layer folders, so the detectLayer change can't shift its own self-scan)
  • Verified in a clean git worktree (not just the working directory) to rule out local-state false positives, including the direction fix in both directions and the Python/test-folder exclusion

abk1969 and others added 8 commits July 12, 2026 12:10
detectLayerViolations reads the documented {source: definition, target: caller}
connection convention backwards, reporting the exact inverse of reality —
healthy downward deps flagged, genuine upward violations missed. Verified
empirically against the real analyzer in both directions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Task-by-task plan: direction inversion (primary), detectLayer leading-slash
tolerance (secondary), coupling label correction (tertiary), regression pass.
Every code change pre-verified against the real analyzer via card/lib/analyzer.js.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tasks 1+2 interact to introduce a new "test should not import from utils"
false-positive class (dir-based test files classify as layer 'test'=6 and,
with the direction corrected, get flagged for importing anything more
foundational). Excluded via the existing isArchitectureTestFile classifier.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… violations

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… (Python, test-folders)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

@abk1969 is attempting to deploy a commit to the braedonsaunders' projects Team on Vercel.

A member of the Team first needs to authorize it.

@braedonsaunders braedonsaunders left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed the graph convention and the implementation, including the root-level layer normalization and test-importer guard. The full branch suite passes locally (42/42). The only failing status is Vercel contributor authorization, not a code/test failure. Approved for merge.

@braedonsaunders
braedonsaunders merged commit 74063c9 into braedonsaunders:main Jul 13, 2026
1 check failed
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