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
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
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>
This commit is contained in:
1 parent
1d5b8cdd53
commit
def926d41e
11 files changed
+391
-21
No files matched your search
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
// The contract Gandalf depends on (gandalf/monitor.py PulseClient.run_command):
|
||||
// POST /api/internal/command -> {execution_id}; poll GET /api/internal/executions/:id
|
||||
// until status is 'completed' (stdout read from the command_result log) or 'failed'.
|
||||
const { gandalf, workerByName, waitForExecution, commandResult } = require('./helpers');
|
||||
|
||||
let workerId;
|
||||
beforeAll(async () => {
|
||||
workerId = (await workerByName('node-01')).id;
|
||||
});
|
||||
|
||||
test('a command runs and its stdout comes back the way Gandalf reads it', async () => {
|
||||
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'echo REACHABLE' });
|
||||
expect(submit.status).toBe(200);
|
||||
expect(submit.json.execution_id).toMatch(/^[0-9a-f-]{36}$/);
|
||||
|
||||
const ex = await waitForExecution(submit.json.execution_id);
|
||||
expect(ex.status).toBe('completed');
|
||||
expect(ex.started_by).toBe('gandalf:link_stats');
|
||||
expect(commandResult(ex).stdout.trim()).toBe('REACHABLE');
|
||||
});
|
||||
|
||||
test('a failing command ends as failed, with the exit code and stderr kept', async () => {
|
||||
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'echo oops >&2; exit 4' });
|
||||
const ex = await waitForExecution(submit.json.execution_id);
|
||||
expect(ex.status).toBe('failed');
|
||||
const r = commandResult(ex);
|
||||
expect(r.success).toBe(false);
|
||||
expect(r.exit_code).toBe(4);
|
||||
expect(r.stderr).toContain('oops');
|
||||
});
|
||||
|
||||
test.each([
|
||||
['a wrong key', 'not-the-key'],
|
||||
['no key', null],
|
||||
])('%s is refused on both endpoints', async (_label, key) => {
|
||||
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'true' }, key);
|
||||
expect(submit.status).toBe(401);
|
||||
const poll = await gandalf('GET', '/api/internal/executions/00000000-0000-0000-0000-000000000000', undefined, key);
|
||||
expect(poll.status).toBe(401);
|
||||
});
|
||||
|
||||
test('missing fields and unknown workers are rejected without creating an execution', async () => {
|
||||
expect((await gandalf('POST', '/api/internal/command', { worker_id: workerId })).status).toBe(400);
|
||||
expect((await gandalf('POST', '/api/internal/command', { command: 'true' })).status).toBe(400);
|
||||
const unknown = await gandalf('POST', '/api/internal/command', { worker_id: 'no-such-worker', command: 'true' });
|
||||
expect(unknown.status).toBe(400);
|
||||
expect(unknown.json.error).toBe('Worker not connected');
|
||||
});
|
||||
|
||||
test('an unknown execution id is a 404', async () => {
|
||||
const r = await gandalf('GET', '/api/internal/executions/00000000-0000-0000-0000-000000000000');
|
||||
expect(r.status).toBe(404);
|
||||
});
|
||||
Reference in new issue
Block a user