@wasit-dev/cli 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -3
- package/dist/dashboard/App.d.ts +9 -0
- package/dist/dashboard/App.js +39 -0
- package/dist/dashboard/CatalogueView.d.ts +5 -0
- package/dist/dashboard/CatalogueView.js +23 -0
- package/dist/dashboard/Home.d.ts +8 -0
- package/dist/dashboard/Home.js +54 -0
- package/dist/dashboard/RunView.d.ts +10 -0
- package/dist/dashboard/RunView.js +165 -0
- package/dist/dashboard/TargetForm.d.ts +8 -0
- package/dist/dashboard/TargetForm.js +60 -0
- package/dist/dashboard/WalletView.d.ts +5 -0
- package/dist/dashboard/WalletView.js +253 -0
- package/dist/dashboard/banner.d.ts +12 -0
- package/dist/dashboard/banner.js +32 -0
- package/dist/dashboard/env-file.d.ts +20 -0
- package/dist/dashboard/env-file.js +67 -0
- package/dist/dashboard/environment.d.ts +14 -0
- package/dist/dashboard/environment.js +25 -0
- package/dist/dashboard/format.d.ts +6 -0
- package/dist/dashboard/format.js +10 -0
- package/dist/dashboard/runners.d.ts +15 -0
- package/dist/dashboard/runners.js +45 -0
- package/dist/dashboard/theme.d.ts +21 -0
- package/dist/dashboard/theme.js +21 -0
- package/dist/dashboard/useElapsedMs.d.ts +10 -0
- package/dist/dashboard/useElapsedMs.js +21 -0
- package/dist/dashboard/useSpinnerFrame.d.ts +7 -0
- package/dist/dashboard/useSpinnerFrame.js +20 -0
- package/dist/dashboard/wallet-actions.d.ts +41 -0
- package/dist/dashboard/wallet-actions.js +64 -0
- package/dist/index.js +15 -2
- package/dist/version.d.ts +1 -0
- package/dist/version.js +8 -0
- package/dist/wallet-command.d.ts +14 -0
- package/dist/wallet-command.js +311 -0
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Protocol-compliance testing for **x402** and **MPP** on Stellar, from your terminal.
|
|
4
4
|
|
|
5
|
-
`wasit` runs the real payment flow against a live service
|
|
5
|
+
`wasit` runs the real payment flow against a live service, not a mock of it, and it is not a schema validator: a response can have every field in the right place and still take money without settling it.
|
|
6
|
+
|
|
7
|
+
For MPP charge mode it verifies the settlement independently — via Stellar RPC and the token contract's own on-chain transfer event, rather than the response the service returns. The x402 checks exercise the same real flow but judge the target on its HTTP behaviour: `X402-06` passes on a 2xx. Giving it the same on-chain verification is tracked for 0.4.0.
|
|
6
8
|
|
|
7
9
|
**Testnet only.** Several checks settle real transactions — do not point this at pubnet or use production keys.
|
|
8
10
|
|
|
@@ -10,15 +12,21 @@ Protocol-compliance testing for **x402** and **MPP** on Stellar, from your termi
|
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
14
|
# run once, no install
|
|
13
|
-
npx @wasit-dev/cli test --target <your-service-url>
|
|
15
|
+
npx @wasit-dev/cli test --target <your-service-url> --read-only
|
|
14
16
|
|
|
15
17
|
# or install globally
|
|
16
18
|
npm install -g @wasit-dev/cli
|
|
17
|
-
wasit test --target <your-service-url>
|
|
19
|
+
wasit test --target <your-service-url> --read-only
|
|
18
20
|
```
|
|
19
21
|
|
|
20
22
|
Requires Node.js `>=24`.
|
|
21
23
|
|
|
24
|
+
Both lines carry `--read-only` deliberately: without it the payment checks
|
|
25
|
+
`X402-06`/`07` run as soon as a `STELLAR_PRIVATE_KEY` is available, and the CLI
|
|
26
|
+
reads `.env` from the directory you run it in — so on a machine already set up
|
|
27
|
+
for a later suite, the first command in this README would settle a real testnet
|
|
28
|
+
payment.
|
|
29
|
+
|
|
22
30
|
## Quick start
|
|
23
31
|
|
|
24
32
|
The default posture costs nothing — no keys required:
|
|
@@ -88,6 +96,32 @@ wasit mpp-channel --target <url> [options]
|
|
|
88
96
|
|
|
89
97
|
`--channel` **asserts**, it does not select: the channel under test is resolved from the target's own 402 challenge, so every check in a run reports on the same contract. When `--channel` differs from what the target advertises, `MPP-10` fails and inspects nothing.
|
|
90
98
|
|
|
99
|
+
### `wasit checks` — the catalogue
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
wasit checks [--protocol x402|mpp-charge|mpp-channel] [--json]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Lists every check by ID with the subcommand that runs it, and flags the ones that are negative, destructive, or spend funds. No network, no keys.
|
|
106
|
+
|
|
107
|
+
### `wasit wallet` — testnet keys
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
wasit wallet status [--role x402|mpp-charge] [--json]
|
|
111
|
+
wasit wallet create --role x402|mpp-charge|mpp-channel [--fund]
|
|
112
|
+
wasit wallet fund --role x402|mpp-charge [--asset xlm|usdc] [--amount <n>]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Testnet-only helpers for the keys the subcommands above read from `.env`. There is deliberately no `--network` flag. `create` prints the exact `.env` lines to paste and never writes the file itself; `fund --asset xlm` uses Stellar's public Friendbot and is fully automatic.
|
|
116
|
+
|
|
117
|
+
`fund --asset usdc` opens the Circle testnet USDC trustline automatically, but **receiving a balance always needs one human step**: there is no scriptable USDC faucet for Stellar. Visit [faucet.circle.com](https://faucet.circle.com) once, or set `WASIT_USDC_DISTRIBUTOR_SECRET` to an account you funded that way and every later run sends from it automatically.
|
|
118
|
+
|
|
119
|
+
`create` prints a secret key to stdout — don't run it on a screen you're recording.
|
|
120
|
+
|
|
121
|
+
### The interactive dashboard
|
|
122
|
+
|
|
123
|
+
Running `wasit` with no arguments in a terminal opens a menu: the same three check runners, a catalogue browser, and a wallet screen, driven by arrow keys. A run shows a live elapsed timer and per-check progress, and `s` saves the finished run to `wasit-<protocol>-<timestamp>.json` — the same shape `--json` prints. Piped or in CI it prints help instead, so nothing that scripts Wasit today changes behaviour. See [`docs/guides/cli.md`](https://github.com/wasit-dev/wasit/blob/main/docs/guides/cli.md).
|
|
124
|
+
|
|
91
125
|
## Reading output
|
|
92
126
|
|
|
93
127
|
```
|
|
@@ -126,6 +160,7 @@ A run with both a failure and an error exits `1` — a real finding outranks a m
|
|
|
126
160
|
| `COMMITMENT_SECRET_HEX` | `mpp-channel` |
|
|
127
161
|
| `CHANNEL_CONTRACT` | `mpp-channel` (optional assertion) |
|
|
128
162
|
| `CHANNEL_CONTRACT_DISPOSABLE` | `mpp-channel --allow-destructive` |
|
|
163
|
+
| `WASIT_USDC_DISTRIBUTOR_SECRET` | `wallet fund --asset usdc` (optional) |
|
|
129
164
|
|
|
130
165
|
All keys are **testnet only**. `wasit` also reads a `.env` file in the current working directory — pass `--payer-key` / `--commitment-key` directly to override it for a single run.
|
|
131
166
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** One thing the dashboard can run. See runners.ts for what each does. */
|
|
2
|
+
export type DashboardAction = {
|
|
3
|
+
readonly kind: "x402-read";
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: "mpp-channel";
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "mpp-charge";
|
|
8
|
+
};
|
|
9
|
+
export declare function App(): import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useInput } from "ink";
|
|
4
|
+
import { Home } from "./Home.js";
|
|
5
|
+
import { TargetForm } from "./TargetForm.js";
|
|
6
|
+
import { RunView } from "./RunView.js";
|
|
7
|
+
import { CatalogueView } from "./CatalogueView.js";
|
|
8
|
+
import { WalletView } from "./WalletView.js";
|
|
9
|
+
const PROTOCOL_BY_ACTION = {
|
|
10
|
+
"x402-read": "x402",
|
|
11
|
+
"mpp-channel": "mpp-channel",
|
|
12
|
+
"mpp-charge": "mpp-charge",
|
|
13
|
+
};
|
|
14
|
+
export function App() {
|
|
15
|
+
const [screen, setScreen] = useState({ name: "home" });
|
|
16
|
+
// Ctrl+C must stop the process from any screen, including while a text
|
|
17
|
+
// field has focus. Unlike a plain letter key, no legitimate typed input
|
|
18
|
+
// (a target URL, a y/n confirmation) ever contains a literal Ctrl+C
|
|
19
|
+
// keystroke, so binding it globally here never collides with typing.
|
|
20
|
+
// 128 + SIGINT (2) — the exit code a shell expects after Ctrl+C.
|
|
21
|
+
useInput((input, key) => {
|
|
22
|
+
if (key.ctrl && input === "c") {
|
|
23
|
+
process.exit(130);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (screen.name === "home") {
|
|
27
|
+
return (_jsx(Home, { onSelectAction: (action) => setScreen({ name: "target", action }), onBrowseCatalogue: () => setScreen({ name: "catalogue" }), onOpenWallet: () => setScreen({ name: "wallet" }) }));
|
|
28
|
+
}
|
|
29
|
+
if (screen.name === "catalogue") {
|
|
30
|
+
return _jsx(CatalogueView, { onBack: () => setScreen({ name: "home" }) });
|
|
31
|
+
}
|
|
32
|
+
if (screen.name === "wallet") {
|
|
33
|
+
return _jsx(WalletView, { onBack: () => setScreen({ name: "home" }) });
|
|
34
|
+
}
|
|
35
|
+
if (screen.name === "target") {
|
|
36
|
+
return (_jsx(TargetForm, { action: screen.action, onSubmit: (target) => setScreen({ name: "run", action: screen.action, target }), onCancel: () => setScreen({ name: "home" }) }));
|
|
37
|
+
}
|
|
38
|
+
return (_jsx(RunView, { protocol: PROTOCOL_BY_ACTION[screen.action.kind], action: screen.action, target: screen.target, onBack: () => setScreen({ name: "home" }) }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text, useApp, useInput } from "ink";
|
|
3
|
+
import { CHECK_CATALOGUE, PROTOCOL_IDS } from "@wasit-dev/core";
|
|
4
|
+
import { THEME } from "./theme.js";
|
|
5
|
+
const COMMAND_BY_PROTOCOL = {
|
|
6
|
+
x402: "test",
|
|
7
|
+
"mpp-charge": "mpp-charge",
|
|
8
|
+
"mpp-channel": "mpp-channel",
|
|
9
|
+
};
|
|
10
|
+
export function CatalogueView({ onBack }) {
|
|
11
|
+
const { exit } = useApp();
|
|
12
|
+
// No text field on this screen, so "q" is safe as a bare letter key —
|
|
13
|
+
// distinct from Enter/Esc, which go back to the menu instead of quitting.
|
|
14
|
+
useInput((input, key) => {
|
|
15
|
+
if (input === "q") {
|
|
16
|
+
exit();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (key.escape || key.return)
|
|
20
|
+
onBack();
|
|
21
|
+
});
|
|
22
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: THEME.accent, paddingX: 2, paddingY: 1, children: [_jsx(Text, { bold: true, color: THEME.accent, children: "Check catalogue" }), PROTOCOL_IDS.map((protocol) => (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { bold: true, children: [protocol, " (wasit ", COMMAND_BY_PROTOCOL[protocol], ")"] }), CHECK_CATALOGUE.filter((entry) => entry.protocol === protocol).map((entry) => (_jsxs(Text, { children: [" ", entry.id, " ", entry.name] }, entry.id)))] }, protocol))), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Enter or Esc to go back \u00B7 q to quit" }) })] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DashboardAction } from "./App.js";
|
|
2
|
+
interface HomeProps {
|
|
3
|
+
readonly onSelectAction: (action: DashboardAction) => void;
|
|
4
|
+
readonly onBrowseCatalogue: () => void;
|
|
5
|
+
readonly onOpenWallet: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function Home({ onSelectAction, onBrowseCatalogue, onOpenWallet }: HomeProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text, useApp, useInput } from "ink";
|
|
3
|
+
import SelectInput from "ink-select-input";
|
|
4
|
+
import { THEME } from "./theme.js";
|
|
5
|
+
import { CLI_VERSION } from "../version.js";
|
|
6
|
+
import { renderWordmark } from "./banner.js";
|
|
7
|
+
import { getEnvironmentStatus } from "./environment.js";
|
|
8
|
+
const ACTION_KINDS = ["x402-read", "mpp-channel", "mpp-charge"];
|
|
9
|
+
const ITEMS = [
|
|
10
|
+
{ label: "Run x402 test (read-only checks)", value: "x402-read" },
|
|
11
|
+
{ label: "Run MPP channel test (non-destructive)", value: "mpp-channel" },
|
|
12
|
+
{ label: "Run MPP charge test (settles a real testnet payment)", value: "mpp-charge" },
|
|
13
|
+
{ label: "Browse check catalogue", value: "catalogue" },
|
|
14
|
+
{ label: "Manage testnet wallets", value: "wallet" },
|
|
15
|
+
{ label: "Quit", value: "quit" },
|
|
16
|
+
];
|
|
17
|
+
// Computed once at module load, not per render: it's ASCII art of a fixed
|
|
18
|
+
// string, not something that ever changes while the process is running.
|
|
19
|
+
const WORDMARK_LINES = renderWordmark("WASIT");
|
|
20
|
+
function isActionKind(value) {
|
|
21
|
+
return ACTION_KINDS.includes(value);
|
|
22
|
+
}
|
|
23
|
+
export function Home({ onSelectAction, onBrowseCatalogue, onOpenWallet }) {
|
|
24
|
+
// Ink's own exit, not process.exit: it unmounts the tree and restores the
|
|
25
|
+
// terminal (cursor, raw mode) before the process ends, which a bare
|
|
26
|
+
// process.exit skips — leaving a hidden cursor behind on quit.
|
|
27
|
+
const { exit } = useApp();
|
|
28
|
+
// Safe as a bare letter key here: this screen has no text field, so
|
|
29
|
+
// nothing the user types could ever collide with "q".
|
|
30
|
+
useInput((input) => {
|
|
31
|
+
if (input === "q") {
|
|
32
|
+
exit();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const handleSelect = (item) => {
|
|
36
|
+
if (item.value === "catalogue") {
|
|
37
|
+
onBrowseCatalogue();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (item.value === "wallet") {
|
|
41
|
+
onOpenWallet();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (item.value === "quit") {
|
|
45
|
+
exit();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (isActionKind(item.value)) {
|
|
49
|
+
onSelectAction({ kind: item.value });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const environment = getEnvironmentStatus();
|
|
53
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { flexDirection: "column", marginBottom: 1, children: WORDMARK_LINES.map((line, index) => (_jsx(Text, { color: THEME.accent, children: line }, index))) }), _jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: THEME.accent, paddingX: 2, paddingY: 1, children: [_jsx(Text, { bold: true, children: "Welcome to Wasit" }), _jsx(Text, { dimColor: true, children: "x402 / MPP compliance tester \u00B7 Stellar Testnet" }), _jsxs(Box, { marginTop: 1, flexDirection: "row", gap: 4, children: [_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, color: THEME.accent, children: "Tips" }), _jsx(Text, { dimColor: true, children: "\u2191\u2193 + Enter to pick an action" }), _jsx(Text, { dimColor: true, children: "Esc to go back \u00B7 Ctrl+C to quit anywhere" }), _jsx(Text, { dimColor: true, children: "docs/CHECKS.md has every check's pass criteria" })] }), _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, color: THEME.accent, children: "Environment" }), environment.map((status) => (_jsxs(Text, { color: status.ready ? THEME.success : THEME.muted, children: [status.ready ? "✓" : "·", " ", status.label] }, status.label)))] })] }), _jsx(Box, { marginTop: 1, children: _jsx(SelectInput, { items: ITEMS, onSelect: handleSelect }) }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["v", CLI_VERSION, " \u00B7 q to quit"] }) })] })] }));
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ProtocolId } from "@wasit-dev/core";
|
|
2
|
+
import type { DashboardAction } from "./App.js";
|
|
3
|
+
interface RunViewProps {
|
|
4
|
+
readonly protocol: ProtocolId;
|
|
5
|
+
readonly action: DashboardAction;
|
|
6
|
+
readonly target: string;
|
|
7
|
+
readonly onBack: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function RunView({ protocol, action, target, onBack }: RunViewProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { writeFile } from "node:fs/promises";
|
|
4
|
+
import { Box, Text, useApp, useInput } from "ink";
|
|
5
|
+
import { CHECK_CATALOGUE, checkStatus, summarize, toStructuredRun, } from "@wasit-dev/core";
|
|
6
|
+
import { runAction } from "./runners.js";
|
|
7
|
+
import { THEME } from "./theme.js";
|
|
8
|
+
import { formatDuration } from "./format.js";
|
|
9
|
+
import { useSpinnerFrame } from "./useSpinnerFrame.js";
|
|
10
|
+
import { useElapsedMs } from "./useElapsedMs.js";
|
|
11
|
+
function iconFor(status, spinnerFrame) {
|
|
12
|
+
switch (status) {
|
|
13
|
+
case "PASS":
|
|
14
|
+
return "✓";
|
|
15
|
+
case "FAIL":
|
|
16
|
+
return "✗";
|
|
17
|
+
case "ERROR":
|
|
18
|
+
return "⨯";
|
|
19
|
+
case "SKIP":
|
|
20
|
+
return "⚠";
|
|
21
|
+
default:
|
|
22
|
+
return spinnerFrame;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function colorFor(status) {
|
|
26
|
+
switch (status) {
|
|
27
|
+
case "PASS":
|
|
28
|
+
return THEME.success;
|
|
29
|
+
case "FAIL":
|
|
30
|
+
return THEME.danger;
|
|
31
|
+
case "ERROR":
|
|
32
|
+
// Not a conformance failure — the check produced no verdict at all
|
|
33
|
+
// (network/config), so it gets the brand color rather than red.
|
|
34
|
+
return THEME.accent;
|
|
35
|
+
case "SKIP":
|
|
36
|
+
return THEME.warning;
|
|
37
|
+
default:
|
|
38
|
+
return THEME.muted;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// X402-06/07 need a real settled payment and are never touched by the
|
|
42
|
+
// read-only x402 action — listing them as "pending" would leave two rows
|
|
43
|
+
// spinning forever after the run has already finished.
|
|
44
|
+
const READ_ONLY_EXCLUDED_IDS = new Set(["X402-06", "X402-07"]);
|
|
45
|
+
export function RunView({ protocol, action, target, onBack }) {
|
|
46
|
+
const { exit } = useApp();
|
|
47
|
+
const initialEntries = useMemo(() => {
|
|
48
|
+
const catalogueEntries = CHECK_CATALOGUE.filter((entry) => entry.protocol === protocol);
|
|
49
|
+
const relevant = action.kind === "x402-read"
|
|
50
|
+
? catalogueEntries.filter((entry) => !READ_ONLY_EXCLUDED_IDS.has(entry.id))
|
|
51
|
+
: catalogueEntries;
|
|
52
|
+
return relevant.map((entry) => ({
|
|
53
|
+
id: entry.id,
|
|
54
|
+
name: entry.name,
|
|
55
|
+
status: "pending",
|
|
56
|
+
}));
|
|
57
|
+
}, [protocol, action.kind]);
|
|
58
|
+
const [entries, setEntries] = useState(initialEntries);
|
|
59
|
+
const [extra, setExtra] = useState([]);
|
|
60
|
+
const [done, setDone] = useState(false);
|
|
61
|
+
const [errorMessage, setErrorMessage] = useState(undefined);
|
|
62
|
+
const [summaryLine, setSummaryLine] = useState(undefined);
|
|
63
|
+
const [finalResults, setFinalResults] = useState(undefined);
|
|
64
|
+
const [savedTo, setSavedTo] = useState(undefined);
|
|
65
|
+
const [saveError, setSaveError] = useState(undefined);
|
|
66
|
+
// Timestamps live in refs, not state: they don't need their own re-render,
|
|
67
|
+
// the spinner hook below already re-renders often enough while the run is
|
|
68
|
+
// live, and the state updates at completion re-render once more.
|
|
69
|
+
const startedAtRef = useRef(Date.now());
|
|
70
|
+
const finishedAtRef = useRef(undefined);
|
|
71
|
+
// Also what makes the live elapsed timer below tick — it re-renders on
|
|
72
|
+
// the same interval. Stops once the run is done: nothing left to animate.
|
|
73
|
+
const spinnerFrame = useSpinnerFrame(!done);
|
|
74
|
+
// Ticks the elapsed counter in state rather than reading the clock while
|
|
75
|
+
// rendering, and freezes at the run's real total once done flips.
|
|
76
|
+
const elapsedMs = useElapsedMs(!done, startedAtRef.current);
|
|
77
|
+
// Kicks off the run exactly once. Ignored intentionally: initialEntries is
|
|
78
|
+
// derived from `protocol`, which does not change once a run has started.
|
|
79
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
let cancelled = false;
|
|
82
|
+
const onResult = (result) => {
|
|
83
|
+
if (cancelled)
|
|
84
|
+
return;
|
|
85
|
+
const status = checkStatus(result);
|
|
86
|
+
const isKnown = initialEntries.some((entry) => entry.id === result.id);
|
|
87
|
+
if (isKnown) {
|
|
88
|
+
setEntries((current) => current.map((entry) => (entry.id === result.id ? { ...entry, status } : entry)));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Results outside the catalogue (e.g. PREFLIGHT) still need to be shown.
|
|
92
|
+
setExtra((current) => [...current, { id: result.id, name: result.name, status }]);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
runAction(action, target, onResult)
|
|
96
|
+
.then((results) => {
|
|
97
|
+
if (cancelled)
|
|
98
|
+
return;
|
|
99
|
+
finishedAtRef.current = Date.now();
|
|
100
|
+
const totalMs = finishedAtRef.current - startedAtRef.current;
|
|
101
|
+
const summary = summarize(results);
|
|
102
|
+
const parts = [`${summary.passed} passed`];
|
|
103
|
+
if (summary.failed > 0)
|
|
104
|
+
parts.push(`${summary.failed} failed`);
|
|
105
|
+
if (summary.errored > 0)
|
|
106
|
+
parts.push(`${summary.errored} could not run`);
|
|
107
|
+
if (summary.skipped > 0)
|
|
108
|
+
parts.push(`${summary.skipped} skipped`);
|
|
109
|
+
const avgMs = results.length > 0 ? totalMs / results.length : 0;
|
|
110
|
+
setSummaryLine(`${parts.join(", ")}. ${formatDuration(totalMs)} total · ${formatDuration(avgMs)} avg/check.`);
|
|
111
|
+
setFinalResults(results);
|
|
112
|
+
setDone(true);
|
|
113
|
+
})
|
|
114
|
+
.catch((error) => {
|
|
115
|
+
if (cancelled)
|
|
116
|
+
return;
|
|
117
|
+
finishedAtRef.current = Date.now();
|
|
118
|
+
setErrorMessage(error instanceof Error ? error.message : String(error));
|
|
119
|
+
setDone(true);
|
|
120
|
+
});
|
|
121
|
+
return () => {
|
|
122
|
+
cancelled = true;
|
|
123
|
+
};
|
|
124
|
+
}, []);
|
|
125
|
+
const saveResults = () => {
|
|
126
|
+
if (finalResults === undefined)
|
|
127
|
+
return;
|
|
128
|
+
const filename = `wasit-${protocol}-${Date.now()}.json`;
|
|
129
|
+
writeFile(filename, JSON.stringify(toStructuredRun(finalResults), null, 2), "utf8")
|
|
130
|
+
.then(() => setSavedTo(filename))
|
|
131
|
+
.catch((error) => {
|
|
132
|
+
setSaveError(error instanceof Error ? error.message : String(error));
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
useInput((input, key) => {
|
|
136
|
+
if (input === "q") {
|
|
137
|
+
exit();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (!done)
|
|
141
|
+
return;
|
|
142
|
+
if (input === "s") {
|
|
143
|
+
saveResults();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (key.return)
|
|
147
|
+
onBack();
|
|
148
|
+
if (key.escape)
|
|
149
|
+
exit();
|
|
150
|
+
});
|
|
151
|
+
// A config error (missing key, bad target) means no check ever ran — the
|
|
152
|
+
// pending checklist below would just be dead weight, so this gets its own
|
|
153
|
+
// focused screen instead of a red line bolted under it.
|
|
154
|
+
if (errorMessage !== undefined) {
|
|
155
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: THEME.danger, paddingX: 2, paddingY: 1, children: [_jsx(Text, { bold: true, color: THEME.danger, children: "Could not run this check" }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { children: errorMessage }) }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Enter to go back \u00B7 q to quit" }) })] }));
|
|
156
|
+
}
|
|
157
|
+
const firstPendingIndex = entries.findIndex((entry) => entry.status === "pending");
|
|
158
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: THEME.accent, paddingX: 2, paddingY: 1, children: [_jsx(Text, { bold: true, color: THEME.accent, children: target }), !done && (_jsxs(Text, { dimColor: true, children: ["Running \u00B7 ", formatDuration(elapsedMs)] })), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [extra.map((entry) => (_jsxs(Text, { color: colorFor(entry.status), children: [iconFor(entry.status, spinnerFrame), " ", entry.id, " ", entry.name] }, entry.id))), entries.map((entry, index) => {
|
|
159
|
+
const isRunningNow = entry.status === "pending" && index === firstPendingIndex;
|
|
160
|
+
const icon = entry.status === "pending" && !isRunningNow
|
|
161
|
+
? "·"
|
|
162
|
+
: iconFor(entry.status, spinnerFrame);
|
|
163
|
+
return (_jsxs(Text, { color: isRunningNow ? THEME.accent : colorFor(entry.status), dimColor: entry.status === "pending" && !isRunningNow, children: [icon, " ", entry.id, " ", entry.name] }, entry.id));
|
|
164
|
+
})] }), done && summaryLine !== undefined && (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { bold: true, children: summaryLine }), savedTo !== undefined && _jsxs(Text, { color: THEME.success, children: ["Saved to ", savedTo] }), saveError !== undefined && (_jsxs(Text, { color: THEME.danger, children: ["Could not save results: ", saveError] })), _jsx(Text, { dimColor: true, children: "Enter to go back \u00B7 s to save JSON \u00B7 q to quit" })] }))] }));
|
|
165
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DashboardAction } from "./App.js";
|
|
2
|
+
interface TargetFormProps {
|
|
3
|
+
readonly action: DashboardAction;
|
|
4
|
+
readonly onSubmit: (target: string) => void;
|
|
5
|
+
readonly onCancel: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function TargetForm({ action, onSubmit, onCancel }: TargetFormProps): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Box, Text, useInput } from "ink";
|
|
4
|
+
import TextInput from "ink-text-input";
|
|
5
|
+
import { THEME } from "./theme.js";
|
|
6
|
+
const ACTION_LABEL = {
|
|
7
|
+
"x402-read": "x402 read-only checks (X402-01..05)",
|
|
8
|
+
"mpp-channel": "MPP channel checks (MPP-10, 11, 12, 14 — non-destructive)",
|
|
9
|
+
"mpp-charge": "MPP-01 charge settlement",
|
|
10
|
+
};
|
|
11
|
+
function isValidUrl(value) {
|
|
12
|
+
try {
|
|
13
|
+
// eslint-disable-next-line no-new
|
|
14
|
+
new URL(value);
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function TargetForm({ action, onSubmit, onCancel }) {
|
|
22
|
+
const [target, setTarget] = useState("");
|
|
23
|
+
const [confirmedTarget, setConfirmedTarget] = useState("");
|
|
24
|
+
const [step, setStep] = useState("url");
|
|
25
|
+
const [error, setError] = useState(undefined);
|
|
26
|
+
const handleUrlSubmit = (value) => {
|
|
27
|
+
const trimmed = value.trim();
|
|
28
|
+
if (trimmed.length === 0) {
|
|
29
|
+
setError("Target URL cannot be empty.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!isValidUrl(trimmed)) {
|
|
33
|
+
setError(`"${trimmed}" is not a valid URL.`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
setError(undefined);
|
|
37
|
+
setConfirmedTarget(trimmed);
|
|
38
|
+
if (action.kind === "mpp-charge") {
|
|
39
|
+
setStep("confirm");
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
onSubmit(trimmed);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
useInput((input, key) => {
|
|
46
|
+
if (key.escape) {
|
|
47
|
+
onCancel();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (step !== "confirm")
|
|
51
|
+
return;
|
|
52
|
+
if (key.return || input.toLowerCase() === "y") {
|
|
53
|
+
onSubmit(confirmedTarget);
|
|
54
|
+
}
|
|
55
|
+
else if (input.toLowerCase() === "n") {
|
|
56
|
+
onCancel();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: THEME.accent, paddingX: 2, paddingY: 1, children: [_jsx(Text, { bold: true, color: THEME.accent, children: ACTION_LABEL[action.kind] }), step === "url" && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { children: "Target URL:" }), _jsx(TextInput, { value: target, onChange: setTarget, onSubmit: handleUrlSubmit }), error !== undefined && _jsx(Text, { color: THEME.danger, children: error }), _jsx(Text, { dimColor: true, children: "Enter to continue \u00B7 Esc to go back" })] })), step === "confirm" && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { color: THEME.warning, children: ["This settles a real payment on Stellar Testnet against ", confirmedTarget, "."] }), _jsx(Text, { children: "Continue? (Y/n)" })] }))] }));
|
|
60
|
+
}
|