| 1 | // Run: tsx src/__tests__/submission-id-bridge-mock.test.ts |
| 2 | |
| 3 | import { app, onEvent } from "../lib/bridge"; |
| 4 | import type { WireEvent } from "../lib/types"; |
| 5 | |
| 6 | let passed = 0; |
| 7 | let failed = 0; |
| 8 | |
| 9 | function eq(actual: unknown, expected: unknown, label: string) { |
| 10 | if (actual === expected) { |
| 11 | process.stdout.write(` PASS ${label}\n`); |
| 12 | passed += 1; |
| 13 | } else { |
| 14 | process.stdout.write(` FAIL ${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}\n`); |
| 15 | failed += 1; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | console.log("\nsubmission id browser mock contract"); |
| 20 | |
| 21 | const events: WireEvent[] = []; |
| 22 | const off = onEvent((event) => events.push(event)); |
| 23 | const submit = app.SubmitToTabWithID("mock-correlation-tab", "mock correlation turn", "opaque-correlation"); |
| 24 | await new Promise((resolve) => setTimeout(resolve, 0)); |
| 25 | |
| 26 | const started = events.find((event) => event.kind === "turn_started"); |
| 27 | eq(started?.tabId, "mock-correlation-tab", "mock TurnStarted keeps the submitted tab scope"); |
| 28 | eq(started?.submissionId, "opaque-correlation", "mock TurnStarted carries the local submission correlation"); |
| 29 | |
| 30 | await app.CancelTab("mock-correlation-tab"); |
| 31 | await submit; |
| 32 | off(); |
| 33 | |
| 34 | console.log(`\n${passed} passed, ${failed} failed, ${passed + failed} total`); |
| 35 | if (failed > 0) process.exit(1); |
| 36 |