The mock vault implements just enough of the vault server API for the app's remote vault code to connect, sync and fail in controlled ways. It encrypts with the app's own crypto functions, so the envelope and state formats it serves are the ones the app must read.
Files
File | Role |
|---|---|
| |
Standalone fallback that serves only the vault routes on port 4790. Its comment calls it a fallback "until the lead mounts routes.ts"; the test server now mounts them, so it is not needed for normal runs | |
A scripted drive of the built app through the whole vault flow, with screenshots |
The vault URL a test types is http://127.0.0.1:4790/vault.
Fixed fixtures
Defined at the top of routes.ts L14-L25. All are test bytes, not secrets:
Name | Value |
|---|---|
Credential secret | 32 bytes of |
DEK (data encryption key) | 64 bytes of |
|
|
|
|
State after reset | One account |
API endpoints
Method and path | Behaviour |
|---|---|
| An HTML approval page with one Approve button. It reads |
| The one time mailbox. |
| Needs |
| Same auth. Body |
| Same auth. |
The mailbox payload is JSON {vaultUrl, userId, credentialId, secret} encrypted with the 32 byte connect token (routes.ts L65-L78). See Vault: connect ceremony and Vault: API and sync.
Control endpoints
All are POST with a JSON body, under /vault/__test/:
Path | Body | Effect |
|---|---|---|
|
| Restores the reset state, clears conflicts, counters and mailboxes |
|
| The next |
|
| Wraps the DEK with a wrong key (32 bytes of |
|
| Puts an encrypted approval in the mailbox. |
|
| Adds account |
| any |
|
Who uses it
vault.test.ts (27 tests): replaces globalThis.fetch with a function that calls handle directly and throws on any other URL, then resets before each test. It covers connect, wrong mailbox key, URL mismatch, retry after an aborted reply, three conflicts, corrupt DEK, tombstones, lock and logout.
vault.test.contract (3 tests): local state, an invalid URL, and a pending connection that warns after clock + 6000 with fetches failing and expires after clock + 900000. Contract request steps take literal JSON only, so a test cannot pass the generated token to approve; approval is left to the drive.
drive.mjs: completes the approval by reading the token out of the app's connect link.
The scripted drive
bun exact.mjs test web # builds target/web-dist
bun tools/mock-vault/drive.mjs web # or ios; needs the test server on 4790It imports open and textOf from Exact's scripts/agent.mjs (EXACT env, default ~/Code/exact), opens the app at /me/vault on fresh storage with seed: 42, and runs two sessions:
Local mode, connect and cancel, connect and approve, remote identities visible in Me, one forced 409 with a local import uploaded (writes >= 2), background sync paused while visibility-state is hidden across clock +30000, a remote addition appearing, a corrupt DEK error and recovery, lock, unlock, back to local.
A wrong mailbox key ("Failed to decrypt vault connect payload."), retry, and confirmed logout.
Screenshots in light and dark go to ~/.local/state/seed-mobile-exact/screenshots/vault/<host>-<name>-<scheme>.png.
Related
Real vault compatibility suite, the same flows against the real server
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime