FE-GATE-029는 check:design-system:fixture와 check:diagnostics:fixture가 exit 1과 머리말을 내면 통과로 센다. 거절된 파일이 하나만 있어도 그 조건이 채워진다. 그래서 검사기에서 진짜 규칙(TSX의 raw palette·hue mix·inline style, direct console·민감 context)을 지워도 029가 초록이었다. fixture 폴더에서만 도는 표식 규칙(TOOLTIP_ONLY_REQUIRED_INFORMATION, UNKNOWN_DIAGNOSTIC_EVENT)이 자기 파일을 늘 거절했기 때문이다. check-i18n.ts가 하던 파일별 판정을 scripts/lib/fixture-rejection.ts로 옮기고 세 검사기가 같이 쓴다. fixture 모드에서 어느 failure도 이름을 대지 않는 fixture 파일이 있거나 fixture 파일이 하나도 없으면, 그 목록을 찍고 exit 2로 끝난다. 029는 exit 1을 기대하므로 실패한다. 파일 이름은 경로 경계로 맞춘다(a.ts가 a.tsx·b/a.ts에 맞지 않는다). i18n 판정은 endsWith에서 이 판정으로 바뀌어 조금 엄격해진다. 표식 규칙 둘을 지운다. tooltip-only.tsx는 그 표식 말고 거절할 규칙이 없어 지운다. headless-vendor-import.tsx·hue-mix.tsx를 더하고, raw-palette.tsx는 inline style 없이 SVG fill로 바꿔 fixture 하나가 규칙 하나에 걸리게 한다. direct-console.ts에서는 표식 문자열을 뺀다. fe-design-system 스킬이 지운 tooltip 규칙을 있는 것처럼 적던 줄도 고친다. 버린 안: gates.json의 expectedDiagnosticId를 규칙 문구로 좁히기. 항목 범위가 029 정의를 바꾸지 말라고 하고, 규칙이 여럿이라 문구 하나로는 다 못 본다. 한계: 파일마다 「failure가 하나라도 있는지」를 본다. fixture 하나에 서로 다른 규칙 둘이 걸리면 하나를 지워도 다른 하나가 거절한다. 지금 fixture는 규칙 하나씩이고 시험이 failure 목록을 그대로 단언하지만, 새 fixture에 그것을 강제하지는 않는다. check-i18n.ts가 helper를 부르는지 단언하는 시험은 없다(main에도 없다). 시험: design-system-rules.test.ts·fixture-rejection.test.ts가 임시 root에서 검사기를 돌려, fixture마다 기대한 failure만 나오는지와 거절되지 않는 파일을 더하면 exit 2와 그 파일이 찍히는지 본다. helper는 경로 경계· 빈 폴더를 단위로 본다. timeout은 desktop에서 잰 가장 긴 값(test:unit 1,038 ms)이다. design-system 쪽 두 시험(가장 긴 719 ms)은 기존 describe의 3,540 ms 안이다. RED·GREEN은 PR 본문에 적는다. Refs: REV-FE-0002
146 lines
5.5 KiB
TypeScript
146 lines
5.5 KiB
TypeScript
import { mkdir, readFile, readdir } from "node:fs/promises";
|
|
|
|
import { diagnosticsReportArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
import { fixtureRejectionFailure } from "./lib/fixture-rejection.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
DIAGNOSTIC_CONTEXT_ALLOWLIST,
|
|
DIAGNOSTIC_CONTEXT_CARDINALITY,
|
|
DIAGNOSTIC_EVENT_REGISTRY,
|
|
} from "../src/contracts/diagnostics.ts";
|
|
import {
|
|
TELEMETRY_ATTRIBUTE_ALLOWLIST,
|
|
TELEMETRY_REGISTRY,
|
|
} from "../src/contracts/telemetry.ts";
|
|
|
|
const fixtureMode = process.argv.includes("--fixture");
|
|
const failures: string[] = [];
|
|
const extensions = /\.(?:ts|tsx|mts|cts)$/;
|
|
|
|
async function filesBelow(directory: string): Promise<string[]> {
|
|
const result: string[] = [];
|
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
const target = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) result.push(...(await filesBelow(target)));
|
|
else if (extensions.test(entry.name)) result.push(target);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const telemetryProducerFiles: Readonly<Record<string, string>> = {
|
|
"app.boot.failed": "src/adapters/diagnostics/bounded-diagnostics.ts",
|
|
"api.request.failed": "src/bootstrap/runtime-adapters.ts",
|
|
"ui.render.failed": "src/application/create-application.ts",
|
|
"release.mismatch.detected": "src/application/create-application.ts",
|
|
"service-worker.start.failed": "src/bootstrap/optional-runtime-host.ts",
|
|
"telemetry.delivery.dropped":
|
|
"src/adapters/telemetry/best-effort-telemetry.ts",
|
|
};
|
|
const diagnosticProducerFiles: Readonly<Record<string, string>> = {
|
|
"app.boot.failed": "src/adapters/diagnostics/bounded-diagnostics.ts",
|
|
"http.request.completed": "src/bootstrap/runtime-adapters.ts",
|
|
"cache.operation.failed":
|
|
"src/adapters/query-cache/tanstack-query-cache.ts",
|
|
"storage.operation.failed":
|
|
"src/adapters/storage/browser-storage-adapter.ts",
|
|
"route.changed": "src/application/create-application.ts",
|
|
"ui.render.failed": "src/application/create-application.ts",
|
|
"release.mismatch.detected": "src/application/create-application.ts",
|
|
"telemetry.delivery.dropped": "src/bootstrap/runtime-adapters.ts",
|
|
"feature.override.unknown": "src/bootstrap/runtime-adapters.ts",
|
|
};
|
|
|
|
for (const key of DIAGNOSTIC_CONTEXT_ALLOWLIST) {
|
|
if (!DIAGNOSTIC_CONTEXT_CARDINALITY[key]) {
|
|
failures.push(`diagnostic context key has no cardinality class: ${key}`);
|
|
}
|
|
}
|
|
for (const key of TELEMETRY_ATTRIBUTE_ALLOWLIST) {
|
|
// Defensive at runtime: the types already exclude it, the gate still checks.
|
|
const cardinality: string | undefined = DIAGNOSTIC_CONTEXT_CARDINALITY[key];
|
|
if (cardinality === "request") {
|
|
failures.push(`request-cardinality telemetry attribute is forbidden: ${key}`);
|
|
}
|
|
}
|
|
|
|
if (!fixtureMode) {
|
|
for (const eventName of Object.keys(TELEMETRY_REGISTRY)) {
|
|
const producer = telemetryProducerFiles[eventName];
|
|
if (!producer) {
|
|
failures.push(`telemetry event has no declared producer: ${eventName}`);
|
|
continue;
|
|
}
|
|
const source = await readFile(producer, "utf8");
|
|
if (!source.includes(`"${eventName}"`)) {
|
|
failures.push(`telemetry producer is not executable: ${eventName}`);
|
|
}
|
|
}
|
|
for (const eventId of Object.keys(DIAGNOSTIC_EVENT_REGISTRY)) {
|
|
const producer = diagnosticProducerFiles[eventId];
|
|
if (!producer) {
|
|
failures.push(`diagnostic event has no declared producer: ${eventId}`);
|
|
continue;
|
|
}
|
|
const source = await readFile(producer, "utf8");
|
|
if (!source.includes(`"${eventId}"`)) {
|
|
failures.push(`diagnostic producer is not executable: ${eventId}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
const sources = fixtureMode
|
|
? await filesBelow("tests/fixtures/diagnostics/forbidden")
|
|
: await filesBelow("src");
|
|
const sensitiveContext =
|
|
/\b(?:authorization|cookie|access_token|refresh_token|request_body|response_body|raw_url|query_string|email|user_name)\b/i;
|
|
for (const file of sources) {
|
|
const source = await readFile(file, "utf8");
|
|
if (file.includes("contracts/telemetry.ts")) continue;
|
|
if (source.includes("console.")) {
|
|
failures.push(`direct console diagnostics bypass in ${file}`);
|
|
}
|
|
const calls = source.match(
|
|
/(?:\.record\(\{|\.emit\()[\s\S]{0,700}?(?:\}\)|\}\);)/g,
|
|
) ?? [];
|
|
if (calls.some((call) => sensitiveContext.test(call))) {
|
|
failures.push(`sensitive diagnostic or telemetry context in ${file}`);
|
|
}
|
|
}
|
|
|
|
const report = diagnosticsReportArtifactSchema.parse({
|
|
schemaVersion: 1,
|
|
mode: fixtureMode ? "negative-fixture" : "source",
|
|
telemetryEventCount: Object.keys(TELEMETRY_REGISTRY).length,
|
|
diagnosticEventCount: Object.keys(DIAGNOSTIC_EVENT_REGISTRY).length,
|
|
checkedFiles: sources.length,
|
|
failures,
|
|
passed: failures.length === 0,
|
|
});
|
|
await mkdir("artifacts/quality", { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: fixtureMode
|
|
? "artifacts/quality/diagnostics-fixture.json"
|
|
: "artifacts/quality/diagnostics.json",
|
|
schema: diagnosticsReportArtifactSchema,
|
|
value: report,
|
|
});
|
|
// Every fixture file must be rejected by a rule of its own (REV-FE-0002).
|
|
const unrejectedFixtures = fixtureMode
|
|
? fixtureRejectionFailure("Diagnostics", sources, failures)
|
|
: undefined;
|
|
if (unrejectedFixtures) {
|
|
process.stderr.write(unrejectedFixtures);
|
|
process.exit(2);
|
|
}
|
|
if (failures.length > 0) {
|
|
process.stderr.write(
|
|
`Diagnostics contract failed:\n${failures.join("\n")}\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Diagnostics contract: ${report.diagnosticEventCount} diagnostics and ${report.telemetryEventCount} telemetry producers PASS\n`,
|
|
);
|