frontend-quality-gates / merge / static checks (pull_request) Successful in 2m56s
frontend-quality-gates / merge / tests (pull_request) Failing after 14m26s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 9m20s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
frontend-quality-gates / main / checker self-tests (pull_request) Skipped
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
isRefusedOnEveryAttempt는 failure.code를 읽는데, 그 값은 기능의 mapProblem이 정한다(1112/01-06). 그래서 둘이 틀린다. - 기능이 백엔드 400 VALIDATION_FAILED를 자기 code로 바꾸면 모든 시도가 받는 거절인데도 결과 불명이 풀리지 않는다. - 기능이 시각·데이터베이스를 읽는 자기 거절(400)을 VALIDATION_FAILED로 바꾸면 첫 요청이 반영됐을 수 있는데도 결과 불명이 풀린다. AppFailure에 backendCode를 더한다(선택 칸, 추가만). HTTP 바인딩이 ENVELOPE_V1 operation의 PROBLEM에서 백엔드 error.code를 그대로 싣고, 판정은 이 칸과 status만 읽는다. Envelope가 없는 operation의 실패에는 싣지 않아 결과 불명이 풀리지 않는다(안전한 쪽). 버린 대안: 판정 표를 기능 code에 맞춰 늘리기(기능이 code를 바꿀 때마다 표가 어긋난다). 위험·한계: createFailure로 실패를 직접 만들어 재전송 거절을 흉내 내던 코드는 backendCode를 함께 줘야 결과 불명이 풀린다. 템플릿 안에서는 코디네이터 시험 넷뿐이고 고쳤다. 다운스트림 시험이 같은 방식이면 CHANGELOG [계약]에 적는다. mapProblem이 예외를 던져 MAPPING_CONTRACT_VIOLATION이 된 실패에는 싣지 않는다. Refs: 1112/01-06, 1106/03-01
370 lines
12 KiB
TypeScript
370 lines
12 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
createFeatureHttpBinding,
|
|
defineFeatureHttpOperation,
|
|
type HttpExecutionOutcome,
|
|
type InstalledHttpOperationExecutor,
|
|
} from "../../../src/adapters/http/index.ts";
|
|
import {
|
|
mappingFailure,
|
|
mappingSuccess,
|
|
} from "../../../src/contracts/boundary-mapper.ts";
|
|
import type {
|
|
InstalledHttpContract,
|
|
RuntimeValidator,
|
|
} from "../../../src/contracts/external-contract-runtime.ts";
|
|
|
|
type ResourceInput = Readonly<{ resourceId: string }>;
|
|
type ResourceWire = Readonly<{ id: string; title: string }>;
|
|
type ResourceProblem = Readonly<{ code?: string }>;
|
|
|
|
function validator<T>(schemaId: string): RuntimeValidator<T> {
|
|
return Object.freeze({
|
|
schemaId,
|
|
safeParse(value: unknown) {
|
|
return Object.freeze({
|
|
success: true as const,
|
|
data: value as T,
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
const LOAD_RESOURCE_CONTRACT = Object.freeze({
|
|
contract: Object.freeze({
|
|
operationId: "LOAD_RESOURCE",
|
|
method: "GET" as const,
|
|
pathTemplate: "/resources/{resourceId}",
|
|
inputValidator: validator<ResourceInput>("ResourceInput"),
|
|
outputValidator: validator<ResourceWire>("ResourceWire"),
|
|
problemValidator: validator<ResourceProblem>("ResourceProblem"),
|
|
acceptedStatuses: Object.freeze([200]),
|
|
emptyBodyStatuses: Object.freeze([]),
|
|
retrySemantics: "SAFE" as const,
|
|
requestBody: "NONE" as const,
|
|
responseBody: "REQUIRED_JSON" as const,
|
|
responseEnvelope: "NONE" as const,
|
|
commandRecovery: null,
|
|
commandEffect: null,
|
|
projectRequest(input: ResourceInput) {
|
|
return Object.freeze({
|
|
pathValues: Object.freeze({ resourceId: input.resourceId }),
|
|
queryEntries: Object.freeze([]),
|
|
body: null,
|
|
});
|
|
},
|
|
}),
|
|
frontend: Object.freeze({
|
|
policyId: "TEST_LOAD_RESOURCE",
|
|
requestByteLimit: 0,
|
|
responseByteLimit: 8_192,
|
|
totalDeadlineMs: 1_000,
|
|
retryBudget: 0 as const,
|
|
authProfileId: "TEST",
|
|
diagnosticsOperation: "test.load-resource",
|
|
}),
|
|
}) satisfies InstalledHttpContract<ResourceInput, ResourceWire, ResourceProblem>;
|
|
|
|
const OPERATIONS = Object.freeze({
|
|
LOAD_RESOURCE: defineFeatureHttpOperation({
|
|
contract: LOAD_RESOURCE_CONTRACT,
|
|
routeId: "RESOURCE_DETAIL",
|
|
mapSuccess(value) {
|
|
if (value.title.length === 0) {
|
|
return mappingFailure("MAPPING_INVARIANT_REJECTED");
|
|
}
|
|
return mappingSuccess(
|
|
Object.freeze({ id: value.id, title: value.title }),
|
|
);
|
|
},
|
|
mapProblem(problem, metadata) {
|
|
if (metadata.status !== 409) return undefined;
|
|
return Object.freeze({
|
|
kind: "CONFLICT" as const,
|
|
code: problem.code ?? "RESOURCE_CONFLICT",
|
|
});
|
|
},
|
|
}),
|
|
} as const);
|
|
|
|
function scriptedExecutor<WireOutput, Problem>(
|
|
outcome: HttpExecutionOutcome<WireOutput, Problem>,
|
|
) {
|
|
const calls: Array<
|
|
Readonly<{
|
|
contract: unknown;
|
|
input: unknown;
|
|
context: unknown;
|
|
}>
|
|
> = [];
|
|
const implementation = async (
|
|
contract: unknown,
|
|
input: unknown,
|
|
context: unknown,
|
|
) => {
|
|
calls.push(Object.freeze({ contract, input, context }));
|
|
return outcome;
|
|
};
|
|
const execute = vi.fn(implementation) as unknown as
|
|
InstalledHttpOperationExecutor["execute"];
|
|
return {
|
|
executor: Object.freeze({ execute }) satisfies InstalledHttpOperationExecutor,
|
|
calls,
|
|
execute,
|
|
};
|
|
}
|
|
|
|
describe("feature HTTP binding", () => {
|
|
it("keeps contract-derived input while platform owns route/context execution", async () => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "SUCCESS" as const,
|
|
value: Object.freeze({ id: "resource-1", title: "Reference" }),
|
|
metadata: Object.freeze({ status: 200 }),
|
|
effect: "NOT_APPLICABLE" as const,
|
|
}),
|
|
);
|
|
const binding = createFeatureHttpBinding(scripted.executor, OPERATIONS);
|
|
|
|
const result = await binding.execute("LOAD_RESOURCE", {
|
|
resourceId: "resource-1",
|
|
});
|
|
|
|
expect(result).toEqual({
|
|
ok: true,
|
|
value: { id: "resource-1", title: "Reference" },
|
|
});
|
|
expect(scripted.calls).toEqual([
|
|
{
|
|
contract: LOAD_RESOURCE_CONTRACT,
|
|
input: { resourceId: "resource-1" },
|
|
context: { routeId: "RESOURCE_DETAIL" },
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("normalizes transport failure before it crosses the feature gateway", async () => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "TRANSPORT_FAILURE" as const,
|
|
failure: Object.freeze({
|
|
kind: "TIMEOUT" as const,
|
|
retryable: true,
|
|
}),
|
|
effect: "NOT_STARTED" as const,
|
|
}),
|
|
);
|
|
const binding = createFeatureHttpBinding(scripted.executor, OPERATIONS);
|
|
|
|
const result = await binding.execute("LOAD_RESOURCE", {
|
|
resourceId: "resource-1",
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error.kind).toBe("REQUEST_TIMEOUT");
|
|
expect(result.error.operationId).toBe("LOAD_RESOURCE");
|
|
expect(result.error.effect).toBe("NOT_STARTED");
|
|
});
|
|
|
|
it("turns a domain mapper rejection into the shared mapping failure", async () => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "SUCCESS" as const,
|
|
value: Object.freeze({ id: "resource-1", title: "" }),
|
|
metadata: Object.freeze({ status: 200 }),
|
|
effect: "NOT_APPLICABLE" as const,
|
|
}),
|
|
);
|
|
const binding = createFeatureHttpBinding(scripted.executor, OPERATIONS);
|
|
|
|
const result = await binding.execute("LOAD_RESOURCE", {
|
|
resourceId: "resource-1",
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error.kind).toBe("MAPPING_CONTRACT_VIOLATION");
|
|
expect(result.error.code).toBe("MAPPING_INVARIANT_REJECTED");
|
|
});
|
|
|
|
/**
|
|
* 03-02. A request refused before dispatch is never a server answer. Only an
|
|
* input the user can change is "input rejected"; a wiring defect in this
|
|
* client (contract not installed, path template and projection disagree,
|
|
* mutation intent disagrees with the contract) is a client failure.
|
|
*/
|
|
it.each([
|
|
["FINAL_REQUEST_INVARIANT_FAILED", undefined, "VALIDATION_REJECTED"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "INPUT_INVALID", "VALIDATION_REJECTED"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "PATH_VALUE_INVALID", "VALIDATION_REJECTED"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "QUERY_TOO_LARGE", "VALIDATION_REJECTED"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "URL_TOO_LARGE", "VALIDATION_REJECTED"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "REQUEST_BODY_TOO_LARGE", "VALIDATION_REJECTED"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "PATH_PLACEHOLDER_MISSING", "UNKNOWN_CLIENT_FAILURE"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "CONTRACT_NOT_INSTALLED", "UNKNOWN_CLIENT_FAILURE"],
|
|
["FINAL_REQUEST_INVARIANT_FAILED", "HEADER_NOT_ALLOWED", "UNKNOWN_CLIENT_FAILURE"],
|
|
["MISSING_IDEMPOTENCY_KEY", undefined, "UNKNOWN_CLIENT_FAILURE"],
|
|
["UNEXPECTED_IDEMPOTENCY_KEY", undefined, "UNKNOWN_CLIENT_FAILURE"],
|
|
] as const)(
|
|
"reports the request-side violation %s (%s) as %s, never as a server answer",
|
|
async (violationKind, reason, expectedKind) => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "CONTRACT_VIOLATION" as const,
|
|
violation: Object.freeze({
|
|
kind: violationKind,
|
|
operation: "REQUEST" as const,
|
|
...(reason === undefined ? {} : { reason }),
|
|
}),
|
|
effect: "NOT_APPLICABLE" as const,
|
|
}),
|
|
);
|
|
const binding = createFeatureHttpBinding(scripted.executor, OPERATIONS);
|
|
|
|
const result = await binding.execute("LOAD_RESOURCE", {
|
|
resourceId: "resource-1",
|
|
});
|
|
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: { kind: expectedKind, code: violationKind },
|
|
});
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
[
|
|
"mapSuccess",
|
|
Object.freeze({
|
|
kind: "SUCCESS" as const,
|
|
value: Object.freeze({ id: "resource-1", title: "Reference" }),
|
|
metadata: Object.freeze({ status: 201 }),
|
|
effect: "APPLIED_CONFIRMED" as const,
|
|
}),
|
|
],
|
|
[
|
|
"mapProblem",
|
|
Object.freeze({
|
|
kind: "PROBLEM" as const,
|
|
problem: Object.freeze({ code: "RESOURCE_NAME_EXISTS" }),
|
|
metadata: Object.freeze({ status: 409 }),
|
|
effect: "APPLIED_CONFIRMED" as const,
|
|
}),
|
|
],
|
|
])(
|
|
"returns a mapping failure with the server effect when %s throws",
|
|
async (_mapper, outcome) => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(outcome);
|
|
const binding = createFeatureHttpBinding(scripted.executor, {
|
|
LOAD_RESOURCE: defineFeatureHttpOperation({
|
|
contract: LOAD_RESOURCE_CONTRACT,
|
|
routeId: "RESOURCE_DETAIL",
|
|
mapSuccess(): never {
|
|
throw new TypeError("mapper defect");
|
|
},
|
|
mapProblem(): never {
|
|
throw new TypeError("mapper defect");
|
|
},
|
|
}),
|
|
} as const);
|
|
|
|
const result = await binding.execute("LOAD_RESOURCE", {
|
|
resourceId: "resource-1",
|
|
});
|
|
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
kind: "MAPPING_CONTRACT_VIOLATION",
|
|
code: "MAPPING_CONTRACT_VIOLATION",
|
|
effect: "APPLIED_CONFIRMED",
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it("lets the feature interpret a typed business problem", async () => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "PROBLEM" as const,
|
|
problem: Object.freeze({ code: "RESOURCE_NAME_EXISTS" }),
|
|
metadata: Object.freeze({ status: 409 }),
|
|
effect: "NOT_APPLIED" as const,
|
|
}),
|
|
);
|
|
const binding = createFeatureHttpBinding(scripted.executor, OPERATIONS);
|
|
|
|
const result = await binding.execute("LOAD_RESOURCE", {
|
|
resourceId: "resource-1",
|
|
});
|
|
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
kind: "CONFLICT",
|
|
code: "RESOURCE_NAME_EXISTS",
|
|
httpStatus: 409,
|
|
},
|
|
});
|
|
});
|
|
|
|
// 1112/01-06. An Envelope operation's failure keeps the backend's own code
|
|
// next to the one the feature mapped, so the resend decision reads the
|
|
// answer the backend gave.
|
|
it("keeps the backend's Envelope code when the feature maps it to another", async () => {
|
|
const enveloped = Object.freeze({
|
|
LOAD_RESOURCE: defineFeatureHttpOperation({
|
|
contract: Object.freeze({
|
|
...LOAD_RESOURCE_CONTRACT,
|
|
contract: Object.freeze({
|
|
...LOAD_RESOURCE_CONTRACT.contract,
|
|
responseEnvelope: "ENVELOPE_V1" as const,
|
|
}),
|
|
}),
|
|
routeId: "RESOURCE_DETAIL",
|
|
mapSuccess: (value: ResourceWire) => mappingSuccess(value),
|
|
mapProblem: () => Object.freeze({ kind: "VALIDATION_REJECTED" as const, code: "VALIDATION_FAILED" }),
|
|
}),
|
|
} as const);
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "PROBLEM" as const,
|
|
problem: Object.freeze({ code: "WORKLOG_INVALID" }),
|
|
metadata: Object.freeze({ status: 400 }),
|
|
effect: "NOT_APPLIED" as const,
|
|
}),
|
|
);
|
|
|
|
const result = await createFeatureHttpBinding(scripted.executor, enveloped).execute(
|
|
"LOAD_RESOURCE",
|
|
{ resourceId: "resource-1" },
|
|
);
|
|
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: { code: "VALIDATION_FAILED", backendCode: "WORKLOG_INVALID" },
|
|
});
|
|
});
|
|
|
|
it("gives no backend code to an operation without an Envelope", async () => {
|
|
const scripted = scriptedExecutor<ResourceWire, ResourceProblem>(
|
|
Object.freeze({
|
|
kind: "PROBLEM" as const,
|
|
problem: Object.freeze({ code: "RESOURCE_NAME_EXISTS" }),
|
|
metadata: Object.freeze({ status: 409 }),
|
|
effect: "NOT_APPLIED" as const,
|
|
}),
|
|
);
|
|
|
|
const result = await createFeatureHttpBinding(scripted.executor, OPERATIONS).execute(
|
|
"LOAD_RESOURCE",
|
|
{ resourceId: "resource-1" },
|
|
);
|
|
|
|
expect(result.ok).toBe(false);
|
|
expect(result.ok ? undefined : result.error.backendCode).toBeUndefined();
|
|
});
|
|
});
|