@wasit-dev/core 0.7.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 +1 -1
- package/dist/baseline.d.ts +109 -0
- package/dist/baseline.js +351 -0
- package/dist/catalogue.js +10 -0
- package/dist/check.d.ts +57 -2
- package/dist/check.js +46 -6
- 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 +31 -2
- package/dist/index.js +27 -1
- 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 +2 -0
- package/dist/mpp/charge.js +17 -1
- 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.js +3 -0
- package/dist/x402/chains/index.d.ts +8 -0
- package/dist/x402/chains/index.js +13 -2
- package/dist/x402/chains/stellar.d.ts +8 -1
- package/dist/x402/chains/stellar.js +125 -1
- package/dist/x402/chains/types.d.ts +68 -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 +1 -0
- package/dist/x402/requirements.js +37 -4
- package/dist/x402/simulator.d.ts +52 -1
- package/dist/x402/simulator.js +452 -82
- package/package.json +1 -1
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
|
|
|
@@ -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.js
CHANGED
|
@@ -101,6 +101,16 @@ export const CHECK_CATALOGUE = [
|
|
|
101
101
|
negative: true,
|
|
102
102
|
fix: "Verify each payment with the facilitator before serving: it refuses an authorization past its window (validBefore on EVM, the auth entry's expiration ledger on Stellar).",
|
|
103
103
|
},
|
|
104
|
+
{
|
|
105
|
+
id: "X402-11",
|
|
106
|
+
name: "Rejected Request Not Settled",
|
|
107
|
+
protocol: "x402",
|
|
108
|
+
specRef: "x402 v2 spec §6.1 (verify, run the resource, settle); Soroban authorization nonces",
|
|
109
|
+
summary: "A valid payment sent with a request the config declares invalid must not settle: the chain still holds its authorization unused after it expires.",
|
|
110
|
+
negative: true,
|
|
111
|
+
costsFunds: true,
|
|
112
|
+
fix: "Validate a request before its payment is settled, and settle only once the request has been accepted; a refused request must not cost the payer.",
|
|
113
|
+
},
|
|
104
114
|
{
|
|
105
115
|
id: "MPP-01",
|
|
106
116
|
name: "Charge Settlement On-Chain",
|
package/dist/check.d.ts
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
* The result shape shared by every conformance check, across protocols.
|
|
3
3
|
*/
|
|
4
4
|
import { type CheckError } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Why a check did not run, for a reader who has to tell "Wasit cannot grade
|
|
7
|
+
* this" from "you asked for less" from "an earlier check failed". The four
|
|
8
|
+
* statuses stay as they are; this refines SKIP and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* - `unsupported`: Wasit cannot grade it (an x402 v1 challenge, a network it
|
|
11
|
+
* does not pay on). Not a FAIL, and not a pass either.
|
|
12
|
+
* - `resource-consumed`: the first payment used up a single-use resource.
|
|
13
|
+
* - `needs-payer`: the check pays and no payer key was given.
|
|
14
|
+
* - `read-only`: the run was asked not to pay.
|
|
15
|
+
* - `not-applicable`: the target gives the check nothing to test.
|
|
16
|
+
* - `dependency`: an earlier check failed or gave no verdict, so there is
|
|
17
|
+
* nothing for this one to inspect.
|
|
18
|
+
*/
|
|
19
|
+
export type SkipKind = "unsupported" | "resource-consumed" | "needs-payer" | "read-only" | "not-applicable" | "dependency";
|
|
20
|
+
export declare const SKIP_KINDS: readonly SkipKind[];
|
|
5
21
|
export interface CheckResult {
|
|
6
22
|
/** Stable catalogue identifier, e.g. "MPP-11". Must match docs/CHECKS.md. */
|
|
7
23
|
id: string;
|
|
@@ -15,6 +31,23 @@ export interface CheckResult {
|
|
|
15
31
|
* {@link fixFor}). Meaningful only on a FAIL.
|
|
16
32
|
*/
|
|
17
33
|
hint?: string;
|
|
34
|
+
/**
|
|
35
|
+
* What the check expected, and what the service sent instead, in a few words
|
|
36
|
+
* each ("status 402", "status 200"). Set by the check that knows them, on a
|
|
37
|
+
* FAIL, so a report can show the reason, the expected and the actual value,
|
|
38
|
+
* and the fix. `detail` and `hint` say the same in prose and are unchanged.
|
|
39
|
+
* Both quote the service, so both pass through the sanitiser on the way out,
|
|
40
|
+
* and are cut to a short length there, after the secrets are removed.
|
|
41
|
+
*/
|
|
42
|
+
expected?: string;
|
|
43
|
+
actual?: string;
|
|
44
|
+
/**
|
|
45
|
+
* The settlement a check read back from the chain and found to be this
|
|
46
|
+
* payment (X402-06's transaction: a Stellar or EVM transaction hash, a Solana
|
|
47
|
+
* signature). Set only on a PASS whose settlement was verified on chain; a
|
|
48
|
+
* report may link it to an explorer after checking its shape.
|
|
49
|
+
*/
|
|
50
|
+
reference?: string;
|
|
18
51
|
/**
|
|
19
52
|
* True when the check did not run. A skipped check is neither a pass nor a
|
|
20
53
|
* failure: `pass` is false so it can never be counted as conformance, and
|
|
@@ -23,6 +56,8 @@ export interface CheckResult {
|
|
|
23
56
|
skipped?: boolean;
|
|
24
57
|
/** Why the check was skipped. Required whenever `skipped` is true. */
|
|
25
58
|
skipReason?: string;
|
|
59
|
+
/** What kind of reason it is, when the code that skipped it knows. Meaningful only on a SKIP. */
|
|
60
|
+
skipKind?: SkipKind;
|
|
26
61
|
/**
|
|
27
62
|
* True when running this check permanently alters the target's state.
|
|
28
63
|
* Destructive checks are skipped unless the operator explicitly opts in,
|
|
@@ -72,8 +107,20 @@ export declare function skippedDestructive(id: string, name: string, reason: str
|
|
|
72
107
|
* reported and exit-coded separately from conformance failures.
|
|
73
108
|
*/
|
|
74
109
|
export declare function errored(id: string, name: string, error: unknown): CheckResult;
|
|
75
|
-
/**
|
|
76
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Builds the result for a check that was not run, for a non-destructive reason.
|
|
112
|
+
* `kind` says what sort of reason it is; leave it out when the code does not know.
|
|
113
|
+
*/
|
|
114
|
+
export declare function skipped(id: string, name: string, reason: string, kind?: SkipKind): CheckResult;
|
|
115
|
+
/**
|
|
116
|
+
* A value a service sent, quoted for the `actual` of a FAIL: a string in JSON
|
|
117
|
+
* quotes (control characters written out, not carried), anything else as JSON.
|
|
118
|
+
*
|
|
119
|
+
* Not cut here unless `max` is given. A cut made before the secrets of the run
|
|
120
|
+
* are removed can leave the start of a secret in the output, so the cut is made
|
|
121
|
+
* by the sinks that remove them (`redactValue`, the comment renderer).
|
|
122
|
+
*/
|
|
123
|
+
export declare function quoteValue(value: unknown, max?: number): string;
|
|
77
124
|
/** What to do about a failure, and where it is documented. */
|
|
78
125
|
export interface FailureGuidance {
|
|
79
126
|
readonly fix: string;
|
|
@@ -97,6 +144,14 @@ export interface StructuredCheckResult {
|
|
|
97
144
|
* unreachable | configuration | harness | setup.
|
|
98
145
|
*/
|
|
99
146
|
readonly errorKind?: string;
|
|
147
|
+
/** Present only when `status` is "SKIP" and the reason has a kind: see {@link SkipKind}. */
|
|
148
|
+
readonly skipKind?: SkipKind;
|
|
149
|
+
/** Present only when `status` is "FAIL" and the check recorded it: what it expected. */
|
|
150
|
+
readonly expected?: string;
|
|
151
|
+
/** Present only when `status` is "FAIL" and the check recorded it: what the service sent. */
|
|
152
|
+
readonly actual?: string;
|
|
153
|
+
/** Present only when `status` is "PASS" and the check verified a settlement on chain: its reference. */
|
|
154
|
+
readonly reference?: string;
|
|
100
155
|
/** Present only when `status` is "FAIL": what to change (see {@link fixFor}). */
|
|
101
156
|
readonly fix?: string;
|
|
102
157
|
/** Present only when `status` is "FAIL": the check's docs page. */
|
package/dist/check.js
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { catalogueEntry, docsUrlFor } from "./catalogue.js";
|
|
5
5
|
import { classifyCheckError } from "./errors.js";
|
|
6
|
+
import { sanitizeText } from "./sanitize.js";
|
|
7
|
+
export const SKIP_KINDS = [
|
|
8
|
+
"unsupported",
|
|
9
|
+
"resource-consumed",
|
|
10
|
+
"needs-payer",
|
|
11
|
+
"read-only",
|
|
12
|
+
"not-applicable",
|
|
13
|
+
"dependency",
|
|
14
|
+
];
|
|
6
15
|
/**
|
|
7
16
|
* Classifies one result.
|
|
8
17
|
*
|
|
@@ -84,17 +93,36 @@ export function errored(id, name, error) {
|
|
|
84
93
|
detail: `Check could not run (${classified.kind}): ${classified.message}`,
|
|
85
94
|
};
|
|
86
95
|
}
|
|
87
|
-
/**
|
|
88
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Builds the result for a check that was not run, for a non-destructive reason.
|
|
98
|
+
* `kind` says what sort of reason it is; leave it out when the code does not know.
|
|
99
|
+
*/
|
|
100
|
+
export function skipped(id, name, reason, kind) {
|
|
89
101
|
return {
|
|
90
102
|
id,
|
|
91
103
|
name,
|
|
92
104
|
pass: false,
|
|
93
105
|
skipped: true,
|
|
94
106
|
skipReason: reason,
|
|
107
|
+
...(kind === undefined ? {} : { skipKind: kind }),
|
|
95
108
|
detail: `Skipped: ${reason}`,
|
|
96
109
|
};
|
|
97
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* A value a service sent, quoted for the `actual` of a FAIL: a string in JSON
|
|
113
|
+
* quotes (control characters written out, not carried), anything else as JSON.
|
|
114
|
+
*
|
|
115
|
+
* Not cut here unless `max` is given. A cut made before the secrets of the run
|
|
116
|
+
* are removed can leave the start of a secret in the output, so the cut is made
|
|
117
|
+
* by the sinks that remove them (`redactValue`, the comment renderer).
|
|
118
|
+
*/
|
|
119
|
+
export function quoteValue(value, max) {
|
|
120
|
+
const quoted = typeof value === "string" ? JSON.stringify(value) : (JSON.stringify(value) ?? String(value));
|
|
121
|
+
if (max === undefined)
|
|
122
|
+
return quoted;
|
|
123
|
+
const characters = Array.from(quoted);
|
|
124
|
+
return characters.length <= max ? quoted : `${characters.slice(0, Math.max(1, max - 1)).join("")}…`;
|
|
125
|
+
}
|
|
98
126
|
/**
|
|
99
127
|
* The guidance a front end shows under a FAIL: the result's own hint when it
|
|
100
128
|
* has one, else the check's catalogue fix. Undefined for anything that is not
|
|
@@ -130,14 +158,26 @@ export function toStructuredRun(results) {
|
|
|
130
158
|
skipped: counts.skipped,
|
|
131
159
|
results: results.map((result) => {
|
|
132
160
|
const guidance = fixFor(result);
|
|
161
|
+
const status = checkStatus(result);
|
|
133
162
|
return {
|
|
134
163
|
id: result.id,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
164
|
+
// Text a service chose can reach these three fields; the report is a
|
|
165
|
+
// sink for the one sanitiser (spec A8 #6).
|
|
166
|
+
name: sanitizeText(result.name),
|
|
167
|
+
status,
|
|
168
|
+
detail: sanitizeText(result.detail),
|
|
138
169
|
destructive: result.destructive === true,
|
|
139
170
|
...(result.error ? { errorKind: result.error.kind } : {}),
|
|
140
|
-
...(
|
|
171
|
+
...(status === "SKIP" && result.skipKind !== undefined ? { skipKind: result.skipKind } : {}),
|
|
172
|
+
...(status === "FAIL" && result.expected !== undefined ? { expected: sanitizeText(result.expected) } : {}),
|
|
173
|
+
...(status === "FAIL" && result.actual !== undefined ? { actual: sanitizeText(result.actual) } : {}),
|
|
174
|
+
...(status === "PASS" && result.reference !== undefined ? { reference: sanitizeText(result.reference) } : {}),
|
|
175
|
+
...(guidance === undefined
|
|
176
|
+
? {}
|
|
177
|
+
: {
|
|
178
|
+
fix: sanitizeText(guidance.fix),
|
|
179
|
+
...(guidance.docs === undefined ? {} : { docs: guidance.docs }),
|
|
180
|
+
}),
|
|
141
181
|
};
|
|
142
182
|
}),
|
|
143
183
|
};
|