Files
clean-architecture-frontend…/tests/unit/test-evidence-repository-configs.test.ts
DongHyeonka 439d327120 fix(checkers): 시험 증거 검사가 checkout에 없는 Playwright 설정을 이름으로 댄다
문제: 시험 증거 전체 검사(`scripts/check-test-evidence.ts`, FE-GATE-008)는
등록부(`config/repository-layout.json`)의 `playwright-configs` 집합,
또는 `--playwright-config`로 받은 설정을 읽어 `forbidOnly: true`를 본다.
그 파일이 checkout에 없으면 `readFile`의 ENOENT로 죽는다. 보고서도
쓰기 전이라 게이트 로그에는 스택만 남는다. 파생 프로젝트가 capability를
지우며 `playwright.capabilities.config.ts`를 지우고 등록부 항목을 남기면
이렇게 된다(#55 이전부터, #66이 fixture 실행만 고침).

고른 방법: (가)+(다).
- (가) 설정을 못 읽으면 ENOENT일 때만 실패 줄을 하나 더하고 다음
  설정으로 간다. 등록부에서 온 설정은 「등록부가 playwright-configs에
  적었지만 이 checkout에 그 파일이 없다, 되살리거나 항목을 지운다」,
  인자로 온 설정은 「--playwright-config가 적었지만 없다」. 릴리스 증거
  토큰을 읽는 `playwright.config.ts`가 없으면 토큰 검사를 건너뛰고, 등록부
  줄이 없을 때(설정을 인자로 받은 경우)만 따로 이름으로 댄다. 검사는 그대로
  실패하고(조용한 통과 없음) 보고서에 그 줄이 남는다. ENOENT가 아닌
  오류(설정 자리에 폴더가 있는 EISDIR 등)는 지금처럼 던진다. 이 검사가
  설명할 수 있는 오류가 아니라서다. 같은 파일의 source contract·visual 증거도
  없는 파일을 이름으로 대는 실패 줄로 낸다.
- (다) `docs/manual/03-outside-feature-folder.md`의 루트 항목 순서에
  「지울 때는 등록부 항목과 secret-scan `trackedRoots`도 지운다」를 더한다.
버린 것:
- (나) 그 항목을 `optional`로 두기: 등록부가 이 설정을 「없어도 되는
  것」으로 바꾸어 템플릿에서 설정이 사라져도 forbidOnly 검사가 조용히
  넘어간다. `fixture-copy`·`secret-scan` 집합에도 같이 걸린다.

위험·한계: 실패 문구만 바뀐다(종료 코드·게이트 판정 그대로). 같은
원인의 다른 자리: 제거 드릴의 사본 만들기(`scripts/lib/removal-fixture.ts`
`prepareRemovalFixture`)는 등록부 `fixture-copy` 경로를 `cp`로 복사해,
없는 항목에서 원문 ENOENT로 죽는다(`optional`인 `recipes`도 같다). 이
변경은 그것을 고치지 않는다(범위 밖, PR 본문에 적음). 문서대로 항목을
지우면 둘 다 일어나지 않는다.

검증(desktop `scripts/verify.sh`, 깨끗한 worktree):
- RED: 기준 972139e6 + 새 시험, `node scripts/run-vitest.ts run
  tests/unit/test-evidence-repository-configs.test.ts` → 새 시험 둘이
  stderr의 `ENOENT: … open 'playwright.capabilities.config.ts'`(등록부
  설정)·`… 'absent.config.ts'`(인자 설정) 스택으로 실패, 기존 시험 통과.
- 리뷰 반영(등록부 설정 넷을 하나씩 빼는 경우, 인자 설정과 e2e 설정이
  둘 다 없는 경우): 반영 전 트리에서 `playwright.config.ts` 경우와
  인자+e2e 경우만 실패.
- ENOENT 밖 오류 두 경우(설정 자리가 폴더): 설정 검사의 throw를 지운
  변이에서 「config check」 경우만, 토큰 읽기의 throw를 지운 변이에서
  「token read」 경우만 실패.
- GREEN: 같은 파일 + `tests/unit/test-evidence-source-rules.test.ts`
  3회 연속 14 통과(작은 checkout 시험 168~233ms, load 24).
  `lint`·`check:types` rc=0. merge 단계와 main 단계 게이트는 PR 본문에
  적는다.

Refs: fe-ci-next (3)
2026-11-20 02:27:56 +09:00

141 lines
7.2 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { copyFile, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { REPOSITORY_LAYOUT_FILE, selectRepositoryPaths } from "../../scripts/lib/repository-layout.ts";
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
const ARTIFACT = "artifacts/quality/test-evidence-repository-configs.json";
const CHECKER = path.resolve("scripts/check-test-evidence.ts");
/**
* Longest desktop run of a test in this file: the first one, in FE-GATE-005's
* test:unit at load 14 (2026-11-20); its test:coverage run there was shorter.
* The ones that run in a small checkout took 131 to 233 ms alone.
*/
const CHECK_MS = 746;
type Report = { facts: { playwrightConfigs?: string[] }; failures: string[] };
/**
* The full check (no --source-root) in a checkout that has only what the
* test copied into it and a policy with no scenario catalog or source
* contract, so every other failure it reports names a missing file without
* reading one.
*/
async function fullCheckIn(root: string, ...options: string[]) {
const policy = path.join(root, "test-evidence-policy.json");
await writeFile(policy, JSON.stringify({ schemaVersion: 2, scenarioCatalogs: [], sourceContracts: [] }));
const artifact = path.join(root, "report.json");
const result = spawnSync(
process.execPath,
[CHECKER, "--source-only", "--policy", policy, "--artifact", artifact, ...options],
{ cwd: root, encoding: "utf8" },
);
return { result, report: async () => JSON.parse(await readFile(artifact, "utf8")) as Report };
}
// The full check reads every Playwright config of the registry for forbidOnly;
// a fixture run reads only the configs it is given
// (tests/unit/test-evidence-source-rules.test.ts). Every config has forbidOnly,
// so nothing else fails if the full check reads none. The browser file/storage
// removal drill deletes this test with playwright.capabilities.config.ts.
describe("test evidence full check", () => {
it("reads every Playwright config of the registry", async () => {
await rm(ARTIFACT, { force: true });
const result = spawnSync(
process.execPath,
["scripts/check-test-evidence.ts", "--source-only", "--artifact", ARTIFACT],
{ encoding: "utf8" },
);
expect(result.status, result.stderr).toBe(0);
const report = JSON.parse(await readFile(ARTIFACT, "utf8")) as Report;
expect(report.facts.playwrightConfigs).toEqual([...selectRepositoryPaths("playwright-configs")]);
expect(report.facts.playwrightConfigs?.length).toBeGreaterThan(0);
}, childProcessTimeout(CHECK_MS));
// fe-ci-next (3). A product that deletes a Playwright config and keeps its
// registry entry (playwright.capabilities.config.ts with its capability)
// ended the full check on ENOENT, before it wrote its report, so FE-GATE-008
// showed a stack trace instead of what to fix. Now it fails by name: the
// config, the registry, and the two ways out. Each run is in a checkout that
// has every other registered config and nothing more, so the check reports
// what that checkout lacks instead of reading this repository.
const configs = [...selectRepositoryPaths("playwright-configs")];
it.each(configs)("names %s when the checkout lacks it, with the registry entry to remove", async (lacking) => {
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-registry-"));
try {
for (const config of configs.filter((config) => config !== lacking)) {
await mkdir(path.dirname(path.join(root, config)), { recursive: true });
await copyFile(config, path.join(root, config));
}
const { result, report: read } = await fullCheckIn(root);
expect(result.status).toBe(1);
expect(result.stderr).not.toMatch(/ENOENT|\n {4}at /u);
const report = await read();
expect(report.facts.playwrightConfigs).toEqual(configs);
const named = `${lacking}: ${REPOSITORY_LAYOUT_FILE} lists it in playwright-configs, but this checkout has no such file; restore it or remove its entry`;
expect(report.failures.filter((failure) => configs.some((config) => failure.startsWith(`${config}:`)))).toEqual([
named,
]);
expect(result.stderr).toContain(named);
} finally {
await rm(root, { recursive: true, force: true });
}
}, childProcessTimeout(CHECK_MS));
// With configs given, the registry's are not read, so the e2e config the
// full check reads for its release evidence tokens is named on its own.
it("names a config the run gives and the e2e config when the checkout lacks them", async () => {
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-registry-"));
try {
const { result, report: read } = await fullCheckIn(root, "--playwright-config", "absent.config.ts");
expect(result.status).toBe(1);
expect(result.stderr).not.toMatch(/ENOENT|\n {4}at /u);
const report = await read();
expect(report.facts.playwrightConfigs).toEqual(["absent.config.ts"]);
expect(
report.failures.filter((failure) => /^(?:absent|playwright)\.config\.ts:/u.test(failure)),
).toEqual([
"absent.config.ts: --playwright-config names it, but this checkout has no such file",
"playwright.config.ts: the full check reads its release evidence tokens, but this checkout has no such file",
]);
} finally {
await rm(root, { recursive: true, force: true });
}
}, childProcessTimeout(CHECK_MS));
// Only a missing file becomes a named failure. Another read error (a folder
// where the config should be, no permission) is not one this check can
// explain, so the check still ends on it, in each place it reads a config.
// The folder stands where only that place reads: a registered config other
// than the e2e one (the token read after the config check then succeeds), or
// the e2e config in a run that gives a readable config instead.
const readErrorRuns: [string, string, string[]][] = [
["the config check", configs.find((config) => config !== "playwright.config.ts") ?? "", []],
["the release evidence token read", "playwright.config.ts", ["--playwright-config", "given.config.ts"]],
];
it.each(readErrorRuns)("ends on a read error other than a missing file in %s", async (_, folder, options) => {
expect(configs).toContain(folder);
const root = await mkdtemp(path.join(tmpdir(), "test-evidence-registry-"));
try {
for (const config of configs.filter((config) => config !== folder)) {
await mkdir(path.dirname(path.join(root, config)), { recursive: true });
await copyFile(config, path.join(root, config));
}
await mkdir(path.join(root, folder), { recursive: true });
await writeFile(path.join(root, "given.config.ts"), "export default { forbidOnly: true };\n");
const { result } = await fullCheckIn(root, ...options);
expect(result.status).not.toBe(0);
expect(result.stderr).toMatch(/EISDIR/u);
expect(result.stderr).not.toContain("this checkout has no such file");
} finally {
await rm(root, { recursive: true, force: true });
}
}, childProcessTimeout(CHECK_MS));
});