@wasit-dev/cli 0.7.0 → 0.8.0-beta.2

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
@@ -6,7 +6,9 @@ Protocol-compliance testing for **x402** and **MPP** on Stellar, from your termi
6
6
 
7
7
  For both MPP charge payments and x402 payments it verifies the settlement independently — via Stellar RPC and the token contract's own on-chain transfer event, rather than the response the service returns.
8
8
 
9
- **Testnet only.** Several checks settle real transactions — do not point this at pubnet or use production keys.
9
+ **Testnet by default.** Several checks settle real transactions. The payment checks pay on test networks only: any other network, `stellar:pubnet` included, is refused before a key is read, but for `wasit run --mainnet` (beta, below). Do not use production keys: the mainnet opt-in takes a dedicated account only.
10
+
11
+ **This README describes 0.8.0-beta.2**, a pre-release on npm under the `beta` tag (`npm install -g @wasit-dev/cli@beta`). `latest` is still 0.7.0. New in 0.8.0-beta.2: `wasit init`, which writes the config from one unpaid request to your route and can set up a testnet payer; MPP charge and channel checks in `wasit run`; the capped mainnet opt-in, `wasit run --mainnet` (beta, x402 only); and "resource consumed", the result for a single-use route. New in 0.8.0-beta.1: `wasit run` for a whole service from a `wasit.config.json`, `wasit ci-report`, the GitHub Action, a seventeenth check (`X402-11`), and a cap on every payment Wasit signs.
10
12
 
11
13
  ## Install
12
14
 
@@ -37,6 +39,13 @@ wasit test --target https://your-service.example.com/paid --read-only
37
39
 
38
40
  That runs the read-only x402 checks (`X402-01`–`05`): whether the service issues a well-formed 402 challenge. Drop `--read-only` and set `STELLAR_PRIVATE_KEY` to also exercise the payment flow — `X402-06` settles a real testnet payment, and `X402-07`–`10` send payments the service must refuse.
39
41
 
42
+ For a whole service you operate, let Wasit write the config from one unpaid request to a route, then run the free checks:
43
+
44
+ ```bash
45
+ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me # your service is running; init reads its 402
46
+ wasit run --read-only # what init prints as the next command for x402
47
+ ```
48
+
40
49
  ## Commands
41
50
 
42
51
  ### `wasit test` — x402
@@ -48,15 +57,15 @@ wasit test --target <url> [options]
48
57
  | Option | Default | Notes |
49
58
  |---|---|---|
50
59
  | `--target <url>` | required | Must include the scheme |
