Merge pull request 'Quick Command shows the output right under the form' (#81) from quick-inline-output into main
CI / UI screenshots (before/after) (push) Skipped
CI / Security (npm audit) (push) Successful in 33s
CI / Test (jest) (push) Failing after 35s
CI / Lint (eslint) (push) Canceled after 0s
CI / Integration (api) (push) Canceled after 1m56s
CI / Scan (secrets, workflows, shell) (push) Canceled after 1m55s
CI / UI (playwright) (push) Canceled after 0s
CI / Deploy (push) Canceled after 0s
CI / Deploy worker (push) Canceled after 0s
CI / Notify (push) Successful in 4s
CI / UI screenshots (before/after) (push) Skipped
CI / Security (npm audit) (push) Successful in 33s
CI / Test (jest) (push) Failing after 35s
CI / Lint (eslint) (push) Canceled after 0s
CI / Integration (api) (push) Canceled after 1m56s
CI / Scan (secrets, workflows, shell) (push) Canceled after 1m55s
CI / UI (playwright) (push) Canceled after 0s
CI / Deploy (push) Canceled after 0s
CI / Deploy worker (push) Canceled after 0s
CI / Notify (push) Successful in 4s
This commit was merged in pull request #81.
This commit is contained in:
commit
33a3f7c0b9
6 files changed
+195
-64
No files matched your search
@@ -182,3 +182,8 @@ html[data-theme="light"] .pulse-dim { color: var(--text-muted); }
|
||||
html[data-theme="light"] .pulse-running {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* The `hidden` attribute must win over component display rules such as
|
||||
.lt-form-group { display: flex }, or hidden sections still show (both
|
||||
Quick Command worker pickers were visible in either mode). */
|
||||
[hidden] { display: none !important; }
|
||||
@@ -83,3 +83,38 @@
|
||||
color: var(--text-muted);
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
/* Results under the form, one card per worker (#5). */
|
||||
.qc-run-summary {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.qc-run {
|
||||
border: 1px solid var(--border-dim, var(--border-color));
|
||||
background: var(--bg-primary);
|
||||
padding: 0.6rem 0.75rem;
|
||||
margin-bottom: 0.6rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.qc-run-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.4rem 0.75rem;
|
||||
}
|
||||
.qc-run-time { color: var(--text-muted); font-size: 0.75rem; }
|
||||
.qc-run-link { margin-left: auto; font-size: 0.75rem; }
|
||||
.qc-run-body pre {
|
||||
max-height: 24rem;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
margin: 0.5rem 0 0;
|
||||
}
|
||||
.qc-out-err {
|
||||
color: var(--accent-red);
|
||||
border-left-color: var(--accent-red);
|
||||
text-shadow: none;
|
||||
}
|
||||
.qc-out-note { color: var(--text-muted); font-size: 0.72rem; margin-top: 0.4rem; }
|
||||
+108
-56
@@ -166,65 +166,117 @@
|
||||
/* -------------------------------------------------------------------
|
||||
Result rendering
|
||||
------------------------------------------------------------------- */
|
||||
function renderSingleSuccess(executionId) {
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-alert lt-alert--success">' +
|
||||
'<span class="lt-alert-icon">✓</span>' +
|
||||
'<div class="lt-alert-body">' +
|
||||
'<div class="lt-alert-title">Command sent successfully</div>' +
|
||||
'<div class="lt-alert-msg">Execution ID: <code>' + esc(executionId) + '</code> | ' +
|
||||
'<a href="/executions?open=' + encodeURIComponent(executionId) + '">view in Executions</a>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
/* Results show here as they arrive, per worker, instead of only in Executions (#5).
|
||||
A card per run: "running" until its command_result comes in over the live
|
||||
connection, or a poll finds it finished if that event was missed. */
|
||||
const OUTPUT_MAX = 100000; // characters shown per stream
|
||||
const _runs = new Map(); // execution id -> { card, startedAt, timer }
|
||||
const _early = new Map(); // results that beat the POST response
|
||||
|
||||
function forgetRuns() {
|
||||
_runs.forEach(r => clearTimeout(r.timer));
|
||||
_runs.clear();
|
||||
}
|
||||
|
||||
function renderSingleFailure(message) {
|
||||
function renderRuns(entries, summary) {
|
||||
forgetRuns();
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-alert lt-alert--error">' +
|
||||
'<span class="lt-alert-icon">✕</span>' +
|
||||
'<div class="lt-alert-body">' +
|
||||
'<div class="lt-alert-title">Command failed</div>' +
|
||||
'<div class="lt-alert-msg">' + esc(message) + '</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
const head = summary ? '<div class="qc-run-summary">' + esc(summary) + '</div>' : '';
|
||||
wrap.innerHTML = head + entries.map(runCard).join('');
|
||||
entries.forEach((e, i) => {
|
||||
if (!e.executionId) return;
|
||||
const run = { card: document.getElementById('qc-run-' + i), startedAt: Date.now(), timer: null };
|
||||
_runs.set(e.executionId, run);
|
||||
if (_early.has(e.executionId)) { showResult(e.executionId, _early.get(e.executionId)); return; }
|
||||
run.timer = setTimeout(() => pollRun(e.executionId, 0), 5000);
|
||||
});
|
||||
}
|
||||
|
||||
function renderMultiResult(results, successCount, failCount) {
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
const rows = results.map(r =>
|
||||
'<tr>' +
|
||||
'<td data-label="Worker">' + esc(r.worker) + '</td>' +
|
||||
'<td data-label="Result">' +
|
||||
(r.success
|
||||
? '<span class="lt-status lt-status-completed">✓ Sent (' + esc(String(r.executionId || '').slice(0, 8)) + '…)</span>'
|
||||
: '<span class="lt-status lt-status-failed">✕ ' + esc(r.error) + '</span>') +
|
||||
'</td>' +
|
||||
'</tr>'
|
||||
).join('');
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-alert' + (failCount === 0 ? ' lt-alert--success' : (successCount === 0 ? ' lt-alert--error' : ' lt-alert--warning')) + '">' +
|
||||
'<div class="lt-alert-body">' +
|
||||
'<div class="lt-alert-title">Multi-worker execution complete</div>' +
|
||||
'<div class="lt-alert-msg">Success: ' + successCount + ' | Failed: ' + failCount + '</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<table class="lt-table lt-table-sm lt-table-responsive">' +
|
||||
'<thead><tr><th>Worker</th><th>Result</th></tr></thead>' +
|
||||
'<tbody>' + rows + '</tbody>' +
|
||||
'</table>';
|
||||
function runCard(e, i) {
|
||||
const id = e.executionId;
|
||||
const worker = esc(e.worker);
|
||||
if (!id) {
|
||||
return '<div class="qc-run" id="qc-run-' + i + '"><div class="qc-run-head">' +
|
||||
'<strong class="qc-run-worker">' + worker + '</strong>' +
|
||||
'<span class="lt-status lt-status-failed qc-run-status">✕ Not sent</span></div>' +
|
||||
'<div class="qc-run-body"><pre class="lt-log-output qc-out-err">' + esc(e.error || 'Failed to send') + '</pre></div></div>';
|
||||
}
|
||||
return '<div class="qc-run" id="qc-run-' + i + '"><div class="qc-run-head">' +
|
||||
'<strong class="qc-run-worker">' + worker + '</strong>' +
|
||||
'<span class="lt-status lt-status-running qc-run-status">Running…</span>' +
|
||||
'<span class="qc-run-time"></span>' +
|
||||
'<a class="qc-run-link" href="/executions?open=' + encodeURIComponent(id) + '">view in Executions</a></div>' +
|
||||
'<div class="qc-run-body"></div></div>';
|
||||
}
|
||||
|
||||
function clip(text) {
|
||||
const t = String(text || '');
|
||||
if (t.length <= OUTPUT_MAX) return esc(t);
|
||||
return esc(t.slice(0, OUTPUT_MAX)) + '\n<span class="qc-out-note">[' + (t.length - OUTPUT_MAX).toLocaleString() +
|
||||
' more characters: see the full output in Executions]</span>';
|
||||
}
|
||||
|
||||
function failureLabel(r) {
|
||||
if (r.timed_out) return 'Timed out';
|
||||
if (r.signal) return 'Killed (' + r.signal + ')';
|
||||
if (typeof r.exit_code === 'number') return 'Failed (exit ' + r.exit_code + ')';
|
||||
return 'Failed';
|
||||
}
|
||||
|
||||
function showResult(executionId, r) {
|
||||
const run = _runs.get(executionId);
|
||||
if (!run || !run.card) return;
|
||||
clearTimeout(run.timer);
|
||||
_runs.delete(executionId);
|
||||
_early.delete(executionId);
|
||||
const status = run.card.querySelector('.qc-run-status');
|
||||
const ok = Boolean(r.success);
|
||||
const label = ok ? 'Completed' : failureLabel(r);
|
||||
status.className = 'lt-status qc-run-status ' + (ok ? 'lt-status-completed' : 'lt-status-failed');
|
||||
status.textContent = (ok ? '\u2713 ' : '\u2715 ') + label;
|
||||
const ms = typeof r.duration === 'number' ? r.duration : Date.now() - run.startedAt;
|
||||
run.card.querySelector('.qc-run-time').textContent = ms < 1000 ? ms + ' ms' : (ms / 1000).toFixed(1) + ' s';
|
||||
const parts = [];
|
||||
if (r.stdout) parts.push('<pre class="lt-log-output qc-out">' + clip(r.stdout) + '</pre>');
|
||||
if (r.stderr) parts.push('<pre class="lt-log-output qc-out-err">' + clip(r.stderr) + '</pre>');
|
||||
if (!r.success && r.error && !r.stderr) parts.push('<pre class="lt-log-output qc-out-err">' + esc(r.error) + '</pre>');
|
||||
if (!parts.length) parts.push('<div class="qc-out-note">No output</div>');
|
||||
const body = run.card.querySelector('.qc-run-body');
|
||||
body.innerHTML = parts.join('');
|
||||
}
|
||||
|
||||
// Fallback for a result event that never arrived (e.g. the live connection dropped).
|
||||
async function pollRun(executionId, tries) {
|
||||
const run = _runs.get(executionId);
|
||||
if (!run) return;
|
||||
try {
|
||||
const ex = await Pulse.api.get('/api/executions/' + encodeURIComponent(executionId));
|
||||
if (ex && ex.status !== 'running') {
|
||||
const logs = Array.isArray(ex.logs) ? ex.logs : [];
|
||||
const r = logs.filter(l => l.action === 'command_result').pop();
|
||||
showResult(executionId, r || { success: ex.status === 'completed', error: 'No result recorded (' + ex.status + ')' });
|
||||
return;
|
||||
}
|
||||
} catch (e) { /* try again */ }
|
||||
if (tries < 180 && _runs.has(executionId)) run.timer = setTimeout(() => pollRun(executionId, tries + 1), 5000);
|
||||
}
|
||||
|
||||
function onCommandResult(data) {
|
||||
if (!data || !data.execution_id) return false;
|
||||
if (_runs.has(data.execution_id)) { showResult(data.execution_id, data); return true; }
|
||||
// Can arrive before the POST that started it returns: keep it briefly.
|
||||
_early.set(data.execution_id, data);
|
||||
if (_early.size > 100) _early.delete(_early.keys().next().value);
|
||||
return false;
|
||||
}
|
||||
|
||||
function renderExecuting(count) {
|
||||
forgetRuns();
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">Executing' +
|
||||
(count > 1 ? ' on ' + count + ' worker(s)' : '') + '…</div></div>';
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">Sending' +
|
||||
(count > 1 ? ' to ' + count + ' workers' : '') + '…</div></div>';
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
@@ -253,10 +305,9 @@
|
||||
try {
|
||||
const data = await Pulse.api.post('/api/workers/' + encodeURIComponent(workerId) + '/command', { command });
|
||||
addToHistory(command, workerName);
|
||||
renderSingleSuccess(data && data.execution_id);
|
||||
Pulse.beep('success');
|
||||
renderRuns([{ worker: workerName, executionId: data && data.execution_id }]);
|
||||
} catch (e) {
|
||||
renderSingleFailure(e.message || 'Failed to execute command');
|
||||
renderRuns([{ worker: workerName, error: e.message || 'Failed to execute command' }]);
|
||||
Pulse.beep('error');
|
||||
}
|
||||
return;
|
||||
@@ -283,10 +334,10 @@
|
||||
const successCount = results.filter(r => r.success).length;
|
||||
const failCount = results.length - successCount;
|
||||
addToHistory(command, workerIds.length + ' workers');
|
||||
renderMultiResult(results, successCount, failCount);
|
||||
if (failCount === 0) Pulse.beep('success');
|
||||
else if (successCount > 0) Pulse.beep('info');
|
||||
else Pulse.beep('error');
|
||||
renderRuns(results, failCount === 0
|
||||
? 'Sent to ' + successCount + ' workers'
|
||||
: 'Sent to ' + successCount + ' of ' + results.length + ' workers; ' + failCount + ' could not be reached');
|
||||
if (failCount > 0) Pulse.beep(successCount > 0 ? 'info' : 'error');
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
@@ -375,11 +426,12 @@
|
||||
return loadWorkers().then(() => { consumeRerun(); });
|
||||
}
|
||||
|
||||
function onEvent(type) {
|
||||
function onEvent(type, data) {
|
||||
if (type === 'worker_update') {
|
||||
loadWorkers();
|
||||
return true;
|
||||
}
|
||||
if (type === 'command_result') return onCommandResult(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -630,6 +630,7 @@ wss.on('connection', (ws, req) => {
|
||||
stdout: stdout,
|
||||
stderr: stderr,
|
||||
...failure,
|
||||
duration: duration,
|
||||
is_automated: isAutomated,
|
||||
});
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ test('empty states say what to do next (#33)', async ({ page }) => {
|
||||
await page.keyboard.press('Escape');
|
||||
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-multi').check(); // the checkbox list is the multi-worker picker
|
||||
await expect(page.locator('#qc-worker-list').getByRole('link', { name: 'Workers' })).toHaveAttribute('href', '/workers');
|
||||
|
||||
await page.goto('/workflows');
|
||||
|
||||
@@ -13,8 +13,11 @@ test('a quick command runs on a worker and its output shows in Executions', asyn
|
||||
await page.locator('#qc-command').fill(`echo ${marker}`);
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
// The output shows right under the form (#5), with a link to the full record.
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result).toContainText('Command sent successfully');
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Completed/);
|
||||
await expect(result.locator('pre.qc-out')).toHaveText(marker);
|
||||
await expect(result).toContainText('node-02');
|
||||
await result.getByRole('link', { name: 'view in Executions' }).click();
|
||||
|
||||
await expect(page).toHaveURL(/\/executions/);
|
||||
@@ -34,7 +37,10 @@ test('a failing command is reported as failed with its stderr', async ({ page })
|
||||
await page.locator('#qc-command').fill(`echo ${marker} >&2; exit 3`);
|
||||
await page.locator('#qc-command').press('Control+Enter'); // the documented shortcut
|
||||
|
||||
await page.locator('#qc-result').getByRole('link', { name: 'view in Executions' }).click();
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Failed \(exit 3\)/);
|
||||
await expect(result.locator('pre.qc-out-err')).toHaveText(marker);
|
||||
await result.getByRole('link', { name: 'view in Executions' }).click();
|
||||
const detail = page.locator('#ex-detail-body');
|
||||
await expect(detail).toContainText(marker);
|
||||
await expect(detail).toContainText(/failed/i);
|
||||
@@ -44,13 +50,19 @@ test('multi-worker mode sends the command to every selected worker', async ({ pa
|
||||
await page.goto('/quick');
|
||||
await page.locator('label[for="qc-mode-multi"], #qc-mode-multi').first().click();
|
||||
await page.getByRole('button', { name: /select all/i }).click();
|
||||
await page.locator('#qc-command').fill(`echo ${token()}`);
|
||||
await page.locator('#qc-command').fill('echo "$WORKER_NAME says hi"');
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
// One card per worker, each with its own output (#5).
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result).toContainText('Success: 3');
|
||||
await expect(result).toContainText('Failed: 0');
|
||||
await expect(result.locator('tbody tr')).toHaveCount(3);
|
||||
await expect(result).toContainText('Sent to 3 workers');
|
||||
const runs = result.locator('.qc-run');
|
||||
await expect(runs).toHaveCount(3);
|
||||
for (const n of ['node-01', 'node-02', 'node-03']) {
|
||||
const card = runs.filter({ hasText: n });
|
||||
await expect(card.locator('.qc-run-status')).toHaveText(/Completed/);
|
||||
await expect(card.locator('pre.qc-out')).toHaveText(`${n} says hi`);
|
||||
}
|
||||
});
|
||||
|
||||
test('Executions updates live when a command starts elsewhere', async ({ page, request }) => {
|
||||
@@ -89,7 +101,7 @@ test('Quick Command remembers the mode and workers after a reload (#31)', async
|
||||
await boxes.filter({ hasText: 'node-03' }).locator('input').check();
|
||||
await page.locator('#qc-command').fill('true');
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
await expect(page.locator('#qc-result')).toContainText(/2/);
|
||||
await expect(page.locator('#qc-result')).toContainText('Sent to 2 workers');
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('#qc-mode-multi')).toBeChecked();
|
||||
@@ -103,7 +115,7 @@ test('Quick Command remembers the mode and workers after a reload (#31)', async
|
||||
await page.locator('#qc-worker').selectOption(node3);
|
||||
await page.locator('#qc-command').fill('true'); // the reload emptied it
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
await expect(page.locator('#qc-result')).toContainText('Command sent successfully');
|
||||
await expect(page.locator('#qc-result .qc-run-status')).toHaveText(/Completed/);
|
||||
await page.reload();
|
||||
await expect(page.locator('#qc-mode-single')).toBeChecked();
|
||||
await expect(page.locator('#qc-worker option:checked')).toContainText('node-03');
|
||||
@@ -129,3 +141,28 @@ test('a live update keeps the rows brought in with Load More (#17)', async ({ pa
|
||||
await expect(rows.first()).toContainText(marker, { timeout: 10_000 });
|
||||
await expect(rows).toHaveCount(shown);
|
||||
});
|
||||
|
||||
test('the result still shows when the live update is missed (#5)', async ({ page }) => {
|
||||
// No live connection at all: the page has to find the result by polling.
|
||||
await page.routeWebSocket(/.*/, () => { /* never connects to the server */ });
|
||||
const marker = token();
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-worker').selectOption({ label: 'node-03 (online)' });
|
||||
await page.locator('#qc-command').fill(`echo ${marker}`);
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Running/);
|
||||
await expect(result.locator('pre.qc-out')).toHaveText(marker, { timeout: 15_000 });
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Completed/);
|
||||
});
|
||||
|
||||
test('only the worker picker for the chosen mode is shown', async ({ page }) => {
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-single').check();
|
||||
await expect(page.locator('#qc-single-mode')).toBeVisible();
|
||||
await expect(page.locator('#qc-multi-mode')).toBeHidden();
|
||||
await page.locator('#qc-mode-multi').check();
|
||||
await expect(page.locator('#qc-multi-mode')).toBeVisible();
|
||||
await expect(page.locator('#qc-single-mode')).toBeHidden();
|
||||
});
|
||||
Reference in new issue
Block a user