Integration tests (Gandalf contract, auth, reliability); fix worker offline status #50

Merged
jared merged 1 commits from ci-integration into main 2026-11-22 14:21:47 -05:00
Owner

Part of #45 (phase 3).

New CI job: Integration (api)

The job runs the real server and three workers on Node 20 (production's version) against MariaDB. It then tests them as a black box over HTTP and WebSocket: 20 tests, about 12 s. I used this instead of the app-factory refactor I'd planned: it tests what Gandalf and the workers actually talk to, with no changes to server.js.

Suite Checks
gandalf.int.js Gandalf's exact submit and poll flow (monitor.py run_command). A completed command's stdout comes from command_result. A failed one keeps its exit code and stderr. A wrong or missing key gets 401 on both endpoints. Missing fields or an unknown worker get 400; an unknown execution gets 404
auth.int.js SSO identity, the 401 and 403 cases, the heartbeat key, and that /healthz exposes only status. The WebSocket upgrade is refused with no credentials, a wrong key or a wrong group. A signed-in browser gets live events, and a browser socket can't forge a command result
reliability.int.js A worker killed mid-command fails the execution at once. A worker at capacity answers with a failure. An aborted execution stays failed when the late result arrives. A disconnected worker shows offline

Tests that need to kill or limit a worker start their own, and delete it afterwards.

Bug found and fixed (from #42)

A disconnected worker was never marked offline: it showed "online" until the stale-heartbeat sweep. The close handler deleted the worker's runtime-id entry first, then checked whether the socket was still live under its database id. Those ids are normally the same key, so the check always failed. The fix decides whether the socket is live before unmapping anything. Without the fix, all 4 reliability tests fail; with it, they pass.

Gandalf wasn't affected, because /api/internal/command checks live sockets, not the database status.

Other

  • scripts/ci/mariadb.sh now handles the in-container MariaDB setup for both the integration and UI jobs.
  • Deploy waits for all five checks.
  • README: a new "Integration tests" section.

Verification (local)

  • Lint has 0 errors; jest unit 67/67; integration 20/20; Playwright 30/30.
  • I ran integration then UI on the same stack to confirm the integration tests clean up after themselves.

After merge, I'll add CI / Integration (api) (push) to the required checks.

🤖 Generated with Claude Code

Part of #45 (phase 3). ## New CI job: `Integration (api)` The job runs the real server and three workers on **Node 20** (production's version) against MariaDB. It then tests them as a black box over HTTP and WebSocket: 20 tests, about 12 s. I used this instead of the app-factory refactor I'd planned: it tests what Gandalf and the workers actually talk to, with no changes to `server.js`. | Suite | Checks | |---|---| | `gandalf.int.js` | Gandalf's exact submit and poll flow (`monitor.py` `run_command`). A completed command's stdout comes from `command_result`. A failed one keeps its exit code and stderr. A wrong or missing key gets 401 on both endpoints. Missing fields or an unknown worker get 400; an unknown execution gets 404 | | `auth.int.js` | SSO identity, the 401 and 403 cases, the heartbeat key, and that `/healthz` exposes only status. The WebSocket upgrade is refused with no credentials, a wrong key or a wrong group. A signed-in browser gets live events, and **a browser socket can't forge a command result** | | `reliability.int.js` | A worker killed mid-command fails the execution at once. A worker at capacity answers with a failure. An aborted execution stays failed when the late result arrives. A disconnected worker shows offline | Tests that need to kill or limit a worker start their own, and delete it afterwards. ## Bug found and fixed (from #42) A disconnected worker was **never marked offline**: it showed "online" until the stale-heartbeat sweep. The close handler deleted the worker's runtime-id entry first, then checked whether the socket was still live under its database id. Those ids are normally the same key, so the check always failed. The fix decides whether the socket is live before unmapping anything. Without the fix, all 4 reliability tests fail; with it, they pass. Gandalf wasn't affected, because `/api/internal/command` checks live sockets, not the database status. ## Other - `scripts/ci/mariadb.sh` now handles the in-container MariaDB setup for both the integration and UI jobs. - Deploy waits for all five checks. - README: a new "Integration tests" section. ## Verification (local) - Lint has 0 errors; jest unit 67/67; integration 20/20; Playwright 30/30. - I ran integration then UI on the same stack to confirm the integration tests clean up after themselves. After merge, I'll add `CI / Integration (api) (push)` to the required checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-22 14:14:48 -05:00
Integration tests for the Gandalf contract, auth and reliability; fix worker offline status
CI / Lint (eslint) (push) Successful in 46s
CI / Security (npm audit) (push) Successful in 26s
CI / Integration (api) (push) Successful in 1m31s
CI / Test (jest) (pull_request) Successful in 50s
CI / UI (playwright) (push) Successful in 2m31s
CI / Integration (api) (pull_request) Successful in 1m58s
CI / Test (jest) (push) Successful in 13s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Successful in 2m16s
CI / Lint (eslint) (pull_request) Successful in 15s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
def926d41e
New CI job `Integration (api)` (#45 phase 3) runs the real server and three
workers on Node 20 against MariaDB and tests them as a black box over HTTP
and WebSocket (20 tests, about 12 s):

- Gandalf contract: submit and poll, stdout from command_result, failures
  with exit code and stderr, 401 for wrong or missing key, 400 for missing
  fields or an unknown worker, 404 for an unknown execution
- Auth: SSO identity, 401/403, heartbeat key, /healthz exposes only status;
  WebSocket upgrade refused without credentials, with a wrong key or a wrong
  group; live events reach a signed-in browser; a browser socket cannot
  forge a command result
- Reliability: a worker killed mid-command fails the execution at once; a
  worker at capacity answers with a failure; an aborted execution stays
  failed when the late result arrives; a disconnected worker shows offline

The last test found a bug from #42: the close handler deleted the worker's
runtime-id entry before checking whether the socket was still live under its
database id, and the two ids are normally the same key. So a disconnected
worker was never marked offline and showed 'online' until the stale
heartbeat sweep. Gandalf was unaffected (it checks live sockets).

MariaDB setup for CI moves to scripts/ci/mariadb.sh, shared by both jobs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared merged commit 4f32bd1363 into main 2026-11-22 14:21:47 -05:00
jared deleted branch ci-integration 2026-11-22 14:21:50 -05:00
Sign in to join this conversation.