51
- | `--network <id>` | `stellar:testnet` | Network the payment checks pay on (`stellar:testnet`, `stellar:pubnet`, `eip155:84532` for Base Sepolia, `eip155:11155111` for Ethereum Sepolia, or `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` for Solana devnet); `X402-01`–`05` apply on any chain |
60
+ | `--network <id>` | `stellar:testnet` | Network the payment checks pay on: `stellar:testnet`, `eip155:84532` (Base Sepolia), `eip155:11155111` (Ethereum Sepolia) or `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (Solana devnet). Any other network is refused before a key is read. `X402-01`–`05` apply on any chain |
52
61
  | `--payer-key <key>` | `STELLAR_PRIVATE_KEY`, `EVM_PRIVATE_KEY` on Base or Ethereum Sepolia, or `SVM_PRIVATE_KEY` on Solana devnet | A Stellar secret (`S...`), an EVM private key (`0x` + 64 hex), or a Solana keypair (base58 of its 64 bytes) |
53
- | `--rpc-url <url>` | testnet default | Soroban RPC used to verify `X402-06`'s settlement |
62
+ | `--rpc-url <url>` | testnet default | Soroban RPC the payment is built through and `X402-06`'s settlement is read from; https only |
54
63
  | `--method <verb>` | `GET` | HTTP method the paid endpoint uses |
55
64
  | `--body <json>` | — | Request body; implies `Content-Type: application/json` |
56
65
  | `--header <name:value>` | — | Extra request header, repeatable |
57
66
  | `--read-only` | off | Restricts the run to `X402-01`–`05` (no payment) |
58
67
 
59
- Without a payer key, the payment checks are skipped automatically. When they run: **`X402-06` settles a real payment, `X402-07` attempts one with a corrupted signature** — testnet funds move on every call.
68
+ Without a payer key, the payment checks are skipped automatically. When they run: **`X402-06` settles a real payment, `X402-07` attempts one with a corrupted signature**, so testnet funds move on every call. A price above $1.00 is not paid: `X402-06` gets no verdict (`ERROR (setup)`) and nothing is signed. `X402-11` needs a request the service must refuse, which only `wasit run` reads from the config, so `wasit test` skips it.
60
69
 
61
70
  ### `wasit mpp-charge` — MPP, charge mode
62
71
 
@@ -68,10 +77,10 @@ wasit mpp-charge --target <url> [options]
68
77
  |---|---|---|
69
78
  | `--target <url>` | required | The paid resource |
70
79
  | `--payer-key <key>` | `MPP_PAYER_SECRET` | Secret key, `S...` |
71
- | `--network <id>` | `MPP_STELLAR_NETWORK` | CAIP-2. Only a challenge on this network is paid |
72
- | `--rpc-url <url>` | testnet default | Used for the payment and the settlement read; https only. Required for pubnet |
80
+ | `--network <id>` | `MPP_STELLAR_NETWORK` | CAIP-2. Only a challenge on this network is paid; `stellar:testnet` only, any other network is refused |
81
+ | `--rpc-url <url>` | testnet default | Used for the payment and the settlement read; https only |
73
82
 
74
- **Every run settles a real payment.** Charge mode has no dry run — a settlement that never happened cannot be verified on-chain.
83
+ **Every run settles a real payment.** A settlement that never happened cannot be verified on-chain, so this command has no dry run. To see what a payment would be before anything is signed, use `wasit run --dry-run` (below): it prints the plan of an MPP charge endpoint from its unpaid challenge and signs nothing.
75
84
 
76
85
  ### `wasit mpp-channel` — MPP, channel mode
77
86
 
@@ -97,6 +106,47 @@ wasit mpp-channel --target <url> [options]
97
106
 
98
107
  `--channel` **asserts**, it does not select: the channel under test is resolved from the target's own 402 challenge, so every check in a run reports on the same contract. When `--channel` differs from what the target advertises, `MPP-10` fails and inspects nothing.
99
108
 
109
+ ### `wasit init`: write the config for one route (new in 0.8.0-beta.2)
110
+
111
+ ```bash
112
+ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
113
+ wasit init --url http://127.0.0.1:3000/api/chat --method POST --body-file body.json --operated-by-me --start "npm start"
114
+ wasit init --url http://127.0.0.1:3000/mpp/chat --operated-by-me --protocol mpp-charge
115
+ wasit init # at a terminal: asks for what you leave out
116
+ ```
117
+
118
+ Writes a `wasit.config.json` for one paid route of a service you operate. It sends the route one unpaid request (the method and body you give, and the `WASIT_HEADER_*` headers `wasit run` sends), follows at most one redirect inside the route's origin, and pays and signs nothing. The 402 tells x402 from MPP and gives the protocol, the network, the receiving address and asset (pinned), and for an MPP channel its contract. A route that answers 200, 500 or 503, or does not answer, writes nothing; `--no-read` writes the route from the flags alone, as x402.
119
+
120
+ Nothing is written without `--operated-by-me` (at a terminal, `init` asks): Wasit tests only services their operator runs. At a terminal `init` asks only for what the flags leave out; without one it asks nothing and names the missing flags (exit 2). An existing config is added to, never overwritten (`--force` replaces it), and a route it already has exactly as given is left as it is, so `init` can run again. It writes test networks only, never a header of the route (send a credential in a `WASIT_HEADER_<NAME>` variable), and never a key or a `WASIT_HEADER_*` value. A URL whose query has a parameter named like a credential (`api_key`, `token`, `sig`), given with `--url` or reached by the redirect, is refused, and nothing is written. After writing it prints what it read from your service, what you gave, what it filled in by default and what it did not read, then the next command: `wasit run --read-only` for x402, `wasit run --dry-run` for MPP, which has no read-only checks. Exit codes: `0` the config has the route (written now, or already there as given); `2` `init` refused and nothing was written.
121
+
122
+ **Key setup (Stellar testnet only)**, with `--setup-keys` or a yes at a terminal, after the config is written. First `init` checks that git will not commit `.env`: it must not be tracked and must be ignored, else `.env` is added to `.gitignore` (asked at a terminal) or no key is written. A key that is already set is kept and its account only read. Otherwise `init` makes a testnet key (`STELLAR_PRIVATE_KEY` for x402, `MPP_PAYER_SECRET` for MPP charge), appends it to `.env` without showing the secret, funds it with Friendbot, adds the USDC trustline and swaps 10 test XLM for test USDC on the public test exchange, then prints a status table; what it could not finish is in the table with the command that finishes it. An MPP channel gets no key: `COMMITMENT_SECRET_HEX` must be the key the channel was opened with. A variable set to nothing in your shell hides `.env` from `wasit run`, so `init` says so and writes no key. The key setup never changes the exit code.
123
+
124
+ ### `wasit run`: a whole service from `wasit.config.json` (new in 0.8.0-beta.1)
125
+
126
+ ```bash
127
+ wasit run --read-only --start # the free checks, X402-01 to 05, with the service started from the config
128
+ wasit run --dry-run --start # what the payment checks would sign; no key, nothing sent
129
+ wasit run --start # the payment tier, on a test network
130
+ ```
131
+
132
+ `wasit.config.json` (version 1) holds a service's endpoints, methods, request bodies and environments. The loader is strict: an unknown key is an error, and secrets, the mainnet opt-in and per-payment caps have no place in it. `wasit run` runs every endpoint (`--env`, `--endpoint`) and writes one report (`--json`, `--out`); it can start the service itself (`--start`, `--start-if-local`) and compare with the report of the default branch (`--baseline`).
133
+
134
+ Without `--read-only` or `--dry-run` the run is the payment tier. It pays on test networks only, when the environment has `operatedByMe: true` and the chain's key variable is set: at most $1.00 a payment and $5.00 a run (`maxRunUsd` can only lower it), only to the `payTo` and asset the config pins. In GitHub Actions it pays only on a push to the default branch, a schedule and `workflow_dispatch`; a pull request runs the read-only checks. In another CI the payment tier is refused with exit 2: use `--read-only` there. On `stellar:pubnet` a paying run needs `--mainnet` (beta, x402 only, real USDC): it runs only when every rule of the mainnet opt-in holds, says `MAINNET RUN` in its first line, writes every signature to a run ledger before the key signs, and refuses a payer that holds less than the run needs to finish its checks (it says how much is missing), and ends by comparing the payer's balances with that ledger (consistent, explained by checks that FAILed, or inconsistent: exit 2); it does not read `.env`, so export `WASIT_MAINNET_PAYER_SECRET` in the shell; `wasit run --help` lists the rules. `wasit run --dry-run` on `stellar:pubnet` reads no key. A run that will pay checks its RPC before it starts the service, so an RPC that `service.start` itself starts is not up yet and the run stops with exit 2: start such an RPC before `wasit run`. `wasit run --help` lists every option.
135
+
136
+ For an endpoint with a `reject` case in the config, on Stellar, the payment tier also runs `X402-11`: a valid payment is sent with the request the service must refuse, and the chain is read until that payment's authorization has expired, up to six minutes.
137
+
138
+ **MPP in `wasit run` (new in 0.8.0-beta.2).** MPP endpoints run in the payment tier on `stellar:testnet` only, by the same rules as x402: `MPP-01` (charge) with `MPP_PAYER_SECRET`, planned from its unpaid challenge and held to the same caps, in the same budget as x402, and `MPP-10`, `11`, `12` and `14` (channel) with `COMMITMENT_SECRET_HEX`, with the channel and its expected terms from the config. With a channel in the config, commitments are signed for that channel only, and a route whose challenge names another gets none. The channel checks sign commitments off-chain and Wasit sends no transaction for them, so they are not charged to the cap. `MPP-13`, which closes a channel for good, is never run by `wasit run`. The network and the channel come from the config: `MPP_STELLAR_NETWORK` and `CHANNEL_CONTRACT` are not read. An MPP endpoint is sent a plain GET: one with a method, a body or headers is not sent anything. A mainnet run pays its x402 endpoints only.
139
+
140
+ **Single-use routes (new in 0.8.0-beta.2).** A route that can be bought once answers 409 where a new 402 was expected, after `X402-06`'s payment was served. `X402-07`, `09`, `10` and `11` need a new challenge to pay, so they are skipped as "resource consumed" (nothing is signed for them, and the route is not asked again); `X402-08`, the replay, needs none and still runs. A 409 before any payment of the run skips `X402-06` with that reason.
141
+
142
+ ### `wasit ci-report`: the pull request comment and the job summary (new in 0.8.0-beta.1)
143
+
144
+ ```bash
145
+ wasit ci-report --report wasit-report.json --comment comment.md
146
+ ```
147
+
148
+ Turns the report of `wasit run --json --out` into the pull request comment and the job summary, compared with the default branch's report (`--baseline`). `--check-run <file>` also writes the title, summary and conclusion of a GitHub check run. The Action also uses `--summary <file>` (the job summary; default `$GITHUB_STEP_SUMMARY`), `--baseline-out <file>` (the next baseline, for a run on the default branch), `--history <file>` (the newest completed run's baseline, for the recent-failures line) and `--baseline-run <id>`; `wasit ci-report --help` lists them. The GitHub Action in the repository's `action/` directory runs `wasit run` and `wasit ci-report` in a workflow and comments on the pull request; pin it by full commit SHA.
149
+
100
150
  ### `wasit checks` — the catalogue
101
151
 
102
152
  ```bash
