Skip to content

test(architecture): ratchet top-level layer direction and mutual imports - #10584

Merged
morluto merged 2 commits into
mainfrom
test/top-level-layer-cycles
Nov 15, 2026
Merged

morluto merged 2 commits into
mainfrom
test/top-level-layer-cycles

Conversation

@morluto

@morluto morluto commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Summary

Plan step 2.6 (structural audit W9, report 08 §3). verify:module-boundaries checked pure layers, application ↛ composition and an allowlist of migrated provider roots, but not layer direction in general or cycles. A new directory was unconstrained by default. This extends the existing verifier (no parallel tool) with a declared layer for every top-level src/ unit and a counted, ratcheting baseline.

Problem and expected behavior

Dependencies should flow inward (AGENTS.md; docs/architecture/architecture.mermaid). On main, provider directories import application, process imports artifacts, and 23 unit pairs import each other. Nothing stops these from growing. Expected: the counts cannot go up, and an undeclared directory fails.

Change and scope

  • scripts/lib/module-layers.mjs: UNIT_LAYERS assigns every top-level directory and root src/*.ts file to one of domain, contracts, foundation (process, filesystem, windows, config, compression, identity, logger, package metadata), providers, application, composition, adapters (cli, server, main, root CLI/MCP/catalog files). An import may point to the same or a lower layer.
  • scripts/lib/module-boundaries.mjs: import resolution is split into resolveModuleImports so the per-file checks and the graph share one resolver (package-map and file: handling included). inspectModuleBoundaries behaves as before.
  • scripts/verify-module-boundaries.mjs: on a full run (not a file selection), it builds the production import graph between units (tests, specs, fixtures excluded; type imports included) and compares it with scripts/lib/module-layers.baseline.json:
    • Upward imports per unit pair (45 pairs, 248 imports): most are provider → application (ports such as AnalysisProvider), plus process → artifacts 20, domain → contracts 4, composition → cliCommandNames.ts 3, application → mcpStartupPolicy.ts 3, windows → artifacts 2, config → native/application.
    • Mutual imports (23 pairs): application ↔ artifacts/browser/config/desktop/dotnet/frida/providers, artifacts ↔ dotnet/firmware/gpu/javascript/native/process, contracts ↔ domain, config ↔ filesystem, main ↔ server, process ↔ windows, catalogIdentity.ts ↔ recordedCatalogDigests.ts, and five cli ↔ root cli*.ts pairs.
    • A new upward pair, more imports on a recorded pair, a new mutual pair, or an undeclared unit fails. Shrinkage prints a "baseline can be lowered" notice and does not fail, so unrelated PRs that remove an import are not blocked. --print-layer-baseline prints the current facts.
  • Cycles are measured as mutual pairs. A longer cycle always contains an upward import, which the per-pair count already ratchets. The report's 12 cycles are all among the 23 pairs. The extra pairs come from root cli*.ts files and from artifacts ↔ provider directories that the report did not list.
  • Not included: moving ports to src/ports/, or moving root CLI files into src/cli/ (W9 moves).

Contribution scope: not applicable (verification only).

Contract and boundary impact

  • Semantic owner and earliest changed stage: scripts/lib/module-layers.mjs owns the layer table; module-boundaries.mjs owns import resolution.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: none.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests added: tests/evaluation/moduleLayers.test.ts: every top-level unit is declared; unit mapping (root files, .js specifiers, tests ignored); upward counting and mutual pairs; undeclared unit refused; growth fails and shrinkage is reported.
  • Full verifier run on this branch: 4,304 files, passes against the recorded baseline.
  • Remaining proof gaps: the layer assignment of a few root files (catalogIdentity.ts, serverIdentity.ts, mcpStartupPolicy.ts as adapters; identity.ts, logger.ts as foundation) follows report 08 and is open to maintainer adjustment.

Validation performed

  • npm run test:local -- tests/evaluation/moduleLayers.test.ts tests/evaluation/moduleBoundaries.test.ts — 148 passed
  • node scripts/verify-module-boundaries.mjs — "Checked resolved module boundaries in 4304 source files."
  • npm run check:fast — passed (its lint step runs the verifier)

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A contributor adding a top-level directory must add it to UNIT_LAYERS.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Declare a layer for every top-level src/ directory and root source file
(domain, contracts, foundation, providers, application, composition,
adapters) in scripts/lib/module-layers.mjs. verify:module-boundaries now also
builds the production import graph between those units and compares it with
a counted baseline: 45 unit pairs import a higher layer (248 imports) and 23
unit pairs import each other. A new upward pair, more imports on a recorded
pair, a new mutual import, or an undeclared unit fails; shrinkage is
reported so the baseline can be lowered.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T19:03:07.219517Z 3c25acb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The update appears safe to merge; the previous finding is fixed and no new actionable issues were found.

Summary

The PR adds declared source layers and a baseline that prevents upward imports and mutual imports from growing.

  • The full source check now tracks layer direction and mutual imports.

Reviews (3) · Last reviewed commit: "fix(architecture): enforce layers for is..." · Reviewed by Greptile

Comment thread scripts/lib/module-layers.mjs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e617c2c40

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/verify-module-boundaries.mjs Resolved
@morluto
morluto merged commit 8c052bd into main Nov 15, 2026
54 checks passed
@morluto
morluto deleted the test/top-level-layer-cycles branch November 15, 2026 00:37
morluto added a commit that referenced this pull request Nov 15, 2026
…rts (#10584)

* test(architecture): ratchet top-level layer direction and mutual imports

Declare a layer for every top-level src/ directory and root source file
(domain, contracts, foundation, providers, application, composition,
adapters) in scripts/lib/module-layers.mjs. verify:module-boundaries now also
builds the production import graph between those units and compares it with
a counted baseline: 45 unit pairs import a higher layer (248 imports) and 23
unit pairs import each other. A new upward pair, more imports on a recorded
pair, a new mutual import, or an undeclared unit fails; shrinkage is
reported so the baseline can be lowered.

* fix(architecture): enforce layers for isolated units
@morluto morluto added the area: tests Test suite and verification label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Test suite and verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant