diff --git a/config/scale/feature-shape-ceilings.json b/config/scale/feature-shape-ceilings.json index 18a3f356..2be41026 100644 --- a/config/scale/feature-shape-ceilings.json +++ b/config/scale/feature-shape-ceilings.json @@ -41,8 +41,8 @@ "initialJavascript": { "gzipBytes": 194354, "files": 17, - "firstFeatureGzipBytes": 6327, - "perFeatureGzipBytes": 539, - "perContextGzipBytes": 4 + "firstFeatureGzipBytes": 6355, + "perFeatureGzipBytes": 528, + "perContextGzipBytes": 21 } } diff --git a/scripts/create-feature.ts b/scripts/create-feature.ts index 63b02aac..21477cc3 100644 --- a/scripts/create-feature.ts +++ b/scripts/create-feature.ts @@ -884,6 +884,7 @@ export type ${pascal}CreateCommand = Readonly<{ name: string }>; ` : ""; return `import type {} from "../../../application/ports/in/application-api.ts"; +import { isAbortFailure } from "../../../contracts/errors.ts"; ${write ? `import type { MutationIntent } from "../../../contracts/mutation-intent.ts";\n` : ""}import type { Result } from "../../../contracts/result.ts"; import { failOpenTelemetryPort, @@ -938,7 +939,8 @@ export function create${pascal}FeatureInput( // scale-architecture.md §24, §26: telemetry is best-effort and never changes the result. const events = failOpenTelemetryPort(telemetry); function reported(kind: string, result: Result): Result { - if (!result.ok && result.error.kind !== "REQUEST_ABORTED") { + // An aborted or fenced request did not fail (isAbortFailure). + if (!result.ok && !isAbortFailure(result.error)) { void events.emit({ kind, severity: "warning", @@ -1279,6 +1281,18 @@ describe("${names.id} application input", () => { await expect(input.listItems()).resolves.toEqual({ ok: false, error: failure }); expect(emit).not.toHaveBeenCalled(); }); + + it("does not report a load a scope fence ended", async () => { + const failure = createFailure("SCOPE_GENERATION_CHANGED", "${operationId}", 0); + const emit = vi.fn(); + const input = create${pascal}FeatureInput( + gatewayListing(async () => ({ ok: false, error: failure })), + { telemetry: { emit } }, + ); + + await expect(input.listItems()).resolves.toEqual({ ok: false, error: failure }); + expect(emit).not.toHaveBeenCalled(); + }); }); `; } diff --git a/src/contracts/errors.ts b/src/contracts/errors.ts index f6b98b62..bd3d8cd9 100644 --- a/src/contracts/errors.ts +++ b/src/contracts/errors.ts @@ -259,6 +259,16 @@ export const REFUSALS_OF_EVERY_ATTEMPT: Readonly> = IDEMPOTENCY_KEY_INVALID: 400, }); +/** + * 1112/01-03. The request did not fail: its caller aborted it + * (`REQUEST_ABORTED`) or a scope fence ended it (`SCOPE_GENERATION_CHANGED`, + * sign-out or account switch). Telemetry and terminal error screens do not + * count it (testing strategy 7.1절). + */ +export function isAbortFailure(failure: AppFailure): boolean { + return failure.kind === "REQUEST_ABORTED" || failure.kind === "SCOPE_GENERATION_CHANGED"; +} + /** * 1106/03-01 (D10 supplement and its second fix). A `NOT_APPLIED` refusal * the same request gets on every attempt: a row above, code and status diff --git a/tests/unit/abort-failure.test.ts b/tests/unit/abort-failure.test.ts new file mode 100644 index 00000000..709b68b0 --- /dev/null +++ b/tests/unit/abort-failure.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vitest"; + +import { createFailure, isAbortFailure } from "../../src/contracts/errors.ts"; + +/** + * 1112/01-03. A request its caller aborted and one a scope fence ended + * (sign-out, account switch) are not failures: telemetry and terminal error + * screens must not count them (docs/design/2026-07-26-frontend-platform-testing-strategy-design.md + * 7.1절). The generated feature asked only for `REQUEST_ABORTED`, so a fenced + * request went out as `.list.failed`. + */ +describe("isAbortFailure", () => { + it("counts a caller abort and a scope fence as aborts", () => { + expect(isAbortFailure(createFailure("REQUEST_ABORTED", "LIST", 0))).toBe(true); + expect(isAbortFailure(createFailure("SCOPE_GENERATION_CHANGED", "LIST", 0))).toBe(true); + }); + + it("does not count a timeout, a server failure or a refusal", () => { + for (const kind of ["REQUEST_TIMEOUT", "SERVER_FAILURE", "FORBIDDEN", "RATE_LIMITED"] as const) { + expect(isAbortFailure(createFailure(kind, "LIST", 0)), kind).toBe(false); + } + }); +}); diff --git a/tests/unit/create-feature.test.ts b/tests/unit/create-feature.test.ts index addc1b40..222b50b6 100644 --- a/tests/unit/create-feature.test.ts +++ b/tests/unit/create-feature.test.ts @@ -459,6 +459,21 @@ describe("create:feature context declaration", () => { }); }); +// 1112/01-03. The generated input reports a failed load, not one a scope +// fence ended (sign-out, account switch): it asks the shared rule. +describe("generated feature input telemetry", () => { + it("does not report a load a scope fence ended", () => { + const { files } = plan({ id: "invoice-feature" }); + + expect(files.get("src/features/invoice-feature/application/invoice-feature-api.ts")).toContain( + "isAbortFailure(result.error)", + ); + expect(files.get("tests/features/invoice-feature/invoice-feature-input.test.ts")).toContain( + 'createFailure("SCOPE_GENERATION_CHANGED"', + ); + }); +}); + describe("create:feature refusals", () => { it.each(["Invoice", "invoice_feature", "-invoice", "invoice--x", "invoice-", "", "a".repeat(41)])( "refuses the id %j",