@@ -117,7 +167,7 @@ Testnet-only helpers for the keys the subcommands above read from `.env`. `--net
117
167
 
118
168
  `fund --asset usdc` opens the Circle testnet USDC trustline automatically, but **receiving a balance always needs one human step**: there is no scriptable USDC faucet for Stellar. Visit [faucet.circle.com](https://faucet.circle.com) once, or set `WASIT_USDC_DISTRIBUTOR_SECRET` to an account you funded that way and every later run sends from it automatically.
119
169
 
120
- `create` prints a secret key to stdout — don't run it on a screen you're recording.
170
+ `create` prints a secret key to stdout — don't run it on a screen you're recording. `wasit init --setup-keys` needs none of this for a Stellar testnet route: it makes the key, writes it to `.env` without showing it and gets test USDC by a swap on the public test exchange (see `wasit init`).
121
171
 
122
172
  ### `wasit serve` — a paywall that misbehaves, for testing an agent that pays
123
173
 
@@ -154,6 +204,8 @@ SKIP X402-02 Payment Header Present
154
204
  7 passed.
155
205
  ```
156
206
 
207
+ At a terminal, `wasit test` shows the checks live and in colour, in two blocks (challenge and payment). A pipe, CI, `--json` and `NO_COLOR` get the plain text above.
208
+
157
209
  `PREFLIGHT` appears in place of the checks when the target URL or network identifier itself is invalid — both are wrong for every check in the suite, so it's reported once rather than repeated identically.
