Skip to content

Commit da2356e

Browse files
committed
Merge branch 'worktree-agent-ae2cda84'
2 parents f21d55d + e17645e commit da2356e

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

cli-e2e.test.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,26 @@ describe("CLI e2e happy path", () => {
19501950
assert.equal(allowance.rail, "mpp", "rail should be mpp");
19511951
});
19521952

1953+
// GH-81: after MPP faucet succeeds, `--json` summary must reflect funded=true
1954+
// and the polled balance. Previously `summary.allowance` was captured before
1955+
// the faucet branch ran, so the JSON reported `funded: false` and
1956+
// `usd_micros: 0` even when the human-readable lines said "funded".
1957+
it("init mpp --json reports funded=true after faucet settles (GH-81)", async () => {
1958+
tempoRpcCallCount = 0; // first eth_call returns 0 → triggers faucet path
1959+
const { run } = await import("./cli/lib/init.mjs");
1960+
captureStart();
1961+
await run(["mpp", "--json"]);
1962+
captureStop();
1963+
const stdout = capturedStdout();
1964+
const parsed = JSON.parse(stdout);
1965+
assert.equal(parsed.rail, "mpp", `rail must be mpp; got: ${parsed.rail}`);
1966+
assert.equal(parsed.allowance.funded, true,
1967+
`summary.allowance.funded must be true after successful faucet; got: ${JSON.stringify(parsed.allowance)}`);
1968+
assert.equal(parsed.balance.symbol, "pathUSD");
1969+
assert.ok(parsed.balance.usd_micros > 0,
1970+
`summary.balance.usd_micros must reflect polled balance (>0); got: ${parsed.balance.usd_micros}`);
1971+
});
1972+
19531973
it("allowance status (MPP rail)", async () => {
19541974
const { run } = await import("./cli/lib/allowance.mjs");
19551975
captureStart();

cli/lib/init.mjs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,23 @@ export async function run(args = []) {
112112
});
113113
const data = await res.json();
114114
if (data.result) {
115-
// Tempo faucet is instant — re-read balance once
116-
try {
117-
const raw = await client.readContract({ address: PATH_USD, abi: USDC_ABI, functionName: "balanceOf", args: [allowance.address] });
118-
balance = Number(raw);
119-
} catch {}
115+
// Tempo faucet is "instant" on-chain, but the client RPC read can be
116+
// racy relative to faucet settlement — poll up to 30s (GH-81), mirroring
117+
// the x402 path below.
118+
for (let i = 0; i < 30; i++) {
119+
await new Promise(r => setTimeout(r, 1000));
120+
try {
121+
const raw = await client.readContract({ address: PATH_USD, abi: USDC_ABI, functionName: "balanceOf", args: [allowance.address] });
122+
balance = Number(raw);
123+
if (balance > 0) break;
124+
} catch {}
125+
}
120126
saveAllowance({ ...allowance, funded: true, lastFaucet: new Date().toISOString() });
127+
summary.allowance.funded = true;
121128
if (balance > 0) {
122129
line("Balance", `${(balance / 1e6).toFixed(2)} pathUSD (funded)`);
123130
} else {
124-
line("Balance", "faucet sent — checking balance...");
131+
line("Balance", "faucet sent — not yet confirmed on-chain");
125132
}
126133
} else {
127134
line("Balance", `faucet failed: ${data.error?.message || "unknown error"}`);
@@ -131,6 +138,7 @@ export async function run(args = []) {
131138
}
132139
} else {
133140
line("Balance", `${(balance / 1e6).toFixed(2)} pathUSD`);
141+
summary.allowance.funded = balance > 0;
134142
}
135143
summary.balance = { symbol: "pathUSD", usd_micros: balance };
136144
} else {
@@ -162,6 +170,7 @@ export async function run(args = []) {
162170
} catch {}
163171
}
164172
saveAllowance({ ...allowance, funded: true, lastFaucet: new Date().toISOString() });
173+
summary.allowance.funded = true;
165174
if (balance > 0) {
166175
line("Balance", `${(balance / 1e6).toFixed(2)} USDC (funded)`);
167176
} else {
@@ -174,6 +183,7 @@ export async function run(args = []) {
174183
}
175184
} else {
176185
line("Balance", `${(balance / 1e6).toFixed(2)} USDC`);
186+
summary.allowance.funded = balance > 0;
177187
}
178188
summary.balance = { symbol: "USDC", usd_micros: balance };
179189
}

0 commit comments

Comments
 (0)