@botiverse/stamp-cli 0.1.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/bin/stamp.mjs +96 -0
- package/package.json +12 -0
package/bin/stamp.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// stamp — CLI for the Stamp acceptance system (https://raft-app-stamp.botiverse.dev)
|
|
3
|
+
//
|
|
4
|
+
// stamp cases list the case library
|
|
5
|
+
// stamp run <case-id...> [--app slug] [--apk ref] [--release id] [--by who]
|
|
6
|
+
// stamp runs list recent runs
|
|
7
|
+
// stamp show <run-id> run detail: cases, verdicts, evidence
|
|
8
|
+
//
|
|
9
|
+
// Auth: STAMP_TOKEN env (deploy token). STAMP_URL overrides the instance.
|
|
10
|
+
|
|
11
|
+
const URL_BASE = process.env.STAMP_URL || "https://raft-app-stamp.botiverse.dev";
|
|
12
|
+
const TOKEN = process.env.STAMP_TOKEN || "";
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const cmd = args.shift();
|
|
16
|
+
|
|
17
|
+
function flag(name, dflt) {
|
|
18
|
+
const i = args.indexOf(`--${name}`);
|
|
19
|
+
if (i === -1) return dflt;
|
|
20
|
+
const v = args[i + 1];
|
|
21
|
+
args.splice(i, 2);
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function api(method, path, body) {
|
|
26
|
+
if (!TOKEN) die("STAMP_TOKEN is not set (deploy token)");
|
|
27
|
+
const res = await fetch(`${URL_BASE}/api${path}`, {
|
|
28
|
+
method,
|
|
29
|
+
headers: { authorization: `Bearer ${TOKEN}`, "content-type": "application/json" },
|
|
30
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
31
|
+
});
|
|
32
|
+
const text = await res.text();
|
|
33
|
+
let json;
|
|
34
|
+
try { json = JSON.parse(text); } catch { die(`${res.status}: ${text.slice(0, 200)}`); }
|
|
35
|
+
if (!res.ok) die(`${res.status}: ${json.error ?? text.slice(0, 200)}`);
|
|
36
|
+
return json;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function die(msg) { console.error(`stamp: ${msg}`); process.exit(1); }
|
|
40
|
+
function table(rows, cols) {
|
|
41
|
+
const w = cols.map((c) => Math.max(c.length, ...rows.map((r) => String(r[c] ?? "").length)));
|
|
42
|
+
console.log(cols.map((c, i) => c.padEnd(w[i])).join(" "));
|
|
43
|
+
for (const r of rows) console.log(cols.map((c, i) => String(r[c] ?? "").padEnd(w[i])).join(" "));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
switch (cmd) {
|
|
47
|
+
case "cases": {
|
|
48
|
+
const { cases } = await api("GET", "/cases");
|
|
49
|
+
table(cases.map((c) => ({ id: c.id, tier: c.tier, rev: c.revision, title: c.title })), ["id", "tier", "rev", "title"]);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "run": {
|
|
53
|
+
const app = flag("app", "raft-android");
|
|
54
|
+
const apk = flag("apk", "ci-built:debug");
|
|
55
|
+
const release = flag("release");
|
|
56
|
+
const by = flag("by", process.env.USER || "stamp-cli");
|
|
57
|
+
const caseIds = args.filter((a) => !a.startsWith("--"));
|
|
58
|
+
if (!caseIds.length) die("usage: stamp run <case-id...> [--app slug] [--apk ref] [--release id]");
|
|
59
|
+
const out = await api("POST", "/runs", {
|
|
60
|
+
app_slug: app, case_ids: caseIds, apk_ref: apk, hands_release_id: release, requested_by: by,
|
|
61
|
+
});
|
|
62
|
+
console.log(`run ${out.run_id} — ${out.cases} case(s), ${out.dispatched} dispatched`);
|
|
63
|
+
console.log(`${URL_BASE}/runs/${out.run_id}`);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "runs": {
|
|
67
|
+
const { runs } = await api("GET", "/runs");
|
|
68
|
+
table(runs.map((r) => ({
|
|
69
|
+
run: r.id.slice(0, 8), app: r.app_slug, status: r.status,
|
|
70
|
+
cases: r.case_count, release: r.hands_release_id ?? "-",
|
|
71
|
+
created: new Date(r.created_at).toISOString().slice(0, 16),
|
|
72
|
+
})), ["run", "app", "status", "cases", "release", "created"]);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case "show": {
|
|
76
|
+
const id = args[0] || die("usage: stamp show <run-id>");
|
|
77
|
+
const d = await api("GET", `/runs/${id}`);
|
|
78
|
+
console.log(`run ${d.run.id} — ${d.run.status} (${d.run.app_slug}, release: ${d.run.hands_release_id ?? "-"})`);
|
|
79
|
+
console.log(`${URL_BASE}/runs/${d.run.id}\n`);
|
|
80
|
+
table(d.cases.map((rc) => {
|
|
81
|
+
const v = rc.verdict_json ? JSON.parse(rc.verdict_json) : null;
|
|
82
|
+
const ev = d.evidence.filter((e) => e.run_case_id === rc.id).length;
|
|
83
|
+
return { case: rc.case_id, status: rc.status, verdict: v?.verdict ?? "-", turns: v?.turns ?? "-", evidence: ev };
|
|
84
|
+
}), ["case", "status", "verdict", "turns", "evidence"]);
|
|
85
|
+
for (const rv of d.reviews) console.log(`\nfinal: ${rv.verdict} by ${rv.reviewer}${rv.comment ? ` — ${rv.comment}` : ""}`);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
console.log("stamp — the acceptance stamp in the Raft release loop\n");
|
|
90
|
+
console.log(" stamp cases list the case library");
|
|
91
|
+
console.log(" stamp run <case-id...> [--app --apk --release --by]");
|
|
92
|
+
console.log(" stamp runs list recent runs");
|
|
93
|
+
console.log(" stamp show <run-id> run detail");
|
|
94
|
+
console.log("\nauth: STAMP_TOKEN env; instance: STAMP_URL (default raft-app-stamp.botiverse.dev)");
|
|
95
|
+
process.exit(cmd ? 1 : 0);
|
|
96
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@botiverse/stamp-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for Stamp — the acceptance stamp in the Raft release loop",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": { "stamp": "bin/stamp.mjs" },
|
|
8
|
+
"files": ["bin"],
|
|
9
|
+
"engines": { "node": ">=18" },
|
|
10
|
+
"repository": { "type": "git", "url": "git+https://github.com/botiverse/stamp.git" },
|
|
11
|
+
"publishConfig": { "access": "public" }
|
|
12
|
+
}
|