shoplazza-ai-dev-cli 0.1.11 → 0.1.13
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 +192 -11
- package/dist/cli.mjs +4 -1
- package/package.json +1 -1
package/dist/_chunks/test.mjs
CHANGED
|
@@ -638,6 +638,166 @@ async function batch$1(client, args, json) {
|
|
|
638
638
|
for (const r of data.results.filter((r) => r.action === "created")) console.log(` ${r.case_id} ${r.client_ref || ""}`);
|
|
639
639
|
for (const r of data.results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
640
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
|
+
}
|
|
641
801
|
async function runCases(client, args, json) {
|
|
642
802
|
const action = args[0];
|
|
643
803
|
const subArgs = args.slice(1);
|
|
@@ -645,10 +805,12 @@ async function runCases(client, args, json) {
|
|
|
645
805
|
case "create": return create$3(client, subArgs, json);
|
|
646
806
|
case "list": return list$1(client, subArgs, json);
|
|
647
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);
|
|
648
810
|
case "--help":
|
|
649
811
|
case "-h":
|
|
650
812
|
case void 0:
|
|
651
|
-
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`);
|
|
652
814
|
return;
|
|
653
815
|
default:
|
|
654
816
|
printError(`Unknown cases action: ${action}`);
|
|
@@ -683,26 +845,24 @@ async function members(client, args, json) {
|
|
|
683
845
|
const { positional, named } = parseNamedArgs(args);
|
|
684
846
|
const setId = positional[0];
|
|
685
847
|
if (!setId) {
|
|
686
|
-
printError("Usage: test case-sets members <set_id>
|
|
848
|
+
printError("Usage: test case-sets members <set_id> --add ...");
|
|
687
849
|
process.exitCode = 2;
|
|
688
850
|
return;
|
|
689
851
|
}
|
|
690
852
|
const add = asArray(named["add"]);
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
printError("Provide --add or --remove");
|
|
853
|
+
if (!add.length) {
|
|
854
|
+
printError("Provide --add");
|
|
694
855
|
process.exitCode = 2;
|
|
695
856
|
return;
|
|
696
857
|
}
|
|
697
858
|
const body = {};
|
|
698
859
|
if (add.length) body["add"] = add;
|
|
699
|
-
if (remove.length) body["remove"] = remove;
|
|
700
860
|
const data = await client.post(`/api/test/case-sets/${setId}/members:batch`, body);
|
|
701
861
|
if (json) {
|
|
702
862
|
printJson(data);
|
|
703
863
|
return;
|
|
704
864
|
}
|
|
705
|
-
printSuccess(`Added ${data.added},
|
|
865
|
+
printSuccess(`Added ${data.added}, invalid: ${(data.invalid ?? []).length}`);
|
|
706
866
|
}
|
|
707
867
|
async function get$1(client, args, json) {
|
|
708
868
|
const { positional } = parseNamedArgs(args);
|
|
@@ -788,7 +948,7 @@ async function runCaseSets(client, args, json) {
|
|
|
788
948
|
case "--help":
|
|
789
949
|
case "-h":
|
|
790
950
|
case void 0:
|
|
791
|
-
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
|
|
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>)`);
|
|
792
952
|
return;
|
|
793
953
|
default:
|
|
794
954
|
printError(`Unknown case-sets action: ${action}`);
|
|
@@ -925,6 +1085,26 @@ async function list(client, args, json) {
|
|
|
925
1085
|
]);
|
|
926
1086
|
printPagination(data.total);
|
|
927
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
|
+
}
|
|
928
1108
|
async function runPlans(client, args, json) {
|
|
929
1109
|
const action = args[0];
|
|
930
1110
|
const subArgs = args.slice(1);
|
|
@@ -932,10 +1112,11 @@ async function runPlans(client, args, json) {
|
|
|
932
1112
|
case "create": return create$1(client, subArgs, json);
|
|
933
1113
|
case "get": return get(client, subArgs, json);
|
|
934
1114
|
case "list": return list(client, subArgs, json);
|
|
1115
|
+
case "remove": return remove(client, subArgs, json);
|
|
935
1116
|
case "--help":
|
|
936
1117
|
case "-h":
|
|
937
1118
|
case void 0:
|
|
938
|
-
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`);
|
|
939
1120
|
return;
|
|
940
1121
|
default:
|
|
941
1122
|
printError(`Unknown plans action: ${action}`);
|
|
@@ -980,7 +1161,7 @@ async function mark(client, args, json) {
|
|
|
980
1161
|
}
|
|
981
1162
|
printSuccess(`Marked ${caseId} as ${body["status"]} in ${planId}`);
|
|
982
1163
|
const p = data["progress"];
|
|
983
|
-
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`);
|
|
984
1165
|
console.log(` Plan status: ${data["plan_status"]}`);
|
|
985
1166
|
}
|
|
986
1167
|
async function batch(client, args, json) {
|
|
@@ -1002,7 +1183,7 @@ async function batch(client, args, json) {
|
|
|
1002
1183
|
printSuccess(`Batch submitted: ${data["marked"]} marked, ${(invalid ?? []).length} invalid`);
|
|
1003
1184
|
console.log(` Plan status: ${data["plan_status"]}`);
|
|
1004
1185
|
const p = data["progress"];
|
|
1005
|
-
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`);
|
|
1006
1187
|
}
|
|
1007
1188
|
async function runResults(client, args, json) {
|
|
1008
1189
|
const action = args[0];
|
package/dist/cli.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { homedir, hostname, platform, tmpdir } from "os";
|
|
|
13
13
|
import { access, chmod, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, realpath, rm, stat, symlink, writeFile } from "fs/promises";
|
|
14
14
|
import { createServer } from "http";
|
|
15
15
|
import { gunzipSync } from "node:zlib";
|
|
16
|
-
import { mkdirSync as mkdirSync$1, writeFileSync as writeFileSync$1 } from "node:fs";
|
|
16
|
+
import { chmodSync as chmodSync$1, mkdirSync as mkdirSync$1, writeFileSync as writeFileSync$1 } from "node:fs";
|
|
17
17
|
import { dirname as dirname$1, normalize as normalize$1, resolve as resolve$1, sep as sep$1 } from "node:path";
|
|
18
18
|
import { parse } from "yaml";
|
|
19
19
|
import * as readline from "readline";
|
|
@@ -1342,6 +1342,8 @@ function extractTarGz(gz, dest) {
|
|
|
1342
1342
|
const header = tar.subarray(offset, offset + 512);
|
|
1343
1343
|
if (header[0] === 0) break;
|
|
1344
1344
|
const name = readCStr(header, 0, 100);
|
|
1345
|
+
const modeOctal = readCStr(header, 100, 8).trim();
|
|
1346
|
+
const mode = parseInt(modeOctal || "0", 8);
|
|
1345
1347
|
const sizeOctal = readCStr(header, 124, 12).trim();
|
|
1346
1348
|
const size = parseInt(sizeOctal || "0", 8);
|
|
1347
1349
|
const typeFlag = String.fromCharCode(header[156] || 0);
|
|
@@ -1359,6 +1361,7 @@ function extractTarGz(gz, dest) {
|
|
|
1359
1361
|
else if (typeFlag === "0" || typeFlag === "\0") {
|
|
1360
1362
|
mkdirSync$1(dirname$1(targetAbs), { recursive: true });
|
|
1361
1363
|
writeFileSync$1(targetAbs, tar.subarray(offset + 512, offset + 512 + size));
|
|
1364
|
+
if (mode & 73) chmodSync$1(targetAbs, mode & 511);
|
|
1362
1365
|
}
|
|
1363
1366
|
offset += advance;
|
|
1364
1367
|
}
|