The contract suite
Every bridge passes this suite: the web fallback, and each native shell. It is the evidence behind "swapping a shell is a config change".
It has no test-runner dependency. Each case is a name and an async function that throws
on failure, so the same cases run under bun test against the web fallback and inside a
Swift or Tauri shell's own web view, where there is no bun:test. runContract() runs them
all and returns a report; src/contract.test.ts adapts them to bun test one case per test.
The harness
A shell under test supplies a harness:
make(capabilities)returns a fresh bridge with no saves, purchases or achievements, built forCONTRACT_CONFIG, or, whencapabilitiesis given, built as if the config declared exactly those (which is how the suite checks that the undeclared is refused);expects, optionally, lists the capabilities this shell must report forCONTRACT_CONFIG, so a shell that quietly lost one fails instead of skipping its cases;completes, optionally, lists the interactions that finish with no person present:'links'(opening a link),'share'(a share sheet) and'prompts'(asking the player for a permission). A shell under an unattended run validates the call and answers without showing anything; the cases that need the real thing are skipped where it cannot;purchasesis'approve'when a purchase completes without a person (the web fallback, a StoreKit test configuration), or'manual'when it cannot, which skips the cases that buy;reopen(bridge), optionally, returns a new bridge over the same persisted state, as if the app had been quit and relaunched;simulate, optionally, haspause()andresume()functions that make the shell emit those events, for the shells that can, andsaved(bridge, key, value), which makes a save arrive as if another device had written it (valueisnullfor one removed there),filed(bridge, name, base64), which puts a file in the app's folder from outside,opened(bridge, id), which is the player opening the app through that notification,refunded(bridge, productId), which is the store taking that purchase back (a refund), outside any call the game made,located(bridge, fixes), which is the device reporting those positions to the watch, in order, andtop(bridge), which is the player tapping an iPhone's status bar.holding(), optionally, answers whether the shell is holding the app awake right now, for the shells that hold it while the page pauses.
The suite's own files are all named contract-…, and a shell's fresh state removes only
those, so running it never touches a file the player made.
A case that needs something the harness lacks is skipped and reported as skipped, never passed.
runContract
Runs every case and reports each as passed, failed or skipped. For a shell's web view,
where a report is all there is to send back.