@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.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/dist/baseline.d.ts +109 -0
  3. package/dist/baseline.js +351 -0
  4. package/dist/catalogue.js +10 -0
  5. package/dist/check.d.ts +57 -2
  6. package/dist/check.js +46 -6
  7. package/dist/ci-report.d.ts +74 -0
  8. package/dist/ci-report.js +391 -0
  9. package/dist/config.d.ts +205 -0
  10. package/dist/config.js +1011 -0
  11. package/dist/denied-env.d.ts +33 -0
  12. package/dist/denied-env.js +86 -0
  13. package/dist/errors.d.ts +44 -1
  14. package/dist/errors.js +151 -2
  15. package/dist/guard/budget.d.ts +135 -0
  16. package/dist/guard/budget.js +199 -0
  17. package/dist/guard/ci-event.d.ts +50 -0
  18. package/dist/guard/ci-event.js +125 -0
  19. package/dist/guard/mainnet-optin.d.ts +58 -0
  20. package/dist/guard/mainnet-optin.js +95 -0
  21. package/dist/guard/networks.d.ts +50 -0
  22. package/dist/guard/networks.js +80 -0
  23. package/dist/guard/rpc-identity.d.ts +45 -0
  24. package/dist/guard/rpc-identity.js +156 -0
  25. package/dist/guard/rpc-in-use.d.ts +48 -0
  26. package/dist/guard/rpc-in-use.js +84 -0
  27. package/dist/index.d.ts +31 -2
  28. package/dist/index.js +27 -1
  29. package/dist/mpp/channel-commitment.d.ts +48 -2
  30. package/dist/mpp/channel-commitment.js +80 -4
  31. package/dist/mpp/channel-credential.js +3 -0
  32. package/dist/mpp/channel.js +29 -0
  33. package/dist/mpp/charge.d.ts +2 -0
  34. package/dist/mpp/charge.js +17 -1
  35. package/dist/mpp/network.js +4 -1
  36. package/dist/mpp/suite.js +10 -2
  37. package/dist/report.d.ts +163 -0
  38. package/dist/report.js +282 -0
  39. package/dist/sanitize.d.ts +52 -0
  40. package/dist/sanitize.js +106 -0
  41. package/dist/settlement.d.ts +14 -0
  42. package/dist/settlement.js +1 -1
  43. package/dist/verdict.d.ts +24 -0
  44. package/dist/verdict.js +46 -0
  45. package/dist/versions.d.ts +50 -0
  46. package/dist/versions.js +123 -0
  47. package/dist/x402/chains/evm.js +3 -0
  48. package/dist/x402/chains/index.d.ts +8 -0
  49. package/dist/x402/chains/index.js +13 -2
  50. package/dist/x402/chains/stellar.d.ts +8 -1
  51. package/dist/x402/chains/stellar.js +125 -1
  52. package/dist/x402/chains/types.d.ts +68 -0
  53. package/dist/x402/plan.d.ts +82 -0
  54. package/dist/x402/plan.js +146 -0
  55. package/dist/x402/rejected-request.d.ts +146 -0
  56. package/dist/x402/rejected-request.js +269 -0
  57. package/dist/x402/requirements.d.ts +1 -0
  58. package/dist/x402/requirements.js +37 -4
  59. package/dist/x402/simulator.d.ts +52 -1
  60. package/dist/x402/simulator.js +452 -82
  61. package/package.json +1 -1
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The pull request comment and the job summary (spec A4, A5), as pure
3
+ * functions over the run report and, when there is one, the baseline of the
4
+ * default branch.
5
+ *
6
+ * Every value that can carry text a service chose goes through
7
+ * `sanitizeForMarkdown`: one line, links and mentions removed, 300 characters at
8
+ * most, Markdown and HTML escaped. What is not passed through it is a constant
9
+ * of this file, a number, or a value checked against a fixed set (an outcome, a
10
+ * status, a protocol, a version, a docs link on usewasit.dev).
11
+ */
12
+ import { type Baseline, type History } from "./baseline.js";
13
+ import { type RunReport } from "./report.js";
14
+ import { type ToolVersions } from "./versions.js";
15
+ /** The comment that starts with this is the one Wasit updates. */
16
+ export declare const COMMENT_MARKER = "<!-- wasit-report -->";
17
+ export interface CiReportInput {
18
+ readonly report: RunReport;
19
+ /** The baseline of the default branch, when one was found and could be read. */
20
+ readonly baseline?: Baseline;
21
+ /** Why no baseline could be used, when one was looked for: shown in place of "no baseline yet". */
22
+ readonly baselineNote?: string;
23
+ /** The id of the run on main the baseline came from: the last green one (D-022b). */
24
+ readonly baselineRun?: number;
25
+ /**
26
+ * The history of every completed run on main, failed ones included (D-022b),
27
+ * for the recent-failures line. Absent: the baseline's own history.
28
+ */
29
+ readonly history?: History;
30
+ /** Values no output may carry (a header value, a key, an RPC url). */
31
+ readonly secrets?: readonly string[];
32
+ }
33
+ /** The pull request comment: the marker, then the report. */
34
+ export declare function renderComment(input: CiReportInput): string;
35
+ /** The job summary: the same text without the marker. */
36
+ export declare function renderSummary(input: CiReportInput): string;
37
+ /** The pull request comment for a run that left no report: the marker, then the fixed text. */
38
+ export declare function renderNoReportComment(versions: ToolVersions): string;
39
+ /** The job summary for a run that left no report: the same text without the marker. */
40
+ export declare function renderNoReportSummary(versions: ToolVersions): string;
41
+ /** What a GitHub check run shows: its title, its summary and how it ended. */
42
+ export interface CheckRunOutput {
43
+ /** At most 255 characters: the verdict and the counts, nothing a service chose. */
44
+ readonly title: string;
45
+ /** The job summary's text: the same sanitised report. */
46
+ readonly summary: string;
47
+ readonly conclusion: "success" | "failure" | "neutral";
48
+ }
49
+ /**
50
+ * The check run "Wasit conformance" at the end of a run: success for a run that
51
+ * exits 0, failure for 1, neutral for no verdict. The title holds only the
52
+ * verdict word and counts; the summary is the job summary.
53
+ */
54
+ export declare function renderCheckRun(input: CiReportInput): CheckRunOutput;
55
+ /** The check run for a run that left no report: neutral, with the fixed text of the no-report comment. */
56
+ export declare function renderNoReportCheckRun(versions: ToolVersions): CheckRunOutput;
57
+ export interface RunningCommentInput {
58
+ /** When the run started, as an ISO time; anything else is left out. */
59
+ readonly startedAt: string;
60
+ /** The run's page; left out unless it has the shape GitHub gives it. */
61
+ readonly runUrl?: string;
62
+ /** The environment the run tests, when the workflow names one. */
63
+ readonly environment?: string;
64
+ /** Values no output may carry. */
65
+ readonly secrets?: readonly string[];
66
+ }
67
+ /**
68
+ * The pull request comment while Wasit runs (Najmi, 2026-11-20): the marker,
69
+ * then a fixed line with the start time and a link to the run. The result
70
+ * replaces it when the run ends. The only value from outside is the
71
+ * environment's name, which goes through the sanitiser; the link is used only
72
+ * when it has the shape of a GitHub run page.
73
+ */
74
+ export declare function renderRunningComment(input: RunningCommentInput): string;
@@ -0,0 +1,391 @@
1
+ /**
2
+ * The pull request comment and the job summary (spec A4, A5), as pure
3
+ * functions over the run report and, when there is one, the baseline of the
4
+ * default branch.
5
+ *
6
+ * Every value that can carry text a service chose goes through
7
+ * `sanitizeForMarkdown`: one line, links and mentions removed, 300 characters at
8
+ * most, Markdown and HTML escaped. What is not passed through it is a constant
9
+ * of this file, a number, or a value checked against a fixed set (an outcome, a
10
+ * status, a protocol, a version, a docs link on usewasit.dev).
11
+ */
12
+ import { baselineProblem, diffReports, recentFailures, } from "./baseline.js";
13
+ import { checkGroup, describeTotals, } from "./report.js";
14
+ import { sanitizeForMarkdown } from "./sanitize.js";
15
+ import { isShortCommit } from "./versions.js";
16
+ import { runExitCode } from "./verdict.js";
17
+ /** The comment that starts with this is the one Wasit updates. */
18
+ export const COMMENT_MARKER = "<!-- wasit-report -->";
19
+ /** GitHub refuses a comment over 65,536 characters; stay well under. */
20
+ const MAX_COMMENT_CHARACTERS = 60_000;
21
+ const MAX_FAILURES_SHOWN = 20;
22
+ const MAX_CHANGES_SHOWN = 30;
23
+ const MAX_RECENT_SHOWN = 10;
24
+ /** Docs links go in only if they point at the site: the file they come from is data. */
25
+ const DOCS_LINK = /^https:\/\/usewasit\.dev\/[A-Za-z0-9/_.-]*$/;
26
+ /** A check's status at a glance (Najmi, 2026-11-20): emoji are safe in a comment, which is HTML. */
27
+ const STATUS_MARK = { PASS: "✅", FAIL: "❌", SKIP: "⚪", ERROR: "⚠️" };
28
+ const OUTCOME_MARK = {
29
+ conformant: "✅",
30
+ "non-conformant": "❌",
31
+ "no-verdict": "⚠️",
32
+ unsupported: "⚪",
33
+ };
34
+ const VERDICT_MARK = {
35
+ conformant: "✅",
36
+ "non-conformant": "❌",
37
+ regression: "❌",
38
+ "nothing graded": "⚪",
39
+ "no verdict": "⚠️",
40
+ };
41
+ /** Endpoints shown with a table of their checks; a config with more points at the report file for the rest. */
42
+ const MAX_ENDPOINT_SECTIONS = 10;
43
+ /** A Stellar transaction hash: the only reference a payment proof links, and only on the test network. */
44
+ const STELLAR_TX = /^[0-9a-f]{64}$/;
45
+ /** A run's page, as `GITHUB_SERVER_URL/GITHUB_REPOSITORY/actions/runs/GITHUB_RUN_ID` gives it. */
46
+ const RUN_URL = /^https:\/\/[A-Za-z0-9.-]+(?::[0-9]{1,5})?\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/actions\/runs\/[0-9]{1,20}$/;
47
+ const VERSION = /^[0-9A-Za-z.+-]{1,40}$/;
48
+ const GROUP_LABEL = {
49
+ challenge: "challenge",
50
+ payment: "payment",
51
+ mppCharge: "MPP charge",
52
+ mppChannel: "MPP channel",
53
+ };
54
+ const GROUP_ORDER = ["challenge", "payment", "mppCharge", "mppChannel"];
55
+ const SKIP_KIND_TEXT = {
56
+ "read-only": "read-only tier",
57
+ "needs-payer": "no payer key",
58
+ unsupported: "unsupported",
59
+ "resource-consumed": "resource consumed",
60
+ "not-applicable": "not applicable",
61
+ dependency: "an earlier check did not pass",
62
+ };
63
+ const CHANGE_ORDER = [
64
+ "regression",
65
+ "new-failure",
66
+ "status-changed",
67
+ "fixed",
68
+ "graded",
69
+ "new-endpoint",
70
+ "removed-endpoint",
71
+ ];
72
+ function version(value) {
73
+ return VERSION.test(value) ? value : "unknown";
74
+ }
75
+ /** "Wasit 0.7.0 (core 0.7.0)", and ", built from commit 0123456" when an Action build names its commit. */
76
+ function wasitText(wasit) {
77
+ const build = isShortCommit(wasit.build) ? `, built from commit ${wasit.build}` : "";
78
+ return `Wasit ${version(wasit.cli)} (core ${version(wasit.core)})${build}`;
79
+ }
80
+ /** The reason follows "unsupported." in the list, so it starts a sentence. */
81
+ function upperFirst(text) {
82
+ return text.charAt(0).toUpperCase() + text.slice(1);
83
+ }
84
+ /** "challenge 5/5", or "payment not run: read-only tier" when the whole group was skipped for one reason. */
85
+ function groupText(endpoint, group) {
86
+ const results = endpoint.results.filter((result) => checkGroup(result.id, endpoint.protocol) === group);
87
+ if (results.length === 0)
88
+ return undefined;
89
+ const count = (status) => results.filter((result) => result.status === status).length;
90
+ const label = GROUP_LABEL[group];
91
+ const skipped = count("SKIP");
92
+ if (skipped === results.length) {
93
+ const kinds = new Set(results.map((result) => result.skipKind));
94
+ const [only] = [...kinds];
95
+ return kinds.size === 1 && only !== undefined ? `${label} not run: ${SKIP_KIND_TEXT[only]}` : `${label} not run`;
96
+ }
97
+ const parts = [`${label} ${count("PASS")}/${results.length}`];
98
+ if (count("FAIL") > 0)
99
+ parts.push(`${count("FAIL")} failed`);
100
+ if (count("ERROR") > 0)
101
+ parts.push(`${count("ERROR")} could not run`);
102
+ if (skipped > 0)
103
+ parts.push(`${skipped} skipped`);
104
+ return parts.join(", ");
105
+ }
106
+ function checksCell(endpoint) {
107
+ return GROUP_ORDER.map((group) => groupText(endpoint, group)).filter((text) => text !== undefined).join("; ");
108
+ }
109
+ /** The baseline the run is compared with (one of another environment is not), and the run's verdict. */
110
+ function verdictOf(input) {
111
+ const { report } = input;
112
+ // A baseline from another environment is another service: it is not compared.
113
+ const problem = input.baseline === undefined ? undefined : baselineProblem(report, input.baseline.report);
114
+ const baseline = problem === undefined ? input.baseline : undefined;
115
+ const note = problem ?? input.baselineNote;
116
+ const verdict = runExitCode(report, baseline?.report);
117
+ const couldNotRun = report.endpoints.some((endpoint) => endpoint.results.some((result) => result.status === "ERROR"));
118
+ const word = verdict.code === 0
119
+ ? "conformant"
120
+ : verdict.code === 1
121
+ ? report.totals.nonConformant > 0
122
+ ? "non-conformant"
123
+ : "regression"
124
+ : report.totals.graded === 0 && !couldNotRun
125
+ ? "nothing graded"
126
+ : "no verdict";
127
+ return { baseline, note, code: verdict.code, word };
128
+ }
129
+ /**
130
+ * The payment proof under an endpoint: a link to X402-06's transaction on
131
+ * Stellar Expert, and only when every part is Wasit's own and checked: the run
132
+ * is on `stellar:testnet`, X402-06 passed, and its reference (read back from the
133
+ * chain by the check) is a 64-character lower-case hex hash. Never a link built
134
+ * from a service's text.
135
+ */
136
+ function paymentProof(endpoint, network) {
137
+ if (network !== "stellar:testnet")
138
+ return undefined;
139
+ const honest = endpoint.results.find((result) => result.id === "X402-06" && result.status === "PASS");
140
+ const reference = honest?.reference;
141
+ if (reference === undefined || !STELLAR_TX.test(reference))
142
+ return undefined;
143
+ return (`**Payment proof**: X402-06 settled on stellar:testnet, ` +
144
+ `[tx ${reference.slice(0, 4)}…${reference.slice(-4)} on Stellar Expert](https://stellar.expert/explorer/testnet/tx/${reference}).`);
145
+ }
146
+ /** An endpoint's heading and the table of its checks, each with its mark, then its payment proof. */
147
+ function endpointSection(endpoint, network, md) {
148
+ const out = [
149
+ "",
150
+ `### ${OUTCOME_MARK[endpoint.outcome]} ${md(endpoint.name)} · ${endpoint.protocol} · ${endpoint.outcome}`,
151
+ "",
152
+ "| | Check | Result |",
153
+ "| --- | --- | --- |",
154
+ ...endpoint.results.map((result) => `| ${STATUS_MARK[result.status]} | ${md(result.id)} ${md(result.name)} | ${result.status} |`),
155
+ ];
156
+ const proof = paymentProof(endpoint, network);
157
+ if (proof !== undefined)
158
+ out.push("", proof);
159
+ return out;
160
+ }
161
+ /** Every check's detail, folded away at the end, so a long report cuts here and not in the verdict. */
162
+ function detailsBlock(report, md) {
163
+ const out = ["", "<details><summary>Details of each check</summary>", ""];
164
+ for (const endpoint of report.endpoints.slice(0, MAX_ENDPOINT_SECTIONS)) {
165
+ out.push(`**${md(endpoint.name)}**`, "");
166
+ let lastSkip;
167
+ for (const result of endpoint.results) {
168
+ // A skip with the reason of the skip just above it says so instead of repeating it.
169
+ const repeated = result.status === "SKIP" && lastSkip === result.detail;
170
+ lastSkip = result.status === "SKIP" ? result.detail : undefined;
171
+ const detail = repeated ? "the same reason as above." : md(result.detail);
172
+ out.push(`- ${STATUS_MARK[result.status]} ${md(result.id)} ${md(result.name)}: ${detail}`);
173
+ }
174
+ out.push("");
175
+ }
176
+ out.push("</details>");
177
+ return out;
178
+ }
179
+ function renderBody(input) {
180
+ const { report } = input;
181
+ const md = (value) => sanitizeForMarkdown(value, { redact: input.secrets ?? [] });
182
+ const { baseline, note, word } = verdictOf(input);
183
+ const sdk = report.sdk;
184
+ const out = [
185
+ `**Wasit: ${VERDICT_MARK[word]} ${word}.** ${describeTotals(report.totals)} on ${md(report.environment)}, ${md(report.network)}. ` +
186
+ `${wasitText(report.wasit)}, x402 v2, ` +
187
+ `@x402/core ${version(sdk["@x402/core"])}, @x402/stellar ${version(sdk["@x402/stellar"])}, ` +
188
+ `@stellar/mpp ${version(sdk["@stellar/mpp"])}, mppx ${version(sdk.mppx)}, ` +
189
+ `@stellar/stellar-sdk ${version(sdk["@stellar/stellar-sdk"])}.`,
190
+ "",
191
+ "| Endpoint | Protocol | Outcome | Checks |",
192
+ "| --- | --- | --- | --- |",
193
+ ...report.endpoints.map((endpoint) => `| ${md(endpoint.name)} | ${endpoint.protocol} | ${OUTCOME_MARK[endpoint.outcome]} ${endpoint.outcome} | ${checksCell(endpoint)} |`),
194
+ ];
195
+ for (const endpoint of report.endpoints.slice(0, MAX_ENDPOINT_SECTIONS))
196
+ out.push(...endpointSection(endpoint, report.network, md));
197
+ if (report.endpoints.length > MAX_ENDPOINT_SECTIONS) {
198
+ const rest = report.endpoints.length - MAX_ENDPOINT_SECTIONS;
199
+ out.push("", `${rest} more endpoint${rest === 1 ? " is" : "s are"} not shown check by check here; ` +
200
+ "the JSON report of wasit run has every check (in the Action, the log of the step Run Wasit).");
201
+ }
202
+ const notGraded = report.endpoints.filter((endpoint) => (endpoint.outcome === "unsupported" || endpoint.outcome === "no-verdict") && endpoint.reason !== undefined);
203
+ if (notGraded.length > 0) {
204
+ out.push("", "### Not graded");
205
+ for (const endpoint of notGraded)
206
+ out.push(`- **${md(endpoint.name)}**: ${endpoint.outcome}. ${md(upperFirst(endpoint.reason ?? ""))}`);
207
+ }
208
+ out.push("", "### Changed since main");
209
+ if (baseline === undefined) {
210
+ out.push(note === undefined
211
+ ? "No baseline on main yet, so nothing is compared. The next run on main creates it."
212
+ : `The baseline from main could not be used (${md(note)}), so nothing is compared and the history starts again with the next run on main.`);
213
+ }
214
+ else {
215
+ const changes = diffReports(report, baseline.report).sort((a, b) => CHANGE_ORDER.indexOf(a.kind) - CHANGE_ORDER.indexOf(b.kind));
216
+ out.push(comparedWith(baseline.report.startedAt, input.baselineRun));
217
+ if (changes.length === 0)
218
+ out.push("No change since main.");
219
+ for (const change of changes.slice(0, MAX_CHANGES_SHOWN))
220
+ out.push(`- ${describeChange(change, md)}`);
221
+ if (changes.length > MAX_CHANGES_SHOWN)
222
+ out.push(`- ${changes.length - MAX_CHANGES_SHOWN} more changes not shown.`);
223
+ }
224
+ const failures = report.endpoints.flatMap((endpoint) => endpoint.results.filter((result) => result.status === "FAIL").map((result) => ({ endpoint, result })));
225
+ if (failures.length > 0) {
226
+ out.push("", "### Failures");
227
+ for (const { endpoint, result } of failures.slice(0, MAX_FAILURES_SHOWN)) {
228
+ out.push("", `**${md(endpoint.name)}: ${md(result.id)} ${md(result.name)}**`, `- Found: ${md(result.detail)}`);
229
+ // What the check expected and what the service sent: quoted from the service, so cut and escaped like the rest.
230
+ if (result.expected !== undefined)
231
+ out.push(`- Expected: ${md(result.expected)}`);
232
+ if (result.actual !== undefined)
233
+ out.push(`- Actual: ${md(result.actual)}`);
234
+ if (result.fix !== undefined)
235
+ out.push(`- Fix: ${md(result.fix)}`);
236
+ if (result.docs !== undefined && DOCS_LINK.test(result.docs))
237
+ out.push(`- Docs: ${result.docs}`);
238
+ }
239
+ if (failures.length > MAX_FAILURES_SHOWN) {
240
+ const rest = failures.length - MAX_FAILURES_SHOWN;
241
+ out.push("", `${rest} more failure${rest === 1 ? "" : "s"} not shown.`);
242
+ }
243
+ }
244
+ const recent = baseline === undefined ? [] : recentFailures(input.history ?? baseline.history);
245
+ if (recent.length > 0) {
246
+ out.push("", "### Recent failures on main");
247
+ for (const item of recent.slice(0, MAX_RECENT_SHOWN)) {
248
+ out.push(`- ${md(item.endpoint)} ${md(item.check)}: failed in ${item.failed} of the last ${item.runs} runs on main`);
249
+ }
250
+ }
251
+ if (report.notes.length > 0) {
252
+ out.push("", "### Notes");
253
+ for (const item of report.notes)
254
+ out.push(`- ${md(item)}`);
255
+ }
256
+ out.push(...detailsBlock(report, md));
257
+ return out.join("\n");
258
+ }
259
+ /** "2026-11-15 10:00 UTC", from the report's own start time; nothing that is not a time. */
260
+ function utcMinute(iso) {
261
+ const time = Date.parse(iso);
262
+ if (!Number.isFinite(time))
263
+ return undefined;
264
+ return `${new Date(time).toISOString().slice(0, 16).replace("T", " ")} UTC`;
265
+ }
266
+ /**
267
+ * The line that says what "Changed since main" compares with (D-022b): the last
268
+ * green run on main, so a FAIL that main has now is not read as this run's.
269
+ */
270
+ function comparedWith(startedAt, run) {
271
+ const when = utcMinute(startedAt);
272
+ const id = run !== undefined && Number.isSafeInteger(run) && run > 0 ? run : undefined;
273
+ const started = when === undefined ? "" : `started ${when}`;
274
+ const which = id !== undefined ? `: run ${id}${started === "" ? "" : `, ${started}`}` : started === "" ? "" : `, ${started}`;
275
+ return `Compared with the last green run on main${which}. Runs on main that failed after it are counted under Recent failures on main, not here.`;
276
+ }
277
+ function describeChange(change, md) {
278
+ const endpoint = md(change.endpoint);
279
+ const check = md(change.check ?? "");
280
+ switch (change.kind) {
281
+ case "regression":
282
+ return `Regression: ${endpoint} was ${change.from} on main and is now ${change.to}.`;
283
+ case "new-failure":
284
+ return `New FAIL: ${endpoint} ${check} (was ${change.from} on main).`;
285
+ case "fixed":
286
+ return `Fixed: ${endpoint} ${check} (was FAIL on main).`;
287
+ case "status-changed":
288
+ return `${endpoint} ${check}: ${change.from} on main, now ${change.to}.`;
289
+ case "graded":
290
+ return `Now graded: ${endpoint} (was ${change.from} on main).`;
291
+ case "new-endpoint":
292
+ return `New endpoint: ${endpoint}.`;
293
+ case "removed-endpoint":
294
+ return `Removed endpoint: ${endpoint}.`;
295
+ }
296
+ }
297
+ /** A text over the limit is cut at a line break, and says so. */
298
+ function withinLimit(text) {
299
+ if (text.length <= MAX_COMMENT_CHARACTERS)
300
+ return text;
301
+ const cut = text.lastIndexOf("\n", MAX_COMMENT_CHARACTERS - 200);
302
+ return `${text.slice(0, cut > 0 ? cut : MAX_COMMENT_CHARACTERS - 200)}\n\n(The rest is cut: the JSON report of wasit run has all of it; in the Action, the log of the step Run Wasit.)`;
303
+ }
304
+ /** The pull request comment: the marker, then the report. */
305
+ export function renderComment(input) {
306
+ return withinLimit(`${COMMENT_MARKER}\n${renderBody(input)}\n`);
307
+ }
308
+ /** The job summary: the same text without the marker. */
309
+ export function renderSummary(input) {
310
+ return withinLimit(`${renderBody(input)}\n`);
311
+ }
312
+ /**
313
+ * What the comment says when the run left no report to render: the service did
314
+ * not start, never answered, or the config could not be used. The comment from
315
+ * the push before must not stay next to a red check, so this replaces it. The
316
+ * text is fixed: nothing from the service, the config or the broken report is
317
+ * quoted, because none of it can be trusted to be there or to be safe.
318
+ */
319
+ function renderNoReportBody(versions) {
320
+ const sdk = versions.sdk;
321
+ return [
322
+ "**Wasit: ⚠️ no verdict.** The run ended before it wrote a report, so nothing was graded. " +
323
+ `${wasitText(versions.wasit)}, x402 v2, ` +
324
+ `@x402/core ${version(sdk["@x402/core"])}, @x402/stellar ${version(sdk["@x402/stellar"])}, ` +
325
+ `@stellar/mpp ${version(sdk["@stellar/mpp"])}, mppx ${version(sdk.mppx)}, ` +
326
+ `@stellar/stellar-sdk ${version(sdk["@stellar/stellar-sdk"])}.`,
327
+ "",
328
+ "This is not a failure of the service and not a pass: the service did not start or never answered, " +
329
+ "or the config could not be used. The reason is in the job log. This comment is replaced on the next push.",
330
+ ].join("\n");
331
+ }
332
+ /** The pull request comment for a run that left no report: the marker, then the fixed text. */
333
+ export function renderNoReportComment(versions) {
334
+ return `${COMMENT_MARKER}\n${renderNoReportBody(versions)}\n`;
335
+ }
336
+ /** The job summary for a run that left no report: the same text without the marker. */
337
+ export function renderNoReportSummary(versions) {
338
+ return `${renderNoReportBody(versions)}\n`;
339
+ }
340
+ /** The check run's limits, as GitHub sets them. */
341
+ const MAX_CHECK_TITLE = 255;
342
+ const MAX_CHECK_SUMMARY = 65_535;
343
+ /** "10 passed, 1 failed, 1 could not run, 1 skipped", over every endpoint. */
344
+ function statusCounts(report) {
345
+ const all = report.endpoints.flatMap((endpoint) => endpoint.results);
346
+ const count = (status) => all.filter((result) => result.status === status).length;
347
+ const parts = [`${count("PASS")} passed`];
348
+ if (count("FAIL") > 0)
349
+ parts.push(`${count("FAIL")} failed`);
350
+ if (count("ERROR") > 0)
351
+ parts.push(`${count("ERROR")} could not run`);
352
+ if (count("SKIP") > 0)
353
+ parts.push(`${count("SKIP")} skipped`);
354
+ return parts.join(", ");
355
+ }
356
+ /**
357
+ * The check run "Wasit conformance" at the end of a run: success for a run that
358
+ * exits 0, failure for 1, neutral for no verdict. The title holds only the
359
+ * verdict word and counts; the summary is the job summary.
360
+ */
361
+ export function renderCheckRun(input) {
362
+ const { code, word } = verdictOf(input);
363
+ return {
364
+ title: `${VERDICT_MARK[word]} ${word} · ${statusCounts(input.report)}`.slice(0, MAX_CHECK_TITLE),
365
+ summary: renderSummary(input).slice(0, MAX_CHECK_SUMMARY),
366
+ conclusion: code === 0 ? "success" : code === 1 ? "failure" : "neutral",
367
+ };
368
+ }
369
+ /** The check run for a run that left no report: neutral, with the fixed text of the no-report comment. */
370
+ export function renderNoReportCheckRun(versions) {
371
+ return {
372
+ title: "⚠️ no verdict · the run ended before it wrote a report",
373
+ summary: renderNoReportSummary(versions).slice(0, MAX_CHECK_SUMMARY),
374
+ conclusion: "neutral",
375
+ };
376
+ }
377
+ /**
378
+ * The pull request comment while Wasit runs (Najmi, 2026-11-20): the marker,
379
+ * then a fixed line with the start time and a link to the run. The result
380
+ * replaces it when the run ends. The only value from outside is the
381
+ * environment's name, which goes through the sanitiser; the link is used only
382
+ * when it has the shape of a GitHub run page.
383
+ */
384
+ export function renderRunningComment(input) {
385
+ const md = (value) => sanitizeForMarkdown(value, { redact: input.secrets ?? [] });
386
+ const when = utcMinute(input.startedAt);
387
+ const environment = input.environment !== undefined && input.environment.trim() !== "" ? ` on ${md(input.environment)}` : "";
388
+ const started = when === undefined ? "" : ` · started ${when}`;
389
+ const link = input.runUrl !== undefined && RUN_URL.test(input.runUrl) ? ` · [follow the run](${input.runUrl})` : "";
390
+ return `${COMMENT_MARKER}\n⏳ **Wasit is running**${environment}${started}${link}\n\nThe result replaces this comment when the run ends.\n`;
391
+ }
@@ -0,0 +1,205 @@
1
+ /**
2
+ * `wasit.config.json`, version 1: the schema and the loader.
3
+ *
4
+ * One file, read the same way by `wasit run`, the Action and `wasit init`. It
5
+ * is committed, so a pull request can change it, and every run reads it. That
6
+ * shapes the loader:
7
+ *
8
+ * - strict: an unknown key or version is an error that names the key, never a
9
+ * setting that is silently dropped;
10
+ * - closed: a secret, a secret variable name, the mainnet opt-in, a flag that
11
+ * enables MPP-13 and a per-payment cap have no place in the file, and each is
12
+ * refused with its own reason (the only cap the file may set is a LOWER
13
+ * per-run one, `maxRunUsd`, at most 5);
14
+ * - quiet: an error names the key and never the value, so a secret that was
15
+ * pasted into the file by mistake does not come back through the message;
16
+ * - bounded: a path cannot leave the origin of `baseUrl`, and a header that is
17
+ * a credential travels in an environment variable, not in the file.
18
+ *
19
+ * Pure and offline: it reads a file at most, and sends and signs nothing.
20
+ */
21
+ import { type ProtocolId } from "./catalogue.js";
22
+ import { ConfigurationError } from "./errors.js";
23
+ import { type NetworkClass } from "./guard/networks.js";
24
+ /** The only version this loader reads. */
25
+ export declare const CONFIG_VERSION = 1;
26
+ /** One problem found in a config, located by the key it is about. */
27
+ export interface ConfigIssue {
28
+ /** Dotted path of the key, e.g. `endpoints[1].headers.authorization`. Empty for the file itself. */
29
+ readonly path: string;
30
+ /** What is wrong and what to do. Never contains a value from the file. */
31
+ readonly message: string;
32
+ }
33
+ /**
34
+ * The config cannot be used. A `ConfigurationError`: nothing is learned about
35
+ * any service, so it is no verdict and exits 2.
36
+ */
37
+ export declare class ConfigError extends ConfigurationError {
38
+ readonly issues: readonly ConfigIssue[];
39
+ constructor(title: string, issues: readonly ConfigIssue[]);
40
+ }
41
+ /** A JSON value, as a request body may be. */
42
+ export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
43
+ readonly [key: string]: JsonValue;
44
+ };
45
+ export interface ReadyConfig {
46
+ readonly url: string;
47
+ readonly timeoutSeconds: number;
48
+ }
49
+ export interface ServiceConfig {
50
+ readonly start?: string;
51
+ readonly ready?: ReadyConfig;
52
+ }
53
+ export interface PinConfig {
54
+ readonly payTo: string;
55
+ readonly asset: string;
56
+ }
57
+ export interface EnvironmentConfig {
58
+ /** An http(s) URL with no credentials, query or fragment; no trailing slash. */
59
+ readonly baseUrl: string;
60
+ /** A CAIP-2 id. Default `stellar:testnet`. */
61
+ readonly network: string;
62
+ /** Must be true for any payment check to run on this environment. Default false. */
63
+ readonly operatedByMe: boolean;
64
+ readonly pinned?: PinConfig;
65
+ /** Env `WASIT_RPC_URL` wins. Only its origin is ever printed. */
66
+ readonly rpcUrl?: string;
67
+ /** A LOWER per-run cap in USD, above 0 and at most 5. */
68
+ readonly maxRunUsd?: number;
69
+ }
70
+ export interface RejectConfig {
71
+ readonly method?: string;
72
+ readonly headers: Readonly<Record<string, string>>;
73
+ readonly body?: JsonValue;
74
+ readonly note?: string;
75
+ }
76
+ export interface ChannelExpectation {
77
+ readonly token?: string;
78
+ readonly from?: string;
79
+ readonly to?: string;
80
+ readonly refundWaitingPeriod?: number;
81
+ }
82
+ export interface EndpointConfig {
83
+ readonly name: string;
84
+ readonly protocol: ProtocolId;
85
+ /** Starts with a single `/`; joined to `baseUrl`, it keeps the origin. */
86
+ readonly path: string;
87
+ /** Upper case. Default GET. */
88
+ readonly method: string;
89
+ readonly headers: Readonly<Record<string, string>>;
90
+ /** A JSON value (serialised by Wasit) or a string (sent verbatim). */
91
+ readonly body?: JsonValue;
92
+ readonly reject?: RejectConfig;
93
+ readonly channel?: string;
94
+ readonly expect?: ChannelExpectation;
95
+ }
96
+ export interface WasitConfig {
97
+ readonly version: 1;
98
+ readonly service?: ServiceConfig;
99
+ readonly defaultEnvironment?: string;
100
+ readonly environments: Readonly<Record<string, EnvironmentConfig>>;
101
+ readonly endpoints: readonly EndpointConfig[];
102
+ }
103
+ /** True for an http(s) URL on this machine with no credentials: the only kind a readiness wait may probe. */
104
+ export declare function isLoopbackUrl(url: string): boolean;
105
+ /**
106
+ * Joins a base URL and a path, keeping the base URL's origin.
107
+ *
108
+ * The path is held to the rules above, and the result is checked to have the
109
+ * origin of `baseUrl`: a path that could carry a request to another host is
110
+ * refused, not repaired (spec A8 #5).
111
+ *
112
+ * @throws {ConfigError} For a path that could leave the origin, or a base URL that is not one.
113
+ */
114
+ export declare function joinTarget(baseUrl: string, path: string): string;
115
+ /** The variable that carries the value of header `name`: upper case, `-` written as `_`. */
116
+ export declare function headerEnvName(name: string): string;
117
+ /**
118
+ * The headers given in the environment, by name in lower case.
119
+ *
120
+ * `WASIT_HEADER_<NAME>` carries the header `<NAME>` written in upper case with
121
+ * `-` as `_`. Values are secrets: they are never printed, and a refusal names
122
+ * the variable, not the value. A header Wasit sets itself cannot be given this
123
+ * way either; the credential-like names the file refuses are exactly what this
124
+ * is for.
125
+ *
126
+ * @throws {ConfigError} For a variable whose name or value cannot be a header.
127
+ */
128
+ export declare function headersFromEnv(env: Readonly<Record<string, string | undefined>>): Record<string, string>;
129
+ /**
130
+ * Validates parsed JSON as a version 1 config.
131
+ *
132
+ * @throws {ConfigError} Naming every key that is wrong, never a value.
133
+ */
134
+ export declare function validateConfig(value: unknown): WasitConfig;
135
+ /**
136
+ * Parses config text.
137
+ *
138
+ * @throws {ConfigError} For text that is not JSON (located by line and column, never quoted), or a config that is not valid.
139
+ */
140
+ export declare function parseConfig(text: string): WasitConfig;
141
+ /**
142
+ * Reads and parses a config file.
143
+ *
144
+ * @throws {ConfigError} For a file that cannot be read, is too large, or is not a valid config.
145
+ */
146
+ export declare function readConfigFile(path: string | URL): WasitConfig;
147
+ export interface RunSelection {
148
+ /** `--env`. Else the config's `defaultEnvironment`, else the only environment. */
149
+ readonly environment?: string;
150
+ /** `--endpoint`, by name. Else all, in the config's order. */
151
+ readonly endpoints?: readonly string[];
152
+ }
153
+ export interface ResolvedReject {
154
+ readonly method?: string;
155
+ readonly headers: Readonly<Record<string, string>>;
156
+ readonly body?: string;
157
+ readonly note?: string;
158
+ }
159
+ export interface ResolvedEndpoint {
160
+ readonly name: string;
161
+ readonly protocol: ProtocolId;
162
+ readonly method: string;
163
+ readonly path: string;
164
+ /** `baseUrl` + `path`; always the origin of `baseUrl`. */
165
+ readonly url: string;
166
+ /** The file's headers with `WASIT_HEADER_*` over them. Values are secrets: never print this object. */
167
+ readonly headers: Readonly<Record<string, string>>;
168
+ /** Serialised: a JSON value as JSON, a string verbatim. */
169
+ readonly body?: string;
170
+ /** Exactly what the file says; the check that uses it decides how it applies to the request. */
171
+ readonly reject?: ResolvedReject;
172
+ readonly channel?: string;
173
+ readonly expect?: ChannelExpectation;
174
+ }
175
+ export interface ResolvedRun {
176
+ readonly environment: string;
177
+ readonly baseUrl: string;
178
+ readonly network: string;
179
+ readonly networkClass: NetworkClass;
180
+ readonly operatedByMe: boolean;
181
+ readonly pinned?: PinConfig;
182
+ /** Full URL: may carry a key. Print only {@link urlOrigin} of it. */
183
+ readonly rpcUrl?: string;
184
+ readonly maxRunUsd?: number;
185
+ readonly service?: ServiceConfig;
186
+ readonly endpoints: readonly ResolvedEndpoint[];
187
+ }
188
+ /**
189
+ * Turns a validated config into what a run uses.
190
+ *
191
+ * Picks the environment and endpoints, joins each path to the base URL, applies
192
+ * the `WASIT_HEADER_*` and `WASIT_RPC_URL` variables of `env` (injected, so a
193
+ * test needs no process state), and serialises bodies.
194
+ *
195
+ * @throws {ConfigError} For an environment or endpoint that does not exist, a bad variable, or a path that could leave the origin.
196
+ */
197
+ export declare function resolveRun(config: WasitConfig, selection: RunSelection, env: Readonly<Record<string, string | undefined>>): ResolvedRun;
198
+ /** The origin of a URL, which is all of an RPC URL that is ever printed: a key often rides in its path or query. */
199
+ export declare function urlOrigin(url: string): string;
200
+ /**
201
+ * A short description of a run for a terminal or a log: the environment, base
202
+ * URL, network, the RPC origin and the endpoints. No header value, no pin
203
+ * secret, no RPC path or query. Sanitised.
204
+ */
205
+ export declare function describeRun(run: ResolvedRun): string;