158
210
 
159
211
  ## Exit codes
@@ -170,21 +222,22 @@ A run with both a failure and an error exits `1` — a real finding outranks a m
170
222
 
171
223
  | Env var | Used by |
172
224
  |---|---|
173
- | `STELLAR_PRIVATE_KEY` | `test` (x402 payment checks on Stellar) |
225
+ | `STELLAR_PRIVATE_KEY` | `test`, `run` (x402 payment checks on Stellar), `init --setup-keys` |
174
226
  | `EVM_PRIVATE_KEY` | `test --network eip155:84532` or `eip155:11155111` (x402 payment checks on Base or Ethereum Sepolia) |
175
227
  | `SVM_PRIVATE_KEY` | `test --network solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (x402 payment checks on Solana devnet) |
176
- | `MPP_PAYER_SECRET` | `mpp-charge` |
228
+ | `MPP_PAYER_SECRET` | `mpp-charge`, `run` (MPP charge), `init --setup-keys` |
177
229
  | `MPP_STELLAR_NETWORK` | `mpp-charge`, `mpp-channel` |
178
- | `COMMITMENT_SECRET_HEX` | `mpp-channel` |
230
+ | `COMMITMENT_SECRET_HEX` | `mpp-channel`, `run` (MPP channel) |
179
231
  | `CHANNEL_CONTRACT` | `mpp-channel` (optional assertion) |
180
232
  | `CHANNEL_CONTRACT_DISPOSABLE` | `mpp-channel --allow-destructive` |
181
233
  | `WASIT_USDC_DISTRIBUTOR_SECRET` | `wallet fund --asset usdc` (optional) |
234
+ | `WASIT_MAINNET_PAYER_SECRET` | `run --mainnet` only (beta): a dedicated account's secret, exported in the shell, never in `.env` |
182
235
 
183
- All keys are **testnet only**. `wasit` also reads a `.env` file in the current working directory — pass `--payer-key` / `--commitment-key` directly to override it for a single run.
236
+ All keys are **testnet only**, except `WASIT_MAINNET_PAYER_SECRET`, which `wasit run --mainnet` reads from the shell alone (a dedicated account; see `wasit run`). `wasit` also reads a `.env` file in the current working directory — pass `--payer-key` / `--commitment-key` directly to override it for a single run. `wasit run` does not read `.env` in CI, nor with `--mainnet`.
184
237
 
185
238
  ## What's checked
186
239
 
187
- Thirteen checks across x402 and MPP, each traced to a written spec clause — the full catalogue, with pass criteria and spec references, is in [`docs/CHECKS.md`](https://github.com/wasit-dev/wasit/blob/main/docs/CHECKS.md).
240
+ Seventeen checks across x402 and MPP (`X402-11` is new in 0.8.0-beta.1), each traced to a written spec clause — the full catalogue, with pass criteria and spec references, is in [`docs/CHECKS.md`](https://github.com/wasit-dev/wasit/blob/main/docs/CHECKS.md).
188
241
 
189
242
  ## Related
190
243
 
@@ -0,0 +1,40 @@
1
+ /**
2
+ * `wasit ci-report`: the run report (and the baseline of the default branch, if
3
+ * there is one) in; `comment.md`, the job summary and, when asked, the next
4
+ * baseline out (spec A4, A5).
5
+ *
6
+ * It is a pure function over files. It decides nothing about the job: the job's
7
+ * result is the exit code of `wasit run`. When the run left no usable report (the
8
+ * service never started, never answered, or the config was unusable) it still
9
+ * writes a fixed "no verdict" comment and summary, so the comment of the push
10
+ * before does not stay next to a red check, and it writes no baseline. It exits 2
11
+ * when the report is there but unusable, or when it cannot write what it was asked.
12
+ */
13
+ export interface CiReportOptions {
14
+ /** The `wasit run --json --out` file. */
15
+ readonly report: string;
16
+ /** The baseline file of the default branch: absent or unusable, the comment says so. */
17
+ readonly baseline?: string;
18
+ /** Where the pull request comment goes. */
19
+ readonly comment: string;
20
+ /** The job summary file, appended to. Default: `$GITHUB_STEP_SUMMARY`, if set. */
21
+ readonly summary?: string;
22
+ /** Where the next baseline goes: the report with its history. The caller uploads it on a run on the default branch. */
23
+ readonly baselineOut?: string;
24
+ /**
25
+ * The baseline file of the newest completed run on the default branch, failed
26
+ * or not (D-022b): its history is the one the recent-failures line counts and
27
+ * the next baseline carries on. Absent or unusable: the baseline's own.
28
+ */
29
+ readonly history?: string;
30
+ /** The id of the run the baseline came from, named in the comment. Only a whole number above 0 is used. */
31
+ readonly baselineRun?: string;
32
+ /** Where the check run's title, summary and conclusion go, as JSON, for the step that completes it. */
33
+ readonly checkRun?: string;
34
+ }
35
+ export interface CiReportContext {
36
+ readonly env: Readonly<Record<string, string | undefined>>;
37
+ readonly stdout: (line: string) => void;
38
+ readonly stderr: (line: string) => void;
39
+ }
40
+ export declare function executeCiReport(options: CiReportOptions, context: CiReportContext): Promise<number>;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * `wasit ci-report`: the run report (and the baseline of the default branch, if
3
+ * there is one) in; `comment.md`, the job summary and, when asked, the next
4
+ * baseline out (spec A4, A5).
5
+ *
6
+ * It is a pure function over files. It decides nothing about the job: the job's
7
+ * result is the exit code of `wasit run`. When the run left no usable report (the
8
+ * service never started, never answered, or the config was unusable) it still
9
+ * writes a fixed "no verdict" comment and summary, so the comment of the push
10
+ * before does not stay next to a red check, and it writes no baseline. It exits 2
11
+ * when the report is there but unusable, or when it cannot write what it was asked.
12
+ */
13
+ import { appendFileSync, readFileSync, statSync, writeFileSync } from "node:fs";
14
+ import { MAX_BASELINE_BYTES, ReportFormatError, baselineProblem, deniedEnvValues, parseRunReport, readBaseline, readBuildCommit, readToolVersions, renderCheckRun, renderComment, renderNoReportCheckRun, renderNoReportComment, renderNoReportSummary, renderSummary, sanitizeText, selectBaseline, serializeBaseline, updateHistory, } from "@wasit-dev/core";
15
+ import { CLI_VERSION } from "./version.js";
16
+ function readFileText(path, max) {
17
+ if (statSync(path).size > max)
18
+ throw Object.assign(new Error("too large"), { code: "E2BIG" });
19
+ return readFileSync(path, "utf-8");
20
+ }
21
+ function readBaselineFile(path) {
22
+ try {
23
+ return readBaseline(readFileText(path, MAX_BASELINE_BYTES));
24
+ }
25
+ catch (error) {
26
+ const code = error.code;
27
+ return { ok: false, reason: `the baseline file cannot be read${typeof code === "string" ? ` (${code})` : ""}` };
28
+ }
29
+ }
30
+ export async function executeCiReport(options, context) {
31
+ const secrets = deniedEnvValues(context.env);
32
+ const fail = (message) => {
33
+ context.stderr(sanitizeText(message, { redact: secrets }));
34
+ return 2;
35
+ };
36
+ /** The run left nothing to render: say so in the comment and the summary, and write no baseline. */
37
+ const writeNoReport = (message, code) => {
38
+ context.stderr(sanitizeText(message, { redact: secrets }));
39
+ try {
40
+ const versions = readToolVersions(CLI_VERSION, readBuildCommit(context.env));
41
+ writeFileSync(options.comment, renderNoReportComment(versions));
42
+ context.stdout(`Wrote ${options.comment}`);
43
+ const summary = options.summary ?? context.env["GITHUB_STEP_SUMMARY"];
44
+ if (summary !== undefined && summary !== "") {
45
+ appendFileSync(summary, renderNoReportSummary(versions));
46
+ context.stdout(`Appended the summary to ${summary}`);
47
+ }
48
+ if (options.checkRun !== undefined) {
49
+ writeFileSync(options.checkRun, JSON.stringify(renderNoReportCheckRun(versions)));
50
+ context.stdout(`Wrote ${options.checkRun}`);
51
+ }
52
+ }
53
+ catch (error) {
54
+ const errno = error.code;
55
+ return fail(`wasit ci-report: cannot write a file${typeof errno === "string" ? ` (${errno})` : ""}`);
56
+ }
57
+ return code;
58
+ };
59
+ let report;
60
+ try {
61
+ report = parseRunReport(JSON.parse(readFileText(options.report, MAX_BASELINE_BYTES)));
62
+ }
63
+ catch (error) {
64
+ // Nothing from the file is quoted: it is data, and it may be broken or hostile.
65
+ if (error instanceof ReportFormatError)
66
+ return writeNoReport("wasit ci-report: the report is not a Wasit report", 2);
67
+ if (error instanceof SyntaxError)
68
+ return writeNoReport("wasit ci-report: the report is not valid JSON", 2);
69
+ const code = error.code;
70
+ if (code === "ENOENT") {
71
+ return writeNoReport("wasit ci-report: wasit run wrote no report, so the comment says no verdict (the reason is in the log of the run step)", 0);
72
+ }
73
+ return writeNoReport(`wasit ci-report: cannot read the report${typeof code === "string" ? ` (${code})` : ""}`, 2);
74
+ }
75
+ const selected = selectBaseline(report, options.baseline === undefined ? undefined : readBaselineFile(options.baseline));
76
+ // D-022b: the history of every completed run on main, when the newest one is given.
77
+ let history = selected.baseline?.history;
78
+ let historyGiven = false;
79
+ if (options.history !== undefined) {
80
+ const read = readBaselineFile(options.history);
81
+ const problem = read.ok ? baselineProblem(report, read.baseline.report) : read.reason;
82
+ if (read.ok && problem === undefined) {
83
+ history = read.baseline.history;
84
+ historyGiven = true;
85
+ }
86
+ else {
87
+ context.stderr(sanitizeText(`wasit ci-report: the history file is not used (${problem ?? "unknown"}); the history of the baseline is used`, {
88
+ redact: secrets,
89
+ }));
90
+ }
91
+ }
92
+ const run = options.baselineRun !== undefined && /^[1-9][0-9]{0,15}$/.test(options.baselineRun) ? Number(options.baselineRun) : undefined;
93
+ const input = {
94
+ report,
95
+ ...(selected.baseline === undefined ? {} : { baseline: selected.baseline }),
96
+ ...(selected.note === undefined ? {} : { baselineNote: selected.note }),
97
+ ...(run === undefined || !Number.isSafeInteger(run) ? {} : { baselineRun: run }),
98
+ ...(historyGiven && history !== undefined ? { history } : {}),
99
+ secrets,
100
+ };
101
+ try {
102
+ writeFileSync(options.comment, renderComment(input));
103
+ context.stdout(`Wrote ${options.comment}`);
104
+ const summary = options.summary ?? context.env["GITHUB_STEP_SUMMARY"];
105
+ if (summary !== undefined && summary !== "") {
106
+ appendFileSync(summary, `${renderSummary(input)}\n`);
107
+ context.stdout(`Appended the summary to ${summary}`);
108
+ }
109
+ if (options.baselineOut !== undefined) {
110
+ writeFileSync(options.baselineOut, serializeBaseline(report, updateHistory(history, report)));
111
+ context.stdout(`Wrote ${options.baselineOut}`);
112
+ }
113
+ if (options.checkRun !== undefined) {
114
+ writeFileSync(options.checkRun, JSON.stringify(renderCheckRun(input)));
115
+ context.stdout(`Wrote ${options.checkRun}`);
116
+ }
117
+ }
118
+ catch (error) {
119
+ const code = error.code;
120
+ return fail(`wasit ci-report: cannot write a file${typeof code === "string" ? ` (${code})` : ""}`);
121
+ }
122
+ return 0;
123
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import "dotenv/config";
2
+ export {};