fix(errors): 「JSON 아님」을 response.invalid로 나누고 telemetry 정책 시험을 더한다 #84
@@ -122,6 +122,7 @@ Gitea runner에서 merge 단계를 초록으로 만들고, worker를 늘리지
|
||||
| [계약] | FE-GATE-005의 명령이 `test:coverage`·`check:scale:pr` 둘이 된다. `tests/unit`·`tests/contract`의 JUnit 증거(`unit.xml`·`contract.xml`, 이름·형식 그대로)는 coverage 실행 안의 reporter가 쓰고, 두 증거의 producer는 `test-coverage`다. 한 폴더에서 시험 파일이 하나도 돌지 않거나 보고서가 그 폴더에서 돈 파일과 다른 파일을 담으면 그 실행이 실패한다. unit·contract 시험은 이제 coverage 계측 아래에서만 돈다. FE-GATE-004·006·007은 자기 실행을 그대로 둔다(decisions.md FE-4) | `config/ci/gates.json`, `package.json`, `scripts/lib/coverage-bundle-junit-reporter.ts`, `scripts/lib/feature-scaffold-drill.ts`, `tests/unit/coverage-bundle-junit-reporter.test.ts`, `docs/operations/ci-quality-gates.md` | `6cba1f50` |
|
||||
| [계약] | `check:ci:gating`(FE-GATE-029)이 Playwright 실행의 `--grep`·`--grep-invert`·파일 필터를 읽는다. testDir은 필터 없는 gated 실행이 있거나, `--grep-invert P` 실행마다 같은 testDir을 `--grep P`(같은 글자)로 도는 gated 실행이 있을 때만 게이트 안으로 센다. 파일 필터가 있는 실행, `--grep`·`--grep-invert`를 합쳐 둘 이상 쓴 실행, 설정(또는 그 설정이 import한 설정)에 `grep`·`grepInvert`가 있는 실행은 부분 실행으로 센다. 그 testDir의 게이트 밖 파일은 testDir·실행·빠진 짝을 대는 한 줄로 실패한다. 전에는 009의 Playwright 실행을 빼도 통과해, 시험이 모두 `@a11y`인 `tests/e2e/accessibility.spec.ts`가 어느 게이트에서도 돌지 않았다. `-c X`·`-cX`·`--config=X`로 고른 설정도 이제 읽는다(전에는 e2e 설정의 testDir로 셌다). 위 "먼저 할 일" | `scripts/lib/playwright-test-args.ts`, `scripts/lib/ungated-tests.ts`, `scripts/check-ci-gating.ts`, `playwright.a11y.config.ts`, `tests/unit/playwright-test-args.test.ts`, `tests/unit/ungated-tests.test.ts`, `tests/unit/playwright-result-paths.test.ts`, `docs/operations/ci-quality-gates.md` | `32982e55` |
|
||||
| [보안] | telemetry payload 정제가 복사하는 값의 총수를 `maxNodes`(기본 512)로 막는다. 같은 객체를 여러 key가 가리키는 payload(정규화된 엔티티 graph 등)를 경로마다 따로 복사해, `emit` 한 번이 호출 스택을 수 초 막거나 heap OOM으로 탭을 죽였다. 여러 경로가 가리키는 객체의 key는 한 번만 읽는다. 순회가 너비 우선이 되어 상한이 차면 얕은 필드가 남고 깊은 값이 `[truncated]`가 된다. 복사본 객체의 key 순서가 원본 순서가 된다(전에는 거꾸로, fingerprint는 그대로). 깊이 제한 시험이 잘린 모양과 순환 payload를 단언한다 | `src/platform/telemetry/redact-telemetry.ts`, `src/platform/telemetry/telemetry-pipeline.ts`, `tests/platform/telemetry/redact-telemetry.test.ts`, `config/scale/feature-shape-ceilings.json` | `d406c10b`, `0190b631` |
|
||||
| [계약] | `mapTransportFailure`가 `JsonBudgetExceededError`의 own data `violation`이 `"invalid-json"`이면 `response.invalid`로 분류한다. 전에는 `parseBoundedJson`이 JSON이 아닌 응답에 던진 오류가 `response.too-large`가 되어 날 `SyntaxError`(`response.invalid`)와 갈렸다. 두 kind의 category(`contract`)·retryability(`never`)는 같다. `violation`이 accessor면 부르지 않고 `response.too-large`로 둔다. 시험 표에 fan-out 초과·`TimeoutError`·invalid-json 줄을 더한다 | `src/platform/errors/platform-errors.ts`, `tests/platform/errors/platform-errors.test.ts` | `a934554d` |
|
||||
|
||||
### 그 밖의 변경
|
||||
|
||||
|
||||
@@ -18,3 +18,4 @@
|
||||
{"date": "2026-11-19", "test": "tests/browser-capabilities/cross-context-invalidation.spec.ts:223", "category": "concurrency-order", "first_run": "371", "verdict": "원인 확정(2026-11-19). [chromium] runner run 371 1회 실패(받은 deliveries []). desktop main f3de258d 단독 3회 모두 통과, CPU·메모리 hog 12개(nice 19, load 17.5) 아래 --repeat-each 20 중 1회 실패(같은 단언). Chromium은 탭의 첫 localStorage 읽기(CachedStorageArea::EnsureLoaded)에서 observer를 바꾸며 이미 도착한 다른 탭의 변경 알림을 버린다. 받는 page가 바쁠 때 그 page의 첫 읽기(발행 직후 snapshot, 또는 앱 부트의 설정 읽기)가 먼저 돌아 pulse를 잃었다(늦음이 아니라 잃음: 실패 회차에 raw storage 이벤트 0개). 받는 page를 막은 사이 발행하고 같은 작업에서 첫 읽기를 하는 탐침이 고치기 전 chromium 5/5 실패(firefox·webkit 10/10 통과). 고친 트리 ddda30a3에서 hog 12개 아래 chromium 그 spec 120회 실패 0", "quarantined_until": "", "fixed_by": "프론트 #63"}
|
||||
{"date": "2026-11-19", "test": "tests/e2e/generated-feature.spec.ts:127", "category": "fixed-time", "first_run": "344", "verdict": "runner run 344(#60 62ba55d7, FE-GATE-008 webkit :276)에서 1회 실패. signInAt의 첫 h1 기본 5초 대기에서 h1 없음(429와 무관). 원인은 CPU 포화 — 세션 부하 실험(nice 없는 busy loop·메모리 hog, 01:06~02:0x)과 runner job이 겹쳤다(sar 01:40~02:00 idle 0.08~2.5%, runq 28, iowait 0.01%). 평시에는 재현 안 됨 0/~970(webkit goto→h1 최대 2.2s, load 32 이하). 일부러 포화시키면(busy loop 34, load 44~51) h1>5s 7~33/90이고, 청크 가로채기 유무와 무관(7/90·8/90). 시험은 고치지 않는다. 부하 실험을 nice -n 19로 돌리고 runner job이 없을 때 시작한다", "quarantined_until": "", "fixed_by": ""}
|
||||
{"date": "2026-11-21", "test": "tests/unit/browser-rpc/browser-rpc-remediation.test.ts:577", "category": "fixed-time", "first_run": "455", "verdict": "재현 안 됨. runner run 455(main 945b70c0) FE-GATE-030 드릴 사본의 test에서 1회 실패(job 시작 load 8.04): RPC-01 「waitClosed returns a non-promise」의 :577 expect(probe.opened()).toBe(1)이 0을 받았다. desktop 같은 트리(31053211)에서 그 파일 단독 3회 모두 통과(load 5.65 9.78 11.59), busy loop 12개(nice 19, 12코어) 아래 20회 실패 0(load 12.1~15.9). 범주는 실패 모양으로 붙인 후보다: 시험이 실제 시계로 total·idle deadline 25 ms(shortDeadline)와 30 ms로 자른 sleep(cappedClock)을 쓰고, 물리 스트림이 열리기 전에 끝났다. 시험은 고치지 않고 다음 실패를 기다린다", "quarantined_until": "", "fixed_by": ""}
|
||||
{"date": "2026-11-21", "test": "tests/e2e/production-csp.spec.ts:55", "category": "resource-io", "first_run": "476", "verdict": "재현 안 됨. runner run 476(main b687a04c, job 5414 merge / browser tests, FE-GATE-008 webkit)에서 1회 실패: 33행 route.fetch가 vite preview의 GET /assets/navigation-policy-*.js에서 socket hang up, 그 뒤 h1 없음(같은 job의 나머지 176개 passed). 같은 내용의 PR run 474 browser tests는 success. desktop main 트리 webkit 세 번 3/3 통과(load 23~24, nproc 12), nproc개 CPU 부하 아래 --repeat-each=20 20/20 통과(끝 load 20.4). route.fetch가 preview 서버 연결을 잃은 것이라 자원·IO로 둔다", "quarantined_until": "", "fixed_by": ""}
|
||||
|
||||
@@ -59,6 +59,13 @@ function errorName(error: unknown): string | undefined {
|
||||
return error instanceof Error ? error.name : undefined;
|
||||
}
|
||||
|
||||
/** Reads an own data property; an accessor is never invoked. */
|
||||
function ownDataValue(value: unknown, key: string): unknown {
|
||||
if (value === null || typeof value !== "object") return undefined;
|
||||
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
||||
return descriptor && "value" in descriptor ? descriptor.value : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a raw failure thrown by a transport (fetch, a lease wait, a budget
|
||||
* check) to a platform error. An abort is a timeout only when the caller
|
||||
@@ -83,7 +90,10 @@ export function mapTransportFailure(
|
||||
return PLATFORM_ERRORS.TRAFFIC_BUDGET_EXCEEDED;
|
||||
}
|
||||
if (name === "JsonBudgetExceededError") {
|
||||
return PLATFORM_ERRORS.RESPONSE_TOO_LARGE;
|
||||
// `parseBoundedJson` reports text that is not JSON with this error too.
|
||||
return ownDataValue(error, "violation") === "invalid-json"
|
||||
? PLATFORM_ERRORS.RESPONSE_INVALID
|
||||
: PLATFORM_ERRORS.RESPONSE_TOO_LARGE;
|
||||
}
|
||||
if (name === "SyntaxError") return PLATFORM_ERRORS.RESPONSE_INVALID;
|
||||
return PLATFORM_ERRORS.NETWORK_UNAVAILABLE;
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import { isAppError } from "../../../src/platform/errors/app-error.ts";
|
||||
import { RequestBudgetExceededError } from "../../../src/platform/traffic/request-budget.ts";
|
||||
import { ConcurrencyQueueFullError } from "../../../src/platform/traffic/concurrency-budget.ts";
|
||||
import { RequestFanoutExceededError } from "../../../src/platform/traffic/request-fanout.ts";
|
||||
import { DeadlineExceededError } from "../../../src/platform/resilience/deadline.ts";
|
||||
import { JsonBudgetExceededError } from "../../../src/platform/validation/bounded-json.ts";
|
||||
import { TEST_LIST_HTTP_CONTRACT } from "../../helpers/external-contract-fixture.ts";
|
||||
@@ -48,13 +49,32 @@ describe("platform error normalization", () => {
|
||||
[new TypeError("Failed to fetch"), "network.unavailable"],
|
||||
[new RequestBudgetExceededError(2), "traffic.budget-exceeded"],
|
||||
[new ConcurrencyQueueFullError(0), "traffic.budget-exceeded"],
|
||||
[new RequestFanoutExceededError(2, 1), "traffic.budget-exceeded"],
|
||||
// `AbortSignal.timeout()` aborts with this reason; it is a timeout even
|
||||
// when the caller's own deadline has not expired.
|
||||
[new DOMException("signal timed out", "TimeoutError"), "request.timeout"],
|
||||
[new JsonBudgetExceededError("too-large", "x"), "response.too-large"],
|
||||
// `parseBoundedJson` wraps a `JSON.parse` failure in this error.
|
||||
[new JsonBudgetExceededError("invalid-json", "x"), "response.invalid"],
|
||||
[new SyntaxError("Unexpected token"), "response.invalid"],
|
||||
["not even an error", "network.unavailable"],
|
||||
] as const)("maps %s to %s", (error, kind) => {
|
||||
expect(mapTransportFailure(error, { deadlineExpired: false }).kind).toBe(kind);
|
||||
});
|
||||
|
||||
it("reads a JSON budget violation only as own data, never through an accessor", () => {
|
||||
const violation = vi.fn(() => "invalid-json");
|
||||
const lookalike = Object.defineProperties(new RangeError("x"), {
|
||||
name: { value: "JsonBudgetExceededError" },
|
||||
violation: { get: violation },
|
||||
});
|
||||
|
||||
expect(mapTransportFailure(lookalike, { deadlineExpired: false }).kind).toBe(
|
||||
"response.too-large",
|
||||
);
|
||||
expect(violation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps every platform error a valid, stable envelope", () => {
|
||||
for (const error of Object.values(PLATFORM_ERRORS)) {
|
||||
expect(isAppError(error)).toBe(true);
|
||||
|
||||
@@ -14,6 +14,10 @@ const criticalEvent = (id: string): TelemetryEvent<unknown> => ({
|
||||
severity: "critical",
|
||||
payload: { id },
|
||||
});
|
||||
const at = (severity: TelemetryEvent<unknown>["severity"]): TelemetryEvent<unknown> => ({
|
||||
kind: `test.${severity}`,
|
||||
severity,
|
||||
});
|
||||
|
||||
describe("createDeterministicSampler", () => {
|
||||
it("makes the same sampling decision for the same stable key", () => {
|
||||
@@ -63,10 +67,6 @@ describe("createTelemetryBuffer", () => {
|
||||
});
|
||||
|
||||
it("evicts nothing when eviction cannot make room for the incoming event (Q-6.9-11)", () => {
|
||||
const at = (severity: TelemetryEvent<unknown>["severity"]) => ({
|
||||
kind: `test.${severity}`,
|
||||
severity,
|
||||
});
|
||||
const evicted: string[] = [];
|
||||
const buffer = createTelemetryBuffer({
|
||||
maxEvents: 10,
|
||||
@@ -93,6 +93,21 @@ describe("createTelemetryBuffer", () => {
|
||||
expect(buffer.dropped).toBe(1);
|
||||
});
|
||||
|
||||
it("evicts the lowest severity first, even when an older event is more severe", () => {
|
||||
const evicted: string[] = [];
|
||||
const buffer = createTelemetryBuffer({
|
||||
maxEvents: 2,
|
||||
maxBytes: 1_024,
|
||||
onEvict: (entry) => evicted.push(entry.event.severity),
|
||||
});
|
||||
buffer.push(at("warning"));
|
||||
buffer.push(at("info"));
|
||||
|
||||
expect(buffer.push(at("error"))).toBe(true);
|
||||
expect(buffer.items.map((item) => item.severity)).toEqual(["warning", "error"]);
|
||||
expect(evicted).toEqual(["info"]);
|
||||
});
|
||||
|
||||
it("enforces the byte ceiling independently of the event count", () => {
|
||||
const buffer = createTelemetryBuffer({ maxEvents: 100, maxBytes: 200 });
|
||||
for (let i = 0; i < 50; i += 1) buffer.push(infoEvent(`event-${i}`));
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type TelemetryPipelineBudget,
|
||||
} from "../../../src/platform/telemetry/telemetry-pipeline.ts";
|
||||
import type { TelemetryEvent } from "../../../src/platform/telemetry/telemetry-event.ts";
|
||||
import { createDeterministicSampler } from "../../../src/platform/telemetry/telemetry-sampler.ts";
|
||||
|
||||
const TEST_TELEMETRY_BUDGET: TelemetryPipelineBudget = {
|
||||
...DEFAULT_TELEMETRY_PIPELINE_BUDGET,
|
||||
@@ -251,6 +252,36 @@ describe("createTelemetryPipeline", () => {
|
||||
expect(pipeline.stats()).toMatchObject({ sampledOut: 1, buffered: 1 });
|
||||
});
|
||||
|
||||
it("keeps or drops an interaction's info and warning events together", async () => {
|
||||
const sampleRate = 0.5;
|
||||
const sampler = createDeterministicSampler({ rate: sampleRate });
|
||||
// Four interactions the rate keeps and four it drops, so both paths run.
|
||||
const candidates = Array.from({ length: 1_000 }, (_, i) => `interaction-${i}`);
|
||||
const kept = candidates.filter((interactionId) => sampler.keep(interactionId)).slice(0, 4);
|
||||
const dropped = candidates.filter((interactionId) => !sampler.keep(interactionId)).slice(0, 4);
|
||||
expect([kept.length, dropped.length]).toEqual([4, 4]);
|
||||
const interactions = [...dropped, ...kept];
|
||||
const batches: TelemetryBatchItem[][] = [];
|
||||
const pipeline = createTelemetryPipeline({
|
||||
transport: { send: (batch) => void batches.push([...batch]) },
|
||||
budget: { ...TEST_TELEMETRY_BUDGET, sampleRate },
|
||||
schedule: () => {},
|
||||
});
|
||||
// Each event has its own payload, so its fingerprint (which leaves the
|
||||
// interaction id out) differs from every other event's.
|
||||
for (const [step, interactionId] of interactions.entries()) {
|
||||
await pipeline.emit({ kind: "a.info", severity: "info", interactionId, payload: { step } });
|
||||
await pipeline.emit({ kind: "a.warning", severity: "warning", interactionId, payload: { step } });
|
||||
}
|
||||
await pipeline.flush();
|
||||
|
||||
expect(
|
||||
batches.flat().map((item) => `${item.event.interactionId}:${item.event.severity}`),
|
||||
).toEqual(kept.flatMap((interactionId) => [`${interactionId}:info`, `${interactionId}:warning`]));
|
||||
expect(pipeline.stats().sampledOut).toBe(2 * dropped.length);
|
||||
pipeline.dispose();
|
||||
});
|
||||
|
||||
it("drops invalid envelopes and stops admitting after dispose", async () => {
|
||||
const send = vi.fn();
|
||||
const pipeline = createTelemetryPipeline({
|
||||
|
||||
Reference in New Issue
Block a user