Files
tech-log-frontend/tests/features/reference-feature/reference-http-gateway.test.ts
DongHyeonkaandClaude Opus 5 afde2b1da1 chore: sync the frontend template from 5434760 to ebea300
Carries 21 template commits: the shared IndexedDB connection/transaction
kernel and the four runtimes moved onto it, the adapter barrel boundary and
the architecture rule that enforces it, the feature adapter contribution
model, `feature-http-binding`, the split of several oversized test files,
and the release identity now derived from the package name.

Product identity is unchanged. The three hard-coded `tech-log-frontend/…`
verifier ids are gone because the template derives them from the package
name and this package is `tech-log-frontend`.

Two decisions worth naming. The platform HTTP executor is the template's
verbatim — it now takes the installed contract so a feature's types flow
through the binding — and TechLog's four gateways, which address operations
by id, reach it through one adapter at the composition root instead of being
rewritten here. And the three derived CI baselines were recomputed from the
merged `config/ci/gates.json` rather than taken from either side: 94 command
definitions, 106 references, 141 artifacts, gate shape `629e5898…`. The
method was checked by first reproducing the pre-merge values from the
pre-merge file.

Verified here: types, lint, architecture, adapter inventory, CI contract,
design system, diagnostics, remediation ledger, browser security and build
all pass; 1789 unit, 152 component, 415 TechLog, 102 integration, 19
reference-feature, 17 recipe and 7 contract tests pass. Five gates stay
red and every one was reproduced at b297d65 first: `check:i18n`,
`check:registries`, `test:runtime-schema`, `verify:documentation` and
`test:sample-removal`.

Full decision record, including what was deliberately not carried and the
five open follow-ups, in `docs/operations/template-sync-2026-09-21.md`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 16:31:05 +09:00

106 lines
3.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { Result } from "../../../src/contracts/result.ts";
import { createFailure, type ApiFailure } from "../../../src/contracts/errors.ts";
import {
createReferenceHttpGateway,
type ReferenceHttpBinding,
} from "../../../src/features/reference-feature/adapters/reference-http-gateway.ts";
import type { ReferenceResource } from "../../../src/features/reference-feature/domain/reference-resource.ts";
const resources = Object.freeze({
first: Object.freeze({
id: "reference-1",
displayName: "First",
createdAt: null,
}),
created: Object.freeze({
id: "reference-2",
displayName: "Created",
createdAt: "2026-07-26T00:00:00.000Z",
}),
}) satisfies Readonly<Record<string, ReferenceResource>>;
type ScriptedResult = Result<
ReferenceResource | readonly ReferenceResource[],
ApiFailure
>;
function scriptedBinding(results: ScriptedResult[]) {
const calls: Array<
readonly [operationId: string, input: unknown, context: unknown]
> = [];
let index = 0;
const execute = (async (
operationId: string,
input: unknown,
context?: unknown,
) => {
calls.push([operationId, input, context]);
const result = results[index];
index += 1;
if (!result) throw new Error("Missing scripted result");
return result;
}) as ReferenceHttpBinding["execute"];
return {
binding: Object.freeze({ execute }) satisfies ReferenceHttpBinding,
calls,
};
}
describe("reference HTTP operation gateway", () => {
it("delegates exact typed feature inputs to the capability binding", async () => {
const scripted = scriptedBinding([
{ ok: true, value: [resources.first] },
{ ok: true, value: resources.created },
{ ok: true, value: resources.first },
]);
const gateway = createReferenceHttpGateway(scripted.binding);
const signal = new AbortController().signal;
await expect(
gateway.list({ cursor: "next", limit: 20, tags: ["active"] }, { signal }),
).resolves.toEqual({ ok: true, value: [resources.first] });
await expect(
gateway.create({ name: "Created", note: "safe note" }),
).resolves.toEqual({ ok: true, value: resources.created });
await expect(
gateway.get("reference-1", { signal }),
).resolves.toEqual({ ok: true, value: resources.first });
expect(scripted.calls).toEqual([
[
"LIST_REFERENCE_RESOURCES",
{ cursor: "next", limit: 20, tags: ["active"] },
{ signal },
],
[
"CREATE_REFERENCE_RESOURCE",
{ name: "Created", note: "safe note" },
undefined,
],
[
"GET_REFERENCE_RESOURCE",
{ resourceId: "reference-1" },
{ signal },
],
]);
});
it("preserves a capability-normalized failure across the feature gateway", async () => {
const failure = createFailure(
"SCHEMA_MISMATCH",
"GET_REFERENCE_RESOURCE",
0,
);
const scripted = scriptedBinding([{ ok: false, error: failure }]);
const gateway = createReferenceHttpGateway(scripted.binding);
await expect(gateway.get("invalid")).resolves.toEqual({
ok: false,
error: failure,
});
});
});