@hamsterbase/evidra 0.2.0 → 0.3.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/sdk/conformance-rules.js +1454 -0
- package/dist/sdk/conformance.js +5 -0
- package/dist/sdk/index.d.ts +10 -0
- package/dist/sdk/main.js +66 -37
- package/dist/sdk/rules.d.ts +149 -0
- package/dist/sdk/types-B6cBsknY.d.ts +12 -0
- package/dist/service/cli.js +698 -332
- package/dist/web/assets/{cssMode-C0YhK9yk.js → cssMode-BTAZgpQt.js} +1 -1
- package/dist/web/assets/{editor.api-CMNmRHg7.js → editor.api-CfnVkTAL.js} +1 -1
- package/dist/web/assets/{freemarker2-BPF-_qAr.js → freemarker2-BV0isRRj.js} +1 -1
- package/dist/web/assets/{handlebars-ZZYTfRBR.js → handlebars-CbLz4Wc3.js} +1 -1
- package/dist/web/assets/{html-Dgtv0wV7.js → html-D2xBZbJh.js} +1 -1
- package/dist/web/assets/{htmlMode-CE3TDKC3.js → htmlMode-DwPRG6d4.js} +1 -1
- package/dist/web/assets/index-CJuNTIx5.css +2 -0
- package/dist/web/assets/index-CqRUszBc.js +35 -0
- package/dist/web/assets/{javascript-v3U6PHk8.js → javascript-D-gNVUGD.js} +1 -1
- package/dist/web/assets/{jsonMode-CRbfEt8i.js → jsonMode-BMqe91Um.js} +1 -1
- package/dist/web/assets/{liquid-D_mEV4oV.js → liquid-D6FHObSg.js} +1 -1
- package/dist/web/assets/{lspLanguageFeatures-DX6MhoAE.js → lspLanguageFeatures-D6i7D2oO.js} +1 -1
- package/dist/web/assets/{mdx-BhVFxchM.js → mdx-CGtrE9A8.js} +1 -1
- package/dist/web/assets/{monaco-C2bEmNwl.js → monaco-C3WraHAR.js} +4 -4
- package/dist/web/assets/{python-BWAEzptE.js → python-B2ywaTtF.js} +1 -1
- package/dist/web/assets/{razor-fGgHB_D8.js → razor-zzTWj2fW.js} +1 -1
- package/dist/web/assets/{tsMode-Dhqndf6Y.js → tsMode-BrfjRJaR.js} +1 -1
- package/dist/web/assets/{typescript-BdctO1F-.js → typescript-xVM47PRQ.js} +1 -1
- package/dist/web/assets/{workers-CL1LWpiD.js → workers-DEZ7PLe8.js} +1 -1
- package/dist/web/assets/{xml-h8WCDUbN.js → xml-kpizFTtc.js} +1 -1
- package/dist/web/assets/{yaml-Dh4FUWeU.js → yaml-DDFZ3vPi.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +15 -6
- package/packages/conformance/rules/commit-message/RULE.md +29 -0
- package/packages/conformance/rules/duplicate-localization/RULE.md +37 -0
- package/packages/conformance/rules/e2e-scenarios-structure/RULE.md +39 -0
- package/packages/conformance/rules/index.md +18 -0
- package/packages/conformance/rules/same-dir-import-only/RULE.md +35 -0
- package/packages/conformance/rules/single-component-file/RULE.md +33 -0
- package/packages/conformance/rules/source-locale-defaults/RULE.md +48 -0
- package/packages/conformance/rules/sync-locales/RULE.md +45 -0
- package/packages/conformance/rules/ui-scenarios-structure/RULE.md +43 -0
- package/skills/evidra/SKILL.md +8 -3
- package/dist/web/assets/index-D_0ZWPum.js +0 -37
- package/dist/web/assets/index-U9oKSlEO.css +0 -2
package/dist/service/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/service/src/cli.ts
|
|
2
2
|
import { cac } from "cac";
|
|
3
|
-
import
|
|
3
|
+
import path33 from "node:path";
|
|
4
4
|
|
|
5
5
|
// modules/core/implementations/Functions/resolveConfig.ts
|
|
6
6
|
import path3 from "node:path";
|
|
@@ -29,10 +29,22 @@ var NamespaceSchema = z3.object({
|
|
|
29
29
|
id: z3.string().regex(/^[A-Za-z0-9-]+$/),
|
|
30
30
|
name: z3.string().trim().min(1)
|
|
31
31
|
});
|
|
32
|
+
var ChangeConfigSchema = z3.object({
|
|
33
|
+
scope: z3.union([
|
|
34
|
+
z3.array(z3.string().trim().min(1)),
|
|
35
|
+
z3.string().transform(
|
|
36
|
+
(value) => value.split(",").map((scope) => scope.trim()).filter(Boolean)
|
|
37
|
+
)
|
|
38
|
+
]).default([]).transform((scopes) => [...new Set(scopes)]),
|
|
39
|
+
notedir: z3.string().trim().min(1).default("changelog-notes"),
|
|
40
|
+
/** 更新日志读取的本地分支。 */
|
|
41
|
+
branch: z3.string().trim().min(1).default("main")
|
|
42
|
+
});
|
|
32
43
|
var ConfigSchema = z3.object({
|
|
33
44
|
reportDir: z3.string().min(1).optional(),
|
|
34
45
|
storage: z3.enum(["s3", "local"]).default("local"),
|
|
35
|
-
namespaces: z3.array(NamespaceSchema)
|
|
46
|
+
namespaces: z3.array(NamespaceSchema),
|
|
47
|
+
change: ChangeConfigSchema.optional()
|
|
36
48
|
});
|
|
37
49
|
|
|
38
50
|
// modules/core/implementations/config.ts
|
|
@@ -55,7 +67,8 @@ function parseConfig(config) {
|
|
|
55
67
|
return {
|
|
56
68
|
reportDir: dir,
|
|
57
69
|
storage: value.storage,
|
|
58
|
-
namespaces: value.namespaces.map(({ id, name }) => ({ id, name }))
|
|
70
|
+
namespaces: value.namespaces.map(({ id, name }) => ({ id, name })),
|
|
71
|
+
...value.change ? { change: value.change } : {}
|
|
59
72
|
};
|
|
60
73
|
}
|
|
61
74
|
|
|
@@ -295,7 +308,7 @@ import { readFile as readFile4, readdir } from "node:fs/promises";
|
|
|
295
308
|
import path8 from "node:path";
|
|
296
309
|
|
|
297
310
|
// modules/core/contracts/taskRecord.ts
|
|
298
|
-
var
|
|
311
|
+
var TASK_SCHEMA_VERSION = 3;
|
|
299
312
|
|
|
300
313
|
// modules/core/implementations/Utils/readJson.ts
|
|
301
314
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
@@ -327,7 +340,7 @@ async function writeJsonAtomic(file, value) {
|
|
|
327
340
|
// modules/core/implementations/Utils/readTaskRecord.ts
|
|
328
341
|
async function readTaskRecord(file) {
|
|
329
342
|
const manifest = JSON.parse(await readFile4(file, "utf8"));
|
|
330
|
-
if ((manifest.formatVersion ?? 0) <
|
|
343
|
+
if ((manifest.formatVersion ?? 0) < TASK_SCHEMA_VERSION)
|
|
331
344
|
throw new Error("\u62A5\u544A\u683C\u5F0F\u4E0D\u652F\u6301\uFF0C\u8BF7\u91CD\u65B0\u8FD0\u884C\u6D4B\u8BD5");
|
|
332
345
|
const directory = path8.join(path8.dirname(file), "cases");
|
|
333
346
|
const files = (await readdir(directory)).filter((name) => name.endsWith(".json")).sort();
|
|
@@ -461,8 +474,6 @@ var CompareTaskInputSchema = z8.object({ repoRoot: z8.string(), taskId: z8.strin
|
|
|
461
474
|
// modules/core/implementations/internal/compare.ts
|
|
462
475
|
import { access } from "node:fs/promises";
|
|
463
476
|
import path13 from "node:path";
|
|
464
|
-
import pixelmatch from "pixelmatch";
|
|
465
|
-
import { PNG } from "pngjs";
|
|
466
477
|
|
|
467
478
|
// modules/core/contracts/internal/compare.ts
|
|
468
479
|
import { z as z9 } from "zod";
|
|
@@ -480,6 +491,26 @@ async function download(_cwd, storage, key) {
|
|
|
480
491
|
return Buffer.from(await storage.download(key));
|
|
481
492
|
}
|
|
482
493
|
|
|
494
|
+
// modules/core/implementations/Utils/imageDiff.ts
|
|
495
|
+
import pixelmatch from "pixelmatch";
|
|
496
|
+
import { PNG } from "pngjs";
|
|
497
|
+
function diffPng(png, match, oldBytes, newBytes) {
|
|
498
|
+
if (Buffer.from(oldBytes).equals(Buffer.from(newBytes))) return { diffPixels: 0 };
|
|
499
|
+
const oldImage = png.sync.read(Buffer.from(oldBytes));
|
|
500
|
+
const newImage = png.sync.read(Buffer.from(newBytes));
|
|
501
|
+
if (oldImage.width !== newImage.width || oldImage.height !== newImage.height) {
|
|
502
|
+
return { dimensionMismatch: true };
|
|
503
|
+
}
|
|
504
|
+
const diff = new png({ width: oldImage.width, height: oldImage.height });
|
|
505
|
+
const diffPixels = match(oldImage.data, newImage.data, diff.data, diff.width, diff.height, {
|
|
506
|
+
threshold: 0.1
|
|
507
|
+
});
|
|
508
|
+
return { diffPixels, png: png.sync.write(diff) };
|
|
509
|
+
}
|
|
510
|
+
function localImageDiff(oldBytes, newBytes) {
|
|
511
|
+
return diffPng(PNG, pixelmatch, oldBytes, newBytes);
|
|
512
|
+
}
|
|
513
|
+
|
|
483
514
|
// modules/core/implementations/Utils/imageDiffPool.ts
|
|
484
515
|
import { createRequire } from "node:module";
|
|
485
516
|
import { Worker } from "node:worker_threads";
|
|
@@ -492,24 +523,11 @@ const { PNG } = require(workerData.pngjsPath);
|
|
|
492
523
|
const pixelmatchModule = require(workerData.pixelmatchPath);
|
|
493
524
|
const pixelmatch = pixelmatchModule.default || pixelmatchModule;
|
|
494
525
|
|
|
526
|
+
const diffPng = ${diffPng.toString()};
|
|
527
|
+
|
|
495
528
|
parentPort.on('message', ({ id, oldBytes, newBytes }) => {
|
|
496
529
|
try {
|
|
497
|
-
|
|
498
|
-
const newImage = PNG.sync.read(Buffer.from(newBytes));
|
|
499
|
-
if (oldImage.width !== newImage.width || oldImage.height !== newImage.height) {
|
|
500
|
-
parentPort.postMessage({ id, dimensionMismatch: true });
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const diff = new PNG({ width: oldImage.width, height: oldImage.height });
|
|
504
|
-
const diffPixels = pixelmatch(
|
|
505
|
-
oldImage.data,
|
|
506
|
-
newImage.data,
|
|
507
|
-
diff.data,
|
|
508
|
-
diff.width,
|
|
509
|
-
diff.height,
|
|
510
|
-
{ threshold: 0.1 },
|
|
511
|
-
);
|
|
512
|
-
parentPort.postMessage({ id, diffPixels, png: PNG.sync.write(diff) });
|
|
530
|
+
parentPort.postMessage({ id, ...diffPng(PNG, pixelmatch, oldBytes, newBytes) });
|
|
513
531
|
} catch (error) {
|
|
514
532
|
parentPort.postMessage({ id, error: error instanceof Error ? error.message : String(error) });
|
|
515
533
|
}
|
|
@@ -938,18 +956,6 @@ async function imageDiff(oldBytes, newBytes, pool) {
|
|
|
938
956
|
}
|
|
939
957
|
return localImageDiff(oldBytes, newBytes);
|
|
940
958
|
}
|
|
941
|
-
function localImageDiff(oldBytes, newBytes) {
|
|
942
|
-
const oldImage = PNG.sync.read(Buffer.from(oldBytes));
|
|
943
|
-
const newImage = PNG.sync.read(Buffer.from(newBytes));
|
|
944
|
-
if (oldImage.width !== newImage.width || oldImage.height !== newImage.height) {
|
|
945
|
-
return { dimensionMismatch: true };
|
|
946
|
-
}
|
|
947
|
-
const diff = new PNG({ width: oldImage.width, height: oldImage.height });
|
|
948
|
-
const diffPixels = pixelmatch(oldImage.data, newImage.data, diff.data, diff.width, diff.height, {
|
|
949
|
-
threshold: 0.1
|
|
950
|
-
});
|
|
951
|
-
return { diffPixels, png: PNG.sync.write(diff) };
|
|
952
|
-
}
|
|
953
959
|
|
|
954
960
|
// modules/core/implementations/repository.ts
|
|
955
961
|
import path15 from "node:path";
|
|
@@ -1114,9 +1120,6 @@ async function compareTask(input) {
|
|
|
1114
1120
|
return compare({ taskId }, reportDir, reportDir, storageFor(reportDir, root));
|
|
1115
1121
|
}
|
|
1116
1122
|
|
|
1117
|
-
// modules/core/implementations/Functions/approve.ts
|
|
1118
|
-
import path18 from "node:path";
|
|
1119
|
-
|
|
1120
1123
|
// modules/core/contracts/functions/approve.ts
|
|
1121
1124
|
import { z as z11 } from "zod";
|
|
1122
1125
|
var ApproveInputSchema = z11.object({
|
|
@@ -1169,7 +1172,7 @@ async function readBaseline(root, namespace) {
|
|
|
1169
1172
|
}
|
|
1170
1173
|
|
|
1171
1174
|
// modules/core/implementations/internal/updateBaseline.ts
|
|
1172
|
-
import {
|
|
1175
|
+
import { readdir as readdir2, rm as rm3 } from "node:fs/promises";
|
|
1173
1176
|
import path17 from "node:path";
|
|
1174
1177
|
|
|
1175
1178
|
// modules/core/contracts/internal/updateBaseline.ts
|
|
@@ -1201,7 +1204,7 @@ function canonical2(value) {
|
|
|
1201
1204
|
}
|
|
1202
1205
|
|
|
1203
1206
|
// modules/core/implementations/internal/updateBaseline.ts
|
|
1204
|
-
async function
|
|
1207
|
+
async function updateBaseline(input, cwd, baselineRoot, storage, concurrency = 1) {
|
|
1205
1208
|
const value = UpdateBaselineInputSchema.parse(input);
|
|
1206
1209
|
const directory = taskDirectory(cwd, value.taskPath);
|
|
1207
1210
|
const record = await readTaskRecord(path17.join(directory, "task.json"));
|
|
@@ -1303,10 +1306,14 @@ async function updateBaselineUnlocked(input, cwd, baselineRoot, storage, concurr
|
|
|
1303
1306
|
};
|
|
1304
1307
|
const { approvedAt: _approvedAt, ...content } = entry;
|
|
1305
1308
|
const filename = `baseline-${hash(canonical2(content))}.json`;
|
|
1309
|
+
const superseded = await readdir2(paths.directory).catch((error) => {
|
|
1310
|
+
if (error.code === "ENOENT") return [];
|
|
1311
|
+
throw error;
|
|
1312
|
+
});
|
|
1306
1313
|
await writeJsonAtomic(path17.join(paths.directory, filename), entry);
|
|
1307
|
-
for (const file of
|
|
1314
|
+
for (const file of superseded) {
|
|
1308
1315
|
if (file !== filename && /^baseline(?:-[a-f0-9]{64})?\.json$/.test(file)) {
|
|
1309
|
-
await rm3(path17.join(paths.directory, file));
|
|
1316
|
+
await rm3(path17.join(paths.directory, file), { force: true });
|
|
1310
1317
|
}
|
|
1311
1318
|
}
|
|
1312
1319
|
const caseFile = [...casePath, filename].join("/");
|
|
@@ -1331,41 +1338,8 @@ async function updateBaselineUnlocked(input, cwd, baselineRoot, storage, concurr
|
|
|
1331
1338
|
comparison: nextComparison
|
|
1332
1339
|
};
|
|
1333
1340
|
}
|
|
1334
|
-
var writes = /* @__PURE__ */ new Map();
|
|
1335
|
-
async function updateBaseline(input, cwd, baselineRoot, storage, concurrency = 1) {
|
|
1336
|
-
const key = path17.resolve(baselineRoot);
|
|
1337
|
-
const next = (writes.get(key) ?? Promise.resolve()).then(async () => {
|
|
1338
|
-
const lock = path17.join(baselineRoot, "cache", "baseline-write.lock");
|
|
1339
|
-
await mkdir3(path17.dirname(lock), { recursive: true });
|
|
1340
|
-
const deadline = Date.now() + 3e4;
|
|
1341
|
-
for (; ; ) {
|
|
1342
|
-
try {
|
|
1343
|
-
await mkdir3(lock);
|
|
1344
|
-
break;
|
|
1345
|
-
} catch (error) {
|
|
1346
|
-
if (error.code !== "EEXIST") throw error;
|
|
1347
|
-
if (Date.now() >= deadline) throw new Error("\u57FA\u7EBF\u5199\u5165\u9501\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u4E2D\u65AD\u7684\u5199\u5165");
|
|
1348
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
try {
|
|
1352
|
-
return await updateBaselineUnlocked(input, cwd, baselineRoot, storage, concurrency);
|
|
1353
|
-
} finally {
|
|
1354
|
-
await rm3(lock, { recursive: true, force: true });
|
|
1355
|
-
}
|
|
1356
|
-
});
|
|
1357
|
-
const settled = next.catch(() => {
|
|
1358
|
-
});
|
|
1359
|
-
writes.set(key, settled);
|
|
1360
|
-
try {
|
|
1361
|
-
return await next;
|
|
1362
|
-
} finally {
|
|
1363
|
-
if (writes.get(key) === settled) writes.delete(key);
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
1341
|
|
|
1367
1342
|
// modules/core/implementations/Functions/approve.ts
|
|
1368
|
-
var approvals = /* @__PURE__ */ new Map();
|
|
1369
1343
|
async function approve(input) {
|
|
1370
1344
|
const {
|
|
1371
1345
|
repoRoot: root,
|
|
@@ -1374,33 +1348,24 @@ async function approve(input) {
|
|
|
1374
1348
|
baselineVersion: expectedVersion
|
|
1375
1349
|
} = ApproveInputSchema.parse(input);
|
|
1376
1350
|
const task = await readTask(root, taskId);
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
const
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
if (!diff) throw new Error("\u7528\u4F8B\u4E0D\u53EF\u5BA1\u6279");
|
|
1388
|
-
return { id, baselineHash: diff.baselineHash ?? null };
|
|
1389
|
-
});
|
|
1390
|
-
const result = await updateBaseline(
|
|
1391
|
-
{ taskPath: await taskPathOf(root, taskId), cases, baselineVersion: expectedVersion },
|
|
1392
|
-
reportDir,
|
|
1393
|
-
reportDir,
|
|
1394
|
-
storageFor(reportDir, root)
|
|
1395
|
-
);
|
|
1396
|
-
return { conflict: result.conflict, comparison: result.comparison };
|
|
1351
|
+
if (!task.finishedAt) throw new Error("\u4EFB\u52A1\u5C1A\u672A\u7ED3\u675F");
|
|
1352
|
+
if (!ids.length || new Set(ids).size !== ids.length) throw new Error("\u5BA1\u6279\u7528\u4F8B\u5217\u8868\u4E3A\u7A7A\u6216\u91CD\u590D");
|
|
1353
|
+
const reportDir = await reportRoot(root);
|
|
1354
|
+
if (await readBaselineVersion(reportDir, task.namespace) !== expectedVersion)
|
|
1355
|
+
return { conflict: true, comparison: await compareTask({ repoRoot: root, taskId }) };
|
|
1356
|
+
const comparison = await compareTask({ repoRoot: root, taskId });
|
|
1357
|
+
const cases = ids.map((id) => {
|
|
1358
|
+
const diff = comparison.cases.find((item) => item.id === id);
|
|
1359
|
+
if (!diff) throw new Error("\u7528\u4F8B\u4E0D\u53EF\u5BA1\u6279");
|
|
1360
|
+
return { id, baselineHash: diff.baselineHash ?? null };
|
|
1397
1361
|
});
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1362
|
+
const result = await updateBaseline(
|
|
1363
|
+
{ taskPath: await taskPathOf(root, taskId), cases, baselineVersion: expectedVersion },
|
|
1364
|
+
reportDir,
|
|
1365
|
+
reportDir,
|
|
1366
|
+
storageFor(reportDir, root)
|
|
1402
1367
|
);
|
|
1403
|
-
return
|
|
1368
|
+
return { conflict: result.conflict, comparison: result.comparison };
|
|
1404
1369
|
}
|
|
1405
1370
|
|
|
1406
1371
|
// modules/core/contracts/functions/reviewCodeChanges.ts
|
|
@@ -1413,17 +1378,14 @@ var ReviewCodeChangesInputSchema = z13.object({
|
|
|
1413
1378
|
reviewed: z13.boolean()
|
|
1414
1379
|
});
|
|
1415
1380
|
|
|
1416
|
-
// modules/core/implementations/Functions/reviewCodeChanges.ts
|
|
1417
|
-
import { realpath as realpath3 } from "node:fs/promises";
|
|
1418
|
-
|
|
1419
1381
|
// modules/core/implementations/gitChanges.ts
|
|
1420
1382
|
import { createHash as createHash3 } from "node:crypto";
|
|
1421
1383
|
import { createReadStream } from "node:fs";
|
|
1422
1384
|
import { lstat, readlink, realpath } from "node:fs/promises";
|
|
1423
|
-
import
|
|
1385
|
+
import path18 from "node:path";
|
|
1424
1386
|
|
|
1425
1387
|
// modules/core/implementations/git.ts
|
|
1426
|
-
import { execFile } from "node:child_process";
|
|
1388
|
+
import { execFile, spawn } from "node:child_process";
|
|
1427
1389
|
function runGit(repoRoot, args, timeoutMs = 2e4) {
|
|
1428
1390
|
return new Promise((resolve) => {
|
|
1429
1391
|
execFile(
|
|
@@ -1448,6 +1410,26 @@ async function gitOptional(repoRoot, args) {
|
|
|
1448
1410
|
async function resolveRef(repoRoot, ref) {
|
|
1449
1411
|
return gitOptional(repoRoot, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`]);
|
|
1450
1412
|
}
|
|
1413
|
+
function gitCatFileBatch(repoRoot, oids) {
|
|
1414
|
+
return new Promise((resolve, reject) => {
|
|
1415
|
+
const child = spawn("git", ["-C", repoRoot, "cat-file", "--batch"], {
|
|
1416
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1417
|
+
timeout: 6e4,
|
|
1418
|
+
windowsHide: true
|
|
1419
|
+
});
|
|
1420
|
+
const chunks = [];
|
|
1421
|
+
let stderr = "";
|
|
1422
|
+
child.stdout.on("data", (chunk) => chunks.push(chunk));
|
|
1423
|
+
child.stderr.on("data", (chunk) => stderr += chunk);
|
|
1424
|
+
child.on("error", reject);
|
|
1425
|
+
child.on(
|
|
1426
|
+
"close",
|
|
1427
|
+
(code) => code === 0 ? resolve(Buffer.concat(chunks)) : reject(new Error(stderr.trim() || `git cat-file \u9000\u51FA\u7801 ${code}`))
|
|
1428
|
+
);
|
|
1429
|
+
child.stdin.on("error", reject);
|
|
1430
|
+
child.stdin.end(oids.join("\n") + "\n");
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1451
1433
|
|
|
1452
1434
|
// modules/core/implementations/gitChanges.ts
|
|
1453
1435
|
var MAX_BYTES = 256 * 1024;
|
|
@@ -1493,20 +1475,20 @@ function fileDigest(file) {
|
|
|
1493
1475
|
});
|
|
1494
1476
|
}
|
|
1495
1477
|
async function worktreeSide(repo, file) {
|
|
1496
|
-
const absolute =
|
|
1497
|
-
const parent = await realpath(
|
|
1498
|
-
const relative =
|
|
1499
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
1478
|
+
const absolute = path18.resolve(repo, file);
|
|
1479
|
+
const parent = await realpath(path18.dirname(absolute));
|
|
1480
|
+
const relative = path18.relative(repo, parent);
|
|
1481
|
+
if (relative === ".." || relative.startsWith(`..${path18.sep}`) || path18.isAbsolute(relative))
|
|
1500
1482
|
throw new Error("\u6587\u4EF6\u4E0D\u5728\u4ED3\u5E93\u5185");
|
|
1501
|
-
const
|
|
1502
|
-
if (
|
|
1503
|
-
if (
|
|
1483
|
+
const stat4 = await lstat(absolute);
|
|
1484
|
+
if (stat4.isSymbolicLink()) return { mode: "120000", hash: hash(await readlink(absolute)) };
|
|
1485
|
+
if (stat4.isDirectory()) {
|
|
1504
1486
|
const commit = (await git(absolute, ["rev-parse", "HEAD"])).trim();
|
|
1505
1487
|
return { mode: "160000", hash: hash(`Subproject commit ${commit}
|
|
1506
1488
|
`) };
|
|
1507
1489
|
}
|
|
1508
1490
|
return {
|
|
1509
|
-
mode:
|
|
1491
|
+
mode: stat4.mode & 73 ? "100755" : "100644",
|
|
1510
1492
|
hash: await fileDigest(absolute)
|
|
1511
1493
|
};
|
|
1512
1494
|
}
|
|
@@ -1522,103 +1504,72 @@ function reviewKey(change, after) {
|
|
|
1522
1504
|
})
|
|
1523
1505
|
);
|
|
1524
1506
|
}
|
|
1525
|
-
function
|
|
1507
|
+
async function collectCodeChanges(root, ref) {
|
|
1508
|
+
const { sha, files } = await collectChanges(root, ref);
|
|
1509
|
+
const repo = await realpath(root);
|
|
1526
1510
|
return {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1511
|
+
sha,
|
|
1512
|
+
files: await mapLimit(files, 16, async (change) => ({
|
|
1513
|
+
path: change.path,
|
|
1514
|
+
...change.oldPath ? { oldPath: change.oldPath } : {},
|
|
1515
|
+
status: change.status,
|
|
1516
|
+
reviewKey: reviewKey(
|
|
1517
|
+
change,
|
|
1518
|
+
change.status === "deleted" ? null : await worktreeSide(repo, change.path)
|
|
1519
|
+
)
|
|
1520
|
+
}))
|
|
1531
1521
|
};
|
|
1532
1522
|
}
|
|
1533
1523
|
async function reviewFile(root) {
|
|
1534
|
-
return
|
|
1524
|
+
return path18.join(await reportRoot(root), "cache", "reviews", "code.json");
|
|
1535
1525
|
}
|
|
1536
1526
|
async function readReviews(root) {
|
|
1537
1527
|
return await readJson(await reviewFile(root)) ?? {};
|
|
1538
1528
|
}
|
|
1539
1529
|
|
|
1540
|
-
// modules/core/implementations/Functions/getGitChanges.ts
|
|
1541
|
-
import { realpath as realpath2 } from "node:fs/promises";
|
|
1542
|
-
|
|
1543
|
-
// modules/core/contracts/functions/getGitChanges.ts
|
|
1544
|
-
import { z as z14 } from "zod";
|
|
1545
|
-
var GetGitChangesInputSchema = z14.object({ repoRoot: z14.string(), ref: z14.string() });
|
|
1546
|
-
|
|
1547
|
-
// modules/core/implementations/Functions/getGitChanges.ts
|
|
1548
|
-
async function getGitChanges(input) {
|
|
1549
|
-
const { repoRoot: root, ref } = GetGitChangesInputSchema.parse(input);
|
|
1550
|
-
const { sha, files } = await collectChanges(root, ref);
|
|
1551
|
-
const repo = await realpath2(root);
|
|
1552
|
-
const reviews = await readReviews(root);
|
|
1553
|
-
const changes = [];
|
|
1554
|
-
for (const change of files) {
|
|
1555
|
-
const after = change.status === "deleted" ? null : await worktreeSide(repo, change.path);
|
|
1556
|
-
changes.push(publicChange(change, after));
|
|
1557
|
-
}
|
|
1558
|
-
const keys = new Set(changes.map((change) => change.reviewKey));
|
|
1559
|
-
return {
|
|
1560
|
-
sha,
|
|
1561
|
-
files: changes,
|
|
1562
|
-
reviewed: Object.keys(reviews).filter((key) => keys.has(key)).sort()
|
|
1563
|
-
};
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
1530
|
// modules/core/implementations/Functions/reviewCodeChanges.ts
|
|
1567
1531
|
async function reviewCodeChanges(input) {
|
|
1568
1532
|
const { repoRoot, ref, version: version2, items, reviewed } = ReviewCodeChangesInputSchema.parse(input);
|
|
1569
|
-
const changes = await
|
|
1570
|
-
|
|
1533
|
+
const changes = await collectCodeChanges(repoRoot, ref);
|
|
1534
|
+
const keys = new Set(changes.files.map((file) => file.reviewKey));
|
|
1535
|
+
if (changes.sha !== version2 || items.some((key) => !keys.has(key)))
|
|
1571
1536
|
throw Object.assign(new Error("\u4EE3\u7801\u6539\u52A8\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u65B0\u5BA1\u6838"), { statusCode: 409 });
|
|
1572
|
-
|
|
1573
|
-
const file = changes.files.find((item) => item.reviewKey === key);
|
|
1574
|
-
if (!file)
|
|
1575
|
-
throw Object.assign(new Error("\u4EE3\u7801\u6539\u52A8\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u65B0\u5BA1\u6838"), { statusCode: 409 });
|
|
1576
|
-
return { path: file.path, key };
|
|
1577
|
-
});
|
|
1578
|
-
if (new Set(files.map((file) => file.key)).size !== files.length)
|
|
1579
|
-
throw new Error("\u5BA1\u6838\u6587\u4EF6\u4E0D\u80FD\u91CD\u590D");
|
|
1580
|
-
const { files: currentChanges } = await collectChanges(repoRoot, ref);
|
|
1581
|
-
const byPath = new Map(currentChanges.map((change) => [change.path, change]));
|
|
1582
|
-
const repo = await realpath3(repoRoot);
|
|
1537
|
+
if (new Set(items).size !== items.length) throw new Error("\u5BA1\u6838\u6587\u4EF6\u4E0D\u80FD\u91CD\u590D");
|
|
1583
1538
|
const reviews = await readReviews(repoRoot);
|
|
1584
|
-
for (const
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
throw Object.assign(new Error("\u4EE3\u7801\u6539\u52A8\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u65B0\u5BA1\u6838"), { statusCode: 409 });
|
|
1588
|
-
const after = change.status === "deleted" ? null : await worktreeSide(repo, change.path);
|
|
1589
|
-
if (reviewKey(change, after) !== file.key)
|
|
1590
|
-
throw Object.assign(new Error("\u4EE3\u7801\u6539\u52A8\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0\u540E\u91CD\u65B0\u5BA1\u6838"), { statusCode: 409 });
|
|
1591
|
-
if (reviewed) reviews[file.key] = (/* @__PURE__ */ new Date()).toISOString();
|
|
1592
|
-
else delete reviews[file.key];
|
|
1539
|
+
for (const key of items) {
|
|
1540
|
+
if (reviewed) reviews[key] = (/* @__PURE__ */ new Date()).toISOString();
|
|
1541
|
+
else delete reviews[key];
|
|
1593
1542
|
}
|
|
1594
1543
|
await writeJsonAtomic(await reviewFile(repoRoot), reviews);
|
|
1595
|
-
return {
|
|
1544
|
+
return {
|
|
1545
|
+
reviewed: Object.keys(reviews).filter((key) => keys.has(key)).sort()
|
|
1546
|
+
};
|
|
1596
1547
|
}
|
|
1597
1548
|
|
|
1598
1549
|
// modules/core/implementations/Functions/reviewBaselineChanges.ts
|
|
1599
|
-
import
|
|
1550
|
+
import path21 from "node:path";
|
|
1600
1551
|
|
|
1601
1552
|
// modules/core/contracts/functions/reviewBaselineChanges.ts
|
|
1602
|
-
import { z as
|
|
1603
|
-
var ReviewBaselineChangesInputSchema =
|
|
1604
|
-
repoRoot:
|
|
1605
|
-
ref:
|
|
1606
|
-
version:
|
|
1607
|
-
items:
|
|
1608
|
-
reviewed:
|
|
1553
|
+
import { z as z14 } from "zod";
|
|
1554
|
+
var ReviewBaselineChangesInputSchema = z14.object({
|
|
1555
|
+
repoRoot: z14.string(),
|
|
1556
|
+
ref: z14.string(),
|
|
1557
|
+
version: z14.string(),
|
|
1558
|
+
items: z14.array(z14.string()).min(1),
|
|
1559
|
+
reviewed: z14.boolean()
|
|
1609
1560
|
});
|
|
1610
1561
|
|
|
1611
1562
|
// modules/core/contracts/functions/getBaselineChanges.ts
|
|
1612
|
-
import { z as
|
|
1613
|
-
var GetBaselineChangesInputSchema =
|
|
1563
|
+
import { z as z15 } from "zod";
|
|
1564
|
+
var GetBaselineChangesInputSchema = z15.object({ repoRoot: z15.string(), ref: z15.string() });
|
|
1614
1565
|
|
|
1615
1566
|
// modules/core/implementations/reportResources.ts
|
|
1616
|
-
import
|
|
1567
|
+
import path19 from "node:path";
|
|
1617
1568
|
function reportStaticUrl(reportDir, file) {
|
|
1618
|
-
const relative =
|
|
1619
|
-
if (relative.startsWith("..") ||
|
|
1569
|
+
const relative = path19.relative(reportDir, file);
|
|
1570
|
+
if (relative.startsWith("..") || path19.isAbsolute(relative))
|
|
1620
1571
|
throw new Error("\u56FE\u7247\u8DEF\u5F84\u8D85\u51FA\u62A5\u544A\u76EE\u5F55");
|
|
1621
|
-
return `/report-static/${relative.split(
|
|
1572
|
+
return `/report-static/${relative.split(path19.sep).map(encodeURIComponent).join("/")}`;
|
|
1622
1573
|
}
|
|
1623
1574
|
async function prepareBaselineImages(root, snapshots) {
|
|
1624
1575
|
const reportDir = await reportRoot(root);
|
|
@@ -1638,8 +1589,7 @@ async function prepareBaselineImages(root, snapshots) {
|
|
|
1638
1589
|
|
|
1639
1590
|
// modules/core/implementations/Functions/getBaselineChanges.ts
|
|
1640
1591
|
import { readFile as readFile9 } from "node:fs/promises";
|
|
1641
|
-
import
|
|
1642
|
-
import path21 from "node:path";
|
|
1592
|
+
import path20 from "node:path";
|
|
1643
1593
|
import { PNG as PNG2 } from "pngjs";
|
|
1644
1594
|
async function fromGit(root, sha, file) {
|
|
1645
1595
|
const result = await runGit(root, ["show", `${sha}:${file}`]);
|
|
@@ -1648,33 +1598,26 @@ async function fromGit(root, sha, file) {
|
|
|
1648
1598
|
if (!exists.ok) return null;
|
|
1649
1599
|
throw new Error(result.stderr);
|
|
1650
1600
|
}
|
|
1651
|
-
async function gitBaselineFiles(root, sha, directory) {
|
|
1601
|
+
async function gitBaselineFiles(root, sha, directory, only) {
|
|
1652
1602
|
const result = await runGit(root, ["ls-tree", "-r", "-z", sha, "--", directory]);
|
|
1653
1603
|
if (!result.ok) throw new Error(result.stderr);
|
|
1654
1604
|
const files = result.stdout.split("\0").filter(Boolean).flatMap((line) => {
|
|
1655
1605
|
const separator = line.indexOf(" ");
|
|
1656
1606
|
const file = line.slice(separator + 1);
|
|
1657
1607
|
const [, type, oid] = line.slice(0, separator).split(" ");
|
|
1658
|
-
|
|
1608
|
+
if (type !== "blob" || !/\/baseline(?:-[a-f0-9]{64})?\.json$/.test(file)) return [];
|
|
1609
|
+
const parts = file.slice(directory.length + 1).split("/");
|
|
1610
|
+
const namespace = parts[0];
|
|
1611
|
+
const casePath = parts.slice(1, -1).join("/");
|
|
1612
|
+
return !only || only.has(`${namespace}/${casePath}`) ? [{ file, oid, namespace, casePath }] : [];
|
|
1659
1613
|
}).sort((a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : 0);
|
|
1660
1614
|
if (!files.length) return [];
|
|
1661
|
-
const output = await
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
{
|
|
1666
|
-
encoding: "buffer",
|
|
1667
|
-
maxBuffer: 32 * 1024 * 1024,
|
|
1668
|
-
timeout: 2e4,
|
|
1669
|
-
windowsHide: true
|
|
1670
|
-
},
|
|
1671
|
-
(error, stdout) => error ? reject(error) : resolve(stdout)
|
|
1672
|
-
);
|
|
1673
|
-
child.stdin.on("error", reject);
|
|
1674
|
-
child.stdin.end(files.map(({ oid }) => oid).join("\n") + "\n");
|
|
1675
|
-
});
|
|
1615
|
+
const output = await gitCatFileBatch(
|
|
1616
|
+
root,
|
|
1617
|
+
files.map(({ oid }) => oid)
|
|
1618
|
+
);
|
|
1676
1619
|
let offset = 0;
|
|
1677
|
-
return files.map(({ file, oid }) => {
|
|
1620
|
+
return files.map(({ file, oid, namespace, casePath }) => {
|
|
1678
1621
|
const end = output.indexOf(10, offset);
|
|
1679
1622
|
const [actualOid, type, length] = output.subarray(offset, end).toString().split(" ");
|
|
1680
1623
|
const size = Number(length);
|
|
@@ -1684,8 +1627,7 @@ async function gitBaselineFiles(root, sha, directory) {
|
|
|
1684
1627
|
output.subarray(end + 1, end + 1 + size).toString("utf8")
|
|
1685
1628
|
);
|
|
1686
1629
|
offset = end + 1 + size + 1;
|
|
1687
|
-
|
|
1688
|
-
return { namespace: parts[0], path: parts.slice(1, -1).join("/"), file, baseline };
|
|
1630
|
+
return { namespace, path: casePath, file, baseline };
|
|
1689
1631
|
});
|
|
1690
1632
|
}
|
|
1691
1633
|
async function currentBaseline(root, namespace) {
|
|
@@ -1723,12 +1665,12 @@ async function getBaselineChanges(input) {
|
|
|
1723
1665
|
const { repoRoot: root, ref } = GetBaselineChangesInputSchema.parse(input);
|
|
1724
1666
|
const { sha, files: gitChanges } = await collectChanges(root, ref);
|
|
1725
1667
|
if (!sha) throw new Error("\u627E\u4E0D\u5230\u6BD4\u8F83\u5206\u652F");
|
|
1726
|
-
const
|
|
1668
|
+
const entries2 = [];
|
|
1727
1669
|
const config = await loadConfig({ repoRoot: root });
|
|
1728
1670
|
const historicalConfig = await fromGit(root, sha, "evidra.config.json");
|
|
1729
1671
|
const oldConfig = historicalConfig ? parseConfig(JSON.parse(historicalConfig)) : config;
|
|
1730
|
-
const currentDirectory =
|
|
1731
|
-
const oldDirectory =
|
|
1672
|
+
const currentDirectory = path20.posix.join(config.reportDir.split(path20.sep).join("/"), "baselines");
|
|
1673
|
+
const oldDirectory = path20.posix.join(oldConfig.reportDir.split(path20.sep).join("/"), "baselines");
|
|
1732
1674
|
const configChanged = gitChanges.some((item) => item.path === "evidra.config.json");
|
|
1733
1675
|
const affected = new Set(
|
|
1734
1676
|
gitChanges.flatMap((item) => [item.path, item.oldPath].filter((file) => !!file)).flatMap((file) => {
|
|
@@ -1743,7 +1685,7 @@ async function getBaselineChanges(input) {
|
|
|
1743
1685
|
return [];
|
|
1744
1686
|
})
|
|
1745
1687
|
);
|
|
1746
|
-
const historical = configChanged || affected.size ? await gitBaselineFiles(root, sha, oldDirectory) : [];
|
|
1688
|
+
const historical = configChanged || affected.size ? await gitBaselineFiles(root, sha, oldDirectory, configChanged ? void 0 : affected) : [];
|
|
1747
1689
|
const namespaces = configChanged || affected.size ? [...config.namespaces] : [];
|
|
1748
1690
|
const byNamespace = /* @__PURE__ */ new Map();
|
|
1749
1691
|
for (const item of historical) {
|
|
@@ -1786,10 +1728,10 @@ async function getBaselineChanges(input) {
|
|
|
1786
1728
|
}
|
|
1787
1729
|
const changed = snapshots.some((snapshot) => snapshot.change !== "same") || a?.baseline.name !== b?.baseline.name || canonical(a?.baseline.treePath) !== canonical(b?.baseline.treePath);
|
|
1788
1730
|
if (!changed) continue;
|
|
1789
|
-
|
|
1731
|
+
entries2.push({
|
|
1790
1732
|
namespace: namespace.id,
|
|
1791
1733
|
namespaceName: namespace.name,
|
|
1792
|
-
file: b?.file ?
|
|
1734
|
+
file: b?.file ? path20.posix.join(currentDirectory, namespace.id, b.file) : a?.file ?? path20.posix.join(currentDirectory, namespace.id, b?.path ?? a.path, "baseline.json"),
|
|
1793
1735
|
item: {
|
|
1794
1736
|
id: b?.baseline.id ?? a.baseline.id,
|
|
1795
1737
|
change: !a ? "added" : !b ? "deleted" : "modified",
|
|
@@ -1800,21 +1742,21 @@ async function getBaselineChanges(input) {
|
|
|
1800
1742
|
});
|
|
1801
1743
|
}
|
|
1802
1744
|
}
|
|
1803
|
-
const digest = version([sha,
|
|
1745
|
+
const digest = version([sha, entries2]);
|
|
1804
1746
|
const reportDir = await reportRoot(root);
|
|
1805
1747
|
await prepareBaselineImages(
|
|
1806
1748
|
root,
|
|
1807
|
-
|
|
1749
|
+
entries2.flatMap(
|
|
1808
1750
|
(entry) => entry.item.snapshots.flatMap(
|
|
1809
1751
|
(snapshot) => [snapshot.baseline, snapshot.current].filter((item) => !!item)
|
|
1810
1752
|
)
|
|
1811
1753
|
)
|
|
1812
1754
|
);
|
|
1813
|
-
for (const entry of
|
|
1755
|
+
for (const entry of entries2) {
|
|
1814
1756
|
for (const snapshot of entry.item.snapshots) {
|
|
1815
1757
|
if (snapshot.baseline?.type === "image" && snapshot.current?.type === "image" && snapshot.baseline.key !== snapshot.current.key) {
|
|
1816
1758
|
const file = await prepareImageDiff(root, snapshot.baseline, snapshot.current);
|
|
1817
|
-
snapshot.diffFile =
|
|
1759
|
+
snapshot.diffFile = path20.relative(reportDir, file).split(path20.sep).join("/");
|
|
1818
1760
|
snapshot.diffUrl = reportStaticUrl(reportDir, file);
|
|
1819
1761
|
}
|
|
1820
1762
|
}
|
|
@@ -1823,26 +1765,26 @@ async function getBaselineChanges(input) {
|
|
|
1823
1765
|
ref,
|
|
1824
1766
|
sha,
|
|
1825
1767
|
version: digest,
|
|
1826
|
-
entries,
|
|
1768
|
+
entries: entries2,
|
|
1827
1769
|
reviewed: await readJson(
|
|
1828
|
-
|
|
1770
|
+
path20.join(await reportRoot(root), "cache", "reviews", `${digest}.json`)
|
|
1829
1771
|
) ?? []
|
|
1830
1772
|
};
|
|
1831
1773
|
}
|
|
1832
1774
|
async function prepareImageDiff(root, before, after) {
|
|
1833
1775
|
if (!before.key || !after.key) throw new Error("\u57FA\u7EBF\u56FE\u7247\u7F3A\u5C11\u5BF9\u8C61\u5B58\u50A8 key");
|
|
1834
1776
|
const reportDir = await reportRoot(root);
|
|
1835
|
-
const directory =
|
|
1777
|
+
const directory = path20.join(
|
|
1836
1778
|
reportDir,
|
|
1837
1779
|
"cache",
|
|
1838
1780
|
"comparisons",
|
|
1839
1781
|
version(["git", before.key, after.key])
|
|
1840
1782
|
);
|
|
1841
|
-
const index =
|
|
1783
|
+
const index = path20.join(directory, "diff-v2.json");
|
|
1842
1784
|
const cached = await readJson(index);
|
|
1843
1785
|
try {
|
|
1844
1786
|
if (cached) {
|
|
1845
|
-
const file2 =
|
|
1787
|
+
const file2 = path20.join(directory, cached);
|
|
1846
1788
|
await readFile9(file2);
|
|
1847
1789
|
return file2;
|
|
1848
1790
|
}
|
|
@@ -1859,7 +1801,7 @@ async function prepareImageDiff(root, before, after) {
|
|
|
1859
1801
|
const result = localImageDiff(PNG2.sync.write(left), PNG2.sync.write(right));
|
|
1860
1802
|
if (!result.png) throw new Error("\u65E0\u6CD5\u751F\u6210\u56FE\u7247\u5DEE\u5F02");
|
|
1861
1803
|
const filename = `diff-${hash(result.png)}.png`;
|
|
1862
|
-
const file =
|
|
1804
|
+
const file = path20.join(directory, filename);
|
|
1863
1805
|
await writeBytesAtomic(file, result.png);
|
|
1864
1806
|
await writeJsonAtomic(index, filename);
|
|
1865
1807
|
return file;
|
|
@@ -1880,23 +1822,23 @@ async function reviewBaselineChanges(input) {
|
|
|
1880
1822
|
for (const id of items) reviewed ? selected.add(id) : selected.delete(id);
|
|
1881
1823
|
const ids = [...selected];
|
|
1882
1824
|
await writeJsonAtomic(
|
|
1883
|
-
|
|
1825
|
+
path21.join(await reportRoot(repoRoot), "cache", "reviews", `${version2}.json`),
|
|
1884
1826
|
ids
|
|
1885
1827
|
);
|
|
1886
1828
|
return { reviewed: ids };
|
|
1887
1829
|
}
|
|
1888
1830
|
|
|
1889
1831
|
// modules/core/implementations/Functions/deleteBaselineFile.ts
|
|
1890
|
-
import
|
|
1832
|
+
import path22 from "node:path";
|
|
1891
1833
|
import { rm as rm4 } from "node:fs/promises";
|
|
1892
1834
|
|
|
1893
1835
|
// modules/core/contracts/functions/deleteBaselineFile.ts
|
|
1894
|
-
import { z as
|
|
1895
|
-
var DeleteBaselineFileInputSchema =
|
|
1896
|
-
repoRoot:
|
|
1897
|
-
namespace:
|
|
1898
|
-
file:
|
|
1899
|
-
version:
|
|
1836
|
+
import { z as z16 } from "zod";
|
|
1837
|
+
var DeleteBaselineFileInputSchema = z16.object({
|
|
1838
|
+
repoRoot: z16.string(),
|
|
1839
|
+
namespace: z16.string(),
|
|
1840
|
+
file: z16.string(),
|
|
1841
|
+
version: z16.string()
|
|
1900
1842
|
});
|
|
1901
1843
|
|
|
1902
1844
|
// modules/core/implementations/Functions/deleteBaselineFile.ts
|
|
@@ -1908,19 +1850,19 @@ async function deleteBaselineFile(input) {
|
|
|
1908
1850
|
throw Object.assign(new Error("\u57FA\u7EBF\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0"), { statusCode: 409 });
|
|
1909
1851
|
if (!current.candidates.some((item) => item.file === file))
|
|
1910
1852
|
throw Object.assign(new Error("\u57FA\u7EBF\u6587\u4EF6\u4E0D\u5B58\u5728"), { statusCode: 404 });
|
|
1911
|
-
await rm4(
|
|
1853
|
+
await rm4(path22.join(absoluteReportPath, "baselines", namespace, file));
|
|
1912
1854
|
return { ok: true };
|
|
1913
1855
|
}
|
|
1914
1856
|
|
|
1915
1857
|
// modules/core/implementations/Functions/compareTasks.ts
|
|
1916
|
-
import
|
|
1858
|
+
import path23 from "node:path";
|
|
1917
1859
|
|
|
1918
1860
|
// modules/core/contracts/functions/compareTasks.ts
|
|
1919
|
-
import { z as
|
|
1920
|
-
var CompareTasksInputSchema =
|
|
1921
|
-
repoRoot:
|
|
1922
|
-
baseTaskId:
|
|
1923
|
-
taskId:
|
|
1861
|
+
import { z as z17 } from "zod";
|
|
1862
|
+
var CompareTasksInputSchema = z17.object({
|
|
1863
|
+
repoRoot: z17.string(),
|
|
1864
|
+
baseTaskId: z17.string().regex(/^[a-zA-Z0-9_-]{3,}$/),
|
|
1865
|
+
taskId: z17.string().regex(/^[a-zA-Z0-9_-]{3,}$/)
|
|
1924
1866
|
});
|
|
1925
1867
|
|
|
1926
1868
|
// modules/core/implementations/Functions/compareTasks.ts
|
|
@@ -1958,7 +1900,7 @@ async function compareTasks(input) {
|
|
|
1958
1900
|
download: (key) => readTaskImage(reportDir, key),
|
|
1959
1901
|
localPath: async (key) => {
|
|
1960
1902
|
await readTaskImage(reportDir, key);
|
|
1961
|
-
return
|
|
1903
|
+
return path23.resolve(reportDir, "objects", key);
|
|
1962
1904
|
},
|
|
1963
1905
|
upload: async () => {
|
|
1964
1906
|
throw new Error("\u4EFB\u52A1\u6BD4\u8F83\u4E0D\u5199\u5165\u57FA\u7EBF\u5B58\u50A8");
|
|
@@ -1987,9 +1929,28 @@ async function compareTasks(input) {
|
|
|
1987
1929
|
};
|
|
1988
1930
|
}
|
|
1989
1931
|
|
|
1932
|
+
// modules/core/contracts/functions/getGitChanges.ts
|
|
1933
|
+
import { z as z18 } from "zod";
|
|
1934
|
+
var GetGitChangesInputSchema = z18.object({ repoRoot: z18.string(), ref: z18.string() });
|
|
1935
|
+
|
|
1936
|
+
// modules/core/implementations/Functions/getGitChanges.ts
|
|
1937
|
+
async function getGitChanges(input) {
|
|
1938
|
+
const { repoRoot: root, ref } = GetGitChangesInputSchema.parse(input);
|
|
1939
|
+
const [{ sha, files }, reviews] = await Promise.all([
|
|
1940
|
+
collectCodeChanges(root, ref),
|
|
1941
|
+
readReviews(root)
|
|
1942
|
+
]);
|
|
1943
|
+
const keys = new Set(files.map((change) => change.reviewKey));
|
|
1944
|
+
return {
|
|
1945
|
+
sha,
|
|
1946
|
+
files,
|
|
1947
|
+
reviewed: Object.keys(reviews).filter((key) => keys.has(key)).sort()
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1990
1951
|
// modules/core/implementations/Functions/getGitDiff.ts
|
|
1991
|
-
import
|
|
1992
|
-
import { lstat as lstat2, readFile as readFile10, readlink as readlink2, realpath as
|
|
1952
|
+
import path24 from "node:path";
|
|
1953
|
+
import { lstat as lstat2, readFile as readFile10, readlink as readlink2, realpath as realpath2 } from "node:fs/promises";
|
|
1993
1954
|
|
|
1994
1955
|
// modules/core/contracts/functions/getGitDiff.ts
|
|
1995
1956
|
import { z as z19 } from "zod";
|
|
@@ -2007,7 +1968,7 @@ async function getGitDiff(input) {
|
|
|
2007
1968
|
const entry = files.find((entry2) => entry2.path === file);
|
|
2008
1969
|
if (!entry) throw new Error("\u627E\u4E0D\u5230\u4EE3\u7801\u6539\u52A8\u6587\u4EF6");
|
|
2009
1970
|
if (expectedKey) {
|
|
2010
|
-
const after = entry.status === "deleted" ? null : await worktreeSide(await
|
|
1971
|
+
const after = entry.status === "deleted" ? null : await worktreeSide(await realpath2(root), entry.path);
|
|
2011
1972
|
if (reviewKey(entry, after) !== expectedKey)
|
|
2012
1973
|
throw Object.assign(new Error("\u4EE3\u7801\u6539\u52A8\u5DF2\u53D8\u5316\uFF0C\u8BF7\u5237\u65B0"), { statusCode: 409 });
|
|
2013
1974
|
}
|
|
@@ -2022,18 +1983,18 @@ async function getGitDiff(input) {
|
|
|
2022
1983
|
else original = await git(root, ["show", object]);
|
|
2023
1984
|
}
|
|
2024
1985
|
if (entry.status !== "deleted") {
|
|
2025
|
-
const absolute =
|
|
2026
|
-
const parent = await
|
|
2027
|
-
const repo = await
|
|
2028
|
-
const relative =
|
|
2029
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
1986
|
+
const absolute = path24.resolve(root, file);
|
|
1987
|
+
const parent = await realpath2(path24.dirname(absolute));
|
|
1988
|
+
const repo = await realpath2(root);
|
|
1989
|
+
const relative = path24.relative(repo, parent);
|
|
1990
|
+
if (relative === ".." || relative.startsWith(`..${path24.sep}`) || path24.isAbsolute(relative))
|
|
2030
1991
|
throw new Error("\u6587\u4EF6\u4E0D\u5728\u4ED3\u5E93\u5185");
|
|
2031
|
-
const
|
|
2032
|
-
if (
|
|
2033
|
-
else if (
|
|
1992
|
+
const stat4 = await lstat2(absolute);
|
|
1993
|
+
if (stat4.isSymbolicLink()) modified = await readlink2(absolute);
|
|
1994
|
+
else if (stat4.isDirectory())
|
|
2034
1995
|
modified = `Subproject commit ${(await git(absolute, ["rev-parse", "HEAD"])).trim()}
|
|
2035
1996
|
`;
|
|
2036
|
-
else if (
|
|
1997
|
+
else if (stat4.size > MAX_BYTES) tooLarge = true;
|
|
2037
1998
|
else modified = await readFile10(absolute, "utf8");
|
|
2038
1999
|
}
|
|
2039
2000
|
const isBinary = original.includes("\0") || modified.includes("\0");
|
|
@@ -2048,10 +2009,150 @@ async function getGitDiff(input) {
|
|
|
2048
2009
|
};
|
|
2049
2010
|
}
|
|
2050
2011
|
|
|
2051
|
-
// modules/core/
|
|
2012
|
+
// modules/core/implementations/Functions/pruneTasks.ts
|
|
2013
|
+
import { readdir as readdir4, readFile as readFile11, rm as rm5, rmdir, stat } from "node:fs/promises";
|
|
2014
|
+
import path26 from "node:path";
|
|
2015
|
+
|
|
2016
|
+
// modules/core/contracts/functions/pruneTasks.ts
|
|
2052
2017
|
import { z as z20 } from "zod";
|
|
2053
|
-
var
|
|
2054
|
-
repoRoot: z20.string()
|
|
2018
|
+
var PruneTasksInputSchema = z20.object({
|
|
2019
|
+
repoRoot: z20.string(),
|
|
2020
|
+
/** 只统计可清理的任务数量,不删除。 */
|
|
2021
|
+
dryRun: z20.boolean().optional()
|
|
2022
|
+
});
|
|
2023
|
+
|
|
2024
|
+
// modules/core/contracts/internal/listTasks.ts
|
|
2025
|
+
import { z as z21 } from "zod";
|
|
2026
|
+
var ListTasksInputSchema = z21.object({
|
|
2027
|
+
limit: z21.number().int().min(1).max(100).optional()
|
|
2028
|
+
});
|
|
2029
|
+
var TASK_LIST_LIMIT = 50;
|
|
2030
|
+
|
|
2031
|
+
// modules/core/implementations/internal/listTasks.ts
|
|
2032
|
+
import { readdir as readdir3 } from "node:fs/promises";
|
|
2033
|
+
import path25 from "node:path";
|
|
2034
|
+
async function listTasks(input, cwd, namespaces) {
|
|
2035
|
+
const { limit = 20 } = ListTasksInputSchema.parse(input);
|
|
2036
|
+
const root = path25.join(cwd, "tasks");
|
|
2037
|
+
const tasks = [];
|
|
2038
|
+
const removable = [];
|
|
2039
|
+
async function directories(directory, pattern) {
|
|
2040
|
+
try {
|
|
2041
|
+
return (await readdir3(directory, { withFileTypes: true })).filter((entry) => entry.isDirectory() && pattern.test(entry.name)).map((entry) => entry.name).sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
|
|
2042
|
+
} catch (error) {
|
|
2043
|
+
if (error.code === "ENOENT") return [];
|
|
2044
|
+
throw error;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
for (const day of await directories(root, /^\d{4}-\d{2}-\d{2}$/)) {
|
|
2048
|
+
const dayRoot = path25.join(root, day);
|
|
2049
|
+
for (const run of await directories(dayRoot, /^\d{2}-\d{2}-\d{2}-[A-Za-z0-9-]+$/)) {
|
|
2050
|
+
if (tasks.length === limit) {
|
|
2051
|
+
removable.push(`${day}/${run}`);
|
|
2052
|
+
continue;
|
|
2053
|
+
}
|
|
2054
|
+
const file = path25.join(dayRoot, run, "task.json");
|
|
2055
|
+
const manifest = await readJson(file);
|
|
2056
|
+
if (!manifest || (manifest.formatVersion ?? 0) < TASK_SCHEMA_VERSION || !namespaces.has(manifest.task.namespace))
|
|
2057
|
+
continue;
|
|
2058
|
+
if (manifest.task.finishedAt && manifest.failedCount !== void 0) {
|
|
2059
|
+
tasks.push({ ...manifest.task, failedCount: manifest.failedCount });
|
|
2060
|
+
continue;
|
|
2061
|
+
}
|
|
2062
|
+
const record = await readTaskRecord(file);
|
|
2063
|
+
tasks.push({
|
|
2064
|
+
...record.task,
|
|
2065
|
+
failedCount: record.cases.filter((item) => item.result.status === "failed").length
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
return { tasks, removable };
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
// modules/core/implementations/Functions/pruneTasks.ts
|
|
2073
|
+
var OBJECT_GRACE_MS = 10 * 60 * 1e3;
|
|
2074
|
+
async function entries(directory) {
|
|
2075
|
+
try {
|
|
2076
|
+
return await readdir4(directory, { withFileTypes: true });
|
|
2077
|
+
} catch (error) {
|
|
2078
|
+
if (error.code === "ENOENT") return [];
|
|
2079
|
+
throw error;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
async function removeIfEmpty(directory) {
|
|
2083
|
+
await rmdir(directory).catch((error) => {
|
|
2084
|
+
if (!["ENOTEMPTY", "EEXIST", "ENOENT"].includes(error.code ?? "")) throw error;
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
async function removeUnreferencedObjects(reportDir) {
|
|
2088
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
2089
|
+
const tasks = path26.join(reportDir, "tasks");
|
|
2090
|
+
for (const day of await entries(tasks)) {
|
|
2091
|
+
if (!day.isDirectory() || day.name === "_index") continue;
|
|
2092
|
+
for (const run of await entries(path26.join(tasks, day.name))) {
|
|
2093
|
+
const cases = path26.join(tasks, day.name, run.name, "cases");
|
|
2094
|
+
for (const file of await entries(cases)) {
|
|
2095
|
+
if (!file.name.endsWith(".json")) continue;
|
|
2096
|
+
const item = JSON.parse(await readFile11(path26.join(cases, file.name), "utf8"));
|
|
2097
|
+
for (const image of [...item.snapshots ?? [], ...item.observations ?? []])
|
|
2098
|
+
if (image.type === "image") referenced.add(image.key);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
const objects = path26.join(reportDir, "objects");
|
|
2103
|
+
const deadline = Date.now() - OBJECT_GRACE_MS;
|
|
2104
|
+
const directories = [];
|
|
2105
|
+
for (const entry of await readdir4(objects, { withFileTypes: true, recursive: true }).catch(
|
|
2106
|
+
(error) => {
|
|
2107
|
+
if (error.code === "ENOENT") return [];
|
|
2108
|
+
throw error;
|
|
2109
|
+
}
|
|
2110
|
+
)) {
|
|
2111
|
+
const file = path26.join(entry.parentPath, entry.name);
|
|
2112
|
+
if (entry.isDirectory()) {
|
|
2113
|
+
directories.push(file);
|
|
2114
|
+
continue;
|
|
2115
|
+
}
|
|
2116
|
+
if (referenced.has(path26.relative(objects, file).split(path26.sep).join("/"))) continue;
|
|
2117
|
+
if ((await stat(file)).mtimeMs < deadline) await rm5(file);
|
|
2118
|
+
}
|
|
2119
|
+
for (const directory of directories.sort((a, b) => b.length - a.length))
|
|
2120
|
+
await removeIfEmpty(directory);
|
|
2121
|
+
}
|
|
2122
|
+
async function pruneTasks(input) {
|
|
2123
|
+
const { repoRoot, dryRun } = PruneTasksInputSchema.parse(input);
|
|
2124
|
+
const config = await loadConfig({ repoRoot });
|
|
2125
|
+
const reportDir = await reportRoot(repoRoot);
|
|
2126
|
+
const { removable } = await listTasks(
|
|
2127
|
+
{ limit: TASK_LIST_LIMIT },
|
|
2128
|
+
reportDir,
|
|
2129
|
+
new Set(config.namespaces.map((item) => item.id))
|
|
2130
|
+
);
|
|
2131
|
+
if (dryRun || !removable.length) return { count: removable.length };
|
|
2132
|
+
const cache = pathSchema.cache(reportDir).directory;
|
|
2133
|
+
const comparisons = path26.join(cache, "comparisons");
|
|
2134
|
+
const taskComparisons = path26.join(cache, "task-comparisons");
|
|
2135
|
+
const options = { recursive: true, force: true };
|
|
2136
|
+
for (const taskPath of removable) {
|
|
2137
|
+
const taskId = taskPath.split("/")[1].slice("HH-mm-ss-".length);
|
|
2138
|
+
await rm5(taskDirectory(reportDir, taskPath), options);
|
|
2139
|
+
await rm5(pathSchema.taskIndex(reportDir, taskId), { force: true });
|
|
2140
|
+
for (const namespace of await entries(comparisons))
|
|
2141
|
+
await rm5(path26.join(comparisons, namespace.name, taskId), options);
|
|
2142
|
+
await rm5(path26.join(taskComparisons, taskId), options);
|
|
2143
|
+
for (const base of await entries(taskComparisons))
|
|
2144
|
+
await rm5(path26.join(taskComparisons, base.name, taskId), options);
|
|
2145
|
+
}
|
|
2146
|
+
for (const day of new Set(removable.map((taskPath) => taskPath.split("/")[0])))
|
|
2147
|
+
await removeIfEmpty(path26.join(reportDir, "tasks", day));
|
|
2148
|
+
await removeUnreferencedObjects(reportDir);
|
|
2149
|
+
return { count: removable.length };
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
// modules/core/contracts/functions/listTaskSummaries.ts
|
|
2153
|
+
import { z as z22 } from "zod";
|
|
2154
|
+
var ListTaskSummariesInputSchema = z22.object({
|
|
2155
|
+
repoRoot: z22.string()
|
|
2055
2156
|
});
|
|
2056
2157
|
|
|
2057
2158
|
// modules/core/implementations/reportStatus.ts
|
|
@@ -2097,54 +2198,13 @@ function taskDisplay(task) {
|
|
|
2097
2198
|
};
|
|
2098
2199
|
}
|
|
2099
2200
|
|
|
2100
|
-
// modules/core/implementations/internal/listTasks.ts
|
|
2101
|
-
import { readdir as readdir3 } from "node:fs/promises";
|
|
2102
|
-
import path26 from "node:path";
|
|
2103
|
-
|
|
2104
|
-
// modules/core/contracts/internal/listTasks.ts
|
|
2105
|
-
import { z as z21 } from "zod";
|
|
2106
|
-
var ListTasksInputSchema = z21.object({
|
|
2107
|
-
limit: z21.number().int().min(1).max(100).optional()
|
|
2108
|
-
});
|
|
2109
|
-
|
|
2110
|
-
// modules/core/implementations/internal/listTasks.ts
|
|
2111
|
-
async function listTasks(input, cwd, namespaces) {
|
|
2112
|
-
const { limit = 20 } = ListTasksInputSchema.parse(input);
|
|
2113
|
-
const root = path26.join(cwd, "tasks");
|
|
2114
|
-
const tasks = [];
|
|
2115
|
-
async function directories(directory, pattern) {
|
|
2116
|
-
try {
|
|
2117
|
-
return (await readdir3(directory, { withFileTypes: true })).filter((entry) => entry.isDirectory() && pattern.test(entry.name)).map((entry) => entry.name).sort((a, b) => a < b ? 1 : a > b ? -1 : 0);
|
|
2118
|
-
} catch (error) {
|
|
2119
|
-
if (error.code === "ENOENT") return [];
|
|
2120
|
-
throw error;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
for (const day of await directories(root, /^\d{4}-\d{2}-\d{2}$/)) {
|
|
2124
|
-
const dayRoot = path26.join(root, day);
|
|
2125
|
-
for (const run of await directories(dayRoot, /^\d{2}-\d{2}-\d{2}-[A-Za-z0-9-]+$/)) {
|
|
2126
|
-
const file = path26.join(dayRoot, run, "task.json");
|
|
2127
|
-
const manifest = await readJson(file);
|
|
2128
|
-
if (!manifest || (manifest.formatVersion ?? 0) < TASK_SCEHAM_VERSION || !namespaces.has(manifest.task.namespace))
|
|
2129
|
-
continue;
|
|
2130
|
-
const record = await readTaskRecord(file);
|
|
2131
|
-
tasks.push({
|
|
2132
|
-
...record.task,
|
|
2133
|
-
failedCount: record.cases.filter((item) => item.result.status === "failed").length
|
|
2134
|
-
});
|
|
2135
|
-
if (tasks.length === limit) return { tasks };
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
2138
|
-
return { tasks };
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
2201
|
// modules/core/implementations/Functions/listTaskSummaries.ts
|
|
2142
2202
|
async function listTaskSummaries(input) {
|
|
2143
2203
|
const { repoRoot: root } = ListTaskSummariesInputSchema.parse(input);
|
|
2144
2204
|
const config = await loadConfig({ repoRoot: root });
|
|
2145
2205
|
const namespaces = new Set(config.namespaces.map((item) => item.id));
|
|
2146
2206
|
const reportDir = await reportRoot(root);
|
|
2147
|
-
const page = await listTasks({ limit:
|
|
2207
|
+
const page = await listTasks({ limit: TASK_LIST_LIMIT }, reportDir, namespaces);
|
|
2148
2208
|
const tasks = page.tasks;
|
|
2149
2209
|
const versions = new Map(
|
|
2150
2210
|
await Promise.all(
|
|
@@ -2181,8 +2241,8 @@ async function listTaskSummaries(input) {
|
|
|
2181
2241
|
}
|
|
2182
2242
|
|
|
2183
2243
|
// modules/core/contracts/functions/readProjectInfo.ts
|
|
2184
|
-
import { z as
|
|
2185
|
-
var ReadProjectInfoInputSchema =
|
|
2244
|
+
import { z as z23 } from "zod";
|
|
2245
|
+
var ReadProjectInfoInputSchema = z23.object({ repoRoot: z23.string() });
|
|
2186
2246
|
|
|
2187
2247
|
// modules/core/implementations/Functions/readProjectInfo.ts
|
|
2188
2248
|
var FALLBACK_REFS = ["main", "master", "origin/main", "origin/master"];
|
|
@@ -2228,15 +2288,15 @@ async function readProjectInfo(input) {
|
|
|
2228
2288
|
}
|
|
2229
2289
|
|
|
2230
2290
|
// modules/core/contracts/functions/listBaselines.ts
|
|
2231
|
-
import { z as
|
|
2232
|
-
var ListBaselinesInputSchema =
|
|
2291
|
+
import { z as z24 } from "zod";
|
|
2292
|
+
var ListBaselinesInputSchema = z24.object({ repoRoot: z24.string() });
|
|
2233
2293
|
|
|
2234
2294
|
// modules/core/implementations/reportTree.ts
|
|
2235
2295
|
var reportEntryKey = (namespace, id) => JSON.stringify([namespace, id]);
|
|
2236
|
-
function buildReportTree(namespaces,
|
|
2296
|
+
function buildReportTree(namespaces, entries2, running) {
|
|
2237
2297
|
return namespaces.flatMap((ns) => {
|
|
2238
2298
|
const children = [];
|
|
2239
|
-
for (const entry of
|
|
2299
|
+
for (const entry of entries2.filter((e) => e.namespace === ns.id)) {
|
|
2240
2300
|
const item = entry.item.current ?? entry.item.baseline;
|
|
2241
2301
|
const parts = item.treePath.length ? item.treePath : [{ key: item.id, display: item.name }];
|
|
2242
2302
|
let nodes = children;
|
|
@@ -2283,7 +2343,7 @@ async function listBaselines(input) {
|
|
|
2283
2343
|
...(group.candidates ?? []).flatMap((item) => item.baseline.snapshots)
|
|
2284
2344
|
])
|
|
2285
2345
|
);
|
|
2286
|
-
const
|
|
2346
|
+
const entries2 = namespaces.flatMap(
|
|
2287
2347
|
(group) => (group.candidates ?? group.cases.map((baseline) => ({ baseline, file: "", ignored: false }))).map(({ baseline, file, ignored }) => ({
|
|
2288
2348
|
key: reportEntryKey(group.id, file || baseline.id),
|
|
2289
2349
|
ignored,
|
|
@@ -2303,15 +2363,15 @@ async function listBaselines(input) {
|
|
|
2303
2363
|
}
|
|
2304
2364
|
}))
|
|
2305
2365
|
);
|
|
2306
|
-
return { namespaces, entries, tree: buildReportTree(namespaces,
|
|
2366
|
+
return { namespaces, entries: entries2, tree: buildReportTree(namespaces, entries2, false) };
|
|
2307
2367
|
}
|
|
2308
2368
|
|
|
2309
2369
|
// modules/core/implementations/Functions/readTaskReport.ts
|
|
2310
2370
|
import path27 from "node:path";
|
|
2311
2371
|
|
|
2312
2372
|
// modules/core/contracts/functions/readTaskReport.ts
|
|
2313
|
-
import { z as
|
|
2314
|
-
var ReadTaskReportInputSchema =
|
|
2373
|
+
import { z as z25 } from "zod";
|
|
2374
|
+
var ReadTaskReportInputSchema = z25.object({ repoRoot: z25.string(), taskId: z25.string() });
|
|
2315
2375
|
|
|
2316
2376
|
// modules/core/implementations/Functions/readTaskReport.ts
|
|
2317
2377
|
async function readTaskReport(input) {
|
|
@@ -2339,7 +2399,7 @@ async function readTaskReport(input) {
|
|
|
2339
2399
|
id: task.namespace,
|
|
2340
2400
|
name: task.namespace
|
|
2341
2401
|
};
|
|
2342
|
-
const
|
|
2402
|
+
const entries2 = comparison.cases.map((item) => ({
|
|
2343
2403
|
key: reportEntryKey(task.namespace, item.id),
|
|
2344
2404
|
namespace: task.namespace,
|
|
2345
2405
|
item,
|
|
@@ -2354,7 +2414,208 @@ async function readTaskReport(input) {
|
|
|
2354
2414
|
caseCount: task.cases.length,
|
|
2355
2415
|
failedCount: task.cases.filter((item) => item.result.status === "failed").length
|
|
2356
2416
|
});
|
|
2357
|
-
return { task, comparison, entries, tree: buildReportTree([namespace],
|
|
2417
|
+
return { task, comparison, entries: entries2, tree: buildReportTree([namespace], entries2, true), display };
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
// modules/core/implementations/Functions/listChangelogCommits.ts
|
|
2421
|
+
import path29 from "node:path";
|
|
2422
|
+
|
|
2423
|
+
// modules/core/contracts/functions/changelog.ts
|
|
2424
|
+
import { z as z26 } from "zod";
|
|
2425
|
+
var ChangelogNoteSchema = z26.object({
|
|
2426
|
+
changelog: z26.string().optional(),
|
|
2427
|
+
reviewed: z26.boolean().optional(),
|
|
2428
|
+
entries: z26.record(z26.string(), z26.string()).optional(),
|
|
2429
|
+
excludeTags: z26.array(z26.string()).optional()
|
|
2430
|
+
}).passthrough();
|
|
2431
|
+
var ListChangelogCommitsInputSchema = z26.object({
|
|
2432
|
+
repoRoot: z26.string()
|
|
2433
|
+
});
|
|
2434
|
+
var GetChangelogFilesInputSchema = z26.object({
|
|
2435
|
+
repoRoot: z26.string(),
|
|
2436
|
+
commitId: z26.string().regex(/^[a-f0-9]{40}$/)
|
|
2437
|
+
});
|
|
2438
|
+
var GetChangelogDiffInputSchema = GetChangelogFilesInputSchema.extend({
|
|
2439
|
+
file: z26.string().min(1)
|
|
2440
|
+
});
|
|
2441
|
+
var ChangelogPatchSchema = z26.object({
|
|
2442
|
+
scope: z26.string().optional(),
|
|
2443
|
+
changelog: z26.string().optional(),
|
|
2444
|
+
reviewed: z26.boolean().optional(),
|
|
2445
|
+
excludeTags: z26.array(z26.string()).optional()
|
|
2446
|
+
});
|
|
2447
|
+
var UpdateChangelogNoteInputSchema = GetChangelogFilesInputSchema.extend({
|
|
2448
|
+
patch: ChangelogPatchSchema
|
|
2449
|
+
});
|
|
2450
|
+
|
|
2451
|
+
// modules/core/implementations/changelog.ts
|
|
2452
|
+
import path28 from "node:path";
|
|
2453
|
+
async function changelogConfig(repoRoot) {
|
|
2454
|
+
const config = await loadConfig({ repoRoot });
|
|
2455
|
+
if (!config.change) throw Object.assign(new Error("\u6B64\u9879\u76EE\u672A\u914D\u7F6E\u66F4\u65B0\u65E5\u5FD7"), { statusCode: 404 });
|
|
2456
|
+
return { ...config.change, notedir: path28.resolve(repoRoot, config.change.notedir) };
|
|
2457
|
+
}
|
|
2458
|
+
function notePath(notedir, commitId) {
|
|
2459
|
+
return path28.join(notedir, commitId.slice(0, 2), `${commitId.slice(2)}.json`);
|
|
2460
|
+
}
|
|
2461
|
+
async function readChangelogNote(notedir, commitId) {
|
|
2462
|
+
return ChangelogNoteSchema.parse(await readJson(notePath(notedir, commitId)) ?? {});
|
|
2463
|
+
}
|
|
2464
|
+
async function commitMetadata(repoRoot, commitId) {
|
|
2465
|
+
const raw = await git(repoRoot, ["show", "-s", "--format=%H%x00%cs%x00%s", commitId, "--"]);
|
|
2466
|
+
const [sha, date, message] = raw.trimEnd().split("\0");
|
|
2467
|
+
const tags = (await git(repoRoot, ["tag", "--points-at", commitId])).split("\n").filter(Boolean);
|
|
2468
|
+
return { commitId: sha, date, message, tags };
|
|
2469
|
+
}
|
|
2470
|
+
function toChangelogCommit(metadata, note, scope) {
|
|
2471
|
+
return {
|
|
2472
|
+
...metadata,
|
|
2473
|
+
reviewed: note.reviewed ?? false,
|
|
2474
|
+
changelog: note.changelog ?? "",
|
|
2475
|
+
entries: Object.fromEntries(
|
|
2476
|
+
scope.map((key) => [
|
|
2477
|
+
key,
|
|
2478
|
+
note.entries && Object.hasOwn(note.entries, key) ? note.entries[key] : ""
|
|
2479
|
+
])
|
|
2480
|
+
),
|
|
2481
|
+
excludeTags: note.excludeTags ?? []
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
async function commitFiles(repoRoot, commitId) {
|
|
2485
|
+
const parent = await gitOptional(repoRoot, ["rev-parse", "--verify", `${commitId}^1`]);
|
|
2486
|
+
const raw = await git(
|
|
2487
|
+
repoRoot,
|
|
2488
|
+
parent ? ["diff", "--name-status", "-z", "--find-renames", parent, commitId, "--"] : [
|
|
2489
|
+
"diff-tree",
|
|
2490
|
+
"--root",
|
|
2491
|
+
"--no-commit-id",
|
|
2492
|
+
"-r",
|
|
2493
|
+
"--name-status",
|
|
2494
|
+
"-z",
|
|
2495
|
+
"--find-renames",
|
|
2496
|
+
commitId,
|
|
2497
|
+
"--"
|
|
2498
|
+
]
|
|
2499
|
+
);
|
|
2500
|
+
const fields = raw.split("\0");
|
|
2501
|
+
const files = [];
|
|
2502
|
+
for (let i = 0; fields[i]; ) {
|
|
2503
|
+
const code = fields[i++];
|
|
2504
|
+
const first = fields[i++];
|
|
2505
|
+
const renamed = code.startsWith("R") || code.startsWith("C");
|
|
2506
|
+
const file = renamed ? fields[i++] : first;
|
|
2507
|
+
if (!file) throw new Error("\u65E0\u6CD5\u89E3\u6790\u63D0\u4EA4\u6587\u4EF6");
|
|
2508
|
+
files.push({
|
|
2509
|
+
path: file,
|
|
2510
|
+
...renamed ? { oldPath: first } : {},
|
|
2511
|
+
status: code.startsWith("R") ? "renamed" : code.startsWith("C") || code === "A" ? "added" : code === "D" ? "deleted" : "modified"
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
return { parent, files: files.sort((a, b) => a.path.localeCompare(b.path)) };
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
// modules/core/implementations/Functions/listChangelogCommits.ts
|
|
2518
|
+
async function listChangelogCommits(input) {
|
|
2519
|
+
const { repoRoot } = ListChangelogCommitsInputSchema.parse(input);
|
|
2520
|
+
const { change: config } = await loadConfig({ repoRoot });
|
|
2521
|
+
if (!config) return "";
|
|
2522
|
+
const sha = await resolveRef(repoRoot, `refs/heads/${config.branch}`);
|
|
2523
|
+
if (!sha) return "";
|
|
2524
|
+
const [raw, tagOutput] = await Promise.all([
|
|
2525
|
+
git(repoRoot, ["log", "--format=%H%x00%cs%x00%s", sha, "--"]),
|
|
2526
|
+
git(repoRoot, [
|
|
2527
|
+
"for-each-ref",
|
|
2528
|
+
"--format=%(objectname) %(refname:short) %(*objectname)",
|
|
2529
|
+
"refs/tags"
|
|
2530
|
+
])
|
|
2531
|
+
]);
|
|
2532
|
+
const tags = /* @__PURE__ */ new Map();
|
|
2533
|
+
for (const line of tagOutput.split("\n").filter(Boolean)) {
|
|
2534
|
+
const [object, tag, dereferenced] = line.trim().split(" ");
|
|
2535
|
+
const key = dereferenced || object;
|
|
2536
|
+
tags.set(key, [...tags.get(key) ?? [], tag]);
|
|
2537
|
+
}
|
|
2538
|
+
const commits = await mapLimit(raw.trimEnd().split("\n").filter(Boolean), 16, async (line) => {
|
|
2539
|
+
const [commitId, date, message] = line.split("\0");
|
|
2540
|
+
return toChangelogCommit(
|
|
2541
|
+
{ commitId, date, message, tags: tags.get(commitId) ?? [] },
|
|
2542
|
+
await readChangelogNote(path29.resolve(repoRoot, config.notedir), commitId),
|
|
2543
|
+
config.scope
|
|
2544
|
+
);
|
|
2545
|
+
});
|
|
2546
|
+
return { scope: config.scope, commits };
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
// modules/core/implementations/Functions/getChangelogFiles.ts
|
|
2550
|
+
async function getChangelogFiles(input) {
|
|
2551
|
+
const { repoRoot, commitId } = GetChangelogFilesInputSchema.parse(input);
|
|
2552
|
+
await changelogConfig(repoRoot);
|
|
2553
|
+
const { files } = await commitFiles(repoRoot, commitId);
|
|
2554
|
+
return { commitId, files };
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
// modules/core/implementations/Functions/getChangelogDiff.ts
|
|
2558
|
+
async function getChangelogDiff(input) {
|
|
2559
|
+
const { repoRoot, commitId, file } = GetChangelogDiffInputSchema.parse(input);
|
|
2560
|
+
await changelogConfig(repoRoot);
|
|
2561
|
+
const { parent, files } = await commitFiles(repoRoot, commitId);
|
|
2562
|
+
const entry = files.find((item) => item.path === file);
|
|
2563
|
+
if (!entry) throw Object.assign(new Error("\u6B64\u6587\u4EF6\u4E0D\u5728\u63D0\u4EA4\u5DEE\u5F02\u4E2D"), { statusCode: 404 });
|
|
2564
|
+
let tooLarge = false;
|
|
2565
|
+
const readSide = async (ref, name, absent) => {
|
|
2566
|
+
if (!ref || absent) return "";
|
|
2567
|
+
const object = `${ref}:${name}`;
|
|
2568
|
+
const type = (await git(repoRoot, ["cat-file", "-t", object])).trim();
|
|
2569
|
+
if (type === "commit")
|
|
2570
|
+
return `Subproject commit ${(await git(repoRoot, ["rev-parse", object])).trim()}
|
|
2571
|
+
`;
|
|
2572
|
+
if (Number(await git(repoRoot, ["cat-file", "-s", object])) > MAX_BYTES) {
|
|
2573
|
+
tooLarge = true;
|
|
2574
|
+
return "";
|
|
2575
|
+
}
|
|
2576
|
+
return git(repoRoot, ["show", object]);
|
|
2577
|
+
};
|
|
2578
|
+
const [original, modified] = await Promise.all([
|
|
2579
|
+
readSide(parent, entry.oldPath ?? file, entry.status === "added"),
|
|
2580
|
+
readSide(commitId, file, entry.status === "deleted")
|
|
2581
|
+
]);
|
|
2582
|
+
const isBinary = original.includes("\0") || modified.includes("\0");
|
|
2583
|
+
return {
|
|
2584
|
+
...entry,
|
|
2585
|
+
original: isBinary || tooLarge ? "" : original,
|
|
2586
|
+
modified: isBinary || tooLarge ? "" : modified,
|
|
2587
|
+
isBinary,
|
|
2588
|
+
tooLarge
|
|
2589
|
+
};
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
// modules/core/implementations/Functions/updateChangelogNote.ts
|
|
2593
|
+
async function updateChangelogNote(input) {
|
|
2594
|
+
const { repoRoot, commitId, patch } = UpdateChangelogNoteInputSchema.parse(input);
|
|
2595
|
+
const config = await changelogConfig(repoRoot);
|
|
2596
|
+
const metadata = await commitMetadata(repoRoot, commitId);
|
|
2597
|
+
if (patch.changelog !== void 0 && (config.scope.length ? !patch.scope || !config.scope.includes(patch.scope) : !!patch.scope))
|
|
2598
|
+
throw Object.assign(new Error("\u66F4\u65B0\u65E5\u5FD7 scope \u4E0E\u9879\u76EE\u914D\u7F6E\u4E0D\u5339\u914D"), { statusCode: 400 });
|
|
2599
|
+
if (patch.excludeTags?.some((tag) => !metadata.tags.includes(tag)))
|
|
2600
|
+
throw Object.assign(new Error("\u6807\u7B7E\u4E0D\u5C5E\u4E8E\u6B64\u63D0\u4EA4"), { statusCode: 400 });
|
|
2601
|
+
const file = notePath(config.notedir, commitId);
|
|
2602
|
+
const note = await readChangelogNote(config.notedir, commitId);
|
|
2603
|
+
note.reviewed ??= false;
|
|
2604
|
+
if (patch.reviewed !== void 0) note.reviewed = patch.reviewed;
|
|
2605
|
+
if (patch.excludeTags !== void 0) note.excludeTags = [...new Set(patch.excludeTags)];
|
|
2606
|
+
if (config.scope.length) {
|
|
2607
|
+
note.entries = {
|
|
2608
|
+
...Object.fromEntries(config.scope.map((scope) => [scope, ""])),
|
|
2609
|
+
...note.entries
|
|
2610
|
+
};
|
|
2611
|
+
if (patch.changelog !== void 0)
|
|
2612
|
+
note.entries = { ...note.entries, [patch.scope]: patch.changelog };
|
|
2613
|
+
} else {
|
|
2614
|
+
note.changelog ??= "";
|
|
2615
|
+
if (patch.changelog !== void 0) note.changelog = patch.changelog;
|
|
2616
|
+
}
|
|
2617
|
+
await writeJsonAtomic(file, note);
|
|
2618
|
+
return toChangelogCommit(metadata, note, config.scope);
|
|
2358
2619
|
}
|
|
2359
2620
|
|
|
2360
2621
|
// packages/service/src/index.ts
|
|
@@ -2365,16 +2626,16 @@ import { serve } from "@hono/node-server";
|
|
|
2365
2626
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
2366
2627
|
import { Hono } from "hono";
|
|
2367
2628
|
import { existsSync } from "node:fs";
|
|
2368
|
-
import { stat } from "node:fs/promises";
|
|
2369
|
-
import
|
|
2370
|
-
import { z as
|
|
2629
|
+
import { stat as stat2 } from "node:fs/promises";
|
|
2630
|
+
import path30 from "node:path";
|
|
2631
|
+
import { z as z27 } from "zod";
|
|
2371
2632
|
function defaultWebDist() {
|
|
2372
|
-
const fromSource =
|
|
2373
|
-
const fromBundle =
|
|
2374
|
-
return [fromSource, fromBundle].find((directory) => existsSync(
|
|
2633
|
+
const fromSource = path30.resolve(import.meta.dirname, "../../../dist/web");
|
|
2634
|
+
const fromBundle = path30.resolve(import.meta.dirname, "../../dist/web");
|
|
2635
|
+
return [fromSource, fromBundle].find((directory) => existsSync(path30.join(directory, "index.html"))) ?? fromSource;
|
|
2375
2636
|
}
|
|
2376
2637
|
async function startServer(options) {
|
|
2377
|
-
const root =
|
|
2638
|
+
const root = path30.resolve(options.repoRoot);
|
|
2378
2639
|
await loadConfig({ repoRoot: root });
|
|
2379
2640
|
const webDist = options.webDist ?? defaultWebDist();
|
|
2380
2641
|
const app = createApp(root, webDist);
|
|
@@ -2405,7 +2666,7 @@ async function startServer(options) {
|
|
|
2405
2666
|
function createApp(root, webDist) {
|
|
2406
2667
|
const app = new Hono();
|
|
2407
2668
|
app.onError((error, context) => {
|
|
2408
|
-
const status = error instanceof
|
|
2669
|
+
const status = error instanceof z27.ZodError ? 400 : error.statusCode ?? 500;
|
|
2409
2670
|
return context.json({ error: String(error.message ?? error) }, status);
|
|
2410
2671
|
});
|
|
2411
2672
|
app.use("/api/*", async (context, next) => {
|
|
@@ -2416,6 +2677,39 @@ function createApp(root, webDist) {
|
|
|
2416
2677
|
"/api/project",
|
|
2417
2678
|
async (context) => context.json(await readProjectInfo({ repoRoot: root }))
|
|
2418
2679
|
);
|
|
2680
|
+
app.get(
|
|
2681
|
+
"/api/changelog",
|
|
2682
|
+
async (context) => context.json(await listChangelogCommits({ repoRoot: root }))
|
|
2683
|
+
);
|
|
2684
|
+
app.get(
|
|
2685
|
+
"/api/changelog/:commitId/files",
|
|
2686
|
+
async (context) => context.json(
|
|
2687
|
+
await getChangelogFiles({
|
|
2688
|
+
repoRoot: root,
|
|
2689
|
+
commitId: context.req.param("commitId")
|
|
2690
|
+
})
|
|
2691
|
+
)
|
|
2692
|
+
);
|
|
2693
|
+
app.get(
|
|
2694
|
+
"/api/changelog/:commitId/diff",
|
|
2695
|
+
async (context) => context.json(
|
|
2696
|
+
await getChangelogDiff({
|
|
2697
|
+
repoRoot: root,
|
|
2698
|
+
commitId: context.req.param("commitId"),
|
|
2699
|
+
file: context.req.query("path") ?? ""
|
|
2700
|
+
})
|
|
2701
|
+
)
|
|
2702
|
+
);
|
|
2703
|
+
app.patch(
|
|
2704
|
+
"/api/changelog/:commitId",
|
|
2705
|
+
async (context) => context.json(
|
|
2706
|
+
await updateChangelogNote({
|
|
2707
|
+
repoRoot: root,
|
|
2708
|
+
commitId: context.req.param("commitId"),
|
|
2709
|
+
patch: await context.req.json()
|
|
2710
|
+
})
|
|
2711
|
+
)
|
|
2712
|
+
);
|
|
2419
2713
|
app.get(
|
|
2420
2714
|
"/api/code-changes",
|
|
2421
2715
|
async (context) => context.json(await getGitChanges({ repoRoot: root, ref: context.req.query("ref") ?? "HEAD" }))
|
|
@@ -2458,6 +2752,14 @@ function createApp(root, webDist) {
|
|
|
2458
2752
|
"/api/baselines",
|
|
2459
2753
|
async (context) => context.json(await listBaselines({ repoRoot: root }))
|
|
2460
2754
|
);
|
|
2755
|
+
app.get(
|
|
2756
|
+
"/api/tasks/removable",
|
|
2757
|
+
async (context) => context.json(await pruneTasks({ repoRoot: root, dryRun: true }))
|
|
2758
|
+
);
|
|
2759
|
+
app.delete(
|
|
2760
|
+
"/api/tasks/removable",
|
|
2761
|
+
async (context) => context.json(await pruneTasks({ repoRoot: root }))
|
|
2762
|
+
);
|
|
2461
2763
|
app.get("/api/tasks/:taskId", async (context) => {
|
|
2462
2764
|
return context.json(
|
|
2463
2765
|
await readTaskReport({ repoRoot: root, taskId: context.req.param("taskId") })
|
|
@@ -2483,12 +2785,12 @@ function createApp(root, webDist) {
|
|
|
2483
2785
|
await next();
|
|
2484
2786
|
const filePath = context.get("staticFile");
|
|
2485
2787
|
if (!filePath) return;
|
|
2486
|
-
const stats = await
|
|
2788
|
+
const stats = await stat2(filePath);
|
|
2487
2789
|
context.header(
|
|
2488
2790
|
"ETag",
|
|
2489
2791
|
`W/"${stats.size.toString(16)}-${stats.mtimeMs.toString(16)}-${stats.ctimeMs.toString(16)}"`
|
|
2490
2792
|
);
|
|
2491
|
-
const relativePath =
|
|
2793
|
+
const relativePath = path30.relative(webDist, filePath).split(path30.sep).join("/");
|
|
2492
2794
|
const immutable = context.req.path.startsWith("/report-static/") && /(?:^|[-/])[a-f0-9]{64}\.png$/.test(context.req.path) || !context.req.path.startsWith("/report-static/") && /^assets\/.+-[\w-]{8,}\.[\w.]+$/.test(relativePath);
|
|
2493
2795
|
context.header("Cache-Control", immutable ? "public, max-age=31536000, immutable" : "no-cache");
|
|
2494
2796
|
if (context.res.status !== 200 || !["GET", "HEAD"].includes(context.req.method)) return;
|
|
@@ -2528,7 +2830,7 @@ function createApp(root, webDist) {
|
|
|
2528
2830
|
await next();
|
|
2529
2831
|
});
|
|
2530
2832
|
app.get("*", serveStatic({ root: webDist, ...staticOptions }));
|
|
2531
|
-
app.get("*", (context, next) =>
|
|
2833
|
+
app.get("*", (context, next) => path30.extname(context.req.path) ? context.notFound() : next());
|
|
2532
2834
|
app.get("*", serveStatic({ root: webDist, path: "index.html", ...staticOptions }));
|
|
2533
2835
|
app.get("*", (context) => context.text("\u62A5\u544A UI \u5C1A\u672A\u6784\u5EFA\uFF1A\u8BF7\u5148\u8FD0\u884C pnpm build", 404));
|
|
2534
2836
|
return app;
|
|
@@ -2557,47 +2859,108 @@ async function startWorkbench(options) {
|
|
|
2557
2859
|
}
|
|
2558
2860
|
|
|
2559
2861
|
// packages/service/src/init.ts
|
|
2560
|
-
import { mkdir as
|
|
2561
|
-
import
|
|
2862
|
+
import { mkdir as mkdir3, readFile as readFile12, stat as stat3, writeFile as writeFile3 } from "node:fs/promises";
|
|
2863
|
+
import path31 from "node:path";
|
|
2562
2864
|
async function initProject(directory) {
|
|
2563
|
-
const root =
|
|
2564
|
-
await
|
|
2865
|
+
const root = path31.resolve(directory);
|
|
2866
|
+
await mkdir3(root, { recursive: true });
|
|
2565
2867
|
const messages = [];
|
|
2566
2868
|
async function create(file, content) {
|
|
2567
2869
|
try {
|
|
2568
2870
|
await writeFile3(file, content, { flag: "wx" });
|
|
2569
|
-
messages.push(`\u5DF2\u521B\u5EFA ${
|
|
2871
|
+
messages.push(`\u5DF2\u521B\u5EFA ${path31.relative(root, file)}`);
|
|
2570
2872
|
} catch (error) {
|
|
2571
2873
|
if (error.code !== "EEXIST") throw error;
|
|
2572
|
-
messages.push(`\u5DF2\u4FDD\u7559 ${
|
|
2874
|
+
messages.push(`\u5DF2\u4FDD\u7559 ${path31.relative(root, file)}`);
|
|
2573
2875
|
}
|
|
2574
2876
|
}
|
|
2575
|
-
const skill = await
|
|
2576
|
-
|
|
2877
|
+
const skill = await readFile12(
|
|
2878
|
+
path31.resolve(import.meta.dirname, "../../../skills/evidra/SKILL.md"),
|
|
2577
2879
|
"utf8"
|
|
2578
2880
|
);
|
|
2579
2881
|
let injected = false;
|
|
2580
2882
|
for (const agent of [".claude", ".codex"]) {
|
|
2581
2883
|
let exists = false;
|
|
2582
2884
|
try {
|
|
2583
|
-
exists = (await
|
|
2885
|
+
exists = (await stat3(path31.join(root, agent))).isDirectory();
|
|
2584
2886
|
} catch (error) {
|
|
2585
2887
|
if (error.code !== "ENOENT") throw error;
|
|
2586
2888
|
}
|
|
2587
2889
|
if (!exists) continue;
|
|
2588
2890
|
injected = true;
|
|
2589
|
-
const target =
|
|
2590
|
-
await
|
|
2591
|
-
await create(
|
|
2891
|
+
const target = path31.join(root, agent, "skills/evidra");
|
|
2892
|
+
await mkdir3(target, { recursive: true });
|
|
2893
|
+
await create(path31.join(target, "SKILL.md"), skill);
|
|
2592
2894
|
}
|
|
2593
2895
|
if (!injected) messages.push("\u672A\u53D1\u73B0 .claude \u6216 .codex \u6587\u4EF6\u5939\uFF0C\u672A\u6CE8\u5165\u4EFB\u4F55 skill\u3002");
|
|
2594
2896
|
return messages;
|
|
2595
2897
|
}
|
|
2596
2898
|
|
|
2899
|
+
// packages/conformance/runner/cli.ts
|
|
2900
|
+
import { access as access2 } from "node:fs/promises";
|
|
2901
|
+
import path32 from "node:path";
|
|
2902
|
+
import { pathToFileURL } from "node:url";
|
|
2903
|
+
import { tsImport } from "tsx/esm/api";
|
|
2904
|
+
|
|
2905
|
+
// packages/conformance/runner/run.ts
|
|
2906
|
+
async function runner(common, tasks) {
|
|
2907
|
+
const results = [];
|
|
2908
|
+
for (const [index, task] of tasks.entries()) {
|
|
2909
|
+
try {
|
|
2910
|
+
const result = await task(Object.freeze({ ...common }));
|
|
2911
|
+
if (!result || typeof result.name !== "string" || typeof result.success !== "boolean" || typeof result.messages !== "string" || typeof result.howToFix !== "string") {
|
|
2912
|
+
throw new Error("\u4EFB\u52A1\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684 RuleResult");
|
|
2913
|
+
}
|
|
2914
|
+
results.push(result);
|
|
2915
|
+
} catch (error) {
|
|
2916
|
+
results.push({
|
|
2917
|
+
name: `rule[${index + 1}]`,
|
|
2918
|
+
success: false,
|
|
2919
|
+
messages: error instanceof Error ? error.message : String(error),
|
|
2920
|
+
howToFix: "\u4FEE\u590D\u8BE5\u4EFB\u52A1\u7684\u914D\u7F6E\u6216\u6267\u884C\u9519\u8BEF\u540E\u91CD\u65B0\u8FD0\u884C\u3002"
|
|
2921
|
+
});
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
return results;
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// packages/conformance/runner/report.ts
|
|
2928
|
+
function printResults(results) {
|
|
2929
|
+
for (const result of results) {
|
|
2930
|
+
console.log(`== ${result.name} ==`);
|
|
2931
|
+
console.log(result.messages);
|
|
2932
|
+
if (!result.success && result.howToFix) console.log(`\u4FEE\u590D\u5EFA\u8BAE\uFF1A${result.howToFix}`);
|
|
2933
|
+
console.log("");
|
|
2934
|
+
}
|
|
2935
|
+
return results.every((result) => result.success);
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2938
|
+
// packages/conformance/runner/cli.ts
|
|
2939
|
+
async function runConformance(directory) {
|
|
2940
|
+
const file = path32.resolve(directory, "evidra.conformance.ts");
|
|
2941
|
+
await access2(file).catch(() => {
|
|
2942
|
+
throw new Error(`\u65E0\u6CD5\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6\uFF1A${file}`);
|
|
2943
|
+
});
|
|
2944
|
+
let config;
|
|
2945
|
+
try {
|
|
2946
|
+
const loaded = (await tsImport(pathToFileURL(file).href, import.meta.url)).default;
|
|
2947
|
+
config = loaded?.__esModule ? loaded.default : loaded;
|
|
2948
|
+
} catch (error) {
|
|
2949
|
+
throw new Error(
|
|
2950
|
+
`\u52A0\u8F7D\u914D\u7F6E\u5931\u8D25 ${file}\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
2951
|
+
);
|
|
2952
|
+
}
|
|
2953
|
+
if (!config || !Array.isArray(config.rules) || config.rules.some((task) => typeof task !== "function") || config.projectRoot !== void 0 && typeof config.projectRoot !== "string") {
|
|
2954
|
+
throw new Error(`${file} \u5FC5\u987B\u9ED8\u8BA4\u5BFC\u51FA { projectRoot?: string, rules: RuleTask[] }`);
|
|
2955
|
+
}
|
|
2956
|
+
const projectRoot = path32.resolve(path32.dirname(file), config.projectRoot ?? ".");
|
|
2957
|
+
return printResults(await runner({ projectRoot }, config.rules));
|
|
2958
|
+
}
|
|
2959
|
+
|
|
2597
2960
|
// packages/service/src/cli.ts
|
|
2598
2961
|
var cli = cac("evidra");
|
|
2599
2962
|
cli.command("init [path]", "\u590D\u5236 skill \u5230\u9879\u76EE\uFF0C\u9ED8\u8BA4\u5F53\u524D\u76EE\u5F55").action(async (target) => {
|
|
2600
|
-
const root =
|
|
2963
|
+
const root = path33.resolve(target ?? process.cwd());
|
|
2601
2964
|
console.log(`\u521D\u59CB\u5316 Evidra\uFF1A${root}`);
|
|
2602
2965
|
for (const message of await initProject(root)) console.log(message);
|
|
2603
2966
|
});
|
|
@@ -2606,14 +2969,14 @@ cli.command("start", "\u542F\u52A8\u5DE5\u4F5C\u53F0\uFF0C\u670D\u52A1\u5728\u52
|
|
|
2606
2969
|
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
2607
2970
|
throw new Error("\u7AEF\u53E3\u5FC5\u987B\u662F 1\u201365535 \u7684\u6574\u6570");
|
|
2608
2971
|
await startWorkbench({
|
|
2609
|
-
repoRoot:
|
|
2972
|
+
repoRoot: path33.resolve(options.repo ?? process.env.TEST_REPORT_REPO ?? process.cwd()),
|
|
2610
2973
|
port
|
|
2611
2974
|
});
|
|
2612
2975
|
});
|
|
2613
2976
|
cli.command("compare", "\u8C03\u7528 core \u6BD4\u8F83\u4EFB\u52A1\u548C\u57FA\u7EBF\uFF0C\u8F93\u51FA summary").option("--repo <path>", "\u4ED3\u5E93\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u5F53\u524D\u76EE\u5F55").option("--task-id <id>", "\u4EFB\u52A1 ID").option("--full", "\u8F93\u51FA\u5B8C\u6574\u6BD4\u8F83\u7ED3\u679C").action(async (options) => {
|
|
2614
2977
|
if (!options.taskId) throw new Error("\u8BF7\u63D0\u4F9B --task-id");
|
|
2615
2978
|
const result = await compareTask({
|
|
2616
|
-
repoRoot:
|
|
2979
|
+
repoRoot: path33.resolve(options.repo ?? process.cwd()),
|
|
2617
2980
|
taskId: options.taskId
|
|
2618
2981
|
});
|
|
2619
2982
|
console.log(JSON.stringify(options.full ? result : result.summary, null, 2));
|
|
@@ -2623,13 +2986,16 @@ cli.command("compare-tasks", "\u6BD4\u8F83\u4E24\u4E2A\u4EFB\u52A1\u7684\u7528\u
|
|
|
2623
2986
|
if (!options.baseTaskId) throw new Error("\u8BF7\u63D0\u4F9B --base-task-id");
|
|
2624
2987
|
if (!options.taskId) throw new Error("\u8BF7\u63D0\u4F9B --task-id");
|
|
2625
2988
|
const result = await compareTasks({
|
|
2626
|
-
repoRoot:
|
|
2989
|
+
repoRoot: path33.resolve(options.repo ?? process.cwd()),
|
|
2627
2990
|
baseTaskId: options.baseTaskId,
|
|
2628
2991
|
taskId: options.taskId
|
|
2629
2992
|
});
|
|
2630
2993
|
console.log(JSON.stringify(options.full ? result : result.summary, null, 2));
|
|
2631
2994
|
}
|
|
2632
2995
|
);
|
|
2996
|
+
cli.command("conformance", "\u6267\u884C\u5F53\u524D\u76EE\u5F55 evidra.conformance.ts \u4E2D\u7684\u89C4\u7EA6").action(async () => {
|
|
2997
|
+
process.exitCode = await runConformance(process.cwd()) ? 0 : 1;
|
|
2998
|
+
});
|
|
2633
2999
|
cli.help();
|
|
2634
3000
|
try {
|
|
2635
3001
|
cli.parse(process.argv, { run: false });
|