@nasebanal/cli 0.12.0 → 0.13.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 CHANGED
@@ -29,8 +29,9 @@ $ nb account me tokens create --data '{"name":"ci"}'
29
29
 
30
30
  `nb assurance report upload` reads a test report on the runner, reduces it to a
31
31
  small summary (counts, coverage-free metrics, the first failures, and for JUnit
32
- the per-test cases) and reports it to a NASEBANAL Assurance project. The same line works in a pipeline and on a
33
- laptop; in CI it needs only a token:
32
+ the per-test cases) and reports it to a NASEBANAL Assurance **spec**: an API spec of the catalog that is tied to a repository
33
+ (see "Which spec a result or a monitor is about" below). The same line works in a pipeline and on a laptop; in CI it needs a
34
+ token and the spec's id:
34
35
 
35
36
  The **kind** is one of a fixed set of perspectives (`unit`, `e2e`, `contract`,
36
37
  `security`, `load`); the **tool** is a free label (`vitest`, `pytest`, `playwright`,
@@ -42,41 +43,48 @@ numbers with `--metric` (for a scanner: `critical`, `high`, `medium`, `low`, `in
42
43
 
43
44
  ```bash
44
45
  export NB_TOKEN=nbpat_… # a PAT or service-account token (no browser needed)
46
+ export NB_SPEC_ID=… # the spec's id in the catalog (Spec Management, or `nb specs specs list`; a CI variable)
45
47
 
46
48
  # JUnit XML: vitest (--reporter=junit), pytest (--junitxml), Specmatic, Playwright (--reporter=junit)
47
49
  nb assurance report upload --file report/junit.xml --kind unit --tool pytest
48
- nb assurance report upload --file results/junit.xml --kind e2e --tool playwright --component web
50
+ nb assurance report upload --file results/junit.xml --kind e2e --tool playwright
49
51
 
50
- # Two scans of one tool on the same components (ZAP's baseline and full scan): a label tells them apart
51
- nb assurance report upload --file report/baseline-junit.xml --kind security --tool zap --component frontend --label baseline
52
- nb assurance report upload --file report/full-scan-junit.xml --kind security --tool zap --component frontend --label full-scan
52
+ # By names instead of the id (all checked against the catalog; --component is optional: none = the repository as a whole;
53
+ # --group is optional too: none = the specs in no group, an environment is a group)
54
+ nb assurance report upload --file results/junit.xml --kind e2e --tool playwright \
55
+ --repository nasebanal/nb-account-api --component account-internal --group Staging --spec "Account API (internal)"
56
+
57
+ # A result that belongs to the source, not to an environment (unit tests, a security scan), goes to EVERY spec of the repository
58
+ # at ONE API version (one per environment), one line each; refused for the other kinds. A repository row whose specs are all at one
59
+ # API version needs no --api-version; with several (v1 and v2 side by side) it is required: a release branch feeds its own version only
60
+ nb assurance report upload --file report/junit.xml --kind unit --tool vitest --repository nasebanal/nb-account-api --all-specs --api-version v1
61
+
62
+ # Two scans of one tool of the same spec (ZAP's baseline and full scan): a label tells them apart
63
+ nb assurance report upload --file report/baseline-junit.xml --kind security --tool zap --label baseline
64
+ nb assurance report upload --file report/full-scan-junit.xml --kind security --tool zap --label full-scan
53
65
 
54
66
  # The tool's own version is informational and optional
55
67
  nb assurance report upload --file report/junit.xml --kind unit --tool pytest --tool-version 9.1.0
56
68
 
57
- # A result may be about several components: repeat the flag (new names are created in the project; none = `default`)
58
- nb assurance report upload --file results/junit.xml --kind e2e --tool playwright --component frontend --component backend
59
-
60
69
  # Specmatic: the JUnit XML, plus its HTML report for the API coverage (coverage_pct = operations exercised / operations in the spec)
61
70
  nb assurance report upload --file specmatic/junit/TEST-junit-jupiter.xml --kind contract --tool specmatic \
62
71
  --coverage-report specmatic/report/test/html/index.html
63
72
 
64
- # One repository, several API versions: label the result (the version is part of the suite's identity, so v1 and v2 of the same name sit side by side)
65
- nb assurance report upload --file specmatic/v2/junit.xml --kind contract --tool specmatic --api-version v2
66
- # unit tests hold for every version: leave --api-version out
67
- # set NB_API_VERSION once (a CI variable per job or branch) instead of repeating the flag; the flag wins, an empty variable means none
68
- NB_API_VERSION=v2 nb assurance report upload --file specmatic/v2/junit.xml --kind contract --tool specmatic
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
- # without one is refused with 422 API_VERSION_REQUIRED (the message says to pass --api-version or set NB_API_VERSION)
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.
73
+ # An API at several API versions (v1 and v2 side by side) is one SPEC per API version, so a result needs no version of its own: it
74
+ # goes to the spec it belongs to. By names, --api-version is part of the spec's KEY (it selects the spec; it is not a label of the result)
75
+ nb assurance report upload --file specmatic/v2/junit.xml --kind contract --tool specmatic \
76
+ --repository nasebanal/nb-account-api --spec "Account API" --api-version v2
77
+ # NB_API_VERSION and the result's own api_version are retired (the variable is ignored with a warning); the API versions a result
78
+ # must name (the spec's "How results are handled") are gone with them
79
+
80
+ # Which contract the result was produced against: the SHA-256 of the contract document (the catalog's content_hash; `nb specs specs versions list`
81
+ # prints it), so Evolution can tell a result of the current revision from one of an older or an unknown one. Not the API version
82
+ # (v1, v2: the spec's) and not the document's info.version (edited by hand): a hash. Informational, not part of the result's identity.
75
83
  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)
84
+ # or let the CLI hash the file the test ran against (a pinned package's spec.yaml hashes to what `nb specs specs push` of it registered)
77
85
  nb assurance report upload --file specmatic/junit.xml --kind contract --tool specmatic \
78
86
  --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
87
+ # Evolution matches the hash against the revisions of this spec
80
88
 
81
89
  # Extra numbers for the suite (repeatable), e.g. ZAP's findings by severity - what the Assurance security gate reads
82
90
  nb assurance report upload --file zap/report/baseline-junit.xml --kind security --tool zap --metric high=0 --metric medium=3 --metric low=2
@@ -85,16 +93,26 @@ nb assurance report upload --file zap/report/baseline-junit.xml --kind security
85
93
  nb assurance report upload --dir locust/logs/20261001_090000
86
94
  ```
87
95
 
88
- - **Project:** found by name, created when missing (`--no-create-project` to fail
89
- instead). In CI the name defaults to the repository (`GITHUB_REPOSITORY` /
90
- `CI_PROJECT_PATH`); elsewhere pass `--project`. That is the zero-configuration
91
- start; once the project exists, **pin it by id** (`--project-id <id>` or
92
- `NB_ASSURANCE_PROJECT_ID`): the upload then goes straight to that project, nothing
93
- is looked up by name or created, so renaming the project, a typo, or a renamed
94
- repository can no longer send results elsewhere. An unknown id is an error, never a
95
- new project. The id is printed after every upload (and, in GitHub Actions, written
96
- to `$GITHUB_OUTPUT` as `project_id`). Keep one id per environment (`--env`), and
97
- take care when copying a workflow to another repository: its id goes with it.
96
+ - **Spec (the target of a report):** a result is reported to a **spec of the catalog that is tied to a
97
+ repository**, by its id, `--spec-id <id>` or `$NB_SPEC_ID` (a pipeline's repository variable; it is not
98
+ a secret, and it is not a file in the repository: a copy of a workflow keeps its own variable, so it
99
+ cannot report into another API by accident), or by names, `--repository <owner/name> [--component <name>] [--group <name>] [--api-version <v>] --spec <name>`
100
+ (+ `--repository-provider`, default `github`; no `--component` = the repository as a whole; no `--group` = the specs
101
+ in no group, **not** any group; no `--api-version` = the API version of the one spec the rest of the key leaves, several
102
+ are an error that lists them), which are checked against each other (the spec must be tied to exactly that group,
103
+ repository row and API version; on a miss the error lists where the name does exist). `--all-specs` (with `--repository`
104
+ [`--api-version`], instead of `--spec`) sends a `unit` or `security` result to every spec tied to that repository row at that API
105
+ version. A name asked for wins over the variable; an id and
106
+ names together are refused; with none the command stops before sending anything and says how. **Nothing is created:** a
107
+ spec or a repository that the catalog does not have is an error that points at `nb specs`, and a spec tied to no
108
+ repository is refused (the request carries the spec in the path and its `repository_id` in the body, and Assurance
109
+ checks the pair with the catalog: `422 SPEC_WITHOUT_REPOSITORY` / `REPOSITORY_MISMATCH`). The ids are printed after
110
+ every upload (and, in GitHub Actions, written to `$GITHUB_OUTPUT` as `spec_id` and `repository_id`). `--org <id|personal>`
111
+ (or `$NB_SPECS_ORG`) says whose specs these are; it is sent to the catalog and, for an organization, to Assurance.
112
+ Keep one id per environment (`--env`). **What this replaces:** `--repository-id` / `NB_REPOSITORY_ID` (a clear error says
113
+ so for this release), the old `--component` of a result (the component is now part of the repository's key), `--project`,
114
+ `--project-id`, `--no-create-project`, `--spec-environment` and `--spec-file` are gone: Assurance creates and links
115
+ nothing, the spec and its repository belong to the catalog, and registering them is its own step (`nb specs`).
98
116
  - **Link to the report in the repository:** the CLI also sends the CI `--provider`
99
117
  (`github` | `gitlab` | `other`, detected) and, when the report file is **committed**
100
118
  (tracked, unchanged since `HEAD`, and `HEAD` is the reported commit), its path
@@ -103,24 +121,7 @@ nb assurance report upload --dir locust/logs/20261001_090000
103
121
  override with `--report-path`.
104
122
  The repository's web address is sent too (`repo_url`, detected from `GITHUB_SERVER_URL` /
105
123
  `CI_PROJECT_URL`; override with `--repo-url`), so the link also works on a self-hosted
106
- GitLab or GitHub Enterprise. The CI's repository also replaces the project's `repo`
107
- (the latest sender wins).
108
- - **Tie the project to its API in the catalog (`--spec-id`, `--spec-environment`):**
109
- `--spec-id <id>` links the project to a spec of the API catalog (its id in Assurance /
110
- Specs), `--spec-environment production` says which environment of it the project covers
111
- (needs `--spec-id`). A new project is created already linked; an existing one is
112
- changed **only when it differs**, so a pipeline that runs on every commit writes nothing
113
- once the link is right. Pointing it at another spec clears the old environment unless one
114
- is given too. The id is not looked up in the catalog (it is another service): a typo shows
115
- as "no spec" on the project. The link is set after the result is in, so a failure there
116
- leaves the result reported and says so. `--spec-file <openapi.yaml>` does the whole chain in one command (see below).
117
- - **Register the spec file and tie the project to it in one command (`--spec-file`):**
118
- `nb assurance report upload ... --spec-file openapi.yaml [--spec-name N] [--spec-group G]
119
- [--spec-org ID] [--spec-environment production]` first runs `nb specs push` on the file,
120
- then creates / links the project to the spec it returns, then reports the result. The
121
- catalog's answer never costs the result: if registering the spec fails (a plan without the
122
- catalog, the limit of specs), the result is still reported, without the link, and the command
123
- ends with the reason and a non-zero exit. Exclusive with `--spec-id`.
124
+ GitLab or GitHub Enterprise.
124
125
  - **Run:** every job of one pipeline run shares a run key (CI: `GITHUB_RUN_ID` +
125
126
  attempt, `CI_PIPELINE_ID`; locally `local-<sha>-<day>`), so a unit job and an e2e
126
127
  job land in the same run, and re-running a job replaces its own result.
@@ -131,12 +132,12 @@ nb assurance report upload --dir locust/logs/20261001_090000
131
132
  report, Specmatic's report, a JUnit file with everything in it). `--attach` sends the
132
133
  original with the result: a file as it is, a folder as a zip made by the CLI (regular
133
134
  files only, symbolic links are never followed). Up to 20 MiB per result and 200 MiB per
134
- project; the CLI checks the size before anything is sent. It is **opt-in twice** - nothing is
135
+ repository; the CLI checks the size before anything is sent. It is **opt-in twice** - nothing is
135
136
  attached unless you pass it, and the server refuses it (403 `ATTACHMENTS_DISABLED`) until
136
- the project has turned on "Attaching original reports" in its settings in Assurance (off by
137
+ the spec has turned on "Attaching original reports" in its settings (off by
137
138
  default). Make sure the report holds no secrets or personal data.
138
139
  The server only stores it (next to the result's cases, deleted with the result and by
139
- the project's retention) and offers it as a **download** to the project's members in
140
+ the repository's retention) and offers it as a **download** to the repository's members in
140
141
  Assurance; it is never opened, unzipped or shown in the browser. A failed attachment
141
142
  leaves the result reported and the command exits non-zero with the reason.
142
143
  - **Pass / fail:** JUnit - any failed or errored test fails the suite. Locust - an
@@ -150,12 +151,131 @@ nb assurance report upload --dir locust/logs/20261001_090000
150
151
  is sent in total (names and outcomes always stay). Locust reports have no cases.
151
152
  - `--dry-run` prints what would be sent and calls nothing.
152
153
 
153
- ## The API catalog from a pipeline (`nb specs push`)
154
+ ## Repositories and the API catalog from a pipeline (`nb specs`)
155
+
156
+ `nb specs` is generated from the catalog's contract like every other group, so it reads
157
+ `nb specs <resource> <verb>`: `nb specs specs list`, `nb specs specs versions list <id>`,
158
+ `nb specs repositories get <id>`, `nb specs groups list`, and `--org <id|personal>` (or
159
+ `$NB_SPECS_ORG`) on each, since the catalog is per owner. The verbs a pipeline wants are
160
+ hand-written and sit in the same tree: `specs push`, `specs pull`, `specs settings` and `repositories upsert`.
161
+ The old direct form (`nb specs push`, `nb specs pull`, `nb specs versions`) still works, as hidden aliases.
162
+
163
+ **The commands match the screens.** Each sub-menu of NASEBANAL Evolution's *API management* manages one resource of
164
+ the catalog, and `nb specs <resource>` is that resource:
165
+
166
+ | Evolution screen | Resource | Command group | What it holds |
167
+ |---|---|---|---|
168
+ | Repository Management | repositories | `nb specs repositories` | `provider`, `name`, `component` and the one repository setting, `attachments_enabled` (`upsert --attachments`, `update --attachments`) |
169
+ | Spec Management | specs | `nb specs specs` | the spec (`push`, `update`, `delete`), its description document (`docs push|pull|delete`), the consumer-facing reference publishing (`update`: `reference_access`) and the quality settings: the public badge and report with their links (`settings`) |
170
+ | Catalog | (a read-only view of the specs) | `nb specs specs list` / `get` / `versions list` / `docs pull` | what is registered, its revisions and its description document, to read |
171
+
172
+ The quality settings (public badge and report with their links) are columns of the
173
+ **spec**; the repository is where it lives (its identity) and holds one setting, **attachments**: whether a result may
174
+ carry the original test report, which comes from the repository's CI. A spec is tied to a repository
175
+ optionally, so either can be registered first.
176
+
177
+ ### Environments: one spec per environment, filed in a group
178
+
179
+ An API deployed to several environments (development, staging, production) is **one OpenAPI file in the
180
+ repository and one spec per environment**, each filed in a **group named after the environment**. What
181
+ differs between them is where the API is served, which is the document's top-level `servers`: `push
182
+ --server-url <url>` replaces it just before sending (see below), and the catalog's **contract hash**
183
+ (`latest_contract_hash`, which ignores `servers`) says whether two environments run the same contract.
184
+ A promotion is the same file pushed to the next environment's spec; a rollback is an older file pushed
185
+ as a new revision of that environment's spec (the history stays one straight line). A spec's key is its
186
+ **group, its repository row (provider, name, component), its API version and its name**: the same name may exist in other
187
+ groups, which is exactly the case of the same API in two environments.
188
+
189
+ ```bash
190
+ # the first run makes the group, the repository and the spec (idempotent; nothing set on a screen is overwritten)
191
+ nb specs specs push --file openapi.yaml --group Staging --server-url https://staging.api.example.com/v1 \
192
+ --repository nasebanal/nb-account-api --name "Account API"
193
+ # the spec's id goes to the environment's variable (GitHub: Settings > Environments > Staging > Variables)
194
+ # NB_SPEC_ID=<spec_id printed above>
195
+ # every later run pushes a new version only if the document changed, and the test jobs report to NB_SPEC_ID
196
+ ```
197
+
198
+ In GitHub Actions use **Environments**: the same workflow runs per environment and each environment carries
199
+ its own `NB_SPEC_ID`, so the report steps are written once.
200
+
201
+ ### API versions: one spec per API version, one branch per version
202
+
203
+ The **API version** (`v1`, `v2`) is a property of the **spec**, and a new major API version is a **new spec**. The numbered
204
+ history inside a spec is its **revisions** (#1, #2, ...: one per push that changed the document; the catalog's `version`
205
+ field). `nb specs specs push` takes the API version from the document: the major of `info.version` (`1.8.0` -> `v1`,
206
+ `v2.0` -> `v2`, `1.0.0-rc.1` -> `v1`, `007.1` -> `v7`). A version that has no leading major (`2023-01`, `latest`, `1.x`) needs
207
+ `--api-version <v>`; an explicit one always wins. So:
208
+
209
+ - an additive change (an example, a new field) is a new **revision** of the same spec: bump `info.version` to `1.9.0`, push, and the
210
+ spec is still `v1`;
211
+ - a breaking change is a new major (`2.0.0`): the same push makes the **v2 spec** and leaves v1 untouched; pushing a document of
212
+ another major to a spec by `--id` is refused (`API_VERSION_MISMATCH`: register it as its own spec).
213
+
214
+ To maintain several API versions, keep each one on a **branch** of the repository with its own OpenAPI file, and let the same CI
215
+ job push and report from whichever branch it runs on:
216
+
217
+ ```bash
218
+ # main (v2, info.version 2.x) and release/v1 (v1, info.version 1.x): the same step on both branches
219
+ nb specs specs push --file openapi.yaml --group Production --server-url "$API_URL" --repository nasebanal/nb-account-api --name "Account API"
220
+ # test results: the spec of the branch's API version. Either the id (a variable per branch, picked in the workflow) ...
221
+ nb assurance report upload --file junit.xml --kind e2e --tool playwright --spec-id "${{ github.ref_name == 'main' && vars.NB_SPEC_ID_V2 || vars.NB_SPEC_ID_V1 }}"
222
+ # ... or by names, with the branch's API version
223
+ nb assurance report upload --file junit.xml --kind e2e --tool playwright \
224
+ --repository nasebanal/nb-account-api --group Production --api-version "$API_VERSION" --spec "Account API"
225
+ # a result that belongs to the source goes to every environment of THIS API version only
226
+ nb assurance report upload --file junit.xml --kind unit --tool vitest --repository nasebanal/nb-account-api --all-specs --api-version "$API_VERSION"
227
+ ```
228
+
229
+ `NB_SPEC_ID` is a per-repository or per-**environment** variable, not a per-branch one: with several API versions either pick
230
+ the id in the workflow as above (one variable per API version) or report by names with `--api-version`.
231
+
232
+ ### A repository first (`nb specs repositories upsert`)
233
+
234
+ A **repository** is where one or more of your APIs are implemented (something that is not in git,
235
+ such as a vendor's delivery, is a repository with provider `other`). Its key is the **provider, the
236
+ name and the component**: the component is your own name for a part of it (`account-api`, `web`),
237
+ optional (none = the repository as a whole, which is a row of its own), and one id says which
238
+ repository AND which component. A part of a monorepo is simply another row. Register it once, by
239
+ hand or from the screen, and keep the id the catalog issues:
240
+
241
+ ```bash
242
+ nb specs repositories upsert --provider github --name nasebanal/nb-recorder-api
243
+ # -> {"id":"kMsl4TXEMmeN","provider":"github","name":"nasebanal/nb-recorder-api","component":""}
244
+ nb specs repositories upsert --name nasebanal/nb-account-api --component account-internal
245
+ nb specs repositories upsert --name nasebanal/nb-recorder-api --attachments on # applied only when it registers the repository
246
+ nb specs repositories update kMsl4TXEMmeN --attachments on # change it later (merged into --data)
247
+ ```
248
+
249
+ It is idempotent (the same provider, name and component always answer the same id, and nothing
250
+ set on a screen is overwritten: `--attachments` is applied only when the call registers the repository), so it is safe to repeat. Give the id to the pipeline as the repository
251
+ variable `NB_REPOSITORY_ID` (it is not a secret, and it is not a file in the repository: a copy of
252
+ a template would report into another repository); `nb specs specs push` reads it (or takes `--repository-id`) to tie
253
+ the spec it registers. Test results do not use it: they are reported to the **spec** (`NB_SPEC_ID`), see below.
154
254
 
155
- `nb specs push --file openapi.yaml` registers an OpenAPI document in the catalog (your own
156
- specs, Evolution): a new spec, or a new version of the one that has the same name (or `--id`).
255
+ ### Registering a spec (`nb specs specs push`)
256
+
257
+ `nb specs specs push --file openapi.yaml` registers an OpenAPI document in the catalog (your own
258
+ specs, Evolution): a new spec, or a new revision of the one that has the same name at the same API version (or `--id`).
157
259
  It is made to run on **every commit**:
158
260
 
261
+ - **A spec's key is its group, its repository row, its API version and its name** (a name is unique within a group, a
262
+ repository row, `repository + component`, and an API version; the ones with no group or no repository are unique among
263
+ themselves). So the name is looked up **inside the group you name** with `--group`, **inside the
264
+ repository you name** with `--repository [--component]` and **at the API version of the document** (its `info.version`,
265
+ or `--api-version`; see "API versions" above): another group's, repository's or API version's spec of that
266
+ name is not touched (a document of another major makes the new spec), and a spec with no repository is not adopted by name
267
+ (use `--id` to tie one).
268
+ **A group left out means "no group", not any group**: a name that exists only in groups is an error that
269
+ lists them and asks for `--group` (or `--id`), instead of silently making a second spec. With no
270
+ repository named, the spec that has none wins; a name held by exactly one spec is used; a name held by
271
+ several specs under repositories is refused, listing them.
272
+ - **`--server-url <url>`** replaces the document's top-level `servers` with `[{ url }]` before sending: one file
273
+ in the repository, one URL per environment. A JSON file is edited as JSON; a YAML file as **text** (comments and
274
+ order kept) when the edit is proven safe (the document without `servers` must be identical), otherwise it is
275
+ written again (the CLI says so: comments are not kept in what is pushed; the file on disk is never changed).
276
+ The hash used for "unchanged" is of the text that is sent, so the same file to the same environment is
277
+ unchanged on the next run; `--dry-run` shows `server_url`.
278
+
159
279
  - **A retitled document needs `--id`.** Without it the spec is found by its name (the document's
160
280
  `info.title`), so a new title registers a second spec next to the old one. `--id <id>` pushes to
161
281
  the spec you mean (a pipeline can read the id from `spec_id` of an earlier run), and adding
@@ -163,54 +283,123 @@ It is made to run on **every commit**:
163
283
  printed (`renamed_from` in the JSON). A rename happens only on request, so a name set by hand in
164
284
  the catalog is not overwritten on every push, and `--rename` without `--id` is refused.
165
285
 
166
- - **Nothing is uploaded when the file is already the latest version.** The CLI compares the
167
- document's SHA-256 with the `content_hash` the catalog keeps for the latest version before it
168
- sends anything; the same bytes print `unchanged (already vN: nothing uploaded)`. (The catalog
286
+ - **Nothing is uploaded when the file is already the latest revision.** The CLI compares the
287
+ document's SHA-256 with the `content_hash` the catalog keeps for the latest revision before it
288
+ sends anything; the same bytes print `unchanged (already rev N of vM: nothing uploaded)`. (The catalog
169
289
  refuses an identical upload itself, `409 UNCHANGED`, which is also taken as "unchanged", for two
170
290
  jobs racing.) The comparison is of bytes: a generator that writes a timestamp into the
171
- document makes a new version every run, so keep the output stable.
291
+ document makes a new revision every run, so keep the output stable.
172
292
  - **No group has to exist.** A spec is registered in no group unless `--group <name>` is given
173
- (the group is made when missing); an existing spec is never moved by a push (the catalog
174
- moves it, by drag and drop or the select on its page).
175
- - The name is `--name`, else the document's `info.title`, else the file's name. A new version
293
+ (the group is made when missing, on the first run); an existing spec is never moved by a push (the
294
+ catalog moves it, by drag and drop or the select on its page).
295
+ - The name is `--name`, else the document's `info.title`, else the file's name. A new revision
176
296
  carries a note made from the commit, the branch and the CI run (`--note` replaces it), so
177
- "which commit made v7" has an answer.
297
+ "which commit made revision 7" has an answer.
298
+ - **`--api-version <v>`** names the API version when the document's `info.version` gives none (and always wins over it); a bad
299
+ label is refused before the catalog is read. The result prints `api_version`.
178
300
  - `--org <id|personal>` (or `$NB_SPECS_ORG`) says whose catalog it is: the catalog is per
179
301
  owner and needs `X-Active-Organization-Id`; `personal` (the default) is your own, an
180
302
  organization's needs its Enterprise plan. `--dry-run` reads the catalog and says what would
181
303
  happen. `NB_SPECS_BASE_URL` points it at another host (local: `http://localhost:8792`).
182
- - In GitHub Actions the spec's id is written to `$GITHUB_OUTPUT` as `spec_id`.
304
+ - **A repository is optional.** `--repository-id <id>` (default `$NB_REPOSITORY_ID`) ties the spec
305
+ to that repository: a new spec is created tied to it, an existing spec that has none is tied to
306
+ it. `--repository <owner/name>` (+ `--provider`, default `github`, and the optional `--component`)
307
+ registers the repository first, idempotently, and uses the id it returns, for a pipeline that would rather not keep an
308
+ id. **A push never moves a spec:** one that is tied to another repository stays there and the
309
+ command says so (`repository_kept` in the JSON). A spec uploaded by hand needs no repository.
310
+ - In GitHub Actions the spec's id is written to `$GITHUB_OUTPUT` as `spec_id`, and the repository's
311
+ as `repository_id`.
312
+
313
+ ### A spec's description document (`nb specs specs docs`)
314
+
315
+ One **Markdown file per spec** (up to 200 KiB, UTF-8), shown rendered in the catalog beside the API reference, like
316
+ a developer portal's overview page. It belongs to Spec Management; the catalog only shows it.
317
+
318
+ ```bash
319
+ nb specs specs docs push --file README.md --spec-id kMsl4TXEMmeN # added or replaced (201 / 200)
320
+ nb specs specs docs push --file docs/overview.md --spec "Account API" --group Staging --repository nasebanal/nb-account-api
321
+ nb specs specs docs pull --spec-id kMsl4TXEMmeN --out README.md # or to standard output
322
+ nb specs specs docs delete --spec-id kMsl4TXEMmeN # also when there is none
323
+ ```
324
+
325
+ The spec is named like everywhere else: `--spec-id` (default `$NB_SPEC_ID`), or `--spec <name>` with the optional
326
+ `--repository [--component]` and `--group`. For these verbs what is left out means none (a spec in no group, tied to no
327
+ repository), so a spec that is tied to a repository needs `--repository`. The catalog answers `413` over 200 KiB and `415`
328
+ for a body that is not Markdown; a missing file, an empty one and a binary one are refused before anything is sent. (This
329
+ group replaces the generated `docs` leaf, whose body would be JSON.)
330
+
331
+ ### A spec's public settings (`nb specs specs settings`)
332
+
333
+ ```bash
334
+ nb specs specs settings kMsl4TXEMmeN --public-badge on --report-access login
335
+ nb specs specs settings kMsl4TXEMmeN --rotate-quality-public-id # new badge / report links; the old ones stop
336
+ ```
337
+
338
+ One `PATCH /specs/{id}` with only the flags you pass (the same fields as the screen: `public_badge`,
339
+ `report_access` = `hidden` / `login` / `public`, `rotate_quality_public_id`); there is no API version rule any more (a spec has
340
+ one API version, so a result needs none); it prints the spec, including its `quality_public_id`. A spec starts
341
+ private. Attachments are the repository's, not the spec's (`nb specs repositories update <id> --attachments on`). (`nb specs specs update <id> --data '{...}'` does the same with a raw body.)
342
+
343
+ ### Which spec a result or a monitor is about
344
+
345
+ Test results and external monitoring belong to a **spec that has a repository** (they are reported
346
+ against that repository row). A command that needs one takes the spec by id, `--spec-id <id>`, or by
347
+ the names of its key, `--repository <name> [--component <name>] [--group <name>] [--api-version <v>] --spec <name>`
348
+ (`--provider`, default `github`; no `--component` = the repository as a whole; no `--group` = the specs in no group, not any;
349
+ **no `--api-version` is the one exception to "left out means none"**: it is the API version of the one spec the rest of the key
350
+ leaves, and when it leaves several the error lists their API versions and asks for `--api-version`);
351
+ it never creates a spec or a
352
+ repository (`--no-create` has no meaning for specs: register them with `nb specs`), and a spec that is tied to
353
+ no repository is refused. The shared resolution is `resolveSpec` in `src/specs/resolve.ts`.
354
+
355
+ **API quality assessment: screens and commands.** The three screens under *API quality assessment* in
356
+ Evolution work on one API's data (Assurance), each of its sub-menus is a command group of `nb assurance`, and
357
+ what they work on is a spec:
358
+
359
+ | Evolution screen | Command | What it does |
360
+ |---|---|---|
361
+ | Charts | `nb assurance specs quality <id>` (and `nb assurance specs list` / `get`) | the quality dashboard data of a spec |
362
+ | Test results | `nb assurance report upload` (to send), `nb assurance specs runs ...`, `nb assurance specs results ...` | register and read results |
363
+ | External monitoring | `nb assurance monitors ...` | the monitors of a spec |
364
+
365
+ ```bash
366
+ # A monitor is about a spec that has a repository: the spec by id or by names, put into the body as spec_id and repository_id
367
+ nb assurance monitors create --spec-id kMsl4TXEMmeN --data '{"url":"https://api.example.com/health","method":"GET","interval_minutes":5,"timeout_ms":10000}'
368
+ nb assurance monitors create --repository nasebanal/nb-account-api --spec "Account API" --data @monitor.json
369
+ nb assurance monitors update <monitor-id> --spec-id kMsl4TXEMmeN --data '{"enabled":true}' # moves it to that spec
370
+ ```
183
371
 
184
- ### Reading a version back (`nb specs pull`, `nb specs versions`)
372
+ ### Reading a revision back (`nb specs specs pull`, `nb specs specs versions list`)
185
373
 
186
374
  A pipeline can work from the catalog's document instead of a copy kept in a repository (a
187
375
  contract test with Specmatic against the API's provider side, a stub for a consumer, a client
188
376
  generator):
