Files
pulse/tests/integration/gandalf.int.js
T
jaredandClaude Opus 5.5 eda319e16a
CI / Test (jest) (pull_request) Successful in 27s
CI / Lint (eslint) (pull_request) Successful in 31s
CI / Security (npm audit) (pull_request) Successful in 11s
CI / Integration (api) (pull_request) Canceled after 1m56s
CI / Scan (secrets, workflows, shell) (pull_request) Canceled after 1m48s
CI / UI (playwright) (pull_request) Canceled after 0s
CI / UI screenshots (before/after) (pull_request) Canceled after 0s
CI / Deploy (pull_request) Canceled after 0s
CI / Deploy worker (pull_request) Canceled after 0s
CI / Notify (pull_request) Canceled after 0s
Executions list: show what a command ran and on which worker (#15)
Every command execution was listed as "[Quick Command]". The list API now
returns, for command executions, the first command (up to 120 characters)
and the worker's name (from the first log entry, joined to workers), and
the row shows them as `command @ worker`. Workflows keep their name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 13:27:12 -05:00

87 lines
4.5 KiB
JavaScript

'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, sso, 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);
});
test('the Automated and Manual views filter on the server (#4)', async () => {
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: 'echo automated' });
await waitForExecution(submit.json.execution_id);
const auto = (await sso('GET', '/api/executions?only_internal=true&limit=200')).json;
const manual = (await sso('GET', '/api/executions?hide_internal=true&limit=200')).json;
const automated = by => /^(gandalf|scheduler):/.test(by || '');
expect(auto.executions.length).toBeGreaterThan(0);
expect(auto.executions.every(e => automated(e.started_by))).toBe(true);
expect(manual.executions.some(e => automated(e.started_by))).toBe(false);
expect(auto.executions.some(e => e.id === submit.json.execution_id)).toBe(true);
});
test('execution search finds runs by the command they ran (#16)', async () => {
const marker = `srch-${Date.now().toString(36)}`;
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: `echo ${marker}` });
await waitForExecution(submit.json.execution_id);
const hit = (await sso('GET', `/api/executions?search=${marker}&limit=50`)).json;
expect(hit.executions.map(e => e.id)).toEqual([submit.json.execution_id]);
const byId = (await sso('GET', `/api/executions?search=${submit.json.execution_id.slice(0, 13)}`)).json;
expect(byId.executions.map(e => e.id)).toContain(submit.json.execution_id);
expect((await sso('GET', '/api/executions?search=no-such-command-anywhere')).json.executions).toEqual([]);
});
test('the execution list says what a command ran and where (#15)', async () => {
const marker = `sum-${Date.now().toString(36)}`;
const submit = await gandalf('POST', '/api/internal/command', { worker_id: workerId, command: `echo ${marker}` });
await waitForExecution(submit.json.execution_id);
const row = (await sso('GET', `/api/executions?search=${marker}`)).json.executions[0];
expect(row).toMatchObject({ command: `echo ${marker}`, worker_name: 'node-01' });
});