Files
tech-log-frontend/tests/features/tech-log/studio-contract-contribution.test.ts
DongHyeonkaandClaude Opus 5 22090a497d fix: 페이지 번호를 눌러도 쪽이 넘어가지 않던 것을 고치고 UI 를 정리한다
요청을 만드는 조립기가 질의 인자를 손으로 나열하는데 거기 page 가 없었다.
그래서 숫자를 눌러도, 꺾쇠를 눌러도 서버에는 page 없이 나갔고 늘 1쪽이
돌아왔다. 작업본과 게시 기록 둘 다 그랬다.

이것이 타입 검사를 통과한 이유: 조립기가 입력을 `(input: never)` 로 받아
캐스팅한다. 계약에 인자를 더해도 여기 적지 않으면 컴파일러는 아무 말도
하지 않고 요청만 조용히 그 값을 뺀다. 같은 모양으로 값이 사라지는 결함을
이 저장소에서 여러 번 만났으므로, 요청을 실제로 만들어 page 가 실리는지
확인하는 가드를 함께 둔다 — 되돌리면 깨지는 것을 확인했다.

UI: 테두리 있는 흰 버튼을 줄지어 놓으니 화면에서 가장 눈에 띄는 덩어리가
되었다. 봐야 할 것은 목록이다. 상자를 걷어내고 `‹ 1 | 2 | 3 ›` 로 두되
누르는 자리는 40px 로 남긴다 — 보이는 반응은 글자뿐이지만 손가락이 닿는
범위까지 글자만큼 줄이면 터치에서 누르기 어렵다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ
2026-08-30 09:33:09 +09:00