189
377
 
190
378
  ```bash
191
- nb specs versions --name "Billing API" # versions newest first, each with its sha256
192
- nb specs pull --name "Billing API" --spec-version 3 --out spec.yaml
193
- nb specs pull --id kMsl4TXEMmeN --spec-version 3 --hash <sha256> --out spec.yaml # pinned: fails if it differs
194
- nb specs pull --name "Billing API" > spec.yaml # latest; the document is all of stdout
379
+ nb specs specs versions list <id> # revisions newest first, each with its sha256
380
+ nb specs specs pull --name "Billing API" --group Production --repository nasebanal/billing --spec-version 3 --out spec.yaml
381
+ nb specs specs pull --id kMsl4TXEMmeN --spec-version 3 --hash <sha256> --out spec.yaml # pinned: fails if it differs
382
+ nb specs specs pull --name "Billing API" > spec.yaml # latest; the document is all of stdout
195
383
  ```
196
384
 
197
- - **`--spec-version` is the catalog's version number** (1, 2, 3...: one per `nb specs push` that
198
- changed the document). It is not the API's URL version (`v1`, `v2`, the label of a test result
199
- in `nb assurance report upload --api-version`), not the document's own `info.version`, and not
200
- the CLI's own `nb --version`.
385
+ - **`--spec-version` is the catalog's revision number** (1, 2, 3...: one per `nb specs specs push` that
386
+ changed the document). It is not the API version (`v1`, `v2`: a property of the spec), not the document's own
387
+ `info.version`, and not the CLI's own `nb --version`.
201
388
  Absent or `latest` is the newest; **pin a number in a pipeline**, `latest` moves.
