diff --git a/public/assets/pages/executions.js b/public/assets/pages/executions.js
index 43c0ce9..87892a2 100644
--- a/public/assets/pages/executions.js
+++ b/public/assets/pages/executions.js
@@ -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) + '">⛔ Abort Execution';
}
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 += '';
+ } else if (cmdLog) {
html += '';
@@ -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;
diff --git a/server.js b/server.js
index bfdf7e7..bca1ec9 100644
--- a/server.js
+++ b/server.js
@@ -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 ')}` : '';
diff --git a/tests/integration/gandalf.int.js b/tests/integration/gandalf.int.js
index ab6512a..f835fa9 100644
--- a/tests/integration/gandalf.int.js
+++ b/tests/integration/gandalf.int.js
@@ -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([]);
+});
diff --git a/tests/ui/quick-command.ui.js b/tests/ui/quick-command.ui.js
index ab84a1b..30fd48a 100644
--- a/tests/ui/quick-command.ui.js
+++ b/tests/ui/quick-command.ui.js
@@ -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);
+});
diff --git a/tests/ui/workflows.ui.js b/tests/ui/workflows.ui.js
index 7f0af26..0f1b8f5 100644
--- a/tests/ui/workflows.ui.js
+++ b/tests/ui/workflows.ui.js
@@ -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);
+});