fix(host-tests): speak TLS to the canonical conformance fake server #18

Merged
troed merged 1 commit from fix/host-conformance-wss-fixture into devel 2026-10-14 19:55:29 +02:00
Owner

fix(host-tests): speak TLS to the canonical conformance fake server

Why

Piece 3 (computer) made the canonical fake realtime server TLS-only:
FakeServer.__init__(ssl_context, ota_schedule=None) now takes a required
SSLContext. The esp32 host suite loads that file by path, so once
computer's devel carried piece 3, all six esp32 conformance tests died at
fixture setup -- loudly, exactly as intended:

TypeError: FakeServer.__init__() missing 1 required positional argument: 'ssl_context'

Before this branch: 152 passed, 6 errors. After: 158 passed.

What

The esp32 suite now pairs the fake server with an ephemeral, in-test
self-signed leaf and dials wss:// -- the same "test doubles mint their own
throwaway certificate" rule the fleet TLS design states, never the shared
../.dev-trust set.

  • host/tests/tls_certs.py (new): mint a two-day self-signed leaf with
    openssl and build the paired server/client contexts. Self-contained --
    this is the esp32-side counterpart of computer/tests/tls_certs.py, not a
    cross-repo import.
  • host/tests/fake_server_fixture.py: session-scoped throwaway cert, pass
    ssl_context= to FakeServer, expose a client context that trusts it.
  • host/tests/conftest.py: ws_url is now wss://...; re-export the cert
    fixture.
  • host/tests/test_conformance.py: use the asyncio client, not
    websockets.sync.client.
  • host/tests/requirements.txt: websockets>=13 -- the harness imports
    websockets.asyncio, which 12.0 does not provide.
  • docs/conformance.md: say the harness is TLS-only.

Why the asyncio client (and not the sync one)

The first cut of this branch used websockets.sync.client in wss:// mode and
turned the suite flaky (~1 in 6-10 runs). Measured on this host (Python
3.14, websockets 17.2), same server, same certificate, same conditions:

client result
websockets.sync.client 3-8 failures / 120 connects
websockets.connect (asyncio) 0 failures / 120 connects

Every failure is the client's opening handshake never completing --
TimeoutError: timed out while waiting for handshake response after the full
10 s open_timeout -- and instrumenting the server shows its handler never
ran
for that connection: the connection is never taken through the
handshake server-side. It is not root-caused to a definitive line, and it is
not resource exhaustion (at failure: 113 threads, 342 fds, cgroup pids 118 --
well inside limits). The asyncio client is clean over the same load, and it is
the pattern computer/tests/conformance already uses.

Verification

Command (host/tests):

python3 -m pytest -q
  • 30/30 consecutive conformance-only runs green (180 TLS connects).
  • 8/8 consecutive full-suite runs green, 158 passed each.

Follow-up

Piece 2's Task 6 (the on-hardware dev-trust run) is still deferred; it is not
affected by this change.

# fix(host-tests): speak TLS to the canonical conformance fake server ## Why Piece 3 (`computer`) made the canonical fake realtime server **TLS-only**: `FakeServer.__init__(ssl_context, ota_schedule=None)` now takes a required `SSLContext`. The esp32 host suite loads that file *by path*, so once `computer`'s `devel` carried piece 3, all six esp32 conformance tests died at fixture setup -- loudly, exactly as intended: ``` TypeError: FakeServer.__init__() missing 1 required positional argument: 'ssl_context' ``` Before this branch: **152 passed, 6 errors**. After: **158 passed**. ## What The esp32 suite now pairs the fake server with an ephemeral, in-test self-signed leaf and dials `wss://` -- the same "test doubles mint their own throwaway certificate" rule the fleet TLS design states, never the shared `../.dev-trust` set. - `host/tests/tls_certs.py` (new): mint a two-day self-signed leaf with `openssl` and build the paired server/client contexts. Self-contained -- this is the esp32-side counterpart of `computer/tests/tls_certs.py`, not a cross-repo import. - `host/tests/fake_server_fixture.py`: session-scoped throwaway cert, pass `ssl_context=` to `FakeServer`, expose a client context that trusts it. - `host/tests/conftest.py`: `ws_url` is now `wss://...`; re-export the cert fixture. - `host/tests/test_conformance.py`: use the **asyncio** client, not `websockets.sync.client`. - `host/tests/requirements.txt`: `websockets>=13` -- the harness imports `websockets.asyncio`, which 12.0 does not provide. - `docs/conformance.md`: say the harness is TLS-only. ## Why the asyncio client (and not the sync one) The first cut of this branch used `websockets.sync.client` in `wss://` mode and turned the suite **flaky** (~1 in 6-10 runs). Measured on this host (Python 3.14, websockets 17.2), same server, same certificate, same conditions: | client | result | | --- | --- | | `websockets.sync.client` | 3-8 failures / 120 connects | | `websockets.connect` (asyncio) | 0 failures / 120 connects | Every failure is the client's opening handshake never completing -- `TimeoutError: timed out while waiting for handshake response` after the full 10 s `open_timeout` -- and instrumenting the server shows its handler **never ran** for that connection: the connection is never taken through the handshake server-side. It is not root-caused to a definitive line, and it is not resource exhaustion (at failure: 113 threads, 342 fds, cgroup pids 118 -- well inside limits). The asyncio client is clean over the same load, and it is the pattern `computer/tests/conformance` already uses. ## Verification Command (`host/tests`): ``` python3 -m pytest -q ``` - 30/30 consecutive conformance-only runs green (180 TLS connects). - 8/8 consecutive full-suite runs green, `158 passed` each. ## Follow-up Piece 2's Task 6 (the on-hardware dev-trust run) is still deferred; it is not affected by this change.
Piece 3 (computer) made the canonical fake realtime server TLS-only:
FakeServer.__init__ now requires an ssl.SSLContext, so the esp32 host
conformance fixture failed at setup ("FakeServer.__init__() missing 1
required positional argument: 'ssl_context'") for all six conformance
tests. Pair the server with a throwaway self-signed leaf and dial wss://.

- host/tests/tls_certs.py: mint a two-day self-signed leaf with openssl and
  build the paired server/client contexts. Self-contained: this is the
  esp32-side copy of computer/tests/tls_certs.py, never a cross-repo import.
- fake_server_fixture.py: session-scoped throwaway cert, pass ssl_context=
  to FakeServer, expose a client context that trusts it.
- conftest.py: ws_url is now wss://; re-export the cert fixture.
- test_conformance.py: use the asyncio client, not websockets.sync.client.
  Over this TLS harness the sync client intermittently (~5%) never receives
  the opening handshake response and dies with "timed out while waiting for
  handshake response" after the full open_timeout, while the asyncio client
  is clean over the same connections (180+ verified). It is also the pattern
  computer's own conformance suite uses.
- requirements.txt: websockets>=13 -- the harness imports
  websockets.asyncio, which 12.0 does not provide.
- docs/conformance.md: say the harness is TLS-only.

Verified: host suite 158 passed across 8 consecutive full runs (was 152
passed + 6 errors before this change) and 30/30 conformance-only runs.
troed merged commit 328d00404a into devel 2026-10-14 19:55:29 +02:00
troed deleted branch fix/host-conformance-wss-fixture 2026-10-14 19:55:29 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starfleet/communicator-esp32!18
No description provided.