fix(architecture): zod 하위 경로 import도 src/contracts/zod.ts를 거치게 한다

문제
zod-is-reached-through-contracts-zod 규칙의 to.path가 ^zod$다. src 파일이
"zod/v4"를 import하면 check:architecture가 rc=0으로 통과한다(실험 Z1). 그
모듈은 src/contracts/zod.ts의 jitless 설정보다 먼저 스키마를 만들 수 있고,
그러면 운영 CSP가 zod의 Function 탐침을 부팅마다 보고한다(F-7).

고른 방법
to.path를 ^zod(/|$)로 넓힌다. 그래프 fixture에 "zod/v4"를 import하는 파일과
그것이 거절되는지 보는 회귀 검사를 더했다. layers.md 규칙 표도 고쳤다.

버린 대안
- eslint no-restricted-imports에 zod 패턴 추가: 같은 규칙을 두 도구에
  둔다. 경계 규칙은 dependency-cruiser가 정본이다.

위험·한계
- src 안에 zod 하위 경로 import는 지금 없다(grep). 다운스트림이 쓰고
  있으면 check:architecture가 실패한다. src/contracts/zod.ts의 z로 바꾼다.

검증
- 수정 뒤: 참조 기능 스키마 파일 import를 "zod/v4"로 바꾸면
  "Architecture violation [zod-is-reached-through-contracts-zod]: ... ->
  zod/v4"로 실패, "zod"도 실패.
- 규칙을 ^zod$로 되돌리면 새 회귀 검사 "zod subpath import outside
  src/contracts/zod.ts is rejected"가 실패한다.
- check:architecture(29 regression checks PASS), check:types, eslint,
  verify:documentation 통과.

Refs: docs/reviews/2026-11-03-maturity-review/07-contracts.md P-07-06
This commit is contained in:
DongHyeonka
2026-11-04 20:38:14 +09:00
parent 84d6e526a3
commit 64f19ac665
4 changed files with 17 additions and 3 deletions
+2 -2
View File
@@ -58,14 +58,14 @@
},
{
"name": "zod-is-reached-through-contracts-zod",
"comment": "F-7 (13-08). src/contracts/zod.ts sets zod jitless before any schema is built, so the production CSP never sees zod's Function probe. Schema code imports z from there.",
"comment": "F-7 (13-08). src/contracts/zod.ts sets zod jitless before any schema is built, so the production CSP never sees zod's Function probe. Schema code imports z from there. A subpath (zod/v4, zod/mini) is the same zod and counts too (0929/P-07-06).",
"severity": "error",
"from": {
"path": "^src",
"pathNot": "^src/contracts/zod\\.ts$"
},
"to": {
"path": "^zod$"
"path": "^zod(/|$)"
}
},
{
+1 -1
View File
@@ -42,7 +42,7 @@ Each row is one `forbidden` rule in `.dependency-cruiser.json`, by its `name`.
| `presentation-does-not-know-adapters` | `src/presentation`, except `adapters/query` | adapters, bootstrap, TanStack |
| `page-templates-own-layout-only` | `src/presentation/templates` | application, adapters, bootstrap, the presentation query adapter, TanStack. Templates take data and actions as props |
| `icon-vendor-is-facade-only` | all of `src`, except the lucide vendor facade | `lucide-react` |
| `zod-is-reached-through-contracts-zod` | all of `src`, except `src/contracts/zod.ts` | `zod` |
| `zod-is-reached-through-contracts-zod` | all of `src`, except `src/contracts/zod.ts` | `zod` and its subpaths (`zod/v4`) |
| `design-system-is-reached-through-its-index` | code outside the design system and its named facades | design-system files other than its `index.ts` |
| `adapters-do-not-know-presentation` | `src/adapters` | presentation, bootstrap |
| `feature-domain-is-framework-neutral` | `src/features/<id>/domain` | application, presentation, adapters, bootstrap, any feature's application, adapters and presentation, React, TanStack |
+9
View File
@@ -931,6 +931,15 @@ async function runGraphFixtureChecks(): Promise<GraphFixtureResult> {
target === "zod",
),
},
{
name: "zod subpath import outside src/contracts/zod.ts is rejected",
passed: blockingViolations(importBoundaryGraph).some(
({ rule, source, target }) =>
rule === "zod-is-reached-through-contracts-zod" &&
source === "src/presentation/pages/subpath-zod.ts" &&
target === "zod/v4",
),
},
{
name: "zod through src/contracts/zod.ts is accepted",
passed: !blockingViolations(importBoundaryGraph).some(({ source }) =>
@@ -0,0 +1,5 @@
// 0929/P-07-06: a zod subpath is the same zod, so it is reached through
// src/contracts/zod.ts too.
import { z } from "zod/v4";
export const subpathSchema = z.string();