Skip to content

chore: add architecture boundary guard to CI - #234

Merged
dirac-run merged 5 commits into
dirac-run:masterfrom
alexdim:chore/arch-guard-script
Sep 30, 2026
Merged

dirac-run merged 5 commits into
dirac-run:masterfrom
alexdim:chore/arch-guard-script

Conversation

@alexdim

@alexdim alexdim commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

PR 0: Architecture Boundary Guard, SCC Cycle Gate, and CI Workflow

Branch: fork/chore/arch-guard-script -> dirac-run/dirac:master
Commits: 5 commits on current master 95edfe36 (head 0bf8c5fd)
Type: chore / CI infrastructure


Summary

Adds automated architecture enforcement that runs in CI on every pull request and on pushes to master: layering violations, new import cycles, scattered tool-taxonomy definitions, numeric || defaults, direct process.env reads in core, and new anys. Existing debt is frozen in baselines; only new instances fail.

Architecture

BEFORE: boundaries enforced only by manual review

AFTER:
  .github/workflows/architecture.yml   (pull_request + push to master)
     npm ci → npm run protos → npm run check:arch
                                   │
                                   ▼
  scripts/check-architecture.sh
     Step 1  depcruise --output-type json ──► scripts/check-arch-graph.mjs
               (a) no module may newly join a cyclic SCC
               (b) no two baseline SCCs may merge
               (c) no new boundary violation (non-circular rules)
     Step 2  syntax checks, each baselined in scripts/architecture-baseline.txt

  Baselines frozen on master 95edfe36:
    cyclic SCC partition ........... 472 modules in 11 SCCs (largest 406, next 47)
    boundary violations ............ 84 known  (0 new allowed)
    check_one_tool_taxonomy ........ 0 known   (0 new allowed)
    check_no_numeric_or_default .... 222 known (0 new allowed)
    check_env_centralized .......... 23 known, now line-level (0 new allowed)
    check_any_ratchet .............. zero-tolerance, diff against the merge base

Why cycles are gated by SCC partition, not by path

The first version of this PR froze dependency-cruiser's no-circular violations, which are keyed by the exact module path of each cycle. With a median cycle length of 16 modules, almost any edit on master reroutes some cycle, so previously known cycles resurfaced as "new". Against later master commits, the old guard reported 24 new no-circular errors, none of them a genuinely new cycle.

The gate now computes strongly-connected components (iterative Tarjan) over the resolved module graph and freezes which modules belong to which cyclic SCC. It fails when:

  • a module joins a cyclic SCC that it was not in (verified: adding import "./index" to src/core/api/ApiConfigurationError.ts fails with NEW cyclic-SCC member(s): + src/core/api/ApiConfigurationError.ts), or
  • two baseline SCCs merge (verified: adding import "../core/api" to src/shared/api.ts fails with an SCC MERGE joining the 47-module and 406-module SCCs).

Known limitation: a new import between two modules that are already in the same SCC changes neither membership nor the partition, so it is not detected. With a 406-module SCC this gap is real. The gate stops cycles from spreading; it does not stop them from getting denser. Closing that gap needs an edge-level ratchet within SCCs, which is out of scope here.

Maintenance: a PR that renames or moves a file inside a cyclic SCC must re-freeze with bash scripts/check-architecture.sh --write-baseline, and the baseline diff shows the move.

