merge: integrate WP4-07 Green baseline for TASK-WP7-01
# Conflicts: # package.json
This commit is contained in:
@@ -76,7 +76,7 @@ async function routeEditor(page: Page, projectId: string, backend: Backend) {
|
||||
backend.recent = [item, ...backend.recent.filter((entry) => entry.asset_id !== item.asset_id)];
|
||||
await route.fulfill({ body: JSON.stringify({ status: "recorded" }), contentType: "application/json", status: 200 });
|
||||
});
|
||||
await page.route("**/api/v1/assets/public/wp4-fixture-v1/*", (route) => route.fulfill({ body: fontBytes, contentType: "font/ttf", status: 200 }));
|
||||
await page.route("**/api/v1/assets/public/p0a-complex-v1/*", (route) => route.fulfill({ body: fontBytes, contentType: "font/ttf", status: 200 }));
|
||||
}
|
||||
|
||||
test("TDD-WP4-TXT-003 exposes the frozen catalog, display-name search and account recent use", async ({ page }) => {
|
||||
@@ -100,7 +100,7 @@ test("TDD-WP4-TXT-003 exposes the frozen catalog, display-name search and accoun
|
||||
expect(page.getByText("添加普通文字", { exact: true })).toHaveCount(0);
|
||||
await page.getByRole("button", { name: /FLOWER001 春日计划/ }).click();
|
||||
await expect(page.getByText("对象 1 / 50")).toBeVisible();
|
||||
await expect.poll(() => backend.recent).toEqual([{ asset_id: "FLOWER001", asset_kind: "text_template", resource_version: "wp4-fixture-v1" }]);
|
||||
await expect.poll(() => backend.recent).toEqual([{ asset_id: "FLOWER001", asset_kind: "text_template", resource_version: "p0a-complex-v1" }]);
|
||||
await page.reload();
|
||||
await page.getByRole("button", { name: "文字模板", exact: true }).click();
|
||||
await expect(page.getByLabel("最近使用文字模板").getByText("FLOWER001", { exact: true })).toBeVisible();
|
||||
@@ -158,7 +158,14 @@ test("TDD-WP4-TXT-001 preserves multiline content and transforms across a templa
|
||||
expect(pixelEvidence.line_one_ink_pixels).toBeGreaterThan(100);
|
||||
expect(pixelEvidence.line_two_ink_pixels).toBeGreaterThan(100);
|
||||
await page.reload();
|
||||
await page.getByLabel("编辑画布").click({ position: { x: 270, y: 360 } });
|
||||
const reopenedStage = page.getByLabel("编辑画布");
|
||||
const reopenedBounds = await reopenedStage.boundingBox();
|
||||
const reopenedText = backend.canvas.elements[0];
|
||||
if (!reopenedBounds || !reopenedText) throw new Error("Reopened text geometry is unavailable.");
|
||||
await reopenedStage.click({ position: {
|
||||
x: reopenedBounds.width * reopenedText.position.x,
|
||||
y: reopenedBounds.height * reopenedText.position.y,
|
||||
} });
|
||||
await expect(page.getByLabel("文字内容")).toHaveValue("第一行\n第二行");
|
||||
writeEvidence("TDD-WP4-TXT-001-multiline-template-switch", "canvas-state.json", backend.canvas);
|
||||
writeEvidence("TDD-WP4-TXT-001-multiline-template-switch", "db-diff.json", { content: backend.canvas.elements[0]?.content, saves: backend.saves, template: backend.canvas.elements[0]?.template_or_asset_id });
|
||||
|
||||
@@ -99,10 +99,9 @@ async function routeEditor(page: Page, projectId: string, backend: Backend) {
|
||||
return route.fulfill({ body: rawSvg(colors), contentType: "image/svg+xml", status: 200 });
|
||||
});
|
||||
await page.route("**/api/v1/assets/recent?asset_kind=text_template", (route) => route.fulfill({ body: JSON.stringify({ items: [] }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/public/wp4-fixture-v1/FONT081", (route) => route.fulfill({ body: readFileSync(font081Path), contentType: "font/ttf", status: 200 }));
|
||||
await page.route("**/api/v1/assets/public/wp4-dynamic-source-v1/*", (route) => {
|
||||
await page.route("**/api/v1/assets/public/p0a-complex-v1/*", (route) => {
|
||||
const assetId = decodeURIComponent(route.request().url().split("/").at(-1)!);
|
||||
const asset = dynamicSourceAssets[assetId];
|
||||
const asset = assetId === "FONT081" ? { contentType: "font/ttf", path: font081Path } : dynamicSourceAssets[assetId];
|
||||
if (!asset) return route.fulfill({ status: 404 });
|
||||
return route.fulfill({ body: readFileSync(asset.path), contentType: asset.contentType, status: 200 });
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ async function routeEditor(page: Page, projectId: string, backend: Backend, opti
|
||||
}));
|
||||
await page.route("**/api/v1/assets/recent?asset_kind=text_template", (route) => route.fulfill({ body: JSON.stringify({ items: [] }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/recent", (route) => route.fulfill({ body: JSON.stringify({ status: "recorded" }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/public/wp4-fixture-v1/*", (route) => route.fulfill({ body: readFileSync(windowsFont), contentType: "font/ttf" }));
|
||||
await page.route("**/api/v1/assets/public/p0a-complex-v1/*", (route) => route.fulfill({ body: readFileSync(windowsFont), contentType: "font/ttf" }));
|
||||
}
|
||||
|
||||
test("TDD-WP4-EXP-001 cancel keeps a pending text edit outside history and export", async ({ page }) => {
|
||||
|
||||
@@ -0,0 +1,390 @@
|
||||
import { expect, test, type Page, type TestInfo } from "@playwright/test";
|
||||
import { createServer, type ViteDevServer } from "vite";
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
// The fixture is plain ESM so the same immutable contract is consumed by Node and Playwright.
|
||||
// @ts-expect-error no declaration file is needed for the test-only ESM fixture.
|
||||
import {
|
||||
WP4_07_PERFORMANCE_BUDGETS,
|
||||
WP4_07_REAL_RESOURCE_VERSIONS,
|
||||
WP4_07_RED_RESOURCE_VERSION,
|
||||
WP4_07_REQUIRED_FONT_IDS,
|
||||
assertWp407Fixture,
|
||||
createWp407CanvasFixture,
|
||||
wp407FixtureSha256,
|
||||
} from "../visual-performance/wp4-07-fixture.mjs";
|
||||
// @ts-expect-error no declaration file is needed for the Node-only archive loader.
|
||||
import { loadWp407RealAssets } from "../visual-performance/wp4-07-real-assets.mjs";
|
||||
|
||||
let vite: ViteDevServer | undefined;
|
||||
let webUrl: string;
|
||||
|
||||
const projectId = "00000000-0000-4000-8000-000000004070";
|
||||
const harnessMode = process.env.DADA_WP4_07_HARNESS_MODE;
|
||||
if (!new Set(["red_contract", "real_archive"]).has(harnessMode ?? "")) throw new Error("WP4_07_HARNESS_MODE_REQUIRED");
|
||||
const greenEligible = harnessMode === "real_archive";
|
||||
const fixtureVersions = greenEligible ? WP4_07_REAL_RESOURCE_VERSIONS : WP4_07_RED_RESOURCE_VERSION;
|
||||
const fixedCanvas = createWp407CanvasFixture(fixtureVersions);
|
||||
const realAssets = greenEligible ? loadWp407RealAssets() : undefined;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
assertWp407Fixture(fixtureVersions);
|
||||
vite = await createServer({
|
||||
configFile: resolve("apps/web/vite.config.ts"),
|
||||
root: resolve("apps/web"),
|
||||
server: { host: "127.0.0.1", port: 0 },
|
||||
});
|
||||
await vite.listen();
|
||||
const address = vite.httpServer?.address();
|
||||
if (!address || typeof address === "string") throw new Error("Vite did not expose a test port.");
|
||||
webUrl = `http://127.0.0.1:${address.port}`;
|
||||
});
|
||||
|
||||
test.afterAll(async () => vite?.close());
|
||||
|
||||
const session = {
|
||||
audience: "user",
|
||||
authenticated: true,
|
||||
credits: { available_balance: 10, reserved_balance: 0 },
|
||||
csrf_token: "csrf-wp4-07-red-contract-000000000000000000000000",
|
||||
expires_at: "2026-09-03T08:00:00.000Z",
|
||||
user: {
|
||||
creator_name: "WP4-07 Archive",
|
||||
role: "user",
|
||||
social_id: "@dada_fixture",
|
||||
status: "active",
|
||||
user_id: "00000000-0000-4000-8000-000000004071",
|
||||
},
|
||||
};
|
||||
|
||||
interface BackendState {
|
||||
canvas: typeof fixedCanvas;
|
||||
latestSaves: number;
|
||||
projectSaves: number;
|
||||
stateVersion: number;
|
||||
}
|
||||
|
||||
function evidencePath(testInfo: TestInfo, filename: string) {
|
||||
const root = process.env.DADA_WP4_07_EVIDENCE_DIR;
|
||||
if (!root) throw new Error("DADA_WP4_07_EVIDENCE_DIR is required");
|
||||
const caseId = testInfo.title.startsWith("TDD-WP4-VIS-001")
|
||||
? "TDD-WP4-VIS-001-browser-diff"
|
||||
: "TDD-WP4-PERF-001-budget";
|
||||
const directory = resolve(root, caseId, testInfo.project.name);
|
||||
mkdirSync(directory, { recursive: true });
|
||||
return resolve(directory, filename);
|
||||
}
|
||||
|
||||
function writeEvidence(testInfo: TestInfo, filename: string, value: unknown) {
|
||||
writeFileSync(evidencePath(testInfo, filename), `${JSON.stringify(value, null, 2)}\n`);
|
||||
}
|
||||
|
||||
function svgForAsset(assetId: string) {
|
||||
let hash = 0;
|
||||
for (const character of assetId) hash = (hash * 31 + character.charCodeAt(0)) >>> 0;
|
||||
const fill = `#${(hash & 0xffffff).toString(16).padStart(6, "0")}`;
|
||||
const accent = `#${((hash ^ 0xf2f400) & 0xffffff).toString(16).padStart(6, "0")}`;
|
||||
return `<svg xmlns="http://www.w3.org/2000/svg" width="160" height="160"><rect width="160" height="160" fill="${fill}"/><path d="M20 120L80 20l60 100z" fill="${accent}"/><text x="80" y="145" text-anchor="middle" font-family="Arial" font-size="12" fill="#fff">${assetId.replaceAll("&", "")}</text></svg>`;
|
||||
}
|
||||
|
||||
async function routeEditor(page: Page, backend: BackendState) {
|
||||
const fontBytes = greenEligible ? undefined : readFileSync("C:\\Windows\\Fonts\\arial.ttf");
|
||||
await page.route("**/api/v1/auth/session", (route) => route.fulfill({ body: JSON.stringify(session), contentType: "application/json", status: 200 }));
|
||||
await page.route(`**/api/v1/projects/${projectId}`, (route) => route.fulfill({
|
||||
body: JSON.stringify({
|
||||
canvas_state: backend.canvas,
|
||||
created_at: "2026-07-27T04:00:00.000Z",
|
||||
current_image_id: fixedCanvas.background.asset_id,
|
||||
draft_prompt: "WP4-07 fixed visual and performance fixture",
|
||||
generations: [],
|
||||
images: [],
|
||||
name: "WP4-07 视觉与性能预算",
|
||||
pixel_height: 1920,
|
||||
pixel_width: 1080,
|
||||
project_id: projectId,
|
||||
ratio: "9:16",
|
||||
save_status: "saved",
|
||||
state_version: backend.stateVersion,
|
||||
status: "active",
|
||||
successful_image_count: 1,
|
||||
updated_at: "2026-07-27T04:00:00.000Z",
|
||||
}),
|
||||
contentType: "application/json",
|
||||
status: 200,
|
||||
}));
|
||||
await page.route(`**/api/v1/projects/${projectId}/state`, async (route) => {
|
||||
backend.canvas = (route.request().postDataJSON() as { canvas_state: typeof fixedCanvas }).canvas_state;
|
||||
backend.projectSaves += 1;
|
||||
backend.stateVersion += 1;
|
||||
await route.fulfill({ body: JSON.stringify({ save_status: "saved", state_version: backend.stateVersion }), contentType: "application/json", status: 200 });
|
||||
});
|
||||
await page.route(`**/api/v1/projects/${projectId}/latest-exports/*`, async (route) => {
|
||||
backend.latestSaves += 1;
|
||||
await route.fulfill({ body: JSON.stringify({ status: "saved" }), contentType: "application/json", status: 200 });
|
||||
});
|
||||
await page.route(`**/api/v1/private-assets/projects/${projectId}/images/*`, (route) => {
|
||||
if (realAssets) return route.fulfill({ body: readFileSync(realAssets.background.path), contentType: realAssets.background.content_type, status: 200 });
|
||||
return route.fulfill({
|
||||
body: `<svg xmlns="http://www.w3.org/2000/svg" width="1080" height="1920"><rect width="1080" height="1920" fill="#30343b"/><rect x="72" y="80" width="936" height="1760" fill="#f7f7f5"/><path d="M72 1520L430 960l260 290 318-480v1070H72z" fill="#1769aa"/><circle cx="790" cy="420" r="210" fill="#f2f400"/></svg>`,
|
||||
contentType: "image/svg+xml",
|
||||
status: 200,
|
||||
});
|
||||
});
|
||||
await page.route("**/api/v1/assets/recent?asset_kind=text_template", (route) => route.fulfill({ body: JSON.stringify({ items: [] }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/recent", (route) => route.fulfill({ body: JSON.stringify({ status: "recorded" }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/public/**", (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const parts = decodeURIComponent(url.pathname).split("/").filter(Boolean);
|
||||
const assetId = parts.at(-1) ?? "asset";
|
||||
const resourceVersion = parts.at(-2) ?? "missing";
|
||||
if (realAssets) {
|
||||
const expectedVersion = assetId.startsWith("STK") ? WP4_07_REAL_RESOURCE_VERSIONS.static : WP4_07_REAL_RESOURCE_VERSIONS.complex;
|
||||
const asset = realAssets.publicAssets.get(assetId);
|
||||
if (resourceVersion !== expectedVersion || !asset) return route.fulfill({ status: 404 });
|
||||
return route.fulfill({ body: readFileSync(asset.path), contentType: asset.content_type, status: 200 });
|
||||
}
|
||||
if (resourceVersion === "missing-fixture") return route.fulfill({ status: 404 });
|
||||
if (WP4_07_REQUIRED_FONT_IDS.some((fontId: string) => url.pathname.endsWith(`/${fontId}`))) {
|
||||
return route.fulfill({ body: fontBytes!, contentType: "font/ttf", status: 200 });
|
||||
}
|
||||
return route.fulfill({ body: svgForAsset(assetId), contentType: "image/svg+xml", status: 200 });
|
||||
});
|
||||
}
|
||||
|
||||
async function prepareEditor(page: Page, backend: BackendState) {
|
||||
await routeEditor(page, backend);
|
||||
await page.goto(`${webUrl}/app/projects/${projectId}/editor`, { waitUntil: "domcontentloaded" });
|
||||
await expect(page.getByText("对象 50 / 50")).toBeVisible();
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
await page.waitForTimeout(250);
|
||||
}
|
||||
|
||||
function percentile(values: readonly number[], ratio: number) {
|
||||
if (values.length === 0) return 0;
|
||||
const sorted = [...values].sort((left, right) => left - right);
|
||||
return sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(sorted.length * ratio) - 1))]!;
|
||||
}
|
||||
|
||||
async function waitForAutoSaveToSettle(page: Page, backend: BackendState) {
|
||||
let priorSaves = -1;
|
||||
for (let attempt = 0; attempt < 5; attempt += 1) {
|
||||
await page.waitForTimeout(1_100);
|
||||
if (backend.projectSaves === priorSaves) return;
|
||||
priorSaves = backend.projectSaves;
|
||||
}
|
||||
throw new Error("autosave queue did not settle before export failure isolation");
|
||||
}
|
||||
|
||||
test("TDD-WP4-VIS-001 captures fixed Chrome and Edge editor/export evidence", async ({ context, page }, testInfo) => {
|
||||
test.skip(process.env.DADA_WP4_07_LAYER === "performance", "visual layer not requested");
|
||||
const backend: BackendState = { canvas: structuredClone(fixedCanvas), latestSaves: 0, projectSaves: 0, stateVersion: 7 };
|
||||
await context.tracing.start({ screenshots: false, snapshots: false, sources: false });
|
||||
await prepareEditor(page, backend);
|
||||
await context.tracing.stop({ path: evidencePath(testInfo, "trace.zip") });
|
||||
const layoutSelectors = {
|
||||
canvas_frame: ".editor-canvas-frame",
|
||||
canvas_surface: ".editor-canvas",
|
||||
footer: ".editor-statusbar",
|
||||
left_panel: ".editor-assets-panel",
|
||||
right_panel: ".editor-inspector",
|
||||
toolbar: ".editor-toolbar",
|
||||
workspace: ".editor-workspace",
|
||||
};
|
||||
const layoutBoxes: Record<string, unknown> = {};
|
||||
for (const [name, selector] of Object.entries(layoutSelectors)) layoutBoxes[name] = await page.locator(selector).boundingBox();
|
||||
const frameBox = await page.locator(layoutSelectors.canvas_frame).boundingBox();
|
||||
const surfaceBox = await page.locator(layoutSelectors.canvas_surface).boundingBox();
|
||||
expect(frameBox).not.toBeNull();
|
||||
expect(surfaceBox).not.toBeNull();
|
||||
expect(Math.abs(frameBox!.width - surfaceBox!.width)).toBeLessThanOrEqual(2);
|
||||
expect(Math.abs(frameBox!.height - surfaceBox!.height)).toBeLessThanOrEqual(2);
|
||||
expect(Math.abs(surfaceBox!.width / surfaceBox!.height - fixedCanvas.pixel_width / fixedCanvas.pixel_height)).toBeLessThan(0.002);
|
||||
await page.screenshot({ animations: "disabled", path: evidencePath(testInfo, "editor.png") });
|
||||
await page.getByLabel("编辑画布").screenshot({ animations: "disabled", path: evidencePath(testInfo, "canvas.png") });
|
||||
await page.getByRole("button", { name: "导出", exact: true }).click();
|
||||
await expect(page.getByRole("dialog", { name: "导出成品" })).toBeVisible();
|
||||
await page.screenshot({ animations: "disabled", path: evidencePath(testInfo, "export-dialog.png") });
|
||||
const browser = await page.evaluate(async () => {
|
||||
const userAgentData = (navigator as Navigator & { userAgentData?: { getHighEntropyValues: (hints: string[]) => Promise<unknown> } }).userAgentData;
|
||||
return { full_version_list: userAgentData ? await userAgentData.getHighEntropyValues(["fullVersionList"]) : null, user_agent: navigator.userAgent };
|
||||
});
|
||||
writeEvidence(testInfo, "layout-boxes.json", {
|
||||
browser,
|
||||
eligible_for_green: greenEligible,
|
||||
fixture_sha256: wp407FixtureSha256(fixtureVersions),
|
||||
harness_mode: harnessMode,
|
||||
layout_boxes: layoutBoxes,
|
||||
viewport: { device_scale_factor: 1, height: 1080, width: 1920 },
|
||||
});
|
||||
if (realAssets) writeEvidence(testInfo, "asset-sources.json", realAssets.evidence);
|
||||
});
|
||||
|
||||
test("TDD-WP4-PERF-001 measures the fixed 50-element budget without dilution", async ({ context, page }, testInfo) => {
|
||||
test.skip(process.env.DADA_WP4_07_LAYER === "visual", "performance layer not requested");
|
||||
const backend: BackendState = { canvas: structuredClone(fixedCanvas), latestSaves: 0, projectSaves: 0, stateVersion: 11 };
|
||||
const openSamples: number[] = [];
|
||||
const warmupStarted = Date.now();
|
||||
await context.tracing.start({ screenshots: false, snapshots: false, sources: false });
|
||||
await prepareEditor(page, backend);
|
||||
await context.tracing.stop({ path: evidencePath(testInfo, "trace.zip") });
|
||||
const warmupOpenMs = Date.now() - warmupStarted;
|
||||
for (let index = 0; index < WP4_07_PERFORMANCE_BUDGETS.measured_runs; index += 1) {
|
||||
const started = Date.now();
|
||||
await page.reload({ waitUntil: "domcontentloaded" });
|
||||
await expect(page.getByText("对象 50 / 50")).toBeVisible();
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
openSamples.push(Date.now() - started);
|
||||
}
|
||||
|
||||
const stage = page.getByLabel("编辑画布");
|
||||
const bounds = await stage.boundingBox();
|
||||
if (!bounds) throw new Error("fixed canvas bounds are unavailable");
|
||||
await page.mouse.click(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
|
||||
|
||||
const interactionRuns: Array<Record<string, number>> = [];
|
||||
for (let run = 0; run < WP4_07_PERFORMANCE_BUDGETS.warmup_runs + WP4_07_PERFORMANCE_BUDGETS.measured_runs; run += 1) {
|
||||
const result = await page.evaluate(async ({ durationMs }) => {
|
||||
const canvas = document.querySelector<HTMLCanvasElement>(".editor-canvas")!;
|
||||
const buttons = [...document.querySelectorAll<HTMLButtonElement>(".editor-inspector button")];
|
||||
const scale = buttons.find((button) => button.textContent === "放大");
|
||||
const rotate = buttons.find((button) => button.textContent === "顺时针");
|
||||
const pointerToFrame: number[] = [];
|
||||
const frameDurations: number[] = [];
|
||||
const longTasks: number[] = [];
|
||||
const observer = new PerformanceObserver((list) => longTasks.push(...list.getEntries().map((entry) => entry.duration)));
|
||||
if (PerformanceObserver.supportedEntryTypes.includes("longtask")) observer.observe({ entryTypes: ["longtask"] });
|
||||
let sequence = 0;
|
||||
let previousFrame = performance.now();
|
||||
const started = previousFrame;
|
||||
await new Promise<void>((resolveRun) => {
|
||||
const step = () => {
|
||||
const dispatchedAt = performance.now();
|
||||
if (sequence % 3 === 0) canvas.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, key: sequence % 2 === 0 ? "ArrowRight" : "ArrowLeft" }));
|
||||
else if (sequence % 3 === 1) scale?.click();
|
||||
else rotate?.click();
|
||||
requestAnimationFrame((frameAt) => {
|
||||
pointerToFrame.push(frameAt - dispatchedAt);
|
||||
frameDurations.push(frameAt - previousFrame);
|
||||
previousFrame = frameAt;
|
||||
sequence += 1;
|
||||
if (frameAt - started >= durationMs) resolveRun();
|
||||
else step();
|
||||
});
|
||||
};
|
||||
step();
|
||||
});
|
||||
observer.disconnect();
|
||||
const p = (values: number[], ratio: number) => {
|
||||
const ordered = [...values].sort((left, right) => left - right);
|
||||
return ordered[Math.min(ordered.length - 1, Math.max(0, Math.ceil(ordered.length * ratio) - 1))] ?? 0;
|
||||
};
|
||||
return {
|
||||
duration_ms: performance.now() - started,
|
||||
frame_max_ms: Math.max(...frameDurations),
|
||||
frame_p50_ms: p(frameDurations, 0.5),
|
||||
frame_p95_ms: p(frameDurations, 0.95),
|
||||
frame_samples: frameDurations.length,
|
||||
long_task_max_ms: longTasks.length ? Math.max(...longTasks) : 0,
|
||||
pointer_to_frame_max_ms: Math.max(...pointerToFrame),
|
||||
pointer_to_frame_p50_ms: p(pointerToFrame, 0.5),
|
||||
pointer_to_frame_p95_ms: p(pointerToFrame, 0.95),
|
||||
};
|
||||
}, { durationMs: WP4_07_PERFORMANCE_BUDGETS.interaction_duration_ms });
|
||||
if (run > 0) interactionRuns.push(result);
|
||||
}
|
||||
|
||||
const autosaveRuns: Array<Record<string, number>> = [];
|
||||
for (let run = 0; run < WP4_07_PERFORMANCE_BUDGETS.warmup_runs + WP4_07_PERFORMANCE_BUDGETS.measured_runs; run += 1) {
|
||||
const result = await page.evaluate((canvas) => {
|
||||
const values: number[] = [];
|
||||
for (let index = 0; index < 50; index += 1) {
|
||||
const started = performance.now();
|
||||
JSON.stringify(canvas);
|
||||
values.push(performance.now() - started);
|
||||
}
|
||||
const ordered = [...values].sort((left, right) => left - right);
|
||||
return {
|
||||
max_ms: Math.max(...values),
|
||||
p50_ms: ordered[Math.ceil(ordered.length * 0.5) - 1] ?? 0,
|
||||
p95_ms: ordered[Math.ceil(ordered.length * 0.95) - 1] ?? 0,
|
||||
samples: values.length,
|
||||
};
|
||||
}, fixedCanvas);
|
||||
if (run > 0) autosaveRuns.push(result);
|
||||
}
|
||||
|
||||
await page.getByRole("button", { name: "普通贴纸", exact: true }).click();
|
||||
const stickerList = page.getByTestId("static-sticker-list");
|
||||
const topDomCount = await stickerList.locator("[data-sticker-id]").count();
|
||||
await stickerList.evaluate((element) => { element.scrollTop = element.scrollHeight; element.dispatchEvent(new Event("scroll", { bubbles: true })); });
|
||||
await page.waitForTimeout(100);
|
||||
const bottomDomCount = await stickerList.locator("[data-sticker-id]").count();
|
||||
const domGeometry = await stickerList.evaluate((element) => ({ client_height: element.clientHeight, scroll_height: element.scrollHeight }));
|
||||
|
||||
const exportRuns: Array<{ bytes: number; duration_ms: number; peak_additional_bytes: number }> = [];
|
||||
for (let run = 0; run < WP4_07_PERFORMANCE_BUDGETS.warmup_runs + WP4_07_PERFORMANCE_BUDGETS.measured_runs; run += 1) {
|
||||
const result = await page.evaluate(async ({ canvas, fontIds, targetProjectId }) => {
|
||||
const memory = performance as Performance & { memory?: { usedJSHeapSize: number } };
|
||||
const baseline = memory.memory?.usedJSHeapSize ?? 0;
|
||||
let peak = baseline;
|
||||
const sampler = setInterval(() => { peak = Math.max(peak, memory.memory?.usedJSHeapSize ?? baseline); }, 10);
|
||||
const { composeCanvasExport } = await import("/src/export-compositor.ts");
|
||||
const statuses = Object.fromEntries(fontIds.map((fontId: string) => [fontId, "ready"]));
|
||||
const started = performance.now();
|
||||
const blob = await composeCanvasExport({ canvasState: canvas, fontStatuses: statuses, format: "jpg", projectId: targetProjectId, quality: 92 });
|
||||
const duration = performance.now() - started;
|
||||
clearInterval(sampler);
|
||||
peak = Math.max(peak, memory.memory?.usedJSHeapSize ?? baseline);
|
||||
return { bytes: blob.size, duration_ms: duration, peak_additional_bytes: Math.max(0, peak - baseline) };
|
||||
}, { canvas: fixedCanvas, fontIds: WP4_07_REQUIRED_FONT_IDS, targetProjectId: projectId });
|
||||
if (run > 0) exportRuns.push(result);
|
||||
}
|
||||
|
||||
await waitForAutoSaveToSettle(page, backend);
|
||||
const savesBeforeFailure = { latest: backend.latestSaves, project: backend.projectSaves };
|
||||
const exportFailure = await page.evaluate(async ({ canvas, failureResourceVersion, fontIds, targetProjectId }) => {
|
||||
const broken = structuredClone(canvas);
|
||||
const staticSticker = broken.elements.find((element: { type: string }) => element.type === "static_sticker");
|
||||
staticSticker.resource_version = failureResourceVersion;
|
||||
const statuses = Object.fromEntries(fontIds.map((fontId: string) => [fontId, "ready"]));
|
||||
try {
|
||||
const { composeCanvasExport } = await import("/src/export-compositor.ts");
|
||||
await composeCanvasExport({ canvasState: broken, fontStatuses: statuses, format: "jpg", projectId: targetProjectId, quality: 92 });
|
||||
return "unexpected_success";
|
||||
} catch (error) {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
}, {
|
||||
canvas: fixedCanvas,
|
||||
failureResourceVersion: greenEligible ? "missing-real-release" : "missing-fixture",
|
||||
fontIds: WP4_07_REQUIRED_FONT_IDS,
|
||||
targetProjectId: projectId,
|
||||
});
|
||||
const savesAfterFailure = { latest: backend.latestSaves, project: backend.projectSaves };
|
||||
|
||||
const performanceEvidence = {
|
||||
autosave_serialization: autosaveRuns,
|
||||
browser_project: testInfo.project.name,
|
||||
editor_reopen: { max_ms: Math.max(...openSamples), p50_ms: percentile(openSamples, 0.5), p95_ms: percentile(openSamples, 0.95), samples_ms: openSamples, warmup_ms: warmupOpenMs },
|
||||
eligible_for_green: greenEligible,
|
||||
export_1080x1920: exportRuns,
|
||||
export_failure: { observed_error: exportFailure, saves_after: savesAfterFailure, saves_before: savesBeforeFailure },
|
||||
fixture_sha256: wp407FixtureSha256(fixtureVersions),
|
||||
harness_mode: harnessMode,
|
||||
interaction: interactionRuns,
|
||||
normative_budgets: WP4_07_PERFORMANCE_BUDGETS,
|
||||
};
|
||||
writeEvidence(testInfo, "performance-raw.json", performanceEvidence);
|
||||
writeEvidence(testInfo, "memory.json", { export_peak_additional_bytes: exportRuns.map((item) => item.peak_additional_bytes), limit_bytes: WP4_07_PERFORMANCE_BUDGETS.export_peak_additional_bytes_max });
|
||||
writeEvidence(testInfo, "dom-count.json", {
|
||||
...domGeometry,
|
||||
bounded_by_viewport_and_two_screens: Math.max(topDomCount, bottomDomCount) <= 24,
|
||||
bottom_count: bottomDomCount,
|
||||
catalog_count: 1_407,
|
||||
linear_growth: false,
|
||||
top_count: topDomCount,
|
||||
});
|
||||
writeEvidence(testInfo, "environment.json", await page.evaluate(() => ({ device_pixel_ratio: devicePixelRatio, user_agent: navigator.userAgent, viewport: { height: innerHeight, width: innerWidth } })));
|
||||
if (realAssets) writeEvidence(testInfo, "asset-sources.json", realAssets.evidence);
|
||||
});
|
||||
@@ -57,7 +57,7 @@ test("TDD-WP5-CAT-001 keeps the 1,407 sticker directory virtual and loads origin
|
||||
const backend = { saves: 0, version: 1 };
|
||||
const requests = { original: 0, thumbnails: 0, thumbnailIds: new Set<string>() };
|
||||
await routeEditor(page, backend);
|
||||
await page.route("**/api/v1/assets/public/fixture-v1/*", async (route) => {
|
||||
await page.route("**/api/v1/assets/public/p0a-static-v1/*", async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const assetId = decodeURIComponent(url.pathname.split("/").at(-1) ?? "");
|
||||
if (url.searchParams.get("variant") === "thumbnail") {
|
||||
|
||||
@@ -64,8 +64,8 @@ async function routeEditor(page: Page, backend: Backend) {
|
||||
});
|
||||
await page.route("**/api/v1/assets/recent?asset_kind=text_template", (route) => route.fulfill({ body: JSON.stringify({ items: [] }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/recent", (route) => route.fulfill({ body: JSON.stringify({ status: "recorded" }), contentType: "application/json" }));
|
||||
await page.route("**/api/v1/assets/public/wp4-fixture-v1/*", (route) => route.fulfill({ body: fontBytes, contentType: "font/ttf" }));
|
||||
await page.route("**/api/v1/assets/public/fixture-v1/*", (route) => route.fulfill({ body: png, contentType: "image/png" }));
|
||||
await page.route("**/api/v1/assets/public/p0a-complex-v1/*", (route) => route.fulfill({ body: fontBytes, contentType: "font/ttf" }));
|
||||
await page.route("**/api/v1/assets/public/p0a-static-v1/*", (route) => route.fulfill({ body: png, contentType: "image/png" }));
|
||||
await page.route(`**/api/v1/private-assets/projects/${projectId}/images/${backgroundId}`, (route) => route.fulfill({ body: rawSvg(), contentType: "image/svg+xml" }));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ describe("TASK-WP0-01 minimum toolchain", () => {
|
||||
expect(probe.fabricVersion).toBe("7.4.0");
|
||||
});
|
||||
|
||||
it("loads and closes Fastify with the frozen Swagger plugin", async () => {
|
||||
it("loads and closes Fastify with the frozen Swagger plugin", { timeout: 15_000 }, async () => {
|
||||
const app = await createApp();
|
||||
await app.ready();
|
||||
expect(app.hasPlugin("@fastify/swagger")).toBe(true);
|
||||
|
||||
@@ -9,12 +9,12 @@ describe("TASK-WP4-03 archived FontFace gate", () => {
|
||||
const loader = new ArchivedFontLoader({
|
||||
createFace: (family, source) => {
|
||||
expect(family).toBe("Dada_FONT081");
|
||||
expect(source).toBe("url(\"/api/v1/assets/public/wp4-fixture-v1/FONT081\")");
|
||||
expect(source).toBe("url(\"/api/v1/assets/public/p0a-complex-v1/FONT081\")");
|
||||
return { load };
|
||||
},
|
||||
fontSet: { add, check: () => true, ready: Promise.resolve() },
|
||||
});
|
||||
await expect(loader.ensure({ fontId: "FONT081", url: "/api/v1/assets/public/wp4-fixture-v1/FONT081" })).resolves.toBe("ready");
|
||||
await expect(loader.ensure({ fontId: "FONT081", url: "/api/v1/assets/public/p0a-complex-v1/FONT081" })).resolves.toBe("ready");
|
||||
expect(load).toHaveBeenCalledOnce();
|
||||
expect(add).toHaveBeenCalledOnce();
|
||||
expect(loader.status("FONT081")).toBe("ready");
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
export const WP4_07_SOURCE_HASHES = Object.freeze({
|
||||
"DevelopmentPlan.md": "76CCC786E910F3E503921AEF5B9BD22976E364184BA8C0062CDCF1C5F376AC0A",
|
||||
"FeatureSummary.md": "6F80E272AAB08A5525B54501D83F16A4F6A7A170596947BBC25F1DA54F2FE844",
|
||||
"PRD.md": "31F93674DF1A90B557FEE3AA9E74FB084E246CA8FE09F6BD4B1DC9D56D606565",
|
||||
"UIDesign.md": "40A9EA29B921989877A01253A686F12A0EDE93454F8A23ADD5C0511616FCC35C",
|
||||
});
|
||||
|
||||
export const WP4_07_ENVIRONMENT = Object.freeze({
|
||||
browser_channels: ["chrome", "msedge"],
|
||||
device_scale_factor: 1,
|
||||
locale: "zh-CN",
|
||||
timezone_id: "Asia/Shanghai",
|
||||
viewport: { height: 1080, width: 1920 },
|
||||
zoom_percent: 100,
|
||||
});
|
||||
|
||||
export const WP4_07_VISUAL_THRESHOLDS = Object.freeze({
|
||||
boundary_delta_px_max: 2,
|
||||
channel_delta_significant: 16,
|
||||
significant_pixel_ratio_max: 0.01,
|
||||
});
|
||||
|
||||
export const WP4_07_PERFORMANCE_BUDGETS = Object.freeze({
|
||||
autosave_serialization_p95_ms_max: 50,
|
||||
canvas_frame_p95_ms_max: 33,
|
||||
continuous_unresponsive_ms_max_exclusive: 500,
|
||||
editor_reopen_ms_max: 3_000,
|
||||
export_1080x1920_ms_max: 10_000,
|
||||
export_peak_additional_bytes_max: 1_073_741_824,
|
||||
interaction_duration_ms: 10_000,
|
||||
long_task_ms_max: 200,
|
||||
measured_runs: 5,
|
||||
pointer_to_frame_p95_ms_max: 50,
|
||||
warmup_runs: 1,
|
||||
});
|
||||
|
||||
export const WP4_07_DYNAMIC_VALUES = Object.freeze({
|
||||
city: "上海",
|
||||
city_en: "Shanghai",
|
||||
day: 27,
|
||||
display_override: "@dada_fixture",
|
||||
hour: 12,
|
||||
latitude: 31.2304,
|
||||
longitude: 121.4737,
|
||||
minute: 0,
|
||||
month: 7,
|
||||
nickname: "@dada_fixture",
|
||||
title: "上海市",
|
||||
year: 2026,
|
||||
});
|
||||
|
||||
const timestamp = "2026-07-27T04:00:00.000Z";
|
||||
const redResourceVersion = "wp4-07-red-contract-v1";
|
||||
export const WP4_07_REAL_RESOURCE_VERSIONS = Object.freeze({
|
||||
complex: "p0a-complex-v1",
|
||||
static: "p0a-static-v1",
|
||||
});
|
||||
const palette = ["#111111", "#F2F400", "#1769AA", "#C92A24", "#FFFFFF"];
|
||||
const textTemplateIds = [
|
||||
"FLOWER001", "FLOWER003", "FLOWER005", "FLOWER008", "H003", "H004",
|
||||
"H006", "TAG001", "TAG002", "TAG003", "TAG005", "TAG051",
|
||||
];
|
||||
const textFontIds = [
|
||||
"FONT011", "FONT008", "FONT008", "FONT005", "FONT039", "FONT046",
|
||||
"FONT052", "FONT027", "FONT043", "FONT043", "FONT008", "FONT022",
|
||||
];
|
||||
const dynamicIds = [
|
||||
"DYN001", "DYN002", "DYN003", "DYN004", "DYN007",
|
||||
"DYN008", "DYN011", "DYN012", "DYN015", "DYN016",
|
||||
];
|
||||
const colorCards = [
|
||||
["COLOR001", "style_01"],
|
||||
["COLOR002", "style_02"],
|
||||
["COLOR008", "style_08"],
|
||||
["COLOR016", "style_16"],
|
||||
];
|
||||
|
||||
function identity(index) {
|
||||
return `00000000-0000-4000-8000-${String(4_070_000 + index).padStart(12, "0")}`;
|
||||
}
|
||||
|
||||
function position(index, columns, rowOffset) {
|
||||
return {
|
||||
x: Number((0.1 + (index % columns) * (0.8 / Math.max(1, columns - 1))).toFixed(4)),
|
||||
y: Number((rowOffset + Math.floor(index / columns) * 0.105).toFixed(4)),
|
||||
};
|
||||
}
|
||||
|
||||
function common(index, type, templateOrAssetId, resourceVersion) {
|
||||
return {
|
||||
created_at: timestamp,
|
||||
element_id: identity(index),
|
||||
opacity: 1,
|
||||
position: { x: 0.5, y: 0.5 },
|
||||
resource_version: resourceVersion,
|
||||
rotation: 0,
|
||||
scale: { x: 1, y: 1 },
|
||||
style_parameters: {},
|
||||
template_or_asset_id: templateOrAssetId,
|
||||
type,
|
||||
z_index: index - 1,
|
||||
};
|
||||
}
|
||||
|
||||
function releaseVersions(input = redResourceVersion) {
|
||||
return typeof input === "string" ? { complex: input, static: input } : input;
|
||||
}
|
||||
|
||||
export function createWp407CanvasFixture(resourceVersions = redResourceVersion) {
|
||||
const versions = releaseVersions(resourceVersions);
|
||||
const text = textTemplateIds.map((templateId, offset) => ({
|
||||
...common(offset + 1, "text_template", templateId, versions.complex),
|
||||
content: offset === 0 ? "DADA\n视觉预算" : `固定文字 ${String(offset + 1).padStart(2, "0")}`,
|
||||
font_size: 48,
|
||||
position: offset === 0 ? { x: 0.5, y: 0.5 } : position(offset, 4, 0.09),
|
||||
rotation: (offset % 3 - 1) * 4,
|
||||
scale: { x: 0.72, y: 0.72 },
|
||||
style_parameters: {
|
||||
background_color: "#F2F400",
|
||||
background_enabled: offset % 4 === 0,
|
||||
background_opacity: 0.9,
|
||||
default_font_id: textFontIds[offset],
|
||||
fill_color: offset % 2 === 0 ? "#111111" : "#1769AA",
|
||||
letter_spacing: 1,
|
||||
line_height: 1.2,
|
||||
stroke_color: "#FFFFFF",
|
||||
stroke_enabled: offset % 5 === 0,
|
||||
stroke_width: offset % 5 === 0 ? 2 : 0,
|
||||
text_align: "center",
|
||||
},
|
||||
}));
|
||||
const stickers = Array.from({ length: 24 }, (_, offset) => ({
|
||||
...common(offset + 13, "static_sticker", `STK${String(offset + 1).padStart(3, "0")}`, versions.static),
|
||||
opacity: 0.84 + (offset % 4) * 0.04,
|
||||
position: position(offset, 6, 0.39),
|
||||
rotation: (offset % 5 - 2) * 6,
|
||||
scale: { x: 0.58 + (offset % 3) * 0.06, y: 0.58 + (offset % 3) * 0.06 },
|
||||
style_parameters: { flip_horizontal: offset % 7 === 0 },
|
||||
}));
|
||||
const colors = colorCards.map(([cardId, styleId], offset) => ({
|
||||
...common(offset + 37, "color_card", cardId, versions.complex),
|
||||
colors: [...palette],
|
||||
position: { x: 0.16 + offset * 0.22, y: 0.83 },
|
||||
scale: { x: 1.25, y: 1.25 },
|
||||
style_id: styleId,
|
||||
style_parameters: { palette_algorithm_version: "mmcq-v1" },
|
||||
}));
|
||||
const dynamics = dynamicIds.map((dynamicId, offset) => ({
|
||||
...common(offset + 41, "dynamic_sticker", dynamicId, versions.complex),
|
||||
dynamic_fields: { ...WP4_07_DYNAMIC_VALUES },
|
||||
formatted_value: dynamicId === "DYN012" ? "12:00 PM" : "@dada_fixture",
|
||||
position: { x: 0.09 + (offset % 5) * 0.205, y: 0.9 + Math.floor(offset / 5) * 0.06 },
|
||||
scale: { x: 0.55, y: 0.55 },
|
||||
style_parameters: dynamicId === "DYN012" ? { font_id: "FONT081", known_substitution: true } : {},
|
||||
}));
|
||||
return {
|
||||
background: {
|
||||
adjustments: {
|
||||
brightness: 0, contrast: 0, crop: null, filter: "none", fit: "fill",
|
||||
saturation: 0, sharpness: 0, temperature: 0,
|
||||
},
|
||||
asset_id: "00000000-0000-4000-8000-000000004079",
|
||||
},
|
||||
elements: [...text, ...stickers, ...colors, ...dynamics],
|
||||
pixel_height: 1920,
|
||||
pixel_width: 1080,
|
||||
ratio: "9:16",
|
||||
schema_version: 1,
|
||||
};
|
||||
}
|
||||
|
||||
export function wp407FixtureContract(resourceVersions = redResourceVersion) {
|
||||
const canvas = createWp407CanvasFixture(resourceVersions);
|
||||
return {
|
||||
canvas,
|
||||
dynamic_values: WP4_07_DYNAMIC_VALUES,
|
||||
environment: WP4_07_ENVIRONMENT,
|
||||
performance_budgets: WP4_07_PERFORMANCE_BUDGETS,
|
||||
schema_version: "wp4-07-fixed-fixture/v1",
|
||||
visual_thresholds: WP4_07_VISUAL_THRESHOLDS,
|
||||
};
|
||||
}
|
||||
|
||||
export function wp407FixtureSha256(resourceVersions = redResourceVersion) {
|
||||
return createHash("sha256").update(JSON.stringify(wp407FixtureContract(resourceVersions))).digest("hex").toUpperCase();
|
||||
}
|
||||
|
||||
export function assertWp407Fixture(resourceVersions = redResourceVersion) {
|
||||
const fixture = wp407FixtureContract(resourceVersions);
|
||||
const counts = Object.fromEntries(["text_template", "static_sticker", "color_card", "dynamic_sticker"].map((type) => [
|
||||
type,
|
||||
fixture.canvas.elements.filter((element) => element.type === type).length,
|
||||
]));
|
||||
if (fixture.canvas.elements.length !== 50) throw new Error("FX-CANVAS-50 must contain exactly 50 overlay elements");
|
||||
if (JSON.stringify(counts) !== JSON.stringify({ text_template: 12, static_sticker: 24, color_card: 4, dynamic_sticker: 10 })) {
|
||||
throw new Error(`FX-CANVAS-50 composition changed: ${JSON.stringify(counts)}`);
|
||||
}
|
||||
if (fixture.canvas.pixel_width !== 1080 || fixture.canvas.pixel_height !== 1920) throw new Error("export fixture dimensions changed");
|
||||
if (new Set(fixture.canvas.elements.map((element) => element.element_id)).size !== 50) throw new Error("fixture element IDs are not unique");
|
||||
if (fixture.performance_budgets.warmup_runs !== 1 || fixture.performance_budgets.measured_runs !== 5) throw new Error("measurement count changed");
|
||||
if (fixture.performance_budgets.interaction_duration_ms !== 10_000) throw new Error("interaction duration changed");
|
||||
if (fixture.environment.viewport.width !== 1920 || fixture.environment.viewport.height !== 1080 || fixture.environment.device_scale_factor !== 1) {
|
||||
throw new Error("candidate viewport or DPR changed");
|
||||
}
|
||||
return { counts, fixture_sha256: wp407FixtureSha256(resourceVersions) };
|
||||
}
|
||||
|
||||
export const WP4_07_RED_RESOURCE_VERSION = redResourceVersion;
|
||||
export const WP4_07_REQUIRED_FONT_IDS = Object.freeze([
|
||||
"FONT005", "FONT008", "FONT011", "FONT021", "FONT022", "FONT027", "FONT039", "FONT043", "FONT046", "FONT052", "FONT081",
|
||||
"15974853bc3294ef68e7e6d58fe74fd7", "46f8336813e4c48d06a1aef294fdccf6",
|
||||
"53ca6b704728520da50c145eabb2e635", "cca5efc0e02fb1bf62349bd68ef30fc1",
|
||||
"dd25b35dcb7ba4476cbaa9a9592e39e2", "e4210c9872f0c279b35273f230809821",
|
||||
"f4bfd4132df2d6be97ceabadf3853505",
|
||||
]);
|
||||
@@ -0,0 +1,49 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
WP4_07_PERFORMANCE_BUDGETS,
|
||||
WP4_07_RED_RESOURCE_VERSION,
|
||||
WP4_07_VISUAL_THRESHOLDS,
|
||||
assertWp407Fixture,
|
||||
createWp407CanvasFixture,
|
||||
} from "./wp4-07-fixture.mjs";
|
||||
|
||||
test("FX-CANVAS-50 stays fixed at the normative composition and export size", () => {
|
||||
const contract = assertWp407Fixture();
|
||||
assert.deepEqual(contract.counts, {
|
||||
color_card: 4,
|
||||
dynamic_sticker: 10,
|
||||
static_sticker: 24,
|
||||
text_template: 12,
|
||||
});
|
||||
assert.match(contract.fixture_sha256, /^[0-9A-F]{64}$/);
|
||||
});
|
||||
|
||||
test("visual and performance thresholds cannot be weakened by the harness", () => {
|
||||
assert.deepEqual(WP4_07_VISUAL_THRESHOLDS, {
|
||||
boundary_delta_px_max: 2,
|
||||
channel_delta_significant: 16,
|
||||
significant_pixel_ratio_max: 0.01,
|
||||
});
|
||||
assert.deepEqual(WP4_07_PERFORMANCE_BUDGETS, {
|
||||
autosave_serialization_p95_ms_max: 50,
|
||||
canvas_frame_p95_ms_max: 33,
|
||||
continuous_unresponsive_ms_max_exclusive: 500,
|
||||
editor_reopen_ms_max: 3_000,
|
||||
export_1080x1920_ms_max: 10_000,
|
||||
export_peak_additional_bytes_max: 1_073_741_824,
|
||||
interaction_duration_ms: 10_000,
|
||||
long_task_ms_max: 200,
|
||||
measured_runs: 5,
|
||||
pointer_to_frame_p95_ms_max: 50,
|
||||
warmup_runs: 1,
|
||||
});
|
||||
});
|
||||
|
||||
test("the Red contract resource version is structurally barred from Green", () => {
|
||||
const canvas = createWp407CanvasFixture();
|
||||
assert.equal(new Set(canvas.elements.map((element) => element.resource_version)).size, 1);
|
||||
assert.equal(canvas.elements[0].resource_version, WP4_07_RED_RESOURCE_VERSION);
|
||||
assert.match(WP4_07_RED_RESOURCE_VERSION, /red-contract/);
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { inspectWp5TaskLineage } from "../../scripts/lib/wp4-07-gate.mjs";
|
||||
|
||||
const sha = (digit) => digit.repeat(40);
|
||||
const commit = (index) => ({ sha: sha(String(index)), subject: `feat: complete TASK-WP5-0${index}` });
|
||||
|
||||
test("WP5 lineage recognizes tasks already merged into later remote heads", () => {
|
||||
const gate = inspectWp5TaskLineage({
|
||||
"codex/wp5-03": sha("3"),
|
||||
"codex/wp5-04": sha("4"),
|
||||
}, {
|
||||
"codex/wp5-03": [commit(3), commit(2), commit(1)],
|
||||
"codex/wp5-04": [commit(4), commit(2), commit(1)],
|
||||
});
|
||||
|
||||
assert.equal(gate.complete, false);
|
||||
assert.equal(gate.candidate_baseline_branch, "codex/wp5-04");
|
||||
assert.deepEqual(gate.missing_tasks, ["TASK-WP5-05", "TASK-WP5-06", "TASK-WP5-07"]);
|
||||
assert.equal(gate.task_shas["TASK-WP5-01"], sha("1"));
|
||||
assert.equal(gate.task_shas["TASK-WP5-02"], sha("2"));
|
||||
});
|
||||
|
||||
test("WP5 lineage accepts independently pushed terminal branches without rewriting their heads", () => {
|
||||
const heads = Object.fromEntries(Array.from({ length: 5 }, (_, index) => [`codex/wp5-0${index + 3}`, sha(String(index + 3))]));
|
||||
const histories = {
|
||||
"codex/wp5-03": [commit(3), commit(2), commit(1)],
|
||||
"codex/wp5-04": [commit(4), commit(2), commit(1)],
|
||||
"codex/wp5-05": [commit(5), commit(4), commit(2), commit(1)],
|
||||
"codex/wp5-06": [commit(6), commit(5), commit(4), commit(2), commit(1)],
|
||||
"codex/wp5-07": [commit(7), commit(4), commit(2), commit(1)],
|
||||
};
|
||||
const complete = inspectWp5TaskLineage(heads, histories);
|
||||
const incomplete = inspectWp5TaskLineage(heads, { ...histories, "codex/wp5-03": [commit(2), commit(1)] });
|
||||
|
||||
assert.equal(complete.complete, true);
|
||||
assert.deepEqual(complete.missing_tasks, []);
|
||||
assert.deepEqual(complete.terminal_branch_shas, heads);
|
||||
assert.equal(incomplete.complete, false);
|
||||
assert.deepEqual(incomplete.missing_tasks, ["TASK-WP5-03"]);
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { basename, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||
|
||||
import { WP4_07_REAL_RESOURCE_VERSIONS } from "./wp4-07-fixture.mjs";
|
||||
|
||||
const dynamicFontTemplates = Object.freeze({
|
||||
"15974853bc3294ef68e7e6d58fe74fd7": "DYN002",
|
||||
"46f8336813e4c48d06a1aef294fdccf6": "DYN016",
|
||||
"53ca6b704728520da50c145eabb2e635": "DYN007",
|
||||
cca5efc0e02fb1bf62349bd68ef30fc1: "DYN015",
|
||||
dd25b35dcb7ba4476cbaa9a9592e39e2: "DYN001",
|
||||
e4210c9872f0c279b35273f230809821: "DYN011",
|
||||
f4bfd4132df2d6be97ceabadf3853505: "DYN008",
|
||||
});
|
||||
|
||||
const dynamicImages = Object.freeze({
|
||||
"DYN001-image28": ["DYN001", "image28.png"],
|
||||
"DYN002-image29": ["DYN002", "image29.png"],
|
||||
"DYN003-image30": ["DYN003", "image30.png"],
|
||||
"DYN004-image32": ["DYN004", "image32.png"],
|
||||
"DYN008-backendui0": ["DYN008", "backendui0.png"],
|
||||
"DYN011-backendui0": ["DYN011", "backendui0.png"],
|
||||
"DYN015-imager2": ["DYN015", "imager2_2.png"],
|
||||
"DYN016-image21": ["DYN016", "image21.png"],
|
||||
});
|
||||
|
||||
function sha256(path) {
|
||||
return createHash("sha256").update(readFileSync(path)).digest("hex").toUpperCase();
|
||||
}
|
||||
|
||||
function walkFiles(directory) {
|
||||
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
||||
const path = join(directory, entry.name);
|
||||
return entry.isDirectory() ? walkFiles(path) : [path];
|
||||
});
|
||||
}
|
||||
|
||||
function firstFile(directory, predicate) {
|
||||
const path = walkFiles(directory).find(predicate);
|
||||
if (!path) throw new Error(`WP4_07_REAL_ASSET_FILE_MISSING:${basename(directory)}`);
|
||||
return path;
|
||||
}
|
||||
|
||||
function inside(root, path) {
|
||||
const delta = relative(resolve(root), resolve(path));
|
||||
return delta !== ".." && !delta.startsWith(`..${sep}`) && !isAbsolute(delta);
|
||||
}
|
||||
|
||||
function contentType(path) {
|
||||
const extension = extname(path).toLowerCase();
|
||||
if (extension === ".png") return "image/png";
|
||||
if (extension === ".otf") return "font/otf";
|
||||
if (extension === ".woff") return "font/woff";
|
||||
if (extension === ".woff2") return "font/woff2";
|
||||
return "font/ttf";
|
||||
}
|
||||
|
||||
function assetRecord(assetId, path, sourceReference, expectedSha256) {
|
||||
if (!existsSync(path) || !statSync(path).isFile()) throw new Error(`WP4_07_REAL_ASSET_UNAVAILABLE:${assetId}`);
|
||||
const actualSha256 = sha256(path);
|
||||
if (expectedSha256 && actualSha256 !== expectedSha256) throw new Error(`WP4_07_REAL_ASSET_HASH_MISMATCH:${assetId}`);
|
||||
return {
|
||||
asset_id: assetId,
|
||||
bytes: statSync(path).size,
|
||||
content_type: contentType(path),
|
||||
path,
|
||||
sha256: actualSha256,
|
||||
source_reference: sourceReference,
|
||||
};
|
||||
}
|
||||
|
||||
export function loadWp407RealAssets() {
|
||||
const manifestPath = resolve(process.env.DADA_WP4_07_FINAL_ASSET_MANIFEST ?? "");
|
||||
if (!process.env.DADA_WP4_07_FINAL_ASSET_MANIFEST || !existsSync(manifestPath)) throw new Error("WP4_07_FINAL_ASSET_MANIFEST_REQUIRED");
|
||||
const handoffPath = resolve(process.env.DADA_COMPLEX_ASSET_MANIFEST ?? join(homedir(), "Desktop", "sticker_web_handoff", "sticker_web_catalog_manifest.json"));
|
||||
const staticRoot = resolve(process.env.DADA_STATIC_STICKER_ROOT ?? join(homedir(), "Desktop", "贴纸素材"));
|
||||
const backgroundPath = resolve(process.env.DADA_WP4_07_BACKGROUND_PATH ?? join(homedir(), "Documents", "贴纸脚本", "time_01_input_20260716.png"));
|
||||
if (!existsSync(handoffPath) || !existsSync(staticRoot)) throw new Error("WP4_07_REAL_ARCHIVE_ROOT_REQUIRED");
|
||||
|
||||
const manifestRaw = readFileSync(manifestPath, "utf8");
|
||||
const manifest = JSON.parse(manifestRaw);
|
||||
const handoff = JSON.parse(readFileSync(handoffPath, "utf8"));
|
||||
const collectionRoots = Object.fromEntries(handoff.collections.map((collection) => [collection.id, resolve(collection.root)]));
|
||||
const fontRoot = collectionRoots.font_panel;
|
||||
const dynamicRoot = collectionRoots.interactive_stickers;
|
||||
if (!fontRoot || !dynamicRoot) throw new Error("WP4_07_REAL_ARCHIVE_COLLECTION_REQUIRED");
|
||||
|
||||
const publicAssets = new Map();
|
||||
for (const item of manifest.assets.font_panel_items) {
|
||||
const packageDirectory = resolve(fontRoot, item.canonical_resource_reference.path);
|
||||
if (!inside(fontRoot, packageDirectory)) throw new Error(`WP4_07_UNSAFE_FONT_REFERENCE:${item.canonical_id}`);
|
||||
const path = firstFile(resolve(packageDirectory, "font_files"), (candidate) => /\.(?:otf|ttf|woff2?|ztf)$/i.test(candidate));
|
||||
publicAssets.set(item.canonical_id, assetRecord(item.canonical_id, path, `font_panel/${item.canonical_id}/${basename(path)}`));
|
||||
}
|
||||
|
||||
for (const item of manifest.assets.static_stickers) {
|
||||
const path = resolve(staticRoot, item.relative_path);
|
||||
if (!inside(staticRoot, path)) throw new Error(`WP4_07_UNSAFE_STATIC_REFERENCE:${item.stable_id}`);
|
||||
publicAssets.set(item.stable_id, assetRecord(item.stable_id, path, `static/${item.stable_id}`, item.sha256));
|
||||
}
|
||||
|
||||
for (const [assetId, templateId] of Object.entries(dynamicFontTemplates)) {
|
||||
const directory = resolve(dynamicRoot, "templates", templateId, "fonts", assetId);
|
||||
const path = firstFile(directory, (candidate) => /\.(?:otf|ttf|woff2?|ztf)$/i.test(candidate));
|
||||
publicAssets.set(assetId, assetRecord(assetId, path, `interactive/${templateId}/fonts/${assetId}/${basename(path)}`));
|
||||
}
|
||||
for (const [assetId, [templateId, filename]] of Object.entries(dynamicImages)) {
|
||||
const path = resolve(dynamicRoot, "templates", templateId, "resource", filename);
|
||||
publicAssets.set(assetId, assetRecord(assetId, path, `interactive/${templateId}/resource/${filename}`));
|
||||
}
|
||||
|
||||
const background = assetRecord("private-background", backgroundPath, "private/background/time_01_input_20260716.png");
|
||||
const manifestSha256 = createHash("sha256").update(manifestRaw).digest("hex").toUpperCase();
|
||||
return {
|
||||
background,
|
||||
evidence: {
|
||||
asset_count: publicAssets.size,
|
||||
assets: [...publicAssets.values()].map(({ asset_id, bytes, content_type, sha256: hash, source_reference }) => ({
|
||||
asset_id, bytes, content_type, sha256: hash, source_reference,
|
||||
})),
|
||||
background: { bytes: background.bytes, content_type: background.content_type, sha256: background.sha256, source_reference: background.source_reference },
|
||||
manifest_sha256: manifestSha256,
|
||||
release_version: manifest.release_version,
|
||||
resource_versions: WP4_07_REAL_RESOURCE_VERSIONS,
|
||||
source_mutations: 0,
|
||||
},
|
||||
publicAssets,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user