Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,39 @@ All notable changes to Wasit are recorded here. Versions follow [Semantic Versio
no longer comes from the workflow's env into the steps that hold the token or
the payer key. A service Wasit starts no longer inherits them from the
workflow's env either; set what it needs in `service.start`.
- On Stellar, the payer's key signs only the authorization Wasit checked:
one `transfer` of the checked amount from the payer to the checked payee,
on the checked asset and the run's network, with no further call, one
signature per payment, valid no longer than the payment's lifetime allows
counted from the first ledger the run reads. The caps were checked on the
terms Wasit hands the x402 client; they now hold on what is signed too, so
an RPC whose simulation asks for anything else gets no signature. Such a
payment check is `ERROR (setup)` with nothing signed, and so is a payment in
a testnet token whose `transfer` needs further authorized calls. A payment
whose built transaction carries anything but that one signed authorization
is discarded unsent.
- A payment run on Stellar refuses an `http://` RPC (`rpcUrl` in the config,
`WASIT_RPC_URL`, `--rpc-url`, the MCP tools' `rpcUrl`) before anything is
sent, and `wasit run` refuses it before it starts the service: the x402
Stellar client builds the payment through that RPC and accepts only https.

**Added.**
- `@wasit-dev/core` exports `mainnetJobRefusals` and `assertMainnetJob`: the
rules a job in GitHub Actions has to meet for the mainnet opt-in, which this
version does not have. The run is started by hand (`workflow_dispatch`), on
the default branch, on a GitHub-hosted runner; it tests a deployed service
(no `service.start`, no local `baseUrl`); nothing was installed in the job
before Wasit (no `node_modules` in the workspace); and
`WASIT_MAINNET_PAYER_SECRET` is the only key variable set. Outside GitHub
Actions none of them applies. `--mainnet` and the Action's `mainnet: true`
still refuse in this version, and now also name the runner rule on a runner
that is not GitHub-hosted.

**Fixed.**
- On Stellar testnet the x402 client builds and simulates the payment through
the run's RPC, the one whose network Wasit checks and reads the settlement
from. It used `https://soroban-testnet.stellar.org` whatever RPC the run was
given.
- In the coloured output of `wasit test` (at a terminal, or with
`FORCE_COLOR`), a wrapped line of a fix could start with `::name::` or
`##[name]` from the middle of the text, which a GitHub job log reads as a
Expand Down
7 changes: 6 additions & 1 deletion action/scripts/inputs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ function checkMainnet(env) {
event === "workflow_dispatch"
? ""
: ` The input is also refused on every event but workflow_dispatch, and this run's event is ${EVENT_NAME.test(event) ? event : "another event"}.`;
// Spec B17.4: a self-hosted runner keeps files and processes between jobs.
const runnerRule =
env["RUNNER_ENVIRONMENT"] === "github-hosted"
? ""
: " The input is also refused on a runner that is not GitHub-hosted: a self-hosted runner keeps files and processes between jobs.";
throw new MainnetRefusedError(
"mainnet: true is refused: the mainnet opt-in is not part of this version. Wasit pays on test networks only." +
`${eventRule} Nothing was installed, started, sent or signed.`,
`${eventRule}${runnerRule} Nothing was installed, started, sent or signed.`,
);
}

Expand Down
18 changes: 17 additions & 1 deletion action/test/inputs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
scrubTokens,
} from "../scripts/inputs.mjs";

const env = (overrides = {}) => ({ INPUT_CONFIG: "wasit.config.json", INPUT_ENVIRONMENT: "", INPUT_TIER: "read-only", INPUT_ENDPOINTS: "", GITHUB_EVENT_NAME: "pull_request", ...overrides });
const env = (overrides = {}) => ({ INPUT_CONFIG: "wasit.config.json", INPUT_ENVIRONMENT: "", INPUT_TIER: "read-only", INPUT_ENDPOINTS: "", GITHUB_EVENT_NAME: "pull_request", RUNNER_ENVIRONMENT: "github-hosted", ...overrides });

describe("parseInputs", () => {
it("takes the defaults: the config file in the working directory, read-only, every endpoint", () => {
Expand Down Expand Up @@ -80,6 +80,22 @@ describe("parseInputs", () => {
}
});

it("adds the runner rule on a runner that is not GitHub-hosted", () => {
for (const runner of ["self-hosted", undefined]) {
assert.throws(
() => parseInputs(env({ INPUT_MAINNET: "true", GITHUB_EVENT_NAME: "workflow_dispatch", RUNNER_ENVIRONMENT: runner })),
(error) =>
SENTENCE.test(error.message) &&
error.message.includes("The input is also refused on a runner that is not GitHub-hosted: a self-hosted runner keeps files and processes between jobs."),
String(runner),
);
}
assert.throws(
() => parseInputs(env({ INPUT_MAINNET: "true", GITHUB_EVENT_NAME: "workflow_dispatch" })),
(error) => !/GitHub-hosted/.test(error.message),
);
});

it("adds the workflow_dispatch rule on any other event, and names the event", () => {
for (const name of ["push", "schedule", "pull_request"]) {
assert.throws(
Expand Down
18 changes: 11 additions & 7 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import {
MainnetOptInRefusedError,
RpcIdentityError,
UnsupportedPaymentNetworkError,
assertRpcServesNetwork,
assertX402PaymentRpc,
} from "@wasit-dev/core";

import { formatRun } from "./run-format.js";
Expand Down Expand Up @@ -309,7 +309,12 @@ export async function executeRun(options: RunCommandOptions, context: RunContext
// B12: the switch exists only to refuse. First, so nothing is read, started, sent or signed.
if (options.mainnet === true) {
try {
refuseMainnetSwitch("--mainnet", inGithubActions(context.env) ? { event: context.env["GITHUB_EVENT_NAME"] ?? "" } : {});
refuseMainnetSwitch(
"--mainnet",
inGithubActions(context.env)
? { event: context.env["GITHUB_EVENT_NAME"] ?? "", runner: context.env["RUNNER_ENVIRONMENT"] ?? "" }
: {},
);
} catch (error) {
if (error instanceof MainnetOptInRefusedError) return fail(`wasit run ${error.message}`);
throw error;
Expand Down Expand Up @@ -384,13 +389,12 @@ export async function executeRun(options: RunCommandOptions, context: RunContext
: undefined;

// D-023a+b: a run that will pay checks its RPC before the service starts or
// anything is sent to it: the settlements are read through it (and, on EVM
// and Solana, the payments are built through it), so it must serve the run's
// own network. On Stellar the x402 client builds the payment through its own
// default RPC for the network; that is changed before the mainnet opt-in.
// anything is sent to it: the payments are built and the settlements read
// through it, so it must be one the x402 client accepts (https on Stellar)
// and serve the run's own network.
if (paying && notPaid === undefined && chain !== undefined && key !== undefined && hasX402) {
try {
await assertRpcServesNetwork(resolved.network, chain.resolveRpcUrl(resolved.network, resolved.rpcUrl));
await assertX402PaymentRpc(resolved.network, chain.resolveRpcUrl(resolved.network, resolved.rpcUrl));
} catch (error) {
if (error instanceof RpcIdentityError) return fail(`wasit run: ${error.message} The service was not started.`);
throw error;
Expand Down
30 changes: 28 additions & 2 deletions packages/cli/test/unit/run-mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,44 @@ describe("wasit run --mainnet (B12: a switch that always refuses)", () => {
});
}

it("in GitHub Actions on workflow_dispatch: still refused, without the event rule", async () => {
it("in GitHub Actions on workflow_dispatch on a hosted runner: still refused, without the event or runner rule", async () => {
paywall = await multiPaywall({ "/weather": [option("10000")] });
const result = await run(
{ config: await pubnetConfig(paywall.base) },
{ GITHUB_ACTIONS: "true", CI: "true", GITHUB_EVENT_NAME: "workflow_dispatch", GITHUB_REF: "refs/heads/main", GITHUB_EVENT_PATH: eventFile },
{
GITHUB_ACTIONS: "true",
CI: "true",
GITHUB_EVENT_NAME: "workflow_dispatch",
GITHUB_REF: "refs/heads/main",
GITHUB_EVENT_PATH: eventFile,
RUNNER_ENVIRONMENT: "github-hosted",
},
);
assert.equal(result.code, 2);
assert.ok(result.stderr.startsWith(SENTENCE), result.stderr);
assert.doesNotMatch(result.stderr, /also refused/);
assert.equal(paywall.requests, 0);
});

it("in GitHub Actions on a self-hosted runner: refused, and says the runner rule", async () => {
paywall = await multiPaywall({ "/weather": [option("10000")] });
const result = await run(
{ config: await pubnetConfig(paywall.base) },
{
GITHUB_ACTIONS: "true",
CI: "true",
GITHUB_EVENT_NAME: "workflow_dispatch",
GITHUB_REF: "refs/heads/main",
GITHUB_EVENT_PATH: eventFile,
RUNNER_ENVIRONMENT: "self-hosted",
},
);
assert.equal(result.code, 2);
assert.ok(result.stderr.startsWith(SENTENCE), result.stderr);
assert.match(result.stderr, /--mainnet is also refused on a runner that is not GitHub-hosted/);
assert.equal(paywall.requests, 0);
});

it("is not read from the environment: WASIT_MAINNET_OPT_IN without the flag changes nothing", async () => {
paywall = await multiPaywall({ "/weather": [option("10000")] });
const result = await run({ config: await pubnetConfig(paywall.base), mainnet: false, readOnly: true }, { WASIT_MAINNET_OPT_IN: "1" });
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/test/unit/run-payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { tmpdir } from "node:os";
import path from "node:path";
import { after, afterEach, before, beforeEach, describe, it } from "node:test";

import { Keypair } from "@stellar/stellar-sdk";
import { setRpcIdentityTransportForTesting } from "@wasit-dev/core/dist/guard/rpc-identity.js";
import { setPaymentChainsForTesting } from "@wasit-dev/core/dist/x402/chains/index.js";

import { executeRun, type RunCommandOptions } from "../../src/run.js";
import {
Expand All @@ -41,6 +43,7 @@ interface EnvironmentSpec {
readonly operatedByMe?: boolean;
readonly pinned?: { payTo: string; asset: string };
readonly maxRunUsd?: number;
readonly rpcUrl?: string;
}

async function writePaymentConfig(
Expand All @@ -62,6 +65,7 @@ async function writePaymentConfig(
operatedByMe: environment.operatedByMe ?? true,
...(environment.pinned === undefined ? {} : { pinned: environment.pinned }),
...(environment.maxRunUsd === undefined ? {} : { maxRunUsd: environment.maxRunUsd }),
...(environment.rpcUrl === undefined ? {} : { rpcUrl: environment.rpcUrl }),
},
},
endpoints,
Expand Down Expand Up @@ -285,6 +289,27 @@ describe("wasit run, payment tier", () => {
assert.equal(recorder.signed.length, 0);
});

it("refuses an http RPC on Stellar before the service starts or any request is sent", async () => {
// The real adapters: the Stellar x402 client builds the payment through the run's RPC.
setPaymentChainsForTesting(undefined);
paywall = await multiPaywall({ "/weather": [option("10000")] });
const config = await writePaymentConfig(dir, paywall.base, {
network: "stellar:testnet",
rpcUrl: "http://127.0.0.1:9/soroban/rpc",
});
let asked = 0;
setRpcIdentityTransportForTesting(async () => {
asked += 1;
return undefined;
});
const run = await pay({ config }, { STELLAR_PRIVATE_KEY: Keypair.random().secret() });
assert.equal(run.code, 2, run.stderr);
assert.match(run.stderr, /accepts only an https RPC/);
assert.match(run.stderr, /The service was not started\./);
assert.equal(asked, 0);
assert.equal(paywall.requests, 0);
});

describe("in a CI that is not GitHub Actions (review R9 a, Najmi 2026-11-17)", () => {
const otherCi = { CI: "true" };

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/guard/budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function formatUsd(amount: bigint): string {
return `${sign}$${whole}.${fraction}`;
}

export type GuardRefusal = "price" | "asset" | "amount" | "pin" | "plan" | "run-cap" | "accepted";
export type GuardRefusal = "price" | "asset" | "amount" | "pin" | "plan" | "run-cap" | "accepted" | "signed-terms";

/**
* A payment the guard will not sign, or, with `signed`, a signed payment it
Expand Down
Loading
Loading