Files
tech-log-frontend/tests/runtime-schema/http-schema.test.ts
T
DongHyeonkaandClaude Opus 5 66c047cec8 feat: register the TechLog Studio contract contribution
Registers the TECH_LOG_STUDIO_SESSION SAME_ORIGIN_COOKIE auth profile and
declares the tech-log-studio-http-v1 contribution covering all 18 JSON
Studio operations (everything except the multipart uploadStudioAsset),
built from two shared builders (safeOperation/keyedOperation) so every
KEYED command gets IDEMPOTENCY_REPLAY recovery and a zero retry budget,
and every SAFE read gets a plain retry budget, without repeating the
declaration shape 18 times.

Rescopes the canonical package identity from "tech-log-studio-contract"
to "@tech-log/studio-contract" (generator, canonical-source.json,
contract-generation.test.ts) because the platform's contribution
composer requires an npm-scoped packageId; the unscoped form failed
composition. Updates the release-manifest test fixture, which hardcoded
an empty expected contract set, to derive its expected packages from the
real installed set now that TechLog is always installed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 01:10:04 +09:00

89 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
validateEnvelope,
validateOperationPayload,
validateOperationRequest,
} from "../../src/adapters/http/schema-registry.ts";
import {
composeRuntimeSchemaCodecs,
validateWithRuntimeSchemaRegistry,
} from "../../src/contracts/schema-registry.ts";
import { INSTALLED_REST_AUTH_PROFILES } from "../../src/contracts/rest-profiles.ts";
describe("HTTP platform schema boundary", () => {
it("rejects an invalid top-level envelope", () => {
expect(validateEnvelope({ success: true }).success).toBe(false);
});
it("accepts and clones a generic valid response envelope", () => {
const source = {
success: true,
data: [],
meta: { requestId: "request-1", traceId: "trace-1" },
};
const result = validateEnvelope(source);
expect(result).toMatchObject({ success: true, data: source });
if (!result.success) throw new Error("expected valid envelope");
expect(result.data).not.toBe(source);
});
it("fails closed without leaking input when a feature schema is absent", () => {
const result = validateOperationPayload("UnknownPayload", {
secret: "not-projected",
});
expect(result).toMatchObject({
success: false,
issues: [{ path: "", code: "SCHEMA_NOT_REGISTERED" }],
});
expect(JSON.stringify(result)).not.toContain("not-projected");
expect(
validateOperationRequest("UnknownCommand", { name: "Example" }).success,
).toBe(false);
});
});
describe("runtime schema codec contribution", () => {
const codec = {
schemaId: "Example",
parse: (value: unknown) => ({ success: true as const, data: value }),
};
it("resolves installed codecs and fails missing IDs closed", () => {
const registry = composeRuntimeSchemaCodecs([{ Example: codec }]);
expect(validateWithRuntimeSchemaRegistry("Example", 42, registry)).toEqual({
success: true,
data: 42,
});
expect(
validateWithRuntimeSchemaRegistry("Missing", 42, registry),
).toMatchObject({
success: false,
issues: [{ code: "SCHEMA_NOT_REGISTERED" }],
});
});
it("rejects duplicate codec contributions", () => {
expect(() =>
composeRuntimeSchemaCodecs([{ Example: codec }, { Example: codec }]),
).toThrow("duplicate runtime schema codec");
});
});
describe("REST auth profile registry", () => {
it("installs the TechLog Studio session auth profile", () => {
const profile = INSTALLED_REST_AUTH_PROFILES.get(
"TECH_LOG_STUDIO_SESSION",
);
expect(profile).toBeTruthy();
expect(profile?.transport).toBe("SAME_ORIGIN_COOKIE");
expect(profile?.credentials).toBe("include");
expect([...(profile?.requiredCredentialHeaders ?? [])]).toEqual([
"x-csrf-token",
]);
expect([...(profile?.allowedCredentialHeaders ?? [])]).toEqual([
"x-csrf-token",
]);
});
});