@blazediff/agent 0.8.2 → 0.9.1
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/index.mjs
CHANGED
|
@@ -350,7 +350,7 @@ async function stabilize(page, waitFor, masks) {
|
|
|
350
350
|
() => new Promise((r) => requestAnimationFrame(() => r()))
|
|
351
351
|
);
|
|
352
352
|
}
|
|
353
|
-
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses) {
|
|
353
|
+
async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses, signal) {
|
|
354
354
|
const viewport = opts.viewport ?? DEFAULT_VIEWPORT;
|
|
355
355
|
const waitFor = opts.waitFor ?? DEFAULT_WAIT_FOR;
|
|
356
356
|
const masks = opts.mask ?? [];
|
|
@@ -368,7 +368,17 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
368
368
|
const context = handle.context;
|
|
369
369
|
const browser = await getBrowser();
|
|
370
370
|
const page = await openStablePage(handle);
|
|
371
|
+
const abortCapture = () => {
|
|
372
|
+
handle.disposable = true;
|
|
373
|
+
void context.close().catch(() => {
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
signal?.addEventListener("abort", abortCapture, { once: true });
|
|
371
377
|
try {
|
|
378
|
+
if (signal?.aborted) {
|
|
379
|
+
abortCapture();
|
|
380
|
+
throw signal.reason instanceof Error ? signal.reason : new Error("capture aborted");
|
|
381
|
+
}
|
|
372
382
|
const rejectScreenshot = async () => {
|
|
373
383
|
throw new HarnessError("setup harness must not call screenshot()");
|
|
374
384
|
};
|
|
@@ -415,6 +425,7 @@ async function captureScreenshot(baseUrl, opts, cwd = process.cwd(), harnesses)
|
|
|
415
425
|
subCaptures: subCaptures.length > 0 ? subCaptures : void 0
|
|
416
426
|
};
|
|
417
427
|
} finally {
|
|
428
|
+
signal?.removeEventListener("abort", abortCapture);
|
|
418
429
|
await page.close().catch(() => {
|
|
419
430
|
});
|
|
420
431
|
await releaseStableContext(handle);
|
|
@@ -491,21 +502,44 @@ function resolveBaseUrl(config, override) {
|
|
|
491
502
|
}
|
|
492
503
|
|
|
493
504
|
// src/graph/semaphore.ts
|
|
505
|
+
function abortReason(signal) {
|
|
506
|
+
return signal.reason instanceof Error ? signal.reason : new Error("operation aborted");
|
|
507
|
+
}
|
|
494
508
|
function createSemaphore(limit) {
|
|
495
509
|
if (limit < 1) throw new Error(`semaphore limit must be >= 1 (got ${limit})`);
|
|
496
510
|
let current = 0;
|
|
497
511
|
const queue = [];
|
|
498
|
-
async function run(fn) {
|
|
512
|
+
async function run(fn, signal) {
|
|
513
|
+
if (signal?.aborted) throw abortReason(signal);
|
|
499
514
|
if (current >= limit) {
|
|
500
|
-
await new Promise((resolve) =>
|
|
515
|
+
await new Promise((resolve, reject) => {
|
|
516
|
+
const onAbort = () => {
|
|
517
|
+
const index = queue.indexOf(waiter);
|
|
518
|
+
if (index >= 0) queue.splice(index, 1);
|
|
519
|
+
reject(abortReason(signal));
|
|
520
|
+
};
|
|
521
|
+
const waiter = {
|
|
522
|
+
start: () => {
|
|
523
|
+
signal?.removeEventListener("abort", onAbort);
|
|
524
|
+
if (signal?.aborted) {
|
|
525
|
+
reject(abortReason(signal));
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
current++;
|
|
529
|
+
resolve();
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
533
|
+
queue.push(waiter);
|
|
534
|
+
});
|
|
535
|
+
} else {
|
|
536
|
+
current++;
|
|
501
537
|
}
|
|
502
|
-
current++;
|
|
503
538
|
try {
|
|
504
539
|
return await fn();
|
|
505
540
|
} finally {
|
|
506
541
|
current--;
|
|
507
|
-
|
|
508
|
-
if (next) next();
|
|
542
|
+
queue.shift()?.start();
|
|
509
543
|
}
|
|
510
544
|
}
|
|
511
545
|
return { run };
|
|
@@ -1281,66 +1315,196 @@ var dim = pc.dim;
|
|
|
1281
1315
|
var bold = pc.bold;
|
|
1282
1316
|
|
|
1283
1317
|
// src/judge/transformers.ts
|
|
1318
|
+
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1319
|
+
var INTERACTIVE_REFRESH_MS = 80;
|
|
1320
|
+
var NON_INTERACTIVE_HEARTBEAT_MS = 1e4;
|
|
1321
|
+
var interactiveLoads = /* @__PURE__ */ new Map();
|
|
1322
|
+
var interactiveLinesDrawn = 0;
|
|
1323
|
+
var interactiveFrame = 0;
|
|
1324
|
+
var interactiveTimer;
|
|
1284
1325
|
var toMb = (bytes) => (bytes / 1048576).toFixed(1);
|
|
1285
|
-
|
|
1326
|
+
var elapsed = (startedAt) => `${((Date.now() - startedAt) / 1e3).toFixed(1)}s`;
|
|
1327
|
+
function clearInteractiveRows() {
|
|
1328
|
+
if (interactiveLinesDrawn === 0) return;
|
|
1329
|
+
process.stderr.write(`\x1B[${interactiveLinesDrawn}F\x1B[J`);
|
|
1330
|
+
interactiveLinesDrawn = 0;
|
|
1331
|
+
}
|
|
1332
|
+
function interactiveLine(load) {
|
|
1333
|
+
const duration = dim(`\xB7 ${elapsed(load.startedAt)}`);
|
|
1334
|
+
const size = load.total > 0 ? dim(`(${toMb(load.total)} MB)`) : "";
|
|
1335
|
+
if (load.status === "ready") {
|
|
1336
|
+
return ` ${pc.green("\u2713")} ${bold(load.label)} model ready ${size} ${duration}`.trimEnd();
|
|
1337
|
+
}
|
|
1338
|
+
if (load.status === "failed") {
|
|
1339
|
+
return ` ${pc.red("\u2717")} ${bold(load.label)} model failed ${duration}`;
|
|
1340
|
+
}
|
|
1341
|
+
const pct = load.total > 0 ? Math.min(100, Math.floor(load.loaded / load.total * 100)) : 0;
|
|
1342
|
+
const transferred = load.total > 0 ? `${pct}% ${dim(`(${toMb(load.loaded)}/${toMb(load.total)} MB)`)}` : `0% ${dim("(0.0 MB)")}`;
|
|
1343
|
+
const phase = load.total > 0 && load.loaded >= load.total ? dim("initializing runtime") : "loading";
|
|
1344
|
+
return ` ${pc.cyan(SPINNER_FRAMES[interactiveFrame])} ${bold(load.label)} model ${phase} ${transferred} ${duration}`;
|
|
1345
|
+
}
|
|
1346
|
+
function stopInteractiveTimer() {
|
|
1347
|
+
if (!interactiveTimer) return;
|
|
1348
|
+
clearInterval(interactiveTimer);
|
|
1349
|
+
interactiveTimer = void 0;
|
|
1350
|
+
}
|
|
1351
|
+
function redrawInteractiveRows() {
|
|
1352
|
+
clearInteractiveRows();
|
|
1353
|
+
let complete = interactiveLoads.size > 0;
|
|
1354
|
+
for (const load of interactiveLoads.values()) {
|
|
1355
|
+
process.stderr.write(`${interactiveLine(load)}
|
|
1356
|
+
`);
|
|
1357
|
+
if (load.status === "loading") complete = false;
|
|
1358
|
+
}
|
|
1359
|
+
if (complete) {
|
|
1360
|
+
interactiveLinesDrawn = 0;
|
|
1361
|
+
interactiveLoads.clear();
|
|
1362
|
+
stopInteractiveTimer();
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
interactiveLinesDrawn = interactiveLoads.size;
|
|
1366
|
+
}
|
|
1367
|
+
function startInteractiveTimer() {
|
|
1368
|
+
if (interactiveTimer) return;
|
|
1369
|
+
interactiveTimer = setInterval(() => {
|
|
1370
|
+
interactiveFrame = (interactiveFrame + 1) % SPINNER_FRAMES.length;
|
|
1371
|
+
redrawInteractiveRows();
|
|
1372
|
+
}, INTERACTIVE_REFRESH_MS);
|
|
1373
|
+
interactiveTimer.unref();
|
|
1374
|
+
}
|
|
1375
|
+
function setInteractiveLoad(id, load, status) {
|
|
1376
|
+
load.status = status;
|
|
1377
|
+
interactiveLoads.set(id, load);
|
|
1378
|
+
redrawInteractiveRows();
|
|
1379
|
+
}
|
|
1380
|
+
function createLoadProgress(label, opts) {
|
|
1286
1381
|
const interactive = Boolean(process.stderr.isTTY);
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1382
|
+
const id = Symbol(label);
|
|
1383
|
+
const files = /* @__PURE__ */ new Map();
|
|
1384
|
+
const load = {
|
|
1385
|
+
label,
|
|
1386
|
+
startedAt: Date.now(),
|
|
1387
|
+
loaded: 0,
|
|
1388
|
+
total: 0,
|
|
1389
|
+
status: "loading"
|
|
1390
|
+
};
|
|
1391
|
+
let started = false;
|
|
1392
|
+
let finished = false;
|
|
1289
1393
|
let lastPct = -1;
|
|
1290
1394
|
let lastBucket = -1;
|
|
1395
|
+
let heartbeat;
|
|
1291
1396
|
const totals = () => {
|
|
1292
1397
|
let loaded = 0;
|
|
1293
1398
|
let total = 0;
|
|
1294
|
-
for (const
|
|
1295
|
-
loaded +=
|
|
1296
|
-
total +=
|
|
1399
|
+
for (const file of files.values()) {
|
|
1400
|
+
loaded += file.loaded;
|
|
1401
|
+
total += file.total;
|
|
1297
1402
|
}
|
|
1298
1403
|
const pct = total > 0 ? Math.min(100, Math.floor(loaded / total * 100)) : 0;
|
|
1299
1404
|
return { loaded, total, pct };
|
|
1300
1405
|
};
|
|
1406
|
+
const stopHeartbeat = () => {
|
|
1407
|
+
if (!heartbeat) return;
|
|
1408
|
+
clearInterval(heartbeat);
|
|
1409
|
+
heartbeat = void 0;
|
|
1410
|
+
};
|
|
1411
|
+
const start = () => {
|
|
1412
|
+
if (started) return;
|
|
1413
|
+
started = true;
|
|
1414
|
+
load.startedAt = Date.now();
|
|
1415
|
+
if (interactive) {
|
|
1416
|
+
interactiveLoads.set(id, load);
|
|
1417
|
+
startInteractiveTimer();
|
|
1418
|
+
redrawInteractiveRows();
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
process.stderr.write(
|
|
1422
|
+
`${dim("[blazediff]")} loading ${bold(label)} model ${dim("(first run may download weights)\u2026")}
|
|
1423
|
+
`
|
|
1424
|
+
);
|
|
1425
|
+
process.stderr.write(` ${label}: 0% ${dim("(0.0 MB)")}
|
|
1426
|
+
`);
|
|
1427
|
+
lastBucket = 0;
|
|
1428
|
+
heartbeat = setInterval(() => {
|
|
1429
|
+
const { loaded, total, pct } = totals();
|
|
1430
|
+
const phase = total > 0 && loaded >= total ? "initializing runtime" : "still loading";
|
|
1431
|
+
const transfer = total > 0 ? `${pct}% (${toMb(loaded)}/${toMb(total)} MB)` : "0% (0.0 MB)";
|
|
1432
|
+
process.stderr.write(
|
|
1433
|
+
` ${label}: ${phase} ${transfer} ${dim(`\xB7 ${elapsed(load.startedAt)}`)}
|
|
1434
|
+
`
|
|
1435
|
+
);
|
|
1436
|
+
}, NON_INTERACTIVE_HEARTBEAT_MS);
|
|
1437
|
+
heartbeat.unref();
|
|
1438
|
+
};
|
|
1439
|
+
const finish = (status) => {
|
|
1440
|
+
if (finished) return;
|
|
1441
|
+
start();
|
|
1442
|
+
finished = true;
|
|
1443
|
+
stopHeartbeat();
|
|
1444
|
+
if (interactive) {
|
|
1445
|
+
setInteractiveLoad(id, load, status);
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const { total } = totals();
|
|
1449
|
+
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1450
|
+
const state = status === "ready" ? pc.green("ready") : pc.red("failed");
|
|
1451
|
+
process.stderr.write(
|
|
1452
|
+
` ${label}: ${state}${size} ${dim(`\xB7 ${elapsed(load.startedAt)}`)}
|
|
1453
|
+
`
|
|
1454
|
+
);
|
|
1455
|
+
};
|
|
1301
1456
|
return {
|
|
1457
|
+
start,
|
|
1302
1458
|
onProgress(event) {
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
);
|
|
1308
|
-
|
|
1459
|
+
start();
|
|
1460
|
+
if (!event.file) return;
|
|
1461
|
+
if (event.status === "done") {
|
|
1462
|
+
const file = files.get(event.file);
|
|
1463
|
+
if (!file) return;
|
|
1464
|
+
files.set(event.file, { loaded: file.total, total: file.total });
|
|
1465
|
+
} else {
|
|
1466
|
+
if (event.status !== "progress" || typeof event.total !== "number")
|
|
1467
|
+
return;
|
|
1468
|
+
files.set(event.file, {
|
|
1469
|
+
loaded: event.loaded ?? 0,
|
|
1470
|
+
total: event.total
|
|
1471
|
+
});
|
|
1309
1472
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
lastPct = pct;
|
|
1316
|
-
const line = ` ${label}: ${pct}% ${dim(`(${toMb(loaded)}/${toMb(total)} MB)`)}`;
|
|
1473
|
+
const current = totals();
|
|
1474
|
+
load.loaded = current.loaded;
|
|
1475
|
+
load.total = current.total;
|
|
1476
|
+
if (current.pct === lastPct) return;
|
|
1477
|
+
lastPct = current.pct;
|
|
1317
1478
|
if (interactive) {
|
|
1318
|
-
|
|
1479
|
+
redrawInteractiveRows();
|
|
1319
1480
|
return;
|
|
1320
1481
|
}
|
|
1321
|
-
const bucket = Math.floor(pct / 25);
|
|
1482
|
+
const bucket = Math.floor(current.pct / 25);
|
|
1322
1483
|
if (bucket > lastBucket) {
|
|
1323
1484
|
lastBucket = bucket;
|
|
1324
|
-
process.stderr.write(`${line}
|
|
1325
|
-
`);
|
|
1326
|
-
}
|
|
1327
|
-
},
|
|
1328
|
-
done() {
|
|
1329
|
-
if (!announced) return;
|
|
1330
|
-
if (interactive) {
|
|
1331
|
-
const { total } = totals();
|
|
1332
|
-
const size = total > 0 ? dim(` (${toMb(total)} MB)`) : "";
|
|
1333
1485
|
process.stderr.write(
|
|
1334
|
-
|
|
1486
|
+
` ${label}: ${current.pct}% ${dim(`(${toMb(current.loaded)}/${toMb(current.total)} MB)`)}
|
|
1335
1487
|
`
|
|
1336
1488
|
);
|
|
1337
|
-
} else if (lastPct < 100) {
|
|
1338
|
-
process.stderr.write(` ${label}: ${pc.green("ready")}
|
|
1339
|
-
`);
|
|
1340
1489
|
}
|
|
1341
|
-
}
|
|
1490
|
+
},
|
|
1491
|
+
done: () => finish("ready"),
|
|
1492
|
+
fail: () => finish("failed")
|
|
1342
1493
|
};
|
|
1343
1494
|
}
|
|
1495
|
+
async function loadTransformersModel(label, load) {
|
|
1496
|
+
const progress = createLoadProgress(label);
|
|
1497
|
+
progress.start();
|
|
1498
|
+
try {
|
|
1499
|
+
const mod = await loadTransformers();
|
|
1500
|
+
const result = await load(mod, progress.onProgress);
|
|
1501
|
+
progress.done();
|
|
1502
|
+
return result;
|
|
1503
|
+
} catch (error) {
|
|
1504
|
+
progress.fail();
|
|
1505
|
+
throw error;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1344
1508
|
async function loadTransformers() {
|
|
1345
1509
|
try {
|
|
1346
1510
|
return await import('@huggingface/transformers');
|
|
@@ -1356,22 +1520,24 @@ async function loadTransformers() {
|
|
|
1356
1520
|
var MODEL_ID = "onnx-community/Qwen3.5-0.8B-ONNX";
|
|
1357
1521
|
var MAX_NEW_TOKENS = 64;
|
|
1358
1522
|
async function defaultFactory() {
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1523
|
+
const { tokenizer, model } = await loadTransformersModel(
|
|
1524
|
+
"classifier",
|
|
1525
|
+
async (mod, progress_callback) => {
|
|
1526
|
+
const [tokenizer2, model2] = await Promise.all([
|
|
1527
|
+
mod.AutoTokenizer.from_pretrained(MODEL_ID, { progress_callback }),
|
|
1528
|
+
mod.Qwen3_5ForConditionalGeneration.from_pretrained(MODEL_ID, {
|
|
1529
|
+
dtype: {
|
|
1530
|
+
embed_tokens: "fp32",
|
|
1531
|
+
vision_encoder: "q8",
|
|
1532
|
+
decoder_model_merged: "q4"
|
|
1533
|
+
},
|
|
1534
|
+
device: "cpu",
|
|
1535
|
+
progress_callback
|
|
1536
|
+
})
|
|
1537
|
+
]);
|
|
1538
|
+
return { tokenizer: tokenizer2, model: model2 };
|
|
1539
|
+
}
|
|
1540
|
+
);
|
|
1375
1541
|
return {
|
|
1376
1542
|
async complete(prompt) {
|
|
1377
1543
|
const inputs = tokenizer.apply_chat_template(
|
|
@@ -1609,23 +1775,25 @@ var PATCH_SIZE = 14;
|
|
|
1609
1775
|
var MAX_NEW_TOKENS2 = 64;
|
|
1610
1776
|
var ANSWER_MARKER = "Answer:";
|
|
1611
1777
|
async function defaultFactory2() {
|
|
1612
|
-
const mod = await
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1778
|
+
const { mod, tokenizer, processor, model } = await loadTransformersModel(
|
|
1779
|
+
"vision",
|
|
1780
|
+
async (mod2, progress_callback) => {
|
|
1781
|
+
const [tokenizer2, processor2, model2] = await Promise.all([
|
|
1782
|
+
mod2.AutoTokenizer.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1783
|
+
mod2.AutoProcessor.from_pretrained(MODEL_ID2, { progress_callback }),
|
|
1784
|
+
mod2.Moondream1ForConditionalGeneration.from_pretrained(MODEL_ID2, {
|
|
1785
|
+
dtype: {
|
|
1786
|
+
embed_tokens: "fp32",
|
|
1787
|
+
vision_encoder: "q8",
|
|
1788
|
+
decoder_model_merged: "q4"
|
|
1789
|
+
},
|
|
1790
|
+
device: "cpu",
|
|
1791
|
+
progress_callback
|
|
1792
|
+
})
|
|
1793
|
+
]);
|
|
1794
|
+
return { mod: mod2, tokenizer: tokenizer2, processor: processor2, model: model2 };
|
|
1795
|
+
}
|
|
1796
|
+
);
|
|
1629
1797
|
return {
|
|
1630
1798
|
async describe(imagePath, question) {
|
|
1631
1799
|
const image = await mod.RawImage.read(imagePath);
|
|
@@ -2599,7 +2767,7 @@ function failResult(entry, outcome, actualPath, baselinePath, verdict) {
|
|
|
2599
2767
|
function asCaptured(entry, output) {
|
|
2600
2768
|
return { entry, output };
|
|
2601
2769
|
}
|
|
2602
|
-
function makeCaptureNode(semaphore) {
|
|
2770
|
+
function makeCaptureNode(semaphore, abortController) {
|
|
2603
2771
|
return async function captureNode(state) {
|
|
2604
2772
|
const entry = state.entry;
|
|
2605
2773
|
const options = state.options;
|
|
@@ -2642,22 +2810,33 @@ function makeCaptureNode(semaphore) {
|
|
|
2642
2810
|
}
|
|
2643
2811
|
const baselinePath = path.join(options.baselinesDir, `${entry.id}.png`);
|
|
2644
2812
|
try {
|
|
2645
|
-
const capture = await semaphore.run(
|
|
2646
|
-
(
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2813
|
+
const capture = await semaphore.run(async () => {
|
|
2814
|
+
emitEvent({
|
|
2815
|
+
type: "capturing",
|
|
2816
|
+
entryId: entry.id,
|
|
2817
|
+
url: entry.url
|
|
2818
|
+
});
|
|
2819
|
+
try {
|
|
2820
|
+
return await captureScreenshot(
|
|
2821
|
+
options.baseUrl,
|
|
2822
|
+
{
|
|
2823
|
+
id: entry.id,
|
|
2824
|
+
url: entry.url,
|
|
2825
|
+
viewport: entry.viewport,
|
|
2826
|
+
mask: entry.mask,
|
|
2827
|
+
waitFor: entry.waitFor,
|
|
2828
|
+
fullPage: entry.fullPage ?? DEFAULT_FULL_PAGE,
|
|
2829
|
+
mode: "actual"
|
|
2830
|
+
},
|
|
2831
|
+
options.cwd,
|
|
2832
|
+
harnesses,
|
|
2833
|
+
abortController.signal
|
|
2834
|
+
);
|
|
2835
|
+
} catch (err) {
|
|
2836
|
+
if (!(err instanceof HarnessError)) abortController.abort(err);
|
|
2837
|
+
throw err;
|
|
2838
|
+
}
|
|
2839
|
+
}, abortController.signal);
|
|
2661
2840
|
const items = [
|
|
2662
2841
|
asCaptured(entry, {
|
|
2663
2842
|
id: entry.id,
|
|
@@ -2726,15 +2905,16 @@ function makeDiffNode(semaphore) {
|
|
|
2726
2905
|
if (!capture.captureOutputPath || !capture.baselinePath) {
|
|
2727
2906
|
throw new Error("diffNode: capture output paths missing");
|
|
2728
2907
|
}
|
|
2729
|
-
const outcome = await semaphore.run(
|
|
2730
|
-
(
|
|
2908
|
+
const outcome = await semaphore.run(() => {
|
|
2909
|
+
emitEvent({ type: "diffing", entryId: entry.id, url: entry.url });
|
|
2910
|
+
return diffEntry(
|
|
2731
2911
|
entry.id,
|
|
2732
2912
|
capture.baselinePath,
|
|
2733
2913
|
capture.captureOutputPath,
|
|
2734
2914
|
{ threshold: options.threshold, emitDiffPng: options.emitDiffPng },
|
|
2735
2915
|
options.cwd
|
|
2736
|
-
)
|
|
2737
|
-
);
|
|
2916
|
+
);
|
|
2917
|
+
});
|
|
2738
2918
|
if (outcome.reason === "file-not-exists") {
|
|
2739
2919
|
return {
|
|
2740
2920
|
diffOutput: {
|
|
@@ -3061,18 +3241,23 @@ var GraphState = Annotation.Root({
|
|
|
3061
3241
|
function threadIdFor(cwd) {
|
|
3062
3242
|
return createHash("sha1").update(paths(cwd).manifest).digest("hex").slice(0, 16);
|
|
3063
3243
|
}
|
|
3064
|
-
function buildCaptureGraph(captureSemaphore) {
|
|
3065
|
-
return new StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore)).addEdge(START, "capture").addEdge("capture", END).compile();
|
|
3244
|
+
function buildCaptureGraph(captureSemaphore, abortController) {
|
|
3245
|
+
return new StateGraph(CaptureState).addNode("capture", makeCaptureNode(captureSemaphore, abortController)).addEdge(START, "capture").addEdge("capture", END).compile();
|
|
3066
3246
|
}
|
|
3067
3247
|
function buildBranchGraph(diffSemaphore) {
|
|
3068
3248
|
return new StateGraph(BranchState).addNode("diff", makeDiffNode(diffSemaphore)).addNode("judge", judgeNode).addEdge(START, "diff").addEdge("diff", "judge").addEdge("judge", END).compile();
|
|
3069
3249
|
}
|
|
3070
3250
|
async function dispatchNode(state) {
|
|
3251
|
+
const total = state.captured.length;
|
|
3252
|
+
const captured = state.captured.filter(
|
|
3253
|
+
(item) => item.output.captureOutputPath
|
|
3254
|
+
).length;
|
|
3255
|
+
emitEvent({ type: "capture-complete", captured, total });
|
|
3071
3256
|
if (state.options) await resolveJudge(state.options.judge).warmup?.();
|
|
3072
3257
|
return {};
|
|
3073
3258
|
}
|
|
3074
|
-
function buildGraph(captureSemaphore, diffSemaphore, checkpointer) {
|
|
3075
|
-
const captureBranch = buildCaptureGraph(captureSemaphore);
|
|
3259
|
+
function buildGraph(captureSemaphore, diffSemaphore, checkpointer, abortController) {
|
|
3260
|
+
const captureBranch = buildCaptureGraph(captureSemaphore, abortController);
|
|
3076
3261
|
const branch = buildBranchGraph(diffSemaphore);
|
|
3077
3262
|
return new StateGraph(GraphState).addNode("load", loadNode).addNode("capture", captureBranch).addNode("dispatch", dispatchNode).addNode("branch", branch).addEdge(START, "load").addConditionalEdges(
|
|
3078
3263
|
"load",
|
|
@@ -3164,9 +3349,15 @@ async function runGraph(opts) {
|
|
|
3164
3349
|
const concurrency = opts.concurrency ?? defaultConcurrency();
|
|
3165
3350
|
const captureSemaphore = createSemaphore(concurrency);
|
|
3166
3351
|
const diffSemaphore = createSemaphore(cpuCores());
|
|
3352
|
+
const abortController = new AbortController();
|
|
3167
3353
|
const baselinesDir = paths(cwd).baselines;
|
|
3168
3354
|
const checkpointer = new FsCheckpointSaver(paths(cwd).checkpoints);
|
|
3169
|
-
const graph = buildGraph(
|
|
3355
|
+
const graph = buildGraph(
|
|
3356
|
+
captureSemaphore,
|
|
3357
|
+
diffSemaphore,
|
|
3358
|
+
checkpointer,
|
|
3359
|
+
abortController
|
|
3360
|
+
);
|
|
3170
3361
|
const threadId = opts.threadId ?? threadIdFor(cwd);
|
|
3171
3362
|
if (!opts.resume) {
|
|
3172
3363
|
await checkpointer.deleteThread(threadId);
|
|
@@ -3187,6 +3378,7 @@ async function runGraph(opts) {
|
|
|
3187
3378
|
try {
|
|
3188
3379
|
collect = await streamGraph(graph, input, threadId, opts.onEvent);
|
|
3189
3380
|
} finally {
|
|
3381
|
+
abortController.abort();
|
|
3190
3382
|
setEventSink(void 0);
|
|
3191
3383
|
await closeBrowser();
|
|
3192
3384
|
}
|