Files
tech-log-frontend/tests/features/tech-log/runtime-composition.test.ts
T
DongHyeonka 11c2713139 feat: let Studio create the topics and projects publishing requires
Publishing needs a topic and nothing could create one. The backend now owns
that surface; this is its consumer — the management contract vendored, a
gateway over its nine operations, and one Studio screen that lists, creates,
and deletes topics and projects.

The screen adds no CSS. It reuses the classes the working-copy list already
uses, so it inherits Studio's spacing, type, and colour rather than growing a
second visual vocabulary beside them. Scope stops at list/create/delete:
renaming, phase changes, and visibility are implemented in the backend and
declared in the contract, but their screens are a separate design.

Two real defects surfaced while making the public port async, and both would
have shipped:

The search page and the header search dialog shared a query key. With an empty
query, `["tech-log","search",""]` was identical for both, so react-query
handed one surface the other's cache — different shapes — and the page died
reading a field that was not there. Keys now name the surface.

The explore filter's selects are uncontrolled and read `defaultValue`, which
React applies once. Their options arrive later now, so the first render had
nothing to match and the value stayed empty: a topic in the URL no longer
showed as selected. The form key includes whether the catalog has arrived, so
it remounts with the options present. Controlled inputs would be the other
answer, but this form submits to build a URL — the URL owns the value.

The route brought its own bookkeeping: a build chunk, a manual accessibility
evidence file, and the CI artifact baseline that counts them. The gate pins a
digest of its own shape precisely so a new route cannot slip in without that
count being reviewed.

Test harnesses that render public screens now assemble the query providers and
await the settled paint, because the screens they render became async.
2026-08-20 23:40:15 +09:00

132 lines
4.7 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "vitest";
import type { ApplicationFeatureInputs } from "../../../src/application/ports/in/application-api.ts";
import { createInstalledFeatureInputs } from "../../../src/features/installed-feature-adapters.ts";
import { FIXTURE_IDS } from "../../../src/features/tech-log/adapters/mock/fixtures.ts";
import { createCsrfTokenProvider } from "../../../src/features/tech-log/adapters/http/studio-session-csrf.ts";
import type { TechLogFeatureInput } from "../../../src/features/tech-log/application/tech-log-feature-input.ts";
import type { WorkingCopy } from "../../../src/features/tech-log/contracts/studio/contract.ts";
type Equal<Left, Right> =
(<Value>() => Value extends Left ? 1 : 2) extends <Value>() =>
Value extends Right ? 1 : 2
? true
: false;
type Expect<Value extends true> = Value;
type InstalledInputs = ReturnType<typeof createInstalledFeatureInputs>;
type _InstalledIdsAreExact = Expect<
Equal<keyof InstalledInputs, "reference-feature" | "tech-log">
>;
type _TechLogRegistryValueIsExact = Expect<
Equal<ApplicationFeatureInputs["tech-log"], TechLogFeatureInput>
>;
void (0 as unknown as _InstalledIdsAreExact);
void (0 as unknown as _TechLogRegistryValueIsExact);
function inputOf(document: WorkingCopy) {
const { id, version, updatedAt, ...input } = document;
void id;
void version;
void updatedAt;
return input;
}
function installedInputs(
studioSource: "MOCK" | "HTTP" = "MOCK",
publicSource: "MOCK" | "HTTP" = "MOCK",
): InstalledInputs {
return createInstalledFeatureInputs({
studioSource,
publicSource,
contractOperations: {
async execute() {
throw new Error("reference executor is not used by composition tests");
},
},
apiBaseUrl: "http://composition.test/",
requestTimeoutMs: 10_000,
csrf: createCsrfTokenProvider({
async execute() {
throw new Error("CSRF provider is not used by composition tests");
},
}),
});
}
test("installs TechLog beside the retained reference feature through application-facing inputs", async () => {
const installed = installedInputs();
assert.deepEqual(Object.keys(installed), ["reference-feature", "tech-log"]);
assert.deepEqual(Object.keys(installed["tech-log"]).sort(), [
"createManagementGateway",
"createStudioAssetGateway",
"createStudioGateway",
"publicContent",
]);
assert.equal(Object.isFrozen(installed), true);
assert.equal(Object.isFrozen(installed["tech-log"]), true);
assert.equal(Object.isFrozen(installed["tech-log"].publicContent), true);
assert.equal(
(await installed["tech-log"].publicContent.getRelease("0.1.0"))?.title,
"TechLog Public·Studio 경계를 확정했습니다",
);
});
test("selects the mock gateway by default and the HTTP gateway when switched", async () => {
const mockGateway = installedInputs("MOCK")["tech-log"].createStudioGateway();
const httpGateway = installedInputs("HTTP")["tech-log"].createStudioGateway();
// The mock reads an in-memory fixture immediately. HTTP defers to the
// (here, throwing) contract executor, so it rejects instead.
await assert.doesNotReject(mockGateway.getDashboard());
await assert.rejects(httpGateway.getDashboard());
});
test("each createStudioGateway call owns an isolated mutable Studio session", async () => {
const installed = installedInputs();
const first = installed["tech-log"].createStudioGateway();
const second = installed["tech-log"].createStudioGateway();
assert.notEqual(first, second);
const firstBefore = await first.getDocument(FIXTURE_IDS.fetchJoinCase);
const secondBefore = await second.getDocument(FIXTURE_IDS.fetchJoinCase);
assert.equal(firstBefore.document.title, secondBefore.document.title);
const saved = await first.saveDocument(
firstBefore.document.id,
{
expectedVersion: firstBefore.document.version,
document: {
...inputOf(firstBefore.document),
title: "첫 번째 세션에서만 수정",
},
},
{ idempotencyKey: "session-isolation" },
);
assert.equal(saved.document.title, "첫 번째 세션에서만 수정");
assert.equal(
(await second.getDocument(FIXTURE_IDS.fetchJoinCase)).document.title,
secondBefore.document.title,
);
assert.equal(
(
await installed["tech-log"].publicContent.getRecord(
"CASE",
"collection-fetch-join-pagination",
)
)?.title,
"컬렉션 Fetch Join과 페이징은 왜 충돌하는가",
);
});
test("each Studio session gets its own asset gateway instance", () => {
const installed = installedInputs("HTTP");
assert.notEqual(
installed["tech-log"].createStudioAssetGateway(),
installed["tech-log"].createStudioAssetGateway(),
);
});