Conversation
Audit (May 2026) compared the e2e-live suite against six explicit user claims (real infra, HMA, intents DB, real swaps, happy paths inc. surplus refund, unhappy paths return assets, no false positives) and found multiple false positives — tests passing on weak proxies that would not actually catch a regression. This change closes the highest-leverage gaps: ## 1. Stale HMA dependency claim removed (Claim 2) `vitest.e2e-live.config.ts` header claimed the suite required the Host Manager Agent (`createHostManager`, `hm.spawn`, HMCP-0). Every helper file explicitly contradicted this — `helpers/contracts.ts` and `helpers/tenant-fixture.ts` both say "NO host-manager, NO HMCP" and spawn containers via direct `docker run`. The vitest config's claim was stale documentation. Replace with an accurate description of what the suite actually does. ## 2. Pin Market API URL (Claim 3) `MARKET_API_URL = 'https://market-api.unicity.network'` added to `constants.ts` and `TestnetConstants` interface. Previously the trader image's hard-coded default was the only reference; tests had no way to assert which Market API was being exercised. ## 3. Portfolio snapshot/assert helpers (foundation) New `helpers/portfolio-assertions.ts` extracts the pre/post balance snapshot pattern from `basic-roundtrip.test.ts:127-170` (the only file that did it correctly). Exports: - `snapshotPortfolio(tenant)` → compact { UCT: bigint, USDU: bigint } - `expectBalanceDelta(before, after, expected)` → exact-delta assert - `expectBalanceUnchanged(before, after, tolerance?)` → no-op assert - `pollUntilBalanceRestored(tenant, baseline, opts?)` → wait for refund ## 4. Multi-agent + multi-agent-disjoint: balance-delta assertions (Claim 4) Previously `state === 'COMPLETED'` only — a regression that left state machines green but skipped token transfer would silently pass. - `multi-agent` 3-trader pairwise: conservation invariant (sum of deltas across all 3 traders = 0 per coin) + each trader's balance must have changed (no-op detection). - `multi-agent` partial-fill: exact deltas asserted (Alice -30 UCT +30 USDU; Bob +30 UCT -30 USDU). - `multi-agent` concurrent-matching: Alice -200/+200; winner +200/-200; loser strictly unchanged. - `multi-agent-disjoint` 2-pair through same escrow: all four exact deltas asserted (-200/+200, +200/-200, -100/+200, +100/-200). ## 5. Negotiation-failures: balance restoration after FAILED (Claim 5b) Previously every unhappy-path test asserted `state === 'FAILED'` and non-empty `error_code` only. The deposit-timeout case — the canonical "did Alice get her tokens back?" scenario — would silently pass even if Alice's deposit was permanently stranded. - `untrusted escrow`: rejection happens pre-deposit, so balances must be unchanged (`expectBalanceUnchanged`). - `deposit timeout`: Alice DOES deposit; her tokens MUST be refunded via the escrow's auto-return-on-cancel mechanism. Use `pollUntilBalanceRestored` with a 5-min budget; fail loud if the refund doesn't propagate. - `escrow unreachable`: similar — both Alice's and Bob's deposits must come back. The test budget bumped to 14 min to accommodate the dual balance polls. If this assertion fires repeatedly, it surfaces a real product gap (no client-side recovery for "escrow died holding my deposit") that Claim 5b is designed to catch. ## 6. basic-roundtrip cancel/expire: balance unchanged Cancel-before-match and intent-expires both assert no swap occurred via `expectBalanceUnchanged`. Comments document the soft-signal nature (shared-aggregator interference is theoretically possible within the test window) — a spurious failure surfaces deltas in the error message so the operator can investigate. ## 7. New surplus-refund.e2e-live.test.ts (Claim 5a(d)) Previously zero coverage for surplus refund. New test asserts the trader emits `accounting_auto_return_enabled` at startup (proof that PR #12's `setAutoReturn('*', true)` wiring is in place). A full end-to-end "over-pay → refund propagates back to original payer" test requires either a trader fault-injection knob to deliberately over-deposit, or a separate SDK-level e2e that bypasses the trader — both larger fixtures than this commit. The wiring assertion is the minimum-viable proof that the auto-return MECHANISM is enabled; the SDK's own unit tests cover the mechanism's correctness. ## Drive-by - `tenant-fixture.ts`: inline `generatePrivateKey` (sphere-sdk no longer exports it at the package root). - `src/trader/main.ts`: guarded `mintFungibleToken` shim (sphere-sdk feature-branch-only API). ## Test plan - typecheck clean for both src and test trees - 671/671 unit tests pass - e2e-live tests will exercise these new assertions; some may fail under current product behavior — that is the intended surfacing of the gaps Claim 5b/Claim 4 were designed to catch
vrogojin
added a commit
that referenced
this pull request
May 4, 2026
Recovery merge of PR #13 used --theirs for src/trader/main.ts which silently reverted PR #12's setAutoReturn block. Without setAutoReturn('*', true), the trader does NOT refund surplus on terminated invoices — exactly the leak surfaced by negotiation-failures.e2e-live's 'deposit timeout' test (UCT delta=-1000, USDU delta=+500 instead of restored to baseline). Re-applies the block right after sphere_initialized log. Behavior matches PR #12 verbatim: - sphere.accounting.setAutoReturn('*', true) gated on sphere.accounting !== null - RATE_LIMITED treated as success (in-process retry within 5s cooldown — flag already set) - All other errors fail fast (storage layer broken → downstream invoice ops would fail unpredictably anyway) Verified: typecheck clean. Re-running negotiation-failures live test will validate the refund path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Audit (May 2026) compared the e2e-live suite against six explicit user claims. Multiple tests passed on weak proxies that wouldn't catch real regressions. This PR closes the highest-leverage gaps.
surplus-refund.e2e-live.test.ts(wiring assertion)pollUntilBalanceRestoredNew helper
test/e2e-live/helpers/portfolio-assertions.ts—snapshotPortfolio,expectBalanceDelta,expectBalanceUnchanged,pollUntilBalanceRestored. Extracted frombasic-roundtrip.ts:127-170.Concrete additions
multi-agent.test.ts: conservation invariant (sum of deltas = 0) + no-op detection on 3-trader pairwise; exact deltas on partial-fill (-30/+30, +30/-30) and concurrent-matching (-200/+200, +200/-200, 0/0).multi-agent-disjoint.test.ts: exact deltas on all four traders for both pairs through the same escrow.negotiation-failures.test.ts:pollUntilBalanceRestoredafter every FAILED transition, including the canonical deposit-timeout "did Alice get her tokens back?" case.basic-roundtrip.test.ts: cancel-before-match and intent-expires assert balance unchanged.surplus-refund.e2e-live.test.ts(new): trader'saccounting_auto_return_enabledlog line asserted at startup.Known limitations
incompatible rate ranges,self-match,blocked counterparty,volume-floor mismatch) intentionally do NOT add strict balance-unchanged assertions: the testnet aggregator is shared, and a fresh intent could legitimately match an unrelated peer during the quiet window. The intent-level assertions (volume_filled === 0non the named intents) remain the right granularity.Expected behavior on first run
The negotiation-failures balance-restoration assertions may fail under current product behavior — that is the intended surfacing of gaps Claim 5b was designed to catch. If those fail, the right fix is product-side (escrow auto-return + trader's setAutoReturn must actually refund deposited funds).
Test plan