@wasit-dev/core 0.6.0 → 0.8.0-beta.1
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 +12 -4
- package/dist/baseline.d.ts +109 -0
- package/dist/baseline.js +351 -0
- package/dist/catalogue.d.ts +10 -0
- package/dist/catalogue.js +69 -3
- package/dist/check.d.ts +78 -2
- package/dist/check.js +69 -10
- package/dist/ci-report.d.ts +74 -0
- package/dist/ci-report.js +391 -0
- package/dist/config.d.ts +205 -0
- package/dist/config.js +1011 -0
- package/dist/denied-env.d.ts +33 -0
- package/dist/denied-env.js +86 -0
- package/dist/errors.d.ts +44 -1
- package/dist/errors.js +151 -2
- package/dist/guard/budget.d.ts +135 -0
- package/dist/guard/budget.js +199 -0
- package/dist/guard/ci-event.d.ts +50 -0
- package/dist/guard/ci-event.js +125 -0
- package/dist/guard/mainnet-optin.d.ts +58 -0
- package/dist/guard/mainnet-optin.js +95 -0
- package/dist/guard/networks.d.ts +50 -0
- package/dist/guard/networks.js +80 -0
- package/dist/guard/rpc-identity.d.ts +45 -0
- package/dist/guard/rpc-identity.js +156 -0
- package/dist/guard/rpc-in-use.d.ts +48 -0
- package/dist/guard/rpc-in-use.js +84 -0
- package/dist/index.d.ts +34 -3
- package/dist/index.js +31 -2
- package/dist/mpp/channel-commitment.d.ts +48 -2
- package/dist/mpp/channel-commitment.js +80 -4
- package/dist/mpp/channel-credential.js +3 -0
- package/dist/mpp/channel.js +29 -0
- package/dist/mpp/charge.d.ts +25 -2
- package/dist/mpp/charge.js +100 -8
- package/dist/mpp/network.js +4 -1
- package/dist/mpp/suite.js +10 -2
- package/dist/report.d.ts +163 -0
- package/dist/report.js +282 -0
- package/dist/sanitize.d.ts +52 -0
- package/dist/sanitize.js +106 -0
- package/dist/settlement.d.ts +14 -0
- package/dist/settlement.js +1 -1
- package/dist/verdict.d.ts +24 -0
- package/dist/verdict.js +46 -0
- package/dist/versions.d.ts +50 -0
- package/dist/versions.js +123 -0
- package/dist/x402/chains/evm.d.ts +65 -0
- package/dist/x402/chains/evm.js +237 -0
- package/dist/x402/chains/index.d.ts +18 -0
- package/dist/x402/chains/index.js +28 -0
- package/dist/x402/chains/stellar.d.ts +38 -0
- package/dist/x402/chains/stellar.js +277 -0
- package/dist/x402/chains/svm.d.ts +69 -0
- package/dist/x402/chains/svm.js +333 -0
- package/dist/x402/chains/types.d.ts +152 -0
- package/dist/x402/chains/types.js +10 -0
- package/dist/x402/chains/wait.d.ts +36 -0
- package/dist/x402/chains/wait.js +42 -0
- package/dist/x402/plan.d.ts +82 -0
- package/dist/x402/plan.js +146 -0
- package/dist/x402/rejected-request.d.ts +146 -0
- package/dist/x402/rejected-request.js +269 -0
- package/dist/x402/requirements.d.ts +46 -0
- package/dist/x402/requirements.js +359 -0
- package/dist/x402/simulator.d.ts +74 -17
- package/dist/x402/simulator.js +907 -246
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ The check suite behind [`@wasit-dev/cli`](https://www.npmjs.com/package/@wasit-d
|
|
|
4
4
|
|
|
5
5
|
This package holds the actual check logic. The CLI and the MCP server are thin adapters over these same functions, so a CLI run and an agent's run can never disagree about the same target — there is only one implementation of each check.
|
|
6
6
|
|
|
7
|
-
**Testnet only.** Several checks settle real transactions on-chain.
|
|
7
|
+
**Testnet only.** Several checks settle real transactions on-chain. In 0.8.0-beta.1 (npm tag `beta`; `latest` is 0.7.0) every payment check pays on test networks only: any other network, `stellar:pubnet` included, is refused before a key is read.
|
|
8
8
|
|
|
9
9
|
Most people should reach for [`@wasit-dev/cli`](https://www.npmjs.com/package/@wasit-dev/cli) (terminal) or [`@wasit-dev/server`](https://www.npmjs.com/package/@wasit-dev/server) (MCP / agents) instead of this package directly. Install `@wasit-dev/core` yourself only if you're building your own tooling on top of the check suite.
|
|
10
10
|
|
|
@@ -16,6 +16,12 @@ npm install @wasit-dev/core
|
|
|
16
16
|
|
|
17
17
|
Requires Node.js `>=22`. Ships ESM only (`"type": "module"`), with TypeScript types included (`dist/index.d.ts`).
|
|
18
18
|
|
|
19
|
+
In a project on TypeScript 6 or 7, npm prints `ERESOLVE overriding peer dependency`
|
|
20
|
+
warnings while installing: they come from `@solana/kit` 5, which the Solana support
|
|
21
|
+
depends on through `@x402/svm`, and which declares an optional peer `typescript ^5`.
|
|
22
|
+
The install succeeds and core runs; measured with TypeScript 5.8, 6.0 and 7.0
|
|
23
|
+
([evidence](https://github.com/wasit-dev/wasit/blob/main/docs/evidence/2026-10-05-0.7.0-verification-runs.md#installing-alongside-typescript)).
|
|
24
|
+
|
|
19
25
|
## Usage
|
|
20
26
|
|
|
21
27
|
```ts
|
|
@@ -51,7 +57,7 @@ Every check function returns `Promise<CheckResult[]>` and never rejects for a ta
|
|
|
51
57
|
| Function | Checks | Cost |
|
|
52
58
|
|---|---|---|
|
|
53
59
|
| `runX402ReadChecks({ target, method?, body?, headers? })` | `X402-01`–`05` | Free |
|
|
54
|
-
| `runX402PaymentChecks({ target, network, payerSecretKey, rpcUrl?, method?, body?, headers? })` | `X402-06
|
|
60
|
+
| `runX402PaymentChecks({ target, network, payerSecretKey, rpcUrl?, method?, body?, headers? })` | `X402-06`–`10` | **Settles a real payment every call** |
|
|
55
61
|
|
|
56
62
|
### MPP — charge mode
|
|
57
63
|
|
|
@@ -84,9 +90,11 @@ The full check catalogue — every check's exact pass criteria and spec referenc
|
|
|
84
90
|
|
|
85
91
|
| Export | What it is |
|
|
86
92
|
|---|---|
|
|
87
|
-
| `CHECK_CATALOGUE` | `readonly CheckCatalogueEntry[]` — every check the suite can run: `id`, `name`, `protocol`, `specRef`, a one-line `summary`, and the optional flags `negative`, `destructive`, `costsFunds`. This is what `wasit checks` prints. |
|
|
93
|
+
| `CHECK_CATALOGUE` | `readonly CheckCatalogueEntry[]` — every check the suite can run: `id`, `name`, `protocol`, `specRef`, a one-line `summary`, a `fix` saying what to change when it fails, and the optional flags `negative`, `destructive`, `costsFunds`. This is what `wasit checks` prints. |
|
|
94
|
+
| `fixFor(result)` | → `FailureGuidance \| undefined` — for a FAIL, `{ fix, docs }`: the result's own `hint` when it has one, else the catalogue `fix`, and the check's docs page. Undefined for anything that is not a FAIL. |
|
|
95
|
+
| `catalogueEntry(id)`, `docsUrlFor(id)` | Look up a check's catalogue entry, or its docs page on usewasit.dev |
|
|
88
96
|
| `PROTOCOL_IDS` | `readonly ProtocolId[]` — `"x402"`, `"mpp-charge"`, `"mpp-channel"` |
|
|
89
|
-
| `toStructuredRun(results)` | → `StructuredRun` — the machine-readable reshape of a run: `outcome`, per-status counts, and a `results` array of `StructuredCheckResult
|
|
97
|
+
| `toStructuredRun(results)` | → `StructuredRun` — the machine-readable reshape of a run: `outcome`, per-status counts, and a `results` array of `StructuredCheckResult` (a FAIL also carries `fix` and `docs`). The CLI's `--json` and the MCP server's `structuredContent` are both this function's output verbatim, so the three surfaces cannot describe the same run differently. |
|
|
90
98
|
|
|
91
99
|
`outcome` is a name — `"conformant"`, `"non-conformant"`, `"no-verdict"` — not an exit code. `no-verdict` must never be read as `conformant`.
|
|
92
100
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The baseline: the run report of the default branch, and the history carried
|
|
3
|
+
* with it (spec A5).
|
|
4
|
+
*
|
|
5
|
+
* A baseline comes out of an artifact, so it is data, never trusted: it is read
|
|
6
|
+
* through the same validator as the report of the current run, every string in
|
|
7
|
+
* it goes through the sanitiser, the totals and group counts are recomputed
|
|
8
|
+
* instead of believed, and anything that does not validate is ignored with a
|
|
9
|
+
* reason. A forged or damaged baseline can only change what a comment says
|
|
10
|
+
* changed, and it cannot make a check pass (A-A05 picks the run it came from).
|
|
11
|
+
*
|
|
12
|
+
* The history is one letter per run and check, oldest first, the last 20 runs:
|
|
13
|
+
* P pass, F fail, E error, S skip.
|
|
14
|
+
*/
|
|
15
|
+
import { type RunReport } from "./report.js";
|
|
16
|
+
/** How many runs of the default branch the history keeps. */
|
|
17
|
+
export declare const HISTORY_LIMIT = 20;
|
|
18
|
+
/** The largest baseline file read. A report of 50 endpoints with their results is far below this. */
|
|
19
|
+
export declare const MAX_BASELINE_BYTES: number;
|
|
20
|
+
/** A report that is not one Wasit wrote. The message names a path, never a value from the file. */
|
|
21
|
+
export declare class ReportFormatError extends Error {
|
|
22
|
+
constructor(path: string, message: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates a run report read from a file or an artifact and returns a clean
|
|
26
|
+
* copy: only the keys a report has, every string sanitised and cut, the totals
|
|
27
|
+
* and group counts recomputed.
|
|
28
|
+
*
|
|
29
|
+
* @throws {ReportFormatError} For anything else, naming the path and no value.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseRunReport(value: unknown): RunReport;
|
|
32
|
+
/** Endpoint name, then check id, to the letters of the last runs. */
|
|
33
|
+
export type History = Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
34
|
+
/**
|
|
35
|
+
* The history after `report`: the previous history with this run's letter added
|
|
36
|
+
* to every check in the report, the last {@link HISTORY_LIMIT} kept. An endpoint
|
|
37
|
+
* or a check that is not in the report is dropped; a new one starts here.
|
|
38
|
+
*/
|
|
39
|
+
export declare function updateHistory(previous: History | undefined, report: RunReport): History;
|
|
40
|
+
export interface RecentFailure {
|
|
41
|
+
readonly endpoint: string;
|
|
42
|
+
readonly check: string;
|
|
43
|
+
/** Runs in which the check failed. */
|
|
44
|
+
readonly failed: number;
|
|
45
|
+
/** Runs the history holds for it. */
|
|
46
|
+
readonly runs: number;
|
|
47
|
+
}
|
|
48
|
+
/** The checks that failed in at least one run of the history, most failures first. */
|
|
49
|
+
export declare function recentFailures(history: History): RecentFailure[];
|
|
50
|
+
export interface Baseline {
|
|
51
|
+
readonly report: RunReport;
|
|
52
|
+
readonly history: History;
|
|
53
|
+
}
|
|
54
|
+
export type BaselineResult = {
|
|
55
|
+
readonly ok: true;
|
|
56
|
+
readonly baseline: Baseline;
|
|
57
|
+
} | {
|
|
58
|
+
readonly ok: false;
|
|
59
|
+
readonly reason: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Reads a baseline file. Never throws: a file that is too large, is not JSON, is
|
|
63
|
+
* not a report, or carries a history that does not validate is ignored, and the
|
|
64
|
+
* reason says which. A file with a report and no history starts the history from
|
|
65
|
+
* that report.
|
|
66
|
+
*/
|
|
67
|
+
export declare function readBaseline(fileText: string): BaselineResult;
|
|
68
|
+
/** The text of a baseline file: the report with its history. */
|
|
69
|
+
export declare function serializeBaseline(report: RunReport, history: History): string;
|
|
70
|
+
/**
|
|
71
|
+
* Why a valid baseline cannot be compared with this run, if it cannot. A
|
|
72
|
+
* baseline from another environment is another service: comparing them would
|
|
73
|
+
* show regressions that are not.
|
|
74
|
+
*/
|
|
75
|
+
export declare function baselineProblem(report: RunReport, baseline: RunReport): string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The baseline a run may be compared with, and the reason when there is none.
|
|
78
|
+
*
|
|
79
|
+
* `read` is what {@link readBaseline} gave for the file, or undefined when no
|
|
80
|
+
* baseline was looked for. The result carries a baseline only if it validated
|
|
81
|
+
* and is from the same environment; otherwise it carries the reason, which the
|
|
82
|
+
* comment shows and the run notes.
|
|
83
|
+
*/
|
|
84
|
+
export declare function selectBaseline(report: RunReport, read: BaselineResult | undefined): {
|
|
85
|
+
readonly baseline?: Baseline;
|
|
86
|
+
readonly note?: string;
|
|
87
|
+
};
|
|
88
|
+
export type ChangeKind = "new-failure" | "fixed" | "regression" | "graded" | "new-endpoint" | "removed-endpoint" | "status-changed";
|
|
89
|
+
export interface Change {
|
|
90
|
+
readonly kind: ChangeKind;
|
|
91
|
+
readonly endpoint: string;
|
|
92
|
+
readonly check?: string;
|
|
93
|
+
readonly from?: string;
|
|
94
|
+
readonly to?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* What changed against the baseline, by endpoint name: new and removed
|
|
98
|
+
* endpoints, an endpoint that is no longer graded (a regression) or is now, and
|
|
99
|
+
* per check a new FAIL, a FAIL that passes, and any other status that differs.
|
|
100
|
+
* A check that is in only one of the two reports is not a change.
|
|
101
|
+
*/
|
|
102
|
+
export declare function diffReports(report: RunReport, baseline: RunReport): Change[];
|
|
103
|
+
/** A service that was graded on the default branch and is not graded now (spec A8 #3, D-021). */
|
|
104
|
+
export interface Regression {
|
|
105
|
+
readonly endpoint: string;
|
|
106
|
+
readonly was: "conformant" | "non-conformant";
|
|
107
|
+
readonly now: "unsupported" | "no-verdict";
|
|
108
|
+
}
|
|
109
|
+
export declare function findRegressions(report: RunReport, baseline: RunReport): Regression[];
|
package/dist/baseline.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The baseline: the run report of the default branch, and the history carried
|
|
3
|
+
* with it (spec A5).
|
|
4
|
+
*
|
|
5
|
+
* A baseline comes out of an artifact, so it is data, never trusted: it is read
|
|
6
|
+
* through the same validator as the report of the current run, every string in
|
|
7
|
+
* it goes through the sanitiser, the totals and group counts are recomputed
|
|
8
|
+
* instead of believed, and anything that does not validate is ignored with a
|
|
9
|
+
* reason. A forged or damaged baseline can only change what a comment says
|
|
10
|
+
* changed, and it cannot make a check pass (A-A05 picks the run it came from).
|
|
11
|
+
*
|
|
12
|
+
* The history is one letter per run and check, oldest first, the last 20 runs:
|
|
13
|
+
* P pass, F fail, E error, S skip.
|
|
14
|
+
*/
|
|
15
|
+
import { PROTOCOL_IDS } from "./catalogue.js";
|
|
16
|
+
import { SKIP_KINDS } from "./check.js";
|
|
17
|
+
import { groupCounts, reportTotals, } from "./report.js";
|
|
18
|
+
import { sanitizeText } from "./sanitize.js";
|
|
19
|
+
import { isShortCommit } from "./versions.js";
|
|
20
|
+
/** How many runs of the default branch the history keeps. */
|
|
21
|
+
export const HISTORY_LIMIT = 20;
|
|
22
|
+
/** The largest baseline file read. A report of 50 endpoints with their results is far below this. */
|
|
23
|
+
export const MAX_BASELINE_BYTES = 2 * 1024 * 1024;
|
|
24
|
+
const MAX_ENDPOINTS = 100;
|
|
25
|
+
const MAX_RESULTS = 100;
|
|
26
|
+
const MAX_NOTES = 50;
|
|
27
|
+
const MAX_DETAIL = 4000;
|
|
28
|
+
/** A report that is not one Wasit wrote. The message names a path, never a value from the file. */
|
|
29
|
+
export class ReportFormatError extends Error {
|
|
30
|
+
constructor(path, message) {
|
|
31
|
+
super(`Not a Wasit run report: ${path === "" ? "the file" : path} ${message}`);
|
|
32
|
+
this.name = "ReportFormatError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const OUTCOMES = ["conformant", "non-conformant", "no-verdict", "unsupported"];
|
|
36
|
+
const STATUSES = ["PASS", "FAIL", "ERROR", "SKIP"];
|
|
37
|
+
const NETWORK_CLASS_VALUES = ["test", "mainnet-optin", "unknown"];
|
|
38
|
+
const ERROR_KINDS = ["unreachable", "configuration", "harness", "setup"];
|
|
39
|
+
const CHECK_ID = /^[A-Za-z0-9_-]{1,40}$/;
|
|
40
|
+
function isRecord(value) {
|
|
41
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
function at(parent, key) {
|
|
44
|
+
return typeof key === "number" ? `${parent}[${key}]` : parent === "" ? key : `${parent}.${key}`;
|
|
45
|
+
}
|
|
46
|
+
/** A string, sanitised and cut to `max`. */
|
|
47
|
+
function text(value, path, max) {
|
|
48
|
+
if (typeof value !== "string")
|
|
49
|
+
throw new ReportFormatError(path, "must be a string");
|
|
50
|
+
return sanitizeText(value).slice(0, max);
|
|
51
|
+
}
|
|
52
|
+
function oneOf(value, allowed, path) {
|
|
53
|
+
if (typeof value !== "string" || !allowed.includes(value)) {
|
|
54
|
+
throw new ReportFormatError(path, "is not one of the values a report uses");
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
function list(value, path, max) {
|
|
59
|
+
if (!Array.isArray(value))
|
|
60
|
+
throw new ReportFormatError(path, "must be a list");
|
|
61
|
+
if (value.length > max)
|
|
62
|
+
throw new ReportFormatError(path, `has more than ${max} entries`);
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
function record(value, path) {
|
|
66
|
+
if (!isRecord(value))
|
|
67
|
+
throw new ReportFormatError(path, "must be an object");
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
function readResult(raw, path) {
|
|
71
|
+
const entry = record(raw, path);
|
|
72
|
+
const id = text(entry["id"], at(path, "id"), 40);
|
|
73
|
+
if (!CHECK_ID.test(id))
|
|
74
|
+
throw new ReportFormatError(at(path, "id"), "is not a check id");
|
|
75
|
+
const status = oneOf(entry["status"], STATUSES, at(path, "status"));
|
|
76
|
+
if (typeof entry["destructive"] !== "boolean")
|
|
77
|
+
throw new ReportFormatError(at(path, "destructive"), "must be true or false");
|
|
78
|
+
return {
|
|
79
|
+
id,
|
|
80
|
+
name: text(entry["name"], at(path, "name"), 200),
|
|
81
|
+
status,
|
|
82
|
+
detail: text(entry["detail"], at(path, "detail"), MAX_DETAIL),
|
|
83
|
+
destructive: entry["destructive"],
|
|
84
|
+
...(entry["errorKind"] === undefined ? {} : { errorKind: oneOf(entry["errorKind"], ERROR_KINDS, at(path, "errorKind")) }),
|
|
85
|
+
...(entry["skipKind"] === undefined ? {} : { skipKind: oneOf(entry["skipKind"], SKIP_KINDS, at(path, "skipKind")) }),
|
|
86
|
+
...(entry["expected"] === undefined ? {} : { expected: text(entry["expected"], at(path, "expected"), 500) }),
|
|
87
|
+
...(entry["actual"] === undefined ? {} : { actual: text(entry["actual"], at(path, "actual"), 500) }),
|
|
88
|
+
...(entry["reference"] === undefined ? {} : { reference: text(entry["reference"], at(path, "reference"), 120) }),
|
|
89
|
+
...(entry["fix"] === undefined ? {} : { fix: text(entry["fix"], at(path, "fix"), 2000) }),
|
|
90
|
+
...(entry["docs"] === undefined ? {} : { docs: text(entry["docs"], at(path, "docs"), 300) }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function readEndpoint(raw, path) {
|
|
94
|
+
const entry = record(raw, path);
|
|
95
|
+
const protocol = oneOf(entry["protocol"], PROTOCOL_IDS, at(path, "protocol"));
|
|
96
|
+
const results = list(entry["results"], at(path, "results"), MAX_RESULTS).map((item, index) => readResult(item, at(at(path, "results"), index)));
|
|
97
|
+
const name = text(entry["name"], at(path, "name"), 200);
|
|
98
|
+
if (name === "")
|
|
99
|
+
throw new ReportFormatError(at(path, "name"), "must not be empty");
|
|
100
|
+
return {
|
|
101
|
+
name,
|
|
102
|
+
protocol,
|
|
103
|
+
method: text(entry["method"], at(path, "method"), 16),
|
|
104
|
+
path: text(entry["path"], at(path, "path"), 2048),
|
|
105
|
+
outcome: oneOf(entry["outcome"], OUTCOMES, at(path, "outcome")),
|
|
106
|
+
...(entry["reason"] === undefined ? {} : { reason: text(entry["reason"], at(path, "reason"), 1000) }),
|
|
107
|
+
// Recomputed from the results: a count in the file is not believed.
|
|
108
|
+
groups: groupCounts(results, protocol),
|
|
109
|
+
results,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Validates a run report read from a file or an artifact and returns a clean
|
|
114
|
+
* copy: only the keys a report has, every string sanitised and cut, the totals
|
|
115
|
+
* and group counts recomputed.
|
|
116
|
+
*
|
|
117
|
+
* @throws {ReportFormatError} For anything else, naming the path and no value.
|
|
118
|
+
*/
|
|
119
|
+
export function parseRunReport(value) {
|
|
120
|
+
const root = record(value, "");
|
|
121
|
+
if (root["schema"] !== 1)
|
|
122
|
+
throw new ReportFormatError("schema", "must be 1");
|
|
123
|
+
const wasit = record(root["wasit"], "wasit");
|
|
124
|
+
const sdk = record(root["sdk"], "sdk");
|
|
125
|
+
const build = wasit["build"];
|
|
126
|
+
if (build !== undefined && !isShortCommit(build)) {
|
|
127
|
+
throw new ReportFormatError("wasit.build", "must be seven lower-case hex characters");
|
|
128
|
+
}
|
|
129
|
+
if (sdk["x402Version"] !== 2)
|
|
130
|
+
throw new ReportFormatError("sdk.x402Version", "must be 2");
|
|
131
|
+
const endpoints = list(root["endpoints"], "endpoints", MAX_ENDPOINTS).map((item, index) => readEndpoint(item, `endpoints[${index}]`));
|
|
132
|
+
const seen = new Set();
|
|
133
|
+
for (const endpoint of endpoints) {
|
|
134
|
+
if (seen.has(endpoint.name))
|
|
135
|
+
throw new ReportFormatError("endpoints", "has two endpoints with the same name");
|
|
136
|
+
seen.add(endpoint.name);
|
|
137
|
+
}
|
|
138
|
+
const notes = root["notes"] === undefined ? [] : list(root["notes"], "notes", MAX_NOTES);
|
|
139
|
+
return {
|
|
140
|
+
schema: 1,
|
|
141
|
+
wasit: {
|
|
142
|
+
cli: text(wasit["cli"], "wasit.cli", 40),
|
|
143
|
+
core: text(wasit["core"], "wasit.core", 40),
|
|
144
|
+
...(build === undefined ? {} : { build }),
|
|
145
|
+
},
|
|
146
|
+
sdk: {
|
|
147
|
+
x402Version: 2,
|
|
148
|
+
"@x402/core": text(sdk["@x402/core"], "sdk.@x402/core", 40),
|
|
149
|
+
"@x402/stellar": text(sdk["@x402/stellar"], "sdk.@x402/stellar", 40),
|
|
150
|
+
"@stellar/mpp": text(sdk["@stellar/mpp"], "sdk.@stellar/mpp", 40),
|
|
151
|
+
mppx: text(sdk["mppx"], "sdk.mppx", 40),
|
|
152
|
+
"@stellar/stellar-sdk": text(sdk["@stellar/stellar-sdk"], "sdk.@stellar/stellar-sdk", 40),
|
|
153
|
+
},
|
|
154
|
+
environment: text(root["environment"], "environment", 200),
|
|
155
|
+
network: text(root["network"], "network", 200),
|
|
156
|
+
networkClass: oneOf(root["networkClass"], NETWORK_CLASS_VALUES, "networkClass"),
|
|
157
|
+
startedAt: text(root["startedAt"], "startedAt", 40),
|
|
158
|
+
endpoints,
|
|
159
|
+
totals: reportTotals(endpoints),
|
|
160
|
+
notes: notes.map((note, index) => text(note, `notes[${index}]`, 1000)),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const LETTER = { PASS: "P", FAIL: "F", ERROR: "E", SKIP: "S" };
|
|
164
|
+
/** When one report lists a check id twice, the worse status is the one kept. */
|
|
165
|
+
const SEVERITY = "SPEF";
|
|
166
|
+
function readHistory(value) {
|
|
167
|
+
const root = record(value, "history");
|
|
168
|
+
const entries = Object.entries(root);
|
|
169
|
+
if (entries.length > MAX_ENDPOINTS)
|
|
170
|
+
throw new ReportFormatError("history", `has more than ${MAX_ENDPOINTS} endpoints`);
|
|
171
|
+
return Object.fromEntries(entries.map(([endpoint, checks]) => {
|
|
172
|
+
const path = at("history", sanitizeText(endpoint).slice(0, 80));
|
|
173
|
+
const inner = Object.entries(record(checks, path));
|
|
174
|
+
if (inner.length > MAX_RESULTS)
|
|
175
|
+
throw new ReportFormatError(path, `has more than ${MAX_RESULTS} checks`);
|
|
176
|
+
return [
|
|
177
|
+
sanitizeText(endpoint).slice(0, 200),
|
|
178
|
+
Object.fromEntries(inner.map(([id, letters]) => {
|
|
179
|
+
if (typeof letters !== "string" || !new RegExp(`^[PFES]{1,${HISTORY_LIMIT}}$`).test(letters)) {
|
|
180
|
+
throw new ReportFormatError(at(path, sanitizeText(id).slice(0, 40)), "is not a run history");
|
|
181
|
+
}
|
|
182
|
+
return [sanitizeText(id).slice(0, 40), letters];
|
|
183
|
+
})),
|
|
184
|
+
];
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The history after `report`: the previous history with this run's letter added
|
|
189
|
+
* to every check in the report, the last {@link HISTORY_LIMIT} kept. An endpoint
|
|
190
|
+
* or a check that is not in the report is dropped; a new one starts here.
|
|
191
|
+
*/
|
|
192
|
+
export function updateHistory(previous, report) {
|
|
193
|
+
return Object.fromEntries(report.endpoints.map((endpoint) => {
|
|
194
|
+
const worst = new Map();
|
|
195
|
+
for (const result of endpoint.results) {
|
|
196
|
+
const letter = LETTER[result.status];
|
|
197
|
+
const kept = worst.get(result.id);
|
|
198
|
+
if (kept === undefined || SEVERITY.indexOf(letter) > SEVERITY.indexOf(kept))
|
|
199
|
+
worst.set(result.id, letter);
|
|
200
|
+
}
|
|
201
|
+
const before = previous !== undefined && Object.hasOwn(previous, endpoint.name) ? previous[endpoint.name] : {};
|
|
202
|
+
return [
|
|
203
|
+
endpoint.name,
|
|
204
|
+
Object.fromEntries([...worst].map(([id, letter]) => {
|
|
205
|
+
const earlier = Object.hasOwn(before, id) ? before[id] : "";
|
|
206
|
+
return [id, `${earlier}${letter}`.slice(-HISTORY_LIMIT)];
|
|
207
|
+
})),
|
|
208
|
+
];
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
/** The checks that failed in at least one run of the history, most failures first. */
|
|
212
|
+
export function recentFailures(history) {
|
|
213
|
+
const failures = [];
|
|
214
|
+
for (const [endpoint, checks] of Object.entries(history)) {
|
|
215
|
+
for (const [check, letters] of Object.entries(checks)) {
|
|
216
|
+
const failed = [...letters].filter((letter) => letter === "F").length;
|
|
217
|
+
if (failed > 0)
|
|
218
|
+
failures.push({ endpoint, check, failed, runs: letters.length });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return failures.sort((a, b) => b.failed - a.failed);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Reads a baseline file. Never throws: a file that is too large, is not JSON, is
|
|
225
|
+
* not a report, or carries a history that does not validate is ignored, and the
|
|
226
|
+
* reason says which. A file with a report and no history starts the history from
|
|
227
|
+
* that report.
|
|
228
|
+
*/
|
|
229
|
+
export function readBaseline(fileText) {
|
|
230
|
+
if (Buffer.byteLength(fileText, "utf-8") > MAX_BASELINE_BYTES) {
|
|
231
|
+
return { ok: false, reason: `the baseline is larger than ${MAX_BASELINE_BYTES / 1024} KiB` };
|
|
232
|
+
}
|
|
233
|
+
let value;
|
|
234
|
+
try {
|
|
235
|
+
value = JSON.parse(fileText);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return { ok: false, reason: "the baseline is not valid JSON" };
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
const report = parseRunReport(value);
|
|
242
|
+
const raw = value["history"];
|
|
243
|
+
return { ok: true, baseline: { report, history: raw === undefined ? updateHistory(undefined, report) : readHistory(raw) } };
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (error instanceof ReportFormatError)
|
|
247
|
+
return { ok: false, reason: error.message };
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** The text of a baseline file: the report with its history. */
|
|
252
|
+
export function serializeBaseline(report, history) {
|
|
253
|
+
return `${JSON.stringify({ ...report, history }, null, 2)}\n`;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Why a valid baseline cannot be compared with this run, if it cannot. A
|
|
257
|
+
* baseline from another environment is another service: comparing them would
|
|
258
|
+
* show regressions that are not.
|
|
259
|
+
*/
|
|
260
|
+
export function baselineProblem(report, baseline) {
|
|
261
|
+
if (baseline.environment !== report.environment) {
|
|
262
|
+
return `the baseline is from environment ${baseline.environment} and this run is ${report.environment}, so the two are not compared`;
|
|
263
|
+
}
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The baseline a run may be compared with, and the reason when there is none.
|
|
268
|
+
*
|
|
269
|
+
* `read` is what {@link readBaseline} gave for the file, or undefined when no
|
|
270
|
+
* baseline was looked for. The result carries a baseline only if it validated
|
|
271
|
+
* and is from the same environment; otherwise it carries the reason, which the
|
|
272
|
+
* comment shows and the run notes.
|
|
273
|
+
*/
|
|
274
|
+
export function selectBaseline(report, read) {
|
|
275
|
+
if (read === undefined)
|
|
276
|
+
return {};
|
|
277
|
+
if (!read.ok)
|
|
278
|
+
return { note: read.reason };
|
|
279
|
+
const problem = baselineProblem(report, read.baseline.report);
|
|
280
|
+
return problem === undefined ? { baseline: read.baseline } : { note: problem };
|
|
281
|
+
}
|
|
282
|
+
const GRADED = ["conformant", "non-conformant"];
|
|
283
|
+
function statuses(endpoint) {
|
|
284
|
+
const map = new Map();
|
|
285
|
+
for (const result of endpoint.results) {
|
|
286
|
+
// A FAIL is never hidden by a second entry for the same id.
|
|
287
|
+
if (map.get(result.id) !== "FAIL")
|
|
288
|
+
map.set(result.id, result.status);
|
|
289
|
+
}
|
|
290
|
+
return map;
|
|
291
|
+
}
|
|
292
|
+
/** The checks of an endpoint that its run skipped because of the tier: read-only, or no payer key. */
|
|
293
|
+
function notRunByTier(endpoint) {
|
|
294
|
+
return new Set(endpoint.results
|
|
295
|
+
.filter((result) => result.status === "SKIP" && (result.skipKind === "read-only" || result.skipKind === "needs-payer"))
|
|
296
|
+
.map((result) => result.id));
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* What changed against the baseline, by endpoint name: new and removed
|
|
300
|
+
* endpoints, an endpoint that is no longer graded (a regression) or is now, and
|
|
301
|
+
* per check a new FAIL, a FAIL that passes, and any other status that differs.
|
|
302
|
+
* A check that is in only one of the two reports is not a change.
|
|
303
|
+
*/
|
|
304
|
+
export function diffReports(report, baseline) {
|
|
305
|
+
const changes = [];
|
|
306
|
+
const before = new Map(baseline.endpoints.map((endpoint) => [endpoint.name, endpoint]));
|
|
307
|
+
const now = new Set(report.endpoints.map((endpoint) => endpoint.name));
|
|
308
|
+
for (const endpoint of report.endpoints) {
|
|
309
|
+
const earlier = before.get(endpoint.name);
|
|
310
|
+
if (earlier === undefined) {
|
|
311
|
+
changes.push({ kind: "new-endpoint", endpoint: endpoint.name });
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const wasGraded = GRADED.includes(earlier.outcome);
|
|
315
|
+
const isGraded = GRADED.includes(endpoint.outcome);
|
|
316
|
+
if (wasGraded && !isGraded) {
|
|
317
|
+
changes.push({ kind: "regression", endpoint: endpoint.name, from: earlier.outcome, to: endpoint.outcome });
|
|
318
|
+
}
|
|
319
|
+
else if (!wasGraded && isGraded) {
|
|
320
|
+
changes.push({ kind: "graded", endpoint: endpoint.name, from: earlier.outcome, to: endpoint.outcome });
|
|
321
|
+
}
|
|
322
|
+
const was = statuses(earlier);
|
|
323
|
+
const notRunBefore = notRunByTier(earlier);
|
|
324
|
+
const notRunNow = notRunByTier(endpoint);
|
|
325
|
+
for (const [check, status] of statuses(endpoint)) {
|
|
326
|
+
const from = was.get(check);
|
|
327
|
+
if (from === undefined || from === status)
|
|
328
|
+
continue;
|
|
329
|
+
// A check one of the two runs did not run because of its tier (a pull request
|
|
330
|
+
// runs the read-only checks, main may pay, D-022a) says nothing about the service.
|
|
331
|
+
if (notRunBefore.has(check) || notRunNow.has(check))
|
|
332
|
+
continue;
|
|
333
|
+
const kind = status === "FAIL" ? "new-failure" : from === "FAIL" && status === "PASS" ? "fixed" : "status-changed";
|
|
334
|
+
changes.push({ kind, endpoint: endpoint.name, check, from, to: status });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
for (const endpoint of baseline.endpoints) {
|
|
338
|
+
if (!now.has(endpoint.name))
|
|
339
|
+
changes.push({ kind: "removed-endpoint", endpoint: endpoint.name });
|
|
340
|
+
}
|
|
341
|
+
return changes;
|
|
342
|
+
}
|
|
343
|
+
export function findRegressions(report, baseline) {
|
|
344
|
+
return diffReports(report, baseline)
|
|
345
|
+
.filter((change) => change.kind === "regression")
|
|
346
|
+
.map((change) => ({
|
|
347
|
+
endpoint: change.endpoint,
|
|
348
|
+
was: change.from,
|
|
349
|
+
now: change.to,
|
|
350
|
+
}));
|
|
351
|
+
}
|
package/dist/catalogue.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ export interface CheckCatalogueEntry {
|
|
|
23
23
|
readonly specRef: string;
|
|
24
24
|
/** One-line summary of what the check verifies. Full pass criteria: docs/CHECKS.md. */
|
|
25
25
|
readonly summary: string;
|
|
26
|
+
/**
|
|
27
|
+
* What to change when the check fails, in one or two sentences. A result
|
|
28
|
+
* may carry a more specific `hint` for the cause it found; this is the
|
|
29
|
+
* fallback, so every failure comes with something to act on.
|
|
30
|
+
*/
|
|
31
|
+
readonly fix: string;
|
|
26
32
|
/** True for a check that only passes because the target correctly REJECTED something. */
|
|
27
33
|
readonly negative?: true;
|
|
28
34
|
/** True for a check that permanently alters the target's state (see SECURITY.md). */
|
|
@@ -31,3 +37,7 @@ export interface CheckCatalogueEntry {
|
|
|
31
37
|
readonly costsFunds?: true;
|
|
32
38
|
}
|
|
33
39
|
export declare const CHECK_CATALOGUE: readonly CheckCatalogueEntry[];
|
|
40
|
+
/** The catalogue entry for a check id, if there is one (PREFLIGHT has none). */
|
|
41
|
+
export declare function catalogueEntry(id: string): CheckCatalogueEntry | undefined;
|
|
42
|
+
/** The docs page for a check id, if it is in the catalogue. */
|
|
43
|
+
export declare function docsUrlFor(id: string): string | undefined;
|