Commit b6a099f
authored
test: Harden browser contract-test adapter against unanswered-command hangs (#1399)
## Summary
The browser SDK contract-test **adapter** (`startAdapter.ts`) forwarded
each command to the browser entity over WebSocket and waited **forever**
for a reply. If the browser ever missed one reply, that REST request —
and therefore the harness — hung indefinitely (even capability/status
queries returned `000`), with no recovery path. This permanently wedged
the service, which is especially painful when reusing one service across
many runs (e.g. flake hunting).
This PR makes the adapter resilient:
- **Timeout on `send()`** (`ADAPTER_REQUEST_TIMEOUT_MS`, default
**30s**). A stalled command now fails that single request with **HTTP
500** so the harness fails that one test and continues, instead of
wedging the whole chain.
- **Reject in-flight commands on WebSocket close**, so no REST request
is left waiting on a dead socket.
- **Error handler on REST `listen()`** so a silent bind failure (e.g.
the port still being held → "WS up but REST never bound") is logged
instead of disappearing.
Changes are confined to test tooling; no SDK runtime code is touched.
## Verification
5 consecutive full suites against one reused adapter/browser stayed
green — `ec=0, fail=0`, adapter responsive at ~1 ms throughout. The
timeout path turns a previously-permanent hang into a single failed
request the harness can recover from.
## Notes
- An earlier revision of this branch also had the entity destroy
leftover clients on `getCapabilities`. **That was removed**:
`getCapabilities` is not a safe "new run" signal because multiple
harnesses can drive one entity concurrently, so it could wipe another
run's active clients. The lingering-final-client cleanup needs a
different, run-aware approach and is out of scope here.
- `packages/sdk/browser/example-fdv2/src/app.ts` has unrelated local
debugging tweaks and is intentionally not part of this branch.
## Test coverage
This tooling package has no unit-test harness; validation was
integration-based (above).
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Only internal contract-test adapter tooling is modified; no production
SDK or auth/data paths are affected.
>
> **Overview**
> The contract-test **adapter** (`startAdapter`) no longer waits
indefinitely for browser-entity WebSocket replies. **`send()`** now uses
a configurable timeout (`requestTimeoutMs` /
`ADAPTER_REQUEST_TIMEOUT_MS`, default **30s**) and rejects with a clear
error; **`waiters`** are scoped **per WebSocket** and include timers
plus **reject on socket close**, so a dropped connection does not leave
unrelated REST calls stuck.
>
> Async REST routes are wrapped with a **`guard`** that maps failures
(timeout, closed socket, etc.) to **HTTP 500** instead of unhandled
rejections that could hang the harness. The REST **`listen()`** server
also gets an **`error`** handler so bind failures (e.g. `EADDRINUSE`)
are logged.
>
> Changes are limited to internal contract-test tooling; SDK runtime is
unchanged.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d62dc65. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent bce024c commit b6a099f
1 file changed
Lines changed: 123 additions & 51 deletions
Lines changed: 123 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
13 | 30 | | |
14 | 31 | | |
15 | 32 | | |
16 | 33 | | |
17 | 34 | | |
18 | 35 | | |
19 | 36 | | |
| 37 | + | |
| 38 | + | |
20 | 39 | | |
21 | 40 | | |
22 | | - | |
23 | 41 | | |
24 | 42 | | |
25 | 43 | | |
26 | 44 | | |
27 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
28 | 52 | | |
29 | 53 | | |
30 | | - | |
31 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
32 | 57 | | |
| 58 | + | |
33 | 59 | | |
34 | 60 | | |
35 | 61 | | |
36 | 62 | | |
37 | 63 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
43 | 72 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
49 | 104 | | |
50 | 105 | | |
51 | 106 | | |
| |||
63 | 118 | | |
64 | 119 | | |
65 | 120 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
71 | 129 | | |
72 | 130 | | |
73 | 131 | | |
74 | 132 | | |
75 | 133 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
90 | 151 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
106 | 170 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
111 | 178 | | |
112 | 179 | | |
113 | 180 | | |
114 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
115 | 187 | | |
116 | 188 | | |
0 commit comments