csspilot 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/dist/bin.js +2133 -981
- package/dist/index.js +2133 -981
- package/dist/skills/testpilot/SKILL.md +13 -2
- package/dist/skills/testpilot/manifest.yaml +5 -2
- package/dist/skills/testpilot/rules/dsl.md +50 -12
- package/package.json +2 -8
- /package/dist/skills/testpilot/workflows/{run.md → run-case.md} +0 -0
package/dist/bin.js
CHANGED
|
@@ -10374,10 +10374,84 @@ var {
|
|
|
10374
10374
|
Help
|
|
10375
10375
|
} = import_index.default;
|
|
10376
10376
|
|
|
10377
|
-
// src/commands/
|
|
10378
|
-
import {
|
|
10379
|
-
import {
|
|
10380
|
-
|
|
10377
|
+
// src/commands/init/ci-initializer.ts
|
|
10378
|
+
import { access, mkdir, writeFile } from "node:fs/promises";
|
|
10379
|
+
import { join } from "node:path";
|
|
10380
|
+
async function exists(path) {
|
|
10381
|
+
try {
|
|
10382
|
+
await access(path);
|
|
10383
|
+
return true;
|
|
10384
|
+
} catch {
|
|
10385
|
+
return false;
|
|
10386
|
+
}
|
|
10387
|
+
}
|
|
10388
|
+
async function detectCi(root) {
|
|
10389
|
+
const workflow = join(root, ".github", "workflows", "testpilot.yml");
|
|
10390
|
+
return {
|
|
10391
|
+
githubWorkflows: await exists(join(root, ".github", "workflows")),
|
|
10392
|
+
gitlabCi: await exists(join(root, ".gitlab-ci.yml")),
|
|
10393
|
+
hasTestpilotWorkflow: await exists(workflow)
|
|
10394
|
+
};
|
|
10395
|
+
}
|
|
10396
|
+
var CI_TEMPLATE = `# csspilot ci init \u751F\u6210;Git Push -> TestPilot Server \u7684\u6B63\u5F0F\u540C\u6B65\u8FB9\u754C
|
|
10397
|
+
name: TestPilot
|
|
10398
|
+
|
|
10399
|
+
on:
|
|
10400
|
+
push:
|
|
10401
|
+
branches: [main]
|
|
10402
|
+
|
|
10403
|
+
jobs:
|
|
10404
|
+
testpilot:
|
|
10405
|
+
runs-on: ubuntu-latest
|
|
10406
|
+
env:
|
|
10407
|
+
TESTPILOT_SERVER_URL: \${{ secrets.TESTPILOT_SERVER_URL }}
|
|
10408
|
+
steps:
|
|
10409
|
+
- uses: actions/checkout@v4
|
|
10410
|
+
|
|
10411
|
+
- uses: actions/setup-node@v4
|
|
10412
|
+
with:
|
|
10413
|
+
node-version: 22
|
|
10414
|
+
|
|
10415
|
+
- name: Validate cases
|
|
10416
|
+
run: npx -y csspilot@latest validate
|
|
10417
|
+
|
|
10418
|
+
# sync-metadata \u662F Git Push -> Server \u7684\u6B63\u5F0F\u540C\u6B65\u8FB9\u754C;\u672A\u914D\u7F6E Server \u65F6\u8DF3\u8FC7
|
|
10419
|
+
- name: Sync case metadata
|
|
10420
|
+
if: \${{ env.TESTPILOT_SERVER_URL != '' }}
|
|
10421
|
+
run: npx -y csspilot@latest sync-metadata
|
|
10422
|
+
|
|
10423
|
+
# \u9700\u8981\u5728 CI \u91CC\u8DD1\u7528\u4F8B\u65F6\u518D\u542F\u7528(Server \u89E6\u53D1\u6216\u672C\u5730\u89E6\u53D1\u5747\u53EF)
|
|
10424
|
+
# - name: Run cases
|
|
10425
|
+
# run: npx -y csspilot@latest run
|
|
10426
|
+
`;
|
|
10427
|
+
async function initCi(root) {
|
|
10428
|
+
const file2 = join(root, ".github", "workflows", "testpilot.yml");
|
|
10429
|
+
if (await exists(file2)) {
|
|
10430
|
+
return { created: false, file: file2 };
|
|
10431
|
+
}
|
|
10432
|
+
await mkdir(join(root, ".github", "workflows"), { recursive: true });
|
|
10433
|
+
await writeFile(file2, CI_TEMPLATE, "utf8");
|
|
10434
|
+
return { created: true, file: file2 };
|
|
10435
|
+
}
|
|
10436
|
+
|
|
10437
|
+
// src/commands/ci.ts
|
|
10438
|
+
function makeCiCommand() {
|
|
10439
|
+
const ci = new Command("ci").description("CI \u96C6\u6210(\u751F\u6210\u6A21\u677F,\u4E0D\u4FEE\u6539\u5DF2\u6709 CI)");
|
|
10440
|
+
ci.command("init").description("\u751F\u6210 .github/workflows/testpilot.yml(validate + sync-metadata;\u5DF2\u6709\u5219\u8DF3\u8FC7)").action(async () => {
|
|
10441
|
+
const result = await initCi(process.cwd());
|
|
10442
|
+
if (result.created) {
|
|
10443
|
+
console.log(`\u2713 CI \u5DE5\u4F5C\u6D41\u5DF2\u751F\u6210 ${result.file}`);
|
|
10444
|
+
console.log(" Git Push \u540E\u81EA\u52A8\u6267\u884C csspilot validate \u4E0E sync-metadata(\u9700\u914D\u7F6E TESTPILOT_SERVER_URL Secret)");
|
|
10445
|
+
} else {
|
|
10446
|
+
console.log(`\u2713 CI \u5DE5\u4F5C\u6D41\u5DF2\u5B58\u5728 ${result.file}(\u8DF3\u8FC7)`);
|
|
10447
|
+
}
|
|
10448
|
+
});
|
|
10449
|
+
return ci;
|
|
10450
|
+
}
|
|
10451
|
+
|
|
10452
|
+
// src/commands/init/doctor.ts
|
|
10453
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
10454
|
+
import { join as join21 } from "node:path";
|
|
10381
10455
|
|
|
10382
10456
|
// ../../packages/core/src/errors/index.ts
|
|
10383
10457
|
var TestPilotError = class extends Error {
|
|
@@ -10390,7 +10464,7 @@ var TestPilotError = class extends Error {
|
|
|
10390
10464
|
};
|
|
10391
10465
|
|
|
10392
10466
|
// ../../packages/core/src/constants/index.ts
|
|
10393
|
-
import { join } from "node:path";
|
|
10467
|
+
import { join as join2 } from "node:path";
|
|
10394
10468
|
var TESTPILOT_DIR = ".testpilot";
|
|
10395
10469
|
var RUNS_DIR = `${TESTPILOT_DIR}/artifacts/runs`;
|
|
10396
10470
|
var RESULT_FILE = "result.json";
|
|
@@ -10399,14 +10473,14 @@ var DEFAULT_STEP_TIMEOUT_MS = 15e3;
|
|
|
10399
10473
|
var WECHAT_DEVTOOLS_CLI_PATHS = [
|
|
10400
10474
|
"C:/Program Files (x86)/Tencent/\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177/cli.bat",
|
|
10401
10475
|
"C:/Program Files/Tencent/\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177/cli.bat",
|
|
10402
|
-
|
|
10476
|
+
join2(process.env.LOCALAPPDATA ?? ".", "\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177", "cli.bat"),
|
|
10403
10477
|
"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"
|
|
10404
10478
|
];
|
|
10405
10479
|
|
|
10406
10480
|
// ../../packages/core/src/config-loader.ts
|
|
10407
10481
|
var import_yaml = __toESM(require_dist(), 1);
|
|
10408
10482
|
import { readFile } from "node:fs/promises";
|
|
10409
|
-
import { join as
|
|
10483
|
+
import { join as join3 } from "node:path";
|
|
10410
10484
|
|
|
10411
10485
|
// ../../node_modules/.pnpm/zod@4.6.1/node_modules/zod/v4/classic/external.js
|
|
10412
10486
|
var external_exports = {};
|
|
@@ -15440,7 +15514,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
15440
15514
|
var NONE = 0;
|
|
15441
15515
|
var ASSUMED = 1;
|
|
15442
15516
|
var PROVEN = 2;
|
|
15443
|
-
function isRecursive(inst, stack,
|
|
15517
|
+
function isRecursive(inst, stack, resolve5) {
|
|
15444
15518
|
const cached2 = recursive.get(inst);
|
|
15445
15519
|
if (cached2 !== void 0)
|
|
15446
15520
|
return cached2 ? PROVEN : NONE;
|
|
@@ -15450,7 +15524,7 @@ function isRecursive(inst, stack, resolve3) {
|
|
|
15450
15524
|
let result = NONE;
|
|
15451
15525
|
const check2 = (child) => {
|
|
15452
15526
|
if (result !== PROVEN && child?._zod) {
|
|
15453
|
-
const answer = isRecursive(child, stack,
|
|
15527
|
+
const answer = isRecursive(child, stack, resolve5);
|
|
15454
15528
|
if (answer > result)
|
|
15455
15529
|
result = answer;
|
|
15456
15530
|
}
|
|
@@ -15461,7 +15535,7 @@ function isRecursive(inst, stack, resolve3) {
|
|
|
15461
15535
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
15462
15536
|
if (spread && !desc.enumerable)
|
|
15463
15537
|
continue;
|
|
15464
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
15538
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
|
|
15465
15539
|
if (child > answer)
|
|
15466
15540
|
answer = child;
|
|
15467
15541
|
}
|
|
@@ -15528,7 +15602,7 @@ function isRecursive(inst, stack, resolve3) {
|
|
|
15528
15602
|
break;
|
|
15529
15603
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
15530
15604
|
case "lazy": {
|
|
15531
|
-
const inner = def._cachedInner ?? (
|
|
15605
|
+
const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
|
|
15532
15606
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
15533
15607
|
break;
|
|
15534
15608
|
}
|
|
@@ -30081,16 +30155,37 @@ function date4(params) {
|
|
|
30081
30155
|
}
|
|
30082
30156
|
|
|
30083
30157
|
// ../../packages/core/src/config-loader.ts
|
|
30158
|
+
var environmentEntrySchema = external_exports.strictObject({ baseUrl: external_exports.string().min(1).optional() }).optional();
|
|
30084
30159
|
var configSchema = external_exports.strictObject({
|
|
30160
|
+
/** 配置文件版本(csspilot init 生成为 1) */
|
|
30161
|
+
version: external_exports.number().optional(),
|
|
30162
|
+
/** 旧式用例目录字段;与 test.caseDirectory 等价,二选一 */
|
|
30085
30163
|
casesDir: external_exports.string().min(1).optional(),
|
|
30164
|
+
project: external_exports.strictObject({ name: external_exports.string().min(1).optional() }).optional(),
|
|
30165
|
+
test: external_exports.strictObject({
|
|
30166
|
+
directory: external_exports.string().min(1).optional(),
|
|
30167
|
+
caseDirectory: external_exports.string().min(1).optional()
|
|
30168
|
+
}).optional(),
|
|
30169
|
+
/** 环境配置:default 指定默认环境名,其余键为环境名 -> { baseUrl } */
|
|
30170
|
+
environment: external_exports.record(external_exports.string(), external_exports.union([external_exports.string().min(1), environmentEntrySchema])).optional(),
|
|
30171
|
+
/** 项目声明的执行端(playwright / wechatide);仅作声明,实际可用性以 doctor 检测为准 */
|
|
30172
|
+
adapters: external_exports.array(external_exports.string().min(1)).optional(),
|
|
30173
|
+
workspace: external_exports.strictObject({ default: external_exports.string().min(1).optional() }).optional(),
|
|
30174
|
+
/** TestPilot Control Plane 地址(sync-metadata / init 关联项目时使用) */
|
|
30175
|
+
server: external_exports.strictObject({ baseUrl: external_exports.string().min(1).optional() }).optional(),
|
|
30086
30176
|
web: external_exports.strictObject({ baseUrl: external_exports.string().min(1).optional() }).optional(),
|
|
30177
|
+
/** API 执行端(target: api):相对 url 的基准地址与超时 */
|
|
30178
|
+
api: external_exports.strictObject({
|
|
30179
|
+
baseUrl: external_exports.string().min(1).optional(),
|
|
30180
|
+
timeoutMs: external_exports.number().int().positive().optional()
|
|
30181
|
+
}).optional(),
|
|
30087
30182
|
miniapp: external_exports.strictObject({
|
|
30088
30183
|
projectPath: external_exports.string().min(1).optional(),
|
|
30089
30184
|
cliPath: external_exports.string().min(1).optional()
|
|
30090
30185
|
}).optional()
|
|
30091
30186
|
});
|
|
30092
30187
|
async function loadTestpilotConfig(cwd = process.cwd()) {
|
|
30093
|
-
const file2 =
|
|
30188
|
+
const file2 = join3(cwd, "testpilot.yaml");
|
|
30094
30189
|
let raw;
|
|
30095
30190
|
try {
|
|
30096
30191
|
raw = (0, import_yaml.parse)(await readFile(file2, "utf8"));
|
|
@@ -30106,8 +30201,17 @@ async function loadTestpilotConfig(cwd = process.cwd()) {
|
|
|
30106
30201
|
throw new Error(`testpilot.yaml \u914D\u7F6E\u4E0D\u5408\u6CD5:${detail}`);
|
|
30107
30202
|
}
|
|
30108
30203
|
return {
|
|
30109
|
-
|
|
30204
|
+
version: result.data.version,
|
|
30205
|
+
// 用例目录:旧字段 casesDir 优先,其次 test.caseDirectory,最后默认值
|
|
30206
|
+
casesDir: result.data.casesDir ?? result.data.test?.caseDirectory ?? DEFAULT_CASES_DIR,
|
|
30207
|
+
testDirectory: result.data.test?.directory,
|
|
30208
|
+
projectName: result.data.project?.name,
|
|
30209
|
+
environment: result.data.environment,
|
|
30210
|
+
adapters: result.data.adapters,
|
|
30211
|
+
workspace: result.data.workspace,
|
|
30212
|
+
server: result.data.server,
|
|
30110
30213
|
web: result.data.web,
|
|
30214
|
+
api: result.data.api,
|
|
30111
30215
|
miniapp: result.data.miniapp
|
|
30112
30216
|
};
|
|
30113
30217
|
}
|
|
@@ -30115,7 +30219,7 @@ async function loadTestpilotConfig(cwd = process.cwd()) {
|
|
|
30115
30219
|
// ../../packages/core/src/wechat-devtools.ts
|
|
30116
30220
|
import { execFile } from "node:child_process";
|
|
30117
30221
|
import { existsSync, readdirSync } from "node:fs";
|
|
30118
|
-
import { join as
|
|
30222
|
+
import { join as join4 } from "node:path";
|
|
30119
30223
|
var CLI_NAMES = ["cli.bat", "cli"];
|
|
30120
30224
|
var REGISTRY_UNINSTALL_KEYS = [
|
|
30121
30225
|
"HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
|
|
@@ -30131,7 +30235,7 @@ async function findWechatDevToolsCli() {
|
|
|
30131
30235
|
if (process.platform !== "win32") return void 0;
|
|
30132
30236
|
for (const dir of candidateInstallDirs()) {
|
|
30133
30237
|
for (const name of CLI_NAMES) {
|
|
30134
|
-
const cli =
|
|
30238
|
+
const cli = join4(dir, name);
|
|
30135
30239
|
if (existsSync(cli)) return cli;
|
|
30136
30240
|
}
|
|
30137
30241
|
}
|
|
@@ -30144,19 +30248,19 @@ function candidateInstallDirs() {
|
|
|
30144
30248
|
const drive = `${String.fromCharCode(code)}:\\`;
|
|
30145
30249
|
if (!existsSync(drive)) continue;
|
|
30146
30250
|
tencentParents.push(
|
|
30147
|
-
|
|
30148
|
-
|
|
30251
|
+
join4(drive, "Program Files (x86)", "Tencent"),
|
|
30252
|
+
join4(drive, "Program Files", "Tencent")
|
|
30149
30253
|
);
|
|
30150
30254
|
}
|
|
30151
30255
|
if (process.env.LOCALAPPDATA) {
|
|
30152
|
-
tencentParents.push(
|
|
30256
|
+
tencentParents.push(join4(process.env.LOCALAPPDATA, "Programs"));
|
|
30153
30257
|
}
|
|
30154
30258
|
for (const parent of tencentParents) {
|
|
30155
30259
|
if (!existsSync(parent)) continue;
|
|
30156
30260
|
try {
|
|
30157
30261
|
for (const entry of readdirSync(parent)) {
|
|
30158
30262
|
if (/微信web开发者工具|wechatwebdevtools/i.test(entry)) {
|
|
30159
|
-
dirs.push(
|
|
30263
|
+
dirs.push(join4(parent, entry));
|
|
30160
30264
|
}
|
|
30161
30265
|
}
|
|
30162
30266
|
} catch {
|
|
@@ -30179,7 +30283,7 @@ async function findFromRegistry() {
|
|
|
30179
30283
|
const installDir = dirBefore(raw, /微信开发者工具\.exe|卸载微信开发者工具\.exe/i);
|
|
30180
30284
|
if (!installDir) continue;
|
|
30181
30285
|
for (const name of CLI_NAMES) {
|
|
30182
|
-
const cli =
|
|
30286
|
+
const cli = join4(installDir, name);
|
|
30183
30287
|
if (existsSync(cli)) return cli;
|
|
30184
30288
|
}
|
|
30185
30289
|
}
|
|
@@ -30202,188 +30306,16 @@ function execToString(command, args) {
|
|
|
30202
30306
|
});
|
|
30203
30307
|
}
|
|
30204
30308
|
|
|
30205
|
-
// src/
|
|
30206
|
-
import {
|
|
30207
|
-
import { extname, join as join4 } from "node:path";
|
|
30208
|
-
var DEFAULT_CASES_DIR2 = "tests/e2e/cases";
|
|
30209
|
-
async function collectCaseFiles(paths) {
|
|
30210
|
-
const files = [];
|
|
30211
|
-
for (const input2 of paths) {
|
|
30212
|
-
const info = await stat(input2).catch(() => void 0);
|
|
30213
|
-
if (!info) continue;
|
|
30214
|
-
if (info.isDirectory()) {
|
|
30215
|
-
files.push(...await collectFromDir(input2));
|
|
30216
|
-
} else if (isCaseFile(input2)) {
|
|
30217
|
-
files.push(input2);
|
|
30218
|
-
}
|
|
30219
|
-
}
|
|
30220
|
-
return [...new Set(files)].sort();
|
|
30221
|
-
}
|
|
30222
|
-
async function collectFromDir(dir) {
|
|
30223
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
30224
|
-
const found = [];
|
|
30225
|
-
for (const entry of entries) {
|
|
30226
|
-
const full = join4(dir, entry.name);
|
|
30227
|
-
if (entry.isDirectory()) {
|
|
30228
|
-
found.push(...await collectFromDir(full));
|
|
30229
|
-
} else if (isCaseFile(entry.name)) {
|
|
30230
|
-
found.push(full);
|
|
30231
|
-
}
|
|
30232
|
-
}
|
|
30233
|
-
return found;
|
|
30234
|
-
}
|
|
30235
|
-
function isCaseFile(file2) {
|
|
30236
|
-
const ext = extname(file2).toLowerCase();
|
|
30237
|
-
return ext === ".yaml" || ext === ".yml";
|
|
30238
|
-
}
|
|
30239
|
-
|
|
30240
|
-
// src/commands/doctor.ts
|
|
30241
|
-
function makeDoctorCommand() {
|
|
30242
|
-
return new Command("doctor").description("\u68C0\u67E5\u672C\u5730\u73AF\u5883(Node / Playwright / WeChat DevTools / \u9879\u76EE\u914D\u7F6E)").action(async () => {
|
|
30243
|
-
let problems = 0;
|
|
30244
|
-
const ok = (label) => console.log(`\u2713 ${label}`);
|
|
30245
|
-
const fail = (label, hint) => {
|
|
30246
|
-
problems++;
|
|
30247
|
-
console.log(`\u2717 ${label}${hint ? `(${hint})` : ""}`);
|
|
30248
|
-
};
|
|
30249
|
-
console.log("TestPilot Doctor");
|
|
30250
|
-
console.log("");
|
|
30251
|
-
const nodeMajor = Number(process.versions.node.split(".")[0]);
|
|
30252
|
-
if (nodeMajor >= 22) ok(`Node.js ${process.versions.node}`);
|
|
30253
|
-
else fail(`Node.js ${process.versions.node}`, "\u9700\u8981 Node.js >= 22");
|
|
30254
|
-
ok("TestPilot CLI (0.1.0)");
|
|
30255
|
-
if (existsSync2("testpilot.yaml")) ok("testpilot.yaml");
|
|
30256
|
-
else fail("testpilot.yaml", "\u8FD0\u884C npx csspilot init \u751F\u6210");
|
|
30257
|
-
const caseFiles = await collectCaseFiles([DEFAULT_CASES_DIR2]).catch(() => []);
|
|
30258
|
-
if (caseFiles.length > 0) ok(`${DEFAULT_CASES_DIR2} (${caseFiles.length} \u4E2A\u7528\u4F8B)`);
|
|
30259
|
-
else fail(DEFAULT_CASES_DIR2, "\u672A\u627E\u5230\u7528\u4F8B");
|
|
30260
|
-
if (existsSync2(".ai/skills/testpilot/manifest.yaml")) ok("TestPilot Skill (.ai/skills/testpilot)");
|
|
30261
|
-
else fail("TestPilot Skill", "\u8FD0\u884C npx csspilot init \u5B89\u88C5");
|
|
30262
|
-
console.log("");
|
|
30263
|
-
console.log("Web");
|
|
30264
|
-
const playwright = resolvePlaywright();
|
|
30265
|
-
if (!playwright) {
|
|
30266
|
-
fail("Playwright", "pnpm add -D playwright \u6216 @playwright/test");
|
|
30267
|
-
fail("Chromium");
|
|
30268
|
-
} else {
|
|
30269
|
-
ok(`Playwright (${playwright.version})`);
|
|
30270
|
-
if (chromiumInstalled(playwright.module)) ok("Chromium");
|
|
30271
|
-
else fail("Chromium", "pnpm exec playwright install chromium");
|
|
30272
|
-
}
|
|
30273
|
-
console.log("");
|
|
30274
|
-
console.log("Mini Program");
|
|
30275
|
-
const devtools = await findWechatDevToolsCli();
|
|
30276
|
-
if (devtools) ok(`WeChat Developer Tools (${devtools})`);
|
|
30277
|
-
else fail("WeChat Developer Tools", "\u672A\u627E\u5230,\u53EF\u8BBE\u7F6E WECHAT_DEVTOOLS_CLI \u6307\u5411 cli \u53EF\u6267\u884C\u6587\u4EF6");
|
|
30278
|
-
console.log("");
|
|
30279
|
-
console.log(problems === 0 ? "Environment looks good." : `\u53D1\u73B0 ${problems} \u4E2A\u95EE\u9898,\u89C1\u4E0A\u8868\u3002`);
|
|
30280
|
-
});
|
|
30281
|
-
}
|
|
30282
|
-
function resolvePlaywright() {
|
|
30283
|
-
const require2 = createRequire(join5(process.cwd(), "package.json"));
|
|
30284
|
-
for (const name of ["playwright", "@playwright/test"]) {
|
|
30285
|
-
try {
|
|
30286
|
-
const module = require2(name);
|
|
30287
|
-
const version2 = require2(`${name}/package.json`).version;
|
|
30288
|
-
return { module, version: version2 };
|
|
30289
|
-
} catch {
|
|
30290
|
-
continue;
|
|
30291
|
-
}
|
|
30292
|
-
}
|
|
30293
|
-
return void 0;
|
|
30294
|
-
}
|
|
30295
|
-
function chromiumInstalled(module) {
|
|
30296
|
-
try {
|
|
30297
|
-
const path = module.chromium.executablePath();
|
|
30298
|
-
return path !== "" && existsSync2(path);
|
|
30299
|
-
} catch {
|
|
30300
|
-
return false;
|
|
30301
|
-
}
|
|
30302
|
-
}
|
|
30303
|
-
|
|
30304
|
-
// src/commands/init.ts
|
|
30305
|
-
import { existsSync as existsSync3 } from "node:fs";
|
|
30306
|
-
import { access, cp, mkdir, writeFile } from "node:fs/promises";
|
|
30307
|
-
import { dirname, join as join6 } from "node:path";
|
|
30308
|
-
import { fileURLToPath } from "node:url";
|
|
30309
|
-
var TESTPILOT_YAML_TEMPLATE = `# TestPilot \u9879\u76EE\u914D\u7F6E
|
|
30310
|
-
# validate / list / run \u9ED8\u8BA4\u5728\u8FD9\u4E2A\u76EE\u5F55\u67E5\u627E *.yaml \u7528\u4F8B
|
|
30311
|
-
casesDir: tests/e2e/cases
|
|
30312
|
-
|
|
30313
|
-
# Web \u7AEF:navigate \u76F8\u5BF9 url \u7684\u57FA\u51C6\u5730\u5740
|
|
30314
|
-
# web:
|
|
30315
|
-
# baseUrl: http://127.0.0.1:8080
|
|
30316
|
-
|
|
30317
|
-
# \u5C0F\u7A0B\u5E8F\u7AEF:\u586B\u5165\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55\u540E\u5373\u53EF\u6267\u884C target: miniapp \u7684\u6B65\u9AA4
|
|
30318
|
-
# miniapp:
|
|
30319
|
-
# projectPath: path/to/miniprogram
|
|
30320
|
-
# cliPath: C:/Program Files (x86)/Tencent/\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177/cli.bat
|
|
30321
|
-
`;
|
|
30322
|
-
async function exists(path) {
|
|
30323
|
-
try {
|
|
30324
|
-
await access(path);
|
|
30325
|
-
return true;
|
|
30326
|
-
} catch {
|
|
30327
|
-
return false;
|
|
30328
|
-
}
|
|
30329
|
-
}
|
|
30330
|
-
function resolveSkillSourceDir() {
|
|
30331
|
-
const fromEnv = process.env.TESTPILOT_SKILL_DIR;
|
|
30332
|
-
if (fromEnv) return fromEnv;
|
|
30333
|
-
const bundled = fileURLToPath(new URL("./skills/testpilot", import.meta.url));
|
|
30334
|
-
if (existsSync3(bundled)) return bundled;
|
|
30335
|
-
const inRepo = fileURLToPath(new URL("../../../../skills/testpilot", import.meta.url));
|
|
30336
|
-
return existsSync3(inRepo) ? inRepo : void 0;
|
|
30337
|
-
}
|
|
30338
|
-
function makeInitCommand() {
|
|
30339
|
-
return new Command("init").description("\u628A TestPilot \u63A5\u5165\u5F53\u524D\u4E1A\u52A1\u9879\u76EE").action(async () => {
|
|
30340
|
-
const cwd = process.cwd();
|
|
30341
|
-
const skillDest = join6(cwd, ".ai", "skills", "testpilot");
|
|
30342
|
-
if (await exists(join6(skillDest, "manifest.yaml"))) {
|
|
30343
|
-
console.log("\u2713 Skill \u5B89\u88C5 .ai/skills/testpilot/(\u5DF2\u5B58\u5728,\u8DF3\u8FC7)");
|
|
30344
|
-
} else {
|
|
30345
|
-
const skillSrc = resolveSkillSourceDir();
|
|
30346
|
-
if (!skillSrc) {
|
|
30347
|
-
console.error("\u2717 \u65E0\u6CD5\u5B9A\u4F4D TestPilot Skill \u6E90\u76EE\u5F55");
|
|
30348
|
-
console.error(" \u53EF\u901A\u8FC7\u73AF\u5883\u53D8\u91CF TESTPILOT_SKILL_DIR \u6307\u5B9A skills/testpilot \u8DEF\u5F84\u540E\u91CD\u8BD5");
|
|
30349
|
-
process.exitCode = 1;
|
|
30350
|
-
return;
|
|
30351
|
-
}
|
|
30352
|
-
await mkdir(dirname(skillDest), { recursive: true });
|
|
30353
|
-
await cp(skillSrc, skillDest, { recursive: true });
|
|
30354
|
-
console.log("\u2713 Skill \u5B89\u88C5 .ai/skills/testpilot/");
|
|
30355
|
-
}
|
|
30356
|
-
await mkdir(join6(cwd, ".testpilot", "artifacts"), { recursive: true });
|
|
30357
|
-
const keep = join6(cwd, ".testpilot", "artifacts", ".gitkeep");
|
|
30358
|
-
if (!await exists(keep)) {
|
|
30359
|
-
await writeFile(keep, "", "utf8");
|
|
30360
|
-
}
|
|
30361
|
-
console.log("\u2713 Runtime \u76EE\u5F55 .testpilot/");
|
|
30362
|
-
for (const dir of ["tests/e2e/cases", "tests/e2e/fixtures", "tests/e2e/data"]) {
|
|
30363
|
-
await mkdir(join6(cwd, dir), { recursive: true });
|
|
30364
|
-
}
|
|
30365
|
-
console.log("\u2713 \u6D4B\u8BD5\u76EE\u5F55 tests/e2e/{cases,fixtures,data}");
|
|
30366
|
-
const configPath = join6(cwd, "testpilot.yaml");
|
|
30367
|
-
if (await exists(configPath)) {
|
|
30368
|
-
console.log("\u2713 \u9879\u76EE\u914D\u7F6E testpilot.yaml(\u5DF2\u5B58\u5728,\u8DF3\u8FC7)");
|
|
30369
|
-
} else {
|
|
30370
|
-
await writeFile(configPath, TESTPILOT_YAML_TEMPLATE, "utf8");
|
|
30371
|
-
console.log("\u2713 \u9879\u76EE\u914D\u7F6E testpilot.yaml");
|
|
30372
|
-
}
|
|
30373
|
-
console.log("");
|
|
30374
|
-
console.log("\u4E0B\u4E00\u6B65:");
|
|
30375
|
-
console.log(" 1. \u8BA9 AI \u9605\u8BFB .ai/skills/testpilot/SKILL.md");
|
|
30376
|
-
console.log(" 2. \u5728 tests/e2e/cases/ \u521B\u5EFA Case(\u9075\u5FAA SKILL.md \u4E0E rules/)");
|
|
30377
|
-
console.log(" 3. npx csspilot validate");
|
|
30378
|
-
console.log(" 4. npx csspilot run");
|
|
30379
|
-
});
|
|
30380
|
-
}
|
|
30309
|
+
// ../../packages/sdk/src/client.ts
|
|
30310
|
+
import { isAbsolute as isAbsolute3, join as join17 } from "node:path";
|
|
30381
30311
|
|
|
30382
|
-
// src/
|
|
30383
|
-
import { readFile as
|
|
30312
|
+
// ../../packages/sdk/src/cases.ts
|
|
30313
|
+
import { mkdir as mkdir3, readFile as readFile3, readdir, stat as stat2, writeFile as writeFile3 } from "node:fs/promises";
|
|
30314
|
+
import { dirname, extname, isAbsolute, join as join6, resolve as resolve2 } from "node:path";
|
|
30384
30315
|
|
|
30385
30316
|
// ../../packages/dsl/src/schema/index.ts
|
|
30386
|
-
var STEP_TARGETS = ["web", "miniapp"];
|
|
30317
|
+
var STEP_TARGETS = ["web", "miniapp", "api"];
|
|
30318
|
+
var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"];
|
|
30387
30319
|
var ACTIONS = [
|
|
30388
30320
|
"launch",
|
|
30389
30321
|
"navigate",
|
|
@@ -30393,7 +30325,8 @@ var ACTIONS = [
|
|
|
30393
30325
|
"wait",
|
|
30394
30326
|
"assert",
|
|
30395
30327
|
"extract",
|
|
30396
|
-
"screenshot"
|
|
30328
|
+
"screenshot",
|
|
30329
|
+
"request"
|
|
30397
30330
|
];
|
|
30398
30331
|
var locatorSchema = external_exports.strictObject({
|
|
30399
30332
|
text: external_exports.string().min(1).optional(),
|
|
@@ -30406,6 +30339,12 @@ var stepSchema = external_exports.strictObject({
|
|
|
30406
30339
|
url: external_exports.string().min(1).optional(),
|
|
30407
30340
|
value: external_exports.string().optional(),
|
|
30408
30341
|
expected: external_exports.string().optional(),
|
|
30342
|
+
/** api target:request 的 HTTP 方法(默认 GET) */
|
|
30343
|
+
method: external_exports.enum(HTTP_METHODS).optional(),
|
|
30344
|
+
/** api target:request 的请求头(值支持 ${var} 模板) */
|
|
30345
|
+
headers: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
30346
|
+
/** api target:请求体;对象按 JSON 序列化,字符串原样发送(支持 ${var} 模板) */
|
|
30347
|
+
body: external_exports.union([external_exports.string(), external_exports.record(external_exports.string(), external_exports.unknown())]).optional(),
|
|
30409
30348
|
variable: external_exports.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/, "\u53D8\u91CF\u540D\u9700\u4EE5\u5B57\u6BCD\u6216\u4E0B\u5212\u7EBF\u5F00\u5934,\u4EC5\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF").optional(),
|
|
30410
30349
|
timeout: external_exports.number().int().positive().optional()
|
|
30411
30350
|
});
|
|
@@ -30413,6 +30352,12 @@ var caseSchema = external_exports.strictObject({
|
|
|
30413
30352
|
id: external_exports.string().regex(/^[a-z0-9][a-z0-9-]*$/, "id \u9700\u4E3A kebab-case(\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u8FDE\u5B57\u7B26)"),
|
|
30414
30353
|
name: external_exports.string().min(1, "name \u4E0D\u80FD\u4E3A\u7A7A"),
|
|
30415
30354
|
description: external_exports.string().optional(),
|
|
30355
|
+
/** 引用 Test Workspace(多系统环境组合);Case 只表达测试意图,环境由 Workspace 提供 */
|
|
30356
|
+
workspace: external_exports.string().min(1).optional(),
|
|
30357
|
+
/** 引用项目环境(testpilot.yaml environment 段);Case 不写死地址 */
|
|
30358
|
+
environment: external_exports.string().min(1).optional(),
|
|
30359
|
+
/** 引用测试账号标识;凭据由 Environment + Server/CI Secret 管理,禁止写进 Case */
|
|
30360
|
+
accountRef: external_exports.string().min(1).optional(),
|
|
30416
30361
|
tags: external_exports.array(external_exports.string().min(1)).optional(),
|
|
30417
30362
|
steps: external_exports.array(stepSchema).min(1, "Case \u81F3\u5C11\u5305\u542B\u4E00\u4E2A step")
|
|
30418
30363
|
});
|
|
@@ -30458,23 +30403,30 @@ var ADAPTER_SUPPORT = {
|
|
|
30458
30403
|
input: ["web", "miniapp"],
|
|
30459
30404
|
select: ["web"],
|
|
30460
30405
|
wait: ["web", "miniapp"],
|
|
30461
|
-
assert: ["web", "miniapp"],
|
|
30462
|
-
extract: ["web", "miniapp"],
|
|
30463
|
-
screenshot: ["web", "miniapp"]
|
|
30406
|
+
assert: ["web", "miniapp", "api"],
|
|
30407
|
+
extract: ["web", "miniapp", "api"],
|
|
30408
|
+
screenshot: ["web", "miniapp"],
|
|
30409
|
+
request: ["api"]
|
|
30464
30410
|
};
|
|
30465
30411
|
var LOCATOR_REQUIRED = /* @__PURE__ */ new Set(["click", "input", "select", "assert", "extract"]);
|
|
30466
30412
|
var VALUE_REQUIRED = /* @__PURE__ */ new Set(["input", "select"]);
|
|
30467
30413
|
var FIELD_ALLOWED = {
|
|
30468
|
-
url: ["navigate"],
|
|
30469
|
-
value: ["input", "select"],
|
|
30470
|
-
expected: ["assert"],
|
|
30414
|
+
url: ["navigate", "request"],
|
|
30415
|
+
value: ["input", "select", "extract"],
|
|
30416
|
+
expected: ["assert", "request"],
|
|
30471
30417
|
variable: ["extract"],
|
|
30472
|
-
timeout: ["wait"]
|
|
30418
|
+
timeout: ["wait"],
|
|
30419
|
+
method: ["request"],
|
|
30420
|
+
headers: ["request"],
|
|
30421
|
+
body: ["request"]
|
|
30473
30422
|
};
|
|
30474
|
-
var VARIABLE_REF = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
30423
|
+
var VARIABLE_REF = /\$\{([A-Za-z_][A-Za-z0-9_.]*)\}/g;
|
|
30475
30424
|
function validateCase(data) {
|
|
30476
30425
|
const issues = [];
|
|
30477
30426
|
const declared = /* @__PURE__ */ new Set();
|
|
30427
|
+
if (data.accountRef) {
|
|
30428
|
+
declared.add("account");
|
|
30429
|
+
}
|
|
30478
30430
|
data.steps.forEach((step, index) => {
|
|
30479
30431
|
checkStep(step, `steps[${index}]`, declared, issues);
|
|
30480
30432
|
});
|
|
@@ -30497,7 +30449,13 @@ function checkStep(step, at, declared, issues) {
|
|
|
30497
30449
|
message: `action "${step.action}" \u4E0D\u652F\u6301 target "${step.target}"(\u652F\u6301:${supported.join(" / ")})`
|
|
30498
30450
|
});
|
|
30499
30451
|
}
|
|
30500
|
-
|
|
30452
|
+
if (step.target === "api") {
|
|
30453
|
+
if (step.locator) {
|
|
30454
|
+
issues.push({ path: `${at}.locator`, code: "semantic", message: "api \u7AEF\u4E0D\u652F\u6301 locator,\u65AD\u8A00\u7528 expected,\u63D0\u53D6\u7528 value(JSON path)" });
|
|
30455
|
+
}
|
|
30456
|
+
} else {
|
|
30457
|
+
checkLocator(step, at, issues);
|
|
30458
|
+
}
|
|
30501
30459
|
if (step.target === "miniapp" && step.locator?.text !== void 0) {
|
|
30502
30460
|
issues.push({
|
|
30503
30461
|
path: `${at}.locator.text`,
|
|
@@ -30518,9 +30476,15 @@ function checkStep(step, at, declared, issues) {
|
|
|
30518
30476
|
if (step.action === "navigate" && !step.url) {
|
|
30519
30477
|
issues.push({ path: `${at}.url`, code: "semantic", message: "navigate \u5FC5\u987B\u63D0\u4F9B url" });
|
|
30520
30478
|
}
|
|
30479
|
+
if (step.action === "request" && !step.url) {
|
|
30480
|
+
issues.push({ path: `${at}.url`, code: "semantic", message: "request \u5FC5\u987B\u63D0\u4F9B url(\u76F8\u5BF9\u8DEF\u5F84\u6309 api.baseUrl \u89E3\u6790)" });
|
|
30481
|
+
}
|
|
30521
30482
|
if (VALUE_REQUIRED.has(step.action) && !step.value) {
|
|
30522
30483
|
issues.push({ path: `${at}.value`, code: "semantic", message: `action "${step.action}" \u5FC5\u987B\u63D0\u4F9B value` });
|
|
30523
30484
|
}
|
|
30485
|
+
if (step.action === "extract" && step.target === "api" && !step.value) {
|
|
30486
|
+
issues.push({ path: `${at}.value`, code: "semantic", message: "api \u7AEF extract \u5FC5\u987B\u63D0\u4F9B value(\u70B9\u53F7 JSON path,\u5982 data.orderId)" });
|
|
30487
|
+
}
|
|
30524
30488
|
if (step.action === "assert" && !step.expected) {
|
|
30525
30489
|
issues.push({ path: `${at}.expected`, code: "semantic", message: "assert \u5FC5\u987B\u63D0\u4F9B expected" });
|
|
30526
30490
|
}
|
|
@@ -30562,77 +30526,167 @@ function checkLocator(step, at, issues) {
|
|
|
30562
30526
|
}
|
|
30563
30527
|
}
|
|
30564
30528
|
function checkVariableRefs(step, at, declared, issues) {
|
|
30565
|
-
|
|
30566
|
-
|
|
30567
|
-
if (!raw)
|
|
30529
|
+
const refs = [];
|
|
30530
|
+
const collect = (field, raw) => {
|
|
30531
|
+
if (!raw) return;
|
|
30568
30532
|
for (const match of raw.matchAll(VARIABLE_REF)) {
|
|
30569
|
-
|
|
30570
|
-
|
|
30571
|
-
|
|
30572
|
-
|
|
30573
|
-
|
|
30574
|
-
|
|
30575
|
-
|
|
30576
|
-
|
|
30533
|
+
if (match[1]) refs.push([field, match[1]]);
|
|
30534
|
+
}
|
|
30535
|
+
};
|
|
30536
|
+
collect("value", step.value);
|
|
30537
|
+
collect("expected", step.expected);
|
|
30538
|
+
collect("url", step.url);
|
|
30539
|
+
if (typeof step.body === "string") collect("body", step.body);
|
|
30540
|
+
else if (step.body) collect("body", JSON.stringify(step.body));
|
|
30541
|
+
for (const headerValue of Object.values(step.headers ?? {})) collect("headers", headerValue);
|
|
30542
|
+
for (const [field, name] of refs) {
|
|
30543
|
+
const root = name.split(".")[0] ?? name;
|
|
30544
|
+
if (!declared.has(root)) {
|
|
30545
|
+
issues.push({
|
|
30546
|
+
path: `${at}.${field}`,
|
|
30547
|
+
code: "semantic",
|
|
30548
|
+
message: `\u5F15\u7528\u4E86\u672A\u5B9A\u4E49\u53D8\u91CF "\${${name}}":\u5148\u901A\u8FC7 extract \u63D0\u53D6,\u6216 Case \u58F0\u660E accountRef \u540E\u4F7F\u7528 \${account.*}`
|
|
30549
|
+
});
|
|
30577
30550
|
}
|
|
30578
30551
|
}
|
|
30579
30552
|
}
|
|
30580
30553
|
|
|
30581
|
-
// src/
|
|
30582
|
-
|
|
30583
|
-
|
|
30584
|
-
|
|
30585
|
-
|
|
30586
|
-
|
|
30587
|
-
|
|
30588
|
-
|
|
30589
|
-
|
|
30590
|
-
|
|
30591
|
-
|
|
30592
|
-
|
|
30593
|
-
|
|
30594
|
-
|
|
30595
|
-
|
|
30596
|
-
|
|
30597
|
-
|
|
30598
|
-
|
|
30599
|
-
|
|
30600
|
-
|
|
30601
|
-
|
|
30602
|
-
|
|
30603
|
-
|
|
30604
|
-
|
|
30605
|
-
|
|
30606
|
-
|
|
30607
|
-
|
|
30554
|
+
// ../../packages/sdk/src/project.ts
|
|
30555
|
+
import { mkdir as mkdir2, readFile as readFile2, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
30556
|
+
import { join as join5, resolve } from "node:path";
|
|
30557
|
+
function resolveRoot(root) {
|
|
30558
|
+
return resolve(root ?? process.cwd());
|
|
30559
|
+
}
|
|
30560
|
+
async function loadProjectConfig(root) {
|
|
30561
|
+
return loadTestpilotConfig(resolveRoot(root));
|
|
30562
|
+
}
|
|
30563
|
+
async function inspectProject(root) {
|
|
30564
|
+
const dir = resolveRoot(root);
|
|
30565
|
+
const config2 = await loadTestpilotConfig(dir);
|
|
30566
|
+
const casesDir = join5(dir, config2.casesDir);
|
|
30567
|
+
const artifactsDir = join5(dir, TESTPILOT_DIR, "artifacts");
|
|
30568
|
+
const [hasConfig, casesDirExists, skillInstalled] = await Promise.all([
|
|
30569
|
+
exists2(join5(dir, "testpilot.yaml")),
|
|
30570
|
+
exists2(casesDir),
|
|
30571
|
+
exists2(join5(dir, ".agents", "skills", "testpilot"))
|
|
30572
|
+
]);
|
|
30573
|
+
return {
|
|
30574
|
+
root: dir,
|
|
30575
|
+
hasConfig,
|
|
30576
|
+
config: config2,
|
|
30577
|
+
casesDir,
|
|
30578
|
+
casesDirExists,
|
|
30579
|
+
artifactsDir,
|
|
30580
|
+
runsDir: join5(artifactsDir, "runs"),
|
|
30581
|
+
skillInstalled,
|
|
30582
|
+
targets: config2.miniapp ? ["web", "miniapp"] : ["web"]
|
|
30583
|
+
};
|
|
30584
|
+
}
|
|
30585
|
+
async function exists2(path) {
|
|
30586
|
+
return await stat(path).catch(() => void 0) !== void 0;
|
|
30587
|
+
}
|
|
30588
|
+
var PROJECT_LINK_FILE = join5(TESTPILOT_DIR, "project.json");
|
|
30589
|
+
async function readProjectLink(root) {
|
|
30590
|
+
const file2 = join5(resolveRoot(root), PROJECT_LINK_FILE);
|
|
30591
|
+
try {
|
|
30592
|
+
const raw = JSON.parse(await readFile2(file2, "utf8"));
|
|
30593
|
+
if (!raw.projectId) return void 0;
|
|
30594
|
+
return raw;
|
|
30595
|
+
} catch {
|
|
30596
|
+
return void 0;
|
|
30597
|
+
}
|
|
30598
|
+
}
|
|
30599
|
+
async function writeProjectLink(link, root) {
|
|
30600
|
+
const file2 = join5(resolveRoot(root), PROJECT_LINK_FILE);
|
|
30601
|
+
await mkdir2(join5(file2, ".."), { recursive: true });
|
|
30602
|
+
await writeFile2(file2, `${JSON.stringify(link, null, 2)}
|
|
30603
|
+
`, "utf8");
|
|
30604
|
+
return file2;
|
|
30605
|
+
}
|
|
30606
|
+
|
|
30607
|
+
// ../../packages/sdk/src/cases.ts
|
|
30608
|
+
async function collectCaseFiles(paths) {
|
|
30609
|
+
const files = [];
|
|
30610
|
+
for (const input2 of paths) {
|
|
30611
|
+
const info = await stat2(input2).catch(() => void 0);
|
|
30612
|
+
if (!info) continue;
|
|
30613
|
+
if (info.isDirectory()) {
|
|
30614
|
+
files.push(...await collectFromDir(input2));
|
|
30615
|
+
} else if (isCaseFile(input2)) {
|
|
30616
|
+
files.push(input2);
|
|
30608
30617
|
}
|
|
30609
|
-
|
|
30610
|
-
|
|
30611
|
-
|
|
30612
|
-
|
|
30613
|
-
|
|
30614
|
-
|
|
30615
|
-
|
|
30616
|
-
|
|
30618
|
+
}
|
|
30619
|
+
return [...new Set(files)].sort();
|
|
30620
|
+
}
|
|
30621
|
+
async function collectFromDir(dir) {
|
|
30622
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
30623
|
+
const found = [];
|
|
30624
|
+
for (const entry of entries) {
|
|
30625
|
+
const full = join6(dir, entry.name);
|
|
30626
|
+
if (entry.isDirectory()) {
|
|
30627
|
+
found.push(...await collectFromDir(full));
|
|
30628
|
+
} else if (isCaseFile(entry.name)) {
|
|
30629
|
+
found.push(full);
|
|
30617
30630
|
}
|
|
30618
|
-
|
|
30619
|
-
|
|
30620
|
-
|
|
30621
|
-
|
|
30631
|
+
}
|
|
30632
|
+
return found;
|
|
30633
|
+
}
|
|
30634
|
+
function isCaseFile(file2) {
|
|
30635
|
+
const ext = extname(file2).toLowerCase();
|
|
30636
|
+
return ext === ".yaml" || ext === ".yml";
|
|
30637
|
+
}
|
|
30638
|
+
function resolveAgainstRoot(root, file2) {
|
|
30639
|
+
return isAbsolute(file2) ? file2 : resolve2(resolveRoot(root), file2);
|
|
30640
|
+
}
|
|
30641
|
+
async function collectCases(paths, options = {}) {
|
|
30642
|
+
const files = await collectCaseFiles(
|
|
30643
|
+
paths.map((input2) => resolveAgainstRoot(options.root, input2))
|
|
30644
|
+
);
|
|
30645
|
+
const infos = [];
|
|
30646
|
+
for (const file2 of files) {
|
|
30647
|
+
const validation = await validateCaseFile(file2);
|
|
30648
|
+
infos.push({
|
|
30649
|
+
file: file2,
|
|
30650
|
+
valid: validation.ok,
|
|
30651
|
+
case: validation.data,
|
|
30652
|
+
issues: validation.issues
|
|
30653
|
+
});
|
|
30654
|
+
}
|
|
30655
|
+
return infos;
|
|
30656
|
+
}
|
|
30657
|
+
async function readCaseFile(file2, options = {}) {
|
|
30658
|
+
const target = resolveAgainstRoot(options.root, file2);
|
|
30659
|
+
const source = await readFile3(target, "utf8");
|
|
30660
|
+
return { file: target, source, validation: validateCaseSource(source) };
|
|
30661
|
+
}
|
|
30662
|
+
async function validateCaseFile(file2) {
|
|
30663
|
+
const source = await readFile3(file2, "utf8");
|
|
30664
|
+
return validateCaseSource(source);
|
|
30665
|
+
}
|
|
30666
|
+
async function writeCaseFile(file2, source, options = {}) {
|
|
30667
|
+
const target = resolveAgainstRoot(options.root, file2);
|
|
30668
|
+
const validation = validateCaseSource(source);
|
|
30669
|
+
if (!validation.ok) {
|
|
30670
|
+
return { file: target, written: false, validation };
|
|
30671
|
+
}
|
|
30672
|
+
if (!options.overwrite) {
|
|
30673
|
+
const existing = await stat2(target).catch(() => void 0);
|
|
30674
|
+
if (existing) {
|
|
30675
|
+
throw new Error(`\u7528\u4F8B\u6587\u4EF6\u5DF2\u5B58\u5728:${target}(\u8986\u76D6\u9700\u663E\u5F0F overwrite: true)`);
|
|
30622
30676
|
}
|
|
30623
|
-
|
|
30624
|
-
|
|
30625
|
-
|
|
30677
|
+
}
|
|
30678
|
+
await mkdir3(dirname(target), { recursive: true });
|
|
30679
|
+
await writeFile3(target, source, "utf8");
|
|
30680
|
+
return { file: target, written: true, validation };
|
|
30626
30681
|
}
|
|
30627
30682
|
|
|
30628
|
-
// src/
|
|
30629
|
-
import {
|
|
30630
|
-
import {
|
|
30631
|
-
import { join as join8 } from "node:path";
|
|
30683
|
+
// ../../packages/sdk/src/reports.ts
|
|
30684
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
30685
|
+
import { join as join16 } from "node:path";
|
|
30632
30686
|
|
|
30633
30687
|
// ../../packages/reporter/src/report.ts
|
|
30634
|
-
import { writeFile as
|
|
30635
|
-
import { join as join7, resolve } from "node:path";
|
|
30688
|
+
import { writeFile as writeFile4 } from "node:fs/promises";
|
|
30689
|
+
import { join as join7, resolve as resolve3 } from "node:path";
|
|
30636
30690
|
|
|
30637
30691
|
// ../../packages/reporter/src/summary.ts
|
|
30638
30692
|
function toSummaryView(summary) {
|
|
@@ -30652,12 +30706,12 @@ function toSummaryView(summary) {
|
|
|
30652
30706
|
|
|
30653
30707
|
// ../../packages/reporter/src/report.ts
|
|
30654
30708
|
async function writeReports(runDir, summary) {
|
|
30655
|
-
const dir =
|
|
30709
|
+
const dir = resolve3(runDir);
|
|
30656
30710
|
const jsonPath = join7(dir, "report.json");
|
|
30657
30711
|
const htmlPath = join7(dir, "report.html");
|
|
30658
30712
|
const payload = { generatedAt: (/* @__PURE__ */ new Date()).toISOString(), summary };
|
|
30659
|
-
await
|
|
30660
|
-
await
|
|
30713
|
+
await writeFile4(jsonPath, JSON.stringify(payload, null, 2), "utf8");
|
|
30714
|
+
await writeFile4(htmlPath, renderHtml(summary), "utf8");
|
|
30661
30715
|
return { json: jsonPath, html: htmlPath };
|
|
30662
30716
|
}
|
|
30663
30717
|
function renderHtml(summary) {
|
|
@@ -30726,235 +30780,799 @@ function escapeHtml(input2) {
|
|
|
30726
30780
|
return input2.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
30727
30781
|
}
|
|
30728
30782
|
|
|
30729
|
-
// src/
|
|
30730
|
-
|
|
30731
|
-
|
|
30732
|
-
const runId = options.run ?? await latestRunId();
|
|
30733
|
-
if (!runId) {
|
|
30734
|
-
console.error(`\u672A\u627E\u5230\u8FD0\u884C\u8BB0\u5F55(${RUNS_DIR} \u4E3A\u7A7A,\u5148\u8FD0\u884C npx csspilot run)`);
|
|
30735
|
-
process.exitCode = 1;
|
|
30736
|
-
return;
|
|
30737
|
-
}
|
|
30738
|
-
const runDir = join8(RUNS_DIR, runId);
|
|
30739
|
-
let summary;
|
|
30740
|
-
try {
|
|
30741
|
-
summary = JSON.parse(await readFile3(join8(runDir, RESULT_FILE), "utf8"));
|
|
30742
|
-
} catch {
|
|
30743
|
-
console.error(`\u8BFB\u53D6\u8FD0\u884C\u7ED3\u679C\u5931\u8D25:${join8(runDir, RESULT_FILE)}`);
|
|
30744
|
-
process.exitCode = 1;
|
|
30745
|
-
return;
|
|
30746
|
-
}
|
|
30747
|
-
const written = await writeReports(runDir, summary);
|
|
30748
|
-
console.log(`\u2713 report.json ${written.json}`);
|
|
30749
|
-
console.log(`\u2713 report.html ${written.html}`);
|
|
30750
|
-
if (options.open) await openInBrowser(written.html);
|
|
30751
|
-
});
|
|
30752
|
-
}
|
|
30753
|
-
async function latestRunId() {
|
|
30754
|
-
const entries = await readdir2(RUNS_DIR).catch(() => []);
|
|
30755
|
-
return entries.sort().at(-1);
|
|
30756
|
-
}
|
|
30757
|
-
function openInBrowser(file2) {
|
|
30758
|
-
const command = process.platform === "win32" ? `start "" "${file2}"` : process.platform === "darwin" ? `open "${file2}"` : `xdg-open "${file2}"`;
|
|
30759
|
-
return new Promise((resolvePromise) => {
|
|
30760
|
-
exec(command, () => resolvePromise());
|
|
30761
|
-
});
|
|
30762
|
-
}
|
|
30783
|
+
// ../../packages/sdk/src/runs.ts
|
|
30784
|
+
import { readFile as readFile5, readdir as readdir3 } from "node:fs/promises";
|
|
30785
|
+
import { isAbsolute as isAbsolute2, join as join15 } from "node:path";
|
|
30763
30786
|
|
|
30764
|
-
// src/
|
|
30765
|
-
import {
|
|
30766
|
-
import { join as
|
|
30787
|
+
// ../../packages/execution-engine/src/artifacts/index.ts
|
|
30788
|
+
import { mkdir as mkdir8 } from "node:fs/promises";
|
|
30789
|
+
import { join as join11 } from "node:path";
|
|
30767
30790
|
|
|
30768
|
-
// ../../packages/
|
|
30769
|
-
import {
|
|
30770
|
-
|
|
30771
|
-
|
|
30772
|
-
|
|
30773
|
-
|
|
30774
|
-
function stepTimeout(options) {
|
|
30775
|
-
const fromEnv = Number(process.env.TESTPILOT_STEP_TIMEOUT);
|
|
30776
|
-
if (options.timeout !== void 0) return options.timeout;
|
|
30777
|
-
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : DEFAULT_STEP_TIMEOUT_MS;
|
|
30778
|
-
}
|
|
30779
|
-
async function launchBrowser(options = {}) {
|
|
30780
|
-
const browser = await chromium.launch({ headless: resolveHeadless(options) });
|
|
30781
|
-
return { browser };
|
|
30782
|
-
}
|
|
30783
|
-
async function openCaseContext(bundle, options, evidenceTmpDir) {
|
|
30784
|
-
const context = await bundle.browser.newContext({
|
|
30785
|
-
...evidenceTmpDir ? { recordVideo: { dir: evidenceTmpDir } } : {}
|
|
30786
|
-
});
|
|
30787
|
-
context.setDefaultTimeout(stepTimeout(options));
|
|
30788
|
-
if (evidenceTmpDir) {
|
|
30789
|
-
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
30791
|
+
// ../../packages/evidence/src/log.ts
|
|
30792
|
+
import { appendFile, mkdir as mkdir4 } from "node:fs/promises";
|
|
30793
|
+
import { dirname as dirname2 } from "node:path";
|
|
30794
|
+
var RunLogger = class {
|
|
30795
|
+
constructor(filePath) {
|
|
30796
|
+
this.filePath = filePath;
|
|
30790
30797
|
}
|
|
30791
|
-
|
|
30792
|
-
|
|
30793
|
-
}
|
|
30794
|
-
|
|
30795
|
-
// ../../packages/adapter-playwright/src/page.ts
|
|
30796
|
-
import { existsSync as existsSync4 } from "node:fs";
|
|
30797
|
-
import { mkdtemp, readFile as readFile4, rm } from "node:fs/promises";
|
|
30798
|
-
import { tmpdir } from "node:os";
|
|
30799
|
-
import { join as join9 } from "node:path";
|
|
30800
|
-
var PlaywrightAdapter = class {
|
|
30801
|
-
constructor(bundle, options = {}) {
|
|
30802
|
-
this.bundle = bundle;
|
|
30803
|
-
this.options = options;
|
|
30798
|
+
info(message) {
|
|
30799
|
+
return this.write("INFO", message);
|
|
30804
30800
|
}
|
|
30805
|
-
|
|
30806
|
-
|
|
30807
|
-
/** 浏览器在 create() 时已启动;context/page 按用例惰性创建,launch 保持幂等 */
|
|
30808
|
-
async launch() {
|
|
30801
|
+
warn(message) {
|
|
30802
|
+
return this.write("WARN", message);
|
|
30809
30803
|
}
|
|
30810
|
-
|
|
30811
|
-
|
|
30812
|
-
await this.closeContextQuietly();
|
|
30813
|
-
const evidenceTmpDir = await mkdtemp(join9(tmpdir(), "testpilot-pw-"));
|
|
30814
|
-
this.current = {
|
|
30815
|
-
...await openCaseContext(this.bundle, this.options, evidenceTmpDir),
|
|
30816
|
-
evidenceTmpDir
|
|
30817
|
-
};
|
|
30804
|
+
error(message) {
|
|
30805
|
+
return this.write("ERROR", message);
|
|
30818
30806
|
}
|
|
30819
|
-
|
|
30820
|
-
|
|
30821
|
-
|
|
30822
|
-
|
|
30823
|
-
this.
|
|
30824
|
-
const traceZipPath = join9(evidenceTmpDir ?? tmpdir(), "trace.zip");
|
|
30825
|
-
await context.tracing.stop({ path: traceZipPath }).catch(() => void 0);
|
|
30826
|
-
const recordedVideoPath = await page.video()?.path().catch(() => void 0);
|
|
30827
|
-
await context.close().catch(() => void 0);
|
|
30828
|
-
const video = recordedVideoPath && existsSync4(recordedVideoPath) ? await readFile4(recordedVideoPath) : void 0;
|
|
30829
|
-
const trace = evidenceTmpDir && existsSync4(traceZipPath) ? await readFile4(traceZipPath) : void 0;
|
|
30830
|
-
if (evidenceTmpDir) await rm(evidenceTmpDir, { recursive: true, force: true }).catch(() => void 0);
|
|
30831
|
-
return { video, trace };
|
|
30807
|
+
async write(level, message) {
|
|
30808
|
+
await mkdir4(dirname2(this.filePath), { recursive: true });
|
|
30809
|
+
const line = `${(/* @__PURE__ */ new Date()).toISOString()} ${level} ${message}
|
|
30810
|
+
`;
|
|
30811
|
+
await appendFile(this.filePath, line, "utf8");
|
|
30832
30812
|
}
|
|
30833
|
-
|
|
30834
|
-
|
|
30835
|
-
|
|
30836
|
-
|
|
30837
|
-
|
|
30813
|
+
};
|
|
30814
|
+
|
|
30815
|
+
// ../../packages/evidence/src/screenshot.ts
|
|
30816
|
+
import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
|
|
30817
|
+
import { dirname as dirname3, join as join8 } from "node:path";
|
|
30818
|
+
async function saveScreenshot(dir, fileName, data) {
|
|
30819
|
+
const file2 = join8(dir, fileName);
|
|
30820
|
+
await mkdir5(dirname3(file2), { recursive: true });
|
|
30821
|
+
await writeFile5(file2, data);
|
|
30822
|
+
return file2;
|
|
30823
|
+
}
|
|
30824
|
+
|
|
30825
|
+
// ../../packages/evidence/src/trace.ts
|
|
30826
|
+
import { mkdir as mkdir6, writeFile as writeFile6 } from "node:fs/promises";
|
|
30827
|
+
import { dirname as dirname4, join as join9 } from "node:path";
|
|
30828
|
+
async function saveTrace(dir, fileName, data) {
|
|
30829
|
+
const file2 = join9(dir, fileName);
|
|
30830
|
+
await mkdir6(dirname4(file2), { recursive: true });
|
|
30831
|
+
await writeFile6(file2, data);
|
|
30832
|
+
return file2;
|
|
30833
|
+
}
|
|
30834
|
+
|
|
30835
|
+
// ../../packages/evidence/src/video.ts
|
|
30836
|
+
import { mkdir as mkdir7, writeFile as writeFile7 } from "node:fs/promises";
|
|
30837
|
+
import { dirname as dirname5, join as join10 } from "node:path";
|
|
30838
|
+
async function saveVideo(dir, fileName, data) {
|
|
30839
|
+
const file2 = join10(dir, fileName);
|
|
30840
|
+
await mkdir7(dirname5(file2), { recursive: true });
|
|
30841
|
+
await writeFile7(file2, data);
|
|
30842
|
+
return file2;
|
|
30843
|
+
}
|
|
30844
|
+
|
|
30845
|
+
// ../../packages/execution-engine/src/artifacts/index.ts
|
|
30846
|
+
var ArtifactManager = class {
|
|
30847
|
+
constructor(runDir) {
|
|
30848
|
+
this.runDir = runDir;
|
|
30849
|
+
this.screenshotsDir = join11(runDir, "screenshots");
|
|
30850
|
+
this.videosDir = join11(runDir, "videos");
|
|
30851
|
+
this.tracesDir = join11(runDir, "traces");
|
|
30852
|
+
this.logsDir = join11(runDir, "logs");
|
|
30853
|
+
this.logger = new RunLogger(join11(this.logsDir, "run.log"));
|
|
30838
30854
|
}
|
|
30839
|
-
|
|
30840
|
-
|
|
30855
|
+
screenshotsDir;
|
|
30856
|
+
videosDir;
|
|
30857
|
+
tracesDir;
|
|
30858
|
+
logsDir;
|
|
30859
|
+
logger;
|
|
30860
|
+
async prepare() {
|
|
30861
|
+
await mkdir8(this.screenshotsDir, { recursive: true });
|
|
30862
|
+
await mkdir8(this.logsDir, { recursive: true });
|
|
30841
30863
|
}
|
|
30842
|
-
|
|
30843
|
-
|
|
30864
|
+
/** 保存步骤截图,返回相对 run 目录的路径(screenshots/xxx.png,统一正斜杠供报告链接使用) */
|
|
30865
|
+
async saveStepScreenshot(fileName, data) {
|
|
30866
|
+
await saveScreenshot(this.screenshotsDir, fileName, data);
|
|
30867
|
+
return `screenshots/${fileName}`;
|
|
30844
30868
|
}
|
|
30845
|
-
|
|
30846
|
-
|
|
30869
|
+
/** 保存用例录屏,返回相对 run 目录的路径(videos/xxx.webm) */
|
|
30870
|
+
async saveVideo(fileName, data) {
|
|
30871
|
+
await saveVideo(this.videosDir, fileName, data);
|
|
30872
|
+
return `videos/${fileName}`;
|
|
30847
30873
|
}
|
|
30848
|
-
|
|
30849
|
-
|
|
30850
|
-
|
|
30851
|
-
|
|
30852
|
-
return;
|
|
30853
|
-
}
|
|
30854
|
-
await page.waitForTimeout(timeoutMs ?? 1e3);
|
|
30874
|
+
/** 保存用例 trace 包,返回相对 run 目录的路径(traces/xxx.zip) */
|
|
30875
|
+
async saveTrace(fileName, data) {
|
|
30876
|
+
await saveTrace(this.tracesDir, fileName, data);
|
|
30877
|
+
return `traces/${fileName}`;
|
|
30855
30878
|
}
|
|
30856
|
-
|
|
30857
|
-
|
|
30858
|
-
|
|
30859
|
-
|
|
30860
|
-
|
|
30861
|
-
|
|
30862
|
-
|
|
30863
|
-
}
|
|
30879
|
+
};
|
|
30880
|
+
|
|
30881
|
+
// ../../packages/execution-engine/src/context/index.ts
|
|
30882
|
+
var ExecutionContext = class {
|
|
30883
|
+
variables = /* @__PURE__ */ new Map();
|
|
30884
|
+
set(name, value) {
|
|
30885
|
+
this.variables.set(name, value);
|
|
30864
30886
|
}
|
|
30865
|
-
|
|
30866
|
-
return
|
|
30887
|
+
get(name) {
|
|
30888
|
+
return this.variables.get(name);
|
|
30867
30889
|
}
|
|
30868
|
-
|
|
30869
|
-
|
|
30890
|
+
/**
|
|
30891
|
+
* 将字符串中的 ${name} 替换为已提取的变量值;未定义的引用保持原样(校验阶段已拦截)。
|
|
30892
|
+
* 名字允许点号,用于引擎注入的 account.username 一类凭据变量(用户 extract 变量名不含点号)。
|
|
30893
|
+
*/
|
|
30894
|
+
resolve(template) {
|
|
30895
|
+
return template.replace(
|
|
30896
|
+
/\$\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,
|
|
30897
|
+
(match, name) => this.variables.get(name) ?? match
|
|
30898
|
+
);
|
|
30870
30899
|
}
|
|
30871
|
-
|
|
30872
|
-
|
|
30873
|
-
|
|
30900
|
+
/**
|
|
30901
|
+
* 注入 accountRef 凭据:值为 JSON 对象时按 `${account.<字段>}` 展开为字符串,
|
|
30902
|
+
* 非 JSON 值整条注入为 `${account}`。凭据不进日志/取证,只进模板解析。
|
|
30903
|
+
*/
|
|
30904
|
+
seedAccount(rawValue) {
|
|
30905
|
+
let parsed;
|
|
30906
|
+
try {
|
|
30907
|
+
parsed = JSON.parse(rawValue);
|
|
30908
|
+
} catch {
|
|
30909
|
+
parsed = void 0;
|
|
30910
|
+
}
|
|
30911
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
30912
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
30913
|
+
if (value === null || value === void 0) continue;
|
|
30914
|
+
this.variables.set(
|
|
30915
|
+
`account.${key}`,
|
|
30916
|
+
typeof value === "object" ? JSON.stringify(value) : String(value)
|
|
30917
|
+
);
|
|
30918
|
+
}
|
|
30919
|
+
return;
|
|
30920
|
+
}
|
|
30921
|
+
this.variables.set("account", rawValue);
|
|
30874
30922
|
}
|
|
30875
|
-
|
|
30876
|
-
|
|
30877
|
-
|
|
30923
|
+
};
|
|
30924
|
+
|
|
30925
|
+
// ../../packages/execution-engine/src/lifecycle/index.ts
|
|
30926
|
+
import { mkdir as mkdir9, readdir as readdir2 } from "node:fs/promises";
|
|
30927
|
+
import { join as join12 } from "node:path";
|
|
30928
|
+
function dateStamp(date5 = /* @__PURE__ */ new Date()) {
|
|
30929
|
+
const year = date5.getFullYear();
|
|
30930
|
+
const month = String(date5.getMonth() + 1).padStart(2, "0");
|
|
30931
|
+
const day = String(date5.getDate()).padStart(2, "0");
|
|
30932
|
+
return `${year}${month}${day}`;
|
|
30933
|
+
}
|
|
30934
|
+
async function allocateRunId(runsRoot2) {
|
|
30935
|
+
const stamp = dateStamp();
|
|
30936
|
+
const existing = await readdir2(runsRoot2).catch(() => []);
|
|
30937
|
+
let max = 0;
|
|
30938
|
+
for (const name of existing) {
|
|
30939
|
+
const match = /^(\d{8})-(\d{3})$/.exec(name);
|
|
30940
|
+
if (match && match[1] === stamp) {
|
|
30941
|
+
max = Math.max(max, Number(match[2]));
|
|
30878
30942
|
}
|
|
30879
|
-
return this.current.page;
|
|
30880
30943
|
}
|
|
30881
|
-
|
|
30882
|
-
|
|
30944
|
+
return `${stamp}-${String(max + 1).padStart(3, "0")}`;
|
|
30945
|
+
}
|
|
30946
|
+
async function ensureRunDir(runsRoot2, runId) {
|
|
30947
|
+
const runDir = join12(runsRoot2, runId);
|
|
30948
|
+
await mkdir9(runDir, { recursive: true });
|
|
30949
|
+
return runDir;
|
|
30950
|
+
}
|
|
30951
|
+
|
|
30952
|
+
// ../../packages/execution-engine/src/events/index.ts
|
|
30953
|
+
import { appendFile as appendFile2, mkdir as mkdir10 } from "node:fs/promises";
|
|
30954
|
+
import { dirname as dirname6 } from "node:path";
|
|
30955
|
+
var EventBus = class {
|
|
30956
|
+
subscribers = [];
|
|
30957
|
+
subscribe(subscriber) {
|
|
30958
|
+
this.subscribers.push(subscriber);
|
|
30883
30959
|
}
|
|
30884
|
-
|
|
30885
|
-
|
|
30886
|
-
|
|
30887
|
-
}
|
|
30888
|
-
if (locator.css !== void 0) {
|
|
30889
|
-
return page.locator(locator.css);
|
|
30960
|
+
async emit(event) {
|
|
30961
|
+
for (const subscriber of this.subscribers) {
|
|
30962
|
+
await subscriber(event);
|
|
30890
30963
|
}
|
|
30891
|
-
throw new Error(`\u65E0\u6548\u7684 locator:${JSON.stringify(locator)}`);
|
|
30892
|
-
}
|
|
30893
|
-
async closeContextQuietly() {
|
|
30894
|
-
if (!this.current) return;
|
|
30895
|
-
const { context } = this.current;
|
|
30896
|
-
this.current = void 0;
|
|
30897
|
-
await context.close().catch(() => void 0);
|
|
30898
30964
|
}
|
|
30899
30965
|
};
|
|
30900
|
-
|
|
30901
|
-
|
|
30902
|
-
|
|
30903
|
-
|
|
30904
|
-
|
|
30905
|
-
create: async () => {
|
|
30906
|
-
const bundle = await launchBrowser(options);
|
|
30907
|
-
return new PlaywrightAdapter(bundle, options);
|
|
30908
|
-
}
|
|
30966
|
+
function ndjsonSubscriber(filePath) {
|
|
30967
|
+
return async (event) => {
|
|
30968
|
+
await mkdir10(dirname6(filePath), { recursive: true });
|
|
30969
|
+
await appendFile2(filePath, `${JSON.stringify(event)}
|
|
30970
|
+
`, "utf8");
|
|
30909
30971
|
};
|
|
30910
30972
|
}
|
|
30911
30973
|
|
|
30912
|
-
// ../../packages/adapter-
|
|
30913
|
-
|
|
30914
|
-
|
|
30915
|
-
|
|
30916
|
-
|
|
30917
|
-
|
|
30918
|
-
var ELEMENT_WAIT_MS = 1e4;
|
|
30919
|
-
var CONNECTION_LOST = /connection closed|not connected/i;
|
|
30920
|
-
var automatorLauncher = {
|
|
30921
|
-
launch: async (options) => {
|
|
30922
|
-
try {
|
|
30923
|
-
return await automator.launch(options);
|
|
30924
|
-
} catch (launchError) {
|
|
30925
|
-
if (!options.cliPath) throw launchError;
|
|
30926
|
-
const port = Number(process.env.TESTPILOT_MINIPROGRAM_AUTO_PORT) || 9420;
|
|
30927
|
-
await startCliAuto(options.cliPath, options.projectPath, port);
|
|
30928
|
-
return await connectWithRetry(`ws://127.0.0.1:${port}`, AUTO_PORT_FALLBACK_WAIT_MS);
|
|
30929
|
-
}
|
|
30974
|
+
// ../../packages/adapter-core/src/adapter.ts
|
|
30975
|
+
var SENSITIVE_HEADERS = /* @__PURE__ */ new Set(["authorization", "cookie", "set-cookie", "x-api-key", "proxy-authorization"]);
|
|
30976
|
+
function redactHeaders(headers) {
|
|
30977
|
+
const redacted = {};
|
|
30978
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
30979
|
+
redacted[key] = SENSITIVE_HEADERS.has(key.toLowerCase()) ? "[REDACTED]" : value;
|
|
30930
30980
|
}
|
|
30931
|
-
|
|
30932
|
-
function delay(ms) {
|
|
30933
|
-
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
30981
|
+
return redacted;
|
|
30934
30982
|
}
|
|
30935
|
-
|
|
30936
|
-
|
|
30937
|
-
|
|
30938
|
-
|
|
30939
|
-
|
|
30940
|
-
|
|
30941
|
-
|
|
30942
|
-
|
|
30943
|
-
|
|
30983
|
+
|
|
30984
|
+
// ../../packages/adapter-core/src/session.ts
|
|
30985
|
+
var AdapterSession = class {
|
|
30986
|
+
constructor(target, factory) {
|
|
30987
|
+
this.target = target;
|
|
30988
|
+
this.factory = factory;
|
|
30989
|
+
}
|
|
30990
|
+
adapter;
|
|
30991
|
+
get opened() {
|
|
30992
|
+
return this.adapter !== void 0;
|
|
30993
|
+
}
|
|
30994
|
+
/** 惰性创建;已创建则复用 */
|
|
30995
|
+
async get() {
|
|
30996
|
+
if (!this.adapter) {
|
|
30997
|
+
this.adapter = await this.factory.create();
|
|
30998
|
+
await this.adapter.launch();
|
|
30944
30999
|
}
|
|
31000
|
+
return this.adapter;
|
|
30945
31001
|
}
|
|
30946
|
-
|
|
30947
|
-
|
|
30948
|
-
|
|
30949
|
-
|
|
30950
|
-
|
|
30951
|
-
|
|
30952
|
-
|
|
30953
|
-
|
|
30954
|
-
|
|
30955
|
-
|
|
30956
|
-
|
|
30957
|
-
|
|
31002
|
+
async close() {
|
|
31003
|
+
if (this.adapter) {
|
|
31004
|
+
await this.adapter.close().catch(() => void 0);
|
|
31005
|
+
this.adapter = void 0;
|
|
31006
|
+
}
|
|
31007
|
+
}
|
|
31008
|
+
};
|
|
31009
|
+
|
|
31010
|
+
// ../../packages/execution-engine/src/engine/adapter-resolver.ts
|
|
31011
|
+
var AdapterResolver = class {
|
|
31012
|
+
factories = /* @__PURE__ */ new Map();
|
|
31013
|
+
sessions = /* @__PURE__ */ new Map();
|
|
31014
|
+
register(factory) {
|
|
31015
|
+
this.factories.set(factory.target, factory);
|
|
31016
|
+
}
|
|
31017
|
+
/** 取得(或创建)target 的会话 */
|
|
31018
|
+
async session(target) {
|
|
31019
|
+
let session = this.sessions.get(target);
|
|
31020
|
+
if (!session) {
|
|
31021
|
+
const factory = this.factories.get(target);
|
|
31022
|
+
if (!factory) {
|
|
31023
|
+
throw new TestPilotError("ADAPTER_NOT_FOUND", `\u672A\u6CE8\u518C target "${target}" \u7684 adapter,\u8BE5\u7AEF\u6B65\u9AA4\u65E0\u6CD5\u6267\u884C`);
|
|
31024
|
+
}
|
|
31025
|
+
session = new AdapterSession(target, factory);
|
|
31026
|
+
this.sessions.set(target, session);
|
|
31027
|
+
}
|
|
31028
|
+
return session;
|
|
31029
|
+
}
|
|
31030
|
+
async closeAll() {
|
|
31031
|
+
for (const session of this.sessions.values()) {
|
|
31032
|
+
await session.close();
|
|
31033
|
+
}
|
|
31034
|
+
this.sessions.clear();
|
|
31035
|
+
}
|
|
31036
|
+
};
|
|
31037
|
+
|
|
31038
|
+
// ../../packages/execution-engine/src/engine/step-executor.ts
|
|
31039
|
+
var SNIPPET_LIMIT = 400;
|
|
31040
|
+
async function executeStep(step, index, adapter, context, artifacts, options) {
|
|
31041
|
+
const startedAt = Date.now();
|
|
31042
|
+
const result = {
|
|
31043
|
+
index,
|
|
31044
|
+
target: step.target,
|
|
31045
|
+
action: step.action,
|
|
31046
|
+
status: "passed",
|
|
31047
|
+
durationMs: 0
|
|
31048
|
+
};
|
|
31049
|
+
try {
|
|
31050
|
+
const locator = step.locator ? {
|
|
31051
|
+
text: step.locator.text !== void 0 ? context.resolve(step.locator.text) : void 0,
|
|
31052
|
+
css: step.locator.css !== void 0 ? context.resolve(step.locator.css) : void 0
|
|
31053
|
+
} : void 0;
|
|
31054
|
+
switch (step.action) {
|
|
31055
|
+
case "launch":
|
|
31056
|
+
await adapter.launch();
|
|
31057
|
+
break;
|
|
31058
|
+
case "navigate":
|
|
31059
|
+
await adapter.navigate(context.resolve(step.url ?? ""));
|
|
31060
|
+
break;
|
|
31061
|
+
case "click":
|
|
31062
|
+
await adapter.click(locator);
|
|
31063
|
+
break;
|
|
31064
|
+
case "input":
|
|
31065
|
+
await adapter.input(locator, context.resolve(step.value ?? ""));
|
|
31066
|
+
break;
|
|
31067
|
+
case "select":
|
|
31068
|
+
await adapter.select(locator, context.resolve(step.value ?? ""));
|
|
31069
|
+
break;
|
|
31070
|
+
case "wait":
|
|
31071
|
+
await adapter.wait(locator, step.timeout);
|
|
31072
|
+
break;
|
|
31073
|
+
case "assert":
|
|
31074
|
+
if (step.target === "api") {
|
|
31075
|
+
if (!adapter.assertResponse) throw new Error("\u5F53\u524D adapter \u4E0D\u652F\u6301 api \u65AD\u8A00");
|
|
31076
|
+
await adapter.assertResponse(context.resolve(step.expected ?? ""));
|
|
31077
|
+
} else {
|
|
31078
|
+
await adapter.assert(locator, context.resolve(step.expected ?? ""));
|
|
31079
|
+
}
|
|
31080
|
+
break;
|
|
31081
|
+
case "extract": {
|
|
31082
|
+
const value = step.target === "api" ? await extractApiResponse(adapter, context.resolve(step.value ?? "")) : await adapter.extract(locator);
|
|
31083
|
+
if (step.variable) {
|
|
31084
|
+
context.set(step.variable, value);
|
|
31085
|
+
result.extracted = { [step.variable]: value };
|
|
31086
|
+
}
|
|
31087
|
+
break;
|
|
31088
|
+
}
|
|
31089
|
+
case "screenshot": {
|
|
31090
|
+
const data = await adapter.screenshot();
|
|
31091
|
+
result.screenshot = await artifacts.saveStepScreenshot(`${options.screenshotName}.png`, data);
|
|
31092
|
+
break;
|
|
31093
|
+
}
|
|
31094
|
+
case "request": {
|
|
31095
|
+
if (!adapter.request) throw new Error("\u5F53\u524D adapter \u4E0D\u652F\u6301 api request");
|
|
31096
|
+
const method = step.method ?? "GET";
|
|
31097
|
+
const url2 = context.resolve(step.url ?? "");
|
|
31098
|
+
const headers = resolveHeaders(step.headers, context);
|
|
31099
|
+
const body = resolveBody(step.body, context);
|
|
31100
|
+
const response = await adapter.request({ method, url: url2, headers, body });
|
|
31101
|
+
result.http = {
|
|
31102
|
+
method: method.toUpperCase(),
|
|
31103
|
+
url: url2,
|
|
31104
|
+
status: response.status,
|
|
31105
|
+
...headers ? { requestHeaders: redactHeaders(headers) } : {},
|
|
31106
|
+
...body !== void 0 ? { requestBody: snippet(body) } : {},
|
|
31107
|
+
...response.bodyText ? { responseSnippet: snippet(response.bodyText) } : {}
|
|
31108
|
+
};
|
|
31109
|
+
if (step.expected !== void 0) {
|
|
31110
|
+
const expectedStatus = context.resolve(step.expected);
|
|
31111
|
+
if (String(response.status) !== expectedStatus) {
|
|
31112
|
+
throw new Error(
|
|
31113
|
+
`HTTP \u72B6\u6001\u7801 ${response.status} ${response.statusText},\u671F\u671B ${expectedStatus}:${snippet(response.bodyText, 200)}`
|
|
31114
|
+
);
|
|
31115
|
+
}
|
|
31116
|
+
}
|
|
31117
|
+
break;
|
|
31118
|
+
}
|
|
31119
|
+
default: {
|
|
31120
|
+
const exhaustive = step.action;
|
|
31121
|
+
throw new Error(`\u4E0D\u652F\u6301\u7684 action:${String(exhaustive)}`);
|
|
31122
|
+
}
|
|
31123
|
+
}
|
|
31124
|
+
} catch (err) {
|
|
31125
|
+
result.status = "failed";
|
|
31126
|
+
result.error = err instanceof Error ? err.message : String(err);
|
|
31127
|
+
try {
|
|
31128
|
+
const data = await adapter.screenshot();
|
|
31129
|
+
result.screenshot = await artifacts.saveStepScreenshot(`${options.screenshotName}-failed.png`, data);
|
|
31130
|
+
} catch {
|
|
31131
|
+
}
|
|
31132
|
+
}
|
|
31133
|
+
result.durationMs = Date.now() - startedAt;
|
|
31134
|
+
return result;
|
|
31135
|
+
}
|
|
31136
|
+
async function extractApiResponse(adapter, path) {
|
|
31137
|
+
if (!adapter.extractResponse) throw new Error("\u5F53\u524D adapter \u4E0D\u652F\u6301 api \u63D0\u53D6");
|
|
31138
|
+
if (!path) throw new Error("api \u7AEF extract \u9700\u8981\u63D0\u4F9B value(\u70B9\u53F7 JSON path)");
|
|
31139
|
+
return adapter.extractResponse(path);
|
|
31140
|
+
}
|
|
31141
|
+
function resolveHeaders(headers, context) {
|
|
31142
|
+
if (!headers) return void 0;
|
|
31143
|
+
const resolved = {};
|
|
31144
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
31145
|
+
resolved[key] = context.resolve(value);
|
|
31146
|
+
}
|
|
31147
|
+
return resolved;
|
|
31148
|
+
}
|
|
31149
|
+
function resolveBody(body, context) {
|
|
31150
|
+
if (body === void 0) return void 0;
|
|
31151
|
+
if (typeof body === "string") return context.resolve(body);
|
|
31152
|
+
return JSON.stringify(resolveDeep(body, context));
|
|
31153
|
+
}
|
|
31154
|
+
function resolveDeep(value, context) {
|
|
31155
|
+
if (typeof value === "string") return context.resolve(value);
|
|
31156
|
+
if (Array.isArray(value)) return value.map((item) => resolveDeep(item, context));
|
|
31157
|
+
if (value !== null && typeof value === "object") {
|
|
31158
|
+
const out = {};
|
|
31159
|
+
for (const [key, item] of Object.entries(value)) {
|
|
31160
|
+
out[key] = resolveDeep(item, context);
|
|
31161
|
+
}
|
|
31162
|
+
return out;
|
|
31163
|
+
}
|
|
31164
|
+
return value;
|
|
31165
|
+
}
|
|
31166
|
+
function snippet(text, limit = SNIPPET_LIMIT) {
|
|
31167
|
+
return text.length > limit ? `${text.slice(0, limit)}\u2026` : text;
|
|
31168
|
+
}
|
|
31169
|
+
|
|
31170
|
+
// ../../packages/execution-engine/src/engine/execution-engine.ts
|
|
31171
|
+
var ExecutionEngine = class {
|
|
31172
|
+
async runCase(data, options) {
|
|
31173
|
+
const { runId, file: file2, artifacts, bus, resolver } = options;
|
|
31174
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
31175
|
+
const context = new ExecutionContext();
|
|
31176
|
+
if (data.accountRef && options.accounts?.[data.accountRef] !== void 0) {
|
|
31177
|
+
context.seedAccount(options.accounts[data.accountRef]);
|
|
31178
|
+
}
|
|
31179
|
+
const steps = [];
|
|
31180
|
+
const evidenceAdapters = /* @__PURE__ */ new Map();
|
|
31181
|
+
let caseError;
|
|
31182
|
+
await bus.emit({ type: "case-started", runId, caseId: data.id, file: file2, ts: startedAt.toISOString() });
|
|
31183
|
+
await artifacts.logger.info(`case ${data.id} started (${file2})`);
|
|
31184
|
+
for (const [index, step] of data.steps.entries()) {
|
|
31185
|
+
await bus.emit({
|
|
31186
|
+
type: "step-started",
|
|
31187
|
+
runId,
|
|
31188
|
+
caseId: data.id,
|
|
31189
|
+
index,
|
|
31190
|
+
target: step.target,
|
|
31191
|
+
action: step.action,
|
|
31192
|
+
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
31193
|
+
});
|
|
31194
|
+
let result;
|
|
31195
|
+
try {
|
|
31196
|
+
const adapter = await (await resolver.session(step.target)).get();
|
|
31197
|
+
if (adapter.startEvidence && !evidenceAdapters.has(step.target)) {
|
|
31198
|
+
try {
|
|
31199
|
+
await adapter.startEvidence(data.id);
|
|
31200
|
+
evidenceAdapters.set(step.target, adapter);
|
|
31201
|
+
} catch (err) {
|
|
31202
|
+
await artifacts.logger.info(
|
|
31203
|
+
`evidence start failed for ${step.target}: ${err instanceof Error ? err.message : String(err)}`
|
|
31204
|
+
);
|
|
31205
|
+
}
|
|
31206
|
+
}
|
|
31207
|
+
result = await executeStep(step, index, adapter, context, artifacts, {
|
|
31208
|
+
screenshotName: `${data.id}-step-${String(index).padStart(2, "0")}`
|
|
31209
|
+
});
|
|
31210
|
+
} catch (err) {
|
|
31211
|
+
result = {
|
|
31212
|
+
index,
|
|
31213
|
+
target: step.target,
|
|
31214
|
+
action: step.action,
|
|
31215
|
+
status: "failed",
|
|
31216
|
+
durationMs: 0,
|
|
31217
|
+
error: err instanceof Error ? err.message : String(err)
|
|
31218
|
+
};
|
|
31219
|
+
}
|
|
31220
|
+
steps.push(result);
|
|
31221
|
+
await artifacts.logger.info(`step ${index} ${step.action} -> ${result.status}${result.error ? ` - ${result.error}` : ""}`);
|
|
31222
|
+
await bus.emit({
|
|
31223
|
+
type: "step-finished",
|
|
31224
|
+
runId,
|
|
31225
|
+
caseId: data.id,
|
|
31226
|
+
index,
|
|
31227
|
+
target: step.target,
|
|
31228
|
+
action: step.action,
|
|
31229
|
+
status: result.status,
|
|
31230
|
+
durationMs: result.durationMs,
|
|
31231
|
+
error: result.error,
|
|
31232
|
+
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
31233
|
+
});
|
|
31234
|
+
if (result.status === "failed") {
|
|
31235
|
+
caseError = result.error;
|
|
31236
|
+
for (const [skipIndex, skippedStep] of data.steps.entries()) {
|
|
31237
|
+
if (skipIndex <= index) continue;
|
|
31238
|
+
steps.push({
|
|
31239
|
+
index: skipIndex,
|
|
31240
|
+
target: skippedStep.target,
|
|
31241
|
+
action: skippedStep.action,
|
|
31242
|
+
status: "skipped",
|
|
31243
|
+
durationMs: 0
|
|
31244
|
+
});
|
|
31245
|
+
}
|
|
31246
|
+
break;
|
|
31247
|
+
}
|
|
31248
|
+
}
|
|
31249
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
31250
|
+
const status = caseError ? "failed" : "passed";
|
|
31251
|
+
const caseResult = {
|
|
31252
|
+
caseId: data.id,
|
|
31253
|
+
caseName: data.name,
|
|
31254
|
+
file: file2,
|
|
31255
|
+
status,
|
|
31256
|
+
steps,
|
|
31257
|
+
startedAt: startedAt.toISOString(),
|
|
31258
|
+
finishedAt: finishedAt.toISOString(),
|
|
31259
|
+
durationMs: finishedAt.getTime() - startedAt.getTime()
|
|
31260
|
+
};
|
|
31261
|
+
if (caseError) caseResult.error = caseError;
|
|
31262
|
+
for (const [target, adapter] of evidenceAdapters) {
|
|
31263
|
+
if (!adapter.stopEvidence) continue;
|
|
31264
|
+
try {
|
|
31265
|
+
const evidence = await adapter.stopEvidence(data.id);
|
|
31266
|
+
if (evidence.video) {
|
|
31267
|
+
caseResult.video = await artifacts.saveVideo(`${data.id}-${target}.webm`, evidence.video);
|
|
31268
|
+
}
|
|
31269
|
+
if (evidence.trace) {
|
|
31270
|
+
caseResult.trace = await artifacts.saveTrace(`${data.id}-${target}.zip`, evidence.trace);
|
|
31271
|
+
}
|
|
31272
|
+
} catch (err) {
|
|
31273
|
+
await artifacts.logger.info(
|
|
31274
|
+
`evidence stop failed for ${target}: ${err instanceof Error ? err.message : String(err)}`
|
|
31275
|
+
);
|
|
31276
|
+
}
|
|
31277
|
+
}
|
|
31278
|
+
await bus.emit({
|
|
31279
|
+
type: "case-finished",
|
|
31280
|
+
runId,
|
|
31281
|
+
caseId: data.id,
|
|
31282
|
+
status,
|
|
31283
|
+
durationMs: finishedAt.getTime() - startedAt.getTime(),
|
|
31284
|
+
ts: finishedAt.toISOString()
|
|
31285
|
+
});
|
|
31286
|
+
await artifacts.logger.info(`case ${data.id} ${status}`);
|
|
31287
|
+
return caseResult;
|
|
31288
|
+
}
|
|
31289
|
+
};
|
|
31290
|
+
|
|
31291
|
+
// ../../packages/execution-engine/src/engine/result-collector.ts
|
|
31292
|
+
function buildRunSummary(runId, startedAt, cases, options = {}) {
|
|
31293
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
31294
|
+
const totals = {
|
|
31295
|
+
cases: cases.length,
|
|
31296
|
+
passed: cases.filter((item) => item.status === "passed").length,
|
|
31297
|
+
failed: cases.filter((item) => item.status === "failed").length,
|
|
31298
|
+
steps: 0,
|
|
31299
|
+
stepsPassed: 0,
|
|
31300
|
+
stepsFailed: 0,
|
|
31301
|
+
stepsSkipped: 0
|
|
31302
|
+
};
|
|
31303
|
+
for (const item of cases) {
|
|
31304
|
+
for (const step of item.steps) {
|
|
31305
|
+
totals.steps++;
|
|
31306
|
+
if (step.status === "passed") totals.stepsPassed++;
|
|
31307
|
+
else if (step.status === "failed") totals.stepsFailed++;
|
|
31308
|
+
else totals.stepsSkipped++;
|
|
31309
|
+
}
|
|
31310
|
+
}
|
|
31311
|
+
return {
|
|
31312
|
+
runId,
|
|
31313
|
+
startedAt: startedAt.toISOString(),
|
|
31314
|
+
finishedAt: finishedAt.toISOString(),
|
|
31315
|
+
durationMs: finishedAt.getTime() - startedAt.getTime(),
|
|
31316
|
+
status: totals.failed > 0 ? "failed" : "passed",
|
|
31317
|
+
...options.cancelled ? { cancelled: true } : {},
|
|
31318
|
+
cases,
|
|
31319
|
+
totals
|
|
31320
|
+
};
|
|
31321
|
+
}
|
|
31322
|
+
|
|
31323
|
+
// ../../packages/execution-engine/src/engine/test-runner.ts
|
|
31324
|
+
import { writeFile as writeFile8 } from "node:fs/promises";
|
|
31325
|
+
import { join as join13, resolve as resolve4 } from "node:path";
|
|
31326
|
+
var TestRunner = class {
|
|
31327
|
+
resolver;
|
|
31328
|
+
runsRoot;
|
|
31329
|
+
customRunId;
|
|
31330
|
+
extraSubscriber;
|
|
31331
|
+
signal;
|
|
31332
|
+
accounts;
|
|
31333
|
+
constructor(options) {
|
|
31334
|
+
this.resolver = options.resolver;
|
|
31335
|
+
this.runsRoot = resolve4(options.runsRoot ?? join13(process.cwd(), ".testpilot", "artifacts", "runs"));
|
|
31336
|
+
this.customRunId = options.runId;
|
|
31337
|
+
this.extraSubscriber = options.onEvent;
|
|
31338
|
+
this.signal = options.signal;
|
|
31339
|
+
this.accounts = options.accounts;
|
|
31340
|
+
}
|
|
31341
|
+
async run(cases) {
|
|
31342
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
31343
|
+
const runId = this.customRunId ?? await allocateRunId(this.runsRoot);
|
|
31344
|
+
const runDir = await ensureRunDir(this.runsRoot, runId);
|
|
31345
|
+
const artifacts = new ArtifactManager(runDir);
|
|
31346
|
+
await artifacts.prepare();
|
|
31347
|
+
const bus = new EventBus();
|
|
31348
|
+
bus.subscribe(ndjsonSubscriber(join13(runDir, "events.ndjson")));
|
|
31349
|
+
if (this.extraSubscriber) bus.subscribe(this.extraSubscriber);
|
|
31350
|
+
await bus.emit({ type: "run-started", runId, totalCases: cases.length, ts: startedAt.toISOString() });
|
|
31351
|
+
await artifacts.logger.info(`run ${runId} started with ${cases.length} case(s)`);
|
|
31352
|
+
const engine = new ExecutionEngine();
|
|
31353
|
+
const results = [];
|
|
31354
|
+
for (const item of cases) {
|
|
31355
|
+
if (this.signal?.aborted) {
|
|
31356
|
+
await artifacts.logger.info(`run ${runId} cancelled before case ${item.data.id}`);
|
|
31357
|
+
break;
|
|
31358
|
+
}
|
|
31359
|
+
results.push(
|
|
31360
|
+
await engine.runCase(item.data, {
|
|
31361
|
+
runId,
|
|
31362
|
+
file: item.file,
|
|
31363
|
+
artifacts,
|
|
31364
|
+
bus,
|
|
31365
|
+
resolver: this.resolver,
|
|
31366
|
+
accounts: this.accounts
|
|
31367
|
+
})
|
|
31368
|
+
);
|
|
31369
|
+
}
|
|
31370
|
+
const cancelled = this.signal?.aborted === true;
|
|
31371
|
+
await this.resolver.closeAll();
|
|
31372
|
+
const summary = buildRunSummary(runId, startedAt, results, { cancelled });
|
|
31373
|
+
await bus.emit({
|
|
31374
|
+
type: "run-finished",
|
|
31375
|
+
runId,
|
|
31376
|
+
status: summary.status,
|
|
31377
|
+
totals: { cases: summary.totals.cases, passed: summary.totals.passed, failed: summary.totals.failed },
|
|
31378
|
+
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
31379
|
+
});
|
|
31380
|
+
await artifacts.logger.info(`run ${runId} finished: ${summary.status}`);
|
|
31381
|
+
await writeFile8(join13(runDir, RESULT_FILE), JSON.stringify(summary, null, 2), "utf8");
|
|
31382
|
+
return summary;
|
|
31383
|
+
}
|
|
31384
|
+
};
|
|
31385
|
+
|
|
31386
|
+
// ../../packages/adapter-playwright/src/browser.ts
|
|
31387
|
+
import { chromium } from "playwright";
|
|
31388
|
+
function resolveHeadless(options) {
|
|
31389
|
+
if (options.headless !== void 0) return options.headless;
|
|
31390
|
+
return process.env.TESTPILOT_HEADLESS !== "false";
|
|
31391
|
+
}
|
|
31392
|
+
function stepTimeout(options) {
|
|
31393
|
+
const fromEnv = Number(process.env.TESTPILOT_STEP_TIMEOUT);
|
|
31394
|
+
if (options.timeout !== void 0) return options.timeout;
|
|
31395
|
+
return Number.isFinite(fromEnv) && fromEnv > 0 ? fromEnv : DEFAULT_STEP_TIMEOUT_MS;
|
|
31396
|
+
}
|
|
31397
|
+
async function launchBrowser(options = {}) {
|
|
31398
|
+
const browser = await chromium.launch({ headless: resolveHeadless(options) });
|
|
31399
|
+
return { browser };
|
|
31400
|
+
}
|
|
31401
|
+
async function openCaseContext(bundle, options, evidenceTmpDir) {
|
|
31402
|
+
const context = await bundle.browser.newContext({
|
|
31403
|
+
...evidenceTmpDir ? { recordVideo: { dir: evidenceTmpDir } } : {}
|
|
31404
|
+
});
|
|
31405
|
+
context.setDefaultTimeout(stepTimeout(options));
|
|
31406
|
+
if (evidenceTmpDir) {
|
|
31407
|
+
await context.tracing.start({ screenshots: true, snapshots: true });
|
|
31408
|
+
}
|
|
31409
|
+
const page = await context.newPage();
|
|
31410
|
+
return { context, page };
|
|
31411
|
+
}
|
|
31412
|
+
|
|
31413
|
+
// ../../packages/adapter-playwright/src/page.ts
|
|
31414
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
31415
|
+
import { mkdtemp, readFile as readFile4, rm } from "node:fs/promises";
|
|
31416
|
+
import { tmpdir } from "node:os";
|
|
31417
|
+
import { join as join14 } from "node:path";
|
|
31418
|
+
var PlaywrightAdapter = class {
|
|
31419
|
+
constructor(bundle, options = {}) {
|
|
31420
|
+
this.bundle = bundle;
|
|
31421
|
+
this.options = options;
|
|
31422
|
+
}
|
|
31423
|
+
target = "web";
|
|
31424
|
+
current;
|
|
31425
|
+
/** 浏览器在 create() 时已启动;context/page 按用例惰性创建,launch 保持幂等 */
|
|
31426
|
+
async launch() {
|
|
31427
|
+
}
|
|
31428
|
+
/** 开始用例级取证:为本用例创建独立 context(录屏 + trace) */
|
|
31429
|
+
async startEvidence(_caseId) {
|
|
31430
|
+
await this.closeContextQuietly();
|
|
31431
|
+
const evidenceTmpDir = await mkdtemp(join14(tmpdir(), "testpilot-pw-"));
|
|
31432
|
+
this.current = {
|
|
31433
|
+
...await openCaseContext(this.bundle, this.options, evidenceTmpDir),
|
|
31434
|
+
evidenceTmpDir
|
|
31435
|
+
};
|
|
31436
|
+
}
|
|
31437
|
+
/** 结束取证:trace 落 zip、录屏在 context 关闭后完成,返回二者字节 */
|
|
31438
|
+
async stopEvidence(_caseId) {
|
|
31439
|
+
if (!this.current) return {};
|
|
31440
|
+
const { context, page, evidenceTmpDir } = this.current;
|
|
31441
|
+
this.current = void 0;
|
|
31442
|
+
const traceZipPath = join14(evidenceTmpDir ?? tmpdir(), "trace.zip");
|
|
31443
|
+
await context.tracing.stop({ path: traceZipPath }).catch(() => void 0);
|
|
31444
|
+
const recordedVideoPath = await page.video()?.path().catch(() => void 0);
|
|
31445
|
+
await context.close().catch(() => void 0);
|
|
31446
|
+
const video = recordedVideoPath && existsSync2(recordedVideoPath) ? await readFile4(recordedVideoPath) : void 0;
|
|
31447
|
+
const trace = evidenceTmpDir && existsSync2(traceZipPath) ? await readFile4(traceZipPath) : void 0;
|
|
31448
|
+
if (evidenceTmpDir) await rm(evidenceTmpDir, { recursive: true, force: true }).catch(() => void 0);
|
|
31449
|
+
return { video, trace };
|
|
31450
|
+
}
|
|
31451
|
+
async navigate(url2) {
|
|
31452
|
+
const options = this.options;
|
|
31453
|
+
const page = await this.ensurePage();
|
|
31454
|
+
const target = options.baseUrl && !/^https?:\/\//i.test(url2) ? new URL(url2, options.baseUrl).toString() : url2;
|
|
31455
|
+
await page.goto(target);
|
|
31456
|
+
}
|
|
31457
|
+
async click(locator) {
|
|
31458
|
+
await (await this.toLocator(locator)).click();
|
|
31459
|
+
}
|
|
31460
|
+
async input(locator, value) {
|
|
31461
|
+
await (await this.toLocator(locator)).fill(value);
|
|
31462
|
+
}
|
|
31463
|
+
async select(locator, value) {
|
|
31464
|
+
await (await this.toLocator(locator)).selectOption(value);
|
|
31465
|
+
}
|
|
31466
|
+
async wait(locator, timeoutMs) {
|
|
31467
|
+
const page = await this.ensurePage();
|
|
31468
|
+
if (locator) {
|
|
31469
|
+
await this.toLocatorOn(page, locator).waitFor({ state: "visible", timeout: timeoutMs });
|
|
31470
|
+
return;
|
|
31471
|
+
}
|
|
31472
|
+
await page.waitForTimeout(timeoutMs ?? 1e3);
|
|
31473
|
+
}
|
|
31474
|
+
async assert(locator, expected) {
|
|
31475
|
+
const target = await this.toLocator(locator);
|
|
31476
|
+
await target.waitFor({ state: "visible" });
|
|
31477
|
+
const actual = (await target.innerText()).trim();
|
|
31478
|
+
const wanted = expected.trim();
|
|
31479
|
+
if (!actual.includes(wanted)) {
|
|
31480
|
+
throw new Error(`\u65AD\u8A00\u5931\u8D25:\u671F\u671B\u5305\u542B "${wanted}",\u5B9E\u9645\u4E3A "${actual.slice(0, 200)}"`);
|
|
31481
|
+
}
|
|
31482
|
+
}
|
|
31483
|
+
async extract(locator) {
|
|
31484
|
+
return (await this.toLocator(locator)).innerText().then((text) => text.trim());
|
|
31485
|
+
}
|
|
31486
|
+
async screenshot() {
|
|
31487
|
+
return (await this.ensurePage()).screenshot();
|
|
31488
|
+
}
|
|
31489
|
+
async close() {
|
|
31490
|
+
await this.closeContextQuietly();
|
|
31491
|
+
await this.bundle.browser.close().catch(() => void 0);
|
|
31492
|
+
}
|
|
31493
|
+
async ensurePage() {
|
|
31494
|
+
if (!this.current) {
|
|
31495
|
+
this.current = await openCaseContext(this.bundle, this.options);
|
|
31496
|
+
}
|
|
31497
|
+
return this.current.page;
|
|
31498
|
+
}
|
|
31499
|
+
async toLocator(locator) {
|
|
31500
|
+
return this.toLocatorOn(await this.ensurePage(), locator);
|
|
31501
|
+
}
|
|
31502
|
+
toLocatorOn(page, locator) {
|
|
31503
|
+
if (locator.text !== void 0) {
|
|
31504
|
+
return page.getByText(locator.text, { exact: true });
|
|
31505
|
+
}
|
|
31506
|
+
if (locator.css !== void 0) {
|
|
31507
|
+
return page.locator(locator.css);
|
|
31508
|
+
}
|
|
31509
|
+
throw new Error(`\u65E0\u6548\u7684 locator:${JSON.stringify(locator)}`);
|
|
31510
|
+
}
|
|
31511
|
+
async closeContextQuietly() {
|
|
31512
|
+
if (!this.current) return;
|
|
31513
|
+
const { context } = this.current;
|
|
31514
|
+
this.current = void 0;
|
|
31515
|
+
await context.close().catch(() => void 0);
|
|
31516
|
+
}
|
|
31517
|
+
};
|
|
31518
|
+
|
|
31519
|
+
// ../../packages/adapter-playwright/src/index.ts
|
|
31520
|
+
function playwrightAdapterFactory(options = {}) {
|
|
31521
|
+
return {
|
|
31522
|
+
target: "web",
|
|
31523
|
+
create: async () => {
|
|
31524
|
+
const bundle = await launchBrowser(options);
|
|
31525
|
+
return new PlaywrightAdapter(bundle, options);
|
|
31526
|
+
}
|
|
31527
|
+
};
|
|
31528
|
+
}
|
|
31529
|
+
|
|
31530
|
+
// ../../packages/adapter-wechatide/src/ide.ts
|
|
31531
|
+
import automator from "miniprogram-automator";
|
|
31532
|
+
import { spawn } from "node:child_process";
|
|
31533
|
+
import net from "node:net";
|
|
31534
|
+
var AUTO_PORT_FALLBACK_WAIT_MS = 9e4;
|
|
31535
|
+
var NAVIGATE_RETRY_WINDOW_MS = 45e3;
|
|
31536
|
+
var ELEMENT_WAIT_MS = 1e4;
|
|
31537
|
+
var CONNECTION_LOST = /connection closed|not connected/i;
|
|
31538
|
+
var automatorLauncher = {
|
|
31539
|
+
launch: async (options) => {
|
|
31540
|
+
try {
|
|
31541
|
+
return await automator.launch(options);
|
|
31542
|
+
} catch (launchError) {
|
|
31543
|
+
if (!options.cliPath) throw launchError;
|
|
31544
|
+
const port = Number(process.env.TESTPILOT_MINIPROGRAM_AUTO_PORT) || 9420;
|
|
31545
|
+
await startCliAuto(options.cliPath, options.projectPath, port);
|
|
31546
|
+
return await connectWithRetry(`ws://127.0.0.1:${port}`, AUTO_PORT_FALLBACK_WAIT_MS);
|
|
31547
|
+
}
|
|
31548
|
+
}
|
|
31549
|
+
};
|
|
31550
|
+
function delay(ms) {
|
|
31551
|
+
return new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
31552
|
+
}
|
|
31553
|
+
async function connectWithRetry(wsEndpoint, timeoutMs) {
|
|
31554
|
+
const startedAt = Date.now();
|
|
31555
|
+
let lastError;
|
|
31556
|
+
while (Date.now() - startedAt < timeoutMs) {
|
|
31557
|
+
try {
|
|
31558
|
+
return await automator.connect({ wsEndpoint });
|
|
31559
|
+
} catch (err) {
|
|
31560
|
+
lastError = err;
|
|
31561
|
+
await delay(1e3);
|
|
31562
|
+
}
|
|
31563
|
+
}
|
|
31564
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
31565
|
+
}
|
|
31566
|
+
function startCliAuto(cliPath, projectPath, port) {
|
|
31567
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
31568
|
+
const quote = (value) => /\s/.test(value) ? `"${value}"` : value;
|
|
31569
|
+
const args = ["auto", "--project", projectPath, "--auto-port", String(port)].map(quote);
|
|
31570
|
+
const child = spawn(`"${cliPath}"`, args, { shell: process.platform === "win32" });
|
|
31571
|
+
let output2 = "";
|
|
31572
|
+
child.stdout?.on("data", (chunk) => {
|
|
31573
|
+
output2 += chunk.toString("utf8");
|
|
31574
|
+
});
|
|
31575
|
+
child.stderr?.on("data", (chunk) => {
|
|
30958
31576
|
output2 += chunk.toString("utf8");
|
|
30959
31577
|
});
|
|
30960
31578
|
child.once("error", (err) => rejectPromise(new Error(`\u62C9\u8D77\u5F00\u53D1\u8005\u5DE5\u5177 cli \u5931\u8D25:${err.message}`)));
|
|
@@ -31111,11 +31729,11 @@ var MiniAppAdapter = class {
|
|
|
31111
31729
|
};
|
|
31112
31730
|
|
|
31113
31731
|
// ../../packages/adapter-wechatide/src/project.ts
|
|
31114
|
-
import { existsSync as
|
|
31732
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
31115
31733
|
async function resolveMiniappConfig(input2) {
|
|
31116
31734
|
const projectPath = input2.projectPath ?? process.env.TESTPILOT_MINIPROGRAM_PROJECT_PATH;
|
|
31117
31735
|
if (!projectPath) return void 0;
|
|
31118
|
-
if (!
|
|
31736
|
+
if (!existsSync3(projectPath)) {
|
|
31119
31737
|
throw new Error(`\u5C0F\u7A0B\u5E8F\u9879\u76EE\u8DEF\u5F84\u4E0D\u5B58\u5728:${projectPath}`);
|
|
31120
31738
|
}
|
|
31121
31739
|
const cliPath = input2.cliPath ?? process.env.WECHAT_DEVTOOLS_CLI ?? await findWechatDevToolsCli();
|
|
@@ -31142,561 +31760,1027 @@ function wechatideAdapterFactory(input2 = {}) {
|
|
|
31142
31760
|
};
|
|
31143
31761
|
}
|
|
31144
31762
|
|
|
31145
|
-
// ../../packages/
|
|
31146
|
-
|
|
31147
|
-
|
|
31148
|
-
|
|
31149
|
-
// ../../packages/evidence/src/log.ts
|
|
31150
|
-
import { appendFile, mkdir as mkdir2 } from "node:fs/promises";
|
|
31151
|
-
import { dirname as dirname2 } from "node:path";
|
|
31152
|
-
var RunLogger = class {
|
|
31153
|
-
constructor(filePath) {
|
|
31154
|
-
this.filePath = filePath;
|
|
31763
|
+
// ../../packages/adapter-api/src/index.ts
|
|
31764
|
+
var ApiAdapter = class {
|
|
31765
|
+
constructor(options = {}) {
|
|
31766
|
+
this.options = options;
|
|
31155
31767
|
}
|
|
31156
|
-
|
|
31157
|
-
|
|
31768
|
+
target = "api";
|
|
31769
|
+
last;
|
|
31770
|
+
async launch() {
|
|
31158
31771
|
}
|
|
31159
|
-
|
|
31160
|
-
|
|
31772
|
+
/** 相对 url 按 baseUrl 解析;已带协议的绝对地址原样发送 */
|
|
31773
|
+
resolveUrl(url2) {
|
|
31774
|
+
if (/^https?:\/\//i.test(url2)) return url2;
|
|
31775
|
+
const base = this.options.baseUrl?.replace(/\/$/, "");
|
|
31776
|
+
if (!base) {
|
|
31777
|
+
throw new TestPilotError("CONFIG_MISSING", `\u76F8\u5BF9 url "${url2}" \u9700\u8981\u5728 testpilot.yaml \u914D\u7F6E api.baseUrl`);
|
|
31778
|
+
}
|
|
31779
|
+
return `${base}/${url2.replace(/^\//, "")}`;
|
|
31780
|
+
}
|
|
31781
|
+
async request(request) {
|
|
31782
|
+
const url2 = this.resolveUrl(request.url);
|
|
31783
|
+
const headers = { ...request.headers ?? {} };
|
|
31784
|
+
let body;
|
|
31785
|
+
if (request.body !== void 0) {
|
|
31786
|
+
if (typeof request.body === "string") {
|
|
31787
|
+
body = request.body;
|
|
31788
|
+
} else {
|
|
31789
|
+
body = JSON.stringify(request.body);
|
|
31790
|
+
headers["content-type"] ??= "application/json";
|
|
31791
|
+
}
|
|
31792
|
+
}
|
|
31793
|
+
let res;
|
|
31794
|
+
try {
|
|
31795
|
+
res = await fetch(url2, {
|
|
31796
|
+
method: request.method.toUpperCase(),
|
|
31797
|
+
headers,
|
|
31798
|
+
body,
|
|
31799
|
+
signal: AbortSignal.timeout(this.options.timeoutMs ?? 15e3)
|
|
31800
|
+
});
|
|
31801
|
+
} catch (err) {
|
|
31802
|
+
throw new Error(`API \u8BF7\u6C42\u5931\u8D25 ${request.method.toUpperCase()} ${url2}:${err instanceof Error ? err.message : String(err)}`);
|
|
31803
|
+
}
|
|
31804
|
+
const bodyText = await res.text();
|
|
31805
|
+
let json2;
|
|
31806
|
+
if (bodyText) {
|
|
31807
|
+
try {
|
|
31808
|
+
json2 = JSON.parse(bodyText);
|
|
31809
|
+
} catch {
|
|
31810
|
+
json2 = void 0;
|
|
31811
|
+
}
|
|
31812
|
+
}
|
|
31813
|
+
const responseHeaders = {};
|
|
31814
|
+
res.headers.forEach((value, key) => {
|
|
31815
|
+
responseHeaders[key] = value;
|
|
31816
|
+
});
|
|
31817
|
+
this.last = { status: res.status, statusText: res.statusText, headers: responseHeaders, bodyText, json: json2 };
|
|
31818
|
+
return this.last;
|
|
31819
|
+
}
|
|
31820
|
+
async assertResponse(expected) {
|
|
31821
|
+
if (!this.last) throw new Error("\u5C1A\u672A\u53D1\u8D77\u4EFB\u4F55 API \u8BF7\u6C42,\u65E0\u6CD5\u65AD\u8A00\u54CD\u5E94");
|
|
31822
|
+
if (!this.last.bodyText.includes(expected)) {
|
|
31823
|
+
const snippet2 = this.last.bodyText.slice(0, 200);
|
|
31824
|
+
throw new Error(`\u54CD\u5E94\u4F53\u4E0D\u5305\u542B "${expected}":HTTP ${this.last.status} ${snippet2}`);
|
|
31825
|
+
}
|
|
31826
|
+
}
|
|
31827
|
+
async extractResponse(path) {
|
|
31828
|
+
if (!this.last) throw new Error("\u5C1A\u672A\u53D1\u8D77\u4EFB\u4F55 API \u8BF7\u6C42,\u65E0\u6CD5\u63D0\u53D6\u54CD\u5E94\u5B57\u6BB5");
|
|
31829
|
+
let current = this.last.json;
|
|
31830
|
+
if (current === void 0) throw new Error("\u54CD\u5E94\u4F53\u4E0D\u662F JSON,\u65E0\u6CD5\u6309 path \u63D0\u53D6");
|
|
31831
|
+
for (const segment of path.split(".")) {
|
|
31832
|
+
if (current === null || current === void 0) {
|
|
31833
|
+
throw new Error(`JSON path "${path}" \u5728 "${segment}" \u5904\u4E2D\u65AD:\u503C\u4E3A\u7A7A`);
|
|
31834
|
+
}
|
|
31835
|
+
if (Array.isArray(current)) {
|
|
31836
|
+
const index = Number(segment);
|
|
31837
|
+
if (!Number.isInteger(index) || index < 0 || index >= current.length) {
|
|
31838
|
+
throw new Error(`JSON path "${path}":\u6570\u7EC4\u4E0B\u6807 "${segment}" \u8D8A\u754C`);
|
|
31839
|
+
}
|
|
31840
|
+
current = current[index];
|
|
31841
|
+
} else if (typeof current === "object") {
|
|
31842
|
+
current = current[segment];
|
|
31843
|
+
} else {
|
|
31844
|
+
throw new Error(`JSON path "${path}" \u5728 "${segment}" \u5904\u4E2D\u65AD:\u5DF2\u662F\u6807\u91CF\u503C`);
|
|
31845
|
+
}
|
|
31846
|
+
}
|
|
31847
|
+
if (current === null || current === void 0) throw new Error(`JSON path "${path}" \u7684\u503C\u4E3A\u7A7A`);
|
|
31848
|
+
return typeof current === "object" ? JSON.stringify(current) : String(current);
|
|
31161
31849
|
}
|
|
31162
|
-
|
|
31163
|
-
|
|
31850
|
+
async close() {
|
|
31851
|
+
this.last = void 0;
|
|
31164
31852
|
}
|
|
31165
|
-
|
|
31166
|
-
|
|
31167
|
-
|
|
31168
|
-
`;
|
|
31169
|
-
await appendFile(this.filePath, line, "utf8");
|
|
31853
|
+
// ---- UI 能力:api 端不支持 ----
|
|
31854
|
+
unsupported(action) {
|
|
31855
|
+
throw new TestPilotError("UNSUPPORTED_ACTION", `api \u7AEF\u4E0D\u652F\u6301 "${action}"(\u4EC5\u652F\u6301 request / assert / extract)`);
|
|
31170
31856
|
}
|
|
31171
|
-
|
|
31172
|
-
|
|
31173
|
-
// ../../packages/evidence/src/screenshot.ts
|
|
31174
|
-
import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
|
|
31175
|
-
import { dirname as dirname3, join as join10 } from "node:path";
|
|
31176
|
-
async function saveScreenshot(dir, fileName, data) {
|
|
31177
|
-
const file2 = join10(dir, fileName);
|
|
31178
|
-
await mkdir3(dirname3(file2), { recursive: true });
|
|
31179
|
-
await writeFile3(file2, data);
|
|
31180
|
-
return file2;
|
|
31181
|
-
}
|
|
31182
|
-
|
|
31183
|
-
// ../../packages/evidence/src/trace.ts
|
|
31184
|
-
import { mkdir as mkdir4, writeFile as writeFile4 } from "node:fs/promises";
|
|
31185
|
-
import { dirname as dirname4, join as join11 } from "node:path";
|
|
31186
|
-
async function saveTrace(dir, fileName, data) {
|
|
31187
|
-
const file2 = join11(dir, fileName);
|
|
31188
|
-
await mkdir4(dirname4(file2), { recursive: true });
|
|
31189
|
-
await writeFile4(file2, data);
|
|
31190
|
-
return file2;
|
|
31191
|
-
}
|
|
31192
|
-
|
|
31193
|
-
// ../../packages/evidence/src/video.ts
|
|
31194
|
-
import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
|
|
31195
|
-
import { dirname as dirname5, join as join12 } from "node:path";
|
|
31196
|
-
async function saveVideo(dir, fileName, data) {
|
|
31197
|
-
const file2 = join12(dir, fileName);
|
|
31198
|
-
await mkdir5(dirname5(file2), { recursive: true });
|
|
31199
|
-
await writeFile5(file2, data);
|
|
31200
|
-
return file2;
|
|
31201
|
-
}
|
|
31202
|
-
|
|
31203
|
-
// ../../packages/execution-engine/src/artifacts/index.ts
|
|
31204
|
-
var ArtifactManager = class {
|
|
31205
|
-
constructor(runDir) {
|
|
31206
|
-
this.runDir = runDir;
|
|
31207
|
-
this.screenshotsDir = join13(runDir, "screenshots");
|
|
31208
|
-
this.videosDir = join13(runDir, "videos");
|
|
31209
|
-
this.tracesDir = join13(runDir, "traces");
|
|
31210
|
-
this.logsDir = join13(runDir, "logs");
|
|
31211
|
-
this.logger = new RunLogger(join13(this.logsDir, "run.log"));
|
|
31857
|
+
async navigate() {
|
|
31858
|
+
this.unsupported("navigate");
|
|
31212
31859
|
}
|
|
31213
|
-
|
|
31214
|
-
|
|
31215
|
-
tracesDir;
|
|
31216
|
-
logsDir;
|
|
31217
|
-
logger;
|
|
31218
|
-
async prepare() {
|
|
31219
|
-
await mkdir6(this.screenshotsDir, { recursive: true });
|
|
31220
|
-
await mkdir6(this.logsDir, { recursive: true });
|
|
31860
|
+
async click(_locator) {
|
|
31861
|
+
this.unsupported("click");
|
|
31221
31862
|
}
|
|
31222
|
-
|
|
31223
|
-
|
|
31224
|
-
await saveScreenshot(this.screenshotsDir, fileName, data);
|
|
31225
|
-
return `screenshots/${fileName}`;
|
|
31863
|
+
async input(_locator, _value) {
|
|
31864
|
+
this.unsupported("input");
|
|
31226
31865
|
}
|
|
31227
|
-
|
|
31228
|
-
|
|
31229
|
-
await saveVideo(this.videosDir, fileName, data);
|
|
31230
|
-
return `videos/${fileName}`;
|
|
31866
|
+
async select(_locator, _value) {
|
|
31867
|
+
this.unsupported("select");
|
|
31231
31868
|
}
|
|
31232
|
-
|
|
31233
|
-
|
|
31234
|
-
await saveTrace(this.tracesDir, fileName, data);
|
|
31235
|
-
return `traces/${fileName}`;
|
|
31869
|
+
async wait(_locator, _timeoutMs) {
|
|
31870
|
+
this.unsupported("wait");
|
|
31236
31871
|
}
|
|
31237
|
-
|
|
31238
|
-
|
|
31239
|
-
// ../../packages/execution-engine/src/context/index.ts
|
|
31240
|
-
var ExecutionContext = class {
|
|
31241
|
-
variables = /* @__PURE__ */ new Map();
|
|
31242
|
-
set(name, value) {
|
|
31243
|
-
this.variables.set(name, value);
|
|
31872
|
+
async assert(_locator, _expected) {
|
|
31873
|
+
this.unsupported("assert(locator)");
|
|
31244
31874
|
}
|
|
31245
|
-
|
|
31246
|
-
|
|
31875
|
+
async extract(_locator) {
|
|
31876
|
+
this.unsupported("extract(locator)");
|
|
31247
31877
|
}
|
|
31248
|
-
|
|
31249
|
-
|
|
31250
|
-
return template.replace(
|
|
31251
|
-
/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,
|
|
31252
|
-
(match, name) => this.variables.get(name) ?? match
|
|
31253
|
-
);
|
|
31878
|
+
async screenshot() {
|
|
31879
|
+
this.unsupported("screenshot");
|
|
31254
31880
|
}
|
|
31255
31881
|
};
|
|
31256
|
-
|
|
31257
|
-
|
|
31258
|
-
|
|
31259
|
-
|
|
31260
|
-
|
|
31261
|
-
const year = date5.getFullYear();
|
|
31262
|
-
const month = String(date5.getMonth() + 1).padStart(2, "0");
|
|
31263
|
-
const day = String(date5.getDate()).padStart(2, "0");
|
|
31264
|
-
return `${year}${month}${day}`;
|
|
31882
|
+
function apiAdapterFactory(options = {}) {
|
|
31883
|
+
return {
|
|
31884
|
+
target: "api",
|
|
31885
|
+
create: async () => new ApiAdapter(options)
|
|
31886
|
+
};
|
|
31265
31887
|
}
|
|
31266
|
-
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
|
|
31270
|
-
|
|
31271
|
-
|
|
31272
|
-
|
|
31273
|
-
|
|
31274
|
-
}
|
|
31888
|
+
|
|
31889
|
+
// ../../packages/sdk/src/runs.ts
|
|
31890
|
+
var RunError = class extends Error {
|
|
31891
|
+
code;
|
|
31892
|
+
constructor(code, message) {
|
|
31893
|
+
super(message);
|
|
31894
|
+
this.name = "RunError";
|
|
31895
|
+
this.code = code;
|
|
31275
31896
|
}
|
|
31276
|
-
|
|
31277
|
-
|
|
31278
|
-
|
|
31279
|
-
|
|
31280
|
-
|
|
31281
|
-
|
|
31897
|
+
};
|
|
31898
|
+
function createDefaultAdapters(config2) {
|
|
31899
|
+
return [
|
|
31900
|
+
playwrightAdapterFactory({ baseUrl: config2.web?.baseUrl }),
|
|
31901
|
+
wechatideAdapterFactory({
|
|
31902
|
+
projectPath: config2.miniapp?.projectPath,
|
|
31903
|
+
cliPath: config2.miniapp?.cliPath
|
|
31904
|
+
}),
|
|
31905
|
+
apiAdapterFactory({ baseUrl: config2.api?.baseUrl, timeoutMs: config2.api?.timeoutMs })
|
|
31906
|
+
];
|
|
31282
31907
|
}
|
|
31283
|
-
|
|
31284
|
-
|
|
31285
|
-
|
|
31286
|
-
|
|
31287
|
-
|
|
31288
|
-
|
|
31289
|
-
|
|
31290
|
-
|
|
31908
|
+
async function runCases(options = {}) {
|
|
31909
|
+
const root = resolveRoot(options.root);
|
|
31910
|
+
const config2 = await loadProjectConfig(root);
|
|
31911
|
+
const inputs = options.paths && options.paths.length > 0 ? options.paths.map((input2) => isAbsolute2(input2) ? input2 : join15(root, input2)) : [join15(root, config2.casesDir)];
|
|
31912
|
+
const cases = await collectCases(inputs, { root });
|
|
31913
|
+
if (cases.length === 0) {
|
|
31914
|
+
throw new RunError("ENO_CASES", `\u672A\u627E\u5230\u7528\u4F8B\u6587\u4EF6(\u67E5\u627E:${inputs.join(", ")})`);
|
|
31915
|
+
}
|
|
31916
|
+
const invalid = cases.filter((item) => !item.valid);
|
|
31917
|
+
const runnable = cases.filter(
|
|
31918
|
+
(item) => item.valid && item.case && (!options.tag || (item.case.tags ?? []).includes(options.tag))
|
|
31919
|
+
);
|
|
31920
|
+
const tagFiltered = cases.length - invalid.length - runnable.length;
|
|
31921
|
+
if (runnable.length === 0) {
|
|
31922
|
+
throw new RunError(
|
|
31923
|
+
"EINVALID_CASES",
|
|
31924
|
+
invalid.length > 0 ? "\u6240\u6709\u7528\u4F8B\u6821\u9A8C\u5931\u8D25,\u65E0\u53EF\u6267\u884C\u7528\u4F8B" : "\u6CA1\u6709\u5339\u914D\u7684\u7528\u4F8B"
|
|
31925
|
+
);
|
|
31926
|
+
}
|
|
31927
|
+
const factories = options.adapters ?? createDefaultAdapters(config2);
|
|
31928
|
+
const resolver = new AdapterResolver();
|
|
31929
|
+
for (const factory of factories) resolver.register(factory);
|
|
31930
|
+
const missingAccounts = [
|
|
31931
|
+
...new Set(
|
|
31932
|
+
runnable.map((item) => item.case?.accountRef).filter((ref) => !!ref && options.accounts?.[ref] === void 0)
|
|
31933
|
+
)
|
|
31934
|
+
];
|
|
31935
|
+
const runner = new TestRunner({
|
|
31936
|
+
resolver,
|
|
31937
|
+
runsRoot: join15(root, RUNS_DIR),
|
|
31938
|
+
runId: options.runId,
|
|
31939
|
+
onEvent: options.onEvent,
|
|
31940
|
+
signal: options.signal,
|
|
31941
|
+
accounts: options.accounts
|
|
31942
|
+
});
|
|
31943
|
+
const summary = await runner.run(
|
|
31944
|
+
runnable.map((item) => ({ data: item.case, file: item.file }))
|
|
31945
|
+
);
|
|
31946
|
+
return { summary, invalid, tagFiltered, missingAccounts };
|
|
31947
|
+
}
|
|
31948
|
+
function runsRoot(root) {
|
|
31949
|
+
return join15(resolveRoot(root), RUNS_DIR);
|
|
31950
|
+
}
|
|
31951
|
+
async function listRuns(options = {}) {
|
|
31952
|
+
const base = runsRoot(options.root);
|
|
31953
|
+
const entries = await readdir3(base).catch(() => []);
|
|
31954
|
+
const metas = [];
|
|
31955
|
+
for (const entry of entries.filter((name) => /^\d{8}-\d{3}$/.test(name)).sort().reverse()) {
|
|
31956
|
+
metas.push({ ...await readRunMeta(base, entry), runId: entry, dir: join15(base, entry) });
|
|
31957
|
+
}
|
|
31958
|
+
return metas;
|
|
31959
|
+
}
|
|
31960
|
+
async function latestRunId(options = {}) {
|
|
31961
|
+
const runs = await listRuns(options);
|
|
31962
|
+
return runs[0]?.runId;
|
|
31963
|
+
}
|
|
31964
|
+
async function getRun(runId, options = {}) {
|
|
31965
|
+
const base = runsRoot(options.root);
|
|
31966
|
+
const file2 = join15(base, runId, RESULT_FILE);
|
|
31967
|
+
try {
|
|
31968
|
+
return JSON.parse(await readFile5(file2, "utf8"));
|
|
31969
|
+
} catch {
|
|
31970
|
+
throw new RunError("ENO_CASES", `\u8BFB\u53D6\u8FD0\u884C\u7ED3\u679C\u5931\u8D25:${file2}(\u8FD0\u884C\u672A\u5B8C\u6210\u6216 runId \u4E0D\u5B58\u5728)`);
|
|
31291
31971
|
}
|
|
31292
|
-
|
|
31293
|
-
|
|
31294
|
-
|
|
31295
|
-
|
|
31972
|
+
}
|
|
31973
|
+
async function getRunEvents(runId, options = {}) {
|
|
31974
|
+
const file2 = join15(runsRoot(options.root), runId, "events.ndjson");
|
|
31975
|
+
const source = await readFile5(file2, "utf8").catch(() => "");
|
|
31976
|
+
return source.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
|
|
31977
|
+
}
|
|
31978
|
+
async function readRunMeta(base, runId) {
|
|
31979
|
+
try {
|
|
31980
|
+
const summary = JSON.parse(
|
|
31981
|
+
await readFile5(join15(base, runId, RESULT_FILE), "utf8")
|
|
31982
|
+
);
|
|
31983
|
+
return {
|
|
31984
|
+
status: summary.status,
|
|
31985
|
+
cancelled: summary.cancelled,
|
|
31986
|
+
startedAt: summary.startedAt,
|
|
31987
|
+
finishedAt: summary.finishedAt,
|
|
31988
|
+
durationMs: summary.durationMs,
|
|
31989
|
+
totals: summary.totals
|
|
31990
|
+
};
|
|
31991
|
+
} catch {
|
|
31992
|
+
return { status: "unknown" };
|
|
31296
31993
|
}
|
|
31297
|
-
};
|
|
31298
|
-
function ndjsonSubscriber(filePath) {
|
|
31299
|
-
return async (event) => {
|
|
31300
|
-
await mkdir8(dirname6(filePath), { recursive: true });
|
|
31301
|
-
await appendFile2(filePath, `${JSON.stringify(event)}
|
|
31302
|
-
`, "utf8");
|
|
31303
|
-
};
|
|
31304
31994
|
}
|
|
31305
31995
|
|
|
31306
|
-
// ../../packages/
|
|
31307
|
-
async function
|
|
31308
|
-
const
|
|
31309
|
-
|
|
31310
|
-
|
|
31996
|
+
// ../../packages/sdk/src/reports.ts
|
|
31997
|
+
async function generateReport(runId, options = {}) {
|
|
31998
|
+
const id = runId ?? await latestRunId(options);
|
|
31999
|
+
if (!id) {
|
|
32000
|
+
throw new Error("\u672A\u627E\u5230\u8FD0\u884C\u8BB0\u5F55(\u5148\u8FD0\u884C\u4E00\u6B21\u7528\u4F8B)");
|
|
32001
|
+
}
|
|
32002
|
+
const runDir = join16(resolveRoot(options.root), RUNS_DIR, id);
|
|
32003
|
+
let summary;
|
|
32004
|
+
try {
|
|
32005
|
+
summary = JSON.parse(await readFile6(join16(runDir, "result.json"), "utf8"));
|
|
32006
|
+
} catch {
|
|
32007
|
+
throw new Error(`\u8BFB\u53D6\u8FD0\u884C\u7ED3\u679C\u5931\u8D25:${join16(runDir, "result.json")}(\u8FD0\u884C\u672A\u5B8C\u6210\u6216 runId \u4E0D\u5B58\u5728)`);
|
|
31311
32008
|
}
|
|
31312
|
-
|
|
32009
|
+
const written = await writeReports(runDir, summary);
|
|
32010
|
+
return { runId: id, json: written.json, html: written.html };
|
|
32011
|
+
}
|
|
32012
|
+
async function readReport(runId, options = {}) {
|
|
32013
|
+
const file2 = join16(resolveRoot(options.root), RUNS_DIR, runId, "report.json");
|
|
32014
|
+
const source = await readFile6(file2, "utf8").catch(() => void 0);
|
|
32015
|
+
return source ? JSON.parse(source) : void 0;
|
|
31313
32016
|
}
|
|
31314
32017
|
|
|
31315
|
-
// ../../packages/
|
|
31316
|
-
|
|
31317
|
-
|
|
31318
|
-
|
|
31319
|
-
|
|
32018
|
+
// ../../packages/sdk/src/client.ts
|
|
32019
|
+
function resolveInput(root, input2) {
|
|
32020
|
+
return isAbsolute3(input2) ? input2 : join17(root, input2);
|
|
32021
|
+
}
|
|
32022
|
+
var TestPilotClient = class {
|
|
32023
|
+
/** 业务项目根目录(绝对路径) */
|
|
32024
|
+
root;
|
|
32025
|
+
constructor(options = {}) {
|
|
32026
|
+
this.root = resolveRoot(options.root);
|
|
32027
|
+
}
|
|
32028
|
+
// ---- project ----
|
|
32029
|
+
/** 读取项目配置(testpilot.yaml 不存在时返回默认配置) */
|
|
32030
|
+
getConfig() {
|
|
32031
|
+
return loadProjectConfig(this.root);
|
|
32032
|
+
}
|
|
32033
|
+
/** 项目自检:目录结构 / 配置 / Skill 安装状态 / 可用执行端 */
|
|
32034
|
+
inspect() {
|
|
32035
|
+
return inspectProject(this.root);
|
|
32036
|
+
}
|
|
32037
|
+
/** 读取本地项目与 Server Project 的关联(.testpilot/project.json) */
|
|
32038
|
+
getProjectLink() {
|
|
32039
|
+
return readProjectLink(this.root);
|
|
32040
|
+
}
|
|
32041
|
+
/** 写入本地项目与 Server Project 的关联 */
|
|
32042
|
+
linkProject(link) {
|
|
32043
|
+
return writeProjectLink(link, this.root);
|
|
32044
|
+
}
|
|
32045
|
+
// ---- cases ----
|
|
32046
|
+
/** 收集并校验用例;paths 相对本项目根目录,默认按配置的 casesDir */
|
|
32047
|
+
async listCases(paths, tag) {
|
|
32048
|
+
const config2 = await this.getConfig();
|
|
32049
|
+
const inputs = paths && paths.length > 0 ? paths : [config2.casesDir];
|
|
32050
|
+
const infos = await collectCases(inputs.map((input2) => resolveInput(this.root, input2)), {
|
|
32051
|
+
root: this.root
|
|
32052
|
+
});
|
|
32053
|
+
return tag ? infos.filter((item) => item.case?.tags?.includes(tag)) : infos;
|
|
31320
32054
|
}
|
|
31321
|
-
|
|
31322
|
-
|
|
31323
|
-
return this.
|
|
32055
|
+
/** 读取单个用例:source 原文 + 校验结果 */
|
|
32056
|
+
readCase(file2) {
|
|
32057
|
+
return readCaseFile(file2, { root: this.root });
|
|
31324
32058
|
}
|
|
31325
|
-
/**
|
|
31326
|
-
|
|
31327
|
-
|
|
31328
|
-
this.adapter = await this.factory.create();
|
|
31329
|
-
await this.adapter.launch();
|
|
31330
|
-
}
|
|
31331
|
-
return this.adapter;
|
|
32059
|
+
/** 写入用例(供 Agent 的 create_case 工具使用):先校验后落盘 */
|
|
32060
|
+
writeCase(file2, source, options = {}) {
|
|
32061
|
+
return writeCaseFile(file2, source, { root: this.root, ...options });
|
|
31332
32062
|
}
|
|
31333
|
-
|
|
31334
|
-
|
|
31335
|
-
|
|
31336
|
-
|
|
31337
|
-
}
|
|
32063
|
+
// ---- runs ----
|
|
32064
|
+
/** 执行一次运行 */
|
|
32065
|
+
runCases(options = {}) {
|
|
32066
|
+
return runCases({ ...options, root: this.root });
|
|
31338
32067
|
}
|
|
31339
|
-
|
|
31340
|
-
|
|
31341
|
-
|
|
31342
|
-
var AdapterResolver = class {
|
|
31343
|
-
factories = /* @__PURE__ */ new Map();
|
|
31344
|
-
sessions = /* @__PURE__ */ new Map();
|
|
31345
|
-
register(factory) {
|
|
31346
|
-
this.factories.set(factory.target, factory);
|
|
32068
|
+
/** 历史运行列表(最近的在前) */
|
|
32069
|
+
listRuns() {
|
|
32070
|
+
return listRuns({ root: this.root });
|
|
31347
32071
|
}
|
|
31348
|
-
/**
|
|
31349
|
-
|
|
31350
|
-
|
|
31351
|
-
if (!session) {
|
|
31352
|
-
const factory = this.factories.get(target);
|
|
31353
|
-
if (!factory) {
|
|
31354
|
-
throw new TestPilotError("ADAPTER_NOT_FOUND", `\u672A\u6CE8\u518C target "${target}" \u7684 adapter,\u8BE5\u7AEF\u6B65\u9AA4\u65E0\u6CD5\u6267\u884C`);
|
|
31355
|
-
}
|
|
31356
|
-
session = new AdapterSession(target, factory);
|
|
31357
|
-
this.sessions.set(target, session);
|
|
31358
|
-
}
|
|
31359
|
-
return session;
|
|
32072
|
+
/** 读取一次运行的汇总结果(result.json) */
|
|
32073
|
+
getRun(runId) {
|
|
32074
|
+
return getRun(runId, { root: this.root });
|
|
31360
32075
|
}
|
|
31361
|
-
|
|
31362
|
-
|
|
31363
|
-
|
|
31364
|
-
|
|
31365
|
-
|
|
32076
|
+
/** 读取一次运行的完整事件流(events.ndjson) */
|
|
32077
|
+
getRunEvents(runId) {
|
|
32078
|
+
return getRunEvents(runId, { root: this.root });
|
|
32079
|
+
}
|
|
32080
|
+
// ---- reports ----
|
|
32081
|
+
/** 生成报告(默认最近一次运行) */
|
|
32082
|
+
generateReport(runId) {
|
|
32083
|
+
return generateReport(runId, { root: this.root });
|
|
32084
|
+
}
|
|
32085
|
+
/** 读取已生成的报告 */
|
|
32086
|
+
readReport(runId) {
|
|
32087
|
+
return readReport(runId, { root: this.root });
|
|
31366
32088
|
}
|
|
31367
32089
|
};
|
|
31368
32090
|
|
|
31369
|
-
//
|
|
31370
|
-
|
|
31371
|
-
|
|
31372
|
-
|
|
31373
|
-
|
|
31374
|
-
|
|
31375
|
-
|
|
31376
|
-
|
|
31377
|
-
|
|
31378
|
-
|
|
31379
|
-
|
|
31380
|
-
|
|
31381
|
-
|
|
31382
|
-
|
|
31383
|
-
|
|
31384
|
-
|
|
31385
|
-
|
|
31386
|
-
|
|
31387
|
-
|
|
31388
|
-
|
|
31389
|
-
|
|
31390
|
-
break;
|
|
31391
|
-
case "click":
|
|
31392
|
-
await adapter.click(locator);
|
|
31393
|
-
break;
|
|
31394
|
-
case "input":
|
|
31395
|
-
await adapter.input(locator, context.resolve(step.value ?? ""));
|
|
31396
|
-
break;
|
|
31397
|
-
case "select":
|
|
31398
|
-
await adapter.select(locator, context.resolve(step.value ?? ""));
|
|
31399
|
-
break;
|
|
31400
|
-
case "wait":
|
|
31401
|
-
await adapter.wait(locator, step.timeout);
|
|
31402
|
-
break;
|
|
31403
|
-
case "assert":
|
|
31404
|
-
await adapter.assert(locator, context.resolve(step.expected ?? ""));
|
|
31405
|
-
break;
|
|
31406
|
-
case "extract": {
|
|
31407
|
-
const value = await adapter.extract(locator);
|
|
31408
|
-
if (step.variable) {
|
|
31409
|
-
context.set(step.variable, value);
|
|
31410
|
-
result.extracted = { [step.variable]: value };
|
|
31411
|
-
}
|
|
31412
|
-
break;
|
|
31413
|
-
}
|
|
31414
|
-
case "screenshot": {
|
|
31415
|
-
const data = await adapter.screenshot();
|
|
31416
|
-
result.screenshot = await artifacts.saveStepScreenshot(`${options.screenshotName}.png`, data);
|
|
31417
|
-
break;
|
|
31418
|
-
}
|
|
31419
|
-
default: {
|
|
31420
|
-
const exhaustive = step.action;
|
|
31421
|
-
throw new Error(`\u4E0D\u652F\u6301\u7684 action:${String(exhaustive)}`);
|
|
31422
|
-
}
|
|
31423
|
-
}
|
|
31424
|
-
} catch (err) {
|
|
31425
|
-
result.status = "failed";
|
|
31426
|
-
result.error = err instanceof Error ? err.message : String(err);
|
|
31427
|
-
try {
|
|
31428
|
-
const data = await adapter.screenshot();
|
|
31429
|
-
result.screenshot = await artifacts.saveStepScreenshot(`${options.screenshotName}-failed.png`, data);
|
|
31430
|
-
} catch {
|
|
32091
|
+
// src/commands/init/adapter-detector.ts
|
|
32092
|
+
import { existsSync as existsSync4, readFileSync } from "node:fs";
|
|
32093
|
+
import { join as join18 } from "node:path";
|
|
32094
|
+
async function detectAdapters(root, projectType) {
|
|
32095
|
+
const required2 = projectType === "hybrid" ? ["playwright", "wechatide"] : projectType === "wechat-miniapp" ? ["wechatide"] : projectType === "web" ? ["playwright"] : [];
|
|
32096
|
+
const pkg = readPackageJsonDeps(root);
|
|
32097
|
+
const hasPlaywrightDep = pkg !== void 0 && ("playwright" in pkg || "@playwright/test" in pkg);
|
|
32098
|
+
const playwrightInstalled = hasPlaywrightDep || existsSync4(join18(root, "node_modules", "playwright"));
|
|
32099
|
+
const devtoolsCli = await findWechatDevToolsCli().catch(() => void 0);
|
|
32100
|
+
return [
|
|
32101
|
+
{
|
|
32102
|
+
id: "playwright",
|
|
32103
|
+
available: playwrightInstalled,
|
|
32104
|
+
detail: playwrightInstalled ? pkg?.["playwright"] ?? pkg?.["@playwright/test"] ?? "\u5DF2\u5B89\u88C5" : "\u672A\u68C0\u6D4B\u5230(pnpm add -D playwright)",
|
|
32105
|
+
required: required2.includes("playwright")
|
|
32106
|
+
},
|
|
32107
|
+
{
|
|
32108
|
+
id: "wechatide",
|
|
32109
|
+
available: devtoolsCli !== void 0,
|
|
32110
|
+
detail: devtoolsCli ?? "\u672A\u627E\u5230\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177(\u53EF\u8BBE\u7F6E WECHAT_DEVTOOLS_CLI \u6307\u5411 cli \u53EF\u6267\u884C\u6587\u4EF6)",
|
|
32111
|
+
required: required2.includes("wechatide")
|
|
31431
32112
|
}
|
|
31432
|
-
|
|
31433
|
-
result.durationMs = Date.now() - startedAt;
|
|
31434
|
-
return result;
|
|
32113
|
+
];
|
|
31435
32114
|
}
|
|
31436
|
-
|
|
31437
|
-
|
|
31438
|
-
|
|
31439
|
-
|
|
31440
|
-
const
|
|
31441
|
-
|
|
31442
|
-
|
|
31443
|
-
|
|
31444
|
-
const evidenceAdapters = /* @__PURE__ */ new Map();
|
|
31445
|
-
let caseError;
|
|
31446
|
-
await bus.emit({ type: "case-started", runId, caseId: data.id, file: file2, ts: startedAt.toISOString() });
|
|
31447
|
-
await artifacts.logger.info(`case ${data.id} started (${file2})`);
|
|
31448
|
-
for (const [index, step] of data.steps.entries()) {
|
|
31449
|
-
await bus.emit({
|
|
31450
|
-
type: "step-started",
|
|
31451
|
-
runId,
|
|
31452
|
-
caseId: data.id,
|
|
31453
|
-
index,
|
|
31454
|
-
target: step.target,
|
|
31455
|
-
action: step.action,
|
|
31456
|
-
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
31457
|
-
});
|
|
31458
|
-
let result;
|
|
31459
|
-
try {
|
|
31460
|
-
const adapter = await (await resolver.session(step.target)).get();
|
|
31461
|
-
if (adapter.startEvidence && !evidenceAdapters.has(step.target)) {
|
|
31462
|
-
try {
|
|
31463
|
-
await adapter.startEvidence(data.id);
|
|
31464
|
-
evidenceAdapters.set(step.target, adapter);
|
|
31465
|
-
} catch (err) {
|
|
31466
|
-
await artifacts.logger.info(
|
|
31467
|
-
`evidence start failed for ${step.target}: ${err instanceof Error ? err.message : String(err)}`
|
|
31468
|
-
);
|
|
31469
|
-
}
|
|
31470
|
-
}
|
|
31471
|
-
result = await executeStep(step, index, adapter, context, artifacts, {
|
|
31472
|
-
screenshotName: `${data.id}-step-${String(index).padStart(2, "0")}`
|
|
31473
|
-
});
|
|
31474
|
-
} catch (err) {
|
|
31475
|
-
result = {
|
|
31476
|
-
index,
|
|
31477
|
-
target: step.target,
|
|
31478
|
-
action: step.action,
|
|
31479
|
-
status: "failed",
|
|
31480
|
-
durationMs: 0,
|
|
31481
|
-
error: err instanceof Error ? err.message : String(err)
|
|
31482
|
-
};
|
|
31483
|
-
}
|
|
31484
|
-
steps.push(result);
|
|
31485
|
-
await artifacts.logger.info(`step ${index} ${step.action} -> ${result.status}${result.error ? ` - ${result.error}` : ""}`);
|
|
31486
|
-
await bus.emit({
|
|
31487
|
-
type: "step-finished",
|
|
31488
|
-
runId,
|
|
31489
|
-
caseId: data.id,
|
|
31490
|
-
index,
|
|
31491
|
-
target: step.target,
|
|
31492
|
-
action: step.action,
|
|
31493
|
-
status: result.status,
|
|
31494
|
-
durationMs: result.durationMs,
|
|
31495
|
-
error: result.error,
|
|
31496
|
-
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
31497
|
-
});
|
|
31498
|
-
if (result.status === "failed") {
|
|
31499
|
-
caseError = result.error;
|
|
31500
|
-
for (const [skipIndex, skippedStep] of data.steps.entries()) {
|
|
31501
|
-
if (skipIndex <= index) continue;
|
|
31502
|
-
steps.push({
|
|
31503
|
-
index: skipIndex,
|
|
31504
|
-
target: skippedStep.target,
|
|
31505
|
-
action: skippedStep.action,
|
|
31506
|
-
status: "skipped",
|
|
31507
|
-
durationMs: 0
|
|
31508
|
-
});
|
|
31509
|
-
}
|
|
31510
|
-
break;
|
|
31511
|
-
}
|
|
31512
|
-
}
|
|
31513
|
-
const finishedAt = /* @__PURE__ */ new Date();
|
|
31514
|
-
const status = caseError ? "failed" : "passed";
|
|
31515
|
-
const caseResult = {
|
|
31516
|
-
caseId: data.id,
|
|
31517
|
-
caseName: data.name,
|
|
31518
|
-
file: file2,
|
|
31519
|
-
status,
|
|
31520
|
-
steps,
|
|
31521
|
-
startedAt: startedAt.toISOString(),
|
|
31522
|
-
finishedAt: finishedAt.toISOString(),
|
|
31523
|
-
durationMs: finishedAt.getTime() - startedAt.getTime()
|
|
31524
|
-
};
|
|
31525
|
-
if (caseError) caseResult.error = caseError;
|
|
31526
|
-
for (const [target, adapter] of evidenceAdapters) {
|
|
31527
|
-
if (!adapter.stopEvidence) continue;
|
|
31528
|
-
try {
|
|
31529
|
-
const evidence = await adapter.stopEvidence(data.id);
|
|
31530
|
-
if (evidence.video) {
|
|
31531
|
-
caseResult.video = await artifacts.saveVideo(`${data.id}-${target}.webm`, evidence.video);
|
|
31532
|
-
}
|
|
31533
|
-
if (evidence.trace) {
|
|
31534
|
-
caseResult.trace = await artifacts.saveTrace(`${data.id}-${target}.zip`, evidence.trace);
|
|
31535
|
-
}
|
|
31536
|
-
} catch (err) {
|
|
31537
|
-
await artifacts.logger.info(
|
|
31538
|
-
`evidence stop failed for ${target}: ${err instanceof Error ? err.message : String(err)}`
|
|
31539
|
-
);
|
|
31540
|
-
}
|
|
31541
|
-
}
|
|
31542
|
-
await bus.emit({
|
|
31543
|
-
type: "case-finished",
|
|
31544
|
-
runId,
|
|
31545
|
-
caseId: data.id,
|
|
31546
|
-
status,
|
|
31547
|
-
durationMs: finishedAt.getTime() - startedAt.getTime(),
|
|
31548
|
-
ts: finishedAt.toISOString()
|
|
31549
|
-
});
|
|
31550
|
-
await artifacts.logger.info(`case ${data.id} ${status}`);
|
|
31551
|
-
return caseResult;
|
|
32115
|
+
function readPackageJsonDeps(root) {
|
|
32116
|
+
const file2 = join18(root, "package.json");
|
|
32117
|
+
if (!existsSync4(file2)) return void 0;
|
|
32118
|
+
try {
|
|
32119
|
+
const pkg = JSON.parse(readFileSync(file2, "utf8"));
|
|
32120
|
+
return { ...pkg.dependencies, ...pkg.devDependencies };
|
|
32121
|
+
} catch {
|
|
32122
|
+
return void 0;
|
|
31552
32123
|
}
|
|
31553
|
-
}
|
|
32124
|
+
}
|
|
31554
32125
|
|
|
31555
|
-
//
|
|
31556
|
-
|
|
31557
|
-
|
|
31558
|
-
|
|
31559
|
-
|
|
31560
|
-
|
|
31561
|
-
|
|
31562
|
-
|
|
31563
|
-
|
|
31564
|
-
|
|
31565
|
-
|
|
32126
|
+
// src/commands/init/environment-initializer.ts
|
|
32127
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
32128
|
+
import { join as join19 } from "node:path";
|
|
32129
|
+
var ENV_REF_PATTERN = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
32130
|
+
async function collectEnvVarRefs(root) {
|
|
32131
|
+
let text;
|
|
32132
|
+
try {
|
|
32133
|
+
text = await readFile7(join19(root, "testpilot.yaml"), "utf8");
|
|
32134
|
+
} catch {
|
|
32135
|
+
return [];
|
|
32136
|
+
}
|
|
32137
|
+
const names = /* @__PURE__ */ new Set();
|
|
32138
|
+
for (const match of text.matchAll(ENV_REF_PATTERN)) {
|
|
32139
|
+
names.add(match[1]);
|
|
32140
|
+
}
|
|
32141
|
+
return [...names].sort();
|
|
32142
|
+
}
|
|
32143
|
+
|
|
32144
|
+
// src/commands/init/project-detector.ts
|
|
32145
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
32146
|
+
import { basename, join as join20 } from "node:path";
|
|
32147
|
+
|
|
32148
|
+
// src/lib/git.ts
|
|
32149
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
32150
|
+
import { promisify } from "node:util";
|
|
32151
|
+
var execFileAsync = promisify(execFile2);
|
|
32152
|
+
async function readGitInfo(root) {
|
|
32153
|
+
const run = async (args) => {
|
|
32154
|
+
try {
|
|
32155
|
+
const { stdout } = await execFileAsync("git", args, { cwd: root });
|
|
32156
|
+
return stdout.trim() || void 0;
|
|
32157
|
+
} catch {
|
|
32158
|
+
return void 0;
|
|
32159
|
+
}
|
|
31566
32160
|
};
|
|
31567
|
-
|
|
31568
|
-
|
|
31569
|
-
|
|
31570
|
-
|
|
31571
|
-
|
|
31572
|
-
|
|
32161
|
+
const [branch, commit, repositoryUrl] = await Promise.all([
|
|
32162
|
+
run(["rev-parse", "--abbrev-ref", "HEAD"]),
|
|
32163
|
+
run(["rev-parse", "HEAD"]),
|
|
32164
|
+
run(["remote", "get-url", "origin"])
|
|
32165
|
+
]);
|
|
32166
|
+
return { branch, commit, repositoryUrl };
|
|
32167
|
+
}
|
|
32168
|
+
|
|
32169
|
+
// src/commands/init/project-detector.ts
|
|
32170
|
+
var WEB_DEP_MARKERS = [
|
|
32171
|
+
"playwright",
|
|
32172
|
+
"@playwright/test",
|
|
32173
|
+
"vite",
|
|
32174
|
+
"next",
|
|
32175
|
+
"react",
|
|
32176
|
+
"vue",
|
|
32177
|
+
"@angular/core",
|
|
32178
|
+
"nuxt",
|
|
32179
|
+
"svelte"
|
|
32180
|
+
];
|
|
32181
|
+
var E2E_DIR_CANDIDATES = ["tests/e2e", "test/e2e", "e2e", "cypress"];
|
|
32182
|
+
function readPackageJson(root) {
|
|
32183
|
+
const file2 = join20(root, "package.json");
|
|
32184
|
+
if (!existsSync5(file2)) return void 0;
|
|
32185
|
+
try {
|
|
32186
|
+
return JSON.parse(readFileSync2(file2, "utf8"));
|
|
32187
|
+
} catch {
|
|
32188
|
+
return void 0;
|
|
32189
|
+
}
|
|
32190
|
+
}
|
|
32191
|
+
function detectProjectType(root) {
|
|
32192
|
+
const pkg = readPackageJson(root);
|
|
32193
|
+
const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
32194
|
+
const isWechat = existsSync5(join20(root, "project.config.json")) || existsSync5(join20(root, "app.json")) || existsSync5(join20(root, "miniprogram", "app.json"));
|
|
32195
|
+
const isWeb = existsSync5(join20(root, "index.html")) || WEB_DEP_MARKERS.some((marker) => deps?.[marker] !== void 0) || [".ts", ".tsx", ".js", ".jsx"].some((ext) => existsSync5(join20(root, "src", `index${ext}`)));
|
|
32196
|
+
if (isWechat && isWeb) return "hybrid";
|
|
32197
|
+
if (isWechat) return "wechat-miniapp";
|
|
32198
|
+
if (isWeb) return "web";
|
|
32199
|
+
return "unknown";
|
|
32200
|
+
}
|
|
32201
|
+
async function detectProject(root) {
|
|
32202
|
+
const pkg = readPackageJson(root);
|
|
32203
|
+
const type = detectProjectType(root);
|
|
32204
|
+
const language = existsSync5(join20(root, "tsconfig.json")) ? "TypeScript" : pkg || existsSync5(join20(root, "src")) ? "JavaScript" : "Unknown";
|
|
32205
|
+
const packageManager = existsSync5(join20(root, "pnpm-lock.yaml")) ? "pnpm" : existsSync5(join20(root, "yarn.lock")) ? "yarn" : existsSync5(join20(root, "package-lock.json")) ? "npm" : "npx";
|
|
32206
|
+
const existingE2eDirs = E2E_DIR_CANDIDATES.filter((dir) => existsSync5(join20(root, dir)));
|
|
32207
|
+
return {
|
|
32208
|
+
root,
|
|
32209
|
+
name: pkg?.name ?? basename(root),
|
|
32210
|
+
type,
|
|
32211
|
+
language,
|
|
32212
|
+
packageManager,
|
|
32213
|
+
git: await readGitInfo(root),
|
|
32214
|
+
hasTestsE2e: existingE2eDirs.includes("tests/e2e"),
|
|
32215
|
+
existingE2eDirs,
|
|
32216
|
+
hasTestpilotConfig: existsSync5(join20(root, "testpilot.yaml")),
|
|
32217
|
+
hasProjectLink: existsSync5(join20(root, ".testpilot", "project.json"))
|
|
32218
|
+
};
|
|
32219
|
+
}
|
|
32220
|
+
function defaultAdapterFor(type) {
|
|
32221
|
+
if (type === "wechat-miniapp") return "wechatide";
|
|
32222
|
+
return "playwright";
|
|
32223
|
+
}
|
|
32224
|
+
function adaptersFor(type) {
|
|
32225
|
+
if (type === "hybrid") return ["playwright", "wechatide"];
|
|
32226
|
+
if (type === "wechat-miniapp") return ["wechatide"];
|
|
32227
|
+
if (type === "web") return ["playwright"];
|
|
32228
|
+
return ["playwright"];
|
|
32229
|
+
}
|
|
32230
|
+
|
|
32231
|
+
// src/commands/init/doctor.ts
|
|
32232
|
+
async function runDoctor(root) {
|
|
32233
|
+
const sections = [];
|
|
32234
|
+
const push = (name, items) => {
|
|
32235
|
+
if (items.length > 0) sections.push({ name, items });
|
|
32236
|
+
};
|
|
32237
|
+
const ok = (label) => ({ status: "ok", label });
|
|
32238
|
+
const warn = (label, hint) => ({ status: "warn", label, hint });
|
|
32239
|
+
const error62 = (label, hint) => ({ status: "error", label, hint });
|
|
32240
|
+
const info = await detectProject(root);
|
|
32241
|
+
const runtimeItems = [];
|
|
32242
|
+
const nodeMajor = Number(process.versions.node.split(".")[0]);
|
|
32243
|
+
runtimeItems.push(
|
|
32244
|
+
nodeMajor >= 22 ? ok(`Node.js ${process.versions.node}`) : error62(`Node.js ${process.versions.node}`, "\u9700\u8981 Node.js >= 22")
|
|
32245
|
+
);
|
|
32246
|
+
if (info.packageManager !== "npx") runtimeItems.push(ok(`Package Manager ${info.packageManager}`));
|
|
32247
|
+
else runtimeItems.push(warn("Package Manager \u672A\u8BC6\u522B", "\u672A\u53D1\u73B0 pnpm/yarn/npm lockfile"));
|
|
32248
|
+
runtimeItems.push(
|
|
32249
|
+
info.git.commit ? ok("Git") : warn("Git \u672A\u68C0\u6D4B\u5230", "Case Metadata \u65E0\u6CD5\u540C\u6B65\u5230 Server")
|
|
32250
|
+
);
|
|
32251
|
+
push("Runtime", runtimeItems);
|
|
32252
|
+
const projectItems = [
|
|
32253
|
+
ok(`Project ${info.name}(${info.type})`),
|
|
32254
|
+
info.git.commit ? ok(`Git repository(${info.git.branch ?? "detached"} \xB7 ${info.git.commit.slice(0, 7)})`) : warn("Git repository \u672A\u68C0\u6D4B\u5230", "Case Metadata \u65E0\u6CD5\u540C\u6B65\u5230 Server"),
|
|
32255
|
+
existsSync6(join21(root, ".testpilot", "project.json")) ? ok(".testpilot/project.json") : error62(".testpilot/project.json", "\u8FD0\u884C npx csspilot init \u751F\u6210"),
|
|
32256
|
+
existsSync6(join21(root, "testpilot.yaml")) ? ok("testpilot.yaml") : error62("testpilot.yaml", "\u8FD0\u884C npx csspilot init \u751F\u6210")
|
|
32257
|
+
];
|
|
32258
|
+
push("Project", projectItems);
|
|
32259
|
+
const config2 = await loadTestpilotConfig(root).catch(() => void 0);
|
|
32260
|
+
const casesDir = config2?.casesDir ?? "tests/e2e/cases";
|
|
32261
|
+
const cases = await collectCases([join21(root, casesDir)], { root }).catch(() => []);
|
|
32262
|
+
const invalidCount = cases.filter((item) => !item.valid).length;
|
|
32263
|
+
const testDir = join21(root, "tests", "e2e");
|
|
32264
|
+
push("Test", [
|
|
32265
|
+
existsSync6(testDir) ? ok("tests/e2e") : error62("tests/e2e", "\u8FD0\u884C npx csspilot init \u521B\u5EFA"),
|
|
32266
|
+
existsSync6(join21(root, casesDir)) ? ok(`cases directory(${casesDir})`) : error62(`cases directory(${casesDir})`, "\u8FD0\u884C npx csspilot init \u521B\u5EFA"),
|
|
32267
|
+
cases.length === 0 ? warn("Case validation \u8DF3\u8FC7(\u672A\u627E\u5230\u7528\u4F8B)", "\u5728 tests/e2e/cases \u521B\u5EFA Case") : invalidCount === 0 ? ok(`Case validation(${cases.length} \u4E2A\u7528\u4F8B\u5168\u90E8\u6709\u6548)`) : error62(`Case validation(${invalidCount}/${cases.length} \u4E2A\u7528\u4F8B\u6821\u9A8C\u5931\u8D25)`, "\u8FD0\u884C npx csspilot validate \u67E5\u770B\u8BE6\u60C5")
|
|
32268
|
+
]);
|
|
32269
|
+
const skillDir = join21(root, ".agents", "skills", "testpilot");
|
|
32270
|
+
push("Agent", [
|
|
32271
|
+
existsSync6(join21(skillDir, "manifest.yaml")) ? ok("TestPilot Skill(.agents/skills/testpilot)") : error62("TestPilot Skill", "\u8FD0\u884C npx csspilot init \u5B89\u88C5"),
|
|
32272
|
+
existsSync6(join21(skillDir, "references", "project.md")) ? ok("Project testing guide(references/)") : warn("Project testing guide \u7F3A\u5931", "references/ \u7531 init \u751F\u6210;\u53EF\u91CD\u65B0\u8FD0\u884C npx csspilot init")
|
|
32273
|
+
]);
|
|
32274
|
+
const adapters = await detectAdapters(root, info.type);
|
|
32275
|
+
push(
|
|
32276
|
+
"Adapters",
|
|
32277
|
+
adapters.map(
|
|
32278
|
+
(item) => item.available ? ok(`${item.id}(${item.detail})`) : item.required ? warn(`${item.id} \u4E0D\u53EF\u7528`, item.detail) : warn(`${item.id} \u672A\u5B89\u88C5(\u53EF\u9009)`, item.detail)
|
|
32279
|
+
)
|
|
32280
|
+
);
|
|
32281
|
+
const refs = await collectEnvVarRefs(root);
|
|
32282
|
+
const envItems = refs.map(
|
|
32283
|
+
(name) => process.env[name] !== void 0 ? ok(name) : error62(`${name} missing`, "\u5728\u8FD0\u884C\u73AF\u5883(.env / CI Secret)\u4E2D\u8BBE\u7F6E")
|
|
32284
|
+
);
|
|
32285
|
+
const serverConfigured = (process.env.TESTPILOT_SERVER_URL ?? config2?.server?.baseUrl) !== void 0;
|
|
32286
|
+
const accountRefs = [
|
|
32287
|
+
...new Set(cases.map((item) => item.case?.accountRef).filter((ref) => !!ref))
|
|
32288
|
+
];
|
|
32289
|
+
for (const ref of accountRefs) {
|
|
32290
|
+
const envName = `TESTPILOT_ACCOUNT_${ref.toUpperCase().replace(/-/g, "_")}`;
|
|
32291
|
+
if (process.env[envName] !== void 0) envItems.push(ok(`${envName}(\u8D26\u53F7 ${ref})`));
|
|
32292
|
+
else if (!serverConfigured)
|
|
32293
|
+
envItems.push(
|
|
32294
|
+
warn(
|
|
32295
|
+
`\u8D26\u53F7 ${ref} \u51ED\u636E\u7F3A\u5931`,
|
|
32296
|
+
`\u672C\u5730\u8FD0\u884C\u8BBE\u7F6E ${envName};\u6216\u914D\u7F6E Server \u540E\u6309\u73AF\u5883\u51ED\u636E\u89E3\u6790`
|
|
32297
|
+
)
|
|
32298
|
+
);
|
|
32299
|
+
}
|
|
32300
|
+
if (envItems.length > 0) push("Environment", envItems);
|
|
32301
|
+
const serverUrl = serverConfigured ? process.env.TESTPILOT_SERVER_URL ?? config2?.server?.baseUrl : void 0;
|
|
32302
|
+
if (serverUrl) {
|
|
32303
|
+
const link = await readProjectLink(root);
|
|
32304
|
+
const serverItems = [];
|
|
32305
|
+
try {
|
|
32306
|
+
const res = await fetch(`${serverUrl.replace(/\/$/, "")}/api/health`, {
|
|
32307
|
+
signal: AbortSignal.timeout(3e3)
|
|
32308
|
+
});
|
|
32309
|
+
serverItems.push(res.ok ? ok(`Connected(${serverUrl})`) : error62(`Server ${res.status}`, serverUrl));
|
|
32310
|
+
} catch (err) {
|
|
32311
|
+
serverItems.push(
|
|
32312
|
+
error62(`Server \u4E0D\u53EF\u8FBE(${serverUrl})`, err instanceof Error ? err.message : String(err))
|
|
32313
|
+
);
|
|
31573
32314
|
}
|
|
32315
|
+
if (link?.projectId) serverItems.push(ok(`Project association(${link.projectId})`));
|
|
32316
|
+
else serverItems.push(warn("Project association \u7F3A\u5931", "\u8FD0\u884C npx csspilot init \u91CD\u65B0\u5173\u8054"));
|
|
32317
|
+
push("Server", serverItems);
|
|
31574
32318
|
}
|
|
32319
|
+
const all = sections.flatMap((section) => section.items);
|
|
31575
32320
|
return {
|
|
31576
|
-
|
|
31577
|
-
|
|
31578
|
-
|
|
31579
|
-
|
|
31580
|
-
|
|
31581
|
-
|
|
31582
|
-
|
|
31583
|
-
|
|
32321
|
+
sections,
|
|
32322
|
+
errors: all.filter((item) => item.status === "error").length,
|
|
32323
|
+
warnings: all.filter((item) => item.status === "warn").length
|
|
32324
|
+
};
|
|
32325
|
+
}
|
|
32326
|
+
var MARK = { ok: "\u2714", warn: "\u26A0", error: "\u2717" };
|
|
32327
|
+
function printDoctor(report) {
|
|
32328
|
+
console.log("TestPilot Doctor");
|
|
32329
|
+
console.log("");
|
|
32330
|
+
for (const section of report.sections) {
|
|
32331
|
+
console.log(section.name);
|
|
32332
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
32333
|
+
for (const item of section.items) {
|
|
32334
|
+
const hint = item.hint ? `(${item.hint})` : "";
|
|
32335
|
+
console.log(`${MARK[item.status]} ${item.label}${hint}`);
|
|
32336
|
+
}
|
|
32337
|
+
console.log("");
|
|
32338
|
+
}
|
|
32339
|
+
console.log("Result");
|
|
32340
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
32341
|
+
console.log(`${report.errors} error${report.errors === 1 ? "" : "s"}`);
|
|
32342
|
+
console.log(`${report.warnings} warning${report.warnings === 1 ? "" : "s"}`);
|
|
31584
32343
|
}
|
|
31585
32344
|
|
|
31586
|
-
//
|
|
31587
|
-
|
|
31588
|
-
|
|
31589
|
-
|
|
31590
|
-
|
|
31591
|
-
|
|
31592
|
-
|
|
31593
|
-
|
|
31594
|
-
|
|
31595
|
-
|
|
31596
|
-
|
|
32345
|
+
// src/commands/doctor.ts
|
|
32346
|
+
function makeDoctorCommand() {
|
|
32347
|
+
return new Command("doctor").description("TestPilot \u5065\u5EB7\u68C0\u67E5(Runtime / \u9879\u76EE / \u7528\u4F8B / Skill / Adapter / \u73AF\u5883\u53D8\u91CF / Server)").action(async () => {
|
|
32348
|
+
const report = await runDoctor(process.cwd());
|
|
32349
|
+
printDoctor(report);
|
|
32350
|
+
if (report.errors > 0) process.exitCode = 1;
|
|
32351
|
+
});
|
|
32352
|
+
}
|
|
32353
|
+
|
|
32354
|
+
// src/commands/init/index.ts
|
|
32355
|
+
import { join as join25 } from "node:path";
|
|
32356
|
+
|
|
32357
|
+
// src/commands/init/config-initializer.ts
|
|
32358
|
+
import { access as access2, mkdir as mkdir11, writeFile as writeFile9 } from "node:fs/promises";
|
|
32359
|
+
import { basename as basename2, join as join22 } from "node:path";
|
|
32360
|
+
async function exists3(path) {
|
|
32361
|
+
try {
|
|
32362
|
+
await access2(path);
|
|
32363
|
+
return true;
|
|
32364
|
+
} catch {
|
|
32365
|
+
return false;
|
|
31597
32366
|
}
|
|
31598
|
-
|
|
31599
|
-
|
|
31600
|
-
|
|
31601
|
-
|
|
31602
|
-
|
|
31603
|
-
|
|
31604
|
-
|
|
31605
|
-
|
|
31606
|
-
|
|
31607
|
-
|
|
31608
|
-
|
|
31609
|
-
|
|
31610
|
-
|
|
31611
|
-
|
|
31612
|
-
|
|
31613
|
-
|
|
31614
|
-
|
|
31615
|
-
|
|
31616
|
-
|
|
31617
|
-
|
|
32367
|
+
}
|
|
32368
|
+
var TEST_DIR = "tests/e2e";
|
|
32369
|
+
var CASE_DIR = "tests/e2e/cases";
|
|
32370
|
+
function renderTestpilotYaml(info) {
|
|
32371
|
+
const adapters = adaptersFor(info.type).map((item) => ` - ${item}`).join("\n");
|
|
32372
|
+
return `# TestPilot \u9879\u76EE\u914D\u7F6E(Source of Truth)
|
|
32373
|
+
version: 1
|
|
32374
|
+
|
|
32375
|
+
project:
|
|
32376
|
+
name: ${info.name}
|
|
32377
|
+
|
|
32378
|
+
test:
|
|
32379
|
+
directory: ${TEST_DIR}
|
|
32380
|
+
caseDirectory: ${CASE_DIR}
|
|
32381
|
+
|
|
32382
|
+
# \u73AF\u5883\u914D\u7F6E:Case \u7528 environment: <\u540D\u79F0> \u5F15\u7528;baseUrl \u7531\u73AF\u5883\u53D8\u91CF\u6CE8\u5165,\u7981\u6B62\u5199\u660E\u6587
|
|
32383
|
+
environment:
|
|
32384
|
+
default: test
|
|
32385
|
+
test:
|
|
32386
|
+
baseUrl: \${TEST_BASE_URL}
|
|
32387
|
+
staging:
|
|
32388
|
+
baseUrl: \${STAGING_BASE_URL}
|
|
32389
|
+
|
|
32390
|
+
# \u9879\u76EE\u58F0\u660E\u7684\u6267\u884C\u7AEF(\u5B9E\u9645\u53EF\u7528\u6027\u4EE5 csspilot doctor \u68C0\u6D4B\u4E3A\u51C6)
|
|
32391
|
+
adapters:
|
|
32392
|
+
${adapters}
|
|
32393
|
+
|
|
32394
|
+
# \u9ED8\u8BA4 Workspace(\u591A\u7CFB\u7EDF\u73AF\u5883\u7EC4\u5408);Case \u4E5F\u53EF\u7528 workspace \u5B57\u6BB5\u6309\u9700\u58F0\u660E
|
|
32395
|
+
# workspace:
|
|
32396
|
+
# default: my-workspace
|
|
32397
|
+
|
|
32398
|
+
# TestPilot Server(Control Plane)\u5730\u5740;init \u5173\u8054\u9879\u76EE\u4E0E sync-metadata \u4F7F\u7528
|
|
32399
|
+
# \u4E5F\u53EF\u7528\u73AF\u5883\u53D8\u91CF TESTPILOT_SERVER_URL \u8986\u76D6
|
|
32400
|
+
# server:
|
|
32401
|
+
# baseUrl: http://127.0.0.1:3000
|
|
32402
|
+
|
|
32403
|
+
# Web \u7AEF:navigate \u76F8\u5BF9 url \u7684\u57FA\u51C6\u5730\u5740
|
|
32404
|
+
# web:
|
|
32405
|
+
# baseUrl: http://127.0.0.1:8080
|
|
32406
|
+
|
|
32407
|
+
# \u5C0F\u7A0B\u5E8F\u7AEF:\u586B\u5165\u5C0F\u7A0B\u5E8F\u9879\u76EE\u76EE\u5F55\u540E\u5373\u53EF\u6267\u884C target: miniapp \u7684\u6B65\u9AA4
|
|
32408
|
+
# miniapp:
|
|
32409
|
+
# projectPath: path/to/miniprogram
|
|
32410
|
+
# cliPath: C:/Program Files (x86)/Tencent/\u5FAE\u4FE1web\u5F00\u53D1\u8005\u5DE5\u5177/cli.bat
|
|
32411
|
+
`;
|
|
32412
|
+
}
|
|
32413
|
+
async function initTestPilotConfig(root, info, adapters) {
|
|
32414
|
+
const yamlPath = join22(root, "testpilot.yaml");
|
|
32415
|
+
let yaml = "reused";
|
|
32416
|
+
if (!await exists3(yamlPath)) {
|
|
32417
|
+
await writeFile9(yamlPath, renderTestpilotYaml(info), "utf8");
|
|
32418
|
+
yaml = "created";
|
|
32419
|
+
}
|
|
32420
|
+
const runtimeDir = join22(root, ".testpilot", "artifacts");
|
|
32421
|
+
await mkdir11(runtimeDir, { recursive: true });
|
|
32422
|
+
const keep = join22(runtimeDir, ".gitkeep");
|
|
32423
|
+
if (!await exists3(keep)) {
|
|
32424
|
+
await writeFile9(keep, "", "utf8");
|
|
32425
|
+
}
|
|
32426
|
+
const existing = await readProjectLink(root);
|
|
32427
|
+
const defaultAdapter = defaultAdapterFor(info.type);
|
|
32428
|
+
const serverUrl = process.env.TESTPILOT_SERVER_URL ?? void 0;
|
|
32429
|
+
const link = existing ? { ...existing, version: existing.version ?? 1 } : {
|
|
32430
|
+
...await createProjectOnServer(root, info, adapters, serverUrl),
|
|
32431
|
+
version: 1,
|
|
32432
|
+
testDir: TEST_DIR,
|
|
32433
|
+
caseDir: CASE_DIR,
|
|
32434
|
+
defaultAdapter
|
|
32435
|
+
};
|
|
32436
|
+
if (link.testDir === void 0 || link.caseDir === void 0 || link.defaultAdapter === void 0) {
|
|
32437
|
+
link.testDir ??= TEST_DIR;
|
|
32438
|
+
link.caseDir ??= CASE_DIR;
|
|
32439
|
+
link.defaultAdapter ??= defaultAdapter;
|
|
32440
|
+
}
|
|
32441
|
+
if (link.serverUrl === void 0 && serverUrl) link.serverUrl = serverUrl;
|
|
32442
|
+
const projectLinkFile = await writeProjectLink(link, root);
|
|
32443
|
+
return { yaml, runtimeDir: join22(root, ".testpilot"), projectLink: link, projectLinkFile };
|
|
32444
|
+
}
|
|
32445
|
+
async function createProjectOnServer(root, info, _adapters, serverUrl) {
|
|
32446
|
+
const git = info.git;
|
|
32447
|
+
const base = { repositoryUrl: git.repositoryUrl, branch: git.branch };
|
|
32448
|
+
if (!serverUrl) return { ...base, projectId: `proj_${randomId()}` };
|
|
32449
|
+
try {
|
|
32450
|
+
const res = await fetch(`${serverUrl.replace(/\/$/, "")}/api/projects`, {
|
|
32451
|
+
method: "POST",
|
|
32452
|
+
headers: { "content-type": "application/json" },
|
|
32453
|
+
body: JSON.stringify({
|
|
32454
|
+
name: info.name || basename2(root),
|
|
32455
|
+
rootPath: root,
|
|
32456
|
+
repositoryUrl: git.repositoryUrl,
|
|
32457
|
+
defaultBranch: git.branch
|
|
31618
32458
|
})
|
|
31619
|
-
);
|
|
31620
|
-
await this.resolver.closeAll();
|
|
31621
|
-
const summary = buildRunSummary(runId, startedAt, results);
|
|
31622
|
-
await bus.emit({
|
|
31623
|
-
type: "run-finished",
|
|
31624
|
-
runId,
|
|
31625
|
-
status: summary.status,
|
|
31626
|
-
totals: { cases: summary.totals.cases, passed: summary.totals.passed, failed: summary.totals.failed },
|
|
31627
|
-
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
31628
32459
|
});
|
|
31629
|
-
|
|
31630
|
-
|
|
31631
|
-
return
|
|
32460
|
+
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
|
|
32461
|
+
const project = await res.json();
|
|
32462
|
+
return { ...base, serverUrl, projectId: `proj_${project.id}` };
|
|
32463
|
+
} catch (err) {
|
|
32464
|
+
console.error(`\u2717 \u9879\u76EE\u5173\u8054 Server(${serverUrl})\u4E0D\u53EF\u8FBE:${err instanceof Error ? err.message : err}`);
|
|
32465
|
+
return { ...base, serverUrl, projectId: `proj_${randomId()}` };
|
|
31632
32466
|
}
|
|
31633
|
-
}
|
|
32467
|
+
}
|
|
32468
|
+
function randomId() {
|
|
32469
|
+
return Math.random().toString(16).slice(2, 10);
|
|
32470
|
+
}
|
|
31634
32471
|
|
|
31635
|
-
// src/commands/
|
|
31636
|
-
|
|
31637
|
-
|
|
31638
|
-
|
|
32472
|
+
// src/commands/init/skill-installer.ts
|
|
32473
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
32474
|
+
import { access as access3, cp, mkdir as mkdir12, writeFile as writeFile10 } from "node:fs/promises";
|
|
32475
|
+
import { dirname as dirname7, join as join23 } from "node:path";
|
|
32476
|
+
import { fileURLToPath } from "node:url";
|
|
32477
|
+
async function exists4(path) {
|
|
32478
|
+
try {
|
|
32479
|
+
await access3(path);
|
|
32480
|
+
return true;
|
|
32481
|
+
} catch {
|
|
32482
|
+
return false;
|
|
32483
|
+
}
|
|
32484
|
+
}
|
|
32485
|
+
function resolveSkillSourceDir() {
|
|
32486
|
+
const fromEnv = process.env.TESTPILOT_SKILL_DIR;
|
|
32487
|
+
if (fromEnv) return fromEnv;
|
|
32488
|
+
const bundled = fileURLToPath(new URL("../../skills/testpilot", import.meta.url));
|
|
32489
|
+
if (existsSync7(bundled)) return bundled;
|
|
32490
|
+
const inRepo = fileURLToPath(new URL("../../../../../skills/testpilot", import.meta.url));
|
|
32491
|
+
return existsSync7(inRepo) ? inRepo : void 0;
|
|
32492
|
+
}
|
|
32493
|
+
async function installSkill(root, info, adapters) {
|
|
32494
|
+
const dest = join23(root, ".agents", "skills", "testpilot");
|
|
32495
|
+
let core = "reused";
|
|
32496
|
+
if (!await exists4(join23(dest, "manifest.yaml"))) {
|
|
32497
|
+
const src = resolveSkillSourceDir();
|
|
32498
|
+
if (!src) {
|
|
32499
|
+
throw new Error(
|
|
32500
|
+
"\u65E0\u6CD5\u5B9A\u4F4D TestPilot Skill \u6E90\u76EE\u5F55;\u53EF\u901A\u8FC7\u73AF\u5883\u53D8\u91CF TESTPILOT_SKILL_DIR \u6307\u5B9A skills/testpilot \u8DEF\u5F84"
|
|
32501
|
+
);
|
|
32502
|
+
}
|
|
32503
|
+
await mkdir12(dirname7(dest), { recursive: true });
|
|
32504
|
+
await cp(src, dest, { recursive: true });
|
|
32505
|
+
core = "created";
|
|
32506
|
+
}
|
|
32507
|
+
const config2 = await loadTestpilotConfig(root).catch(() => void 0);
|
|
32508
|
+
const defaultEnvironment = typeof config2?.environment?.default === "string" ? config2.environment.default : "\u672A\u8BBE\u7F6E";
|
|
32509
|
+
const defaultWorkspace = config2?.workspace?.default ?? "\u672A\u8BBE\u7F6E(\u53EF\u5728 yaml workspace.default \u914D\u7F6E)";
|
|
32510
|
+
const refsDir = join23(dest, "references");
|
|
32511
|
+
const files = [
|
|
32512
|
+
["project.md", () => renderProjectMd(info, adapters, defaultEnvironment, defaultWorkspace)],
|
|
32513
|
+
["test-conventions.md", renderTestConventionsMd],
|
|
32514
|
+
["adapters.md", () => renderAdaptersMd(adapters)]
|
|
32515
|
+
];
|
|
32516
|
+
let references = "reused";
|
|
32517
|
+
for (const [name, render] of files) {
|
|
32518
|
+
const file2 = join23(refsDir, name);
|
|
32519
|
+
if (await exists4(file2)) continue;
|
|
32520
|
+
await mkdir12(refsDir, { recursive: true });
|
|
32521
|
+
await writeFile10(file2, render(), "utf8");
|
|
32522
|
+
references = "created";
|
|
32523
|
+
}
|
|
32524
|
+
return { core, references, dest };
|
|
32525
|
+
}
|
|
32526
|
+
function renderProjectMd(info, adapters, defaultEnvironment, defaultWorkspace) {
|
|
32527
|
+
const available = adapters.filter((item) => item.available).map((item) => item.id);
|
|
32528
|
+
return `# Project
|
|
32529
|
+
|
|
32530
|
+
\u81EA\u52A8\u751F\u6210\u4E8E \`csspilot init\`,\u63CF\u8FF0\u672C\u9879\u76EE\u7684 TestPilot \u63A5\u5165\u4FE1\u606F;Agent \u4F18\u5148\u4ECE\u8FD9\u91CC\u4E86\u89E3\u9879\u76EE\u3002
|
|
32531
|
+
|
|
32532
|
+
- Project name: ${info.name}
|
|
32533
|
+
- Project type: ${info.type}
|
|
32534
|
+
- Language: ${info.language}
|
|
32535
|
+
- Package manager: ${info.packageManager}
|
|
32536
|
+
- Test directory: tests/e2e
|
|
32537
|
+
- Case directory: tests/e2e/cases
|
|
32538
|
+
- Available adapters: ${available.length > 0 ? available.join(", ") : "(none detected)"}
|
|
32539
|
+
- Default environment: ${defaultEnvironment}
|
|
32540
|
+
- Default workspace: ${defaultWorkspace}
|
|
32541
|
+
`;
|
|
32542
|
+
}
|
|
32543
|
+
function renderTestConventionsMd() {
|
|
32544
|
+
return `# Test Conventions
|
|
32545
|
+
|
|
32546
|
+
\u672C\u9879\u76EE E2E \u6D4B\u8BD5\u7EA6\u5B9A,Agent \u751F\u6210/\u4FEE\u6539 Case \u65F6\u5FC5\u987B\u9075\u5B88:
|
|
32547
|
+
|
|
32548
|
+
1. E2E Case \u4F4D\u4E8E tests/e2e/cases
|
|
32549
|
+
2. Case \u4F7F\u7528 TestPilot DSL
|
|
32550
|
+
3. \u4E0D\u5141\u8BB8\u76F4\u63A5\u8C03\u7528 Playwright
|
|
32551
|
+
4. \u4E0D\u5141\u8BB8\u76F4\u63A5\u8C03\u7528 WeChatIDE
|
|
32552
|
+
5. \u4E0D\u5141\u8BB8\u5728 Case \u4E2D\u5199\u660E\u6587\u5BC6\u7801(\u7528 accountRef \u5F15\u7528)
|
|
32553
|
+
6. \u4F18\u5148\u590D\u7528\u5DF2\u6709 Case
|
|
32554
|
+
7. \u65B0\u589E Case \u5FC5\u987B\u901A\u8FC7 csspilot validate
|
|
32555
|
+
8. Case ID \u5FC5\u987B\u552F\u4E00
|
|
32556
|
+
`;
|
|
32557
|
+
}
|
|
32558
|
+
function renderAdaptersMd(adapters) {
|
|
32559
|
+
const lines = adapters.map(
|
|
32560
|
+
(item) => `- ${item.id}: ${item.available ? "\u53EF\u7528" : "\u4E0D\u53EF\u7528"}${item.required ? "(\u9879\u76EE\u9700\u8981)" : "(\u53EF\u9009)"} \u2014 ${item.detail}`
|
|
32561
|
+
);
|
|
32562
|
+
return `# Adapters
|
|
32563
|
+
|
|
32564
|
+
\u6267\u884C\u7AEF\u68C0\u6D4B\u7ED3\u679C(\u4EE5 \`csspilot doctor\` \u6700\u65B0\u8F93\u51FA\u4E3A\u51C6):
|
|
32565
|
+
|
|
32566
|
+
${lines.join("\n")}
|
|
32567
|
+
|
|
32568
|
+
Agent \u6C38\u8FDC\u4E0D\u76F4\u63A5\u64CD\u4F5C Adapter;Case \u7ECF Execution Engine \u8C03\u5EA6\u5230\u5BF9\u5E94 Adapter \u6267\u884C\u3002
|
|
32569
|
+
`;
|
|
32570
|
+
}
|
|
32571
|
+
|
|
32572
|
+
// src/commands/init/test-structure.ts
|
|
32573
|
+
import { existsSync as existsSync8, readdirSync as readdirSync2 } from "node:fs";
|
|
32574
|
+
import { mkdir as mkdir13, writeFile as writeFile11 } from "node:fs/promises";
|
|
32575
|
+
import { join as join24 } from "node:path";
|
|
32576
|
+
async function initTestStructure(root, _info) {
|
|
32577
|
+
const dirs = {
|
|
32578
|
+
cases: join24(root, "tests", "e2e", "cases"),
|
|
32579
|
+
fixtures: join24(root, "tests", "e2e", "fixtures"),
|
|
32580
|
+
data: join24(root, "tests", "e2e", "data")
|
|
32581
|
+
};
|
|
32582
|
+
const existed = {
|
|
32583
|
+
cases: existsSync8(dirs.cases),
|
|
32584
|
+
fixtures: existsSync8(dirs.fixtures),
|
|
32585
|
+
data: existsSync8(dirs.data)
|
|
32586
|
+
};
|
|
32587
|
+
for (const dir of Object.values(dirs)) {
|
|
32588
|
+
await mkdir13(dir, { recursive: true });
|
|
32589
|
+
}
|
|
32590
|
+
for (const [name, dir] of Object.entries(dirs)) {
|
|
32591
|
+
if (!existed[name] && readdirSync2(dir).length === 0) {
|
|
32592
|
+
await writeFile11(join24(dir, ".gitkeep"), "", "utf8").catch(() => void 0);
|
|
32593
|
+
}
|
|
32594
|
+
}
|
|
32595
|
+
return {
|
|
32596
|
+
cases: existed.cases ? "reused" : "created",
|
|
32597
|
+
fixtures: existed.fixtures ? "reused" : "created",
|
|
32598
|
+
data: existed.data ? "reused" : "created"
|
|
32599
|
+
};
|
|
32600
|
+
}
|
|
32601
|
+
|
|
32602
|
+
// src/commands/init/index.ts
|
|
32603
|
+
async function runInit(root, options = {}) {
|
|
32604
|
+
if (options.serverUrl !== void 0) {
|
|
32605
|
+
if (options.serverUrl === null) delete process.env.TESTPILOT_SERVER_URL;
|
|
32606
|
+
else process.env.TESTPILOT_SERVER_URL = options.serverUrl;
|
|
32607
|
+
}
|
|
32608
|
+
const project = await detectProject(root);
|
|
32609
|
+
console.log(`\u2714 Project: ${project.name}`);
|
|
32610
|
+
console.log(`\u2714 Type: ${project.type}`);
|
|
32611
|
+
console.log(`\u2714 Language: ${project.language}`);
|
|
32612
|
+
console.log(`\u2714 Package Manager: ${project.packageManager}`);
|
|
32613
|
+
console.log(project.git.commit ? `\u2714 Git repository ${project.git.branch ?? "(detached)"}` : "\u2717 Git repository \u672A\u68C0\u6D4B\u5230");
|
|
32614
|
+
const adapters = await detectAdapters(root, project.type);
|
|
32615
|
+
console.log("");
|
|
32616
|
+
console.log("Testing adapters:");
|
|
32617
|
+
for (const adapter of adapters) {
|
|
32618
|
+
const mark = adapter.available ? "\u2713" : "\u2717";
|
|
32619
|
+
console.log(`${mark} ${adapter.id}${adapter.available ? "" : " not detected"} \u2014 ${adapter.detail}`);
|
|
32620
|
+
}
|
|
32621
|
+
console.log("");
|
|
32622
|
+
const config2 = await initTestPilotConfig(root, project, adapters);
|
|
32623
|
+
console.log(
|
|
32624
|
+
config2.yaml === "created" ? "\u2713 \u9879\u76EE\u914D\u7F6E testpilot.yaml" : "\u2713 \u9879\u76EE\u914D\u7F6E testpilot.yaml(\u5DF2\u5B58\u5728,\u4FDD\u7559)"
|
|
32625
|
+
);
|
|
32626
|
+
console.log(`\u2713 Runtime \u76EE\u5F55 ${join25(".testpilot", "artifacts")}`);
|
|
32627
|
+
const serverMode = config2.projectLink.serverUrl ? `Server:${config2.projectLink.serverUrl}` : "\u672C\u5730\u6A21\u5F0F";
|
|
32628
|
+
console.log(`\u2713 \u9879\u76EE\u5173\u8054 ${config2.projectLink.projectId}(${serverMode})`);
|
|
32629
|
+
const testStructure = await initTestStructure(root, project);
|
|
32630
|
+
const reuseNote = project.existingE2eDirs.filter((dir) => dir !== "tests/e2e");
|
|
32631
|
+
console.log(
|
|
32632
|
+
testStructure.cases === "reused" ? "\u2713 \u6D4B\u8BD5\u76EE\u5F55 tests/e2e(\u5DF2\u5B58\u5728,\u590D\u7528)" : "\u2713 \u6D4B\u8BD5\u76EE\u5F55 tests/e2e/{cases,fixtures,data}"
|
|
32633
|
+
);
|
|
32634
|
+
if (reuseNote.length > 0) {
|
|
32635
|
+
console.log(` \u26A0 \u68C0\u6D4B\u5230\u5176\u4ED6 E2E \u76EE\u5F55:${reuseNote.join(", ")}(\u4FDD\u7559\u4E0D\u52A8,\u672A\u5F3A\u5236\u8FC1\u79FB)`);
|
|
32636
|
+
}
|
|
32637
|
+
const skill = await installSkill(root, project, adapters);
|
|
32638
|
+
console.log(
|
|
32639
|
+
skill.core === "created" ? `\u2713 Skill \u5B89\u88C5 ${join25(".agents", "skills", "testpilot")}` : "\u2713 Skill \u5B89\u88C5 .agents/skills/testpilot/(\u5DF2\u5B58\u5728,\u8DF3\u8FC7)"
|
|
32640
|
+
);
|
|
32641
|
+
console.log(
|
|
32642
|
+
skill.references === "created" ? "\u2713 Agent \u4E0A\u4E0B\u6587 references/{project,test-conventions,adapters}.md" : "\u2713 Agent \u4E0A\u4E0B\u6587 references/(\u5DF2\u5B58\u5728,\u4FDD\u7559)"
|
|
32643
|
+
);
|
|
32644
|
+
console.log("\u2713 \u73AF\u5883\u914D\u7F6E environment \u6BB5(test/staging),baseUrl \u7531 TEST_BASE_URL \u7B49\u53D8\u91CF\u6CE8\u5165");
|
|
32645
|
+
const ci = await detectCi(root);
|
|
32646
|
+
if (ci.hasTestpilotWorkflow) {
|
|
32647
|
+
console.log("\u2713 CI .github/workflows/testpilot.yml(\u5DF2\u5B58\u5728)");
|
|
32648
|
+
} else if (ci.githubWorkflows || ci.gitlabCi) {
|
|
32649
|
+
console.log("\u26A0 CI \u68C0\u6D4B\u5230\u5DF2\u6709 CI \u914D\u7F6E,\u672A\u6539\u52A8;\u53EF\u8FD0\u884C npx csspilot ci init \u751F\u6210 TestPilot \u5DE5\u4F5C\u6D41");
|
|
32650
|
+
} else {
|
|
32651
|
+
console.log("\u2139 CI \u672A\u68C0\u6D4B\u5230 CI;\u53EF\u8FD0\u884C npx csspilot ci init \u751F\u6210\u6A21\u677F");
|
|
32652
|
+
}
|
|
32653
|
+
console.log("");
|
|
32654
|
+
const doctor = await runDoctor(root);
|
|
32655
|
+
printDoctor(doctor);
|
|
32656
|
+
console.log("\u4E0B\u4E00\u6B65:");
|
|
32657
|
+
console.log(" 1. \u8BA9 AI \u9605\u8BFB .agents/skills/testpilot/SKILL.md(\u9879\u76EE\u4E0A\u4E0B\u6587\u89C1 references/)");
|
|
32658
|
+
console.log(" \u53EF\u9009:\u6309\u6240\u7528 Agent \u590D\u5236\u5230 .cursor/skills/\u3001.claude/skills/ \u7B49\u76EE\u5F55");
|
|
32659
|
+
console.log(" 2. \u5728 tests/e2e/cases/ \u521B\u5EFA Case(\u9075\u5FAA references/test-conventions.md)");
|
|
32660
|
+
console.log(" 3. npx csspilot validate && npx csspilot run");
|
|
32661
|
+
return { project, adapters, config: config2, testStructure, skill, doctor };
|
|
32662
|
+
}
|
|
32663
|
+
function makeInitCommand() {
|
|
32664
|
+
return new Command("init").description("\u628A TestPilot \u63A5\u5165\u5F53\u524D\u4E1A\u52A1\u9879\u76EE(\u5E42\u7B49,\u53EF\u91CD\u590D\u6267\u884C)").option("--server <url>", "TestPilot Server \u5730\u5740(\u9ED8\u8BA4\u8BFB TESTPILOT_SERVER_URL / testpilot.yaml)").action(async (options) => {
|
|
32665
|
+
try {
|
|
32666
|
+
await runInit(process.cwd(), options.server ? { serverUrl: options.server } : {});
|
|
32667
|
+
} catch (err) {
|
|
32668
|
+
console.error(`\u2717 init \u5931\u8D25:${err instanceof Error ? err.message : String(err)}`);
|
|
32669
|
+
process.exitCode = 1;
|
|
32670
|
+
}
|
|
32671
|
+
});
|
|
32672
|
+
}
|
|
32673
|
+
|
|
32674
|
+
// src/commands/list.ts
|
|
32675
|
+
function makeListCommand() {
|
|
32676
|
+
return new Command("list").description("\u5217\u51FA\u6D4B\u8BD5\u7528\u4F8B").option("--tag <tag>", "\u6309\u6807\u7B7E\u8FC7\u6EE4").action(async (options) => {
|
|
32677
|
+
const client = new TestPilotClient();
|
|
32678
|
+
const infos = await client.listCases(void 0, options.tag).catch((err) => {
|
|
31639
32679
|
console.error(err.message);
|
|
31640
32680
|
process.exitCode = 1;
|
|
31641
32681
|
return void 0;
|
|
31642
32682
|
});
|
|
31643
|
-
if (!
|
|
31644
|
-
|
|
31645
|
-
|
|
31646
|
-
|
|
31647
|
-
console.error(
|
|
32683
|
+
if (!infos) return;
|
|
32684
|
+
if (infos.length === 0) {
|
|
32685
|
+
const config2 = await client.getConfig();
|
|
32686
|
+
console.error(`\u672A\u627E\u5230\u7528\u4F8B\u76EE\u5F55 ${config2.casesDir}`);
|
|
32687
|
+
console.error("\u63D0\u793A:\u5148\u8FD0\u884C npx csspilot init \u63A5\u5165 TestPilot");
|
|
31648
32688
|
process.exitCode = 1;
|
|
31649
32689
|
return;
|
|
31650
32690
|
}
|
|
31651
|
-
|
|
31652
|
-
|
|
31653
|
-
|
|
31654
|
-
|
|
31655
|
-
|
|
31656
|
-
|
|
31657
|
-
|
|
31658
|
-
|
|
31659
|
-
|
|
31660
|
-
|
|
31661
|
-
|
|
31662
|
-
if (options.tag && !(result.data.tags ?? []).includes(options.tag)) {
|
|
31663
|
-
tagFiltered++;
|
|
31664
|
-
continue;
|
|
32691
|
+
console.log("TestPilot Cases");
|
|
32692
|
+
console.log("");
|
|
32693
|
+
for (const item of infos) {
|
|
32694
|
+
if (item.valid) {
|
|
32695
|
+
const tags = item.case?.tags ?? [];
|
|
32696
|
+
const tagLabel = tags.length > 0 ? ` [${tags.join(", ")}]` : "";
|
|
32697
|
+
console.log(`\u2713 ${item.case?.id}${tagLabel}`);
|
|
32698
|
+
console.log(` ${item.file}`);
|
|
32699
|
+
} else {
|
|
32700
|
+
console.log(`\u2717 ${item.file}`);
|
|
32701
|
+
console.log(` ${item.issues[0]?.message ?? "\u89E3\u6790\u5931\u8D25"}`);
|
|
31665
32702
|
}
|
|
31666
|
-
|
|
32703
|
+
console.log("");
|
|
32704
|
+
}
|
|
32705
|
+
const broken = infos.filter((item) => !item.valid).length;
|
|
32706
|
+
const brokenNote = broken > 0 ? `,${broken} \u4E2A\u6587\u4EF6\u89E3\u6790\u5931\u8D25` : "";
|
|
32707
|
+
const visible = infos.length - broken;
|
|
32708
|
+
console.log(`\u5171 ${visible} \u4E2A\u7528\u4F8B${options.tag ? `(tag: ${options.tag})` : ""}${brokenNote}`);
|
|
32709
|
+
});
|
|
32710
|
+
}
|
|
32711
|
+
|
|
32712
|
+
// src/commands/report.ts
|
|
32713
|
+
import { exec } from "node:child_process";
|
|
32714
|
+
function makeReportCommand() {
|
|
32715
|
+
return new Command("report").description("\u751F\u6210\u6D4B\u8BD5\u62A5\u544A(JSON + HTML)").option("--run <id>", "\u8FD0\u884C\u8BB0\u5F55 ID,\u9ED8\u8BA4\u6700\u8FD1\u4E00\u6B21").option("--open", "\u751F\u6210\u540E\u5728\u6D4F\u89C8\u5668\u6253\u5F00", false).action(async (options) => {
|
|
32716
|
+
const client = new TestPilotClient();
|
|
32717
|
+
try {
|
|
32718
|
+
const report = await client.generateReport(options.run);
|
|
32719
|
+
console.log(`\u2713 report.json ${report.json}`);
|
|
32720
|
+
console.log(`\u2713 report.html ${report.html}`);
|
|
32721
|
+
if (options.open) await openInBrowser(report.html);
|
|
32722
|
+
} catch (err) {
|
|
32723
|
+
console.error(err instanceof Error ? err.message : err);
|
|
32724
|
+
process.exitCode = 1;
|
|
31667
32725
|
}
|
|
31668
|
-
|
|
31669
|
-
|
|
32726
|
+
});
|
|
32727
|
+
}
|
|
32728
|
+
function openInBrowser(file2) {
|
|
32729
|
+
const command = process.platform === "win32" ? `start "" "${file2}"` : process.platform === "darwin" ? `open "${file2}"` : `xdg-open "${file2}"`;
|
|
32730
|
+
return new Promise((resolvePromise) => {
|
|
32731
|
+
exec(command, () => resolvePromise());
|
|
32732
|
+
});
|
|
32733
|
+
}
|
|
32734
|
+
|
|
32735
|
+
// src/commands/run.ts
|
|
32736
|
+
import { join as join26 } from "node:path";
|
|
32737
|
+
function makeRunCommand() {
|
|
32738
|
+
return new Command("run").description("\u6267\u884C\u6D4B\u8BD5\u7528\u4F8B(\u9ED8\u8BA4\u8FD0\u884C testpilot.yaml \u914D\u7F6E\u7684 Case)").argument("[paths...]", "\u7528\u4F8B\u6587\u4EF6\u6216\u76EE\u5F55,\u9ED8\u8BA4\u6309\u9879\u76EE\u914D\u7F6E").option("--tag <tag>", "\u6309\u6807\u7B7E\u8FC7\u6EE4\u7528\u4F8B").action(async (paths, options) => {
|
|
32739
|
+
const client = new TestPilotClient();
|
|
32740
|
+
try {
|
|
32741
|
+
const { summary, invalid, tagFiltered, missingAccounts } = await client.runCases({
|
|
32742
|
+
paths,
|
|
32743
|
+
tag: options.tag,
|
|
32744
|
+
accounts: collectAccountEnv(),
|
|
32745
|
+
onEvent: consoleEventHandler
|
|
32746
|
+
});
|
|
32747
|
+
if (missingAccounts.length > 0) {
|
|
32748
|
+
console.log(
|
|
32749
|
+
`\u26A0 \u7F3A\u5C11\u8D26\u53F7\u51ED\u636E:${missingAccounts.join(", ")}(\u672C\u5730\u7528\u73AF\u5883\u53D8\u91CF TESTPILOT_ACCOUNT_<REF\u5927\u5199\u4E0B\u5212\u7EBF> \u63D0\u4F9B;Server \u89E6\u53D1\u65F6\u6309\u73AF\u5883\u51ED\u636E\u89E3\u6790)`
|
|
32750
|
+
);
|
|
32751
|
+
}
|
|
32752
|
+
const notes = [
|
|
32753
|
+
invalid.length > 0 ? `${invalid.length} \u4E2A\u6821\u9A8C\u5931\u8D25\u8DF3\u8FC7` : "",
|
|
32754
|
+
tagFiltered > 0 ? `${tagFiltered} \u4E2A\u88AB --tag \u8FC7\u6EE4` : ""
|
|
32755
|
+
].filter(Boolean).join(",");
|
|
32756
|
+
console.log("");
|
|
32757
|
+
console.log(
|
|
32758
|
+
`Run ${summary.runId}${summary.cancelled ? "(\u5DF2\u53D6\u6D88)" : ""}: ${summary.status.toUpperCase()} \u2014 \u7528\u4F8B \u2713${summary.totals.passed} \u2717${summary.totals.failed},\u6B65\u9AA4 \u2713${summary.totals.stepsPassed} \u2717${summary.totals.stepsFailed} \u21B7${summary.totals.stepsSkipped}${notes ? `(${notes})` : ""}`
|
|
32759
|
+
);
|
|
32760
|
+
console.log(`\u4EA7\u7269\u76EE\u5F55:${join26(".testpilot", "artifacts", "runs", summary.runId)}`);
|
|
32761
|
+
console.log("\u67E5\u770B\u62A5\u544A:npx csspilot report");
|
|
32762
|
+
if (summary.status === "failed") process.exitCode = 1;
|
|
32763
|
+
} catch (err) {
|
|
32764
|
+
console.error(err instanceof Error ? err.message : err);
|
|
31670
32765
|
process.exitCode = 1;
|
|
31671
|
-
return;
|
|
31672
32766
|
}
|
|
31673
|
-
const resolver = new AdapterResolver();
|
|
31674
|
-
resolver.register(playwrightAdapterFactory({ baseUrl: config2.web?.baseUrl }));
|
|
31675
|
-
resolver.register(
|
|
31676
|
-
wechatideAdapterFactory({
|
|
31677
|
-
projectPath: config2.miniapp?.projectPath,
|
|
31678
|
-
cliPath: config2.miniapp?.cliPath
|
|
31679
|
-
})
|
|
31680
|
-
);
|
|
31681
|
-
const runner = new TestRunner({ resolver, onEvent: consoleEventHandler });
|
|
31682
|
-
const notes = [
|
|
31683
|
-
invalid > 0 ? `${invalid} \u4E2A\u6821\u9A8C\u5931\u8D25\u8DF3\u8FC7` : "",
|
|
31684
|
-
tagFiltered > 0 ? `${tagFiltered} \u4E2A\u88AB --tag \u8FC7\u6EE4` : ""
|
|
31685
|
-
].filter(Boolean).join(",");
|
|
31686
|
-
console.log(`\u8FD0\u884C ${cases.length} \u4E2A\u7528\u4F8B${notes ? `(${notes})` : ""}
|
|
31687
|
-
`);
|
|
31688
|
-
const summary = await runner.run(cases);
|
|
31689
|
-
console.log("");
|
|
31690
|
-
console.log(
|
|
31691
|
-
`Run ${summary.runId}: ${summary.status.toUpperCase()} \u2014 \u7528\u4F8B \u2713${summary.totals.passed} \u2717${summary.totals.failed},\u6B65\u9AA4 \u2713${summary.totals.stepsPassed} \u2717${summary.totals.stepsFailed} \u21B7${summary.totals.stepsSkipped}`
|
|
31692
|
-
);
|
|
31693
|
-
console.log(`\u4EA7\u7269\u76EE\u5F55:${join16(".testpilot", "artifacts", "runs", summary.runId)}`);
|
|
31694
|
-
console.log("\u67E5\u770B\u62A5\u544A:npx csspilot report");
|
|
31695
|
-
if (summary.status === "failed") process.exitCode = 1;
|
|
31696
32767
|
});
|
|
31697
32768
|
}
|
|
32769
|
+
function collectAccountEnv() {
|
|
32770
|
+
const accounts = {};
|
|
32771
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
32772
|
+
if (!key.startsWith("TESTPILOT_ACCOUNT_") || value === void 0) continue;
|
|
32773
|
+
const ref = key.slice("TESTPILOT_ACCOUNT_".length).toLowerCase().replace(/_/g, "-");
|
|
32774
|
+
if (ref) accounts[ref] = value;
|
|
32775
|
+
}
|
|
32776
|
+
return accounts;
|
|
32777
|
+
}
|
|
31698
32778
|
function consoleEventHandler(event) {
|
|
31699
32779
|
switch (event.type) {
|
|
32780
|
+
case "run-started":
|
|
32781
|
+
console.log(`\u8FD0\u884C ${event.totalCases} \u4E2A\u7528\u4F8B
|
|
32782
|
+
`);
|
|
32783
|
+
break;
|
|
31700
32784
|
case "case-started":
|
|
31701
32785
|
console.log(`\u25B6 ${event.caseId} (${event.file})`);
|
|
31702
32786
|
break;
|
|
@@ -31712,49 +32796,117 @@ function consoleEventHandler(event) {
|
|
|
31712
32796
|
}
|
|
31713
32797
|
}
|
|
31714
32798
|
|
|
32799
|
+
// src/commands/sync-metadata.ts
|
|
32800
|
+
import { relative } from "node:path";
|
|
32801
|
+
function makeSyncMetadataCommand() {
|
|
32802
|
+
return new Command("sync-metadata").description("\u540C\u6B65 Case Metadata \u5FEB\u7167\u5230 TestPilot Server(CI / git push \u540E\u4F7F\u7528)").option("--server <url>", "TestPilot Server \u5730\u5740(\u9ED8\u8BA4\u53D6 project.json \u6216 testpilot.yaml)").action(async (options) => {
|
|
32803
|
+
const client = new TestPilotClient();
|
|
32804
|
+
const link = await client.getProjectLink();
|
|
32805
|
+
if (!link) {
|
|
32806
|
+
console.error("\u672A\u627E\u5230 .testpilot/project.json(\u5148\u8FD0\u884C npx csspilot init \u5173\u8054\u9879\u76EE)");
|
|
32807
|
+
process.exitCode = 1;
|
|
32808
|
+
return;
|
|
32809
|
+
}
|
|
32810
|
+
const config2 = await client.getConfig().catch(() => void 0);
|
|
32811
|
+
const serverUrl = options.server ?? process.env.TESTPILOT_SERVER_URL ?? link.serverUrl ?? config2?.server?.baseUrl;
|
|
32812
|
+
if (!serverUrl) {
|
|
32813
|
+
console.error("\u672A\u914D\u7F6E TestPilot Server \u5730\u5740(testpilot.yaml server.baseUrl \u6216 TESTPILOT_SERVER_URL)");
|
|
32814
|
+
process.exitCode = 1;
|
|
32815
|
+
return;
|
|
32816
|
+
}
|
|
32817
|
+
const git = await readGitInfo(process.cwd());
|
|
32818
|
+
if (!git.commit || !git.branch) {
|
|
32819
|
+
console.error("\u5F53\u524D\u76EE\u5F55\u4E0D\u662F Git \u4ED3\u5E93(\u6216\u6CA1\u6709\u4EFB\u4F55\u63D0\u4EA4);sync-metadata \u4EE5 Git Commit \u4E3A\u540C\u6B65\u5355\u5143");
|
|
32820
|
+
process.exitCode = 1;
|
|
32821
|
+
return;
|
|
32822
|
+
}
|
|
32823
|
+
const infos = await client.listCases();
|
|
32824
|
+
const cases = infos.filter((item) => item.valid && item.case).map((item) => ({
|
|
32825
|
+
id: item.case.id,
|
|
32826
|
+
title: item.case.name,
|
|
32827
|
+
file: relative(process.cwd(), item.file).split("\\").join("/"),
|
|
32828
|
+
tags: item.case.tags ?? []
|
|
32829
|
+
}));
|
|
32830
|
+
const skipped = infos.length - cases.length;
|
|
32831
|
+
const numericId = /(\d+)$/.exec(link.projectId ?? "")?.[1];
|
|
32832
|
+
if (!numericId) {
|
|
32833
|
+
console.error(
|
|
32834
|
+
`\u9879\u76EE\u5173\u8054 ${link.projectId} \u4E0D\u662F Server \u6CE8\u518C\u7684\u9879\u76EE(\u672C\u5730\u6A21\u5F0F);\u8BF7\u91CD\u65B0\u8FD0\u884C npx csspilot init \u5E76\u914D\u7F6E server.baseUrl`
|
|
32835
|
+
);
|
|
32836
|
+
process.exitCode = 1;
|
|
32837
|
+
return;
|
|
32838
|
+
}
|
|
32839
|
+
try {
|
|
32840
|
+
const res = await fetch(
|
|
32841
|
+
`${serverUrl.replace(/\/$/, "")}/api/projects/${numericId}/cases/sync`,
|
|
32842
|
+
{
|
|
32843
|
+
method: "POST",
|
|
32844
|
+
headers: { "content-type": "application/json" },
|
|
32845
|
+
body: JSON.stringify({
|
|
32846
|
+
repository: git.repositoryUrl,
|
|
32847
|
+
branch: git.branch,
|
|
32848
|
+
commit: git.commit,
|
|
32849
|
+
cases
|
|
32850
|
+
})
|
|
32851
|
+
}
|
|
32852
|
+
);
|
|
32853
|
+
if (!res.ok) {
|
|
32854
|
+
throw new Error(`${res.status} ${(await res.text()).slice(0, 200)}`);
|
|
32855
|
+
}
|
|
32856
|
+
const result = await res.json();
|
|
32857
|
+
console.log(`\u2713 \u5DF2\u540C\u6B65 ${serverUrl}`);
|
|
32858
|
+
console.log(` \u5206\u652F/\u63D0\u4EA4:${result.branch} \xB7 ${result.commit.slice(0, 7)}`);
|
|
32859
|
+
console.log(
|
|
32860
|
+
` \u65B0\u589E ${result.added} \xB7 \u66F4\u65B0 ${result.updated} \xB7 \u5220\u9664 ${result.deleted},\u5F53\u524D active \u5171 ${result.activeTotal} \u4E2A`
|
|
32861
|
+
);
|
|
32862
|
+
if (skipped > 0) console.log(` (\u8DF3\u8FC7 ${skipped} \u4E2A\u6821\u9A8C\u5931\u8D25\u7684\u7528\u4F8B\u6587\u4EF6)`);
|
|
32863
|
+
} catch (err) {
|
|
32864
|
+
console.error(`\u2717 \u540C\u6B65\u5931\u8D25:${err instanceof Error ? err.message : err}`);
|
|
32865
|
+
process.exitCode = 1;
|
|
32866
|
+
}
|
|
32867
|
+
});
|
|
32868
|
+
}
|
|
32869
|
+
|
|
31715
32870
|
// src/commands/validate.ts
|
|
31716
|
-
import { readFile as readFile6 } from "node:fs/promises";
|
|
31717
32871
|
function makeValidateCommand() {
|
|
31718
32872
|
return new Command("validate").description("\u6821\u9A8C\u7528\u4F8B DSL").argument("[paths...]", "\u7528\u4F8B\u6587\u4EF6\u6216\u76EE\u5F55,\u9ED8\u8BA4\u6309\u9879\u76EE\u914D\u7F6E").action(async (paths) => {
|
|
31719
|
-
const
|
|
32873
|
+
const client = new TestPilotClient();
|
|
32874
|
+
const infos = await client.listCases(paths).catch((err) => {
|
|
31720
32875
|
console.error(err.message);
|
|
31721
32876
|
process.exitCode = 1;
|
|
31722
32877
|
return void 0;
|
|
31723
32878
|
});
|
|
31724
|
-
if (!
|
|
31725
|
-
|
|
31726
|
-
|
|
31727
|
-
if (files.length === 0) {
|
|
31728
|
-
console.error(`\u672A\u627E\u5230\u7528\u4F8B\u6587\u4EF6(\u67E5\u627E:${inputs.join(", ")})`);
|
|
32879
|
+
if (!infos) return;
|
|
32880
|
+
if (infos.length === 0) {
|
|
32881
|
+
console.error(`\u672A\u627E\u5230\u7528\u4F8B\u6587\u4EF6(\u67E5\u627E:${(paths ?? []).join(", ") || "\u9879\u76EE\u914D\u7F6E\u7684 casesDir"})`);
|
|
31729
32882
|
console.error("\u63D0\u793A:\u5148\u8FD0\u884C npx csspilot init \u63A5\u5165 TestPilot");
|
|
31730
32883
|
process.exitCode = 1;
|
|
31731
32884
|
return;
|
|
31732
32885
|
}
|
|
31733
32886
|
let failed = 0;
|
|
31734
|
-
for (const
|
|
31735
|
-
|
|
31736
|
-
|
|
31737
|
-
if (result.ok) {
|
|
31738
|
-
console.log(`\u2713 ${result.data?.id ?? "(unknown)"} ${file2}`);
|
|
32887
|
+
for (const item of infos) {
|
|
32888
|
+
if (item.valid) {
|
|
32889
|
+
console.log(`\u2713 ${item.case?.id ?? "(unknown)"} ${item.file}`);
|
|
31739
32890
|
} else {
|
|
31740
32891
|
failed++;
|
|
31741
|
-
console.log(`\u2717 ${
|
|
31742
|
-
for (const issue2 of
|
|
32892
|
+
console.log(`\u2717 ${item.file}`);
|
|
32893
|
+
for (const issue2 of item.issues) {
|
|
31743
32894
|
const prefix = issue2.code === "yaml" ? "" : `${issue2.path}: `;
|
|
31744
32895
|
console.log(` - ${prefix}${issue2.message}`);
|
|
31745
32896
|
}
|
|
31746
32897
|
}
|
|
31747
32898
|
}
|
|
31748
32899
|
console.log("");
|
|
31749
|
-
console.log(`${
|
|
32900
|
+
console.log(`${infos.length - failed}/${infos.length} \u4E2A\u7528\u4F8B\u901A\u8FC7\u6821\u9A8C`);
|
|
31750
32901
|
if (failed > 0) process.exitCode = 1;
|
|
31751
32902
|
});
|
|
31752
32903
|
}
|
|
31753
32904
|
|
|
31754
32905
|
// src/cli.ts
|
|
32906
|
+
var CLI_VERSION = "0.3.0";
|
|
31755
32907
|
async function createCli() {
|
|
31756
32908
|
const program2 = new Command();
|
|
31757
|
-
program2.name("csspilot").description("TestPilot \u2014 AI Native \u8DE8\u7AEF\u4E1A\u52A1\u6D4B\u8BD5\u57FA\u7840\u8BBE\u65BD").version(
|
|
32909
|
+
program2.name("csspilot").description("TestPilot \u2014 AI Native \u8DE8\u7AEF\u4E1A\u52A1\u6D4B\u8BD5\u57FA\u7840\u8BBE\u65BD CLI").version(CLI_VERSION).addCommand(makeInitCommand()).addCommand(makeValidateCommand()).addCommand(makeListCommand()).addCommand(makeRunCommand()).addCommand(makeReportCommand()).addCommand(makeSyncMetadataCommand()).addCommand(makeDoctorCommand()).addCommand(makeCiCommand());
|
|
31758
32910
|
return program2;
|
|
31759
32911
|
}
|
|
31760
32912
|
|