@blazediff/agent 0.8.1 → 0.9.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 +570 -228
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +292 -100
- package/dist/index.mjs +292 -100
- package/dist/review/client/assets/index-9wONQNrk.js +8 -0
- package/dist/review/client/assets/index-Bod0vbl9.css +1 -0
- package/dist/review/client/assets/logo-DtDpqlir.png +0 -0
- package/dist/review/client/index.html +2 -2
- package/package.json +2 -2
- package/dist/review/client/assets/index-5OALw55C.js +0 -47
- package/dist/review/client/assets/index-CQM1Tg8y.css +0 -1
package/dist/cli.js
CHANGED
|
@@ -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.9.0"};
|
|
55
55
|
var FROZEN_NOW = Date.UTC(2025, 0, 1, 0, 0, 0);
|
|
56
56
|
var STABILITY_CSS = `
|
|
57
57
|
*,*::before,*::after{
|
|
@@ -422,7 +422,7 @@ async function stabilize(page, waitFor, masks) {
|
|
|
422
422
|
() => new Promise((r) => requestAnimationFrame(() => r()))
|
|
423
423
|
);
|
|
424
424
|
}
|
|
425
|
-
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses) {
|
|
425
|
+
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses, signal) {
|
|
426
426
|
const viewport = opts.viewport ?? DEFAULT_VIEWPORT;
|
|
427
427
|
const waitFor = opts.waitFor ?? DEFAULT_WAIT_FOR;
|
|
428
428
|
const masks = opts.mask ?? [];
|
|
@@ -440,7 +440,17 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
440
440
|
const context = handle.context;
|
|
441
441
|
const browser = await getBrowser();
|
|
442
442
|
const page = await openStablePage(handle);
|
|
443
|
+
const abortCapture = () => {
|
|
444
|
+
handle.disposable = true;
|
|
445
|
+
void context.close().catch(() => {
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
signal?.addEventListener("abort", abortCapture, { once: true });
|
|
443
449
|
try {
|
|
450
|
+
if (signal?.aborted) {
|
|
451
|
+
abortCapture();
|
|
452
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("capture aborted");
|
|
453
|
+
}
|
|
444
454
|
const rejectScreenshot = async () => {
|
|
445
455
|
throw new HarnessError("setup harness must not call screenshot()");
|
|
446
456
|
};
|
|
@@ -487,6 +497,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
487
497
|
subCaptures: subCaptures.length > 0 ? subCaptures : void 0
|
|
488
498
|
};
|
|
489
499
|
} finally {
|
|
500
|
+
signal?.removeEventListener("abort", abortCapture);
|
|
490
501
|
await page.close().catch(() => {
|
|
491
502
|
});
|
|
492
503
|
await releaseStableContext(handle);
|
|
@@ -516,21 +527,44 @@ function resolveBaseUrl(config, override) {
|
|
|
516
527
|
}
|
|
517
528
|
|
|
518
529
|
// src/graph/semaphore.ts
|
|
530
|
+
function abortReason(signal) {
|
|
531
|
+
return signal.reason instanceof Error ? signal.reason : new Error("operation aborted");
|
|
532
|
+
}
|
|
519
533
|
function createSemaphore(limit) {
|
|
520
534
|
if (limit < 1) throw new Error(`semaphore limit must be >= 1 (got ${limit})`);
|
|
521
535
|
let current = 0;
|
|
522
536
|
const queue = [];
|
|
523
|
-
async function run(fn) {
|
|
537
|
+
async function run(fn, signal) {
|
|
538
|
+
if (signal?.aborted) throw abortReason(signal);
|
|
524
539
|
if (current >= limit) {
|
|
525
|
-
await new Promise((resolve) =>
|
|
540
|
+
await new Promise((resolve, reject) => {
|
|
541
|
+
const onAbort = () => {
|
|
542
|
+
const index = queue.indexOf(waiter);
|
|
543
|
+
if (index >= 0) queue.splice(index, 1);
|
|
544
|
+
reject(abortReason(signal));
|
|
545
|
+
};
|
|
546
|
+
const waiter = {
|
|
547
|
+
start: () => {
|
|
548
|
+
signal?.removeEventListener("abort", onAbort);
|
|
549
|
+
if (signal?.aborted) {
|
|
550
|
+
reject(abortReason(signal));
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
current++;
|
|
554
|
+
resolve();
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
558
|
+
queue.push(waiter);
|
|
559
|
+
});
|
|
560
|
+
} else {
|
|
561
|
+
current++;
|
|
526
562
|
}
|
|
527
|
-
current++;
|
|
528
563
|
try {
|
|
529
564
|
return await fn();
|
|
530
565
|
} finally {
|
|
531
566
|
current--;
|
|
532
|
-
|
|
533
|
-
if (next) next();
|
|
567
|
+
queue.shift()?.start();
|
|
534
568
|
}
|
|
535
569
|
}
|
|
536
570
|
return { run };
|
|
@@ -1199,66 +1233,196 @@ function relPath(p, cwd = process.cwd()) {
|
|
|
1199
1233
|
}
|
|
1200
1234
|
|
|
1201
1235
|
// src/judge/transformers.ts
|
|
1236
|
+
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1237
|
+
var INTERACTIVE_REFRESH_MS = 80;
|
|
1238
|
+
var NON_INTERACTIVE_HEARTBEAT_MS = 1e4;
|
|
1239
|
+
var interactiveLoads = /* @__PURE__ */ new Map();
|
|
1240
|
+
var interactiveLinesDrawn = 0;
|
|
1241
|
+
var interactiveFrame = 0;
|
|
1242
|
+
var interactiveTimer;
|
|
1202
1243
|
var toMb = (bytes) => (bytes / 1048576).toFixed(1);
|
|
1203
|
-
|
|
1244
|
+
var elapsed = (startedAt) => `${((Date.now() - startedAt) / 1e3).toFixed(1)}s`;
|
|
1245
|
+
function clearInteractiveRows() {
|
|
1246
|
+
if (interactiveLinesDrawn === 0) return;
|
|
1247
|
+
process.stderr.write(`\x1B[${interactiveLinesDrawn}F\x1B[J`);
|
|
1248
|
+
interactiveLinesDrawn = 0;
|
|
1249
|
+
}
|
|
1250
|
+
function interactiveLine(load) {
|
|
1251
|
+
const duration = dim(`\xB7 ${elapsed(load.startedAt)}`);
|
|
1252
|
+
const size = load.total > 0 ? dim(`(${toMb(load.total)} MB)`) : "";
|
|
1253
|
+
if (load.status === "ready") {
|
|
1254
|
+
return ` ${pc__default.default.green("\u2713")} ${bold(load.label)} model ready ${size} ${duration}`.trimEnd();
|
|
1255
|
+
}
|
|
1256
|
+
if (load.status === "failed") {
|
|
1257
|
+
return ` ${pc__default.default.red("\u2717")} ${bold(load.label)} model failed ${duration}`;
|
|
1258
|
+
}
|
|
1259
|
+
const pct = load.total > 0 ? Math.min(100, Math.floor(load.loaded / load.total * 100)) : 0;
|
|
1260
|
+
const transferred = load.total > 0 ? `${pct}% ${dim(`(${toMb(load.loaded)}/${toMb(load.total)} MB)`)}` : `0% ${dim("(0.0 MB)")}`;
|
|
1261
|
+
const phase = load.total > 0 && load.loaded >= load.total ? dim("initializing runtime") : "loading";
|
|
1262
|
+
return ` ${pc__default.default.cyan(SPINNER_FRAMES[interactiveFrame])} ${bold(load.label)} model ${phase} ${transferred} ${duration}`;
|
|
1263
|
+
}
|
|
1264
|
+
function stopInteractiveTimer() {
|
|
1265
|
+
if (!interactiveTimer) return;
|
|
1266
|
+
clearInterval(interactiveTimer);
|
|
1267
|
+
interactiveTimer = void 0;
|
|
1268
|
+
}
|
|
1269
|
+
function redrawInteractiveRows() {
|
|
1270
|
+
clearInteractiveRows();
|
|
1271
|
+
let complete = interactiveLoads.size > 0;
|
|
1272
|
+
for (const load of interactiveLoads.values()) {
|
|
1273
|
+
process.stderr.write(`${interactiveLine(load)}
|
|
1274
|
+
`);
|
|
1275
|
+
if (load.status === "loading") complete = false;
|
|
1276
|
+
}
|
|
1277
|
+
if (complete) {
|
|
1278
|
+
interactiveLinesDrawn = 0;
|
|
1279
|
+
interactiveLoads.clear();
|
|
1280
|
+
stopInteractiveTimer();
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
interactiveLinesDrawn = interactiveLoads.size;
|
|
1284
|
+
}
|
|
1285
|
+
function startInteractiveTimer() {
|
|
1286
|
+
if (interactiveTimer) return;
|
|
1287
|
+
interactiveTimer = setInterval(() => {
|
|
1288
|
+
interactiveFrame = (interactiveFrame + 1) % SPINNER_FRAMES.length;
|
|
1289
|
+
redrawInteractiveRows();
|
|
1290
|
+
}, INTERACTIVE_REFRESH_MS);
|
|
1291
|
+
interactiveTimer.unref();
|
|
1292
|
+
}
|
|
1293
|
+
function setInteractiveLoad(id, load, status) {
|
|
1294
|
+
load.status = status;
|
|
1295
|
+
interactiveLoads.set(id, load);
|
|
1296
|
+
redrawInteractiveRows();
|
|
1297
|
+
}
|
|
1298
|
+
function createLoadProgress(label, opts) {
|
|
1204
1299
|
const interactive = Boolean(process.stderr.isTTY);
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1300
|
+
const id = Symbol(label);
|
|
1301
|
+
const files = /* @__PURE__ */ new Map();
|
|
1302
|
+
const load = {
|
|
1303
|
+
label,
|
|
1304
|
+
startedAt: Date.now(),
|
|
1305
|
+
loaded: 0,
|
|
1306
|
+
total: 0,
|
|
1307
|
+
status: "loading"
|
|
1308
|
+
};
|
|
1309
|
+
let started = false;
|
|
1310
|
+
let finished = false;
|
|
1207
1311
|
let lastPct = -1;
|
|
1208
1312
|
let lastBucket = -1;
|
|
1313
|
+
let heartbeat;
|
|
1209
1314
|
const totals = () => {
|
|
1210
1315
|
let loaded = 0;
|
|
1211
1316
|
let total = 0;
|
|
1212
|
-
for (const
|
|
1213
|
-
loaded +=
|
|
1214
|
-
total +=
|
|
1317
|
+
for (const file of files.values()) {
|
|
1318
|
+
loaded += file.loaded;
|
|
1319
|
+
total += file.total;
|
|
1215
1320
|
}
|
|
1216
1321
|
const pct = total > 0 ? Math.min(100, Math.floor(loaded / total * 100)) : 0;
|
|
1217
1322
|
return { loaded, total, pct };
|
|
1218
1323
|
};
|
|
1324
|
+
const stopHeartbeat = () => {
|
|
1325
|
+
if (!heartbeat) return;
|
|
1326
|
+
clearInterval(heartbeat);
|
|
1327
|
+
heartbeat = void 0;
|
|
1328
|
+
};
|
|
1329
|
+
const start = () => {
|
|
1330
|
+
if (started) return;
|
|
1331
|
+
started = true;
|
|
1332
|
+
load.startedAt = Date.now();
|
|
1333
|
+
if (interactive) {
|
|
1334
|
+
interactiveLoads.set(id, load);
|
|
1335
|
+
startInteractiveTimer();
|
|
1336
|
+
redrawInteractiveRows();
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
process.stderr.write(
|
|
1340
|
+
`${dim("[blazediff]")} loading ${bold(label)} model ${dim("(first run may download weights)\u2026")}
|
|
1341
|
+
`
|
|
1342
|
+
);
|
|
1343
|
+
process.stderr.write(` ${label}: 0% ${dim("(0.0 MB)")}
|
|
1344
|
+
`);
|
|
1345
|
+
lastBucket = 0;
|
|
1346
|
+
heartbeat = setInterval(() => {
|
|
1347
|
+
const { loaded, total, pct } = totals();
|
|
1348
|
+
const phase = total > 0 && loaded >= total ? "initializing runtime" : "still loading";
|
|
1349
|
+
const transfer = total > 0 ? `${pct}% (${toMb(loaded)}/${toMb(total)} MB)` : "0% (0.0 MB)";
|
|
1350
|
+
process.stderr.write(
|
|
1351
|
+
` ${label}: ${phase} ${transfer} ${dim(`\xB7 ${elapsed(load.startedAt)}`)}
|
|
1352
|
+
`
|
|
1353
|
+
);
|
|
1354
|
+
}, NON_INTERACTIVE_HEARTBEAT_MS);
|
|
1355
|
+
heartbeat.unref();
|
|
1356
|
+
};
|
|
1357
|
+
const finish = (status) => {
|
|
1358
|
+
if (finished) return;
|
|
1359
|
+
start();
|
|
1360
|
+
finished = true;
|
|
1361
|
+
stopHeartbeat();
|
|
1362
|
+
if (interactive) {
|
|
1363
|
+
setInteractiveLoad(id, load, status);
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
const { total } = totals();
|
|
1367
|
+
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1368
|
+
const state = status === "ready" ? pc__default.default.green("ready") : pc__default.default.red("failed");
|
|
1369
|
+
process.stderr.write(
|
|
1370
|
+
` ${label}: ${state}${size} ${dim(`\xB7 ${elapsed(load.startedAt)}`)}
|
|
1371
|
+
`
|
|
1372
|
+
);
|
|
1373
|
+
};
|
|
1219
1374
|
return {
|
|
1375
|
+
start,
|
|
1220
1376
|
onProgress(event) {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
);
|
|
1226
|
-
|
|
1377
|
+
start();
|
|
1378
|
+
if (!event.file) return;
|
|
1379
|
+
if (event.status === "done") {
|
|
1380
|
+
const file = files.get(event.file);
|
|
1381
|
+
if (!file) return;
|
|
1382
|
+
files.set(event.file, { loaded: file.total, total: file.total });
|
|
1383
|
+
} else {
|
|
1384
|
+
if (event.status !== "progress" || typeof event.total !== "number")
|
|
1385
|
+
return;
|
|
1386
|
+
files.set(event.file, {
|
|
1387
|
+
loaded: event.loaded ?? 0,
|
|
1388
|
+
total: event.total
|
|
1389
|
+
});
|
|
1227
1390
|
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
lastPct = pct;
|
|
1234
|
-
const line = ` ${label}: ${pct}% ${dim(`(${toMb(loaded)}/${toMb(total)} MB)`)}`;
|
|
1391
|
+
const current = totals();
|
|
1392
|
+
load.loaded = current.loaded;
|
|
1393
|
+
load.total = current.total;
|
|
1394
|
+
if (current.pct === lastPct) return;
|
|
1395
|
+
lastPct = current.pct;
|
|
1235
1396
|
if (interactive) {
|
|
1236
|
-
|
|
1397
|
+
redrawInteractiveRows();
|
|
1237
1398
|
return;
|
|
1238
1399
|
}
|
|
1239
|
-
const bucket = Math.floor(pct / 25);
|
|
1400
|
+
const bucket = Math.floor(current.pct / 25);
|
|
1240
1401
|
if (bucket > lastBucket) {
|
|
1241
1402
|
lastBucket = bucket;
|
|
1242
|
-
process.stderr.write(`${line}
|
|
1243
|
-
`);
|
|
1244
|
-
}
|
|
1245
|
-
},
|
|
1246
|
-
done() {
|
|
1247
|
-
if (!announced) return;
|
|
1248
|
-
if (interactive) {
|
|
1249
|
-
const { total } = totals();
|
|
1250
|
-
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1251
1403
|
process.stderr.write(
|
|
1252
|
-
|
|
1404
|
+
` ${label}: ${current.pct}% ${dim(`(${toMb(current.loaded)}/${toMb(current.total)} MB)`)}
|
|
1253
1405
|
`
|
|
1254
1406
|
);
|
|
1255
|
-
} else if (lastPct < 100) {
|
|
1256
|
-
process.stderr.write(` ${label}: ${pc__default.default.green("ready")}
|
|
1257
|
-
`);
|
|
1258
1407
|
}
|
|
1259
|
-
}
|
|
1408
|
+
},
|
|
1409
|
+
done: () => finish("ready"),
|
|
1410
|
+
fail: () => finish("failed")
|
|
1260
1411
|
};
|
|
1261
1412
|
}
|
|
1413
|
+
async function loadTransformersModel(label, load) {
|
|
1414
|
+
const progress = createLoadProgress(label);
|
|
1415
|
+
progress.start();
|
|
1416
|
+
try {
|
|
1417
|
+
const mod = await loadTransformers();
|
|
1418
|
+
const result = await load(mod, progress.onProgress);
|
|
1419
|
+
progress.done();
|
|
1420
|
+
return result;
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
progress.fail();
|
|
1423
|
+
throw error;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1262
1426
|
async function loadTransformers() {
|
|
1263
1427
|
try {
|
|
1264
1428
|
return await import('@huggingface/transformers');
|
|
@@ -1274,22 +1438,24 @@ async function loadTransformers() {
|
|
|
1274
1438
|
var MODEL_ID = "onnx-community/Qwen3.5-0.8B-ONNX";
|
|
1275
1439
|
var MAX_NEW_TOKENS = 64;
|
|
1276
1440
|
async function defaultFactory() {
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1441
|
+
const { tokenizer, model } = await loadTransformersModel(
|
|
1442
|
+
"classifier",
|
|
1443
|
+
async (mod, progress_callback) => {
|
|
1444
|
+
const [tokenizer2, model2] = await Promise.all([
|
|
1445
|
+
mod.AutoTokenizer.from_pretrained(MODEL_ID, { progress_callback }),
|
|
1446
|
+
mod.Qwen3_5ForConditionalGeneration.from_pretrained(MODEL_ID, {
|
|
1447
|
+
dtype: {
|
|
1448
|
+
embed_tokens: "fp32",
|
|
1449
|
+
vision_encoder: "q8",
|
|
1450
|
+
decoder_model_merged: "q4"
|
|
1451
|
+
},
|
|
1452
|
+
device: "cpu",
|
|
1453
|
+
progress_callback
|
|
1454
|
+
})
|
|
1455
|
+
]);
|
|
1456
|
+
return { tokenizer: tokenizer2, model: model2 };
|
|
1457
|
+
}
|
|
1458
|
+
);
|
|
1293
1459
|
return {
|
|
1294
1460
|
async complete(prompt) {
|
|
1295
1461
|
const inputs = tokenizer.apply_chat_template(
|
|
@@ -1527,23 +1693,25 @@ var PATCH_SIZE = 14;
|
|
|
1527
1693
|
var MAX_NEW_TOKENS2 = 64;
|
|
1528
1694
|
var ANSWER_MARKER = "Answer:";
|
|
1529
1695
|
async function defaultFactory2() {
|
|
1530
|
-
const mod = await
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1696
|
+
const { mod, tokenizer, processor, model } = await loadTransformersModel(
|
|
1697
|
+
"vision",
|
|
1698
|
+
async (mod2, progress_callback) => {
|
|
1699
|
+
const [tokenizer2, processor2, model2] = await Promise.all([
|
|
1700
|
+
mod2.AutoTokenizer.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1701
|
+
mod2.AutoProcessor.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1702
|
+
mod2.Moondream1ForConditionalGeneration.from_pretrained(MODEL_ID2, {
|
|
1703
|
+
dtype: {
|
|
1704
|
+
embed_tokens: "fp32",
|
|
1705
|
+
vision_encoder: "q8",
|
|
1706
|
+
decoder_model_merged: "q4"
|
|
1707
|
+
},
|
|
1708
|
+
device: "cpu",
|
|
1709
|
+
progress_callback
|
|
1710
|
+
})
|
|
1711
|
+
]);
|
|
1712
|
+
return { mod: mod2, tokenizer: tokenizer2, processor: processor2, model: model2 };
|
|
1713
|
+
}
|
|
1714
|
+
);
|
|
1547
1715
|
return {
|
|
1548
1716
|
async describe(imagePath, question) {
|
|
1549
1717
|
const image = await mod.RawImage.read(imagePath);
|
|
@@ -2517,7 +2685,7 @@ function failResult(entry, outcome, actualPath, baselinePath, verdict) {
|
|
|
2517
2685
|
function asCaptured(entry, output) {
|
|
2518
2686
|
return { entry, output };
|
|
2519
2687
|
}
|
|
2520
|
-
function makeCaptureNode(semaphore) {
|
|
2688
|
+
function makeCaptureNode(semaphore, abortController) {
|
|
2521
2689
|
return async function captureNode(state) {
|
|
2522
2690
|
const entry = state.entry;
|
|
2523
2691
|
const options = state.options;
|
|
@@ -2560,22 +2728,33 @@ function makeCaptureNode(semaphore) {
|
|
|
2560
2728
|
}
|
|
2561
2729
|
const baselinePath = path26__default.default.join(options.baselinesDir, `${entry.id}.png`);
|
|
2562
2730
|
try {
|
|
2563
|
-
const capture = await semaphore.run(
|
|
2564
|
-
(
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2731
|
+
const capture = await semaphore.run(async () => {
|
|
2732
|
+
emitEvent({
|
|
2733
|
+
type: "capturing",
|
|
2734
|
+
entryId: entry.id,
|
|
2735
|
+
url: entry.url
|
|
2736
|
+
});
|
|
2737
|
+
try {
|
|
2738
|
+
return await captureScreenshot(
|
|
2739
|
+
options.baseUrl,
|
|
2740
|
+
{
|
|
2741
|
+
id: entry.id,
|
|
2742
|
+
url: entry.url,
|
|
2743
|
+
viewport: entry.viewport,
|
|
2744
|
+
mask: entry.mask,
|
|
2745
|
+
waitFor: entry.waitFor,
|
|
2746
|
+
fullPage: entry.fullPage ?? DEFAULT_FULL_PAGE,
|
|
2747
|
+
mode: "actual"
|
|
2748
|
+
},
|
|
2749
|
+
options.cwd,
|
|
2750
|
+
harnesses,
|
|
2751
|
+
abortController.signal
|
|
2752
|
+
);
|
|
2753
|
+
} catch (err) {
|
|
2754
|
+
if (!(err instanceof HarnessError)) abortController.abort(err);
|
|
2755
|
+
throw err;
|
|
2756
|
+
}
|
|
2757
|
+
}, abortController.signal);
|
|
2579
2758
|
const items = [
|
|
2580
2759
|
asCaptured(entry, {
|
|
2581
2760
|
id: entry.id,
|
|
@@ -2718,15 +2897,16 @@ function makeDiffNode(semaphore) {
|
|
|
2718
2897
|
if (!capture.captureOutputPath || !capture.baselinePath) {
|
|
2719
2898
|
throw new Error("diffNode: capture output paths missing");
|
|
2720
2899
|
}
|
|
2721
|
-
const outcome = await semaphore.run(
|
|
2722
|
-
(
|
|
2900
|
+
const outcome = await semaphore.run(() => {
|
|
2901
|
+
emitEvent({ type: "diffing", entryId: entry.id, url: entry.url });
|
|
2902
|
+
return diffEntry(
|
|
2723
2903
|
entry.id,
|
|
2724
2904
|
capture.baselinePath,
|
|
2725
2905
|
capture.captureOutputPath,
|
|
2726
2906
|
{ threshold: options.threshold, emitDiffPng: options.emitDiffPng },
|
|
2727
2907
|
options.cwd
|
|
2728
|
-
)
|
|
2729
|
-
);
|
|
2908
|
+
);
|
|
2909
|
+
});
|
|
2730
2910
|
if (outcome.reason === "file-not-exists") {
|
|
2731
2911
|
return {
|
|
2732
2912
|
diffOutput: {
|
|
@@ -3053,18 +3233,23 @@ var GraphState = langgraph.Annotation.Root({
|
|
|
3053
3233
|
function threadIdFor(cwd) {
|
|
3054
3234
|
return crypto$1.createHash("sha1").update(paths(cwd).manifest).digest("hex").slice(0, 16);
|
|
3055
3235
|
}
|
|
3056
|
-
function buildCaptureGraph(captureSemaphore) {
|
|
3057
|
-
return new langgraph.StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore)).addEdge(langgraph.START, "capture").addEdge("capture", langgraph.END).compile();
|
|
3236
|
+
function buildCaptureGraph(captureSemaphore, abortController) {
|
|
3237
|
+
return new langgraph.StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore, abortController)).addEdge(langgraph.START, "capture").addEdge("capture", langgraph.END).compile();
|
|
3058
3238
|
}
|
|
3059
3239
|
function buildBranchGraph(diffSemaphore) {
|
|
3060
3240
|
return new langgraph.StateGraph(BranchState).addNode("diff", makeDiffNode(diffSemaphore)).addNode("judge", judgeNode).addEdge(langgraph.START, "diff").addEdge("diff", "judge").addEdge("judge", langgraph.END).compile();
|
|
3061
3241
|
}
|
|
3062
3242
|
async function dispatchNode(state) {
|
|
3243
|
+
const total = state.captured.length;
|
|
3244
|
+
const captured = state.captured.filter(
|
|
3245
|
+
(item) => item.output.captureOutputPath
|
|
3246
|
+
).length;
|
|
3247
|
+
emitEvent({ type: "capture-complete", captured, total });
|
|
3063
3248
|
if (state.options) await resolveJudge(state.options.judge).warmup?.();
|
|
3064
3249
|
return {};
|
|
3065
3250
|
}
|
|
3066
|
-
function buildGraph(captureSemaphore, diffSemaphore, checkpointer) {
|
|
3067
|
-
const captureBranch = buildCaptureGraph(captureSemaphore);
|
|
3251
|
+
function buildGraph(captureSemaphore, diffSemaphore, checkpointer, abortController) {
|
|
3252
|
+
const captureBranch = buildCaptureGraph(captureSemaphore, abortController);
|
|
3068
3253
|
const branch = buildBranchGraph(diffSemaphore);
|
|
3069
3254
|
return new langgraph.StateGraph(GraphState).addNode("load", loadNode).addNode("capture", captureBranch).addNode("dispatch", dispatchNode).addNode("branch", branch).addEdge(langgraph.START, "load").addConditionalEdges(
|
|
3070
3255
|
"load",
|
|
@@ -3156,9 +3341,15 @@ async function runGraph(opts) {
|
|
|
3156
3341
|
const concurrency = opts.concurrency ?? defaultConcurrency();
|
|
3157
3342
|
const captureSemaphore = createSemaphore(concurrency);
|
|
3158
3343
|
const diffSemaphore = createSemaphore(cpuCores());
|
|
3344
|
+
const abortController = new AbortController();
|
|
3159
3345
|
const baselinesDir = paths(cwd).baselines;
|
|
3160
3346
|
const checkpointer = new FsCheckpointSaver(paths(cwd).checkpoints);
|
|
3161
|
-
const graph = buildGraph(
|
|
3347
|
+
const graph = buildGraph(
|
|
3348
|
+
captureSemaphore,
|
|
3349
|
+
diffSemaphore,
|
|
3350
|
+
checkpointer,
|
|
3351
|
+
abortController
|
|
3352
|
+
);
|
|
3162
3353
|
const threadId = opts.threadId ?? threadIdFor(cwd);
|
|
3163
3354
|
if (!opts.resume) {
|
|
3164
3355
|
await checkpointer.deleteThread(threadId);
|
|
@@ -3179,6 +3370,7 @@ async function runGraph(opts) {
|
|
|
3179
3370
|
try {
|
|
3180
3371
|
collect = await streamGraph(graph, input, threadId, opts.onEvent);
|
|
3181
3372
|
} finally {
|
|
3373
|
+
abortController.abort();
|
|
3182
3374
|
setEventSink(void 0);
|
|
3183
3375
|
await closeBrowser();
|
|
3184
3376
|
}
|
|
@@ -3410,122 +3602,233 @@ function summaryLine(report) {
|
|
|
3410
3602
|
const text = `${head}${tail}`;
|
|
3411
3603
|
return failed === 0 && pendingJudgments === 0 ? pc__default.default.green(bold(text)) : pc__default.default.red(bold(text));
|
|
3412
3604
|
}
|
|
3605
|
+
function checkSummary(report, reportPath, judgmentsPath) {
|
|
3606
|
+
const summary = summaryLine(report);
|
|
3607
|
+
if (report.failed === 0 && report.pendingJudgments === 0) {
|
|
3608
|
+
return `${summary}
|
|
3609
|
+
report: ${relPath(reportPath)}`;
|
|
3610
|
+
}
|
|
3611
|
+
return [
|
|
3612
|
+
summary,
|
|
3613
|
+
`report: ${relPath(reportPath)}`,
|
|
3614
|
+
report.pendingJudgments > 0 ? `pending: ${relPath(judgmentsPath)}/ - host writes <id>/verdict.json, then re-run check --apply-judgments` : void 0,
|
|
3615
|
+
"run `blazediff-agent review` to review interactively"
|
|
3616
|
+
].filter(Boolean).join("\n");
|
|
3617
|
+
}
|
|
3618
|
+
function liveResultDetail(result, awaitingJudgment = false) {
|
|
3619
|
+
const details = [];
|
|
3620
|
+
if (result.verdict?.headline) {
|
|
3621
|
+
details.push(result.verdict.headline);
|
|
3622
|
+
} else if (result.status !== "pass" && result.message) {
|
|
3623
|
+
details.push(result.message);
|
|
3624
|
+
} else if (result.status === "fail" && typeof result.diffPercentage === "number") {
|
|
3625
|
+
details.push(`${result.diffPercentage.toFixed(3)}%`);
|
|
3626
|
+
}
|
|
3627
|
+
if (awaitingJudgment) details.push("awaiting judgment");
|
|
3628
|
+
return details.join(" \xB7 ");
|
|
3629
|
+
}
|
|
3413
3630
|
function progressLine(event) {
|
|
3631
|
+
if (event.type === "capturing") {
|
|
3632
|
+
return `${pc__default.default.cyan("\u25CC")} ${event.entryId}${dim(" (capturing\u2026)")}`;
|
|
3633
|
+
}
|
|
3634
|
+
if (event.type === "captured") {
|
|
3635
|
+
return `${pc__default.default.green("\u2713")} ${event.entryId}${dim(" (captured)")}`;
|
|
3636
|
+
}
|
|
3637
|
+
if (event.type === "capture-complete") {
|
|
3638
|
+
const count = event.captured === event.total ? `${event.captured} screenshot${event.captured === 1 ? "" : "s"}` : `${event.captured}/${event.total} screenshots`;
|
|
3639
|
+
return `${pc__default.default.green("\u2713")} capture complete${dim(` (${count})`)}`;
|
|
3640
|
+
}
|
|
3641
|
+
if (event.type === "diffing") {
|
|
3642
|
+
return `${pc__default.default.cyan("\u25CC")} ${event.entryId}${dim(" (comparing\u2026)")}`;
|
|
3643
|
+
}
|
|
3414
3644
|
if (event.type === "result") {
|
|
3415
|
-
const
|
|
3416
|
-
const detail =
|
|
3417
|
-
return `${statusGlyph(
|
|
3645
|
+
const detailText = liveResultDetail(event.result);
|
|
3646
|
+
const detail = detailText ? dim(` (${detailText})`) : "";
|
|
3647
|
+
return `${statusGlyph(event.result.status)} ${event.result.id}${detail}`;
|
|
3418
3648
|
}
|
|
3419
3649
|
if (event.type === "judging") {
|
|
3420
3650
|
return `${pc__default.default.cyan("\u25CC")} ${event.entryId}${dim(" (judging\u2026)")}`;
|
|
3421
3651
|
}
|
|
3422
3652
|
if (event.type === "interrupt") {
|
|
3423
|
-
|
|
3653
|
+
const pending = event.interrupt.pendingResult;
|
|
3654
|
+
const detail = liveResultDetail(pending, true);
|
|
3655
|
+
return `${pc__default.default.yellow("?")} ${event.interrupt.entryId}${detail ? dim(` (${detail})`) : ""}`;
|
|
3424
3656
|
}
|
|
3425
3657
|
return void 0;
|
|
3426
3658
|
}
|
|
3427
|
-
function groupFailures(results) {
|
|
3428
|
-
const order = [];
|
|
3429
|
-
const groups = /* @__PURE__ */ new Map();
|
|
3430
|
-
for (const r of results) {
|
|
3431
|
-
if (r.status === "pass") continue;
|
|
3432
|
-
const signature = r.verdict ? `v:${r.status}|${r.verdict.label}|${r.verdict.headline}|${r.verdict.action}` : `s:${r.id}`;
|
|
3433
|
-
let group = groups.get(signature);
|
|
3434
|
-
if (!group) {
|
|
3435
|
-
group = { signature, results: [], verdict: r.verdict };
|
|
3436
|
-
groups.set(signature, group);
|
|
3437
|
-
order.push(signature);
|
|
3438
|
-
}
|
|
3439
|
-
group.results.push(r);
|
|
3440
|
-
}
|
|
3441
|
-
return order.map((s) => groups.get(s));
|
|
3442
|
-
}
|
|
3443
|
-
function detailFor(r) {
|
|
3444
|
-
if (typeof r.diffPercentage === "number") {
|
|
3445
|
-
return `${r.status} (${r.diffPercentage.toFixed(3)}%)`;
|
|
3446
|
-
}
|
|
3447
|
-
return r.status;
|
|
3448
|
-
}
|
|
3449
|
-
function failureBlock(results) {
|
|
3450
|
-
const groups = groupFailures(results);
|
|
3451
|
-
const verdictGroups = groups.filter((g) => g.verdict);
|
|
3452
|
-
const multipleVerdicts = verdictGroups.length > 1;
|
|
3453
|
-
const lines = [];
|
|
3454
|
-
for (const group of groups) {
|
|
3455
|
-
if (group.verdict) {
|
|
3456
|
-
const headline = group.verdict.headline;
|
|
3457
|
-
if (multipleVerdicts) {
|
|
3458
|
-
const ids = group.results.map((r2) => r2.id).join(", ");
|
|
3459
|
-
lines.push(`${dim(`${ids}:`)} ${headline}`);
|
|
3460
|
-
} else {
|
|
3461
|
-
lines.push(headline);
|
|
3462
|
-
}
|
|
3463
|
-
continue;
|
|
3464
|
-
}
|
|
3465
|
-
const r = group.results[0];
|
|
3466
|
-
lines.push(`${statusGlyph(r.status)} ${bold(r.id)}: ${detailFor(r)}`);
|
|
3467
|
-
if (r.status === "needs-judgment" && r.message) {
|
|
3468
|
-
lines.push(dim(` ${r.message}`));
|
|
3469
|
-
}
|
|
3470
|
-
}
|
|
3471
|
-
return lines;
|
|
3472
|
-
}
|
|
3473
3659
|
|
|
3474
3660
|
// src/cli/render/progress.ts
|
|
3475
3661
|
function createProgress(opts) {
|
|
3476
3662
|
const interactive = Boolean(process.stderr.isTTY);
|
|
3477
|
-
const
|
|
3478
|
-
const
|
|
3479
|
-
let
|
|
3480
|
-
function
|
|
3481
|
-
if (event.type === "
|
|
3663
|
+
const announcedPhases = /* @__PURE__ */ new Set();
|
|
3664
|
+
const completed = /* @__PURE__ */ new Set();
|
|
3665
|
+
let liveLineVisible = false;
|
|
3666
|
+
function terminalKey(event) {
|
|
3667
|
+
if (event.type === "result") return event.result.id;
|
|
3668
|
+
if (event.type === "interrupt") return event.interrupt.entryId;
|
|
3669
|
+
return void 0;
|
|
3670
|
+
}
|
|
3671
|
+
function writePermanent(event) {
|
|
3672
|
+
const key = terminalKey(event);
|
|
3673
|
+
if (key && completed.has(key)) return;
|
|
3482
3674
|
const line = progressLine(event);
|
|
3483
|
-
if (line)
|
|
3675
|
+
if (!line) return;
|
|
3676
|
+
if (key) completed.add(key);
|
|
3677
|
+
process.stderr.write(`${line}
|
|
3484
3678
|
`);
|
|
3485
3679
|
}
|
|
3486
|
-
function
|
|
3487
|
-
if (event.type === "
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3680
|
+
function appendOnly(event) {
|
|
3681
|
+
if (event.type === "capturing" || event.type === "diffing" || event.type === "judging") {
|
|
3682
|
+
if (announcedPhases.has(event.type)) return;
|
|
3683
|
+
announcedPhases.add(event.type);
|
|
3684
|
+
writePermanent(event);
|
|
3685
|
+
return;
|
|
3686
|
+
}
|
|
3687
|
+
if (event.type === "capture-complete" || event.type === "result" || event.type === "interrupt") {
|
|
3688
|
+
writePermanent(event);
|
|
3689
|
+
}
|
|
3494
3690
|
}
|
|
3495
3691
|
function clearLive() {
|
|
3496
|
-
if (
|
|
3497
|
-
process.stderr.write(
|
|
3498
|
-
|
|
3499
|
-
}
|
|
3500
|
-
function
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
if (line) process.stderr.write(`${line}
|
|
3506
|
-
`);
|
|
3507
|
-
}
|
|
3508
|
-
linesDrawn = order.length;
|
|
3692
|
+
if (!liveLineVisible) return;
|
|
3693
|
+
process.stderr.write("\r\x1B[2K");
|
|
3694
|
+
liveLineVisible = false;
|
|
3695
|
+
}
|
|
3696
|
+
function replaceLive(event) {
|
|
3697
|
+
const line = progressLine(event);
|
|
3698
|
+
if (!line) return;
|
|
3699
|
+
process.stderr.write(`\r\x1B[2K${line}`);
|
|
3700
|
+
liveLineVisible = true;
|
|
3509
3701
|
}
|
|
3510
|
-
function
|
|
3511
|
-
if (event.type
|
|
3702
|
+
function interactiveEvent(event) {
|
|
3703
|
+
if (event.type === "report") {
|
|
3704
|
+
clearLive();
|
|
3512
3705
|
return;
|
|
3513
3706
|
}
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3707
|
+
if (event.type === "result" || event.type === "interrupt" || event.type === "capture-complete") {
|
|
3708
|
+
clearLive();
|
|
3709
|
+
writePermanent(event);
|
|
3710
|
+
return;
|
|
3711
|
+
}
|
|
3712
|
+
if (event.type === "capturing" || event.type === "captured" || event.type === "diffing" || event.type === "judging") {
|
|
3713
|
+
replaceLive(event);
|
|
3714
|
+
}
|
|
3517
3715
|
}
|
|
3518
3716
|
function emit(event) {
|
|
3519
|
-
if (
|
|
3520
|
-
|
|
3521
|
-
appendOnly(event);
|
|
3717
|
+
if (interactive) {
|
|
3718
|
+
interactiveEvent(event);
|
|
3522
3719
|
return;
|
|
3523
3720
|
}
|
|
3524
|
-
|
|
3721
|
+
if (event.type !== "report") appendOnly(event);
|
|
3525
3722
|
}
|
|
3526
3723
|
return { emit };
|
|
3527
3724
|
}
|
|
3528
3725
|
|
|
3726
|
+
// src/cli/render/server.ts
|
|
3727
|
+
var SPINNER_FRAMES2 = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
3728
|
+
var INTERACTIVE_REFRESH_MS2 = 80;
|
|
3729
|
+
var NON_INTERACTIVE_HEARTBEAT_MS2 = 1e4;
|
|
3730
|
+
function createDevServerProgress(out, opts) {
|
|
3731
|
+
if (out.isQuiet() || out.isJson()) {
|
|
3732
|
+
return {
|
|
3733
|
+
checking() {
|
|
3734
|
+
},
|
|
3735
|
+
starting() {
|
|
3736
|
+
},
|
|
3737
|
+
ready() {
|
|
3738
|
+
},
|
|
3739
|
+
failed() {
|
|
3740
|
+
}
|
|
3741
|
+
};
|
|
3742
|
+
}
|
|
3743
|
+
const interactive = opts.interactive ?? out.isTTY();
|
|
3744
|
+
const url = `http://127.0.0.1:${opts.port}`;
|
|
3745
|
+
const startedAt = Date.now();
|
|
3746
|
+
let phase = "idle";
|
|
3747
|
+
let frame = 0;
|
|
3748
|
+
let timer;
|
|
3749
|
+
const elapsed2 = () => `${((Date.now() - startedAt) / 1e3).toFixed(1)}s`;
|
|
3750
|
+
const stopTimer = () => {
|
|
3751
|
+
if (!timer) return;
|
|
3752
|
+
clearInterval(timer);
|
|
3753
|
+
timer = void 0;
|
|
3754
|
+
};
|
|
3755
|
+
const interactiveLine2 = () => {
|
|
3756
|
+
const spinner = pc__default.default.cyan(SPINNER_FRAMES2[frame]);
|
|
3757
|
+
if (phase === "checking") {
|
|
3758
|
+
return ` ${spinner} checking dev server ${dim(url)} ${dim(`\xB7 ${elapsed2()}`)}`;
|
|
3759
|
+
}
|
|
3760
|
+
return ` ${spinner} starting dev server ${dim(url)} ${dim(`\xB7 ${elapsed2()}`)}`;
|
|
3761
|
+
};
|
|
3762
|
+
const drawInteractive = () => {
|
|
3763
|
+
process.stderr.write(`\r${interactiveLine2()}\x1B[K`);
|
|
3764
|
+
};
|
|
3765
|
+
const startInteractiveTimer2 = () => {
|
|
3766
|
+
if (timer) return;
|
|
3767
|
+
timer = setInterval(() => {
|
|
3768
|
+
frame = (frame + 1) % SPINNER_FRAMES2.length;
|
|
3769
|
+
drawInteractive();
|
|
3770
|
+
}, INTERACTIVE_REFRESH_MS2);
|
|
3771
|
+
timer.unref();
|
|
3772
|
+
};
|
|
3773
|
+
return {
|
|
3774
|
+
checking() {
|
|
3775
|
+
if (phase !== "idle") return;
|
|
3776
|
+
phase = "checking";
|
|
3777
|
+
if (interactive) {
|
|
3778
|
+
drawInteractive();
|
|
3779
|
+
startInteractiveTimer2();
|
|
3780
|
+
return;
|
|
3781
|
+
}
|
|
3782
|
+
process.stderr.write(
|
|
3783
|
+
`${dim("[blazediff]")} checking dev server ${dim(url)}
|
|
3784
|
+
`
|
|
3785
|
+
);
|
|
3786
|
+
},
|
|
3787
|
+
starting() {
|
|
3788
|
+
if (phase === "ready" || phase === "failed") return;
|
|
3789
|
+
phase = "starting";
|
|
3790
|
+
if (interactive) {
|
|
3791
|
+
drawInteractive();
|
|
3792
|
+
return;
|
|
3793
|
+
}
|
|
3794
|
+
process.stderr.write(
|
|
3795
|
+
`${dim("[blazediff]")} starting dev server
|
|
3796
|
+
command: ${bold(opts.command)}
|
|
3797
|
+
waiting: ${url}
|
|
3798
|
+
logs: ${relPath(opts.logPath)}
|
|
3799
|
+
`
|
|
3800
|
+
);
|
|
3801
|
+
timer = setInterval(() => {
|
|
3802
|
+
process.stderr.write(
|
|
3803
|
+
` dev server: still starting ${dim(`\xB7 ${elapsed2()}`)} ${dim(`\xB7 logs: ${relPath(opts.logPath)}`)}
|
|
3804
|
+
`
|
|
3805
|
+
);
|
|
3806
|
+
}, NON_INTERACTIVE_HEARTBEAT_MS2);
|
|
3807
|
+
timer.unref();
|
|
3808
|
+
},
|
|
3809
|
+
ready(attached) {
|
|
3810
|
+
if (phase === "ready" || phase === "failed") return;
|
|
3811
|
+
phase = "ready";
|
|
3812
|
+
stopTimer();
|
|
3813
|
+
const state = attached ? "already running" : "ready";
|
|
3814
|
+
const logs = attached ? "" : dim(` \xB7 logs: ${relPath(opts.logPath)}`);
|
|
3815
|
+
const line = `${pc__default.default.green("\u2713")} dev server ${state} ${dim(url)} ${dim(`\xB7 ${elapsed2()}`)}${logs}`;
|
|
3816
|
+
process.stderr.write(interactive ? `\r${line}\x1B[K
|
|
3817
|
+
` : `${line}
|
|
3818
|
+
`);
|
|
3819
|
+
},
|
|
3820
|
+
failed() {
|
|
3821
|
+
if (phase === "ready" || phase === "failed") return;
|
|
3822
|
+
phase = "failed";
|
|
3823
|
+
stopTimer();
|
|
3824
|
+
const line = `${pc__default.default.red("\u2717")} dev server failed ${dim(`\xB7 logs: ${relPath(opts.logPath)}`)}`;
|
|
3825
|
+
process.stderr.write(interactive ? `\r${line}\x1B[K
|
|
3826
|
+
` : `${line}
|
|
3827
|
+
`);
|
|
3828
|
+
}
|
|
3829
|
+
};
|
|
3830
|
+
}
|
|
3831
|
+
|
|
3529
3832
|
// src/cli/commands/check.ts
|
|
3530
3833
|
function makeProgressReporter(out) {
|
|
3531
3834
|
if (out.isJson() || out.isQuiet()) return void 0;
|
|
@@ -3545,38 +3848,52 @@ function buildApplyHuman(r, reportPath) {
|
|
|
3545
3848
|
` report: ${relPath(reportPath)}`
|
|
3546
3849
|
].filter(Boolean).join("\n");
|
|
3547
3850
|
}
|
|
3548
|
-
function buildCheckHuman(report, reportPath, judgmentsPath) {
|
|
3549
|
-
const summary = summaryLine(report);
|
|
3550
|
-
if (report.failed === 0 && report.pendingJudgments === 0) {
|
|
3551
|
-
return `${summary}
|
|
3552
|
-
report: ${relPath(reportPath)}`;
|
|
3553
|
-
}
|
|
3554
|
-
const reviewHint = report.failed > 0 || report.pendingJudgments > 0 ? "run `blazediff-agent review` to review interactively" : void 0;
|
|
3555
|
-
return [
|
|
3556
|
-
summary,
|
|
3557
|
-
...failureBlock(report.results),
|
|
3558
|
-
`report: ${relPath(reportPath)}`,
|
|
3559
|
-
report.pendingJudgments > 0 ? `pending: ${relPath(judgmentsPath)}/ - host writes <id>/verdict.json, then re-run check --apply-judgments` : void 0,
|
|
3560
|
-
reviewHint
|
|
3561
|
-
].filter(Boolean).join("\n");
|
|
3562
|
-
}
|
|
3563
3851
|
function exitCodeFor(report) {
|
|
3564
3852
|
return report.failed > 0 ? 1 : void 0;
|
|
3565
3853
|
}
|
|
3566
3854
|
async function ensureDevServer(config, out) {
|
|
3567
|
-
const
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3855
|
+
const devServer = config?.devServer;
|
|
3856
|
+
const port = devServer?.port;
|
|
3857
|
+
if (!devServer || !port) return null;
|
|
3858
|
+
const logPath = paths().serverLog;
|
|
3859
|
+
const progress = createDevServerProgress(out, {
|
|
3860
|
+
command: devServer.command,
|
|
3571
3861
|
port,
|
|
3572
|
-
|
|
3862
|
+
logPath
|
|
3573
3863
|
});
|
|
3574
|
-
|
|
3864
|
+
progress.checking();
|
|
3865
|
+
if (await isPortOpen(port)) {
|
|
3866
|
+
progress.ready(true);
|
|
3867
|
+
return null;
|
|
3868
|
+
}
|
|
3869
|
+
progress.starting();
|
|
3870
|
+
try {
|
|
3871
|
+
const handle = await startServer({
|
|
3872
|
+
command: devServer.command,
|
|
3873
|
+
port,
|
|
3874
|
+
logPath,
|
|
3875
|
+
readyTimeoutMs: devServer.readyTimeoutMs ?? DEFAULT_READY_TIMEOUT_MS
|
|
3876
|
+
});
|
|
3877
|
+
progress.ready(Boolean(handle.attached));
|
|
3878
|
+
return handle.attached ? null : handle;
|
|
3879
|
+
} catch (error) {
|
|
3880
|
+
progress.failed();
|
|
3881
|
+
throw error;
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
async function stopCheckServer(server, out) {
|
|
3885
|
+
const human = !out.isQuiet() && !out.isJson();
|
|
3886
|
+
if (human) {
|
|
3575
3887
|
process.stderr.write(
|
|
3576
|
-
|
|
3888
|
+
`[blazediff] stopping dev server http://127.0.0.1:${server.port}
|
|
3577
3889
|
`
|
|
3578
3890
|
);
|
|
3579
3891
|
}
|
|
3892
|
+
const result = await stopServer(process.cwd(), server.port);
|
|
3893
|
+
if (!human) return;
|
|
3894
|
+
const status = result.killed ? "stopped" : "already stopped";
|
|
3895
|
+
process.stderr.write(`\u2713 dev server ${status} on :${server.port}
|
|
3896
|
+
`);
|
|
3580
3897
|
}
|
|
3581
3898
|
function registerCheck(program, out) {
|
|
3582
3899
|
program.command("check").description("run the visual regression check (CI verb)").option("--base-url <url>", "override base URL").option(
|
|
@@ -3609,28 +3926,32 @@ function registerCheck(program, out) {
|
|
|
3609
3926
|
},
|
|
3610
3927
|
buildApplyHuman(result, reportPath)
|
|
3611
3928
|
);
|
|
3612
|
-
const
|
|
3613
|
-
if (
|
|
3929
|
+
const code = exitCodeFor(result.report);
|
|
3930
|
+
if (code !== void 0) process.exitCode = code;
|
|
3614
3931
|
return;
|
|
3615
3932
|
}
|
|
3616
3933
|
const config = await loadConfig();
|
|
3617
3934
|
const baseUrl = resolveBaseUrl(config, opts.baseUrl);
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3935
|
+
const server = opts.baseUrl ? null : await ensureDevServer(config, out);
|
|
3936
|
+
try {
|
|
3937
|
+
const report = await runGraph({
|
|
3938
|
+
baseUrl,
|
|
3939
|
+
threshold: parseThreshold(opts.threshold),
|
|
3940
|
+
concurrency: opts.concurrency ? parsePositiveInteger(opts.concurrency, "--concurrency") : void 0,
|
|
3941
|
+
emitDiffPng: opts.diffPng,
|
|
3942
|
+
junitPath: opts.junit,
|
|
3943
|
+
judge: parseJudge(opts.judge ?? config?.judge ?? "none"),
|
|
3944
|
+
onEvent: makeProgressReporter(out)
|
|
3945
|
+
});
|
|
3946
|
+
out.emit(
|
|
3947
|
+
slimReport(report, reportPath),
|
|
3948
|
+
checkSummary(report, reportPath, paths().judgments)
|
|
3949
|
+
);
|
|
3950
|
+
const code = exitCodeFor(report);
|
|
3951
|
+
if (code !== void 0) process.exitCode = code;
|
|
3952
|
+
} finally {
|
|
3953
|
+
if (server) await stopCheckServer(server, out);
|
|
3954
|
+
}
|
|
3634
3955
|
});
|
|
3635
3956
|
}
|
|
3636
3957
|
|
|
@@ -5145,6 +5466,23 @@ function imageFile(cwd, kind, id) {
|
|
|
5145
5466
|
if (!resolved.startsWith(path26__default.default.resolve(p.root) + path26__default.default.sep)) return null;
|
|
5146
5467
|
return resolved;
|
|
5147
5468
|
}
|
|
5469
|
+
async function readImageSize(file) {
|
|
5470
|
+
if (!file || !fs.existsSync(file)) return void 0;
|
|
5471
|
+
try {
|
|
5472
|
+
const { width, height } = await sharp__default.default(file).metadata();
|
|
5473
|
+
return width && height ? { width, height } : void 0;
|
|
5474
|
+
} catch {
|
|
5475
|
+
return void 0;
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
async function attachImageSizes(cwd, entry) {
|
|
5479
|
+
if (entry.summary !== "image dimensions changed") return entry;
|
|
5480
|
+
const [baselineSize, candidateSize] = await Promise.all([
|
|
5481
|
+
readImageSize(imageFile(cwd, "baseline", entry.id)),
|
|
5482
|
+
readImageSize(imageFile(cwd, "actual", entry.id))
|
|
5483
|
+
]);
|
|
5484
|
+
return { ...entry, baselineSize, candidateSize };
|
|
5485
|
+
}
|
|
5148
5486
|
async function handleApi(req, res, cwd, url) {
|
|
5149
5487
|
const { pathname } = url;
|
|
5150
5488
|
const method = req.method ?? "GET";
|
|
@@ -5157,7 +5495,11 @@ async function handleApi(req, res, cwd, url) {
|
|
|
5157
5495
|
return true;
|
|
5158
5496
|
}
|
|
5159
5497
|
const { _config, ...meta } = await buildRunMeta(cwd);
|
|
5160
|
-
|
|
5498
|
+
const payload = toReviewPayload(report, meta);
|
|
5499
|
+
const entries = await Promise.all(
|
|
5500
|
+
payload.entries.map((entry) => attachImageSizes(cwd, entry))
|
|
5501
|
+
);
|
|
5502
|
+
sendJson(res, 200, { ...payload, entries });
|
|
5161
5503
|
return true;
|
|
5162
5504
|
}
|
|
5163
5505
|
const image = pathname.match(/^\/api\/image\/([^/]+)\/([^/]+)$/);
|