문제
tests/fixtures/architecture/forbidden/**에는 fixture 전용 ESLint 블록이
붙어 있었다. 모든 계층의 금지 import와 fetch·localStorage·sessionStorage
금지를 합친 것이다. check-architecture.ts는 fixture마다 ESLint 종료 코드가
0이 아니면 거부됐다고 셌다. 그래서 운영 src/presentation/** 블록에서 계층
import 금지와 fetch 금지를 지워도(변이 M2) check:architecture는 "9 forbidden
rejected"로 통과했다. 전역 fetch·localStorage 금지는 이 ESLint 블록 말고 지키는
검사가 없다.
고른 방법
- 새 scripts/lib/architecture-lint-fixtures.ts가 fixture마다 그것이 대표하는
운영 경로(lintAs, 예: src/presentation/__architecture_fixture__/…)와 거부해야
하는 규칙(rejectedBy)을 적는다. ESLint API lintText(code, { filePath })로
그 경로의 운영 설정을 그대로 적용한다. 금지 fixture는 그 규칙이 보고해야
통과하고, 허용 fixture는 계층 규칙(no-restricted-imports·globals)이 아무것도
보고하지 않아야 통과한다. 목록에 없는 fixture 파일도 실패로 센다.
- domain fixture는 domain 코드가 실제로 사는 src/features/*/domain 블록으로
검사한다(최상위 src/domain 폴더는 없다).
- fixture 전용 ESLint 블록을 지운다. check-architecture.ts에서 쓰이지 않게 된
pnpm 하위 프로세스 실행과 npm_execpath 요구를 지운다.
- 버린 대안: 금지 fixture 삭제. import 방향은 그래프가 지키지만 전역 금지의
검출이 0이 된다. 종료 코드만 보고 운영 경로로 옮기기. 다른 규칙(화면 문구
등)이 걸려도 거부로 센다.
위험·한계
- 계층 규칙 이름이 바뀌면 fixture 표의 rejectedBy도 같이 고쳐야 한다(고치지
않으면 실패로 드러난다).
- 출력 문구가 "3 allowed PASS, 9 forbidden rejected by the production rule for
their layer"로 바뀐다. 이 문구를 읽는 스크립트는 없다.
검증
- RED: 수정 전 변이 M2(운영 presentation 블록의 계층 import 금지와 fetch 금지
삭제)에서 check:architecture exit 0, "9 forbidden rejected".
- 수정 뒤 같은 변이에서 check:architecture exit 1, presentation fixture 5개가
"was accepted"로 실패. 되돌린 뒤 exit 0.
- 새 tests/unit/architecture-lint-fixtures.test.ts 3건(운영 설정 통과,
overrideConfig로 규칙을 끄면 실패, 목록 밖 fixture 실패) 통과.
architecture-report 3건 통과. check:types 통과, eslint 통과.
Refs: docs/reviews/2026-11-03-maturity-review/12-guardrails-ci.md 12-04
68 lines
2.7 KiB
TypeScript
68 lines
2.7 KiB
TypeScript
import { cp, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { ESLint } from "eslint";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
ARCHITECTURE_LINT_FIXTURE_ROOT,
|
|
checkArchitectureLintFixtures,
|
|
} from "../../scripts/lib/architecture-lint-fixtures.ts";
|
|
|
|
const roots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
// 1103/12-04. The fixtures used to be linted under an ESLint entry of their
|
|
// own, so deleting a production layer rule still left them "rejected".
|
|
describe("architecture lint fixtures", () => {
|
|
it("are rejected by the production rules for their layer, and only the forbidden ones", async () => {
|
|
const result = await checkArchitectureLintFixtures({
|
|
root: process.cwd(),
|
|
linter: new ESLint({ cwd: process.cwd() }),
|
|
});
|
|
expect(result).toEqual({ allowed: 3, forbidden: 9, failures: [] });
|
|
}, 30_000);
|
|
|
|
it("fail when the production presentation rules lose their layer bans", async () => {
|
|
const result = await checkArchitectureLintFixtures({
|
|
root: process.cwd(),
|
|
linter: new ESLint({
|
|
cwd: process.cwd(),
|
|
overrideConfig: [{
|
|
files: ["src/presentation/**/*.{ts,tsx}"],
|
|
rules: { "no-restricted-globals": "off", "no-restricted-imports": "off" },
|
|
}],
|
|
}),
|
|
});
|
|
expect(result.failures).toEqual(expect.arrayContaining([
|
|
expect.stringContaining("forbidden/presentation-direct-fetch.tsx (as src/presentation/"),
|
|
expect.stringContaining("forbidden/presentation-imports-adapter.ts (as src/presentation/"),
|
|
expect.stringContaining("forbidden/template-imports-application.tsx (as src/presentation/templates/"),
|
|
]));
|
|
expect(result.failures.join("\n")).not.toMatch(/application-imports|domain-imports/u);
|
|
}, 30_000);
|
|
|
|
it("fail for a fixture nobody says what must reject", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "architecture-lint-fixtures-"));
|
|
roots.push(root);
|
|
await cp(ARCHITECTURE_LINT_FIXTURE_ROOT, path.join(root, ARCHITECTURE_LINT_FIXTURE_ROOT), {
|
|
recursive: true,
|
|
});
|
|
await writeFile(
|
|
path.join(root, ARCHITECTURE_LINT_FIXTURE_ROOT, "forbidden/unlisted.ts"),
|
|
"export const unlisted = true;\n",
|
|
);
|
|
const result = await checkArchitectureLintFixtures({
|
|
root,
|
|
linter: { lintText: async () => [{ messages: [{ ruleId: "no-restricted-imports", message: "x" }] }] },
|
|
});
|
|
expect(result.failures).toContain(
|
|
"forbidden/unlisted.ts: not listed in ARCHITECTURE_LINT_FIXTURES, so nothing says what must reject it",
|
|
);
|
|
});
|
|
});
|