TypeScript
/**
* UX (표현) 검증 지표 — PRD §19.
* UX1 산점도 · UX2 매트릭스 · UX3 흐름그래프 · UX4 노드 토글(스킬·로그) ·
* UX5 i18n EN↔KR(한국어 누수 0) · UX6 self-contained(외부 JS/CDN/script 0)
*/
import { existsSync, mkdtempSync, readFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { beforeAll, describe, expect, it } from "vitest";
import { normalizeLang, tr } from "../src/i18n";
import type { Lang, RunOptions } from "../src/models";
import { execute } from "../src/orchestrator";
function baseOpts(out: string, language: Lang): RunOptions {
return {
models: ["opus4.8", "gpt5.5"],
agents: ["cc", "codex"],
harnesses: ["none", "omc"],
bench: "subagent",
tasks: 4,
runs: 1,
seed: 7,
runner: "mock",
concurrency: 4,
timeoutS: 5,
outDir: out,
judge: "none",
score: true,
balanced: false,
language,
};
}
let enHtml = "";
let krHtml = "";
let graphHtml = "";
beforeAll(async () => {
const out = mkdtempSync(join(tmpdir(), "theseus-run-"));
const en = await execute(baseOpts(out, "en"));
enHtml = readFileSync(en.reportPath, "utf8");
graphHtml = readFileSync(en.graphPath, "utf8");
const kr = await execute(baseOpts(out, "kr"));
krHtml = readFileSync(kr.reportPath, "utf8");
});
describe("UX1 scatter present", () => {
it("report contains a cost-performance scatter SVG", () => {
expect(enHtml).toMatch(/Cost-performance scatter/);
expect(enHtml).toContain("<svg");
});
});
describe("UX2 task matrix present", () => {
it("report contains the pass/fail matrix", () => {
expect(enHtml).toMatch(/Task pass\/fail matrix/);
expect(enHtml).toContain('class="matrix"');
});
});
describe("UX3 flow graph present", () => {
it("report and graph.html contain inline flow SVGs", () => {
expect(enHtml).toMatch(/Subagent flow graphs/);
expect(graphHtml).toContain("<svg");
expect(graphHtml).toMatch(/MAIN LOOP/);
});
});
describe("UX4 node toggle (skills/log)", () => {
it("native details toggles exist with no external JS", () => {
expect(graphHtml).toContain("<details");
expect(graphHtml).toMatch(/Skills|Tools|Log/);
});
});
describe("UX5 i18n EN↔KR switch (no korean leak in EN)", () => {
it("EN report has english headers and no Korean section titles", () => {
expect(enHtml).toMatch(/Accuracy/);
expect(enHtml).toMatch(/Efficiency/);
expect(enHtml).not.toMatch(/정확도|효율|관점별 최적/);
});
it("KR report has Korean headers", () => {
expect(krHtml).toMatch(/정확도/);
expect(krHtml).toMatch(/효율/);
});
it("normalizeLang + tr behave", () => {
expect(normalizeLang("english")).toBe("en");
expect(normalizeLang("한국어")).toBe("kr");
expect(normalizeLang("zzz")).toBe("kr");
expect(tr("en", "sec_accuracy")).toMatch(/Accuracy/);
expect(tr("kr", "sec_accuracy")).toMatch(/정확도/);
});
});
describe("UX6 self-contained HTML", () => {
it("no <script>, no CDN, no external src/link", () => {
for (const html of [enHtml, krHtml, graphHtml]) {
expect(html).not.toMatch(/<script/i);
expect(html).not.toMatch(/cdn|googleapis|unpkg|jsdelivr/i);
expect(html).not.toMatch(/src=/i);
expect(html).not.toMatch(/<link/i);
// 유일하게 허용되는 http 참조는 SVG 네임스페이스
const urls = html.match(/https?:\/\/[^"'\s]*/g) ?? [];
expect(urls.every((u) => u === "http://www.w3.org/2000/svg")).toBe(true);
}
});
});