shoplazza-ai-dev-cli 0.1.10 → 0.1.12
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 +224 -29
- package/package.json +1 -1
package/dist/_chunks/test.mjs
CHANGED
|
@@ -326,15 +326,20 @@ async function create$4(client, args, json) {
|
|
|
326
326
|
const { named } = parseNamedArgs(args);
|
|
327
327
|
const reqId = requireArg(named, "req-id", "req_id");
|
|
328
328
|
const title = requireArg(named, "title", "title");
|
|
329
|
-
const bl =
|
|
329
|
+
const bl = requireArg(named, "bl", "business_line");
|
|
330
330
|
const modulePaths = asArray(named["module-paths"]);
|
|
331
|
+
if (modulePaths.length === 0) {
|
|
332
|
+
printError("Missing required flag: --module-paths <path1,path2,...>");
|
|
333
|
+
process.exitCode = 2;
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
331
336
|
const feishuUrl = typeof named["feishu-url"] === "string" ? named["feishu-url"] : void 0;
|
|
332
337
|
const body = {
|
|
333
338
|
req_id: reqId,
|
|
334
|
-
title
|
|
339
|
+
title,
|
|
340
|
+
business_line: bl,
|
|
341
|
+
module_paths: modulePaths
|
|
335
342
|
};
|
|
336
|
-
if (bl) body["business_line"] = bl;
|
|
337
|
-
if (modulePaths.length) body["module_paths"] = modulePaths;
|
|
338
343
|
if (feishuUrl) body["feishu_ticket_url"] = feishuUrl;
|
|
339
344
|
const data = await client.post("/api/test/requirements", body);
|
|
340
345
|
if (json) {
|
|
@@ -479,11 +484,7 @@ async function runRequirements(client, args, json) {
|
|
|
479
484
|
process.exitCode = 2;
|
|
480
485
|
}
|
|
481
486
|
}
|
|
482
|
-
const VALID_CASE_TYPES = [
|
|
483
|
-
"api",
|
|
484
|
-
"ui",
|
|
485
|
-
"e2e"
|
|
486
|
-
];
|
|
487
|
+
const VALID_CASE_TYPES = ["api", "e2e"];
|
|
487
488
|
const VALID_PRIORITIES = [
|
|
488
489
|
"P0",
|
|
489
490
|
"P1",
|
|
@@ -521,9 +522,25 @@ async function create$3(client, args, json) {
|
|
|
521
522
|
business_line: requireArg(named, "bl", "business_line"),
|
|
522
523
|
module_path: requireArg(named, "module-path", "module_path"),
|
|
523
524
|
case_type: requireArg(named, "type", "case_type"),
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
steps: (() => {
|
|
526
|
+
const raw = requireArg(named, "steps", "steps");
|
|
527
|
+
try {
|
|
528
|
+
const parsed = JSON.parse(raw);
|
|
529
|
+
if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("steps must be a non-empty JSON array");
|
|
530
|
+
for (let i = 0; i < parsed.length; i++) {
|
|
531
|
+
const s = parsed[i];
|
|
532
|
+
if (!s.step?.trim()) throw new Error(`steps[${i}].step is empty`);
|
|
533
|
+
if (!s.expected?.trim()) throw new Error(`steps[${i}].expected is empty`);
|
|
534
|
+
}
|
|
535
|
+
return parsed;
|
|
536
|
+
} catch (e) {
|
|
537
|
+
printError(`Invalid --steps: ${e.message}`);
|
|
538
|
+
process.exitCode = 2;
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
})()
|
|
526
542
|
};
|
|
543
|
+
if (body["steps"] === null) return;
|
|
527
544
|
const caseType = body["case_type"];
|
|
528
545
|
if (!VALID_CASE_TYPES.includes(caseType)) {
|
|
529
546
|
printError(`Invalid --type "${caseType}": must be ${VALID_CASE_TYPES.join("|")}`);
|
|
@@ -538,15 +555,10 @@ async function create$3(client, args, json) {
|
|
|
538
555
|
}
|
|
539
556
|
body["priority"] = named["priority"];
|
|
540
557
|
}
|
|
541
|
-
|
|
558
|
+
body["precondition"] = requireArg(named, "precondition", "precondition");
|
|
542
559
|
if (typeof named["source"] === "string") body["source"] = named["source"];
|
|
543
560
|
const tags = asArray(named["tags"]);
|
|
544
561
|
if (tags.length) body["tags"] = tags;
|
|
545
|
-
if (!body["steps"] || body["steps"].length === 0) {
|
|
546
|
-
printError("At least one --steps required");
|
|
547
|
-
process.exitCode = 2;
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
562
|
const data = await client.post("/api/test/cases", body);
|
|
551
563
|
if (json) {
|
|
552
564
|
printJson(data);
|
|
@@ -626,6 +638,166 @@ async function batch$1(client, args, json) {
|
|
|
626
638
|
for (const r of data.results.filter((r) => r.action === "created")) console.log(` ${r.case_id} ${r.client_ref || ""}`);
|
|
627
639
|
for (const r of data.results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
628
640
|
}
|
|
641
|
+
async function remove$1(client, args, json) {
|
|
642
|
+
if (args.length === 0) {
|
|
643
|
+
printError("Usage: test cases delete <case_id...>");
|
|
644
|
+
process.exitCode = 2;
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
const data = await client.post("/api/test/cases:delete", { case_ids: args });
|
|
648
|
+
if (json) {
|
|
649
|
+
printJson(data);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (data.deleted.length) printSuccess(`Deleted: ${data.deleted.join(", ")}`);
|
|
653
|
+
for (const item of data.blocked ?? []) printError(`${item.case_id}: referenced by plan(s) ${item.plan_ids.join(", ")}`);
|
|
654
|
+
if (data.not_found?.length) printError(`Not found: ${data.not_found.join(", ")}`);
|
|
655
|
+
if (data.already?.length) printError(`Already deleted: ${data.already.join(", ")}`);
|
|
656
|
+
}
|
|
657
|
+
const UPDATE_FIELDS = [
|
|
658
|
+
"title",
|
|
659
|
+
"precondition",
|
|
660
|
+
"steps",
|
|
661
|
+
"priority",
|
|
662
|
+
"tags",
|
|
663
|
+
"status",
|
|
664
|
+
"case_type",
|
|
665
|
+
"module_path",
|
|
666
|
+
"module_id",
|
|
667
|
+
"business_line"
|
|
668
|
+
];
|
|
669
|
+
function namedArgsToRaw(named) {
|
|
670
|
+
const flagToField = {
|
|
671
|
+
title: "title",
|
|
672
|
+
precondition: "precondition",
|
|
673
|
+
priority: "priority",
|
|
674
|
+
type: "case_type",
|
|
675
|
+
status: "status",
|
|
676
|
+
"module-path": "module_path",
|
|
677
|
+
bl: "business_line",
|
|
678
|
+
"module-id": "module_id"
|
|
679
|
+
};
|
|
680
|
+
const raw = {};
|
|
681
|
+
for (const [flag, field] of Object.entries(flagToField)) {
|
|
682
|
+
const v = named[flag];
|
|
683
|
+
const val = Array.isArray(v) ? v[v.length - 1] : v;
|
|
684
|
+
if (typeof val === "string") raw[field] = val;
|
|
685
|
+
}
|
|
686
|
+
if (named["tags"] !== void 0) raw["tags"] = asArray(named["tags"]);
|
|
687
|
+
if (typeof named["steps"] === "string") {
|
|
688
|
+
let parsed;
|
|
689
|
+
try {
|
|
690
|
+
parsed = JSON.parse(named["steps"]);
|
|
691
|
+
} catch (e) {
|
|
692
|
+
throw new Error(`Invalid --steps JSON: ${e.message}`);
|
|
693
|
+
}
|
|
694
|
+
raw["steps"] = parsed;
|
|
695
|
+
}
|
|
696
|
+
return raw;
|
|
697
|
+
}
|
|
698
|
+
function buildCaseUpdatePayload(raw) {
|
|
699
|
+
for (const k of Object.keys(raw)) if (!UPDATE_FIELDS.includes(k)) throw new Error(`Unknown field "${k}": allowed fields are ${UPDATE_FIELDS.join(", ")}`);
|
|
700
|
+
const body = {};
|
|
701
|
+
for (const f of [
|
|
702
|
+
"title",
|
|
703
|
+
"precondition",
|
|
704
|
+
"status",
|
|
705
|
+
"module_path",
|
|
706
|
+
"business_line"
|
|
707
|
+
]) if (raw[f] !== void 0) body[f] = String(raw[f]);
|
|
708
|
+
if (raw["module_id"] !== void 0) {
|
|
709
|
+
const n = Number(raw["module_id"]);
|
|
710
|
+
if (!Number.isFinite(n)) throw new Error(`Invalid module_id: ${String(raw["module_id"])}`);
|
|
711
|
+
body["module_id"] = n;
|
|
712
|
+
}
|
|
713
|
+
if (raw["priority"] !== void 0) {
|
|
714
|
+
const p = String(raw["priority"]);
|
|
715
|
+
if (!VALID_PRIORITIES.includes(p)) throw new Error(`Invalid priority "${p}": must be ${VALID_PRIORITIES.join("|")}`);
|
|
716
|
+
body["priority"] = p;
|
|
717
|
+
}
|
|
718
|
+
if (raw["case_type"] !== void 0) {
|
|
719
|
+
const t = String(raw["case_type"]);
|
|
720
|
+
if (!VALID_CASE_TYPES.includes(t)) throw new Error(`Invalid case_type "${t}": must be ${VALID_CASE_TYPES.join("|")}`);
|
|
721
|
+
body["case_type"] = t;
|
|
722
|
+
}
|
|
723
|
+
if (raw["tags"] !== void 0) {
|
|
724
|
+
if (!Array.isArray(raw["tags"])) throw new Error("tags must be an array of strings");
|
|
725
|
+
body["tags"] = raw["tags"].map((x) => String(x));
|
|
726
|
+
}
|
|
727
|
+
if (raw["steps"] !== void 0) {
|
|
728
|
+
const steps = raw["steps"];
|
|
729
|
+
if (!Array.isArray(steps) || steps.length === 0) throw new Error("steps must be a non-empty array");
|
|
730
|
+
for (let i = 0; i < steps.length; i++) {
|
|
731
|
+
const s = steps[i];
|
|
732
|
+
if (!s || typeof s.step !== "string" || !s.step.trim()) throw new Error(`steps[${i}].step is empty`);
|
|
733
|
+
if (typeof s.expected !== "string" || !s.expected.trim()) throw new Error(`steps[${i}].expected is empty`);
|
|
734
|
+
}
|
|
735
|
+
body["steps"] = steps;
|
|
736
|
+
}
|
|
737
|
+
if (Object.keys(body).length === 0) throw new Error("At least one field to update is required (empty update rejected)");
|
|
738
|
+
return body;
|
|
739
|
+
}
|
|
740
|
+
function resolveUpdateInput(positional, named) {
|
|
741
|
+
const caseId = positional[0];
|
|
742
|
+
if (!caseId) throw new Error("case_id positional argument is required");
|
|
743
|
+
const usedNamed = [
|
|
744
|
+
"title",
|
|
745
|
+
"precondition",
|
|
746
|
+
"priority",
|
|
747
|
+
"type",
|
|
748
|
+
"status",
|
|
749
|
+
"module-path",
|
|
750
|
+
"bl",
|
|
751
|
+
"module-id",
|
|
752
|
+
"tags",
|
|
753
|
+
"steps"
|
|
754
|
+
].filter((f) => named[f] !== void 0);
|
|
755
|
+
const useFile = typeof named["file"] === "string";
|
|
756
|
+
if (useFile && usedNamed.length) throw new Error("--file is mutually exclusive with named field flags");
|
|
757
|
+
return {
|
|
758
|
+
caseId,
|
|
759
|
+
useFile
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async function update(client, args, json) {
|
|
763
|
+
const { positional, named } = parseNamedArgs(args);
|
|
764
|
+
let caseId;
|
|
765
|
+
let body;
|
|
766
|
+
try {
|
|
767
|
+
const resolved = resolveUpdateInput(positional, named);
|
|
768
|
+
caseId = resolved.caseId;
|
|
769
|
+
if (resolved.useFile) {
|
|
770
|
+
const raw = readFileInput(named["file"]);
|
|
771
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("--file must contain a JSON object of fields to update");
|
|
772
|
+
body = buildCaseUpdatePayload(raw);
|
|
773
|
+
} else body = buildCaseUpdatePayload(namedArgsToRaw(named));
|
|
774
|
+
} catch (e) {
|
|
775
|
+
printError(e.message);
|
|
776
|
+
process.exitCode = 2;
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
try {
|
|
780
|
+
const data = await client.patch(`/api/test/cases/${encodeURIComponent(caseId)}`, body);
|
|
781
|
+
if (json) {
|
|
782
|
+
printJson(data);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
printSuccess(`Case updated: ${data["case_id"] ?? caseId}`);
|
|
786
|
+
printKV([
|
|
787
|
+
["Title", data["title"]],
|
|
788
|
+
["Type", data["case_type"]],
|
|
789
|
+
["Priority", data["priority"] || "—"],
|
|
790
|
+
["Version", data["version"] ?? "—"]
|
|
791
|
+
]);
|
|
792
|
+
} catch (e) {
|
|
793
|
+
const err = e;
|
|
794
|
+
if (err.code === "CASE_NOT_FOUND" || err.status === 404) printError(`用例不存在:${caseId}`);
|
|
795
|
+
else if (err.code === "CASE_TYPE_AUTOMATED" || err.status === 409) printError(`用例已绑定自动化,不可修改 case_type:${err.message ?? ""}`);
|
|
796
|
+
else if (err.status === 400) printError(`校验失败:${err.message ?? ""}`);
|
|
797
|
+
else printError(e.message);
|
|
798
|
+
process.exitCode = 1;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
629
801
|
async function runCases(client, args, json) {
|
|
630
802
|
const action = args[0];
|
|
631
803
|
const subArgs = args.slice(1);
|
|
@@ -633,10 +805,12 @@ async function runCases(client, args, json) {
|
|
|
633
805
|
case "create": return create$3(client, subArgs, json);
|
|
634
806
|
case "list": return list$1(client, subArgs, json);
|
|
635
807
|
case "batch": return batch$1(client, subArgs, json);
|
|
808
|
+
case "delete": return remove$1(client, subArgs, json);
|
|
809
|
+
case "update": return update(client, subArgs, json);
|
|
636
810
|
case "--help":
|
|
637
811
|
case "-h":
|
|
638
812
|
case void 0:
|
|
639
|
-
console.log(`cases commands:\n create Create a standalone case\n list List cases with filters\n batch Batch create cases from JSON (--file <path>)`);
|
|
813
|
+
console.log(`cases commands:\n create Create a standalone case\n list List cases with filters\n batch Batch create cases from JSON (--file <path>)\n update Patch a case by id (pointer semantics: only pass fields to change; --file <path|-> for JSON body)\n delete Soft-delete case assets by id`);
|
|
640
814
|
return;
|
|
641
815
|
default:
|
|
642
816
|
printError(`Unknown cases action: ${action}`);
|
|
@@ -652,10 +826,12 @@ async function create$2(client, args, json) {
|
|
|
652
826
|
process.exitCode = 2;
|
|
653
827
|
return;
|
|
654
828
|
}
|
|
829
|
+
const moduleId = requireArg(named, "module", "module_id (integer)");
|
|
655
830
|
const body = {
|
|
656
831
|
name,
|
|
657
832
|
kind,
|
|
658
|
-
selection_mode: "manual"
|
|
833
|
+
selection_mode: "manual",
|
|
834
|
+
primary_module_id: parseInt(moduleId, 10)
|
|
659
835
|
};
|
|
660
836
|
const data = await client.post("/api/test/case-sets", body);
|
|
661
837
|
if (json) {
|
|
@@ -669,26 +845,24 @@ async function members(client, args, json) {
|
|
|
669
845
|
const { positional, named } = parseNamedArgs(args);
|
|
670
846
|
const setId = positional[0];
|
|
671
847
|
if (!setId) {
|
|
672
|
-
printError("Usage: test case-sets members <set_id>
|
|
848
|
+
printError("Usage: test case-sets members <set_id> --add ...");
|
|
673
849
|
process.exitCode = 2;
|
|
674
850
|
return;
|
|
675
851
|
}
|
|
676
852
|
const add = asArray(named["add"]);
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
printError("Provide --add or --remove");
|
|
853
|
+
if (!add.length) {
|
|
854
|
+
printError("Provide --add");
|
|
680
855
|
process.exitCode = 2;
|
|
681
856
|
return;
|
|
682
857
|
}
|
|
683
858
|
const body = {};
|
|
684
859
|
if (add.length) body["add"] = add;
|
|
685
|
-
if (remove.length) body["remove"] = remove;
|
|
686
860
|
const data = await client.post(`/api/test/case-sets/${setId}/members:batch`, body);
|
|
687
861
|
if (json) {
|
|
688
862
|
printJson(data);
|
|
689
863
|
return;
|
|
690
864
|
}
|
|
691
|
-
printSuccess(`Added ${data.added},
|
|
865
|
+
printSuccess(`Added ${data.added}, invalid: ${(data.invalid ?? []).length}`);
|
|
692
866
|
}
|
|
693
867
|
async function get$1(client, args, json) {
|
|
694
868
|
const { positional } = parseNamedArgs(args);
|
|
@@ -774,7 +948,7 @@ async function runCaseSets(client, args, json) {
|
|
|
774
948
|
case "--help":
|
|
775
949
|
case "-h":
|
|
776
950
|
case void 0:
|
|
777
|
-
console.log(`case-sets commands:\n create Create a case set (--name, --kind)\n get Get case set detail with members\n members Batch add
|
|
951
|
+
console.log(`case-sets commands:\n create Create a case set (--name, --kind [--module <id>])\n get Get case set detail with members\n members Batch add members (--add)\n sync Sync cases to a set (--file <path>)`);
|
|
778
952
|
return;
|
|
779
953
|
default:
|
|
780
954
|
printError(`Unknown case-sets action: ${action}`);
|
|
@@ -911,6 +1085,26 @@ async function list(client, args, json) {
|
|
|
911
1085
|
]);
|
|
912
1086
|
printPagination(data.total);
|
|
913
1087
|
}
|
|
1088
|
+
async function remove(client, args, json) {
|
|
1089
|
+
const { positional } = parseNamedArgs(args);
|
|
1090
|
+
const [planId, ...caseIDs] = positional;
|
|
1091
|
+
if (!planId || caseIDs.length === 0) {
|
|
1092
|
+
printError("Usage: test plans remove <plan_id> <case_id> [case_id...]");
|
|
1093
|
+
process.exitCode = 2;
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
const data = await client.post(`/api/test/test-plans/${encodeURIComponent(planId)}/cases:remove`, { case_ids: caseIDs });
|
|
1097
|
+
if (json) {
|
|
1098
|
+
printJson(data);
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
const removed = Array.isArray(data["removed"]) ? data["removed"] : [];
|
|
1102
|
+
const blocked = Array.isArray(data["blocked"]) ? data["blocked"] : [];
|
|
1103
|
+
const notInPlan = Array.isArray(data["not_in_plan"]) ? data["not_in_plan"] : [];
|
|
1104
|
+
if (removed.length) printSuccess(`Removed ${removed.length} case(s) from ${planId}`);
|
|
1105
|
+
if (blocked.length) printKV([["Blocked", JSON.stringify(blocked)]]);
|
|
1106
|
+
if (notInPlan.length) printKV([["Not in plan", notInPlan.join(", ")]]);
|
|
1107
|
+
}
|
|
914
1108
|
async function runPlans(client, args, json) {
|
|
915
1109
|
const action = args[0];
|
|
916
1110
|
const subArgs = args.slice(1);
|
|
@@ -918,10 +1112,11 @@ async function runPlans(client, args, json) {
|
|
|
918
1112
|
case "create": return create$1(client, subArgs, json);
|
|
919
1113
|
case "get": return get(client, subArgs, json);
|
|
920
1114
|
case "list": return list(client, subArgs, json);
|
|
1115
|
+
case "remove": return remove(client, subArgs, json);
|
|
921
1116
|
case "--help":
|
|
922
1117
|
case "-h":
|
|
923
1118
|
case void 0:
|
|
924
|
-
console.log(`plans commands:\n create Create a test plan\n get Get plan detail (--json for full case content)\n list List plans`);
|
|
1119
|
+
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 remove Remove case(s) from an unreported plan`);
|
|
925
1120
|
return;
|
|
926
1121
|
default:
|
|
927
1122
|
printError(`Unknown plans action: ${action}`);
|
|
@@ -966,7 +1161,7 @@ async function mark(client, args, json) {
|
|
|
966
1161
|
}
|
|
967
1162
|
printSuccess(`Marked ${caseId} as ${body["status"]} in ${planId}`);
|
|
968
1163
|
const p = data["progress"];
|
|
969
|
-
if (p) console.log(` Progress: ${p["passed"]}/${p["total"]} passed, ${p["failed"]} failed, ${p["pending"]} pending`);
|
|
1164
|
+
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`);
|
|
970
1165
|
console.log(` Plan status: ${data["plan_status"]}`);
|
|
971
1166
|
}
|
|
972
1167
|
async function batch(client, args, json) {
|
|
@@ -988,7 +1183,7 @@ async function batch(client, args, json) {
|
|
|
988
1183
|
printSuccess(`Batch submitted: ${data["marked"]} marked, ${(invalid ?? []).length} invalid`);
|
|
989
1184
|
console.log(` Plan status: ${data["plan_status"]}`);
|
|
990
1185
|
const p = data["progress"];
|
|
991
|
-
if (p) console.log(` Progress: ${p["passed"]} passed, ${p["failed"]} failed, ${p["pending"]} pending`);
|
|
1186
|
+
if (p) console.log(` Progress: ${p["passed"]} passed, ${p["failed"]} failed, ${p["error"]} error, ${p["blocked"]} blocked, ${p["skipped"]} skipped, ${p["pending"]} pending`);
|
|
992
1187
|
}
|
|
993
1188
|
async function runResults(client, args, json) {
|
|
994
1189
|
const action = args[0];
|