132 lines
5.5 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "vitest";
import canonicalSource from "../../../src/features/tech-log/contracts/studio/canonical-source.json" with { type: "json" };
import {
TECH_LOG_STUDIO_CONTRIBUTION,
TECH_LOG_STUDIO_OPERATION_IDS,
} from "../../../src/features/tech-log/contracts/tech-log-studio-contract-contribution.ts";
import { composeContractContributions } from "../../../src/contracts/external-contract-runtime.ts";
import {
assertExactlyOneTechLogStudioBootstrapOperation,
TECH_LOG_STUDIO_BOOTSTRAP_AUTH_PROFILE_ID,
} from "../../../src/features/tech-log/adapters/http/studio-session-credentials.ts";
const UPLOAD = "uploadStudioAsset";
test("declares every canonical operation except the multipart upload", () => {
const expected = canonicalSource.operationIds.filter((id) => id !== UPLOAD);
assert.equal(expected.length, 18);
assert.deepEqual(
[...TECH_LOG_STUDIO_OPERATION_IDS].sort(),
[...expected].sort(),
);
});
test("pins the canonical digest and revision as external package provenance", () => {
const source = TECH_LOG_STUDIO_CONTRIBUTION.source;
assert.equal(source.kind, "EXTERNAL_PACKAGE");
if (source.kind !== "EXTERNAL_PACKAGE") return;
assert.equal(source.package.packageId, canonicalSource.packageId);
assert.equal(source.package.version, canonicalSource.version);
assert.equal(source.package.digest, canonicalSource.digest);
assert.equal(source.package.sourceRevision, canonicalSource.sourceRevision);
assert.equal(source.package.runtimeProtocolVersion, 1);
});
test("composes without violating the platform contract runtime", () => {
const composed = composeContractContributions([TECH_LOG_STUDIO_CONTRIBUTION]);
assert.equal(composed.externalPackages.length, 1);
});
test("every mutating operation replays by idempotency key and never auto-retries", () => {
for (const entry of TECH_LOG_STUDIO_CONTRIBUTION.http) {
if (entry.contract.retrySemantics !== "KEYED") continue;
assert.deepEqual(
entry.contract.commandRecovery,
{
mode: "IDEMPOTENCY_REPLAY",
operationIdentityField: "idempotencyKey",
},
`${entry.contract.operationId} recovery`,
);
assert.equal(
entry.frontend.retryBudget,
0,
`${entry.contract.operationId} budget`,
);
}
});
test("path templates match the canonical /api/v1/studio prefix", () => {
for (const entry of TECH_LOG_STUDIO_CONTRIBUTION.http) {
assert.ok(
entry.contract.pathTemplate.startsWith("/api/v1/studio/"),
`${entry.contract.operationId}: ${entry.contract.pathTemplate}`,
);
}
});
// Fix round 2, item 3. `getStudioSession` must be the sole operation on the
// credential-free bootstrap profile — anything else either reopens the C1
// cycle (zero operations) or lets a mutating operation dispatch with no CSRF
// header at all (a second operation on the bootstrap profile).
test("getStudioSession is the sole operation on the bootstrap auth profile", () => {
const bootstrapOperations = TECH_LOG_STUDIO_CONTRIBUTION.http.filter(
(entry) => entry.frontend.authProfileId === TECH_LOG_STUDIO_BOOTSTRAP_AUTH_PROFILE_ID,
);
assert.deepEqual(
bootstrapOperations.map((entry) => entry.contract.operationId),
["getStudioSession"],
);
});
test("assertExactlyOneTechLogStudioBootstrapOperation rejects zero or multiple bootstrap operations", () => {
assert.throws(
() => assertExactlyOneTechLogStudioBootstrapOperation([
{ operationId: "getStudioDashboard", authProfileId: "TECH_LOG_STUDIO_SESSION" },
]),
/must be used by exactly one operation/,
);
assert.throws(
() => assertExactlyOneTechLogStudioBootstrapOperation([
{ operationId: "getStudioSession", authProfileId: TECH_LOG_STUDIO_BOOTSTRAP_AUTH_PROFILE_ID },
{ operationId: "deleteStudioAsset", authProfileId: TECH_LOG_STUDIO_BOOTSTRAP_AUTH_PROFILE_ID },
]),
/must be used by exactly one operation/,
);
assert.doesNotThrow(() =>
assertExactlyOneTechLogStudioBootstrapOperation([
{ operationId: "getStudioSession", authProfileId: TECH_LOG_STUDIO_BOOTSTRAP_AUTH_PROFILE_ID },
{ operationId: "getStudioDashboard", authProfileId: "TECH_LOG_STUDIO_SESSION" },
]),
);
});
/**
* 목록 화면의 페이지 이동은 `page` 질의 인자 하나에 걸려 있다. 그런데 이 파일의 질의 조립기는
* 필드를 손으로 나열하고 입력을 `never` 로 받아 캐스팅하므로, 계약에 인자를 더해도 여기에
* 적지 않으면 타입 검사도 통과하고 요청만 조용히 그 값을 뺀 채 나간다.
*
* <p>실제로 그렇게 나갔다: `‹ 1 2 3 ›` 의 숫자를 눌러도 서버는 늘 1쪽을 돌려줬다. 화면·게이트웨이·
* 백엔드가 모두 맞았고 틀린 곳은 이 목록 하나였다.
*/
test("목록 연산은 page 를 질의 인자로 실어 보낸다", () => {
const byId = new Map(
TECH_LOG_STUDIO_CONTRIBUTION.http.map((entry) => [entry.contract.operationId, entry]),
);
for (const operationId of ["listStudioDocuments", "listStudioPublications"]) {
const installed = byId.get(operationId);
assert.ok(installed, `${operationId} 가 기여 목록에 있어야 한다`);
const projected = installed.contract.projectRequest({ page: 3, limit: 20 } as never);
const entries = new Map(projected.queryEntries.map(([k, v]) => [k, v]));
assert.equal(
entries.get("page"),
"3",
`${operationId} 가 page 를 실어야 2쪽에서 1쪽으로 돌아올 수 있다`,
);
assert.equal(entries.get("limit"), "20");
}
});