@blazediff/agent 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +379 -363
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +64 -85
- package/dist/index.mjs +64 -85
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ var playwright = require('playwright');
|
|
|
6
6
|
var child_process = require('child_process');
|
|
7
7
|
var fs = require('fs');
|
|
8
8
|
var module$1 = require('module');
|
|
9
|
-
var
|
|
9
|
+
var path26 = require('path');
|
|
10
10
|
var promises = require('fs/promises');
|
|
11
11
|
var os = require('os');
|
|
12
12
|
var url = require('url');
|
|
@@ -16,10 +16,10 @@ var sharp = require('sharp');
|
|
|
16
16
|
var pc = require('picocolors');
|
|
17
17
|
var langgraphCheckpoint = require('@langchain/langgraph-checkpoint');
|
|
18
18
|
var coreNative = require('@blazediff/core-native');
|
|
19
|
-
var promises$1 = require('readline/promises');
|
|
20
19
|
var net = require('net');
|
|
21
20
|
var util = require('util');
|
|
22
21
|
var treeKill = require('tree-kill');
|
|
22
|
+
var promises$1 = require('readline/promises');
|
|
23
23
|
var http = require('http');
|
|
24
24
|
|
|
25
25
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -43,7 +43,7 @@ function _interopNamespace(e) {
|
|
|
43
43
|
return Object.freeze(n);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
var
|
|
46
|
+
var path26__default = /*#__PURE__*/_interopDefault(path26);
|
|
47
47
|
var sharp__default = /*#__PURE__*/_interopDefault(sharp);
|
|
48
48
|
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
49
49
|
var util__namespace = /*#__PURE__*/_interopNamespace(util);
|
|
@@ -51,7 +51,7 @@ var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
|
|
|
51
51
|
|
|
52
52
|
// package.json
|
|
53
53
|
var package_default = {
|
|
54
|
-
version: "0.
|
|
54
|
+
version: "0.7.0"};
|
|
55
55
|
var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
|
|
56
56
|
var STABILITY_CSS = `
|
|
57
57
|
*,*::before,*::after{
|
|
@@ -246,10 +246,10 @@ async function applyMaskOverlays(page, masks) {
|
|
|
246
246
|
function resolvePlaywrightCli() {
|
|
247
247
|
const require_ = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href)));
|
|
248
248
|
const pkgJson = require_.resolve("playwright/package.json");
|
|
249
|
-
const dir =
|
|
249
|
+
const dir = path26__default.default.dirname(pkgJson);
|
|
250
250
|
const candidates = [
|
|
251
|
-
|
|
252
|
-
|
|
251
|
+
path26__default.default.join(dir, "cli.js"),
|
|
252
|
+
path26__default.default.join(dir, "lib", "cli.js")
|
|
253
253
|
];
|
|
254
254
|
const found = candidates.find((p) => fs.existsSync(p));
|
|
255
255
|
if (!found) {
|
|
@@ -326,20 +326,20 @@ function defaultConcurrency() {
|
|
|
326
326
|
}
|
|
327
327
|
var BLAZEDIFF_DIR = ".blazediff";
|
|
328
328
|
var paths = (cwd = process.cwd()) => {
|
|
329
|
-
const root =
|
|
329
|
+
const root = path26__default.default.join(cwd, BLAZEDIFF_DIR);
|
|
330
330
|
return {
|
|
331
331
|
root,
|
|
332
|
-
config:
|
|
333
|
-
manifest:
|
|
334
|
-
harnesses:
|
|
335
|
-
baselines:
|
|
336
|
-
actual:
|
|
337
|
-
judgments:
|
|
338
|
-
checkpoints:
|
|
339
|
-
report:
|
|
340
|
-
gitignore:
|
|
341
|
-
serverLog:
|
|
342
|
-
serverPid:
|
|
332
|
+
config: path26__default.default.join(root, "config.json"),
|
|
333
|
+
manifest: path26__default.default.join(root, "manifest.json"),
|
|
334
|
+
harnesses: path26__default.default.join(root, "harnesses"),
|
|
335
|
+
baselines: path26__default.default.join(root, "baselines"),
|
|
336
|
+
actual: path26__default.default.join(root, "actual"),
|
|
337
|
+
judgments: path26__default.default.join(root, "judgments"),
|
|
338
|
+
checkpoints: path26__default.default.join(root, "checkpoints"),
|
|
339
|
+
report: path26__default.default.join(root, "report.json"),
|
|
340
|
+
gitignore: path26__default.default.join(root, ".gitignore"),
|
|
341
|
+
serverLog: path26__default.default.join(root, "dev-server.log"),
|
|
342
|
+
serverPid: path26__default.default.join(root, "dev-server.pid")
|
|
343
343
|
};
|
|
344
344
|
};
|
|
345
345
|
|
|
@@ -353,16 +353,16 @@ var HarnessError = class extends Error {
|
|
|
353
353
|
};
|
|
354
354
|
var moduleCache = /* @__PURE__ */ new Map();
|
|
355
355
|
function resolveHarnessFile(name, cwd) {
|
|
356
|
-
if (name.includes("/") || name.includes("\\") ||
|
|
357
|
-
return
|
|
356
|
+
if (name.includes("/") || name.includes("\\") || path26__default.default.isAbsolute(name)) {
|
|
357
|
+
return path26__default.default.isAbsolute(name) ? name : path26__default.default.resolve(cwd, name);
|
|
358
358
|
}
|
|
359
359
|
const dir = paths(cwd).harnesses;
|
|
360
|
-
const mjs =
|
|
360
|
+
const mjs = path26__default.default.join(dir, `${name}.mjs`);
|
|
361
361
|
if (fs.existsSync(mjs)) return mjs;
|
|
362
|
-
return
|
|
362
|
+
return path26__default.default.join(dir, `${name}.js`);
|
|
363
363
|
}
|
|
364
364
|
async function loadHarness(harnessFile) {
|
|
365
|
-
const absolute =
|
|
365
|
+
const absolute = path26__default.default.isAbsolute(harnessFile) ? harnessFile : path26__default.default.resolve(process.cwd(), harnessFile);
|
|
366
366
|
if (!fs.existsSync(absolute)) {
|
|
367
367
|
throw new HarnessError(
|
|
368
368
|
`harness not found at ${absolute}. Author one under .blazediff/harnesses/ (or run \`blazediff-agent harness record <name>\` to record one).`
|
|
@@ -404,7 +404,7 @@ async function loadHarness(harnessFile) {
|
|
|
404
404
|
// src/browser/capture.ts
|
|
405
405
|
var SCREENSHOT_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/i;
|
|
406
406
|
async function shoot(page, outputPath, fullPage) {
|
|
407
|
-
await promises.mkdir(
|
|
407
|
+
await promises.mkdir(path26__default.default.dirname(outputPath), { recursive: true });
|
|
408
408
|
const buffer = await page.screenshot({
|
|
409
409
|
path: outputPath,
|
|
410
410
|
type: "png",
|
|
@@ -457,7 +457,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
457
457
|
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 3e4 });
|
|
458
458
|
await stabilize(page, waitFor, masks);
|
|
459
459
|
const outputDir = opts.mode === "baseline" ? paths(cwd).baselines : paths(cwd).actual;
|
|
460
|
-
const outputPath =
|
|
460
|
+
const outputPath = path26__default.default.join(outputDir, `${opts.id}.png`);
|
|
461
461
|
const bytes = await shoot(page, outputPath, fullPage);
|
|
462
462
|
const subCaptures = [];
|
|
463
463
|
const used = /* @__PURE__ */ new Set();
|
|
@@ -472,7 +472,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
472
472
|
}
|
|
473
473
|
used.add(name);
|
|
474
474
|
await stabilize(page, waitFor, masks);
|
|
475
|
-
const subPath =
|
|
475
|
+
const subPath = path26__default.default.join(outputDir, `${opts.id}__${name}.png`);
|
|
476
476
|
const subBytes = await shoot(page, subPath, fullPage);
|
|
477
477
|
subCaptures.push({ name, outputPath: subPath, bytes: subBytes });
|
|
478
478
|
};
|
|
@@ -499,7 +499,7 @@ async function loadConfig(cwd = process.cwd()) {
|
|
|
499
499
|
}
|
|
500
500
|
async function saveConfig(config, cwd = process.cwd()) {
|
|
501
501
|
const file = paths(cwd).config;
|
|
502
|
-
await promises.mkdir(
|
|
502
|
+
await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
|
|
503
503
|
await promises.writeFile(file, `${JSON.stringify(config, null, 2)}
|
|
504
504
|
`, "utf8");
|
|
505
505
|
}
|
|
@@ -557,7 +557,7 @@ async function loadManifest(cwd = process.cwd()) {
|
|
|
557
557
|
}
|
|
558
558
|
async function saveManifest(manifest, cwd = process.cwd()) {
|
|
559
559
|
const file = paths(cwd).manifest;
|
|
560
|
-
await promises.mkdir(
|
|
560
|
+
await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
|
|
561
561
|
await promises.writeFile(file, `${JSON.stringify(manifest, null, 2)}
|
|
562
562
|
`, "utf8");
|
|
563
563
|
}
|
|
@@ -598,7 +598,7 @@ function makeEntry(input) {
|
|
|
598
598
|
fullPage,
|
|
599
599
|
parent: input.parent,
|
|
600
600
|
derived: input.derived || void 0,
|
|
601
|
-
baselinePath:
|
|
601
|
+
baselinePath: path26__default.default.posix.join(".blazediff", "baselines", `${input.id}.png`),
|
|
602
602
|
captureHash: hashMaterial({
|
|
603
603
|
url: input.url,
|
|
604
604
|
viewport,
|
|
@@ -873,7 +873,7 @@ async function resolveRoutes(opts) {
|
|
|
873
873
|
}
|
|
874
874
|
if (opts.routes) {
|
|
875
875
|
return parseRoutesPayload(
|
|
876
|
-
await promises.readFile(
|
|
876
|
+
await promises.readFile(path26__default.default.resolve(opts.routes), "utf8")
|
|
877
877
|
);
|
|
878
878
|
}
|
|
879
879
|
if (opts.stdin) {
|
|
@@ -952,7 +952,7 @@ var STALE_ENTRIES = /* @__PURE__ */ new Set([
|
|
|
952
952
|
var HEADER = "# blazediff: generated artifacts (committed: config.json, manifest.json, baselines/, harnesses/)\n";
|
|
953
953
|
async function ensureGitignore(cwd) {
|
|
954
954
|
const file = paths(cwd).gitignore;
|
|
955
|
-
await promises.mkdir(
|
|
955
|
+
await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
|
|
956
956
|
const existing = fs.existsSync(file) ? await promises.readFile(file, "utf8") : "";
|
|
957
957
|
const lines = existing.split("\n").map((l) => l.trim());
|
|
958
958
|
const hasStale = lines.some((l) => STALE_ENTRIES.has(l));
|
|
@@ -1048,8 +1048,8 @@ async function prepareRegionReads(opts) {
|
|
|
1048
1048
|
const name = `read-${i}.${suffix}.png`;
|
|
1049
1049
|
await sharp__default.default(src).extract(extract).resize(extract.width * scale, extract.height * scale, {
|
|
1050
1050
|
kernel: "lanczos3"
|
|
1051
|
-
}).png().toFile(
|
|
1052
|
-
return
|
|
1051
|
+
}).png().toFile(path26__default.default.join(opts.outputDir, name));
|
|
1052
|
+
return path26__default.default.join(opts.outputDir, name);
|
|
1053
1053
|
};
|
|
1054
1054
|
const [beforePath, afterPath] = await Promise.all([
|
|
1055
1055
|
render(opts.baselinePath, "before"),
|
|
@@ -1117,7 +1117,7 @@ async function prepareTiles(opts) {
|
|
|
1117
1117
|
channels: 3,
|
|
1118
1118
|
background: BG_WHITE
|
|
1119
1119
|
}
|
|
1120
|
-
}).composite(composites).png().toFile(
|
|
1120
|
+
}).composite(composites).png().toFile(path26__default.default.join(opts.outputDir, tilesName));
|
|
1121
1121
|
}
|
|
1122
1122
|
let locatorName;
|
|
1123
1123
|
if (opts.diffPath) {
|
|
@@ -1133,7 +1133,7 @@ async function prepareTiles(opts) {
|
|
|
1133
1133
|
}).join("");
|
|
1134
1134
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${locW}" height="${locH}">${rects}</svg>`;
|
|
1135
1135
|
locatorName = "locator.png";
|
|
1136
|
-
await sharp__default.default(opts.diffPath).resize(locW, locH, { fit: "fill" }).composite([{ input: Buffer.from(svg), left: 0, top: 0 }]).png().toFile(
|
|
1136
|
+
await sharp__default.default(opts.diffPath).resize(locW, locH, { fit: "fill" }).composite([{ input: Buffer.from(svg), left: 0, top: 0 }]).png().toFile(path26__default.default.join(opts.outputDir, locatorName));
|
|
1137
1137
|
}
|
|
1138
1138
|
return {
|
|
1139
1139
|
locatorPath: locatorName,
|
|
@@ -1171,7 +1171,7 @@ var codingAgentHostJudge = {
|
|
|
1171
1171
|
async judge(input, cwd) {
|
|
1172
1172
|
input.onJudgingStart?.();
|
|
1173
1173
|
const p = paths(cwd);
|
|
1174
|
-
const entryDir =
|
|
1174
|
+
const entryDir = path26__default.default.join(p.judgments, input.entry.id);
|
|
1175
1175
|
await promises.mkdir(entryDir, { recursive: true });
|
|
1176
1176
|
await tryPrepareTiles(input, entryDir);
|
|
1177
1177
|
return { kind: "deferred", requestPath: entryDir };
|
|
@@ -1194,7 +1194,7 @@ function statusGlyph(status) {
|
|
|
1194
1194
|
}
|
|
1195
1195
|
function relPath(p, cwd = process.cwd()) {
|
|
1196
1196
|
if (!p) return p;
|
|
1197
|
-
const rel =
|
|
1197
|
+
const rel = path26__default.default.relative(cwd, p);
|
|
1198
1198
|
return rel && !rel.startsWith("..") ? rel : p;
|
|
1199
1199
|
}
|
|
1200
1200
|
|
|
@@ -1721,7 +1721,7 @@ function createLocalJudge(deps = {}) {
|
|
|
1721
1721
|
await Promise.all([vision.get(), classifier.get()]);
|
|
1722
1722
|
},
|
|
1723
1723
|
async judge(input, cwd) {
|
|
1724
|
-
const entryDir =
|
|
1724
|
+
const entryDir = path26__default.default.join(paths(cwd).judgments, input.entry.id);
|
|
1725
1725
|
await promises.mkdir(entryDir, { recursive: true });
|
|
1726
1726
|
try {
|
|
1727
1727
|
const description = await visionSemaphore.run(async () => {
|
|
@@ -1796,7 +1796,7 @@ async function readJsonOrNull(file) {
|
|
|
1796
1796
|
// src/report/json.ts
|
|
1797
1797
|
async function writeReport(report, cwd = process.cwd()) {
|
|
1798
1798
|
const file = paths(cwd).report;
|
|
1799
|
-
await promises.mkdir(
|
|
1799
|
+
await promises.mkdir(path26__default.default.dirname(file), { recursive: true });
|
|
1800
1800
|
await promises.writeFile(file, `${JSON.stringify(report, null, 2)}
|
|
1801
1801
|
`, "utf8");
|
|
1802
1802
|
return file;
|
|
@@ -1850,7 +1850,7 @@ async function readJudgmentDirs(root) {
|
|
|
1850
1850
|
}
|
|
1851
1851
|
const out = [];
|
|
1852
1852
|
for (const name of names) {
|
|
1853
|
-
const dir =
|
|
1853
|
+
const dir = path26__default.default.join(root, name);
|
|
1854
1854
|
let isDir = false;
|
|
1855
1855
|
try {
|
|
1856
1856
|
isDir = (await promises.stat(dir)).isDirectory();
|
|
@@ -1859,9 +1859,9 @@ async function readJudgmentDirs(root) {
|
|
|
1859
1859
|
}
|
|
1860
1860
|
if (!isDir) continue;
|
|
1861
1861
|
const request = await readJsonOrNull(
|
|
1862
|
-
|
|
1862
|
+
path26__default.default.join(dir, "request.json")
|
|
1863
1863
|
);
|
|
1864
|
-
const verdictFile =
|
|
1864
|
+
const verdictFile = path26__default.default.join(dir, "verdict.json");
|
|
1865
1865
|
let verdict = null;
|
|
1866
1866
|
let verdictInvalid = false;
|
|
1867
1867
|
if (await fileExists(verdictFile)) {
|
|
@@ -1875,7 +1875,7 @@ async function readJudgmentDirs(root) {
|
|
|
1875
1875
|
}
|
|
1876
1876
|
function toAbs(cwd, rel) {
|
|
1877
1877
|
if (!rel) return void 0;
|
|
1878
|
-
return
|
|
1878
|
+
return path26__default.default.isAbsolute(rel) ? rel : path26__default.default.join(cwd, rel);
|
|
1879
1879
|
}
|
|
1880
1880
|
function fromDiskResult(cwd, dir, entry) {
|
|
1881
1881
|
const req = dir.request;
|
|
@@ -1897,8 +1897,8 @@ function fromDiskResult(cwd, dir, entry) {
|
|
|
1897
1897
|
};
|
|
1898
1898
|
}
|
|
1899
1899
|
async function passResultFromDisk(entry, cwd) {
|
|
1900
|
-
const baselineAbs =
|
|
1901
|
-
const actualAbs =
|
|
1900
|
+
const baselineAbs = path26__default.default.join(paths(cwd).baselines, `${entry.id}.png`);
|
|
1901
|
+
const actualAbs = path26__default.default.join(paths(cwd).actual, `${entry.id}.png`);
|
|
1902
1902
|
return {
|
|
1903
1903
|
id: entry.id,
|
|
1904
1904
|
url: entry.url,
|
|
@@ -1942,7 +1942,7 @@ async function reconstructFromDisk(cwd, dirs) {
|
|
|
1942
1942
|
return report;
|
|
1943
1943
|
}
|
|
1944
1944
|
async function hasCheckpoint(cwd, threadId) {
|
|
1945
|
-
const dir =
|
|
1945
|
+
const dir = path26__default.default.join(paths(cwd).checkpoints, threadId);
|
|
1946
1946
|
try {
|
|
1947
1947
|
const names = await promises.readdir(dir);
|
|
1948
1948
|
return names.length > 0;
|
|
@@ -1965,7 +1965,7 @@ async function applyJudgments(opts = {}) {
|
|
|
1965
1965
|
const verdicts = {};
|
|
1966
1966
|
for (const d of dirs) {
|
|
1967
1967
|
if (d.verdictInvalid) {
|
|
1968
|
-
invalid.push(
|
|
1968
|
+
invalid.push(path26__default.default.join(paths(cwd).judgments, d.id));
|
|
1969
1969
|
continue;
|
|
1970
1970
|
}
|
|
1971
1971
|
if (d.verdict) {
|
|
@@ -2001,7 +2001,7 @@ var HOST_INSTRUCTIONS = [
|
|
|
2001
2001
|
].join("\n");
|
|
2002
2002
|
function relTo(cwd, abs) {
|
|
2003
2003
|
if (!abs) return void 0;
|
|
2004
|
-
return
|
|
2004
|
+
return path26__default.default.relative(cwd, abs).split(path26__default.default.sep).join("/");
|
|
2005
2005
|
}
|
|
2006
2006
|
function signatureOf(r) {
|
|
2007
2007
|
const pct = typeof r.diffPercentage === "number" ? r.diffPercentage.toFixed(4) : "?";
|
|
@@ -2054,8 +2054,8 @@ function autoVerdict(result) {
|
|
|
2054
2054
|
};
|
|
2055
2055
|
}
|
|
2056
2056
|
async function discoverTiles(dir) {
|
|
2057
|
-
const locatorAbs =
|
|
2058
|
-
const tilesAbs =
|
|
2057
|
+
const locatorAbs = path26__default.default.join(dir, "locator.png");
|
|
2058
|
+
const tilesAbs = path26__default.default.join(dir, "regions.png");
|
|
2059
2059
|
const [locator, tiles] = await Promise.all([
|
|
2060
2060
|
fileExists(locatorAbs),
|
|
2061
2061
|
fileExists(tilesAbs)
|
|
@@ -2073,7 +2073,7 @@ async function writeJudgments(opts) {
|
|
|
2073
2073
|
for (const r of opts.report.results) knownIds.add(r.id);
|
|
2074
2074
|
await Promise.all(
|
|
2075
2075
|
opts.report.results.map(async (result) => {
|
|
2076
|
-
const dir =
|
|
2076
|
+
const dir = path26__default.default.join(root, result.id);
|
|
2077
2077
|
if (result.status === "pass") {
|
|
2078
2078
|
if (await fileExists(dir))
|
|
2079
2079
|
await promises.rm(dir, { recursive: true, force: true });
|
|
@@ -2084,8 +2084,8 @@ async function writeJudgments(opts) {
|
|
|
2084
2084
|
await promises.mkdir(dir, { recursive: true });
|
|
2085
2085
|
const tiles = await discoverTiles(dir);
|
|
2086
2086
|
const request = buildRequest(result, entry, cwd, tiles);
|
|
2087
|
-
const requestFile =
|
|
2088
|
-
const verdictFile =
|
|
2087
|
+
const requestFile = path26__default.default.join(dir, "request.json");
|
|
2088
|
+
const verdictFile = path26__default.default.join(dir, "verdict.json");
|
|
2089
2089
|
const [prior, priorVerdict] = await Promise.all([
|
|
2090
2090
|
readJsonOrNull(requestFile),
|
|
2091
2091
|
fileExists(verdictFile).then(
|
|
@@ -2123,7 +2123,7 @@ async function writeJudgments(opts) {
|
|
|
2123
2123
|
}
|
|
2124
2124
|
await Promise.all(
|
|
2125
2125
|
entries.filter((name) => !knownIds.has(name)).map(
|
|
2126
|
-
(name) => promises.rm(
|
|
2126
|
+
(name) => promises.rm(path26__default.default.join(root, name), { recursive: true, force: true })
|
|
2127
2127
|
)
|
|
2128
2128
|
);
|
|
2129
2129
|
}
|
|
@@ -2143,7 +2143,7 @@ function escapeXml(value) {
|
|
|
2143
2143
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2144
2144
|
}
|
|
2145
2145
|
async function writeJunit(report, destPath) {
|
|
2146
|
-
await promises.mkdir(
|
|
2146
|
+
await promises.mkdir(path26__default.default.dirname(destPath), { recursive: true });
|
|
2147
2147
|
const cases = report.results.map((r) => {
|
|
2148
2148
|
if (r.status === "pass") {
|
|
2149
2149
|
return ` <testcase classname="blazediff" name="${escapeXml(r.id)}"/>`;
|
|
@@ -2195,16 +2195,16 @@ var FsCheckpointSaver = class extends langgraphCheckpoint.BaseCheckpointSaver {
|
|
|
2195
2195
|
this.root = root;
|
|
2196
2196
|
}
|
|
2197
2197
|
threadDir(thread) {
|
|
2198
|
-
return
|
|
2198
|
+
return path26__default.default.join(this.root, thread);
|
|
2199
2199
|
}
|
|
2200
2200
|
nsPath(thread, ns) {
|
|
2201
|
-
return
|
|
2201
|
+
return path26__default.default.join(this.threadDir(thread), nsDir(ns));
|
|
2202
2202
|
}
|
|
2203
2203
|
ckptFile(thread, ns, id) {
|
|
2204
|
-
return
|
|
2204
|
+
return path26__default.default.join(this.nsPath(thread, ns), `${id}.ckpt.json`);
|
|
2205
2205
|
}
|
|
2206
2206
|
writesFile(thread, ns, id) {
|
|
2207
|
-
return
|
|
2207
|
+
return path26__default.default.join(this.nsPath(thread, ns), `${id}.writes.json`);
|
|
2208
2208
|
}
|
|
2209
2209
|
async withLock(key, fn) {
|
|
2210
2210
|
const prev = this.locks.get(key) ?? Promise.resolve();
|
|
@@ -2558,7 +2558,7 @@ function makeCaptureNode(semaphore) {
|
|
|
2558
2558
|
} catch (err) {
|
|
2559
2559
|
return failAll(`harness: ${err.message}`);
|
|
2560
2560
|
}
|
|
2561
|
-
const baselinePath =
|
|
2561
|
+
const baselinePath = path26__default.default.join(options.baselinesDir, `${entry.id}.png`);
|
|
2562
2562
|
try {
|
|
2563
2563
|
const capture = await semaphore.run(
|
|
2564
2564
|
() => captureScreenshot(
|
|
@@ -2589,7 +2589,7 @@ function makeCaptureNode(semaphore) {
|
|
|
2589
2589
|
for (const child of children) {
|
|
2590
2590
|
const name = subNameOf(child);
|
|
2591
2591
|
const sub = name ? subByName.get(name) : void 0;
|
|
2592
|
-
const childBaseline =
|
|
2592
|
+
const childBaseline = path26__default.default.join(
|
|
2593
2593
|
options.baselinesDir,
|
|
2594
2594
|
`${child.id}.png`
|
|
2595
2595
|
);
|
|
@@ -2652,7 +2652,7 @@ async function diffEntry(id, baselinePath, actualPath, opts = {}, cwd = process.
|
|
|
2652
2652
|
if (opts.emitDiffPng) {
|
|
2653
2653
|
const actualDir = paths(cwd).actual;
|
|
2654
2654
|
await promises.mkdir(actualDir, { recursive: true });
|
|
2655
|
-
diffPath =
|
|
2655
|
+
diffPath = path26__default.default.join(actualDir, `${id}.diff.png`);
|
|
2656
2656
|
}
|
|
2657
2657
|
const threshold = opts.threshold ?? DEFAULT_THRESHOLD;
|
|
2658
2658
|
const antialiasing = opts.antialiasing ?? true;
|
|
@@ -3184,7 +3184,7 @@ async function runGraph(opts) {
|
|
|
3184
3184
|
}
|
|
3185
3185
|
const report = collect.report ?? await buildPartialReport(collect, cwd);
|
|
3186
3186
|
if (opts.junitPath) {
|
|
3187
|
-
const target =
|
|
3187
|
+
const target = path26__default.default.isAbsolute(opts.junitPath) ? opts.junitPath : path26__default.default.join(cwd, opts.junitPath);
|
|
3188
3188
|
await writeJunit(report, target);
|
|
3189
3189
|
}
|
|
3190
3190
|
if (collect.interrupts.length === 0) {
|
|
@@ -3201,6 +3201,170 @@ async function resumeGraph(opts) {
|
|
|
3201
3201
|
junitPath: opts.junitPath
|
|
3202
3202
|
});
|
|
3203
3203
|
}
|
|
3204
|
+
var execFileP = util.promisify(child_process.execFile);
|
|
3205
|
+
async function isPortOpen(port, host = "127.0.0.1") {
|
|
3206
|
+
return new Promise((resolve) => {
|
|
3207
|
+
const socket = net.createConnection({ port, host });
|
|
3208
|
+
socket.setTimeout(500);
|
|
3209
|
+
socket.once("connect", () => {
|
|
3210
|
+
socket.destroy();
|
|
3211
|
+
resolve(true);
|
|
3212
|
+
});
|
|
3213
|
+
socket.once("error", () => resolve(false));
|
|
3214
|
+
socket.once("timeout", () => {
|
|
3215
|
+
socket.destroy();
|
|
3216
|
+
resolve(false);
|
|
3217
|
+
});
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
async function waitForPort(port, timeoutMs = 6e4) {
|
|
3221
|
+
const deadline = Date.now() + timeoutMs;
|
|
3222
|
+
while (Date.now() < deadline) {
|
|
3223
|
+
if (await isPortOpen(port)) return;
|
|
3224
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
3225
|
+
}
|
|
3226
|
+
throw new Error(`dev server did not open port ${port} within ${timeoutMs}ms`);
|
|
3227
|
+
}
|
|
3228
|
+
async function findPidByPort(port) {
|
|
3229
|
+
const platform = process.platform;
|
|
3230
|
+
try {
|
|
3231
|
+
if (platform === "darwin" || platform === "linux") {
|
|
3232
|
+
const { stdout } = await execFileP("lsof", [
|
|
3233
|
+
"-ti",
|
|
3234
|
+
`tcp:${port}`,
|
|
3235
|
+
"-sTCP:LISTEN"
|
|
3236
|
+
]);
|
|
3237
|
+
const pid = Number(stdout.trim().split("\n")[0]);
|
|
3238
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
3239
|
+
}
|
|
3240
|
+
if (platform === "win32") {
|
|
3241
|
+
const { stdout } = await execFileP("netstat", ["-ano"]);
|
|
3242
|
+
const line = stdout.split(/\r?\n/).find((l) => l.includes(`:${port} `) && l.includes("LISTENING"));
|
|
3243
|
+
if (!line) return null;
|
|
3244
|
+
const parts = line.trim().split(/\s+/);
|
|
3245
|
+
const pid = Number(parts[parts.length - 1]);
|
|
3246
|
+
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
3247
|
+
}
|
|
3248
|
+
} catch {
|
|
3249
|
+
return null;
|
|
3250
|
+
}
|
|
3251
|
+
return null;
|
|
3252
|
+
}
|
|
3253
|
+
async function startServer(opts) {
|
|
3254
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
3255
|
+
const logPath = opts.logPath ?? paths(cwd).serverLog;
|
|
3256
|
+
const pidPath = opts.pidPath ?? paths(cwd).serverPid;
|
|
3257
|
+
await promises.mkdir(path26__default.default.dirname(logPath), { recursive: true });
|
|
3258
|
+
if (await isPortOpen(opts.port)) {
|
|
3259
|
+
const discoveredPid = await findPidByPort(opts.port);
|
|
3260
|
+
if (discoveredPid) {
|
|
3261
|
+
await promises.writeFile(pidPath, String(discoveredPid), "utf8").catch(() => {
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
return {
|
|
3265
|
+
pid: discoveredPid ?? 0,
|
|
3266
|
+
port: opts.port,
|
|
3267
|
+
url: `http://127.0.0.1:${opts.port}`,
|
|
3268
|
+
attached: true
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
const child = child_process.spawn(opts.command, {
|
|
3272
|
+
cwd,
|
|
3273
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3274
|
+
detached: true,
|
|
3275
|
+
shell: true,
|
|
3276
|
+
env: { ...process.env, FORCE_COLOR: "0", CI: "1" }
|
|
3277
|
+
});
|
|
3278
|
+
const logStream = await import('fs').then(
|
|
3279
|
+
(m) => m.createWriteStream(logPath, { flags: "a" })
|
|
3280
|
+
);
|
|
3281
|
+
child.stdout?.pipe(logStream);
|
|
3282
|
+
child.stderr?.pipe(logStream);
|
|
3283
|
+
if (!child.pid) throw new Error("failed to spawn dev server");
|
|
3284
|
+
await promises.writeFile(pidPath, String(child.pid), "utf8");
|
|
3285
|
+
installSignalHandlers(child);
|
|
3286
|
+
try {
|
|
3287
|
+
await waitForPort(opts.port, opts.readyTimeoutMs ?? 6e4);
|
|
3288
|
+
} catch (err) {
|
|
3289
|
+
await stopProcess(child.pid);
|
|
3290
|
+
throw err;
|
|
3291
|
+
}
|
|
3292
|
+
return {
|
|
3293
|
+
pid: child.pid,
|
|
3294
|
+
port: opts.port,
|
|
3295
|
+
url: `http://127.0.0.1:${opts.port}`
|
|
3296
|
+
};
|
|
3297
|
+
}
|
|
3298
|
+
async function stopServer(cwd = process.cwd(), portFallback) {
|
|
3299
|
+
const pidPath = paths(cwd).serverPid;
|
|
3300
|
+
let pid = null;
|
|
3301
|
+
let via = "none";
|
|
3302
|
+
if (fs.existsSync(pidPath)) {
|
|
3303
|
+
const raw = (await promises.readFile(pidPath, "utf8")).trim();
|
|
3304
|
+
const parsed = Number(raw);
|
|
3305
|
+
if (Number.isFinite(parsed) && parsed > 0 && processExists(parsed)) {
|
|
3306
|
+
pid = parsed;
|
|
3307
|
+
via = "pidfile";
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
if (!pid && portFallback) {
|
|
3311
|
+
pid = await findPidByPort(portFallback);
|
|
3312
|
+
if (pid) via = "port";
|
|
3313
|
+
}
|
|
3314
|
+
if (!pid) {
|
|
3315
|
+
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
3316
|
+
});
|
|
3317
|
+
return { killed: false, pid: null, via: "none" };
|
|
3318
|
+
}
|
|
3319
|
+
await stopProcess(pid);
|
|
3320
|
+
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
3321
|
+
});
|
|
3322
|
+
return { killed: true, pid, via };
|
|
3323
|
+
}
|
|
3324
|
+
function processExists(pid) {
|
|
3325
|
+
try {
|
|
3326
|
+
process.kill(pid, 0);
|
|
3327
|
+
return true;
|
|
3328
|
+
} catch {
|
|
3329
|
+
return false;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
async function stopProcess(pid) {
|
|
3333
|
+
if (!pid) return;
|
|
3334
|
+
await new Promise((resolve) => {
|
|
3335
|
+
treeKill__default.default(pid, "SIGTERM", (err) => {
|
|
3336
|
+
if (err) {
|
|
3337
|
+
treeKill__default.default(pid, "SIGKILL", () => resolve());
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3340
|
+
resolve();
|
|
3341
|
+
});
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3344
|
+
var signalsInstalled = false;
|
|
3345
|
+
function installSignalHandlers(child) {
|
|
3346
|
+
if (signalsInstalled) return;
|
|
3347
|
+
signalsInstalled = true;
|
|
3348
|
+
const cleanup = () => {
|
|
3349
|
+
if (child.pid) {
|
|
3350
|
+
try {
|
|
3351
|
+
process.kill(-child.pid, "SIGTERM");
|
|
3352
|
+
} catch {
|
|
3353
|
+
}
|
|
3354
|
+
treeKill__default.default(child.pid, "SIGKILL", () => {
|
|
3355
|
+
});
|
|
3356
|
+
}
|
|
3357
|
+
};
|
|
3358
|
+
process.on("SIGINT", () => {
|
|
3359
|
+
cleanup();
|
|
3360
|
+
process.exit(130);
|
|
3361
|
+
});
|
|
3362
|
+
process.on("SIGTERM", () => {
|
|
3363
|
+
cleanup();
|
|
3364
|
+
process.exit(143);
|
|
3365
|
+
});
|
|
3366
|
+
process.on("exit", cleanup);
|
|
3367
|
+
}
|
|
3204
3368
|
|
|
3205
3369
|
// src/cli/check-output.ts
|
|
3206
3370
|
function slimResult(r) {
|
|
@@ -3399,6 +3563,21 @@ report: ${relPath(reportPath)}`;
|
|
|
3399
3563
|
function exitCodeFor(report) {
|
|
3400
3564
|
return report.failed > 0 ? 1 : void 0;
|
|
3401
3565
|
}
|
|
3566
|
+
async function ensureDevServer(config, out) {
|
|
3567
|
+
const port = config?.devServer?.port;
|
|
3568
|
+
if (!config?.devServer || !port || await isPortOpen(port)) return;
|
|
3569
|
+
await startServer({
|
|
3570
|
+
command: config.devServer.command,
|
|
3571
|
+
port,
|
|
3572
|
+
readyTimeoutMs: config.devServer.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS
|
|
3573
|
+
});
|
|
3574
|
+
if (!out.isQuiet()) {
|
|
3575
|
+
process.stderr.write(
|
|
3576
|
+
`${dim(`dev server started on :${port} (serve-status --kill to stop)`)}
|
|
3577
|
+
`
|
|
3578
|
+
);
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3402
3581
|
function registerCheck(program, out) {
|
|
3403
3582
|
program.command("check").description("run the visual regression check (CI verb)").option("--base-url <url>", "override base URL").option(
|
|
3404
3583
|
"--threshold <n>",
|
|
@@ -3436,6 +3615,7 @@ function registerCheck(program, out) {
|
|
|
3436
3615
|
}
|
|
3437
3616
|
const config = await loadConfig();
|
|
3438
3617
|
const baseUrl = resolveBaseUrl(config, opts.baseUrl);
|
|
3618
|
+
if (!opts.baseUrl) await ensureDevServer(config, out);
|
|
3439
3619
|
const report = await runGraph({
|
|
3440
3620
|
baseUrl,
|
|
3441
3621
|
threshold: parseThreshold(opts.threshold),
|
|
@@ -3489,9 +3669,9 @@ function extractInternalLinks(base, target, hrefs) {
|
|
|
3489
3669
|
try {
|
|
3490
3670
|
const u = new URL(href, target);
|
|
3491
3671
|
if (u.origin !== base.origin) continue;
|
|
3492
|
-
const
|
|
3493
|
-
if (
|
|
3494
|
-
out.push(
|
|
3672
|
+
const path30 = u.pathname + u.search;
|
|
3673
|
+
if (path30.startsWith("/api/")) continue;
|
|
3674
|
+
out.push(path30);
|
|
3495
3675
|
} catch {
|
|
3496
3676
|
}
|
|
3497
3677
|
}
|
|
@@ -3521,6 +3701,8 @@ async function crawlRoutes(opts) {
|
|
|
3521
3701
|
waitUntil: "domcontentloaded",
|
|
3522
3702
|
timeout: 15e3
|
|
3523
3703
|
});
|
|
3704
|
+
await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
|
|
3705
|
+
});
|
|
3524
3706
|
const hrefs = await page.evaluate(
|
|
3525
3707
|
() => Array.from(
|
|
3526
3708
|
document.querySelectorAll("a[href]")
|
|
@@ -3545,57 +3727,38 @@ async function crawlRoutes(opts) {
|
|
|
3545
3727
|
}
|
|
3546
3728
|
return discovered.slice(0, maxRoutes);
|
|
3547
3729
|
}
|
|
3548
|
-
var DYNAMIC_SEGMENT = /\[[^\]]+\]/;
|
|
3549
|
-
function isPublicRoute(route) {
|
|
3550
|
-
if (DYNAMIC_SEGMENT.test(route)) return false;
|
|
3551
|
-
if (route === "/api" || route.startsWith("/api/")) return false;
|
|
3552
|
-
return true;
|
|
3553
|
-
}
|
|
3554
|
-
async function discoverFromNextManifest(cwd = process.cwd()) {
|
|
3555
|
-
const nextDir = path27__default.default.join(cwd, ".next");
|
|
3556
|
-
if (!fs.existsSync(nextDir)) return [];
|
|
3557
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3558
|
-
const out = [];
|
|
3559
|
-
const add = (url) => {
|
|
3560
|
-
if (seen.has(url)) return;
|
|
3561
|
-
seen.add(url);
|
|
3562
|
-
out.push({ url, source: "next-manifest" });
|
|
3563
|
-
};
|
|
3564
|
-
const routes = await readJsonOrNull(
|
|
3565
|
-
path27__default.default.join(nextDir, "routes-manifest.json")
|
|
3566
|
-
);
|
|
3567
|
-
for (const r of routes?.staticRoutes ?? []) {
|
|
3568
|
-
if (isPublicRoute(r.page)) add(r.page);
|
|
3569
|
-
}
|
|
3570
|
-
const appPaths = await readJsonOrNull(
|
|
3571
|
-
path27__default.default.join(nextDir, "server", "app-paths-manifest.json")
|
|
3572
|
-
);
|
|
3573
|
-
for (const route of Object.keys(appPaths ?? {})) {
|
|
3574
|
-
const normalized = route.replace(/\/page$/, "") || "/";
|
|
3575
|
-
if (isPublicRoute(normalized)) add(normalized);
|
|
3576
|
-
}
|
|
3577
|
-
return out;
|
|
3578
|
-
}
|
|
3579
3730
|
|
|
3580
|
-
// src/discover/
|
|
3581
|
-
var
|
|
3582
|
-
var
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3731
|
+
// src/discover/templates.ts
|
|
3732
|
+
var DEFAULT_SAMPLE_THRESHOLD = 5;
|
|
3733
|
+
var DEFAULT_SAMPLES_PER_TEMPLATE = 2;
|
|
3734
|
+
var DEFAULT_SAMPLING = {
|
|
3735
|
+
threshold: DEFAULT_SAMPLE_THRESHOLD,
|
|
3736
|
+
samples: DEFAULT_SAMPLES_PER_TEMPLATE
|
|
3737
|
+
};
|
|
3738
|
+
function parentPath(path30) {
|
|
3739
|
+
const [pathPart] = path30.split("?", 2);
|
|
3740
|
+
const idx = pathPart.lastIndexOf("/");
|
|
3741
|
+
return idx <= 0 ? "/" : pathPart.slice(0, idx);
|
|
3742
|
+
}
|
|
3743
|
+
function collapseTemplates(routes, { threshold, samples } = DEFAULT_SAMPLING) {
|
|
3744
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3745
|
+
for (const route of routes) {
|
|
3746
|
+
const parent = parentPath(route.url);
|
|
3747
|
+
const group = groups.get(parent);
|
|
3748
|
+
if (group) group.push(route);
|
|
3749
|
+
else groups.set(parent, [route]);
|
|
3750
|
+
}
|
|
3751
|
+
const drop = /* @__PURE__ */ new Set();
|
|
3752
|
+
const collapsed = [];
|
|
3753
|
+
for (const [parent, group] of groups) {
|
|
3754
|
+
if (parent === "/" || group.length < threshold) continue;
|
|
3755
|
+
for (const route of group.slice(samples)) drop.add(route.url);
|
|
3756
|
+
collapsed.push(`${parent}/* (${group.length} \u2192 ${samples})`);
|
|
3597
3757
|
}
|
|
3598
|
-
return
|
|
3758
|
+
return {
|
|
3759
|
+
routes: drop.size ? routes.filter((r) => !drop.has(r.url)) : routes,
|
|
3760
|
+
collapsed
|
|
3761
|
+
};
|
|
3599
3762
|
}
|
|
3600
3763
|
|
|
3601
3764
|
// src/discover/index.ts
|
|
@@ -3605,44 +3768,61 @@ function normalizePath(url) {
|
|
|
3605
3768
|
const normalizedPath = trimmed === "" ? "/" : trimmed;
|
|
3606
3769
|
return query ? `${normalizedPath}?${query}` : normalizedPath;
|
|
3607
3770
|
}
|
|
3608
|
-
function
|
|
3771
|
+
function dedupe(routes) {
|
|
3772
|
+
const merged = /* @__PURE__ */ new Map();
|
|
3609
3773
|
for (const r of routes) {
|
|
3610
3774
|
const key = normalizePath(r.url);
|
|
3611
|
-
if (!
|
|
3775
|
+
if (!merged.has(key)) merged.set(key, { ...r, url: key });
|
|
3612
3776
|
}
|
|
3777
|
+
return Array.from(merged.values());
|
|
3613
3778
|
}
|
|
3614
3779
|
async function discover(opts) {
|
|
3615
|
-
const
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
await crawlRoutes({ baseUrl: opts.baseUrl, maxRoutes: crawlMax }),
|
|
3624
|
-
merged
|
|
3625
|
-
);
|
|
3626
|
-
}
|
|
3627
|
-
}
|
|
3628
|
-
return Array.from(merged.values()).sort((a, b) => a.url.localeCompare(b.url));
|
|
3780
|
+
const crawled = await crawlRoutes({
|
|
3781
|
+
baseUrl: opts.baseUrl,
|
|
3782
|
+
maxRoutes: opts.maxRoutes ?? 50
|
|
3783
|
+
});
|
|
3784
|
+
const deduped = dedupe(crawled);
|
|
3785
|
+
const sampling = opts.sampleTemplates ?? true;
|
|
3786
|
+
const routes = sampling === false ? deduped : collapseTemplates(deduped, sampling === true ? void 0 : sampling).routes;
|
|
3787
|
+
return routes.sort((a, b) => a.url.localeCompare(b.url));
|
|
3629
3788
|
}
|
|
3630
3789
|
|
|
3631
3790
|
// src/cli/commands/discover.ts
|
|
3791
|
+
function posInt(value, fallback) {
|
|
3792
|
+
const n = Number(value);
|
|
3793
|
+
return Number.isInteger(n) && n > 0 ? n : fallback;
|
|
3794
|
+
}
|
|
3632
3795
|
function registerDiscover(program, out) {
|
|
3633
3796
|
program.command("discover").description(
|
|
3634
|
-
"enumerate
|
|
3635
|
-
).option("--base-url <url>", "override base URL").option("--max-routes <n>", "cap on routes returned", "50").option(
|
|
3797
|
+
"enumerate reachable routes by crawling links from the landing page"
|
|
3798
|
+
).option("--base-url <url>", "override base URL").option("--max-routes <n>", "cap on routes returned", "50").option(
|
|
3799
|
+
"--no-sample-templates",
|
|
3800
|
+
"keep every reachable route, even large list/detail groups"
|
|
3801
|
+
).option(
|
|
3802
|
+
"--samples-per-template <n>",
|
|
3803
|
+
"representatives to keep per templated group",
|
|
3804
|
+
String(DEFAULT_SAMPLES_PER_TEMPLATE)
|
|
3805
|
+
).option(
|
|
3806
|
+
"--sample-threshold <n>",
|
|
3807
|
+
"group size at which template sampling kicks in",
|
|
3808
|
+
String(DEFAULT_SAMPLE_THRESHOLD)
|
|
3809
|
+
).action(async (opts) => {
|
|
3636
3810
|
const baseUrl = resolveBaseUrl(await loadConfig(), opts.baseUrl);
|
|
3637
3811
|
const routes = await discover({
|
|
3638
3812
|
baseUrl,
|
|
3639
3813
|
maxRoutes: Number(opts.maxRoutes),
|
|
3640
|
-
|
|
3814
|
+
sampleTemplates: opts.sampleTemplates && {
|
|
3815
|
+
threshold: posInt(opts.sampleThreshold, DEFAULT_SAMPLE_THRESHOLD),
|
|
3816
|
+
samples: posInt(
|
|
3817
|
+
opts.samplesPerTemplate,
|
|
3818
|
+
DEFAULT_SAMPLES_PER_TEMPLATE
|
|
3819
|
+
)
|
|
3820
|
+
}
|
|
3641
3821
|
});
|
|
3642
3822
|
await closeBrowser();
|
|
3643
3823
|
out.emit(
|
|
3644
3824
|
{ ok: true, baseUrl, routes },
|
|
3645
|
-
routes.length ? routes.map((r) =>
|
|
3825
|
+
routes.length ? routes.map((r) => r.url).join("\n") : "no routes discovered"
|
|
3646
3826
|
);
|
|
3647
3827
|
});
|
|
3648
3828
|
}
|
|
@@ -3653,8 +3833,8 @@ var CodegenError = class extends Error {
|
|
|
3653
3833
|
}
|
|
3654
3834
|
};
|
|
3655
3835
|
async function runCodegen(opts) {
|
|
3656
|
-
const tmp = await promises.mkdtemp(
|
|
3657
|
-
const scriptPath =
|
|
3836
|
+
const tmp = await promises.mkdtemp(path26__default.default.join(os.tmpdir(), "blazediff-codegen-"));
|
|
3837
|
+
const scriptPath = path26__default.default.join(tmp, "recording.js");
|
|
3658
3838
|
const command = opts.command ?? process.execPath;
|
|
3659
3839
|
const args = opts.args ?? [
|
|
3660
3840
|
resolvePlaywrightCli(),
|
|
@@ -3934,7 +4114,7 @@ function registerHarness(program, out) {
|
|
|
3934
4114
|
`refusing to record against what looks like a production URL: ${url}. Pass --allow-production to override.`
|
|
3935
4115
|
);
|
|
3936
4116
|
}
|
|
3937
|
-
const harnessPath = opts.output ?
|
|
4117
|
+
const harnessPath = opts.output ? path26__default.default.isAbsolute(opts.output) ? opts.output : path26__default.default.join(process.cwd(), opts.output) : path26__default.default.join(paths().harnesses, `${name}.js`);
|
|
3938
4118
|
if (fs.existsSync(harnessPath) && !opts.force) {
|
|
3939
4119
|
throw new Error(`refusing to overwrite ${harnessPath} (use --force).`);
|
|
3940
4120
|
}
|
|
@@ -3957,9 +4137,9 @@ function registerHarness(program, out) {
|
|
|
3957
4137
|
loginUrl: url,
|
|
3958
4138
|
persona: opts.persona
|
|
3959
4139
|
}) : buildHarness(rawSource, { name, url, phase });
|
|
3960
|
-
await promises.mkdir(
|
|
4140
|
+
await promises.mkdir(path26__default.default.dirname(harnessPath), { recursive: true });
|
|
3961
4141
|
await promises.writeFile(harnessPath, built.source, "utf8");
|
|
3962
|
-
await promises.rm(
|
|
4142
|
+
await promises.rm(path26__default.default.dirname(scriptPath), {
|
|
3963
4143
|
recursive: true,
|
|
3964
4144
|
force: true
|
|
3965
4145
|
}).catch(() => {
|
|
@@ -4095,21 +4275,21 @@ function detectFramework(pkg) {
|
|
|
4095
4275
|
return "unknown";
|
|
4096
4276
|
}
|
|
4097
4277
|
async function readPackageJson(cwd = process.cwd()) {
|
|
4098
|
-
const file =
|
|
4278
|
+
const file = path26__default.default.join(cwd, "package.json");
|
|
4099
4279
|
if (!fs.existsSync(file)) return null;
|
|
4100
4280
|
return JSON.parse(await promises.readFile(file, "utf8"));
|
|
4101
4281
|
}
|
|
4102
4282
|
function detectPackageManager(cwd = process.cwd()) {
|
|
4103
4283
|
let dir = cwd;
|
|
4104
|
-
const { root } =
|
|
4284
|
+
const { root } = path26__default.default.parse(dir);
|
|
4105
4285
|
while (true) {
|
|
4106
|
-
if (fs.existsSync(
|
|
4107
|
-
if (fs.existsSync(
|
|
4286
|
+
if (fs.existsSync(path26__default.default.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
4287
|
+
if (fs.existsSync(path26__default.default.join(dir, "bun.lockb")) || fs.existsSync(path26__default.default.join(dir, "bun.lock")))
|
|
4108
4288
|
return "bun";
|
|
4109
|
-
if (fs.existsSync(
|
|
4110
|
-
if (fs.existsSync(
|
|
4289
|
+
if (fs.existsSync(path26__default.default.join(dir, "yarn.lock"))) return "yarn";
|
|
4290
|
+
if (fs.existsSync(path26__default.default.join(dir, "package-lock.json"))) return "npm";
|
|
4111
4291
|
if (dir === root) return "npm";
|
|
4112
|
-
dir =
|
|
4292
|
+
dir = path26__default.default.dirname(dir);
|
|
4113
4293
|
}
|
|
4114
4294
|
}
|
|
4115
4295
|
var DEFAULT_PORTS = {
|
|
@@ -4274,19 +4454,19 @@ var SKILL_FILES = ["SKILL.md", "JUDGING.md", "MASKING.md"];
|
|
|
4274
4454
|
var cachedDir = null;
|
|
4275
4455
|
var cachedFiles = null;
|
|
4276
4456
|
function moduleDir() {
|
|
4277
|
-
return
|
|
4457
|
+
return path26.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href))));
|
|
4278
4458
|
}
|
|
4279
4459
|
function resolveSkillDir() {
|
|
4280
4460
|
if (cachedDir !== null) return cachedDir;
|
|
4281
4461
|
const here = moduleDir();
|
|
4282
4462
|
const candidates = [
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4463
|
+
path26.join(here, ".."),
|
|
4464
|
+
path26.join(here, "..", ".."),
|
|
4465
|
+
path26.join(here, "..", "..", "..", "skill", "blazediff"),
|
|
4466
|
+
path26.join(here, "..", "..", "..", "..", "skill", "blazediff")
|
|
4287
4467
|
];
|
|
4288
4468
|
for (const dir of candidates) {
|
|
4289
|
-
if (fs.existsSync(
|
|
4469
|
+
if (fs.existsSync(path26.join(dir, "SKILL.md"))) {
|
|
4290
4470
|
cachedDir = dir;
|
|
4291
4471
|
return cachedDir;
|
|
4292
4472
|
}
|
|
@@ -4298,8 +4478,8 @@ function resolveSkillDir() {
|
|
|
4298
4478
|
function loadSkillFiles() {
|
|
4299
4479
|
if (cachedFiles !== null) return cachedFiles;
|
|
4300
4480
|
const dir = resolveSkillDir();
|
|
4301
|
-
cachedFiles = SKILL_FILES.filter((name) => fs.existsSync(
|
|
4302
|
-
(name) => ({ name, content: fs.readFileSync(
|
|
4481
|
+
cachedFiles = SKILL_FILES.filter((name) => fs.existsSync(path26.join(dir, name))).map(
|
|
4482
|
+
(name) => ({ name, content: fs.readFileSync(path26.join(dir, name), "utf8") })
|
|
4303
4483
|
);
|
|
4304
4484
|
return cachedFiles;
|
|
4305
4485
|
}
|
|
@@ -4326,11 +4506,11 @@ var STACKS = {
|
|
|
4326
4506
|
kind: "skill-install",
|
|
4327
4507
|
judge: "host",
|
|
4328
4508
|
detect: (cwd) => someExists([
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4509
|
+
path26.join(cwd, ".claude"),
|
|
4510
|
+
path26.join(cwd, "CLAUDE.md"),
|
|
4511
|
+
path26.join(cwd, "AGENTS.md")
|
|
4332
4512
|
]),
|
|
4333
|
-
target: (cwd) =>
|
|
4513
|
+
target: (cwd) => path26.join(cwd, ".claude", "skills", "blazediff", "SKILL.md"),
|
|
4334
4514
|
format: "skill-file",
|
|
4335
4515
|
scope: "project"
|
|
4336
4516
|
},
|
|
@@ -4340,11 +4520,11 @@ var STACKS = {
|
|
|
4340
4520
|
kind: "skill-install",
|
|
4341
4521
|
judge: "host",
|
|
4342
4522
|
detect: (cwd) => someExists([
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4523
|
+
path26.join(cwd, "AGENTS.md"),
|
|
4524
|
+
path26.join(cwd, ".codex"),
|
|
4525
|
+
path26.join(os.homedir(), ".codex")
|
|
4346
4526
|
]),
|
|
4347
|
-
target: () =>
|
|
4527
|
+
target: () => path26.join(os.homedir(), ".codex", "skills", "blazediff", "SKILL.md"),
|
|
4348
4528
|
format: "skill-file",
|
|
4349
4529
|
scope: "user"
|
|
4350
4530
|
},
|
|
@@ -4353,8 +4533,8 @@ var STACKS = {
|
|
|
4353
4533
|
label: "Cursor",
|
|
4354
4534
|
kind: "skill-install",
|
|
4355
4535
|
judge: "host",
|
|
4356
|
-
detect: (cwd) => someExists([
|
|
4357
|
-
target: (cwd) =>
|
|
4536
|
+
detect: (cwd) => someExists([path26.join(cwd, ".cursor"), path26.join(cwd, ".cursorrules")]),
|
|
4537
|
+
target: (cwd) => path26.join(cwd, ".cursor", "rules", "blazediff.mdc"),
|
|
4358
4538
|
format: "cursor-rule",
|
|
4359
4539
|
scope: "project"
|
|
4360
4540
|
},
|
|
@@ -4426,7 +4606,7 @@ async function writeIfChanged(target, content, force) {
|
|
|
4426
4606
|
const exists = stat3 !== null;
|
|
4427
4607
|
if (isSymlink) {
|
|
4428
4608
|
await promises.unlink(target);
|
|
4429
|
-
await promises.mkdir(
|
|
4609
|
+
await promises.mkdir(path26.dirname(target), { recursive: true });
|
|
4430
4610
|
await promises.writeFile(target, content, "utf8");
|
|
4431
4611
|
return "updated";
|
|
4432
4612
|
}
|
|
@@ -4435,7 +4615,7 @@ async function writeIfChanged(target, content, force) {
|
|
|
4435
4615
|
if (current === content) return "unchanged";
|
|
4436
4616
|
if (!force) return "skipped-exists";
|
|
4437
4617
|
}
|
|
4438
|
-
await promises.mkdir(
|
|
4618
|
+
await promises.mkdir(path26.dirname(target), { recursive: true });
|
|
4439
4619
|
await promises.writeFile(target, content, "utf8");
|
|
4440
4620
|
return exists ? "updated" : "created";
|
|
4441
4621
|
}
|
|
@@ -4457,10 +4637,10 @@ async function installStack(stack, cwd, opts = {}) {
|
|
|
4457
4637
|
const status = await writeIfChanged(target, content, opts.force);
|
|
4458
4638
|
return { stack, path: target, status };
|
|
4459
4639
|
}
|
|
4460
|
-
const targetDir =
|
|
4640
|
+
const targetDir = path26.dirname(target);
|
|
4461
4641
|
const statuses = [];
|
|
4462
4642
|
for (const file of files) {
|
|
4463
|
-
const filePath =
|
|
4643
|
+
const filePath = path26.join(targetDir, file.name);
|
|
4464
4644
|
const status = await writeIfChanged(
|
|
4465
4645
|
filePath,
|
|
4466
4646
|
ensureTrailingNewline(file.content),
|
|
@@ -4470,170 +4650,6 @@ async function installStack(stack, cwd, opts = {}) {
|
|
|
4470
4650
|
}
|
|
4471
4651
|
return { stack, path: target, status: combineStatuses(statuses) };
|
|
4472
4652
|
}
|
|
4473
|
-
var execFileP = util.promisify(child_process.execFile);
|
|
4474
|
-
async function isPortOpen(port, host = "127.0.0.1") {
|
|
4475
|
-
return new Promise((resolve) => {
|
|
4476
|
-
const socket = net.createConnection({ port, host });
|
|
4477
|
-
socket.setTimeout(500);
|
|
4478
|
-
socket.once("connect", () => {
|
|
4479
|
-
socket.destroy();
|
|
4480
|
-
resolve(true);
|
|
4481
|
-
});
|
|
4482
|
-
socket.once("error", () => resolve(false));
|
|
4483
|
-
socket.once("timeout", () => {
|
|
4484
|
-
socket.destroy();
|
|
4485
|
-
resolve(false);
|
|
4486
|
-
});
|
|
4487
|
-
});
|
|
4488
|
-
}
|
|
4489
|
-
async function waitForPort(port, timeoutMs = 6e4) {
|
|
4490
|
-
const deadline = Date.now() + timeoutMs;
|
|
4491
|
-
while (Date.now() < deadline) {
|
|
4492
|
-
if (await isPortOpen(port)) return;
|
|
4493
|
-
await new Promise((r) => setTimeout(r, 250));
|
|
4494
|
-
}
|
|
4495
|
-
throw new Error(`dev server did not open port ${port} within ${timeoutMs}ms`);
|
|
4496
|
-
}
|
|
4497
|
-
async function findPidByPort(port) {
|
|
4498
|
-
const platform = process.platform;
|
|
4499
|
-
try {
|
|
4500
|
-
if (platform === "darwin" || platform === "linux") {
|
|
4501
|
-
const { stdout } = await execFileP("lsof", [
|
|
4502
|
-
"-ti",
|
|
4503
|
-
`tcp:${port}`,
|
|
4504
|
-
"-sTCP:LISTEN"
|
|
4505
|
-
]);
|
|
4506
|
-
const pid = Number(stdout.trim().split("\n")[0]);
|
|
4507
|
-
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
4508
|
-
}
|
|
4509
|
-
if (platform === "win32") {
|
|
4510
|
-
const { stdout } = await execFileP("netstat", ["-ano"]);
|
|
4511
|
-
const line = stdout.split(/\r?\n/).find((l) => l.includes(`:${port} `) && l.includes("LISTENING"));
|
|
4512
|
-
if (!line) return null;
|
|
4513
|
-
const parts = line.trim().split(/\s+/);
|
|
4514
|
-
const pid = Number(parts[parts.length - 1]);
|
|
4515
|
-
return Number.isFinite(pid) && pid > 0 ? pid : null;
|
|
4516
|
-
}
|
|
4517
|
-
} catch {
|
|
4518
|
-
return null;
|
|
4519
|
-
}
|
|
4520
|
-
return null;
|
|
4521
|
-
}
|
|
4522
|
-
async function startServer(opts) {
|
|
4523
|
-
const cwd = opts.cwd ?? process.cwd();
|
|
4524
|
-
const logPath = opts.logPath ?? paths(cwd).serverLog;
|
|
4525
|
-
const pidPath = opts.pidPath ?? paths(cwd).serverPid;
|
|
4526
|
-
await promises.mkdir(path27__default.default.dirname(logPath), { recursive: true });
|
|
4527
|
-
if (await isPortOpen(opts.port)) {
|
|
4528
|
-
const discoveredPid = await findPidByPort(opts.port);
|
|
4529
|
-
if (discoveredPid) {
|
|
4530
|
-
await promises.writeFile(pidPath, String(discoveredPid), "utf8").catch(() => {
|
|
4531
|
-
});
|
|
4532
|
-
}
|
|
4533
|
-
return {
|
|
4534
|
-
pid: discoveredPid ?? 0,
|
|
4535
|
-
port: opts.port,
|
|
4536
|
-
url: `http://127.0.0.1:${opts.port}`,
|
|
4537
|
-
attached: true
|
|
4538
|
-
};
|
|
4539
|
-
}
|
|
4540
|
-
const child = child_process.spawn(opts.command, {
|
|
4541
|
-
cwd,
|
|
4542
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
4543
|
-
detached: true,
|
|
4544
|
-
shell: true,
|
|
4545
|
-
env: { ...process.env, FORCE_COLOR: "0", CI: "1" }
|
|
4546
|
-
});
|
|
4547
|
-
const logStream = await import('fs').then(
|
|
4548
|
-
(m) => m.createWriteStream(logPath, { flags: "a" })
|
|
4549
|
-
);
|
|
4550
|
-
child.stdout?.pipe(logStream);
|
|
4551
|
-
child.stderr?.pipe(logStream);
|
|
4552
|
-
if (!child.pid) throw new Error("failed to spawn dev server");
|
|
4553
|
-
await promises.writeFile(pidPath, String(child.pid), "utf8");
|
|
4554
|
-
installSignalHandlers(child);
|
|
4555
|
-
try {
|
|
4556
|
-
await waitForPort(opts.port, opts.readyTimeoutMs ?? 6e4);
|
|
4557
|
-
} catch (err) {
|
|
4558
|
-
await stopProcess(child.pid);
|
|
4559
|
-
throw err;
|
|
4560
|
-
}
|
|
4561
|
-
return {
|
|
4562
|
-
pid: child.pid,
|
|
4563
|
-
port: opts.port,
|
|
4564
|
-
url: `http://127.0.0.1:${opts.port}`
|
|
4565
|
-
};
|
|
4566
|
-
}
|
|
4567
|
-
async function stopServer(cwd = process.cwd(), portFallback) {
|
|
4568
|
-
const pidPath = paths(cwd).serverPid;
|
|
4569
|
-
let pid = null;
|
|
4570
|
-
let via = "none";
|
|
4571
|
-
if (fs.existsSync(pidPath)) {
|
|
4572
|
-
const raw = (await promises.readFile(pidPath, "utf8")).trim();
|
|
4573
|
-
const parsed = Number(raw);
|
|
4574
|
-
if (Number.isFinite(parsed) && parsed > 0 && processExists(parsed)) {
|
|
4575
|
-
pid = parsed;
|
|
4576
|
-
via = "pidfile";
|
|
4577
|
-
}
|
|
4578
|
-
}
|
|
4579
|
-
if (!pid && portFallback) {
|
|
4580
|
-
pid = await findPidByPort(portFallback);
|
|
4581
|
-
if (pid) via = "port";
|
|
4582
|
-
}
|
|
4583
|
-
if (!pid) {
|
|
4584
|
-
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
4585
|
-
});
|
|
4586
|
-
return { killed: false, pid: null, via: "none" };
|
|
4587
|
-
}
|
|
4588
|
-
await stopProcess(pid);
|
|
4589
|
-
await promises.writeFile(pidPath, "", "utf8").catch(() => {
|
|
4590
|
-
});
|
|
4591
|
-
return { killed: true, pid, via };
|
|
4592
|
-
}
|
|
4593
|
-
function processExists(pid) {
|
|
4594
|
-
try {
|
|
4595
|
-
process.kill(pid, 0);
|
|
4596
|
-
return true;
|
|
4597
|
-
} catch {
|
|
4598
|
-
return false;
|
|
4599
|
-
}
|
|
4600
|
-
}
|
|
4601
|
-
async function stopProcess(pid) {
|
|
4602
|
-
if (!pid) return;
|
|
4603
|
-
await new Promise((resolve) => {
|
|
4604
|
-
treeKill__default.default(pid, "SIGTERM", (err) => {
|
|
4605
|
-
if (err) {
|
|
4606
|
-
treeKill__default.default(pid, "SIGKILL", () => resolve());
|
|
4607
|
-
return;
|
|
4608
|
-
}
|
|
4609
|
-
resolve();
|
|
4610
|
-
});
|
|
4611
|
-
});
|
|
4612
|
-
}
|
|
4613
|
-
var signalsInstalled = false;
|
|
4614
|
-
function installSignalHandlers(child) {
|
|
4615
|
-
if (signalsInstalled) return;
|
|
4616
|
-
signalsInstalled = true;
|
|
4617
|
-
const cleanup = () => {
|
|
4618
|
-
if (child.pid) {
|
|
4619
|
-
try {
|
|
4620
|
-
process.kill(-child.pid, "SIGTERM");
|
|
4621
|
-
} catch {
|
|
4622
|
-
}
|
|
4623
|
-
treeKill__default.default(child.pid, "SIGKILL", () => {
|
|
4624
|
-
});
|
|
4625
|
-
}
|
|
4626
|
-
};
|
|
4627
|
-
process.on("SIGINT", () => {
|
|
4628
|
-
cleanup();
|
|
4629
|
-
process.exit(130);
|
|
4630
|
-
});
|
|
4631
|
-
process.on("SIGTERM", () => {
|
|
4632
|
-
cleanup();
|
|
4633
|
-
process.exit(143);
|
|
4634
|
-
});
|
|
4635
|
-
process.on("exit", cleanup);
|
|
4636
|
-
}
|
|
4637
4653
|
|
|
4638
4654
|
// src/cli/commands/onboard.ts
|
|
4639
4655
|
async function promptForStacks() {
|
|
@@ -4667,8 +4683,8 @@ async function ensureBrowsers(opts, interactive) {
|
|
|
4667
4683
|
const result = await installBrowsers();
|
|
4668
4684
|
return { installed: result.installed, skipped: false };
|
|
4669
4685
|
}
|
|
4670
|
-
function routeId(
|
|
4671
|
-
const slug =
|
|
4686
|
+
function routeId(path30) {
|
|
4687
|
+
const slug = path30.replace(/^\/+|\/+$/g, "").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
4672
4688
|
return slug || "home";
|
|
4673
4689
|
}
|
|
4674
4690
|
function toCaptureRoutes(routes) {
|
|
@@ -4938,14 +4954,14 @@ function recountReport(report) {
|
|
|
4938
4954
|
}
|
|
4939
4955
|
async function approveEntry(id, cwd = process.cwd()) {
|
|
4940
4956
|
const p = paths(cwd);
|
|
4941
|
-
const actualPng =
|
|
4957
|
+
const actualPng = path26__default.default.join(p.actual, `${id}.png`);
|
|
4942
4958
|
if (!fs.existsSync(actualPng)) return null;
|
|
4943
4959
|
await promises.mkdir(p.baselines, { recursive: true });
|
|
4944
|
-
await promises.copyFile(actualPng,
|
|
4960
|
+
await promises.copyFile(actualPng, path26__default.default.join(p.baselines, `${id}.png`));
|
|
4945
4961
|
await Promise.all([
|
|
4946
4962
|
promises.rm(actualPng, { force: true }),
|
|
4947
|
-
promises.rm(
|
|
4948
|
-
promises.rm(
|
|
4963
|
+
promises.rm(path26__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
|
|
4964
|
+
promises.rm(path26__default.default.join(p.judgments, id), { recursive: true, force: true })
|
|
4949
4965
|
]);
|
|
4950
4966
|
const report = await readReport(cwd);
|
|
4951
4967
|
const result = report?.results.find((r) => r.id === id);
|
|
@@ -4972,10 +4988,10 @@ async function rejectEntry(id, cwd = process.cwd()) {
|
|
|
4972
4988
|
action: "investigate"
|
|
4973
4989
|
};
|
|
4974
4990
|
const p = paths(cwd);
|
|
4975
|
-
const dir =
|
|
4991
|
+
const dir = path26__default.default.join(p.judgments, id);
|
|
4976
4992
|
await promises.mkdir(dir, { recursive: true });
|
|
4977
4993
|
await promises.writeFile(
|
|
4978
|
-
|
|
4994
|
+
path26__default.default.join(dir, "verdict.json"),
|
|
4979
4995
|
`${JSON.stringify({ id, verdict, rationale: "rejected via review" }, null, 2)}
|
|
4980
4996
|
`,
|
|
4981
4997
|
"utf8"
|
|
@@ -4994,7 +5010,7 @@ async function rejectEntry(id, cwd = process.cwd()) {
|
|
|
4994
5010
|
|
|
4995
5011
|
// src/review/server.ts
|
|
4996
5012
|
var execFileP2 = util.promisify(child_process.execFile);
|
|
4997
|
-
var CLIENT_DIR =
|
|
5013
|
+
var CLIENT_DIR = path26__default.default.join(__dirname, "review", "client");
|
|
4998
5014
|
var CONTENT_TYPES = {
|
|
4999
5015
|
".html": "text/html; charset=utf-8",
|
|
5000
5016
|
".js": "text/javascript; charset=utf-8",
|
|
@@ -5021,7 +5037,7 @@ function sendJson(res, status, body) {
|
|
|
5021
5037
|
res.end(payload);
|
|
5022
5038
|
}
|
|
5023
5039
|
function streamFile(res, file) {
|
|
5024
|
-
const type = CONTENT_TYPES[
|
|
5040
|
+
const type = CONTENT_TYPES[path26__default.default.extname(file)] ?? "application/octet-stream";
|
|
5025
5041
|
res.writeHead(200, { "content-type": type });
|
|
5026
5042
|
fs.createReadStream(file).on("error", () => {
|
|
5027
5043
|
if (!res.headersSent) res.writeHead(500);
|
|
@@ -5070,7 +5086,7 @@ async function buildRunMeta(cwd) {
|
|
|
5070
5086
|
const baseSha = baseRef ? await gitText(cwd, ["rev-parse", "--short", baseRef]) : "";
|
|
5071
5087
|
const baseline = baseRef ? `${baseRef} @ ${baseSha}`.replace(/ @ $/, "") : "";
|
|
5072
5088
|
return {
|
|
5073
|
-
name:
|
|
5089
|
+
name: path26__default.default.basename(cwd),
|
|
5074
5090
|
baseline,
|
|
5075
5091
|
candidate,
|
|
5076
5092
|
threshold: DEFAULT_THRESHOLD,
|
|
@@ -5079,9 +5095,9 @@ async function buildRunMeta(cwd) {
|
|
|
5079
5095
|
}
|
|
5080
5096
|
function imageFile(cwd, kind, id) {
|
|
5081
5097
|
const p = paths(cwd);
|
|
5082
|
-
const file = kind === "baseline" ?
|
|
5083
|
-
const resolved =
|
|
5084
|
-
if (!resolved.startsWith(
|
|
5098
|
+
const file = kind === "baseline" ? path26__default.default.join(p.baselines, `${id}.png`) : kind === "actual" ? path26__default.default.join(p.actual, `${id}.png`) : path26__default.default.join(p.actual, `${id}.diff.png`);
|
|
5099
|
+
const resolved = path26__default.default.resolve(file);
|
|
5100
|
+
if (!resolved.startsWith(path26__default.default.resolve(p.root) + path26__default.default.sep)) return null;
|
|
5085
5101
|
return resolved;
|
|
5086
5102
|
}
|
|
5087
5103
|
async function handleApi(req, res, cwd, url) {
|
|
@@ -5138,11 +5154,11 @@ async function handleApi(req, res, cwd, url) {
|
|
|
5138
5154
|
}
|
|
5139
5155
|
async function serveStatic(res, pathname) {
|
|
5140
5156
|
const rel = pathname === "/" ? "index.html" : pathname.replace(/^\/+/, "");
|
|
5141
|
-
const candidate =
|
|
5142
|
-
const inside = candidate.startsWith(
|
|
5157
|
+
const candidate = path26__default.default.resolve(CLIENT_DIR, rel);
|
|
5158
|
+
const inside = candidate.startsWith(path26__default.default.resolve(CLIENT_DIR) + path26__default.default.sep);
|
|
5143
5159
|
let file = candidate;
|
|
5144
5160
|
if (!inside || !fs.existsSync(candidate) || !await isFile(candidate)) {
|
|
5145
|
-
file =
|
|
5161
|
+
file = path26__default.default.join(CLIENT_DIR, "index.html");
|
|
5146
5162
|
}
|
|
5147
5163
|
if (!fs.existsSync(file)) {
|
|
5148
5164
|
res.writeHead(500, { "content-type": "text/plain" });
|
|
@@ -5247,9 +5263,9 @@ async function cleanupAfterRewrite(rewrittenIds, scopeAll) {
|
|
|
5247
5263
|
return;
|
|
5248
5264
|
}
|
|
5249
5265
|
const perId = rewrittenIds.flatMap((id) => [
|
|
5250
|
-
promises.rm(
|
|
5251
|
-
promises.rm(
|
|
5252
|
-
promises.rm(
|
|
5266
|
+
promises.rm(path26__default.default.join(p.actual, `${id}.png`), { force: true }),
|
|
5267
|
+
promises.rm(path26__default.default.join(p.actual, `${id}.diff.png`), { force: true }),
|
|
5268
|
+
promises.rm(path26__default.default.join(p.judgments, id), { recursive: true, force: true })
|
|
5253
5269
|
]);
|
|
5254
5270
|
await Promise.all([
|
|
5255
5271
|
...perId,
|
|
@@ -5287,7 +5303,7 @@ async function resolveTargets(manifest, ids, opts) {
|
|
|
5287
5303
|
const names = await promises.readdir(judgmentsDir);
|
|
5288
5304
|
const failed = /* @__PURE__ */ new Set();
|
|
5289
5305
|
for (const name of names) {
|
|
5290
|
-
const full =
|
|
5306
|
+
const full = path26__default.default.join(judgmentsDir, name);
|
|
5291
5307
|
if (fs.statSync(full).isDirectory()) failed.add(name);
|
|
5292
5308
|
}
|
|
5293
5309
|
return failed;
|
|
@@ -5403,14 +5419,14 @@ function extractCwdArg(argv) {
|
|
|
5403
5419
|
function applyCwdFromArgv() {
|
|
5404
5420
|
const value = extractCwdArg(process.argv.slice(2));
|
|
5405
5421
|
if (!value) return;
|
|
5406
|
-
const resolved =
|
|
5422
|
+
const resolved = path26__default.default.resolve(value);
|
|
5407
5423
|
if (fs.existsSync(resolved)) {
|
|
5408
5424
|
process.chdir(resolved);
|
|
5409
5425
|
return;
|
|
5410
5426
|
}
|
|
5411
|
-
const cwdBase =
|
|
5412
|
-
const inputBase =
|
|
5413
|
-
const doubled = cwdBase && inputBase && cwdBase === inputBase && resolved.endsWith(
|
|
5427
|
+
const cwdBase = path26__default.default.basename(process.cwd());
|
|
5428
|
+
const inputBase = path26__default.default.basename(value);
|
|
5429
|
+
const doubled = cwdBase && inputBase && cwdBase === inputBase && resolved.endsWith(path26__default.default.join(cwdBase, cwdBase));
|
|
5414
5430
|
if (doubled) {
|
|
5415
5431
|
throw new Error(
|
|
5416
5432
|
`--cwd "${value}" resolves to ${resolved} which does not exist. Looks like you may already be inside that directory - re-run with --cwd as an absolute path, or from the parent.`
|
|
@@ -5450,10 +5466,10 @@ function makeOutput(getRootOpts) {
|
|
|
5450
5466
|
function envFiles(cwd) {
|
|
5451
5467
|
const root = paths(cwd).root;
|
|
5452
5468
|
return [
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5469
|
+
path26__default.default.join(root, ".env.local"),
|
|
5470
|
+
path26__default.default.join(root, ".env"),
|
|
5471
|
+
path26__default.default.join(cwd, ".env.local"),
|
|
5472
|
+
path26__default.default.join(cwd, ".env")
|
|
5457
5473
|
];
|
|
5458
5474
|
}
|
|
5459
5475
|
function parse(content) {
|