202
389
  - **The document comes back exactly as it was uploaded** (the bytes: a JSON document is not
203
390
  parsed and re-printed), and its SHA-256 is checked against the `content_hash` the catalog keeps
204
- for that version, so a document that did not arrive intact fails. `--hash <sha256>` pins what
205
- the pipeline expects, so a version that was replaced, or a name that now points at another
206
- spec, fails instead of testing the wrong thing. `nb specs versions` prints the hashes.
207
- - A spec is named by `--id` (a rename cannot change it) or by `--name` (matched ignoring case).
391
+ for that revision, so a document that did not arrive intact fails. `--hash <sha256>` pins what
392
+ the pipeline expects, so a revision that was replaced, or a name that now points at another
393
+ spec, fails instead of testing the wrong thing. `nb specs specs versions list` prints the hashes.
394
+ - A spec is named by `--id` (a rename cannot change it) or by `--name` (matched ignoring case); with `--group` and
395
+ `--repository [--component]` and `--api-version` the name is looked up in that group, repository row and API version (its key), which is
396
+ how the same name in two environments (or at two API versions) is told apart.
208
397
  `--org <id|personal>` / `$NB_SPECS_ORG` and `NB_SPECS_BASE_URL` work as for `push`. With `--out`
209
398
  the details are printed as JSON; without it they go to stderr. In GitHub Actions `spec_id`,
