74 lines
4.3 KiB
JavaScript
74 lines
4.3 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import { copyFileSync, existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
|
|
import { readWp5RemoteGate, validateWp407FrozenInputs, validateWp5FinalManifest } from "./lib/wp4-07-gate.mjs";
|
|
|
|
function findFiles(directory, name) {
|
|
if (!existsSync(directory)) return [];
|
|
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
const path = resolve(directory, entry.name);
|
|
return entry.isDirectory() ? findFiles(path, name) : entry.name === name ? [path] : [];
|
|
});
|
|
}
|
|
|
|
const layer = process.argv[2];
|
|
if (!['visual', 'performance'].includes(layer)) {
|
|
console.error("Usage: node scripts/run-wp4-07-layer.mjs <visual|performance>");
|
|
process.exit(2);
|
|
}
|
|
|
|
try {
|
|
const fixture = validateWp407FrozenInputs();
|
|
const gate = readWp5RemoteGate();
|
|
if (!gate.complete) {
|
|
console.error(JSON.stringify({
|
|
code: "WP4_07_WP5_GATE_INCOMPLETE",
|
|
fixture_sha256: fixture.fixture_sha256,
|
|
layer,
|
|
missing_remote_branches: gate.missing_branches,
|
|
observed_remote_heads: gate.heads,
|
|
status: "red",
|
|
}, null, 2));
|
|
process.exit(1);
|
|
}
|
|
const manifest = validateWp5FinalManifest(process.env.DADA_WP4_07_FINAL_ASSET_MANIFEST);
|
|
if (!process.env.DADA_WP4_07_APP_URL || !process.env.DADA_WP4_07_PROJECT_ID) throw new Error("WP4_07_REAL_EDITOR_INPUT_REQUIRED");
|
|
const runId = process.env.DADA_TDD_RUN_ID ?? `wp4-07-${layer}-${new Date().toISOString().replace(/[^0-9]/g, "")}`;
|
|
const runDirectory = resolve("artifacts", "tdd", runId);
|
|
const casesDirectory = resolve(runDirectory, "cases");
|
|
mkdirSync(casesDirectory, { recursive: true });
|
|
const environment = {
|
|
...process.env,
|
|
DADA_PLAYWRIGHT_OUTPUT_DIR: resolve(runDirectory, "playwright-output"),
|
|
DADA_WP4_07_EVIDENCE_DIR: casesDirectory,
|
|
DADA_WP4_07_HARNESS_MODE: "real",
|
|
DADA_WP4_07_LAYER: layer,
|
|
};
|
|
const build = spawnSync(process.env.ComSpec ?? "cmd.exe", ["/d", "/s", "/c", "pnpm --filter @dada/shared-contracts build && pnpm --filter @dada/static-sticker-catalog build && pnpm --filter @dada/template-registry build && pnpm --filter @dada/asset-renderer build"], { encoding: "utf8", env: environment, maxBuffer: 64 * 1024 * 1024 });
|
|
if (build.stdout) process.stdout.write(build.stdout);
|
|
if (build.stderr) process.stderr.write(build.stderr);
|
|
if ((build.status ?? 1) !== 0) process.exit(build.status ?? 1);
|
|
const playwright = spawnSync(process.env.ComSpec ?? "cmd.exe", ["/d", "/s", "/c", "pnpm exec playwright test --config playwright.wp4-07.config.ts"], { encoding: "utf8", env: environment, maxBuffer: 64 * 1024 * 1024 });
|
|
if (playwright.stdout) process.stdout.write(playwright.stdout);
|
|
if (playwright.stderr) process.stderr.write(playwright.stderr);
|
|
if ((playwright.status ?? 1) !== 0) process.exit(playwright.status ?? 1);
|
|
const caseDirectory = resolve(casesDirectory, layer === "visual" ? "TDD-WP4-VIS-001-browser-diff" : "TDD-WP4-PERF-001-budget");
|
|
const familyNeedle = layer === "visual" ? "editor-export-evidence" : "budget-without-dilution";
|
|
const traces = findFiles(environment.DADA_PLAYWRIGHT_OUTPUT_DIR, "trace.zip");
|
|
for (const browser of ["chrome", "edge"]) {
|
|
const trace = traces.find((path) => path.toLowerCase().includes(familyNeedle) && path.toLowerCase().includes(browser));
|
|
if (!trace) throw new Error(`WP4_07_${layer.toUpperCase()}_${browser.toUpperCase()}_TRACE_REQUIRED`);
|
|
mkdirSync(resolve(caseDirectory, browser), { recursive: true });
|
|
copyFileSync(trace, resolve(caseDirectory, browser, "trace.zip"));
|
|
}
|
|
const aggregator = spawnSync(process.execPath, [layer === "visual" ? "scripts/compare-wp4-07-screenshots.mjs" : "scripts/aggregate-wp4-07-performance.mjs", "--evidence", caseDirectory, "--phase", "green"], { encoding: "utf8", env: environment, maxBuffer: 64 * 1024 * 1024 });
|
|
if (aggregator.stdout) process.stdout.write(aggregator.stdout);
|
|
if (aggregator.stderr) process.stderr.write(aggregator.stderr);
|
|
if ((aggregator.status ?? 1) !== 0) process.exit(aggregator.status ?? 1);
|
|
console.log(JSON.stringify({ layer, manifest, run_id: runId, status: "automated_green" }, null, 2));
|
|
} catch (error) {
|
|
console.error(JSON.stringify({ code: error instanceof Error ? error.message : String(error), layer, status: "failed" }, null, 2));
|
|
process.exit(1);
|
|
}
|