@nasebanal/cli 0.10.0 → 0.12.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/README.md +16 -0
- package/dist/reports/upload.js +24 -0
- package/dist/specs/command.js +3 -1
- package/dist/specs/push.js +22 -5
- package/package.json +1 -1
- package/specs/assurance.yaml +13 -2
- package/specs/target.yaml +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,15 @@ NB_API_VERSION=v2 nb assurance report upload --file specmatic/v2/junit.xml --kin
|
|
|
69
69
|
# a project may require a version for some kinds of result (Assurance > Projects > the project's settings): a result of such a kind
|
|
70
70
|
# without one is refused with 422 API_VERSION_REQUIRED (the message says to pass --api-version or set NB_API_VERSION)
|
|
71
71
|
|
|
72
|
+
# Which contract the result was produced against: the SHA-256 of the contract document (the catalog's content_hash; `nb specs versions`
|
|
73
|
+
# prints it), so Evolution can tell a result of the current contract from one of an older or an unknown version. Not the API's URL version
|
|
74
|
+
# (--api-version) and not the document's info.version (edited by hand): a hash. Informational, not part of the result's identity.
|
|
75
|
+
nb assurance report upload --file specmatic/junit.xml --kind contract --tool specmatic --spec-hash 9f2c...64 hex characters
|
|
76
|
+
# or let the CLI hash the file the test ran against (a pinned package's spec.yaml hashes to what `nb specs push` of it registered)
|
|
77
|
+
nb assurance report upload --file specmatic/junit.xml --kind contract --tool specmatic \
|
|
78
|
+
--contract-file node_modules/@nasebanal/api-specs-assurance/spec.yaml
|
|
79
|
+
# needs an Assurance that knows spec_hash (the assurance contract 1.10.0 and later); an older one ignores the field
|
|
80
|
+
|
|
72
81
|
# Extra numbers for the suite (repeatable), e.g. ZAP's findings by severity - what the Assurance security gate reads
|
|
73
82
|
nb assurance report upload --file zap/report/baseline-junit.xml --kind security --tool zap --metric high=0 --metric medium=3 --metric low=2
|
|
74
83
|
|
|
@@ -147,6 +156,13 @@ nb assurance report upload --dir locust/logs/20261001_090000
|
|
|
147
156
|
specs, Evolution): a new spec, or a new version of the one that has the same name (or `--id`).
|
|
148
157
|
It is made to run on **every commit**:
|
|
149
158
|
|
|
159
|
+
- **A retitled document needs `--id`.** Without it the spec is found by its name (the document's
|
|
160
|
+
`info.title`), so a new title registers a second spec next to the old one. `--id <id>` pushes to
|
|
161
|
+
the spec you mean (a pipeline can read the id from `spec_id` of an earlier run), and adding
|
|
162
|
+
`--rename` also renames the spec to `--name` (default: the new `info.title`); the old name is
|
|
163
|
+
printed (`renamed_from` in the JSON). A rename happens only on request, so a name set by hand in
|
|
164
|
+
the catalog is not overwritten on every push, and `--rename` without `--id` is refused.
|
|
165
|
+
|
|
150
166
|
- **Nothing is uploaded when the file is already the latest version.** The CLI compares the
|
|
151
167
|
document's SHA-256 with the `content_hash` the catalog keeps for the latest version before it
|
|
152
168
|
sends anything; the same bytes print `unchanged (already vN: nothing uploaded)`. (The catalog
|
package/dist/reports/upload.js
CHANGED
|
@@ -192,6 +192,7 @@ export function parseReport(opts) {
|
|
|
192
192
|
...(opts.components && opts.components.length > 0 ? { components: opts.components } : {}),
|
|
193
193
|
...(opts.label ? { label: opts.label } : {}),
|
|
194
194
|
...(opts.toolVersion ? { tool_version: opts.toolVersion } : {}),
|
|
195
|
+
...(opts.specHash ? { spec_hash: opts.specHash } : {}),
|
|
195
196
|
};
|
|
196
197
|
if (opts.format === "junit") {
|
|
197
198
|
const j = parseJunit(text);
|
|
@@ -379,6 +380,24 @@ function checkToolVersion(raw) {
|
|
|
379
380
|
fail("--tool-version must be 50 characters or fewer");
|
|
380
381
|
return version;
|
|
381
382
|
}
|
|
383
|
+
/** The `--spec-hash`: a SHA-256 in hex (what `nb specs versions` prints), lower-cased because the API takes lowercase only. */
|
|
384
|
+
function checkSpecHash(raw) {
|
|
385
|
+
if (raw === undefined)
|
|
386
|
+
return undefined;
|
|
387
|
+
const hash = raw.trim().toLowerCase();
|
|
388
|
+
if (!/^[0-9a-f]{64}$/.test(hash))
|
|
389
|
+
fail("--spec-hash must be a SHA-256 in hex (64 characters), e.g. the sha256 `nb specs versions` prints");
|
|
390
|
+
return hash;
|
|
391
|
+
}
|
|
392
|
+
/** The `--contract-file`: the hash the catalog would keep as `content_hash` for this document (SHA-256 of its text). */
|
|
393
|
+
function hashOfContractFile(file) {
|
|
394
|
+
try {
|
|
395
|
+
return hashText(readSpecFile(file));
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
return fail(String(err.message).replace(/^--file:/, "--contract-file:"));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
382
401
|
/** The `--component` names: trimmed, no empty one, no two alike ignoring case, within the API's limits. */
|
|
383
402
|
function checkComponents(raw) {
|
|
384
403
|
if (raw === undefined)
|
|
@@ -455,6 +474,8 @@ export function buildReportUploadCommand() {
|
|
|
455
474
|
.option("--component <name>", "a component the result is for (e.g. frontend, backend), repeatable when it covers several (e.g. an end-to-end test: --component frontend --component backend); new names are created in the project; leave it out for the component `default`", (v, all = []) => [...all, v])
|
|
456
475
|
.option("--label <name>", "tells apart results that are otherwise the same, such as two scans of one tool on the same components (e.g. --label baseline, --label full-scan); part of the result's identity, so the same label again replaces the result; optional")
|
|
457
476
|
.option("--tool-version <version>", "the version of the tool that produced the report (e.g. 9.1.0): informational, shown next to the tool, handy when a tool's new version changes its layout; optional")
|
|
477
|
+
.option("--spec-hash <sha256>", "the SHA-256 of the API contract this result was produced against (64 hex characters; the sha256 `nb specs versions` prints for a catalog version): Evolution compares it with the catalog's versions and tells whether the result was produced with the current contract, an older one or an unknown one. Informational, not part of the result's identity; a report sent again replaces it. Exclusive with --contract-file")
|
|
478
|
+
.option("--contract-file <path>", "the contract document the result was produced against (e.g. node_modules/@nasebanal/api-specs-<api>/spec.yaml): its SHA-256 is sent as --spec-hash would, the same hash the catalog keeps for that document. Exclusive with --spec-hash")
|
|
458
479
|
.option("--metric <key=value>", "an extra number for the suite, repeatable (e.g. --metric high=0 --metric medium=3; for security: critical, high, medium, low, info)", (v, all = []) => [...all, v])
|
|
459
480
|
.option("--api-version <label>", "the API version the result is for (e.g. v1, v2), part of the result's identity next to its kind and components; leave it out for results that hold for every version, such as unit tests. Default: the NB_API_VERSION environment variable (set it once per CI job or branch). A project can require a version for some kinds of result, and then refuses one without it")
|
|
460
481
|
.option("--project <name>", "project name (CI: the repository); found, or created if missing")
|
|
@@ -500,6 +521,8 @@ export function buildReportUploadCommand() {
|
|
|
500
521
|
// The flag wins; NB_API_VERSION (a CI variable) is the default, and an empty one (a CI that declares it but does not set it) is none.
|
|
501
522
|
const versionRaw = opts.apiVersion ?? (process.env.NB_API_VERSION || undefined);
|
|
502
523
|
const apiVersion = versionRaw === undefined ? undefined : checkApiVersion(versionRaw);
|
|
524
|
+
if (opts.specHash !== undefined && opts.contractFile !== undefined)
|
|
525
|
+
fail("--spec-hash and --contract-file are exclusive: one gives the hash, the other a file to take it from");
|
|
503
526
|
const parsed = parseReport({
|
|
504
527
|
format,
|
|
505
528
|
kind,
|
|
@@ -507,6 +530,7 @@ export function buildReportUploadCommand() {
|
|
|
507
530
|
components: checkComponents(opts.component),
|
|
508
531
|
label: checkLabel(opts.label),
|
|
509
532
|
toolVersion: checkToolVersion(opts.toolVersion),
|
|
533
|
+
specHash: opts.contractFile !== undefined ? hashOfContractFile(opts.contractFile) : checkSpecHash(opts.specHash),
|
|
510
534
|
status: opts.status,
|
|
511
535
|
maxFailRatio,
|
|
512
536
|
file,
|
package/dist/specs/command.js
CHANGED
|
@@ -15,6 +15,7 @@ export function buildPushCommand() {
|
|
|
15
15
|
.requiredOption("--file <path>", "the OpenAPI document (YAML or JSON, up to 2 MiB)")
|
|
16
16
|
.option("--name <name>", "the spec's name in the catalog (default: the document's info.title, then the file's name)")
|
|
17
17
|
.option("--id <id>", "push to this spec by id: a rename cannot make a second one")
|
|
18
|
+
.option("--rename", "with --id: also rename the spec to --name (default: the document's info.title) when it is called something else")
|
|
18
19
|
.option("--group <name>", "file a NEW spec in this group (made when missing); default none. An existing spec is never moved by a push")
|
|
19
20
|
.option("--description <text>", "a new spec's description")
|
|
20
21
|
.option("--note <text>", "what changed, shown in the version list (default: the commit, branch and CI run)")
|
|
@@ -33,12 +34,13 @@ export function buildPushCommand() {
|
|
|
33
34
|
description: opts.description,
|
|
34
35
|
note: opts.note ?? ciNote(ci, undefined),
|
|
35
36
|
id: opts.id,
|
|
37
|
+
rename: opts.rename,
|
|
36
38
|
dryRun: opts.dryRun,
|
|
37
39
|
});
|
|
38
40
|
printJson(result);
|
|
39
41
|
exportGithubOutput("spec_id", result.id);
|
|
40
42
|
const what = { created: "created (v1)", new_version: `new version v${result.version}`, unchanged: `unchanged (already v${result.version}: nothing uploaded)` }[result.action];
|
|
41
|
-
process.stderr.write(`${opts.dryRun ? "(dry run) " : ""}✓ ${result.name} -> ${what}\n`);
|
|
43
|
+
process.stderr.write(`${opts.dryRun ? "(dry run) " : ""}✓ ${result.renamed_from ? `${result.renamed_from} renamed to ` : ""}${result.name} -> ${what}\n`);
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
async function connection(opts) {
|
package/dist/specs/push.js
CHANGED
|
@@ -131,16 +131,33 @@ async function pushSpecInner(p) {
|
|
|
131
131
|
const hash = hashText(text);
|
|
132
132
|
const name = specNameFor(text, p.file, p.name);
|
|
133
133
|
const note = p.note !== undefined ? p.note.trim().slice(0, MAX_NOTE) || undefined : undefined;
|
|
134
|
-
|
|
134
|
+
if (p.rename && !p.id)
|
|
135
|
+
throw new Error("--rename needs --id: without an id the spec is found by its name, so there is nothing to rename");
|
|
136
|
+
let existing = await findSpec(p.conn, name, p.id);
|
|
137
|
+
// A rename only on request: a spec named by hand in the catalog is not renamed back to the title on every push.
|
|
138
|
+
let renamedFrom;
|
|
139
|
+
if (existing && p.rename && existing.name !== name) {
|
|
140
|
+
renamedFrom = existing.name;
|
|
141
|
+
if (!p.dryRun) {
|
|
142
|
+
try {
|
|
143
|
+
await request({ ...headersOf(p.conn), method: "PATCH", path: `/api/v1/specs/${encodeURIComponent(existing.id)}`, body: { name } });
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
throw new Error(`The catalog refused the new name '${name}': ${reasonOf(err)}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
existing = { ...existing, name };
|
|
150
|
+
}
|
|
151
|
+
const renamed = renamedFrom ? { renamed_from: renamedFrom } : {};
|
|
135
152
|
if (existing) {
|
|
136
153
|
// Nothing to upload when the file is already the latest version: the hash settles it without sending the document.
|
|
137
154
|
const versions = await request({ ...headersOf(p.conn), method: "GET", path: `/api/v1/specs/${encodeURIComponent(existing.id)}/versions` });
|
|
138
155
|
const latest = versions.data.data.data[0];
|
|
139
156
|
if (latest?.content_hash === hash) {
|
|
140
|
-
return { id: existing.id, name: existing.name, version: latest.version, group_id: existing.group_id, action: "unchanged", content_hash: hash };
|
|
157
|
+
return { id: existing.id, name: existing.name, version: latest.version, group_id: existing.group_id, action: "unchanged", content_hash: hash, ...renamed };
|
|
141
158
|
}
|
|
142
159
|
if (p.dryRun)
|
|
143
|
-
return { id: existing.id, name: existing.name, version: existing.latest_version + 1, group_id: existing.group_id, action: "new_version", content_hash: hash };
|
|
160
|
+
return { id: existing.id, name: existing.name, version: existing.latest_version + 1, group_id: existing.group_id, action: "new_version", content_hash: hash, ...renamed };
|
|
144
161
|
try {
|
|
145
162
|
const res = await request({
|
|
146
163
|
...headersOf(p.conn),
|
|
@@ -149,12 +166,12 @@ async function pushSpecInner(p) {
|
|
|
149
166
|
body: { content: text, ...(note ? { note } : {}) },
|
|
150
167
|
});
|
|
151
168
|
const version = res.data.data.version;
|
|
152
|
-
return { id: existing.id, name: existing.name, version, group_id: existing.group_id, action: "new_version", content_hash: hash };
|
|
169
|
+
return { id: existing.id, name: existing.name, version, group_id: existing.group_id, action: "new_version", content_hash: hash, ...renamed };
|
|
153
170
|
}
|
|
154
171
|
catch (err) {
|
|
155
172
|
// Another job pushed the same document between our comparison and our upload: the catalog says so, and that is the goal.
|
|
156
173
|
if (codeOf(err) === "UNCHANGED")
|
|
157
|
-
return { id: existing.id, name: existing.name, version: existing.latest_version, group_id: existing.group_id, action: "unchanged", content_hash: hash };
|
|
174
|
+
return { id: existing.id, name: existing.name, version: existing.latest_version, group_id: existing.group_id, action: "unchanged", content_hash: hash, ...renamed };
|
|
158
175
|
throw new Error(`The catalog refused the new version: ${reasonOf(err)}`);
|
|
159
176
|
}
|
|
160
177
|
}
|
package/package.json
CHANGED
package/specs/assurance.yaml
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
openapi: 3.0.3
|
|
2
2
|
info:
|
|
3
|
-
title: NASEBANAL
|
|
3
|
+
title: NASEBANAL Assurance API
|
|
4
4
|
description: "Backend of NASEBANAL Assurance (quality assurance for APIs and web apps, under NASEBANAL Evolution). Authenticates users via Auth0 JWT and Personal Access Tokens (PAT) and integrates with the Account API. External monitoring: register URLs to be probed on an interval, then read availability reports. Test results: report the normalised result of each CI/CD job into a named project (typically one per repository), then read its runs and suites. Every response is wrapped as `{ success, data }` (or `{ success: false, error }`)."
|
|
5
|
-
version: 1.9.
|
|
5
|
+
version: 1.9.2
|
|
6
6
|
contact:
|
|
7
7
|
name: NASEBANAL
|
|
8
8
|
url: https://www.nasebanal.com
|
|
@@ -1872,9 +1872,19 @@ components:
|
|
|
1872
1872
|
$ref: "#/components/schemas/User"
|
|
1873
1873
|
Error:
|
|
1874
1874
|
type: object
|
|
1875
|
+
required:
|
|
1876
|
+
- success
|
|
1877
|
+
- error
|
|
1875
1878
|
properties:
|
|
1879
|
+
success:
|
|
1880
|
+
type: boolean
|
|
1881
|
+
enum:
|
|
1882
|
+
- false
|
|
1876
1883
|
error:
|
|
1877
1884
|
type: object
|
|
1885
|
+
required:
|
|
1886
|
+
- code
|
|
1887
|
+
- message
|
|
1878
1888
|
properties:
|
|
1879
1889
|
code:
|
|
1880
1890
|
type: string
|
|
@@ -3354,6 +3364,7 @@ components:
|
|
|
3354
3364
|
schema:
|
|
3355
3365
|
$ref: "#/components/schemas/Error"
|
|
3356
3366
|
example:
|
|
3367
|
+
success: false
|
|
3357
3368
|
error:
|
|
3358
3369
|
code: AUTH_ERROR
|
|
3359
3370
|
message: No authentication token provided
|
package/specs/target.yaml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
openapi: 3.0.3
|
|
2
2
|
info:
|
|
3
|
-
title: NASEBANAL
|
|
3
|
+
title: NASEBANAL Target API
|
|
4
4
|
description: "Target API for NASEBANAL. Provides hierarchical target management: users define goals and organize them in a tree structure. Parent-child links are persisted via `targets.parent_target_id` (authoritative since migration 0017); a legacy cell-based storage layer is kept in sync best-effort for backward compatibility. Targets can be shared with other users (read/write, optionally including the subtree and linked Recorder data), and ownership of a personal target subtree can be transferred to a recipient via an email-approved migration flow. Supports user authentication via Auth0 JWT and Personal Access Tokens (PAT)."
|
|
5
5
|
version: 1.5.0
|
|
6
6
|
contact:
|