shoplazza-ai-dev-cli 0.1.6 → 0.1.7-snapshot.0
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 +831 -0
- package/dist/cli.mjs +11 -1
- package/package.json +1 -1
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
import { loadConfig, runLogin } from "../cli.mjs";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
function parseGlobalFlags(args) {
|
|
4
|
+
const flags = { json: false };
|
|
5
|
+
const rest = [];
|
|
6
|
+
for (let i = 0; i < args.length; i++) {
|
|
7
|
+
const a = args[i];
|
|
8
|
+
if (a === "--json") {
|
|
9
|
+
flags.json = true;
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (a === "--portal" && args[i + 1]) {
|
|
13
|
+
flags.portal = args[++i];
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (a === "--file" && args[i + 1]) {
|
|
17
|
+
flags.file = args[++i];
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (a === "--page" && args[i + 1]) {
|
|
21
|
+
flags.page = Number(args[++i]);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (a === "--size" && args[i + 1]) {
|
|
25
|
+
flags.size = Number(args[++i]);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
rest.push(a);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
flags,
|
|
32
|
+
rest
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function parseNamedArgs(args) {
|
|
36
|
+
const positional = [];
|
|
37
|
+
const named = {};
|
|
38
|
+
for (let i = 0; i < args.length; i++) {
|
|
39
|
+
const a = args[i];
|
|
40
|
+
if (a.startsWith("--") && a.includes("=")) {
|
|
41
|
+
const eqIdx = a.indexOf("=");
|
|
42
|
+
const key = a.slice(2, eqIdx);
|
|
43
|
+
const val = a.slice(eqIdx + 1);
|
|
44
|
+
const existing = named[key];
|
|
45
|
+
if (existing !== void 0) named[key] = Array.isArray(existing) ? [...existing, val] : [existing, val];
|
|
46
|
+
else named[key] = val;
|
|
47
|
+
} else if (a.startsWith("--") && args[i + 1] && !args[i + 1].startsWith("--")) {
|
|
48
|
+
const key = a.slice(2);
|
|
49
|
+
const val = args[++i];
|
|
50
|
+
const existing = named[key];
|
|
51
|
+
if (existing !== void 0) named[key] = Array.isArray(existing) ? [...existing, val] : [existing, val];
|
|
52
|
+
else named[key] = val;
|
|
53
|
+
} else if (a.startsWith("--")) named[a.slice(2)] = "true";
|
|
54
|
+
else positional.push(a);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
positional,
|
|
58
|
+
named
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function readFileInput(filePath) {
|
|
62
|
+
if (filePath === "-") {
|
|
63
|
+
if (process.stdin.isTTY) {
|
|
64
|
+
console.error("✗ --file - requires piped input (e.g., echo '...' | cli test ...)");
|
|
65
|
+
process.exitCode = 2;
|
|
66
|
+
throw new Error("missing --file");
|
|
67
|
+
}
|
|
68
|
+
const raw = readFileSync(0, "utf-8");
|
|
69
|
+
return JSON.parse(raw);
|
|
70
|
+
}
|
|
71
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
72
|
+
return JSON.parse(raw);
|
|
73
|
+
}
|
|
74
|
+
function requireArg(named, key, label) {
|
|
75
|
+
const v = named[key];
|
|
76
|
+
if (!v || Array.isArray(v)) {
|
|
77
|
+
console.error(`✗ Missing required flag: --${key} <${label}>`);
|
|
78
|
+
process.exitCode = 2;
|
|
79
|
+
throw new Error(`missing --${key}`);
|
|
80
|
+
}
|
|
81
|
+
return v;
|
|
82
|
+
}
|
|
83
|
+
function asArray(v) {
|
|
84
|
+
if (!v) return [];
|
|
85
|
+
return Array.isArray(v) ? v : v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
const RESET = "\x1B[0m";
|
|
88
|
+
const GREEN = "\x1B[32m";
|
|
89
|
+
const RED = "\x1B[31m";
|
|
90
|
+
const DIM = "\x1B[38;5;102m";
|
|
91
|
+
function printJson(data) {
|
|
92
|
+
console.log(JSON.stringify(data, null, 2));
|
|
93
|
+
}
|
|
94
|
+
function printSuccess(msg) {
|
|
95
|
+
console.log(`${GREEN}✓${RESET} ${msg}`);
|
|
96
|
+
}
|
|
97
|
+
function printError(msg) {
|
|
98
|
+
console.error(`${RED}✗${RESET} ${msg}`);
|
|
99
|
+
}
|
|
100
|
+
function printKV(pairs) {
|
|
101
|
+
for (const [k, v] of pairs) console.log(` ${DIM}${k}:${RESET} ${v}`);
|
|
102
|
+
}
|
|
103
|
+
function printTable(rows, cols) {
|
|
104
|
+
if (rows.length === 0) {
|
|
105
|
+
console.log(" (no items)");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const widths = cols.map((c) => Math.max(c.label.length, ...rows.map((r) => String(r[c.key] ?? "").length), c.width ?? 0));
|
|
109
|
+
console.log(cols.map((c, i) => c.label.padEnd(widths[i])).join(" "));
|
|
110
|
+
console.log(cols.map((_, i) => "─".repeat(widths[i])).join(" "));
|
|
111
|
+
for (const r of rows) console.log(cols.map((c, i) => String(r[c.key] ?? "").padEnd(widths[i])).join(" "));
|
|
112
|
+
}
|
|
113
|
+
function printPagination(total) {
|
|
114
|
+
console.log(`${DIM}(${total} items)${RESET}`);
|
|
115
|
+
}
|
|
116
|
+
var ApiError = class extends Error {
|
|
117
|
+
status;
|
|
118
|
+
code;
|
|
119
|
+
data;
|
|
120
|
+
constructor(status, code, message, data) {
|
|
121
|
+
super(message);
|
|
122
|
+
this.status = status;
|
|
123
|
+
this.code = code;
|
|
124
|
+
this.data = data;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var TestPlatformClient = class TestPlatformClient {
|
|
128
|
+
baseUrl;
|
|
129
|
+
token;
|
|
130
|
+
interactive;
|
|
131
|
+
constructor(baseUrl, token, interactive) {
|
|
132
|
+
this.baseUrl = baseUrl;
|
|
133
|
+
this.token = token;
|
|
134
|
+
this.interactive = interactive;
|
|
135
|
+
}
|
|
136
|
+
static fromConfig(portalOverride, jsonMode = false) {
|
|
137
|
+
const cfg = loadConfig();
|
|
138
|
+
return new TestPlatformClient((portalOverride ?? cfg.portal).replace(/\/$/, ""), cfg.token ?? "", !jsonMode && (process.stdout.isTTY ?? false));
|
|
139
|
+
}
|
|
140
|
+
async get(path, params) {
|
|
141
|
+
let url = `${this.baseUrl}${path}`;
|
|
142
|
+
if (params) {
|
|
143
|
+
const qs = Object.entries(params).filter(([, v]) => v).map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
|
|
144
|
+
if (qs) url += `?${qs}`;
|
|
145
|
+
}
|
|
146
|
+
return this.request("GET", url);
|
|
147
|
+
}
|
|
148
|
+
async post(path, body) {
|
|
149
|
+
return this.request("POST", `${this.baseUrl}${path}`, body);
|
|
150
|
+
}
|
|
151
|
+
async patch(path, body) {
|
|
152
|
+
return this.request("PATCH", `${this.baseUrl}${path}`, body);
|
|
153
|
+
}
|
|
154
|
+
async delete(path) {
|
|
155
|
+
return this.request("DELETE", `${this.baseUrl}${path}`);
|
|
156
|
+
}
|
|
157
|
+
async request(method, url, body) {
|
|
158
|
+
const headers = {
|
|
159
|
+
"Authorization": `Bearer ${this.token}`,
|
|
160
|
+
"Accept": "application/json"
|
|
161
|
+
};
|
|
162
|
+
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
163
|
+
let resp = await fetch(url, {
|
|
164
|
+
method,
|
|
165
|
+
headers,
|
|
166
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
167
|
+
});
|
|
168
|
+
if (resp.status === 401 && this.interactive) {
|
|
169
|
+
await resp.arrayBuffer().catch(() => void 0);
|
|
170
|
+
await runLogin({ force: true });
|
|
171
|
+
const refreshed = loadConfig().token;
|
|
172
|
+
if (refreshed) {
|
|
173
|
+
this.token = refreshed;
|
|
174
|
+
headers["Authorization"] = `Bearer ${refreshed}`;
|
|
175
|
+
resp = await fetch(url, {
|
|
176
|
+
method,
|
|
177
|
+
headers,
|
|
178
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (resp.status === 204) return void 0;
|
|
183
|
+
const contentType = resp.headers.get("Content-Type") ?? "";
|
|
184
|
+
let payload = null;
|
|
185
|
+
if (contentType.includes("application/json")) try {
|
|
186
|
+
payload = await resp.json();
|
|
187
|
+
} catch {
|
|
188
|
+
payload = null;
|
|
189
|
+
}
|
|
190
|
+
if (!resp.ok) {
|
|
191
|
+
if (payload === null) {
|
|
192
|
+
const preview = (await resp.text().catch(() => "")).slice(0, 200);
|
|
193
|
+
throw new ApiError(resp.status, `HTTP_${resp.status}`, preview || `HTTP ${resp.status}`);
|
|
194
|
+
}
|
|
195
|
+
const errObj = payload && typeof payload === "object" && payload !== null && "error" in payload ? payload.error : null;
|
|
196
|
+
const code = errObj && typeof errObj === "object" && errObj !== null && "code" in errObj ? String(errObj.code) : `HTTP_${resp.status}`;
|
|
197
|
+
const message = errObj && typeof errObj === "object" && errObj !== null && "message" in errObj ? String(errObj.message) : typeof errObj === "string" ? errObj : `HTTP ${resp.status}`;
|
|
198
|
+
throw new ApiError(resp.status, code, message, payload);
|
|
199
|
+
}
|
|
200
|
+
return payload;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
function ensureLoggedIn() {
|
|
204
|
+
if (!loadConfig().token) {
|
|
205
|
+
printError("Not logged in. Run `shoplazza-ai-dev-cli login` first.");
|
|
206
|
+
process.exitCode = 1;
|
|
207
|
+
throw new Error("not logged in");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function listBL(client, json) {
|
|
211
|
+
const data = await client.get("/org/business-lines");
|
|
212
|
+
if (json) {
|
|
213
|
+
printJson(data);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
printTable(data.items, [{
|
|
217
|
+
key: "id",
|
|
218
|
+
label: "ID",
|
|
219
|
+
width: 4
|
|
220
|
+
}, {
|
|
221
|
+
key: "name",
|
|
222
|
+
label: "Name"
|
|
223
|
+
}]);
|
|
224
|
+
printPagination(data.total);
|
|
225
|
+
}
|
|
226
|
+
async function listModules(client, args, json) {
|
|
227
|
+
const { named } = parseNamedArgs(args);
|
|
228
|
+
const blId = requireArg(named, "bl", "business_line_id");
|
|
229
|
+
const q = typeof named["q"] === "string" ? named["q"] : void 0;
|
|
230
|
+
const params = {};
|
|
231
|
+
if (q) params["q"] = q;
|
|
232
|
+
const data = await client.get(`/org/business-lines/${blId}/modules`, params);
|
|
233
|
+
if (json) {
|
|
234
|
+
printJson(data);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
printTable(data.items, [
|
|
238
|
+
{
|
|
239
|
+
key: "id",
|
|
240
|
+
label: "ID",
|
|
241
|
+
width: 4
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
key: "name",
|
|
245
|
+
label: "Name"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: "full_path",
|
|
249
|
+
label: "Full Path"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
key: "depth",
|
|
253
|
+
label: "Depth",
|
|
254
|
+
width: 5
|
|
255
|
+
}
|
|
256
|
+
]);
|
|
257
|
+
printPagination(data.total);
|
|
258
|
+
}
|
|
259
|
+
async function runTaxonomy(client, args, json) {
|
|
260
|
+
const action = args[0];
|
|
261
|
+
const subArgs = args.slice(1);
|
|
262
|
+
switch (action) {
|
|
263
|
+
case "list-bl": return listBL(client, json);
|
|
264
|
+
case "list-modules": return listModules(client, subArgs, json);
|
|
265
|
+
case "--help":
|
|
266
|
+
case "-h":
|
|
267
|
+
case void 0:
|
|
268
|
+
console.log(`taxonomy commands:\n list-bl List product lines\n list-modules List modules (--bl <id> [--q <keyword>])`);
|
|
269
|
+
return;
|
|
270
|
+
default:
|
|
271
|
+
printError(`Unknown taxonomy action: ${action}`);
|
|
272
|
+
process.exitCode = 2;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function create$4(client, args, json) {
|
|
276
|
+
const { named } = parseNamedArgs(args);
|
|
277
|
+
const reqId = requireArg(named, "req-id", "req_id");
|
|
278
|
+
const title = requireArg(named, "title", "title");
|
|
279
|
+
const bl = typeof named["bl"] === "string" ? named["bl"] : void 0;
|
|
280
|
+
const modulePaths = asArray(named["module-paths"]);
|
|
281
|
+
const feishuUrl = typeof named["feishu-url"] === "string" ? named["feishu-url"] : void 0;
|
|
282
|
+
const body = {
|
|
283
|
+
req_id: reqId,
|
|
284
|
+
title
|
|
285
|
+
};
|
|
286
|
+
if (bl) body["business_line"] = bl;
|
|
287
|
+
if (modulePaths.length) body["module_paths"] = modulePaths;
|
|
288
|
+
if (feishuUrl) body["feishu_ticket_url"] = feishuUrl;
|
|
289
|
+
const data = await client.post("/api/test/requirements", body);
|
|
290
|
+
if (json) {
|
|
291
|
+
printJson(data);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
if (data["created"]) {
|
|
295
|
+
printSuccess(`Requirement created: ${data["req_id"]}`);
|
|
296
|
+
printKV([["Title", data["title"]], ["Status", data["status"]]]);
|
|
297
|
+
console.log(" (case set auto-created)");
|
|
298
|
+
} else console.log(`ℹ Requirement already exists: ${data["req_id"]} (not modified)`);
|
|
299
|
+
}
|
|
300
|
+
async function sync(client, args, json) {
|
|
301
|
+
const { positional, named } = parseNamedArgs(args);
|
|
302
|
+
const reqId = positional[0];
|
|
303
|
+
if (!reqId) {
|
|
304
|
+
printError("Usage: test requirements sync <req_id> --file <path>");
|
|
305
|
+
process.exitCode = 2;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
309
|
+
const data = await client.post(`/api/test/requirements/${encodeURIComponent(reqId)}/cases:sync`, payload);
|
|
310
|
+
if (json) {
|
|
311
|
+
printJson(data);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const s = data.summary;
|
|
315
|
+
printSuccess(`Synced ${(s["created"] ?? 0) + (s["referenced"] ?? 0) + (s["updated"] ?? 0)} cases to ${reqId}`);
|
|
316
|
+
printKV([
|
|
317
|
+
["Created", `${s["created"] ?? 0}${data.results.filter((r) => r.action === "created").map((r) => ` (${r.case_id})`).join("")}`],
|
|
318
|
+
["Referenced", s["referenced"] ?? 0],
|
|
319
|
+
["Updated", s["updated"] ?? 0],
|
|
320
|
+
["Unlinked", s["unlinked"] ?? 0],
|
|
321
|
+
["Failed", s["failed"] ?? 0]
|
|
322
|
+
]);
|
|
323
|
+
for (const r of data.results.filter((r) => r.action === "failed")) printError(` ${r.client_ref}: ${(r.errors ?? []).join(", ")}`);
|
|
324
|
+
}
|
|
325
|
+
async function list$2(client, args, json) {
|
|
326
|
+
const { named } = parseNamedArgs(args);
|
|
327
|
+
const params = {};
|
|
328
|
+
for (const k of [
|
|
329
|
+
"q",
|
|
330
|
+
"status",
|
|
331
|
+
"page",
|
|
332
|
+
"size"
|
|
333
|
+
]) {
|
|
334
|
+
const v = named[k];
|
|
335
|
+
const val = Array.isArray(v) ? v[v.length - 1] : v;
|
|
336
|
+
if (typeof val === "string") params[k] = val;
|
|
337
|
+
}
|
|
338
|
+
const data = await client.get("/api/test/requirements", params);
|
|
339
|
+
if (json) {
|
|
340
|
+
printJson(data);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
printTable(data.items, [
|
|
344
|
+
{
|
|
345
|
+
key: "req_id",
|
|
346
|
+
label: "Req ID"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
key: "title",
|
|
350
|
+
label: "Title"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
key: "status",
|
|
354
|
+
label: "Status",
|
|
355
|
+
width: 8
|
|
356
|
+
}
|
|
357
|
+
]);
|
|
358
|
+
printPagination(data.total);
|
|
359
|
+
}
|
|
360
|
+
async function runRequirements(client, args, json) {
|
|
361
|
+
const action = args[0];
|
|
362
|
+
const subArgs = args.slice(1);
|
|
363
|
+
switch (action) {
|
|
364
|
+
case "create": return create$4(client, subArgs, json);
|
|
365
|
+
case "sync": return sync(client, subArgs, json);
|
|
366
|
+
case "list": return list$2(client, subArgs, json);
|
|
367
|
+
case "--help":
|
|
368
|
+
case "-h":
|
|
369
|
+
case void 0:
|
|
370
|
+
console.log(`requirements commands:\n create Create a requirement\n sync Sync cases to requirement (channel 1)\n list List requirements`);
|
|
371
|
+
return;
|
|
372
|
+
default:
|
|
373
|
+
printError(`Unknown requirements action: ${action}`);
|
|
374
|
+
process.exitCode = 2;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function create$3(client, args, json) {
|
|
378
|
+
const { named } = parseNamedArgs(args);
|
|
379
|
+
const body = {
|
|
380
|
+
title: requireArg(named, "title", "title"),
|
|
381
|
+
business_line: requireArg(named, "bl", "business_line"),
|
|
382
|
+
module_path: requireArg(named, "module-path", "module_path"),
|
|
383
|
+
case_type: requireArg(named, "type", "case_type"),
|
|
384
|
+
expected: requireArg(named, "expected", "expected"),
|
|
385
|
+
steps: Array.isArray(named["steps"]) ? named["steps"] : named["steps"] ? [named["steps"]] : []
|
|
386
|
+
};
|
|
387
|
+
if (typeof named["priority"] === "string") body["priority"] = named["priority"];
|
|
388
|
+
if (typeof named["precondition"] === "string") body["precondition"] = named["precondition"];
|
|
389
|
+
if (typeof named["source"] === "string") body["source"] = named["source"];
|
|
390
|
+
const tags = asArray(named["tags"]);
|
|
391
|
+
if (tags.length) body["tags"] = tags;
|
|
392
|
+
if (!body["steps"] || body["steps"].length === 0) {
|
|
393
|
+
printError("At least one --steps required");
|
|
394
|
+
process.exitCode = 2;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const data = await client.post("/api/test/cases", body);
|
|
398
|
+
if (json) {
|
|
399
|
+
printJson(data);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
printSuccess(`Case created: ${data["case_id"]}`);
|
|
403
|
+
printKV([
|
|
404
|
+
["Title", data["title"]],
|
|
405
|
+
["Module", `${data["module_path"] ?? `id=${data["module_id"]}`}`],
|
|
406
|
+
["Type", data["case_type"]],
|
|
407
|
+
["Priority", data["priority"] || "—"]
|
|
408
|
+
]);
|
|
409
|
+
}
|
|
410
|
+
async function list$1(client, args, json) {
|
|
411
|
+
const { named } = parseNamedArgs(args);
|
|
412
|
+
const params = {};
|
|
413
|
+
for (const k of [
|
|
414
|
+
"q",
|
|
415
|
+
"module-id",
|
|
416
|
+
"type",
|
|
417
|
+
"priority",
|
|
418
|
+
"page",
|
|
419
|
+
"size"
|
|
420
|
+
]) {
|
|
421
|
+
const apiKey = k === "module-id" ? "module_id" : k === "type" ? "case_type" : k;
|
|
422
|
+
const v = named[k];
|
|
423
|
+
const val = Array.isArray(v) ? v[v.length - 1] : v;
|
|
424
|
+
if (typeof val === "string") params[apiKey] = val;
|
|
425
|
+
}
|
|
426
|
+
const data = await client.get("/api/test/cases", params);
|
|
427
|
+
if (json) {
|
|
428
|
+
printJson(data);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
printTable(data.items, [
|
|
432
|
+
{
|
|
433
|
+
key: "case_id",
|
|
434
|
+
label: "Case ID"
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
key: "title",
|
|
438
|
+
label: "Title"
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
key: "case_type",
|
|
442
|
+
label: "Type",
|
|
443
|
+
width: 5
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
key: "priority",
|
|
447
|
+
label: "Pri",
|
|
448
|
+
width: 4
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
key: "automation_status",
|
|
452
|
+
label: "Auto",
|
|
453
|
+
width: 10
|
|
454
|
+
}
|
|
455
|
+
]);
|
|
456
|
+
printPagination(data.total);
|
|
457
|
+
}
|
|
458
|
+
async function runCases(client, args, json) {
|
|
459
|
+
const action = args[0];
|
|
460
|
+
const subArgs = args.slice(1);
|
|
461
|
+
switch (action) {
|
|
462
|
+
case "create": return create$3(client, subArgs, json);
|
|
463
|
+
case "list": return list$1(client, subArgs, json);
|
|
464
|
+
case "--help":
|
|
465
|
+
case "-h":
|
|
466
|
+
case void 0:
|
|
467
|
+
console.log(`cases commands:\n create Create a standalone case\n list List cases with filters`);
|
|
468
|
+
return;
|
|
469
|
+
default:
|
|
470
|
+
printError(`Unknown cases action: ${action}`);
|
|
471
|
+
process.exitCode = 2;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
async function create$2(client, args, json) {
|
|
475
|
+
const { named } = parseNamedArgs(args);
|
|
476
|
+
const body = {
|
|
477
|
+
name: requireArg(named, "name", "name"),
|
|
478
|
+
kind: requireArg(named, "kind", "regression|smoke|flow|baseline|custom|curated"),
|
|
479
|
+
selection_mode: "manual"
|
|
480
|
+
};
|
|
481
|
+
const data = await client.post("/api/test/case-sets", body);
|
|
482
|
+
if (json) {
|
|
483
|
+
printJson(data);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
printSuccess(`Case set created: ${data["id"]}`);
|
|
487
|
+
printKV([["Name", data["name"]], ["Kind", data["kind"]]]);
|
|
488
|
+
}
|
|
489
|
+
async function members(client, args, json) {
|
|
490
|
+
const { positional, named } = parseNamedArgs(args);
|
|
491
|
+
const setId = positional[0];
|
|
492
|
+
if (!setId) {
|
|
493
|
+
printError("Usage: test case-sets members <set_id> [--add ...] [--remove ...]");
|
|
494
|
+
process.exitCode = 2;
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const add = asArray(named["add"]);
|
|
498
|
+
const remove = asArray(named["remove"]);
|
|
499
|
+
if (!add.length && !remove.length) {
|
|
500
|
+
printError("Provide --add or --remove");
|
|
501
|
+
process.exitCode = 2;
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const body = {};
|
|
505
|
+
if (add.length) body["add"] = add;
|
|
506
|
+
if (remove.length) body["remove"] = remove;
|
|
507
|
+
const data = await client.post(`/api/test/case-sets/${setId}/members:batch`, body);
|
|
508
|
+
if (json) {
|
|
509
|
+
printJson(data);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
printSuccess(`Added ${data.added}, removed ${data.removed}, invalid: ${(data.invalid ?? []).length}`);
|
|
513
|
+
}
|
|
514
|
+
async function runCaseSets(client, args, json) {
|
|
515
|
+
const action = args[0];
|
|
516
|
+
const subArgs = args.slice(1);
|
|
517
|
+
switch (action) {
|
|
518
|
+
case "create": return create$2(client, subArgs, json);
|
|
519
|
+
case "members": return members(client, subArgs, json);
|
|
520
|
+
case "--help":
|
|
521
|
+
case "-h":
|
|
522
|
+
case void 0:
|
|
523
|
+
console.log(`case-sets commands:\n create Create a case set (--name, --kind)\n members Batch add/remove members (--add/--remove)`);
|
|
524
|
+
return;
|
|
525
|
+
default:
|
|
526
|
+
printError(`Unknown case-sets action: ${action}`);
|
|
527
|
+
process.exitCode = 2;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async function create$1(client, args, json) {
|
|
531
|
+
const { named } = parseNamedArgs(args);
|
|
532
|
+
const body = { type: requireArg(named, "type", "requirement|regression|smoke") };
|
|
533
|
+
if (typeof named["title"] === "string") body["title"] = named["title"];
|
|
534
|
+
if (typeof named["from-set"] === "string") body["from_case_set"] = Number(named["from-set"]);
|
|
535
|
+
if (typeof named["case-ids"] === "string") body["case_ids"] = named["case-ids"].split(",").map((s) => s.trim());
|
|
536
|
+
if (typeof named["req-id"] === "string") body["req_id"] = named["req-id"];
|
|
537
|
+
if (typeof named["env"] === "string") body["env"] = named["env"];
|
|
538
|
+
const tags = asArray(named["tags"]);
|
|
539
|
+
if (tags.length) body["tags"] = tags;
|
|
540
|
+
if (body["from_case_set"] !== void 0 && body["case_ids"]) {
|
|
541
|
+
printError("--from-set and --case-ids are mutually exclusive");
|
|
542
|
+
process.exitCode = 2;
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const data = await client.post("/api/test/test-plans", body);
|
|
546
|
+
if (json) {
|
|
547
|
+
printJson(data);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
printSuccess(`Plan created: ${data["plan_id"]}`);
|
|
551
|
+
printKV([
|
|
552
|
+
["Title", data["title"]],
|
|
553
|
+
["Type", data["type"]],
|
|
554
|
+
["Env", data["env"]],
|
|
555
|
+
["Cases", data["case_count"]],
|
|
556
|
+
["Status", data["status"]]
|
|
557
|
+
]);
|
|
558
|
+
}
|
|
559
|
+
async function get(client, args, json) {
|
|
560
|
+
const { positional } = parseNamedArgs(args);
|
|
561
|
+
const planId = positional[0];
|
|
562
|
+
if (!planId) {
|
|
563
|
+
printError("Usage: test plans get <plan_id>");
|
|
564
|
+
process.exitCode = 2;
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const data = await client.get(`/api/test/test-plans/${encodeURIComponent(planId)}`);
|
|
568
|
+
if (json) {
|
|
569
|
+
printJson(data);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
printKV([
|
|
573
|
+
["Plan ID", data["plan_id"]],
|
|
574
|
+
["Title", data["title"]],
|
|
575
|
+
["Type", data["type"]],
|
|
576
|
+
["Env", data["env"]],
|
|
577
|
+
["Status", data["status"]]
|
|
578
|
+
]);
|
|
579
|
+
const progress = data["progress"];
|
|
580
|
+
if (progress) console.log(` Progress: ${progress["passed"]}p / ${progress["failed"]}f / ${progress["pending"]} pending (total ${progress["total"]})`);
|
|
581
|
+
const cases = data["cases"];
|
|
582
|
+
if (cases && cases.length) {
|
|
583
|
+
console.log(`\n Cases (${cases.length}):`);
|
|
584
|
+
for (const c of cases) console.log(` [${c["case_id"]}] ${c["title"]} (${c["priority"] || "—"})`);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
async function list(client, args, json) {
|
|
588
|
+
const { named } = parseNamedArgs(args);
|
|
589
|
+
const params = {};
|
|
590
|
+
for (const k of [
|
|
591
|
+
"q",
|
|
592
|
+
"type",
|
|
593
|
+
"status",
|
|
594
|
+
"env",
|
|
595
|
+
"req-id",
|
|
596
|
+
"page",
|
|
597
|
+
"size"
|
|
598
|
+
]) {
|
|
599
|
+
const apiKey = k === "req-id" ? "req_id" : k;
|
|
600
|
+
const v = named[k];
|
|
601
|
+
const val = Array.isArray(v) ? v[v.length - 1] : v;
|
|
602
|
+
if (typeof val === "string") params[apiKey] = val;
|
|
603
|
+
}
|
|
604
|
+
const data = await client.get("/api/test/test-plans", params);
|
|
605
|
+
if (json) {
|
|
606
|
+
printJson(data);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
printTable(data.items, [
|
|
610
|
+
{
|
|
611
|
+
key: "plan_id",
|
|
612
|
+
label: "Plan ID"
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
key: "title",
|
|
616
|
+
label: "Title"
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
key: "type",
|
|
620
|
+
label: "Type",
|
|
621
|
+
width: 12
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
key: "status",
|
|
625
|
+
label: "Status",
|
|
626
|
+
width: 6
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
key: "case_count",
|
|
630
|
+
label: "Cases",
|
|
631
|
+
width: 5
|
|
632
|
+
}
|
|
633
|
+
]);
|
|
634
|
+
printPagination(data.total);
|
|
635
|
+
}
|
|
636
|
+
async function runPlans(client, args, json) {
|
|
637
|
+
const action = args[0];
|
|
638
|
+
const subArgs = args.slice(1);
|
|
639
|
+
switch (action) {
|
|
640
|
+
case "create": return create$1(client, subArgs, json);
|
|
641
|
+
case "get": return get(client, subArgs, json);
|
|
642
|
+
case "list": return list(client, subArgs, json);
|
|
643
|
+
case "--help":
|
|
644
|
+
case "-h":
|
|
645
|
+
case void 0:
|
|
646
|
+
console.log(`plans commands:\n create Create a test plan\n get Get plan detail (--json for full case content)\n list List plans`);
|
|
647
|
+
return;
|
|
648
|
+
default:
|
|
649
|
+
printError(`Unknown plans action: ${action}`);
|
|
650
|
+
process.exitCode = 2;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
async function mark(client, args, json) {
|
|
654
|
+
const { positional, named } = parseNamedArgs(args);
|
|
655
|
+
const planId = positional[0];
|
|
656
|
+
const caseId = positional[1];
|
|
657
|
+
if (!planId || !caseId) {
|
|
658
|
+
printError("Usage: test results mark <plan_id> <case_id> --status <status>");
|
|
659
|
+
process.exitCode = 2;
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const body = {
|
|
663
|
+
plan_id: planId,
|
|
664
|
+
case_id: caseId,
|
|
665
|
+
status: requireArg(named, "status", "passed|failed|skipped|blocked")
|
|
666
|
+
};
|
|
667
|
+
if (typeof named["remark"] === "string") body["remark"] = named["remark"];
|
|
668
|
+
if (typeof named["evidence-url"] === "string") body["evidence_url"] = named["evidence-url"];
|
|
669
|
+
if (typeof named["duration-ms"] === "string") {
|
|
670
|
+
const n = Number(named["duration-ms"]);
|
|
671
|
+
if (Number.isNaN(n)) {
|
|
672
|
+
printError("--duration-ms must be a number");
|
|
673
|
+
process.exitCode = 2;
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
body["duration_ms"] = n;
|
|
677
|
+
}
|
|
678
|
+
if (typeof named["executor"] === "string") body["executor"] = named["executor"];
|
|
679
|
+
const data = await client.post("/api/test/case-results", body);
|
|
680
|
+
if (json) {
|
|
681
|
+
printJson(data);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
printSuccess(`Marked ${caseId} as ${body["status"]} in ${planId}`);
|
|
685
|
+
const p = data["progress"];
|
|
686
|
+
if (p) console.log(` Progress: ${p["passed"]}/${p["total"]} passed, ${p["failed"]} failed, ${p["pending"]} pending`);
|
|
687
|
+
console.log(` Plan status: ${data["plan_status"]}`);
|
|
688
|
+
}
|
|
689
|
+
async function batch(client, args, json) {
|
|
690
|
+
const { positional, named } = parseNamedArgs(args);
|
|
691
|
+
const planId = positional[0];
|
|
692
|
+
if (!planId) {
|
|
693
|
+
printError("Usage: test results batch <plan_id> --file <path>");
|
|
694
|
+
process.exitCode = 2;
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
const payload = readFileInput(requireArg(named, "file", "path"));
|
|
698
|
+
payload["plan_id"] = planId;
|
|
699
|
+
if (typeof named["executor"] === "string") payload["executor"] = named["executor"];
|
|
700
|
+
const data = await client.post("/api/test/case-results:batch", payload);
|
|
701
|
+
if (json) {
|
|
702
|
+
printJson(data);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const invalid = data["invalid"];
|
|
706
|
+
printSuccess(`Batch submitted: ${data["marked"]} marked, ${(invalid ?? []).length} invalid`);
|
|
707
|
+
console.log(` Plan status: ${data["plan_status"]}`);
|
|
708
|
+
const p = data["progress"];
|
|
709
|
+
if (p) console.log(` Progress: ${p["passed"]} passed, ${p["failed"]} failed, ${p["pending"]} pending`);
|
|
710
|
+
}
|
|
711
|
+
async function runResults(client, args, json) {
|
|
712
|
+
const action = args[0];
|
|
713
|
+
const subArgs = args.slice(1);
|
|
714
|
+
switch (action) {
|
|
715
|
+
case "mark": return mark(client, subArgs, json);
|
|
716
|
+
case "batch": return batch(client, subArgs, json);
|
|
717
|
+
case "--help":
|
|
718
|
+
case "-h":
|
|
719
|
+
case void 0:
|
|
720
|
+
console.log(`results commands:\n mark Mark a single case result (Scenario A)\n batch Batch submit results from file (Scenario B)`);
|
|
721
|
+
return;
|
|
722
|
+
default:
|
|
723
|
+
printError(`Unknown results action: ${action}`);
|
|
724
|
+
process.exitCode = 2;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
async function create(client, args, json) {
|
|
728
|
+
const { positional, named } = parseNamedArgs(args);
|
|
729
|
+
const planId = positional[0];
|
|
730
|
+
if (!planId) {
|
|
731
|
+
printError("Usage: test reports create <plan_id> [--conclusion <text>]");
|
|
732
|
+
process.exitCode = 2;
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const body = { plan_id: planId };
|
|
736
|
+
if (typeof named["type"] === "string") body["type"] = named["type"];
|
|
737
|
+
if (typeof named["conclusion"] === "string") body["conclusion"] = named["conclusion"];
|
|
738
|
+
if (typeof named["risk-notes"] === "string") body["risk_notes"] = named["risk-notes"];
|
|
739
|
+
const data = await client.post("/api/test/reports", body);
|
|
740
|
+
if (json) {
|
|
741
|
+
printJson(data);
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
printSuccess(`Report issued: ${data["report_id"]} (version ${data["version"]})`);
|
|
745
|
+
console.log(` Plan: ${data["plan_id"]}`);
|
|
746
|
+
const snap = data["summary_snapshot"];
|
|
747
|
+
if (snap) {
|
|
748
|
+
const counts = snap["counts"];
|
|
749
|
+
if (counts) console.log(` Summary: ${counts["passed"]} passed, ${counts["failed"]} failed (total ${counts["total"]})`);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
async function runReports(client, args, json) {
|
|
753
|
+
const action = args[0];
|
|
754
|
+
const subArgs = args.slice(1);
|
|
755
|
+
switch (action) {
|
|
756
|
+
case "create": return create(client, subArgs, json);
|
|
757
|
+
case "--help":
|
|
758
|
+
case "-h":
|
|
759
|
+
case void 0:
|
|
760
|
+
console.log(`reports commands:\n create Issue a report for a plan`);
|
|
761
|
+
return;
|
|
762
|
+
default:
|
|
763
|
+
printError(`Unknown reports action: ${action}`);
|
|
764
|
+
process.exitCode = 2;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
const RESOURCES = {
|
|
768
|
+
taxonomy: runTaxonomy,
|
|
769
|
+
requirements: runRequirements,
|
|
770
|
+
cases: runCases,
|
|
771
|
+
"case-sets": runCaseSets,
|
|
772
|
+
plans: runPlans,
|
|
773
|
+
results: runResults,
|
|
774
|
+
reports: runReports
|
|
775
|
+
};
|
|
776
|
+
const HELP = `Testing platform commands (Scenario A & B).
|
|
777
|
+
|
|
778
|
+
Resources:
|
|
779
|
+
taxonomy Product lines & modules
|
|
780
|
+
cases Test case assets
|
|
781
|
+
requirements Requirements & channel 1 sync
|
|
782
|
+
case-sets Case set member management
|
|
783
|
+
plans Test plans & execution
|
|
784
|
+
results Test results (mark / batch)
|
|
785
|
+
reports Test reports
|
|
786
|
+
|
|
787
|
+
Run: shoplazza-ai-dev-cli test <resource> --help`;
|
|
788
|
+
async function runTest(rawArgs) {
|
|
789
|
+
const { flags, rest } = parseGlobalFlags(rawArgs);
|
|
790
|
+
const resource = rest[0];
|
|
791
|
+
const subArgs = rest.slice(1);
|
|
792
|
+
if (!resource || resource === "--help" || resource === "-h") {
|
|
793
|
+
console.log(HELP);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
ensureLoggedIn();
|
|
797
|
+
const client = TestPlatformClient.fromConfig(flags.portal, flags.json);
|
|
798
|
+
const handler = RESOURCES[resource];
|
|
799
|
+
if (!handler) {
|
|
800
|
+
printError(`Unknown resource: ${resource}`);
|
|
801
|
+
console.log(HELP);
|
|
802
|
+
process.exitCode = 2;
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
try {
|
|
806
|
+
const passthrough = [];
|
|
807
|
+
if (flags.json) passthrough.push("--json");
|
|
808
|
+
if (flags.file) passthrough.push("--file", flags.file);
|
|
809
|
+
if (flags.page !== void 0) passthrough.push("--page", String(flags.page));
|
|
810
|
+
if (flags.size !== void 0) passthrough.push("--size", String(flags.size));
|
|
811
|
+
await handler(client, [...subArgs, ...passthrough], flags.json);
|
|
812
|
+
} catch (err) {
|
|
813
|
+
if (err && typeof err === "object" && "status" in err) {
|
|
814
|
+
const apiErr = err;
|
|
815
|
+
if (flags.json) console.log(JSON.stringify(apiErr.data ?? { error: {
|
|
816
|
+
code: apiErr.code,
|
|
817
|
+
message: apiErr.message
|
|
818
|
+
} }, null, 2));
|
|
819
|
+
else printError(`${apiErr.message}`);
|
|
820
|
+
process.exitCode = 1;
|
|
821
|
+
} else if (err instanceof Error && (err.message.startsWith("missing --") || err.message === "not logged in")) {} else if (err instanceof TypeError) {
|
|
822
|
+
if (flags.json) printJson({ error: {
|
|
823
|
+
code: "NETWORK_ERROR",
|
|
824
|
+
message: err.message
|
|
825
|
+
} });
|
|
826
|
+
else printError(`Network error: ${err.message}`);
|
|
827
|
+
process.exitCode = 1;
|
|
828
|
+
} else throw err;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
export { runTest };
|
package/dist/cli.mjs
CHANGED
|
@@ -6784,6 +6784,8 @@ function showBanner() {
|
|
|
6784
6784
|
console.log();
|
|
6785
6785
|
console.log(` ${DIM}$${RESET} ${TEXT}npx shoplazza-ai-dev-cli init ${DIM}[name]${RESET} ${DIM}Initialize a skill${RESET}`);
|
|
6786
6786
|
console.log();
|
|
6787
|
+
console.log(` ${DIM}$${RESET} ${TEXT}npx shoplazza-ai-dev-cli test ${DIM}<resource> <action>${RESET} ${DIM}Testing platform commands${RESET}`);
|
|
6788
|
+
console.log();
|
|
6787
6789
|
console.log(`${DIM}try:${RESET} npx shoplazza-ai-dev-cli add @public/skills --skill <name>`);
|
|
6788
6790
|
console.log();
|
|
6789
6791
|
}
|
|
@@ -6811,6 +6813,9 @@ ${BOLD}Project:${RESET}
|
|
|
6811
6813
|
${BOLD}Publishing:${RESET}
|
|
6812
6814
|
publish <paths...> Publish skills to the forge portal
|
|
6813
6815
|
|
|
6816
|
+
${BOLD}Testing:${RESET}
|
|
6817
|
+
test <resource> <action> Testing platform commands (Scenario A & B)
|
|
6818
|
+
|
|
6814
6819
|
${BOLD}Auth:${RESET}
|
|
6815
6820
|
login Authenticate with the forge portal (browser OAuth)
|
|
6816
6821
|
|
|
@@ -7172,6 +7177,11 @@ async function main() {
|
|
|
7172
7177
|
await runPublish(paths, publishOptions);
|
|
7173
7178
|
break;
|
|
7174
7179
|
}
|
|
7180
|
+
case "test": {
|
|
7181
|
+
const { runTest } = await import("./_chunks/test.mjs");
|
|
7182
|
+
await runTest(restArgs);
|
|
7183
|
+
break;
|
|
7184
|
+
}
|
|
7175
7185
|
case "report-event":
|
|
7176
7186
|
await runReportEvent(restArgs);
|
|
7177
7187
|
break;
|
|
@@ -7193,4 +7203,4 @@ main().catch((err) => {
|
|
|
7193
7203
|
console.error(`\n${BOLD}✗${RESET} ${msg}`);
|
|
7194
7204
|
process.exitCode = 1;
|
|
7195
7205
|
}).finally(() => flushTelemetry().then(() => process.exit(process.exitCode ?? 0)));
|
|
7196
|
-
export {};
|
|
7206
|
+
export { loadConfig, runLogin };
|