Changes

  • .github/workflows/architecture.yml (new): Node 22, fetch-depth: 0 (needed for the any ratchet's merge base), npm ci, npm run protos (generated sources are gitignored), npm run check:arch. Informational until a maintainer makes it a required check.
  • scripts/check-arch-graph.mjs (new): SCC partition gate plus a boundary-violation comparison keyed by rule|from|to. Exits 0 (pass), 1 (new violation), 2 (bad input). --write-baseline writes scripts/architecture-cycle-sccs.txt (deterministic, sorted) and .dependency-cruiser-known-violations.json (boundary rules only).
  • scripts/check-architecture.sh:
    • Step 1 now runs through check-arch-graph.mjs.
    • check_any_ratchet fails loudly with exit 2 when no merge base with origin/master exists, where it used to silently pass. The driver loop no longer swallows that status.
    • check_env_centralized is line-level, so a file already in the baseline can no longer add new process.env reads unnoticed.
    • New --only <check_id> option runs a single syntax check.
  • .dependency-cruiser.js: rules forbidding upward imports from src/services/ and src/integrations/, task↔controller edges outside host seams, and cross-tool imports. src/generated is excluded, because it is gitignored and results used to depend on whether npm run protos had run.
  • package.json: check:arch script and a dependency-cruiser dev dependency.

Test Plan

  • npm run check:arch exits 0 on the rebased branch (graph OK: 472 modules in 11 cyclic SCCs, all boundary violations known; all four syntax checks pass).
  • Baseline premise: this branch changes no files under src/, cli/src/ or webview-ui/src/ relative to master, so the frozen graph is master's graph.
  • Negative, new SCC member: exit 1, names the module (edit above).
  • Negative, SCC merge: exit 1, reports the merge (edit above).
  • Negative, missing merge base: in a shallow single-branch clone with no origin/master, check-architecture.sh --only check_any_ratchet exits 2 with check_any_ratchet requires a merge base with origin/master. In CI, set fetch-depth: 0.
  • --only check_no_numeric_or_default and --only check_env_centralized exit 0.
  • npm run lint passes.

@dirac-run dirac-run 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.

Blocking for architecture enforcement on head 76d20e8: this PR adds check:arch, but neither a CI workflow nor ci:check-all runs it. #238 used the script manually, which is useful but does not stop future boundary/cycle violations from merging. Please wire the architecture check into a required CI check. Also, check_any_ratchet returns success when it cannot find a merge base; fail explicitly or provide a reliable base in CI so the ratchet cannot silently turn off. No tests/builds were independently run in this review.

Alexandros Salapatas added 5 commits September 30, 2026 10:54
- scripts/check-architecture.sh: 10 checks ratcheting known debt (task->controller, vscode-in-core, leaf violations, tool seal, taxonomy split, numeric ||, env scatter, webview escape, new 'as any')
- baseline file: violations fail only when NEW, so guard is green today and tracks debt shrinkage
- wired as npm run check:arch
- add dependency-cruiser@18.2.0 as devDependency with native --ignore-known baseline
- .dependency-cruiser.js: configure rules for task<->controller, vscode in core, leaf services/integrations, tool seal, webview boundary, and circular dependencies
- scripts/check-architecture.sh: hybrid runner combining depcruise for module graph + AST/regex for code smells (|| 0, env scatter, any ratchet)
- zero false-positives from strings/comments, respects tsconfig path mappings
Review findings from the smells pass: the 5MB pretty-printed
dependency-cruiser baseline is now compacted (3MB single line) and
--write-baseline keeps it compact; the tool-taxonomy check also
catches same-line re-exports of the guarded tool-set identifiers,
closing a smuggling path around shared/tools.ts.
Regenerated .dependency-cruiser-known-violations.json via
check-architecture.sh --write-baseline. Adds 4 no-circular entries
that current master introduced: cycles through
UserToolLoader/ToolDiscoveryService/hook-factory/AuthController.
These are pre-existing on master; breaking them is tracked
separately and is out of scope for this branch.
…ailure

Addresses review on dirac-run#234: adds .github/workflows/architecture.yml (npm ci, protos, check:arch on PRs and master), replaces path-keyed cycle baselining with an SCC partition check (new cyclic member or SCC merge fails), makes check_any_ratchet exit 2 without a merge base, and re-freezes baselines on current master (472 modules / 11 SCCs).
@alexdim
alexdim force-pushed the chore/arch-guard-script branch from 76d20e8 to 0bf8c5f Compare September 30, 2026 08:40
@alexdim

alexdim commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've pushed 0bf8c5fd, rebased onto current master 95edfe36.

The guard now runs in CI. New .github/workflows/architecture.yml runs on pull_request and on pushes to master: Node 22, fetch-depth: 0, npm ci, npm run protos, npm run check:arch. It is informational until you choose to make it a required check. Because this PR comes from a fork, its first run may need your approval.

check_any_ratchet fails loudly. With no merge base it now exits 2 and prints ERROR: check_any_ratchet requires a merge base with origin/master. In CI, set fetch-depth: 0., instead of silently passing. The driver loop no longer swallows that status. I verified this in a shallow single-branch clone with no origin/master: exit 2 plus the message.

One further change, found while rebasing. The original cycle baseline was keyed by dependency-cruiser's exact cycle paths, and later master commits alone made it report 24 "new" no-circular errors, none of them a real new cycle. I replaced it with an SCC partition gate (scripts/check-arch-graph.mjs): the build fails if a module newly joins a cyclic SCC or if two baseline SCCs merge. Both negative cases are verified with real edits, which are listed in the description. The description also states the limitation: a new edge between modules already in the same SCC is not detected.

Baselines are re-frozen on 95edfe36: 472 modules in 11 cyclic SCCs and 84 boundary violations, with the syntax-check baselines in scripts/architecture-baseline.txt. npm run check:arch and npm run lint pass.

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