Executions: Re-run Workflow, and search that finds commands #74

Merged
jared merged 1 commits from executions-search-rerun into main 2026-11-23 13:10:02 -05:00
5 changed files with 116 additions and 16 deletions
Showing only changes of commit 4cf3c084a9 - Show all commits

No files matched your search

+49 -13
View File
@@ -77,6 +77,8 @@
const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) });
if (view === 'manual') params.set('hide_internal', 'true');
if (view === 'automated') params.set('only_internal', 'true'); // server-side (#4)
const term = searchTerm();
if (term) params.set('search', term); // server-side (#16)
try {
const data = await Pulse.api.get('/api/executions?' + params.toString());
@@ -103,21 +105,20 @@
// Live events trigger this; coalesce bursts into at most one reload per 2 s (#10).
const reloadCurrent = Pulse.util.throttle(reloadNow, 2000);
// Typing in the search box: search on the server once typing pauses (#16).
let searchTimer = null;
function searchSoon() {
clearTimeout(searchTimer);
searchTimer = setTimeout(reloadNow, 300);
}
/* ------------------------------------------------------------------
Rendering: list
------------------------------------------------------------------ */
// Search runs on the server (it can see commands); status stays a local filter.
function filteredRows(view) {
const term = searchTerm();
const status = statusTerm();
return state[view].rows.filter((e) => {
if (status && displayStatus(e) !== status) return false;
if (term) {
const name = execName(e).toLowerCase();
const id = String(e.id || '').toLowerCase();
if (name.indexOf(term) === -1 && id.indexOf(term) === -1) return false;
}
return true;
});
return state[view].rows.filter((e) => !status || displayStatus(e) === status);
}
function countLabel(view) {
@@ -473,7 +474,11 @@
'data-execution-id="' + esc(id) + '">&#x26d4; Abort Execution</button>';
}
const cmdLog = (Array.isArray(ex.logs) ? ex.logs : []).find((l) => l.action === 'command_sent' && l.command);
if (cmdLog) {
if (ex.workflow_id) {
// A workflow re-runs as the whole workflow with its parameters, not its first command (#18).
html += '<button type="button" class="lt-btn lt-btn-secondary lt-btn-sm" data-action="ex:rerun-workflow" ' +
'data-execution-id="' + esc(id) + '">&#x21bb; Re-run Workflow</button>';
} else if (cmdLog) {
html += '<button type="button" class="lt-btn lt-btn-secondary lt-btn-sm" data-action="ex:rerun" ' +
'data-command="' + esc(cmdLog.command) + '" data-worker-id="' + esc(cmdLog.worker_id || '') + '">' +
'&#x21bb; Re-run Command</button>';
@@ -633,7 +638,7 @@
setView(view);
},
'ex:search': () => { render(); },
'ex:search': () => { searchSoon(); },
'ex:filter-status': () => { render(); },
'ex:clear-filters': () => {
@@ -641,7 +646,7 @@
const st = $('ex-status');
if (s) s.value = '';
if (st) st.value = '';
render();
reloadNow();
},
'ex:load-more': async (el) => {
@@ -736,6 +741,37 @@
window.location.href = '/quick';
},
'ex:rerun-workflow': async (el) => {
const id = el.getAttribute('data-execution-id');
if (!id) return;
let ex;
try {
ex = await Pulse.api.get('/api/executions/' + encodeURIComponent(id));
} catch (e) {
toast('error', (e && e.message) || 'Failed to load the execution');
return;
}
const paramsLog = (Array.isArray(ex.logs) ? ex.logs : []).find((l) => l.action === 'params');
const params = (paramsLog && paramsLog.params) || {};
const names = Object.keys(params);
const ok = await askConfirm({
title: 'Re-run Workflow',
message: 'Run ' + ((state.rowIndex.get(id) || {}).workflow_name || 'this workflow') + ' again' +
(names.length ? ' with the same parameters?\n\n' + names.map((k) => k + ' = ' + params[k]).join('\n') : '?'),
type: 'warning',
confirmLabel: 'RE-RUN',
});
if (!ok) return;
try {
const started = await Pulse.api.post('/api/executions', { workflow_id: ex.workflow_id, params: params });
toast('success', 'Workflow started');
openDetail(started.id, false);
reloadNow();
} catch (e) {
toast('error', (e && e.message) || 'Failed to start the workflow');
}
},
'ex:download': async (el) => {
const id = el.getAttribute('data-execution-id') || openDetailId();
if (!id) return;
+4 -3
View File
@@ -1682,9 +1682,10 @@ app.get('/api/executions', authenticateSSO, async (req, res) => {
queryParams.push(new Date(req.query.before));
}
if (req.query.search) {
conditions.push('(w.name LIKE ? OR e.started_by LIKE ?)');
const term = `%${req.query.search}%`;
queryParams.push(term, term);
// Workflow name, who started it, the id, or any command it ran (#16).
conditions.push("(w.name LIKE ? OR e.started_by LIKE ? OR e.id LIKE ? OR JSON_SEARCH(e.logs, 'one', ?, NULL, '$[*].command') IS NOT NULL)");
const term = `%${String(req.query.search).slice(0, 200)}%`;
queryParams.push(term, term, term, term);
}
const whereClause = conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
+11
View File
@@ -65,3 +65,14 @@ test('the Automated and Manual views filter on the server (#4)', async () => {
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([]);
});
+13
View File
@@ -63,3 +63,16 @@ test('Executions updates live when a command starts elsewhere', async ({ page, r
// Its own row appears without a reload (by id, so it works however full the list is).
await expect(page.locator(`#ex-list-manual .ex-row[data-execution-id="${id}"]`)).toBeVisible();
});
test('searching Executions finds a run by its command (#16)', async ({ page, request }) => {
const marker = token();
const workers = await (await request.get('/api/workers')).json();
const node1 = workers.find(w => w.name === 'node-01');
const { execution_id: id } = await (await request.post(`/api/workers/${node1.id}/command`, { data: { command: `echo ${marker}` } })).json();
await page.goto('/executions');
await page.locator('#ex-search').fill(marker);
const rows = page.locator('#ex-list-manual .ex-row');
await expect(rows).toHaveCount(1);
await expect(rows.first()).toHaveAttribute('data-execution-id', id);
});
+39
View File
@@ -58,3 +58,42 @@ test('a run waiting on a prompt shows as waiting, and the Waiting filter finds i
await request.post(`/api/executions/${ex}/respond`, { data: { response: 'Yes' } });
});
test('the Create Workflow dialog starts with the example definition (#12)', async ({ page }) => {
await page.goto('/workflows');
await page.getByRole('button', { name: '+ Create Workflow' }).click();
const def = JSON.parse(await page.locator('#wf-create-definition').inputValue());
expect(Array.isArray(def.steps) && def.steps.length).toBeTruthy();
});
test('a workflow without parameters can still be dry-run (#13)', async ({ page, request }) => {
const name = `UI noparams ${Date.now()}`;
await request.post('/api/workflows', { data: { name, definition: { steps: [
{ id: 'a', type: 'execute', command: 'echo hi', targets: ['node-01'] },
] } } });
await page.goto('/workflows');
await page.locator('#wf-list tr', { hasText: name }).getByRole('button', { name: 'Execute' }).click();
await expect(page.locator('#wf-run-dryrun')).toBeVisible();
await page.locator('#wf-run-dryrun').check();
await page.locator('#wf-run-form').getByRole('button', { name: /Run/ }).click();
await expect(page.locator('#ex-detail-body')).toContainText(/dry run/i);
});
test('a workflow execution re-runs as the whole workflow with its parameters (#18)', async ({ page, request }) => {
const name = `UI rerun ${Date.now()}`;
const wf = (await (await request.post('/api/workflows', { data: { name, definition: {
params: [{ name: 'who', required: true }],
steps: [{ id: 'a', type: 'execute', command: 'echo hello {{who}}', targets: ['node-01'] }],
} } })).json()).id;
const first = (await (await request.post('/api/executions', { data: { workflow_id: wf, params: { who: 'world' } } })).json()).id;
await page.goto(`/executions?open=${first}`);
await expect(page.locator('#ex-detail-body')).toContainText('hello world');
await page.getByRole('button', { name: /Re-run Workflow/ }).click();
await page.getByRole('button', { name: 'RE-RUN', exact: true }).click();
await expect.poll(async () => {
const list = await (await request.get('/api/executions?hide_internal=true&limit=20')).json();
return list.executions.filter(e => e.workflow_id === wf).length;
}).toBe(2);
});