import assert from "node:assert/strict"; import { test } from "vitest"; import { findResolvableAsset } from "../../../src/features/tech-log/domain/content-format/asset-evidence-catalog.ts"; import { createResolvedAssetResolver, MISSING_EVIDENCE_ASSET, } from "../../../src/features/tech-log/presentation/shared/public-render/asset-resolvers.ts"; /** 서버가 블록에 붙여 보내는 서술자. 화면이 그림을 그릴 때 읽는 것은 이것뿐이다. */ function figure(asset: Record) { return [{ type: "EVIDENCE_FIGURE", key: String(asset["assetKey"]), asset }] as never; } const READY = { id: "11111111-1111-4111-8111-111111111111", assetKey: "boundary", kind: "DIAGRAM", mediaType: "image/svg+xml", originalFilename: "b.svg", byteSize: 10, width: 1080, height: 420, altText: "경계", decorative: false, managementStatus: "READY", publicPath: "/media/boundary.svg", usageCount: 0, version: 1, createdAt: "2026-08-14T01:00:00.000Z", updatedAt: "2026-08-14T01:00:00.000Z", } as never; test("고를 수 있는 자료를 열쇠로 찾는다", () => { const found = findResolvableAsset([READY], "boundary"); assert.equal(found?.publicPath, "/media/boundary.svg"); assert.equal(found?.width, 1080); assert.equal(found?.height, 420); }); test("falls back to the static registry for the legacy hardcoded key", () => { const resolve = createResolvedAssetResolver([]); const asset = resolve("fetch-strategy-boundary"); assert.equal(asset.src, "/media/fetch-strategy-boundary.svg"); }); test("returns the placeholder instead of throwing on an unknown key", () => { const resolve = createResolvedAssetResolver([]); assert.deepEqual(resolve("does-not-exist"), MISSING_EVIDENCE_ASSET); }); test("격리된 자료는 고르지 않는다", () => { assert.equal( findResolvableAsset([{ ...(READY as object), managementStatus: "QUARANTINED" } as never], "boundary"), undefined, ); }); test("resolves from the server render model blocks", () => { const resolve = createResolvedAssetResolver([ { type: "EVIDENCE_FIGURE", key: "boundary", asset: { assetId: "11111111-1111-4111-8111-111111111111", assetKey: "boundary", mediaType: "image/svg+xml", publicPath: "/media/boundary.svg", width: 800, height: 300, decorative: false, }, }, ]); assert.equal(resolve("boundary").src, "/media/boundary.svg"); assert.equal(resolve("boundary").width, 800); }); test("같은 열쇠를 가진 격리 자료보다 쓸 수 있는 자료가 이긴다", () => { const found = findResolvableAsset( [{ ...(READY as object), managementStatus: "QUARANTINED" } as never, READY], "boundary", ); assert.equal(found?.publicPath, "/media/boundary.svg"); }); test("keeps the legacy key's hand-authored labels when a server block resolves it via descriptor (today's real Preview/Snapshot path)", () => { const resolve = createResolvedAssetResolver([ { type: "EVIDENCE_FIGURE", key: "fetch-strategy-boundary", asset: { assetId: "00000000-0000-4000-8000-000000000001", assetKey: "fetch-strategy-boundary", mediaType: "image/svg+xml", publicPath: "/media/fetch-strategy-boundary.svg", width: 1080, height: 420, decorative: false, }, }, ]); assert.deepEqual(resolve("fetch-strategy-boundary"), { src: "/media/fetch-strategy-boundary.svg", width: 1080, height: 420, triggerLabel: "Fetch Join과 Batch Fetch 비교 다이어그램 크게 보기", dialogLabel: "Fetch Join과 Batch Fetch의 페이징 경계 확대", }); }); test("a colliding backend descriptor's publicPath wins over the legacy src, but the legacy labels still win", () => { const resolve = createResolvedAssetResolver( figure({ assetId: "11111111-1111-4111-8111-111111111111", assetKey: "fetch-strategy-boundary", mediaType: "image/svg+xml", publicPath: "/media/should-win.svg", width: 999, height: 111, decorative: false, }), ); const asset = resolve("fetch-strategy-boundary"); assert.equal(asset.src, "/media/should-win.svg"); assert.equal(asset.width, 999); assert.equal(asset.height, 111); assert.equal(asset.triggerLabel, "Fetch Join과 Batch Fetch 비교 다이어그램 크게 보기"); assert.equal(asset.dialogLabel, "Fetch Join과 Batch Fetch의 페이징 경계 확대"); });