shoplazza-ai-dev-cli 0.1.14 → 0.1.15
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 +176 -18
- package/package.json +3 -2
package/dist/_chunks/test.mjs
CHANGED
|
@@ -285,12 +285,15 @@ function askConfirm(prompt) {
|
|
|
285
285
|
});
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
-
async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
288
|
+
async function syncWithGuard(client, url, payload, json, confirmUnlink, confirm = void 0) {
|
|
289
289
|
try {
|
|
290
290
|
return await client.post(url, payload);
|
|
291
291
|
} catch (err) {
|
|
292
292
|
if (!(err instanceof ApiError) || err.status !== 409 || err.code !== "SYNC_UNLINK_GUARD") throw err;
|
|
293
|
-
const
|
|
293
|
+
const envelope = err.data;
|
|
294
|
+
const detail = envelope?.["error"] && typeof envelope["error"] === "object" ? envelope["error"] : envelope;
|
|
295
|
+
const preview = detail?.["unlink_preview"] ?? [];
|
|
296
|
+
const token = detail?.["unlink_confirm_token"];
|
|
294
297
|
const msg = err.message;
|
|
295
298
|
console.error(`\n⚠ ${msg}`);
|
|
296
299
|
console.error("将被移除的用例:");
|
|
@@ -300,12 +303,12 @@ async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
|
300
303
|
process.exitCode = 1;
|
|
301
304
|
return null;
|
|
302
305
|
}
|
|
303
|
-
if (json || !process.stdin.isTTY) {
|
|
306
|
+
if (!confirm && (json || !process.stdin.isTTY)) {
|
|
304
307
|
console.error("\n非交互模式,不自动重发。请在交互终端使用 --confirm-unlink。");
|
|
305
308
|
process.exitCode = 1;
|
|
306
309
|
return null;
|
|
307
310
|
}
|
|
308
|
-
if (await askConfirm(`确认移除 ${preview.length} 条用例?(y/N) `)
|
|
311
|
+
if (!(confirm ? await confirm() : await askConfirm(`确认移除 ${preview.length} 条用例?(y/N) `) === "y")) {
|
|
309
312
|
console.error("已取消。");
|
|
310
313
|
process.exitCode = 1;
|
|
311
314
|
return null;
|
|
@@ -315,10 +318,12 @@ async function syncWithGuard(client, url, payload, json, confirmUnlink) {
|
|
|
315
318
|
process.exitCode = 1;
|
|
316
319
|
return null;
|
|
317
320
|
}
|
|
321
|
+
if (typeof token !== "string" || !token) throw new ApiError(409, "SYNC_UNLINK_GUARD", "server did not return unlink_confirm_token", err.data);
|
|
318
322
|
const body = {
|
|
319
323
|
...payload,
|
|
320
|
-
|
|
324
|
+
unlink_confirm_token: token
|
|
321
325
|
};
|
|
326
|
+
delete body["force_unlink"];
|
|
322
327
|
return await client.post(url, body);
|
|
323
328
|
}
|
|
324
329
|
}
|
|
@@ -349,7 +354,7 @@ async function create$4(client, args, json) {
|
|
|
349
354
|
if (data["created"]) {
|
|
350
355
|
printSuccess(`Requirement created: ${data["req_id"]}`);
|
|
351
356
|
printKV([["Title", data["title"]], ["Status", data["status"]]]);
|
|
352
|
-
console.log(" (case
|
|
357
|
+
console.log(" (typed case sets are created lazily on first attach or sync)");
|
|
353
358
|
} else console.log(`ℹ Requirement already exists: ${data["req_id"]} (not modified)`);
|
|
354
359
|
}
|
|
355
360
|
async function sync$1(client, args, json) {
|
|
@@ -360,7 +365,18 @@ async function sync$1(client, args, json) {
|
|
|
360
365
|
process.exitCode = 2;
|
|
361
366
|
return;
|
|
362
367
|
}
|
|
363
|
-
const
|
|
368
|
+
const input = readFileInput(requireArg(named, "file", "path"));
|
|
369
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) throw new Error("sync input must be a JSON object");
|
|
370
|
+
const reconcileTypes = asArray(named["reconcile-case-types"]);
|
|
371
|
+
if (reconcileTypes.some((caseType) => !["e2e", "api"].includes(caseType))) {
|
|
372
|
+
printError("--reconcile-case-types must contain only e2e,api");
|
|
373
|
+
process.exitCode = 2;
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const payload = {
|
|
377
|
+
...input,
|
|
378
|
+
...reconcileTypes.length ? { reconcile_case_types: reconcileTypes } : {}
|
|
379
|
+
};
|
|
364
380
|
const confirmUnlink = named["confirm-unlink"] !== void 0;
|
|
365
381
|
const data = await syncWithGuard(client, `/api/test/requirements/${encodeURIComponent(reqId)}/cases:sync`, payload, json, confirmUnlink);
|
|
366
382
|
if (!data) return;
|
|
@@ -379,7 +395,7 @@ async function sync$1(client, args, json) {
|
|
|
379
395
|
["Unlinked", s["unlinked"] ?? 0],
|
|
380
396
|
["Failed", s["failed"] ?? 0]
|
|
381
397
|
]);
|
|
382
|
-
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
398
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${r.error_code ? `[${r.error_code}] ` : ""}${(r.errors ?? []).join(", ")}`);
|
|
383
399
|
}
|
|
384
400
|
async function get$2(client, args, json) {
|
|
385
401
|
const { positional } = parseNamedArgs(args);
|
|
@@ -405,6 +421,31 @@ async function get$2(client, args, json) {
|
|
|
405
421
|
["Created By", detail["created_by_name"] || "—"],
|
|
406
422
|
["Created At", detail["created_at"]]
|
|
407
423
|
]);
|
|
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
|
+
}
|
|
408
449
|
const cases = casesData.items;
|
|
409
450
|
if (cases.length) {
|
|
410
451
|
console.log(`\n Cases (${cases.length}):`);
|
|
@@ -431,7 +472,45 @@ async function get$2(client, args, json) {
|
|
|
431
472
|
]);
|
|
432
473
|
} else console.log("\n No cases linked.");
|
|
433
474
|
}
|
|
434
|
-
async function
|
|
475
|
+
async function attachCases(client, args, json) {
|
|
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) {
|
|
435
514
|
const { named } = parseNamedArgs(args);
|
|
436
515
|
const params = {};
|
|
437
516
|
for (const k of [
|
|
@@ -473,11 +552,12 @@ async function runRequirements(client, args, json) {
|
|
|
473
552
|
case "create": return create$4(client, subArgs, json);
|
|
474
553
|
case "get": return get$2(client, subArgs, json);
|
|
475
554
|
case "sync": return sync$1(client, subArgs, json);
|
|
476
|
-
case "
|
|
555
|
+
case "attach-cases": return attachCases(client, subArgs, json);
|
|
556
|
+
case "list": return list$3(client, subArgs, json);
|
|
477
557
|
case "--help":
|
|
478
558
|
case "-h":
|
|
479
559
|
case void 0:
|
|
480
|
-
console.log(`requirements commands:\n create
|
|
560
|
+
console.log(`requirements commands:\n create Create a requirement (typed sets are lazy)\n get Get requirement detail with typed sets and cases\n attach-cases Add cases; the server routes each case to its typed set\n sync Sync cases to requirement ([--reconcile-case-types] [--confirm-unlink])\n list List requirements`);
|
|
481
561
|
return;
|
|
482
562
|
default:
|
|
483
563
|
printError(`Unknown requirements action: ${action}`);
|
|
@@ -572,7 +652,7 @@ async function create$3(client, args, json) {
|
|
|
572
652
|
["Priority", data["priority"] || "—"]
|
|
573
653
|
]);
|
|
574
654
|
}
|
|
575
|
-
async function list$
|
|
655
|
+
async function list$2(client, args, json) {
|
|
576
656
|
const { named } = parseNamedArgs(args);
|
|
577
657
|
const params = {};
|
|
578
658
|
for (const k of [
|
|
@@ -803,7 +883,7 @@ async function runCases(client, args, json) {
|
|
|
803
883
|
const subArgs = args.slice(1);
|
|
804
884
|
switch (action) {
|
|
805
885
|
case "create": return create$3(client, subArgs, json);
|
|
806
|
-
case "list": return list$
|
|
886
|
+
case "list": return list$2(client, subArgs, json);
|
|
807
887
|
case "batch": return batch$1(client, subArgs, json);
|
|
808
888
|
case "delete": return remove$1(client, subArgs, json);
|
|
809
889
|
case "update": return update(client, subArgs, json);
|
|
@@ -827,9 +907,16 @@ async function create$2(client, args, json) {
|
|
|
827
907
|
return;
|
|
828
908
|
}
|
|
829
909
|
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
|
+
}
|
|
830
916
|
const body = {
|
|
831
917
|
name,
|
|
832
918
|
kind,
|
|
919
|
+
case_type: caseType,
|
|
833
920
|
selection_mode: "manual",
|
|
834
921
|
primary_module_id: parseInt(moduleId, 10)
|
|
835
922
|
};
|
|
@@ -839,7 +926,55 @@ async function create$2(client, args, json) {
|
|
|
839
926
|
return;
|
|
840
927
|
}
|
|
841
928
|
printSuccess(`Case set created: ${data["id"]}`);
|
|
842
|
-
printKV([
|
|
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
|
+
]);
|
|
843
978
|
}
|
|
844
979
|
async function members(client, args, json) {
|
|
845
980
|
const { positional, named } = parseNamedArgs(args);
|
|
@@ -880,6 +1015,7 @@ async function get$1(client, args, json) {
|
|
|
880
1015
|
printKV([
|
|
881
1016
|
["Name", data.name],
|
|
882
1017
|
["Kind", data.kind],
|
|
1018
|
+
["Case Type", data.case_type],
|
|
883
1019
|
["Members", data.members?.length ?? 0]
|
|
884
1020
|
]);
|
|
885
1021
|
if (data.members?.length) printTable(data.members, [
|
|
@@ -916,7 +1052,18 @@ async function sync(client, args, json) {
|
|
|
916
1052
|
process.exitCode = 2;
|
|
917
1053
|
return;
|
|
918
1054
|
}
|
|
919
|
-
const
|
|
1055
|
+
const input = readFileInput(requireArg(named, "file", "path"));
|
|
1056
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) throw new Error("sync input must be a JSON object");
|
|
1057
|
+
const reconcileTypes = asArray(named["reconcile-case-types"]);
|
|
1058
|
+
if (reconcileTypes.some((caseType) => !["e2e", "api"].includes(caseType))) {
|
|
1059
|
+
printError("--reconcile-case-types must contain only e2e,api");
|
|
1060
|
+
process.exitCode = 2;
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const payload = {
|
|
1064
|
+
...input,
|
|
1065
|
+
...reconcileTypes.length ? { reconcile_case_types: reconcileTypes } : {}
|
|
1066
|
+
};
|
|
920
1067
|
const confirmUnlink = named["confirm-unlink"] !== void 0;
|
|
921
1068
|
const data = await syncWithGuard(client, `/api/test/case-sets/${setId}/cases:sync`, payload, json, confirmUnlink);
|
|
922
1069
|
if (!data) return;
|
|
@@ -935,20 +1082,21 @@ async function sync(client, args, json) {
|
|
|
935
1082
|
["Unlinked", s["unlinked"] ?? 0],
|
|
936
1083
|
["Failed", s["failed"] ?? 0]
|
|
937
1084
|
]);
|
|
938
|
-
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
1085
|
+
for (const r of results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${r.error_code ? `[${r.error_code}] ` : ""}${(r.errors ?? []).join(", ")}`);
|
|
939
1086
|
}
|
|
940
1087
|
async function runCaseSets(client, args, json) {
|
|
941
1088
|
const action = args[0];
|
|
942
1089
|
const subArgs = args.slice(1);
|
|
943
1090
|
switch (action) {
|
|
944
1091
|
case "create": return create$2(client, subArgs, json);
|
|
1092
|
+
case "list": return list$1(client, subArgs, json);
|
|
945
1093
|
case "get": return get$1(client, subArgs, json);
|
|
946
1094
|
case "members": return members(client, subArgs, json);
|
|
947
1095
|
case "sync": return sync(client, subArgs, json);
|
|
948
1096
|
case "--help":
|
|
949
1097
|
case "-h":
|
|
950
1098
|
case void 0:
|
|
951
|
-
console.log(`case-sets commands:\n create Create a case set (--name, --kind
|
|
1099
|
+
console.log(`case-sets commands:\n create Create a typed case set (--name, --kind, --module, --type e2e|api)\n list List case sets ([--type e2e|api])\n get Get case set detail with members\n members Batch add members (--add)\n sync Sync cases to a set (--file <path> [--reconcile-case-types] [--confirm-unlink])`);
|
|
952
1100
|
return;
|
|
953
1101
|
default:
|
|
954
1102
|
printError(`Unknown case-sets action: ${action}`);
|
|
@@ -966,6 +1114,15 @@ async function create$1(client, args, json) {
|
|
|
966
1114
|
const body = { type: planType };
|
|
967
1115
|
if (typeof named["title"] === "string") body["title"] = named["title"];
|
|
968
1116
|
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
|
+
}
|
|
969
1126
|
if (typeof named["case-ids"] === "string") body["case_ids"] = named["case-ids"].split(",").map((s) => s.trim());
|
|
970
1127
|
if (typeof named["req-id"] === "string") body["req_id"] = named["req-id"];
|
|
971
1128
|
if (typeof named["env"] === "string") {
|
|
@@ -981,10 +1138,11 @@ async function create$1(client, args, json) {
|
|
|
981
1138
|
const sources = [
|
|
982
1139
|
body["case_ids"] ? "case-ids" : null,
|
|
983
1140
|
body["from_case_set"] !== void 0 ? "from-set" : null,
|
|
1141
|
+
body["from_case_sets"] !== void 0 ? "from-sets" : null,
|
|
984
1142
|
body["req_id"] ? "req-id" : null
|
|
985
1143
|
].filter(Boolean);
|
|
986
1144
|
if (sources.length === 0) {
|
|
987
|
-
printError("Must specify one of --case-ids, --from-set, or --req-id");
|
|
1145
|
+
printError("Must specify one of --case-ids, --from-set, --from-sets, or --req-id");
|
|
988
1146
|
process.exitCode = 2;
|
|
989
1147
|
return;
|
|
990
1148
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shoplazza-ai-dev-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "Shoplazza AI Dev CLI: install, publish and manage AI agent skills/rules",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"format:check": "prettier --check \"src/**/*.ts\" \"scripts/**/*.ts\"",
|
|
23
23
|
"test": "vitest",
|
|
24
24
|
"type-check": "tsc --noEmit",
|
|
25
|
-
"publish:snapshot": "npm version prerelease --preid=snapshot --no-git-tag-version && npm publish --tag snapshot"
|
|
25
|
+
"publish:snapshot": "npm version prerelease --preid=snapshot --no-git-tag-version && npm publish --tag snapshot",
|
|
26
|
+
"publish:latest": "npm ci && npm version patch --no-git-tag-version && npm publish --tag latest"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
28
29
|
"cli",
|