shoplazza-ai-dev-cli 0.1.9 → 0.1.10
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 +219 -20
- package/package.json +1 -1
package/dist/_chunks/test.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { loadConfig, runLogin } from "../cli.mjs";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
|
+
import * as readline from "readline";
|
|
3
4
|
function parseGlobalFlags(args) {
|
|
4
5
|
const flags = { json: false };
|
|
5
6
|
const rest = [];
|
|
@@ -272,6 +273,55 @@ async function runTaxonomy(client, args, json) {
|
|
|
272
273
|
process.exitCode = 2;
|
|
273
274
|
}
|
|
274
275
|
}
|
|
276
|
+
function askConfirm(prompt) {
|
|
277
|
+
const rl = readline.createInterface({
|
|
278
|
+
input: process.stdin,
|
|
279
|
+
output: process.stderr
|
|
280
|
+
});
|
|
281
|
+
return new Promise((resolve) => {
|
|
282
|
+
rl.question(prompt, (answer) => {
|
|
283
|
+
rl.close();
|
|
284
|
+
resolve(answer.trim().toLowerCase());
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
289
|
+
try {
|
|
290
|
+
return await client.post(url, payload);
|
|
291
|
+
} catch (err) {
|
|
292
|
+
if (!(err instanceof ApiError) || err.status !== 409 || err.code !== "SYNC_UNLINK_GUARD") throw err;
|
|
293
|
+
const preview = err.data?.["unlink_preview"] ?? [];
|
|
294
|
+
const msg = err.message;
|
|
295
|
+
console.error(`\n⚠ ${msg}`);
|
|
296
|
+
console.error("将被移除的用例:");
|
|
297
|
+
for (const cid of preview) console.error(` - ${cid}`);
|
|
298
|
+
if (!confirmUnlink) {
|
|
299
|
+
console.error("\n如确认移除,请加 --confirm-unlink 重试。");
|
|
300
|
+
process.exitCode = 1;
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
if (json || !process.stdin.isTTY) {
|
|
304
|
+
console.error("\n非交互模式,不自动重发。请在交互终端使用 --confirm-unlink。");
|
|
305
|
+
process.exitCode = 1;
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
if (await askConfirm(`确认移除 ${preview.length} 条用例?(y/N) `) !== "y") {
|
|
309
|
+
console.error("已取消。");
|
|
310
|
+
process.exitCode = 1;
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
|
|
314
|
+
printError("Sync payload must be a JSON object (not array or primitive)");
|
|
315
|
+
process.exitCode = 1;
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
const body = {
|
|
319
|
+
...payload,
|
|
320
|
+
force_unlink: true
|
|
321
|
+
};
|
|
322
|
+
return await client.post(url, body);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
275
325
|
async function create$4(client, args, json) {
|
|
276
326
|
const { named } = parseNamedArgs(args);
|
|
277
327
|
const reqId = requireArg(named, "req-id", "req_id");
|
|
@@ -306,22 +356,75 @@ async function sync$1(client, args, json) {
|
|
|
306
356
|
return;
|
|
307
357
|
}
|
|
308
358
|
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
309
|
-
const
|
|
359
|
+
const confirmUnlink = named["confirm-unlink"] !== void 0;
|
|
360
|
+
const data = await syncWithGuard(client, `/api/test/requirements/${encodeURIComponent(reqId)}/cases:sync`, payload, json, confirmUnlink);
|
|
361
|
+
if (!data) return;
|
|
310
362
|
if (json) {
|
|
311
363
|
printJson(data);
|
|
312
364
|
return;
|
|
313
365
|
}
|
|
314
|
-
const s = data
|
|
366
|
+
const s = data["summary"];
|
|
367
|
+
const results = data["results"];
|
|
315
368
|
printSuccess(`Synced ${(s["created"] ?? 0) + (s["referenced"] ?? 0) + (s["updated"] ?? 0) + (s["skipped"] ?? 0)} cases to ${reqId}`);
|
|
316
369
|
printKV([
|
|
317
|
-
["Created", `${s["created"] ?? 0}${
|
|
370
|
+
["Created", `${s["created"] ?? 0}${results.filter((r) => r.action === "created").map((r) => ` (${r.case_id})`).join("")}`],
|
|
318
371
|
["Referenced", s["referenced"] ?? 0],
|
|
319
372
|
["Updated", s["updated"] ?? 0],
|
|
320
373
|
["Existing (linked)", s["skipped"] ?? 0],
|
|
321
374
|
["Unlinked", s["unlinked"] ?? 0],
|
|
322
375
|
["Failed", s["failed"] ?? 0]
|
|
323
376
|
]);
|
|
324
|
-
for (const r of
|
|
377
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
378
|
+
}
|
|
379
|
+
async function get$2(client, args, json) {
|
|
380
|
+
const { positional } = parseNamedArgs(args);
|
|
381
|
+
const reqId = positional[0];
|
|
382
|
+
if (!reqId) {
|
|
383
|
+
printError("Usage: test requirements get <req_id>");
|
|
384
|
+
process.exitCode = 2;
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const [detail, casesData] = await Promise.all([client.get(`/api/test/requirements/${encodeURIComponent(reqId)}`), client.get(`/api/test/requirements/${encodeURIComponent(reqId)}/cases`)]);
|
|
388
|
+
if (json) {
|
|
389
|
+
printJson({
|
|
390
|
+
...detail,
|
|
391
|
+
cases: casesData.items
|
|
392
|
+
});
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
printKV([
|
|
396
|
+
["Req ID", detail["req_id"]],
|
|
397
|
+
["Title", detail["title"]],
|
|
398
|
+
["Status", detail["status"]],
|
|
399
|
+
["Case Set ID", detail["case_set_id"] ?? "—"],
|
|
400
|
+
["Created By", detail["created_by_name"] || "—"],
|
|
401
|
+
["Created At", detail["created_at"]]
|
|
402
|
+
]);
|
|
403
|
+
const cases = casesData.items;
|
|
404
|
+
if (cases.length) {
|
|
405
|
+
console.log(`\n Cases (${cases.length}):`);
|
|
406
|
+
printTable(cases, [
|
|
407
|
+
{
|
|
408
|
+
key: "case_id",
|
|
409
|
+
label: "Case ID",
|
|
410
|
+
width: 12
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
key: "title",
|
|
414
|
+
label: "Title"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
key: "case_type",
|
|
418
|
+
label: "Type",
|
|
419
|
+
width: 5
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
key: "priority",
|
|
423
|
+
label: "Pri",
|
|
424
|
+
width: 4
|
|
425
|
+
}
|
|
426
|
+
]);
|
|
427
|
+
} else console.log("\n No cases linked.");
|
|
325
428
|
}
|
|
326
429
|
async function list$2(client, args, json) {
|
|
327
430
|
const { named } = parseNamedArgs(args);
|
|
@@ -363,18 +466,54 @@ async function runRequirements(client, args, json) {
|
|
|
363
466
|
const subArgs = args.slice(1);
|
|
364
467
|
switch (action) {
|
|
365
468
|
case "create": return create$4(client, subArgs, json);
|
|
469
|
+
case "get": return get$2(client, subArgs, json);
|
|
366
470
|
case "sync": return sync$1(client, subArgs, json);
|
|
367
471
|
case "list": return list$2(client, subArgs, json);
|
|
368
472
|
case "--help":
|
|
369
473
|
case "-h":
|
|
370
474
|
case void 0:
|
|
371
|
-
console.log(`requirements commands:\n create Create a requirement\n sync Sync cases to requirement (channel 1)\n list List requirements`);
|
|
475
|
+
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`);
|
|
372
476
|
return;
|
|
373
477
|
default:
|
|
374
478
|
printError(`Unknown requirements action: ${action}`);
|
|
375
479
|
process.exitCode = 2;
|
|
376
480
|
}
|
|
377
481
|
}
|
|
482
|
+
const VALID_CASE_TYPES = [
|
|
483
|
+
"api",
|
|
484
|
+
"ui",
|
|
485
|
+
"e2e"
|
|
486
|
+
];
|
|
487
|
+
const VALID_PRIORITIES = [
|
|
488
|
+
"P0",
|
|
489
|
+
"P1",
|
|
490
|
+
"P2",
|
|
491
|
+
"P3"
|
|
492
|
+
];
|
|
493
|
+
const VALID_PLAN_TYPES = [
|
|
494
|
+
"requirement",
|
|
495
|
+
"regression",
|
|
496
|
+
"smoke"
|
|
497
|
+
];
|
|
498
|
+
const VALID_ENVS = [
|
|
499
|
+
"local",
|
|
500
|
+
"dev",
|
|
501
|
+
"stg",
|
|
502
|
+
"prod",
|
|
503
|
+
"auto"
|
|
504
|
+
];
|
|
505
|
+
const VALID_MARK_STATUSES = [
|
|
506
|
+
"passed",
|
|
507
|
+
"failed",
|
|
508
|
+
"skipped",
|
|
509
|
+
"blocked"
|
|
510
|
+
];
|
|
511
|
+
const VALID_USER_KINDS = [
|
|
512
|
+
"regression",
|
|
513
|
+
"flow",
|
|
514
|
+
"baseline",
|
|
515
|
+
"custom"
|
|
516
|
+
];
|
|
378
517
|
async function create$3(client, args, json) {
|
|
379
518
|
const { named } = parseNamedArgs(args);
|
|
380
519
|
const body = {
|
|
@@ -385,7 +524,20 @@ async function create$3(client, args, json) {
|
|
|
385
524
|
expected: requireArg(named, "expected", "expected"),
|
|
386
525
|
steps: Array.isArray(named["steps"]) ? named["steps"] : named["steps"] ? [named["steps"]] : []
|
|
387
526
|
};
|
|
388
|
-
|
|
527
|
+
const caseType = body["case_type"];
|
|
528
|
+
if (!VALID_CASE_TYPES.includes(caseType)) {
|
|
529
|
+
printError(`Invalid --type "${caseType}": must be ${VALID_CASE_TYPES.join("|")}`);
|
|
530
|
+
process.exitCode = 2;
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (typeof named["priority"] === "string") {
|
|
534
|
+
if (!VALID_PRIORITIES.includes(named["priority"])) {
|
|
535
|
+
printError(`Invalid --priority "${named["priority"]}": must be ${VALID_PRIORITIES.join("|")}`);
|
|
536
|
+
process.exitCode = 2;
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
body["priority"] = named["priority"];
|
|
540
|
+
}
|
|
389
541
|
if (typeof named["precondition"] === "string") body["precondition"] = named["precondition"];
|
|
390
542
|
if (typeof named["source"] === "string") body["source"] = named["source"];
|
|
391
543
|
const tags = asArray(named["tags"]);
|
|
@@ -493,9 +645,16 @@ async function runCases(client, args, json) {
|
|
|
493
645
|
}
|
|
494
646
|
async function create$2(client, args, json) {
|
|
495
647
|
const { named } = parseNamedArgs(args);
|
|
648
|
+
const name = requireArg(named, "name", "name");
|
|
649
|
+
const kind = requireArg(named, "kind", "regression|flow|baseline|custom");
|
|
650
|
+
if (!VALID_USER_KINDS.includes(kind)) {
|
|
651
|
+
printError(`Invalid --kind "${kind}": must be ${VALID_USER_KINDS.join("|")} (requirement and smoke are system-managed)`);
|
|
652
|
+
process.exitCode = 2;
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
496
655
|
const body = {
|
|
497
|
-
name
|
|
498
|
-
kind
|
|
656
|
+
name,
|
|
657
|
+
kind,
|
|
499
658
|
selection_mode: "manual"
|
|
500
659
|
};
|
|
501
660
|
const data = await client.post("/api/test/case-sets", body);
|
|
@@ -584,22 +743,25 @@ async function sync(client, args, json) {
|
|
|
584
743
|
return;
|
|
585
744
|
}
|
|
586
745
|
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
587
|
-
const
|
|
746
|
+
const confirmUnlink = named["confirm-unlink"] !== void 0;
|
|
747
|
+
const data = await syncWithGuard(client, `/api/test/case-sets/${setId}/cases:sync`, payload, json, confirmUnlink);
|
|
748
|
+
if (!data) return;
|
|
588
749
|
if (json) {
|
|
589
750
|
printJson(data);
|
|
590
751
|
return;
|
|
591
752
|
}
|
|
592
|
-
const s = data
|
|
753
|
+
const s = data["summary"];
|
|
754
|
+
const results = data["results"];
|
|
593
755
|
printSuccess(`Synced ${(s["created"] ?? 0) + (s["referenced"] ?? 0) + (s["updated"] ?? 0) + (s["skipped"] ?? 0)} cases to set ${setId}`);
|
|
594
756
|
printKV([
|
|
595
|
-
["Created", `${s["created"] ?? 0}${
|
|
757
|
+
["Created", `${s["created"] ?? 0}${results.filter((r) => r.action === "created").map((r) => ` (${r.case_id})`).join("")}`],
|
|
596
758
|
["Referenced", s["referenced"] ?? 0],
|
|
597
759
|
["Updated", s["updated"] ?? 0],
|
|
598
760
|
["Existing (linked)", s["skipped"] ?? 0],
|
|
599
761
|
["Unlinked", s["unlinked"] ?? 0],
|
|
600
762
|
["Failed", s["failed"] ?? 0]
|
|
601
763
|
]);
|
|
602
|
-
for (const r of
|
|
764
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
603
765
|
}
|
|
604
766
|
async function runCaseSets(client, args, json) {
|
|
605
767
|
const action = args[0];
|
|
@@ -621,19 +783,43 @@ async function runCaseSets(client, args, json) {
|
|
|
621
783
|
}
|
|
622
784
|
async function create$1(client, args, json) {
|
|
623
785
|
const { named } = parseNamedArgs(args);
|
|
624
|
-
const
|
|
786
|
+
const planType = requireArg(named, "type", "requirement|regression|smoke");
|
|
787
|
+
if (!VALID_PLAN_TYPES.includes(planType)) {
|
|
788
|
+
printError(`Invalid --type "${planType}": must be ${VALID_PLAN_TYPES.join("|")}`);
|
|
789
|
+
process.exitCode = 2;
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const body = { type: planType };
|
|
625
793
|
if (typeof named["title"] === "string") body["title"] = named["title"];
|
|
626
794
|
if (typeof named["from-set"] === "string") body["from_case_set"] = Number(named["from-set"]);
|
|
627
795
|
if (typeof named["case-ids"] === "string") body["case_ids"] = named["case-ids"].split(",").map((s) => s.trim());
|
|
628
796
|
if (typeof named["req-id"] === "string") body["req_id"] = named["req-id"];
|
|
629
|
-
if (typeof named["env"] === "string")
|
|
797
|
+
if (typeof named["env"] === "string") {
|
|
798
|
+
if (!VALID_ENVS.includes(named["env"])) {
|
|
799
|
+
printError(`Invalid --env "${named["env"]}": must be ${VALID_ENVS.join("|")}`);
|
|
800
|
+
process.exitCode = 2;
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
body["env"] = named["env"];
|
|
804
|
+
}
|
|
630
805
|
const tags = asArray(named["tags"]);
|
|
631
806
|
if (tags.length) body["tags"] = tags;
|
|
632
|
-
|
|
633
|
-
|
|
807
|
+
const sources = [
|
|
808
|
+
body["case_ids"] ? "case-ids" : null,
|
|
809
|
+
body["from_case_set"] !== void 0 ? "from-set" : null,
|
|
810
|
+
body["req_id"] ? "req-id" : null
|
|
811
|
+
].filter(Boolean);
|
|
812
|
+
if (sources.length === 0) {
|
|
813
|
+
printError("Must specify one of --case-ids, --from-set, or --req-id");
|
|
814
|
+
process.exitCode = 2;
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (sources.length > 1) {
|
|
818
|
+
printError(`--${sources.join(", --")} are mutually exclusive`);
|
|
634
819
|
process.exitCode = 2;
|
|
635
820
|
return;
|
|
636
821
|
}
|
|
822
|
+
if (body["case_ids"]) console.error("⚠ 建议使用 --req-id 或 --from-set 从用例集拉取,避免手工枚举遗漏");
|
|
637
823
|
const data = await client.post("/api/test/test-plans", body);
|
|
638
824
|
if (json) {
|
|
639
825
|
printJson(data);
|
|
@@ -751,17 +937,23 @@ async function mark(client, args, json) {
|
|
|
751
937
|
process.exitCode = 2;
|
|
752
938
|
return;
|
|
753
939
|
}
|
|
940
|
+
const status = requireArg(named, "status", "passed|failed|skipped|blocked");
|
|
941
|
+
if (!VALID_MARK_STATUSES.includes(status)) {
|
|
942
|
+
printError(`Invalid --status "${status}": must be ${VALID_MARK_STATUSES.join("|")}`);
|
|
943
|
+
process.exitCode = 2;
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
754
946
|
const body = {
|
|
755
947
|
plan_id: planId,
|
|
756
948
|
case_id: caseId,
|
|
757
|
-
status
|
|
949
|
+
status
|
|
758
950
|
};
|
|
759
951
|
if (typeof named["remark"] === "string") body["remark"] = named["remark"];
|
|
760
952
|
if (typeof named["evidence-url"] === "string") body["evidence_url"] = named["evidence-url"];
|
|
761
953
|
if (typeof named["duration-ms"] === "string") {
|
|
762
954
|
const n = Number(named["duration-ms"]);
|
|
763
|
-
if (Number.isNaN(n)) {
|
|
764
|
-
printError("--duration-ms must be a number");
|
|
955
|
+
if (Number.isNaN(n) || n < 0 || n > 36e5) {
|
|
956
|
+
printError("--duration-ms must be a number in range 0~3600000");
|
|
765
957
|
process.exitCode = 2;
|
|
766
958
|
return;
|
|
767
959
|
}
|
|
@@ -823,7 +1015,14 @@ async function create(client, args, json) {
|
|
|
823
1015
|
return;
|
|
824
1016
|
}
|
|
825
1017
|
const body = { plan_id: planId };
|
|
826
|
-
if (typeof named["type"] === "string")
|
|
1018
|
+
if (typeof named["type"] === "string") {
|
|
1019
|
+
if (!VALID_PLAN_TYPES.includes(named["type"])) {
|
|
1020
|
+
printError(`Invalid --type "${named["type"]}": must be ${VALID_PLAN_TYPES.join("|")}`);
|
|
1021
|
+
process.exitCode = 2;
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
body["type"] = named["type"];
|
|
1025
|
+
}
|
|
827
1026
|
if (typeof named["conclusion"] === "string") body["conclusion"] = named["conclusion"];
|
|
828
1027
|
if (typeof named["risk-notes"] === "string") body["risk_notes"] = named["risk-notes"];
|
|
829
1028
|
const data = await client.post("/api/test/reports", body);
|