test(templates): keep sweep evidence outside source

This commit is contained in:
2026-10-06 14:20:33 +08:00
parent a601bc46a9
commit 1d8015d552
@@ -3,8 +3,6 @@ const { chromium } = require("playwright");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const REPO_ROOT = path.resolve(__dirname, "..", "..");
function parseArgs(argv) { function parseArgs(argv) {
const args = { const args = {
baseUrl: "http://localhost:3000", baseUrl: "http://localhost:3000",
@@ -12,7 +10,7 @@ function parseArgs(argv) {
expectedCount: 60, expectedCount: 60,
selection: "draftable", selection: "draftable",
templateId: "", templateId: "",
outputDir: "", outputDir: process.env.YUQEI_TEMPLATE_SWEEP_OUTPUT_DIR || "",
screenshots: "all", screenshots: "all",
browserExecutable: "", browserExecutable: "",
email: process.env.YUQEI_TEST_EMAIL || "", email: process.env.YUQEI_TEST_EMAIL || "",
@@ -93,7 +91,7 @@ Options:
--expected-count <n> Expected selected template count. Default: 60 --expected-count <n> Expected selected template count. Default: 60
--selection <mode> draftable | published. Default: draftable --selection <mode> draftable | published. Default: draftable
--template-id <id> Restrict the sweep to one template while retaining the full catalog UI assertion. --template-id <id> Restrict the sweep to one template while retaining the full catalog UI assertion.
--output-dir <path> Artifact directory. Default: output/playwright/template-draft-sweep/<timestamp> --output-dir <path> Required external artifact directory (or set YUQEI_TEMPLATE_SWEEP_OUTPUT_DIR).
--screenshots <mode> all | failures | none. Default: all --screenshots <mode> all | failures | none. Default: all
--browser-executable <path> Use an installed Chromium browser instead of Playwright's bundled browser. --browser-executable <path> Use an installed Chromium browser instead of Playwright's bundled browser.
YUQEI_TEST_EMAIL/PASSWORD Optional authenticated test account; both environment variables are required together. YUQEI_TEST_EMAIL/PASSWORD Optional authenticated test account; both environment variables are required together.
@@ -102,20 +100,15 @@ Options:
`); `);
} }
function nowStamp() {
const value = new Date().toISOString().replace(/[:.]/g, "-");
return value.replace("Z", "");
}
function normalizeBaseUrl(value) { function normalizeBaseUrl(value) {
return value.replace(/\/+$/, ""); return value.replace(/\/+$/, "");
} }
function resolveOutputDir(value) { function resolveOutputDir(value) {
if (value) { if (!value) {
return path.isAbsolute(value) ? value : path.resolve(REPO_ROOT, value); throw new Error("--output-dir or YUQEI_TEMPLATE_SWEEP_OUTPUT_DIR is required; store raw sweep evidence outside the source worktree.");
} }
return path.resolve(REPO_ROOT, "output", "playwright", "template-draft-sweep", nowStamp()); return path.isAbsolute(value) ? value : path.resolve(value);
} }
async function fetchJson(url) { async function fetchJson(url) {