210
399
  `spec_version` and `spec_hash` are written to `$GITHUB_OUTPUT`.
211
400
  - The catalog has no "released" mark yet: unlike the `@nasebanal/api-specs-*` packages, which
212
401
  only advance once the provider has deployed, a pull of `latest` can return a version that
213
- nothing implements. Pinning a version (and its hash) is the safe way to use it today.
402
+ nothing implements. Pinning a revision (and its hash) is the safe way to use it today.
214
403
 
215
404
  ## Installation
216
405
 
package/dist/apis.js CHANGED
@@ -2,5 +2,6 @@ export const API_CATALOG = [
2
2
  { name: "account", spec: "account.yaml", summary: "User profiles, subscriptions, billing, and API tokens" },
3
3
  { name: "record", spec: "recorder.yaml", summary: "Records and tags (NASEBANAL Recorder)" },
4
4
  { name: "target", spec: "target.yaml", summary: "Targets, cells, and shares (NASEBANAL Target)" },
5
- { name: "assurance", spec: "assurance.yaml", summary: "Monitors, projects and CI/CD test results (NASEBANAL Assurance)" },
5
+ { name: "assurance", spec: "assurance.yaml", summary: "Monitors and CI/CD test results of your specs (NASEBANAL Assurance, API quality assessment)" },
6
+ { name: "specs", spec: "specs.yaml", summary: "Repositories and your own OpenAPI documents: the API catalog (NASEBANAL Evolution)" },
6
7
  ];
