shoplazza-ai-dev-cli 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/test.mjs +186 -486
- package/dist/cli.mjs +8 -1
- package/package.json +1 -1
package/dist/_chunks/test.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { loadConfig, runLogin } from "../cli.mjs";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
|
-
import * as readline from "readline";
|
|
4
3
|
function parseGlobalFlags(args) {
|
|
5
4
|
const flags = { json: false };
|
|
6
5
|
const rest = [];
|
|
@@ -185,7 +184,11 @@ var TestPlatformClient = class TestPlatformClient {
|
|
|
185
184
|
let payload = null;
|
|
186
185
|
if (contentType.includes("application/json")) try {
|
|
187
186
|
payload = await resp.json();
|
|
188
|
-
} catch {
|
|
187
|
+
} catch (e) {
|
|
188
|
+
if (resp.ok) {
|
|
189
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
190
|
+
throw new ApiError(resp.status, "RESPONSE_BODY_INVALID", `响应声明 JSON 但解析失败(响应体不完整?): ${detail}`);
|
|
191
|
+
}
|
|
189
192
|
payload = null;
|
|
190
193
|
}
|
|
191
194
|
if (!resp.ok) {
|
|
@@ -273,63 +276,47 @@ async function runTaxonomy(client, args, json) {
|
|
|
273
276
|
process.exitCode = 2;
|
|
274
277
|
}
|
|
275
278
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return new Promise((resolve) => {
|
|
282
|
-
rl.question(prompt, (answer) => {
|
|
283
|
-
rl.close();
|
|
284
|
-
resolve(answer.trim().toLowerCase());
|
|
285
|
-
});
|
|
286
|
-
});
|
|
279
|
+
const FEISHU_DETAIL_RE = /^https:\/\/project\.feishu\.cn\/[A-Za-z0-9_]+\/(?:work_items\/)?[A-Za-z0-9_]+\/detail\/(\d+)\/?$/;
|
|
280
|
+
function parseFeishuWorkItemId(raw) {
|
|
281
|
+
const clean = (raw.split("#")[0] ?? "").split("?")[0]?.trim() ?? "";
|
|
282
|
+
const m = FEISHU_DETAIL_RE.exec(clean);
|
|
283
|
+
return m ? m[1] : null;
|
|
287
284
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (!(confirm ? await confirm() : await askConfirm(`确认移除 ${preview.length} 条用例?(y/N) `) === "y")) {
|
|
312
|
-
console.error("已取消。");
|
|
313
|
-
process.exitCode = 1;
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
317
|
-
printError("Sync payload must be a JSON object (not array or primitive)");
|
|
318
|
-
process.exitCode = 1;
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
if (typeof token !== "string" || !token) throw new ApiError(409, "SYNC_UNLINK_GUARD", "server did not return unlink_confirm_token", err.data);
|
|
322
|
-
const body = {
|
|
323
|
-
...payload,
|
|
324
|
-
unlink_confirm_token: token
|
|
325
|
-
};
|
|
326
|
-
delete body["force_unlink"];
|
|
327
|
-
return await client.post(url, body);
|
|
285
|
+
const SYNC_REPLACE_REMOVED_MSG = "--mode replace 已下线:解绑语义已废弃(2026-07-24),删除用例请在 Web 页面操作";
|
|
286
|
+
const GOVERNANCE_KEYS = [
|
|
287
|
+
"mode",
|
|
288
|
+
"confirm_unlink",
|
|
289
|
+
"force_unlink"
|
|
290
|
+
];
|
|
291
|
+
function validateSyncModeFlag(mode) {
|
|
292
|
+
if (mode === void 0 || mode === "merge") return null;
|
|
293
|
+
return SYNC_REPLACE_REMOVED_MSG;
|
|
294
|
+
}
|
|
295
|
+
function validateSyncFlags(named) {
|
|
296
|
+
if (named["confirm-unlink"] !== void 0 || named["force-unlink"] !== void 0) return SYNC_REPLACE_REMOVED_MSG;
|
|
297
|
+
return validateSyncModeFlag(named["mode"]);
|
|
298
|
+
}
|
|
299
|
+
function buildMergeSyncBody(payload) {
|
|
300
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) throw new Error("Sync payload must be a JSON object (not array or primitive)");
|
|
301
|
+
const obj = payload;
|
|
302
|
+
if (obj["mode"] !== void 0 && obj["mode"] !== "merge") throw new Error(`payload 内嵌 mode="${String(obj["mode"])}" 已下线:sync 仅支持 merge,删除用例请在 Web 页面操作`);
|
|
303
|
+
if (obj["confirm_unlink"] !== void 0 || obj["force_unlink"] !== void 0) throw new Error("payload 内嵌 confirm_unlink/force_unlink 已下线:解绑语义已废弃,删除用例请在 Web 页面操作");
|
|
304
|
+
const body = {};
|
|
305
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
306
|
+
if (GOVERNANCE_KEYS.includes(k)) continue;
|
|
307
|
+
body[k] = v;
|
|
328
308
|
}
|
|
309
|
+
body["mode"] = "merge";
|
|
310
|
+
return body;
|
|
329
311
|
}
|
|
330
|
-
async function create$
|
|
312
|
+
async function create$2(client, args, json) {
|
|
331
313
|
const { named } = parseNamedArgs(args);
|
|
332
|
-
const
|
|
314
|
+
const feishuUrl = requireArg(named, "feishu-url", "feishu_ticket_url");
|
|
315
|
+
if (!parseFeishuWorkItemId(feishuUrl)) {
|
|
316
|
+
printError("--feishu-url 需为飞书需求详情页 URL(…/detail/<数字ID>),请从工单页面复制");
|
|
317
|
+
process.exitCode = 2;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
333
320
|
const title = requireArg(named, "title", "title");
|
|
334
321
|
const bl = requireArg(named, "bl", "business_line");
|
|
335
322
|
const modulePaths = asArray(named["module-paths"]);
|
|
@@ -338,14 +325,12 @@ async function create$4(client, args, json) {
|
|
|
338
325
|
process.exitCode = 2;
|
|
339
326
|
return;
|
|
340
327
|
}
|
|
341
|
-
const feishuUrl = typeof named["feishu-url"] === "string" ? named["feishu-url"] : void 0;
|
|
342
328
|
const body = {
|
|
343
|
-
req_id: reqId,
|
|
344
329
|
title,
|
|
345
330
|
business_line: bl,
|
|
346
|
-
module_paths: modulePaths
|
|
331
|
+
module_paths: modulePaths,
|
|
332
|
+
feishu_ticket_url: feishuUrl
|
|
347
333
|
};
|
|
348
|
-
if (feishuUrl) body["feishu_ticket_url"] = feishuUrl;
|
|
349
334
|
const data = await client.post("/api/test/requirements", body);
|
|
350
335
|
if (json) {
|
|
351
336
|
printJson(data);
|
|
@@ -353,8 +338,11 @@ async function create$4(client, args, json) {
|
|
|
353
338
|
}
|
|
354
339
|
if (data["created"]) {
|
|
355
340
|
printSuccess(`Requirement created: ${data["req_id"]}`);
|
|
356
|
-
printKV([
|
|
357
|
-
|
|
341
|
+
printKV([
|
|
342
|
+
["Title", data["title"]],
|
|
343
|
+
["Status", data["status"]],
|
|
344
|
+
["Case Set ID", data["case_set_id"] ?? "—"]
|
|
345
|
+
]);
|
|
358
346
|
} else console.log(`ℹ Requirement already exists: ${data["req_id"]} (not modified)`);
|
|
359
347
|
}
|
|
360
348
|
async function sync$1(client, args, json) {
|
|
@@ -365,21 +353,22 @@ async function sync$1(client, args, json) {
|
|
|
365
353
|
process.exitCode = 2;
|
|
366
354
|
return;
|
|
367
355
|
}
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
printError("--reconcile-case-types must contain only e2e,api");
|
|
356
|
+
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
357
|
+
const flagErr = validateSyncFlags(named);
|
|
358
|
+
if (flagErr) {
|
|
359
|
+
printError(flagErr);
|
|
373
360
|
process.exitCode = 2;
|
|
374
361
|
return;
|
|
375
362
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
363
|
+
let body;
|
|
364
|
+
try {
|
|
365
|
+
body = buildMergeSyncBody(payload);
|
|
366
|
+
} catch (e) {
|
|
367
|
+
printError(e.message);
|
|
368
|
+
process.exitCode = 2;
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const data = await client.post(`/api/test/requirements/${encodeURIComponent(reqId)}/cases:sync`, body);
|
|
383
372
|
if (json) {
|
|
384
373
|
printJson(data);
|
|
385
374
|
return;
|
|
@@ -392,10 +381,9 @@ async function sync$1(client, args, json) {
|
|
|
392
381
|
["Referenced", s["referenced"] ?? 0],
|
|
393
382
|
["Updated", s["updated"] ?? 0],
|
|
394
383
|
["Existing (linked)", s["skipped"] ?? 0],
|
|
395
|
-
["Unlinked", s["unlinked"] ?? 0],
|
|
396
384
|
["Failed", s["failed"] ?? 0]
|
|
397
385
|
]);
|
|
398
|
-
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${
|
|
386
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
399
387
|
}
|
|
400
388
|
async function get$2(client, args, json) {
|
|
401
389
|
const { positional } = parseNamedArgs(args);
|
|
@@ -421,31 +409,6 @@ async function get$2(client, args, json) {
|
|
|
421
409
|
["Created By", detail["created_by_name"] || "—"],
|
|
422
410
|
["Created At", detail["created_at"]]
|
|
423
411
|
]);
|
|
424
|
-
const caseSets = detail["case_sets"] ?? [];
|
|
425
|
-
if (caseSets.length) {
|
|
426
|
-
console.log("\n Typed case sets:");
|
|
427
|
-
printTable(caseSets, [
|
|
428
|
-
{
|
|
429
|
-
key: "id",
|
|
430
|
-
label: "ID",
|
|
431
|
-
width: 6
|
|
432
|
-
},
|
|
433
|
-
{
|
|
434
|
-
key: "case_type",
|
|
435
|
-
label: "Type",
|
|
436
|
-
width: 5
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
key: "name",
|
|
440
|
-
label: "Name"
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
key: "member_count",
|
|
444
|
-
label: "Cases",
|
|
445
|
-
width: 5
|
|
446
|
-
}
|
|
447
|
-
]);
|
|
448
|
-
}
|
|
449
412
|
const cases = casesData.items;
|
|
450
413
|
if (cases.length) {
|
|
451
414
|
console.log(`\n Cases (${cases.length}):`);
|
|
@@ -472,45 +435,7 @@ async function get$2(client, args, json) {
|
|
|
472
435
|
]);
|
|
473
436
|
} else console.log("\n No cases linked.");
|
|
474
437
|
}
|
|
475
|
-
async function
|
|
476
|
-
const { positional, named } = parseNamedArgs(args);
|
|
477
|
-
const reqId = positional[0];
|
|
478
|
-
if (!reqId) {
|
|
479
|
-
printError("Usage: test requirements attach-cases <req_id> --case-ids TC-1,TC-2");
|
|
480
|
-
process.exitCode = 2;
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
483
|
-
const caseIds = asArray(named["case-ids"]);
|
|
484
|
-
if (!caseIds.length) {
|
|
485
|
-
printError("Provide --case-ids");
|
|
486
|
-
process.exitCode = 2;
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
const data = await client.post(`/api/test/requirements/${encodeURIComponent(reqId)}/cases:attach`, { case_ids: caseIds });
|
|
490
|
-
if (json) {
|
|
491
|
-
printJson(data);
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
printSuccess(`Attached ${(data.items ?? []).reduce((sum, item) => sum + item.added, 0)} case(s) to ${reqId}`);
|
|
495
|
-
if (data.items?.length) printTable(data.items, [
|
|
496
|
-
{
|
|
497
|
-
key: "case_type",
|
|
498
|
-
label: "Type",
|
|
499
|
-
width: 5
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
key: "set_id",
|
|
503
|
-
label: "Set ID",
|
|
504
|
-
width: 8
|
|
505
|
-
},
|
|
506
|
-
{
|
|
507
|
-
key: "added",
|
|
508
|
-
label: "Added",
|
|
509
|
-
width: 5
|
|
510
|
-
}
|
|
511
|
-
]);
|
|
512
|
-
}
|
|
513
|
-
async function list$3(client, args, json) {
|
|
438
|
+
async function list$2(client, args, json) {
|
|
514
439
|
const { named } = parseNamedArgs(args);
|
|
515
440
|
const params = {};
|
|
516
441
|
for (const k of [
|
|
@@ -549,15 +474,14 @@ async function runRequirements(client, args, json) {
|
|
|
549
474
|
const action = args[0];
|
|
550
475
|
const subArgs = args.slice(1);
|
|
551
476
|
switch (action) {
|
|
552
|
-
case "create": return create$
|
|
477
|
+
case "create": return create$2(client, subArgs, json);
|
|
553
478
|
case "get": return get$2(client, subArgs, json);
|
|
554
479
|
case "sync": return sync$1(client, subArgs, json);
|
|
555
|
-
case "
|
|
556
|
-
case "list": return list$3(client, subArgs, json);
|
|
480
|
+
case "list": return list$2(client, subArgs, json);
|
|
557
481
|
case "--help":
|
|
558
482
|
case "-h":
|
|
559
483
|
case void 0:
|
|
560
|
-
console.log(`requirements commands:\n create
|
|
484
|
+
console.log(`requirements commands:\n create Create a requirement\n get Get requirement detail with cases\n sync Sync cases to requirement (channel 1)\n list List requirements`);
|
|
561
485
|
return;
|
|
562
486
|
default:
|
|
563
487
|
printError(`Unknown requirements action: ${action}`);
|
|
@@ -577,17 +501,10 @@ const VALID_PLAN_TYPES = [
|
|
|
577
501
|
"smoke"
|
|
578
502
|
];
|
|
579
503
|
const VALID_ENVS = [
|
|
580
|
-
"local",
|
|
581
504
|
"dev",
|
|
505
|
+
"sandbox",
|
|
582
506
|
"stg",
|
|
583
|
-
"prod"
|
|
584
|
-
"auto"
|
|
585
|
-
];
|
|
586
|
-
const VALID_MARK_STATUSES = [
|
|
587
|
-
"passed",
|
|
588
|
-
"failed",
|
|
589
|
-
"skipped",
|
|
590
|
-
"blocked"
|
|
507
|
+
"prod"
|
|
591
508
|
];
|
|
592
509
|
const VALID_USER_KINDS = [
|
|
593
510
|
"regression",
|
|
@@ -595,64 +512,7 @@ const VALID_USER_KINDS = [
|
|
|
595
512
|
"baseline",
|
|
596
513
|
"custom"
|
|
597
514
|
];
|
|
598
|
-
async function
|
|
599
|
-
const { named } = parseNamedArgs(args);
|
|
600
|
-
const body = {
|
|
601
|
-
title: requireArg(named, "title", "title"),
|
|
602
|
-
business_line: requireArg(named, "bl", "business_line"),
|
|
603
|
-
module_path: requireArg(named, "module-path", "module_path"),
|
|
604
|
-
case_type: requireArg(named, "type", "case_type"),
|
|
605
|
-
steps: (() => {
|
|
606
|
-
const raw = requireArg(named, "steps", "steps");
|
|
607
|
-
try {
|
|
608
|
-
const parsed = JSON.parse(raw);
|
|
609
|
-
if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("steps must be a non-empty JSON array");
|
|
610
|
-
for (let i = 0; i < parsed.length; i++) {
|
|
611
|
-
const s = parsed[i];
|
|
612
|
-
if (!s.step?.trim()) throw new Error(`steps[${i}].step is empty`);
|
|
613
|
-
if (!s.expected?.trim()) throw new Error(`steps[${i}].expected is empty`);
|
|
614
|
-
}
|
|
615
|
-
return parsed;
|
|
616
|
-
} catch (e) {
|
|
617
|
-
printError(`Invalid --steps: ${e.message}`);
|
|
618
|
-
process.exitCode = 2;
|
|
619
|
-
return null;
|
|
620
|
-
}
|
|
621
|
-
})()
|
|
622
|
-
};
|
|
623
|
-
if (body["steps"] === null) return;
|
|
624
|
-
const caseType = body["case_type"];
|
|
625
|
-
if (!VALID_CASE_TYPES.includes(caseType)) {
|
|
626
|
-
printError(`Invalid --type "${caseType}": must be ${VALID_CASE_TYPES.join("|")}`);
|
|
627
|
-
process.exitCode = 2;
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
if (typeof named["priority"] === "string") {
|
|
631
|
-
if (!VALID_PRIORITIES.includes(named["priority"])) {
|
|
632
|
-
printError(`Invalid --priority "${named["priority"]}": must be ${VALID_PRIORITIES.join("|")}`);
|
|
633
|
-
process.exitCode = 2;
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
body["priority"] = named["priority"];
|
|
637
|
-
}
|
|
638
|
-
body["precondition"] = requireArg(named, "precondition", "precondition");
|
|
639
|
-
if (typeof named["source"] === "string") body["source"] = named["source"];
|
|
640
|
-
const tags = asArray(named["tags"]);
|
|
641
|
-
if (tags.length) body["tags"] = tags;
|
|
642
|
-
const data = await client.post("/api/test/cases", body);
|
|
643
|
-
if (json) {
|
|
644
|
-
printJson(data);
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
printSuccess(`Case created: ${data["case_id"]}`);
|
|
648
|
-
printKV([
|
|
649
|
-
["Title", data["title"]],
|
|
650
|
-
["Module", `${data["module_path"] ?? `id=${data["module_id"]}`}`],
|
|
651
|
-
["Type", data["case_type"]],
|
|
652
|
-
["Priority", data["priority"] || "—"]
|
|
653
|
-
]);
|
|
654
|
-
}
|
|
655
|
-
async function list$2(client, args, json) {
|
|
515
|
+
async function list$1(client, args, json) {
|
|
656
516
|
const { named } = parseNamedArgs(args);
|
|
657
517
|
const params = {};
|
|
658
518
|
for (const k of [
|
|
@@ -700,46 +560,11 @@ async function list$2(client, args, json) {
|
|
|
700
560
|
]);
|
|
701
561
|
printPagination(data.total);
|
|
702
562
|
}
|
|
703
|
-
async function batch$1(client, args, json) {
|
|
704
|
-
const { named } = parseNamedArgs(args);
|
|
705
|
-
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
706
|
-
const data = await client.post("/api/test/cases/batch", payload);
|
|
707
|
-
if (json) {
|
|
708
|
-
printJson(data);
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
const s = data.summary;
|
|
712
|
-
printSuccess(`Batch created ${s["created"] ?? 0} cases`);
|
|
713
|
-
printKV([
|
|
714
|
-
["Created", s["created"] ?? 0],
|
|
715
|
-
["Skipped (dup)", s["skipped"] ?? 0],
|
|
716
|
-
["Failed", s["failed"] ?? 0]
|
|
717
|
-
]);
|
|
718
|
-
for (const r of data.results.filter((r) => r.action === "created")) console.log(` ${r.case_id} ${r.client_ref || ""}`);
|
|
719
|
-
for (const r of data.results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
720
|
-
}
|
|
721
|
-
async function remove$1(client, args, json) {
|
|
722
|
-
if (args.length === 0) {
|
|
723
|
-
printError("Usage: test cases delete <case_id...>");
|
|
724
|
-
process.exitCode = 2;
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
const data = await client.post("/api/test/cases:delete", { case_ids: args });
|
|
728
|
-
if (json) {
|
|
729
|
-
printJson(data);
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
if (data.deleted.length) printSuccess(`Deleted: ${data.deleted.join(", ")}`);
|
|
733
|
-
for (const item of data.blocked ?? []) printError(`${item.case_id}: referenced by plan(s) ${item.plan_ids.join(", ")}`);
|
|
734
|
-
if (data.not_found?.length) printError(`Not found: ${data.not_found.join(", ")}`);
|
|
735
|
-
if (data.already?.length) printError(`Already deleted: ${data.already.join(", ")}`);
|
|
736
|
-
}
|
|
737
563
|
const UPDATE_FIELDS = [
|
|
738
564
|
"title",
|
|
739
565
|
"precondition",
|
|
740
566
|
"steps",
|
|
741
567
|
"priority",
|
|
742
|
-
"tags",
|
|
743
568
|
"status",
|
|
744
569
|
"case_type",
|
|
745
570
|
"module_path",
|
|
@@ -763,7 +588,6 @@ function namedArgsToRaw(named) {
|
|
|
763
588
|
const val = Array.isArray(v) ? v[v.length - 1] : v;
|
|
764
589
|
if (typeof val === "string") raw[field] = val;
|
|
765
590
|
}
|
|
766
|
-
if (named["tags"] !== void 0) raw["tags"] = asArray(named["tags"]);
|
|
767
591
|
if (typeof named["steps"] === "string") {
|
|
768
592
|
let parsed;
|
|
769
593
|
try {
|
|
@@ -800,10 +624,6 @@ function buildCaseUpdatePayload(raw) {
|
|
|
800
624
|
if (!VALID_CASE_TYPES.includes(t)) throw new Error(`Invalid case_type "${t}": must be ${VALID_CASE_TYPES.join("|")}`);
|
|
801
625
|
body["case_type"] = t;
|
|
802
626
|
}
|
|
803
|
-
if (raw["tags"] !== void 0) {
|
|
804
|
-
if (!Array.isArray(raw["tags"])) throw new Error("tags must be an array of strings");
|
|
805
|
-
body["tags"] = raw["tags"].map((x) => String(x));
|
|
806
|
-
}
|
|
807
627
|
if (raw["steps"] !== void 0) {
|
|
808
628
|
const steps = raw["steps"];
|
|
809
629
|
if (!Array.isArray(steps) || steps.length === 0) throw new Error("steps must be a non-empty array");
|
|
@@ -829,7 +649,6 @@ function resolveUpdateInput(positional, named) {
|
|
|
829
649
|
"module-path",
|
|
830
650
|
"bl",
|
|
831
651
|
"module-id",
|
|
832
|
-
"tags",
|
|
833
652
|
"steps"
|
|
834
653
|
].filter((f) => named[f] !== void 0);
|
|
835
654
|
const useFile = typeof named["file"] === "string";
|
|
@@ -882,22 +701,19 @@ async function runCases(client, args, json) {
|
|
|
882
701
|
const action = args[0];
|
|
883
702
|
const subArgs = args.slice(1);
|
|
884
703
|
switch (action) {
|
|
885
|
-
case "
|
|
886
|
-
case "list": return list$2(client, subArgs, json);
|
|
887
|
-
case "batch": return batch$1(client, subArgs, json);
|
|
888
|
-
case "delete": return remove$1(client, subArgs, json);
|
|
704
|
+
case "list": return list$1(client, subArgs, json);
|
|
889
705
|
case "update": return update(client, subArgs, json);
|
|
890
706
|
case "--help":
|
|
891
707
|
case "-h":
|
|
892
708
|
case void 0:
|
|
893
|
-
console.log(`cases commands:\n
|
|
709
|
+
console.log(`cases commands:\n list List cases with filters\n update Patch a case by id (pointer semantics: only pass fields to change; --file <path|-> for JSON body)`);
|
|
894
710
|
return;
|
|
895
711
|
default:
|
|
896
712
|
printError(`Unknown cases action: ${action}`);
|
|
897
713
|
process.exitCode = 2;
|
|
898
714
|
}
|
|
899
715
|
}
|
|
900
|
-
async function create$
|
|
716
|
+
async function create$1(client, args, json) {
|
|
901
717
|
const { named } = parseNamedArgs(args);
|
|
902
718
|
const name = requireArg(named, "name", "name");
|
|
903
719
|
const kind = requireArg(named, "kind", "regression|flow|baseline|custom");
|
|
@@ -907,16 +723,9 @@ async function create$2(client, args, json) {
|
|
|
907
723
|
return;
|
|
908
724
|
}
|
|
909
725
|
const moduleId = requireArg(named, "module", "module_id (integer)");
|
|
910
|
-
const caseType = requireArg(named, "type", "e2e|api");
|
|
911
|
-
if (!["e2e", "api"].includes(caseType)) {
|
|
912
|
-
printError(`Invalid --type "${caseType}": must be e2e|api`);
|
|
913
|
-
process.exitCode = 2;
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
726
|
const body = {
|
|
917
727
|
name,
|
|
918
728
|
kind,
|
|
919
|
-
case_type: caseType,
|
|
920
729
|
selection_mode: "manual",
|
|
921
730
|
primary_module_id: parseInt(moduleId, 10)
|
|
922
731
|
};
|
|
@@ -926,78 +735,7 @@ async function create$2(client, args, json) {
|
|
|
926
735
|
return;
|
|
927
736
|
}
|
|
928
737
|
printSuccess(`Case set created: ${data["id"]}`);
|
|
929
|
-
printKV([
|
|
930
|
-
["Name", data["name"]],
|
|
931
|
-
["Kind", data["kind"]],
|
|
932
|
-
["Case Type", data["case_type"]]
|
|
933
|
-
]);
|
|
934
|
-
}
|
|
935
|
-
async function list$1(client, args, json) {
|
|
936
|
-
const { named } = parseNamedArgs(args);
|
|
937
|
-
const params = {};
|
|
938
|
-
if (typeof named["q"] === "string") params["q"] = named["q"];
|
|
939
|
-
if (typeof named["type"] === "string") {
|
|
940
|
-
if (!["e2e", "api"].includes(named["type"])) {
|
|
941
|
-
printError(`Invalid --type "${named["type"]}": must be e2e|api`);
|
|
942
|
-
process.exitCode = 2;
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
params["case_type"] = named["type"];
|
|
946
|
-
}
|
|
947
|
-
const data = await client.get("/api/test/case-sets", params);
|
|
948
|
-
if (json) {
|
|
949
|
-
printJson(data);
|
|
950
|
-
return;
|
|
951
|
-
}
|
|
952
|
-
printTable(data.items, [
|
|
953
|
-
{
|
|
954
|
-
key: "id",
|
|
955
|
-
label: "ID",
|
|
956
|
-
width: 6
|
|
957
|
-
},
|
|
958
|
-
{
|
|
959
|
-
key: "name",
|
|
960
|
-
label: "Name"
|
|
961
|
-
},
|
|
962
|
-
{
|
|
963
|
-
key: "case_type",
|
|
964
|
-
label: "Type",
|
|
965
|
-
width: 5
|
|
966
|
-
},
|
|
967
|
-
{
|
|
968
|
-
key: "kind",
|
|
969
|
-
label: "Kind",
|
|
970
|
-
width: 12
|
|
971
|
-
},
|
|
972
|
-
{
|
|
973
|
-
key: "member_count",
|
|
974
|
-
label: "Cases",
|
|
975
|
-
width: 5
|
|
976
|
-
}
|
|
977
|
-
]);
|
|
978
|
-
}
|
|
979
|
-
async function members(client, args, json) {
|
|
980
|
-
const { positional, named } = parseNamedArgs(args);
|
|
981
|
-
const setId = positional[0];
|
|
982
|
-
if (!setId) {
|
|
983
|
-
printError("Usage: test case-sets members <set_id> --add ...");
|
|
984
|
-
process.exitCode = 2;
|
|
985
|
-
return;
|
|
986
|
-
}
|
|
987
|
-
const add = asArray(named["add"]);
|
|
988
|
-
if (!add.length) {
|
|
989
|
-
printError("Provide --add");
|
|
990
|
-
process.exitCode = 2;
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
const body = {};
|
|
994
|
-
if (add.length) body["add"] = add;
|
|
995
|
-
const data = await client.post(`/api/test/case-sets/${setId}/members:batch`, body);
|
|
996
|
-
if (json) {
|
|
997
|
-
printJson(data);
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
printSuccess(`Added ${data.added}, invalid: ${(data.invalid ?? []).length}`);
|
|
738
|
+
printKV([["Name", data["name"]], ["Kind", data["kind"]]]);
|
|
1001
739
|
}
|
|
1002
740
|
async function get$1(client, args, json) {
|
|
1003
741
|
const { positional } = parseNamedArgs(args);
|
|
@@ -1015,7 +753,6 @@ async function get$1(client, args, json) {
|
|
|
1015
753
|
printKV([
|
|
1016
754
|
["Name", data.name],
|
|
1017
755
|
["Kind", data.kind],
|
|
1018
|
-
["Case Type", data.case_type],
|
|
1019
756
|
["Members", data.members?.length ?? 0]
|
|
1020
757
|
]);
|
|
1021
758
|
if (data.members?.length) printTable(data.members, [
|
|
@@ -1044,6 +781,15 @@ async function get$1(client, args, json) {
|
|
|
1044
781
|
}
|
|
1045
782
|
]);
|
|
1046
783
|
}
|
|
784
|
+
function preflightGroupFields(payload) {
|
|
785
|
+
const cases = payload?.cases;
|
|
786
|
+
if (!Array.isArray(cases)) return null;
|
|
787
|
+
for (let i = 0; i < cases.length; i++) {
|
|
788
|
+
const item = cases[i];
|
|
789
|
+
if (item && item.group !== void 0 && item.group_segments !== void 0) return `cases[${i}] 同时携带 group 与 group_segments(二选一),请只保留一种形态`;
|
|
790
|
+
}
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
1047
793
|
async function sync(client, args, json) {
|
|
1048
794
|
const { positional, named } = parseNamedArgs(args);
|
|
1049
795
|
const setId = positional[0];
|
|
@@ -1052,21 +798,28 @@ async function sync(client, args, json) {
|
|
|
1052
798
|
process.exitCode = 2;
|
|
1053
799
|
return;
|
|
1054
800
|
}
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
printError("--reconcile-case-types must contain only e2e,api");
|
|
801
|
+
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
802
|
+
const groupConflict = preflightGroupFields(payload);
|
|
803
|
+
if (groupConflict) {
|
|
804
|
+
printError(groupConflict);
|
|
1060
805
|
process.exitCode = 2;
|
|
1061
806
|
return;
|
|
1062
807
|
}
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
808
|
+
const flagErr = validateSyncFlags(named);
|
|
809
|
+
if (flagErr) {
|
|
810
|
+
printError(flagErr);
|
|
811
|
+
process.exitCode = 2;
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
let body;
|
|
815
|
+
try {
|
|
816
|
+
body = buildMergeSyncBody(payload);
|
|
817
|
+
} catch (e) {
|
|
818
|
+
printError(e.message);
|
|
819
|
+
process.exitCode = 2;
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
const data = await client.post(`/api/test/case-sets/${setId}/cases:sync`, body);
|
|
1070
823
|
if (json) {
|
|
1071
824
|
printJson(data);
|
|
1072
825
|
return;
|
|
@@ -1079,31 +832,28 @@ async function sync(client, args, json) {
|
|
|
1079
832
|
["Referenced", s["referenced"] ?? 0],
|
|
1080
833
|
["Updated", s["updated"] ?? 0],
|
|
1081
834
|
["Existing (linked)", s["skipped"] ?? 0],
|
|
1082
|
-
["Unlinked", s["unlinked"] ?? 0],
|
|
1083
835
|
["Failed", s["failed"] ?? 0]
|
|
1084
836
|
]);
|
|
1085
|
-
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${
|
|
837
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
1086
838
|
}
|
|
1087
839
|
async function runCaseSets(client, args, json) {
|
|
1088
840
|
const action = args[0];
|
|
1089
841
|
const subArgs = args.slice(1);
|
|
1090
842
|
switch (action) {
|
|
1091
|
-
case "create": return create$
|
|
1092
|
-
case "list": return list$1(client, subArgs, json);
|
|
843
|
+
case "create": return create$1(client, subArgs, json);
|
|
1093
844
|
case "get": return get$1(client, subArgs, json);
|
|
1094
|
-
case "members": return members(client, subArgs, json);
|
|
1095
845
|
case "sync": return sync(client, subArgs, json);
|
|
1096
846
|
case "--help":
|
|
1097
847
|
case "-h":
|
|
1098
848
|
case void 0:
|
|
1099
|
-
console.log(`case-sets commands:\n create Create a
|
|
849
|
+
console.log(`case-sets commands:\n create Create a case set (--name, --kind [--module <id>])\n get Get case set detail with members\n sync Sync cases to a set (--file <path>)`);
|
|
1100
850
|
return;
|
|
1101
851
|
default:
|
|
1102
852
|
printError(`Unknown case-sets action: ${action}`);
|
|
1103
853
|
process.exitCode = 2;
|
|
1104
854
|
}
|
|
1105
855
|
}
|
|
1106
|
-
async function create
|
|
856
|
+
async function create(client, args, json) {
|
|
1107
857
|
const { named } = parseNamedArgs(args);
|
|
1108
858
|
const planType = requireArg(named, "type", "requirement|regression|smoke");
|
|
1109
859
|
if (!VALID_PLAN_TYPES.includes(planType)) {
|
|
@@ -1114,15 +864,6 @@ async function create$1(client, args, json) {
|
|
|
1114
864
|
const body = { type: planType };
|
|
1115
865
|
if (typeof named["title"] === "string") body["title"] = named["title"];
|
|
1116
866
|
if (typeof named["from-set"] === "string") body["from_case_set"] = Number(named["from-set"]);
|
|
1117
|
-
if (typeof named["from-sets"] === "string") {
|
|
1118
|
-
const ids = named["from-sets"].split(",").map((s) => Number(s.trim())).filter((id) => Number.isInteger(id) && id > 0);
|
|
1119
|
-
if (!ids.length) {
|
|
1120
|
-
printError("--from-sets requires one or more numeric IDs");
|
|
1121
|
-
process.exitCode = 2;
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
body["from_case_sets"] = ids;
|
|
1125
|
-
}
|
|
1126
867
|
if (typeof named["case-ids"] === "string") body["case_ids"] = named["case-ids"].split(",").map((s) => s.trim());
|
|
1127
868
|
if (typeof named["req-id"] === "string") body["req_id"] = named["req-id"];
|
|
1128
869
|
if (typeof named["env"] === "string") {
|
|
@@ -1135,24 +876,27 @@ async function create$1(client, args, json) {
|
|
|
1135
876
|
}
|
|
1136
877
|
const tags = asArray(named["tags"]);
|
|
1137
878
|
if (tags.length) body["tags"] = tags;
|
|
1138
|
-
const
|
|
1139
|
-
body["
|
|
1140
|
-
body["
|
|
1141
|
-
body["
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
printError("Must specify one of --case-ids, --from-set, --from-sets, or --req-id");
|
|
879
|
+
const matrixError = validatePlanCreateMatrix(planType, {
|
|
880
|
+
reqId: typeof body["req_id"] === "string" && body["req_id"] !== "",
|
|
881
|
+
caseIds: Array.isArray(body["case_ids"]) && body["case_ids"].length > 0,
|
|
882
|
+
fromSet: body["from_case_set"] !== void 0
|
|
883
|
+
});
|
|
884
|
+
if (matrixError) {
|
|
885
|
+
printError(matrixError);
|
|
1146
886
|
process.exitCode = 2;
|
|
1147
887
|
return;
|
|
1148
888
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
889
|
+
const data = await client.post("/api/test/test-plans", body);
|
|
890
|
+
const problems = reconcilePlanCreateResponse(planType, {
|
|
891
|
+
reqId: body["req_id"],
|
|
892
|
+
caseIds: body["case_ids"]
|
|
893
|
+
}, data);
|
|
894
|
+
if (problems.length) {
|
|
895
|
+
printError(`创建对账失败(计划 ${String(data["plan_id"] ?? "?")} 可能已创建,请人工核查,勿直接重试创建): ${problems.join("; ")}`);
|
|
896
|
+
if (json) printJson(data);
|
|
897
|
+
process.exitCode = 1;
|
|
1152
898
|
return;
|
|
1153
899
|
}
|
|
1154
|
-
if (body["case_ids"]) console.error("⚠ 建议使用 --req-id 或 --from-set 从用例集拉取,避免手工枚举遗漏");
|
|
1155
|
-
const data = await client.post("/api/test/test-plans", body);
|
|
1156
900
|
if (json) {
|
|
1157
901
|
printJson(data);
|
|
1158
902
|
return;
|
|
@@ -1161,11 +905,42 @@ async function create$1(client, args, json) {
|
|
|
1161
905
|
printKV([
|
|
1162
906
|
["Title", data["title"]],
|
|
1163
907
|
["Type", data["type"]],
|
|
908
|
+
["Req", data["req_id"] ?? "—"],
|
|
1164
909
|
["Env", data["env"]],
|
|
1165
910
|
["Cases", data["case_count"]],
|
|
1166
911
|
["Status", data["status"]]
|
|
1167
912
|
]);
|
|
1168
913
|
}
|
|
914
|
+
function validatePlanCreateMatrix(planType, src) {
|
|
915
|
+
switch (planType) {
|
|
916
|
+
case "requirement":
|
|
917
|
+
if (!src.reqId || src.caseIds || src.fromSet) return "type=requirement 只接受 --req-id(需求全量计划)";
|
|
918
|
+
return null;
|
|
919
|
+
case "smoke":
|
|
920
|
+
if (!src.reqId || !src.caseIds || src.fromSet) return "type=smoke 必须同时提供 --req-id 与 --case-ids(测试员手选),不接受 --from-set";
|
|
921
|
+
return null;
|
|
922
|
+
case "regression":
|
|
923
|
+
if (!src.fromSet || src.reqId) return "type=regression 只接受 --from-set(全局用例集),可选 --case-ids 建子集回归,不接受 --req-id";
|
|
924
|
+
return null;
|
|
925
|
+
default: return `Invalid type "${planType}"`;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
function reconcilePlanCreateResponse(planType, requested, data) {
|
|
929
|
+
const problems = [];
|
|
930
|
+
if (data["type"] !== planType) problems.push(`type=${String(data["type"])} ≠ ${planType}`);
|
|
931
|
+
const respCaseIds = Array.isArray(data["case_ids"]) ? data["case_ids"] : null;
|
|
932
|
+
if (!respCaseIds || respCaseIds.length === 0) problems.push("响应缺少冻结 case_ids");
|
|
933
|
+
else if (data["case_count"] !== respCaseIds.length) problems.push(`case_count=${String(data["case_count"])} ≠ len(case_ids)=${respCaseIds.length}`);
|
|
934
|
+
const respReqId = data["req_id"] ?? null;
|
|
935
|
+
if (planType === "regression") {
|
|
936
|
+
if (respReqId !== null) problems.push(`全局回归 req_id 应为 null,实际 ${String(respReqId)}`);
|
|
937
|
+
} else if (respReqId !== requested.reqId) problems.push(`req_id=${String(respReqId)} ≠ ${String(requested.reqId)}`);
|
|
938
|
+
if (respCaseIds && requested.caseIds && requested.caseIds.length > 0) {
|
|
939
|
+
const want = new Set(requested.caseIds);
|
|
940
|
+
if (respCaseIds.length !== want.size || respCaseIds.some((id) => !want.has(id))) problems.push("冻结 case_ids 与请求选集不一致");
|
|
941
|
+
}
|
|
942
|
+
return problems;
|
|
943
|
+
}
|
|
1169
944
|
async function get(client, args, json) {
|
|
1170
945
|
const { positional } = parseNamedArgs(args);
|
|
1171
946
|
const planId = positional[0];
|
|
@@ -1179,19 +954,30 @@ async function get(client, args, json) {
|
|
|
1179
954
|
printJson(data);
|
|
1180
955
|
return;
|
|
1181
956
|
}
|
|
957
|
+
const reqTitle = data["req_title"] ? ` ${String(data["req_title"])}` : "";
|
|
958
|
+
const setName = data["source_case_set_name"] ? ` ${String(data["source_case_set_name"])}` : "";
|
|
1182
959
|
printKV([
|
|
1183
960
|
["Plan ID", data["plan_id"]],
|
|
1184
961
|
["Title", data["title"]],
|
|
1185
962
|
["Type", data["type"]],
|
|
1186
963
|
["Env", data["env"]],
|
|
1187
|
-
["Status", data["status"]]
|
|
964
|
+
["Status", data["status"]],
|
|
965
|
+
["Req", data["req_id"] ? `${String(data["req_id"])}${reqTitle}` : "—"],
|
|
966
|
+
["Source set", data["source_case_set_id"] != null ? `#${String(data["source_case_set_id"])}${setName}` : "—"],
|
|
967
|
+
["Addable from source", data["addable_from_source_count"] ?? 0]
|
|
1188
968
|
]);
|
|
1189
969
|
const progress = data["progress"];
|
|
1190
970
|
if (progress) console.log(` Progress: ${progress["passed"]}p / ${progress["failed"]}f / ${progress["pending"]} pending (total ${progress["total"]})`);
|
|
1191
971
|
const cases = data["cases"];
|
|
1192
972
|
if (cases && cases.length) {
|
|
1193
973
|
console.log(`\n Cases (${cases.length}):`);
|
|
1194
|
-
for (const c of cases)
|
|
974
|
+
for (const c of cases) {
|
|
975
|
+
const marks = [];
|
|
976
|
+
if (c["in_source_set"] === false) marks.push("已离开来源集");
|
|
977
|
+
if (c["content_updated"] === true) marks.push(`正文已更新 v${c["case_version_at_add"]}→v${c["current_version"]}`);
|
|
978
|
+
const suffix = marks.length ? ` [${marks.join(" · ")}]` : "";
|
|
979
|
+
console.log(` [${c["case_id"]}] ${c["title"]} (${c["priority"] || "—"})${suffix}`);
|
|
980
|
+
}
|
|
1195
981
|
}
|
|
1196
982
|
}
|
|
1197
983
|
async function list(client, args, json) {
|
|
@@ -1243,85 +1029,49 @@ async function list(client, args, json) {
|
|
|
1243
1029
|
]);
|
|
1244
1030
|
printPagination(data.total);
|
|
1245
1031
|
}
|
|
1246
|
-
async function
|
|
1032
|
+
async function add(client, args, json) {
|
|
1247
1033
|
const { positional } = parseNamedArgs(args);
|
|
1248
1034
|
const [planId, ...caseIDs] = positional;
|
|
1249
1035
|
if (!planId || caseIDs.length === 0) {
|
|
1250
|
-
printError("Usage: test plans
|
|
1036
|
+
printError("Usage: test plans add <plan_id> <case_id> [case_id...]");
|
|
1251
1037
|
process.exitCode = 2;
|
|
1252
1038
|
return;
|
|
1253
1039
|
}
|
|
1254
|
-
const data = await client.post(`/api/test/test-plans/${encodeURIComponent(planId)}/cases
|
|
1040
|
+
const data = await client.post(`/api/test/test-plans/${encodeURIComponent(planId)}/cases`, { case_ids: caseIDs });
|
|
1255
1041
|
if (json) {
|
|
1256
1042
|
printJson(data);
|
|
1257
1043
|
return;
|
|
1258
1044
|
}
|
|
1259
|
-
const
|
|
1260
|
-
const
|
|
1261
|
-
const
|
|
1262
|
-
if (
|
|
1263
|
-
|
|
1264
|
-
|
|
1045
|
+
const added = Array.isArray(data["added"]) ? data["added"] : [];
|
|
1046
|
+
const already = Array.isArray(data["already_in_plan"]) ? data["already_in_plan"] : [];
|
|
1047
|
+
const rejected = Array.isArray(data["rejected"]) ? data["rejected"] : [];
|
|
1048
|
+
if (added.length) printSuccess(`Added ${added.length} case(s) to ${planId}: ${added.join(", ")}`);
|
|
1049
|
+
printKV([
|
|
1050
|
+
["Already in plan", already.length ? already.join(", ") : "—"],
|
|
1051
|
+
["Rejected", rejected.length ? rejected.map((r) => `${r.case_id}(${r.reason})`).join(", ") : "—"],
|
|
1052
|
+
["Case count", data["case_count"]],
|
|
1053
|
+
["Status", data["status"]]
|
|
1054
|
+
]);
|
|
1055
|
+
if (rejected.length) process.exitCode = 1;
|
|
1265
1056
|
}
|
|
1266
1057
|
async function runPlans(client, args, json) {
|
|
1267
1058
|
const action = args[0];
|
|
1268
1059
|
const subArgs = args.slice(1);
|
|
1269
1060
|
switch (action) {
|
|
1270
|
-
case "create": return create
|
|
1061
|
+
case "create": return create(client, subArgs, json);
|
|
1271
1062
|
case "get": return get(client, subArgs, json);
|
|
1272
1063
|
case "list": return list(client, subArgs, json);
|
|
1273
|
-
case "
|
|
1064
|
+
case "add": return add(client, subArgs, json);
|
|
1274
1065
|
case "--help":
|
|
1275
1066
|
case "-h":
|
|
1276
1067
|
case void 0:
|
|
1277
|
-
console.log(`plans commands:\n create Create a test plan\n get Get plan detail (--json for full case content)\n list List plans\n
|
|
1068
|
+
console.log(`plans commands:\n create Create a test plan\n get Get plan detail (--json for full case content)\n list List plans\n add Append source-set case(s) to an unreported plan`);
|
|
1278
1069
|
return;
|
|
1279
1070
|
default:
|
|
1280
1071
|
printError(`Unknown plans action: ${action}`);
|
|
1281
1072
|
process.exitCode = 2;
|
|
1282
1073
|
}
|
|
1283
1074
|
}
|
|
1284
|
-
async function mark(client, args, json) {
|
|
1285
|
-
const { positional, named } = parseNamedArgs(args);
|
|
1286
|
-
const planId = positional[0];
|
|
1287
|
-
const caseId = positional[1];
|
|
1288
|
-
if (!planId || !caseId) {
|
|
1289
|
-
printError("Usage: test results mark <plan_id> <case_id> --status <status>");
|
|
1290
|
-
process.exitCode = 2;
|
|
1291
|
-
return;
|
|
1292
|
-
}
|
|
1293
|
-
const status = requireArg(named, "status", "passed|failed|skipped|blocked");
|
|
1294
|
-
if (!VALID_MARK_STATUSES.includes(status)) {
|
|
1295
|
-
printError(`Invalid --status "${status}": must be ${VALID_MARK_STATUSES.join("|")}`);
|
|
1296
|
-
process.exitCode = 2;
|
|
1297
|
-
return;
|
|
1298
|
-
}
|
|
1299
|
-
const body = {
|
|
1300
|
-
plan_id: planId,
|
|
1301
|
-
case_id: caseId,
|
|
1302
|
-
status
|
|
1303
|
-
};
|
|
1304
|
-
if (typeof named["remark"] === "string") body["remark"] = named["remark"];
|
|
1305
|
-
if (typeof named["evidence-url"] === "string") body["evidence_url"] = named["evidence-url"];
|
|
1306
|
-
if (typeof named["duration-ms"] === "string") {
|
|
1307
|
-
const n = Number(named["duration-ms"]);
|
|
1308
|
-
if (Number.isNaN(n) || n < 0 || n > 36e5) {
|
|
1309
|
-
printError("--duration-ms must be a number in range 0~3600000");
|
|
1310
|
-
process.exitCode = 2;
|
|
1311
|
-
return;
|
|
1312
|
-
}
|
|
1313
|
-
body["duration_ms"] = n;
|
|
1314
|
-
}
|
|
1315
|
-
const data = await client.post("/api/test/case-results", body);
|
|
1316
|
-
if (json) {
|
|
1317
|
-
printJson(data);
|
|
1318
|
-
return;
|
|
1319
|
-
}
|
|
1320
|
-
printSuccess(`Marked ${caseId} as ${body["status"]} in ${planId}`);
|
|
1321
|
-
const p = data["progress"];
|
|
1322
|
-
if (p) console.log(` Progress: ${p["passed"]}/${p["total"]} passed, ${p["failed"]} failed, ${p["error"]} error, ${p["blocked"]} blocked, ${p["skipped"]} skipped, ${p["pending"]} pending`);
|
|
1323
|
-
console.log(` Plan status: ${data["plan_status"]}`);
|
|
1324
|
-
}
|
|
1325
1075
|
async function batch(client, args, json) {
|
|
1326
1076
|
const { positional, named } = parseNamedArgs(args);
|
|
1327
1077
|
const planId = positional[0];
|
|
@@ -1347,73 +1097,24 @@ async function runResults(client, args, json) {
|
|
|
1347
1097
|
const action = args[0];
|
|
1348
1098
|
const subArgs = args.slice(1);
|
|
1349
1099
|
switch (action) {
|
|
1350
|
-
case "mark": return mark(client, subArgs, json);
|
|
1351
1100
|
case "batch": return batch(client, subArgs, json);
|
|
1352
1101
|
case "--help":
|
|
1353
1102
|
case "-h":
|
|
1354
1103
|
case void 0:
|
|
1355
|
-
console.log(`results commands:\n
|
|
1104
|
+
console.log(`results commands:\n batch Batch submit results from file (Scenario B)`);
|
|
1356
1105
|
return;
|
|
1357
1106
|
default:
|
|
1358
1107
|
printError(`Unknown results action: ${action}`);
|
|
1359
1108
|
process.exitCode = 2;
|
|
1360
1109
|
}
|
|
1361
1110
|
}
|
|
1362
|
-
async function create(client, args, json) {
|
|
1363
|
-
const { positional, named } = parseNamedArgs(args);
|
|
1364
|
-
const planId = positional[0];
|
|
1365
|
-
if (!planId) {
|
|
1366
|
-
printError("Usage: test reports create <plan_id> [--conclusion <text>]");
|
|
1367
|
-
process.exitCode = 2;
|
|
1368
|
-
return;
|
|
1369
|
-
}
|
|
1370
|
-
const body = { plan_id: planId };
|
|
1371
|
-
if (typeof named["type"] === "string") {
|
|
1372
|
-
if (!VALID_PLAN_TYPES.includes(named["type"])) {
|
|
1373
|
-
printError(`Invalid --type "${named["type"]}": must be ${VALID_PLAN_TYPES.join("|")}`);
|
|
1374
|
-
process.exitCode = 2;
|
|
1375
|
-
return;
|
|
1376
|
-
}
|
|
1377
|
-
body["type"] = named["type"];
|
|
1378
|
-
}
|
|
1379
|
-
if (typeof named["conclusion"] === "string") body["conclusion"] = named["conclusion"];
|
|
1380
|
-
if (typeof named["risk-notes"] === "string") body["risk_notes"] = named["risk-notes"];
|
|
1381
|
-
const data = await client.post("/api/test/reports", body);
|
|
1382
|
-
if (json) {
|
|
1383
|
-
printJson(data);
|
|
1384
|
-
return;
|
|
1385
|
-
}
|
|
1386
|
-
printSuccess(`Report issued: ${data["report_id"]} (version ${data["version"]})`);
|
|
1387
|
-
console.log(` Plan: ${data["plan_id"]}`);
|
|
1388
|
-
const snap = data["summary_snapshot"];
|
|
1389
|
-
if (snap) {
|
|
1390
|
-
const counts = snap["counts"];
|
|
1391
|
-
if (counts) console.log(` Summary: ${counts["passed"]} passed, ${counts["failed"]} failed (total ${counts["total"]})`);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
async function runReports(client, args, json) {
|
|
1395
|
-
const action = args[0];
|
|
1396
|
-
const subArgs = args.slice(1);
|
|
1397
|
-
switch (action) {
|
|
1398
|
-
case "create": return create(client, subArgs, json);
|
|
1399
|
-
case "--help":
|
|
1400
|
-
case "-h":
|
|
1401
|
-
case void 0:
|
|
1402
|
-
console.log(`reports commands:\n create Issue a report for a plan`);
|
|
1403
|
-
return;
|
|
1404
|
-
default:
|
|
1405
|
-
printError(`Unknown reports action: ${action}`);
|
|
1406
|
-
process.exitCode = 2;
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
1111
|
const RESOURCES = {
|
|
1410
1112
|
taxonomy: runTaxonomy,
|
|
1411
1113
|
requirements: runRequirements,
|
|
1412
1114
|
cases: runCases,
|
|
1413
1115
|
"case-sets": runCaseSets,
|
|
1414
1116
|
plans: runPlans,
|
|
1415
|
-
results: runResults
|
|
1416
|
-
reports: runReports
|
|
1117
|
+
results: runResults
|
|
1417
1118
|
};
|
|
1418
1119
|
const HELP = `Testing platform commands (Scenario A & B).
|
|
1419
1120
|
|
|
@@ -1423,8 +1124,7 @@ Resources:
|
|
|
1423
1124
|
requirements Requirements & channel 1 sync
|
|
1424
1125
|
case-sets Case set member management
|
|
1425
1126
|
plans Test plans & execution
|
|
1426
|
-
results Test results (
|
|
1427
|
-
reports Test reports
|
|
1127
|
+
results Test results (batch)
|
|
1428
1128
|
|
|
1429
1129
|
Run: shoplazza-ai-dev-cli test <resource> --help`;
|
|
1430
1130
|
async function runTest(rawArgs) {
|
package/dist/cli.mjs
CHANGED
|
@@ -7238,5 +7238,12 @@ main().catch((err) => {
|
|
|
7238
7238
|
const msg = err instanceof Error ? err.stack ?? err.message : String(err);
|
|
7239
7239
|
console.error(`\n${BOLD}✗${RESET} ${msg}`);
|
|
7240
7240
|
process.exitCode = 1;
|
|
7241
|
-
}).finally(() => flushTelemetry().then(() =>
|
|
7241
|
+
}).finally(() => flushTelemetry().then(() => new Promise((resolve) => {
|
|
7242
|
+
let pending = 2;
|
|
7243
|
+
const done = () => {
|
|
7244
|
+
if (--pending === 0) resolve();
|
|
7245
|
+
};
|
|
7246
|
+
process.stdout.write("", done);
|
|
7247
|
+
process.stderr.write("", done);
|
|
7248
|
+
})).then(() => process.exit(process.exitCode ?? 0)));
|
|
7242
7249
|
export { loadConfig, runLogin };
|