package/dist/index.js CHANGED
@@ -14,7 +14,8 @@ import { buildAuthCommand } from "./auth.js";
14
14
  import { specExists } from "./spec/loader.js";
15
15
  import { printError } from "./output.js";
16
16
  import { buildReportUploadCommand } from "./reports/upload.js";
17
- import { buildSpecsCommand } from "./specs/command.js";
17
+ import { attachMonitorSpecOptions } from "./reports/monitors.js";
18
+ import { attachSpecsCommands, buildSpecsCommand } from "./specs/command.js";
18
19
  import { buildUpgradeCommand, startUpdateNotifier } from "./update.js";
19
20
  // Single source of truth for the version: package.json (dist/ and src/ both sit
20
21
  // next to it). A hard-coded string here drifts from the release tag.
@@ -29,9 +30,13 @@ program
29
30
  .showHelpAfterError();
30
31
  program.addCommand(buildAuthCommand());
31
32
  program.addCommand(buildUpgradeCommand(version));
32
- program.addCommand(buildSpecsCommand());
33
33
  for (const api of API_CATALOG) {
34
34
  if (!specExists(api.spec)) {
35
+ // `nb specs push` / `pull` need no contract to run: without one the old standalone group still works.
36
+ if (api.name === "specs") {
37
+ program.addCommand(buildSpecsCommand());
38
+ continue;
39
+ }
35
40
  // Spec not synced yet — register a stub that explains how to fix it rather
36
41
  // than crashing the whole CLI.
37
42
  program
@@ -46,11 +51,15 @@ for (const api of API_CATALOG) {
46
51
  }
47
52
  const group = buildApiCommand(api);
48
53
  // `assurance report` already holds the generated availability report; the
49
- // hand-written `upload` (test-result files -> a project) joins it.
54
+ // hand-written `upload` (test-result files -> a spec) joins it.
50
55
  if (api.name === "assurance") {
51
56
  const report = group.commands.find((c) => c.name() === "report") ?? group.command("report").description("Reports");
52
57
  report.addCommand(buildReportUploadCommand());
58
+ attachMonitorSpecOptions(group);
53
59
  }
60
+ // `nb specs`: the generated tree plus the pipeline verbs (`specs push`, `repositories upsert`) and the old direct form.
61
+ if (api.name === "specs")
62
+ attachSpecsCommands(group);
54
63
  program.addCommand(group);
55
64
  }
56
65
  async function main() {
@@ -0,0 +1,57 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { resolveAccessToken, resolveEnv } from "../config.js";
3
+ import { checkOrg, specsBaseUrl } from "../specs/push.js";
4
+ import { resolveSpec } from "../specs/resolve.js";
5
+ import { specRefOf } from "./upload.js";
6
+ function readBody(data) {
7
+ if (data === undefined)
8
+ return {};
9
+ const raw = data.startsWith("@") ? readFileSync(data.slice(1), "utf8") : data;
10
+ let parsed;
11
+ try {
12
+ parsed = JSON.parse(raw);
13
+ }
14
+ catch {
15
+ throw new Error(`--data must be valid JSON (or @file containing JSON); got: ${data}`);
16
+ }
17
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
18
+ throw new Error("--data must be a JSON object");
19
+ return parsed;
20
+ }
21
+ const NAMES = ["specId", "repository", "component", "group", "apiVersion", "spec", "repositoryProvider"];
22
+ /** Add the spec options to one generated leaf (`create` or `update`) and resolve them just before it runs. */
23
+ function attach(leaf, required) {
24
+ leaf
25
+ .option("--spec-id <id>", `the spec this monitor is about, by its id in the catalog${required ? " (default: $NB_SPEC_ID)" : ""}: sets spec_id and repository_id. Exclusive with --repository / --component / --spec`)
26
+ .option("--repository <owner/name>", "by names: the repository the spec is tied to; needs --spec (--component optional: none = the repository as a whole)")
27
+ .option("--component <name>", "by names: the component part of the repository's key; optional")
28
+ .option("--group <name>", "by names: the group the spec is filed in (an environment, say); optional, none = the specs in no group (not any group)")
29
+ .option("--api-version <v>", "by names: the API version (v1, v2) of the spec, part of its key; left out = the API version of the one spec the rest of the key matches (several: the error lists them)")
30
+ .option("--spec <name>", "by names: the spec's name in the catalog; needs --repository")
31
+ .option("--repository-provider <provider>", "with --repository: github | gitlab | bitbucket | other (default: github)");
32
+ leaf.hook("preAction", async (thisCommand) => {
33
+ const opts = thisCommand.optsWithGlobals();
34
+ const asked = NAMES.some((n) => opts[n] !== undefined);
35
+ const body = readBody(opts.data);
36
+ // `create` must say which spec; `update` only when it moves the monitor (or the body already carries both ids).
37
+ if (!asked && !required)
38
+ return;
39
+ if (!asked && body.spec_id !== undefined && body.repository_id !== undefined)
40
+ return;
41
+ const ref = specRefOf(opts);
42
+ const env = opts.env || resolveEnv();
43
+ const hit = await resolveSpec({ baseUrl: specsBaseUrl(env), token: opts.token || (await resolveAccessToken()), org: checkOrg(opts.org ?? process.env.NB_ASSURANCE_ORG ?? process.env.NB_SPECS_ORG) }, ref);
44
+ thisCommand.setOptionValue("data", JSON.stringify({ ...body, spec_id: hit.spec_id, repository_id: hit.repository_id }));
45
+ });
46
+ }
47
+ /** Called once on the generated `assurance` group. */
48
+ export function attachMonitorSpecOptions(assurance) {
49
+ const monitors = assurance.commands.find((c) => c.name() === "monitors");
50
+ if (!monitors)
51
+ return;
52
+ for (const [verb, required] of [["create", true], ["update", false]]) {
53
+ const leaf = monitors.commands.find((c) => c.name() === verb);
54
+ if (leaf)
55
+ attach(leaf, required);
56
+ }
57
+ }