diff --git a/server.js b/server.js index eb7f889..6fa1676 100644 --- a/server.js +++ b/server.js @@ -795,6 +795,14 @@ function broadcast(data) { } // Helper function to add log entry to execution (atomic: no read-modify-write race condition) +// One readable message for the UI, which shows only `error` (#25): +// "Invalid workflow definition: step check: no step with id "nope"". +function definitionError(problems) { + const parts = problems.slice(0, 5).map(p => `step ${p.step}: ${p.error}`); + if (problems.length > 5) parts.push(`and ${problems.length - 5} more`); + return 'Invalid workflow definition: ' + parts.join('; '); +} + async function addExecutionLog(executionId, logEntry) { try { await pool.query( @@ -1519,7 +1527,7 @@ app.post('/api/workflows', authenticateSSO, requireJSON, async (req, res) => { const { name, description, definition, webhook_url } = req.body; if (!name || !definition) return res.status(400).json({ error: 'name and definition are required' }); const problems = [...conditionErrors(definition), ...gotoErrors(definition)]; - if (problems.length) return res.status(400).json({ error: 'Invalid workflow definition', problems }); + if (problems.length) return res.status(400).json({ error: definitionError(problems), problems }); const webhookCheck = validateWebhookUrl(webhook_url); if (!webhookCheck.ok) return res.status(400).json({ error: webhookCheck.reason }); @@ -1864,7 +1872,7 @@ app.put('/api/workflows/:id', authenticateSSO, requireJSON, async (req, res) => return res.status(400).json({ error: 'Invalid JSON in definition' }); } const problems = [...conditionErrors(defObj), ...gotoErrors(defObj)]; - if (problems.length) return res.status(400).json({ error: 'Invalid workflow definition', problems }); + if (problems.length) return res.status(400).json({ error: definitionError(problems), problems }); const [result] = await pool.query( 'UPDATE workflows SET name=?, description=?, definition=?, webhook_url=?, updated_at=NOW() WHERE id=?', diff --git a/tests/integration/workflows.int.js b/tests/integration/workflows.int.js index d3880fa..1c4fbd8 100644 --- a/tests/integration/workflows.int.js +++ b/tests/integration/workflows.int.js @@ -256,3 +256,12 @@ test('a failure on one target fails the step, after every target has reported (# expect(outputs(ex).filter(o => o === 'ok')).toHaveLength(2); expect(outputs(ex)).not.toContain('should-not-run'); }); + +test('a rejected definition says what is wrong in the error itself (#25)', async () => { + const res = await sso('POST', '/api/workflows', { name: `bad-goto-${unique()}`, definition: { steps: [ + { id: 'check', type: 'execute', command: 'true', goto: 'nope' }, + ] } }); + expect(res.status).toBe(400); + expect(res.json.error).toBe('Invalid workflow definition: step check: no step with id "nope"'); + expect(res.json.problems).toHaveLength(1); +}); diff --git a/tests/ui/workflows.ui.js b/tests/ui/workflows.ui.js index 0f1b8f5..709deaa 100644 --- a/tests/ui/workflows.ui.js +++ b/tests/ui/workflows.ui.js @@ -43,6 +43,30 @@ test('an invalid workflow definition is rejected with a message', async ({ page, expect(problems).toEqual([]); // rejected in the browser, so no failed request either }); +test('a definition the server rejects shows the server\'s reason (#25)', async ({ page, problems }) => { + await page.goto('/workflows'); + await page.getByRole('button', { name: '+ Create Workflow' }).click(); + await page.locator('#wf-create-name').fill(`Bad goto ${Date.now()}`); + await page.locator('#wf-create-definition').fill(JSON.stringify({ steps: [ + { id: 'check', type: 'execute', command: 'true', goto: 'nope' }, + ] })); + await page.locator('#wf-create-form').getByRole('button', { name: 'Create' }).click(); + await expect(page.locator('#wf-create-error')).toContainText('no step with id "nope"'); + // The 400 (and the browser's console line for it) is the point of this test. + expect(problems.every(p => /400/.test(p))).toBe(true); + problems.length = 0; +}); + +test('Escape closes the Run dialog (#25)', async ({ page, request }) => { + const name = `UI esc ${Date.now()}`; + await request.post('/api/workflows', { data: { name, definition: { steps: [{ id: 'a', type: 'execute', command: 'true' }] } } }); + await page.goto('/workflows'); + await page.locator('#wf-list tr', { hasText: name }).getByRole('button', { name: 'Execute' }).click(); + await expect(page.locator('#wf-run-modal')).toBeVisible(); + await page.keyboard.press('Escape'); + await expect(page.locator('#wf-run-modal')).toBeHidden(); +}); + test('a run waiting on a prompt shows as waiting, and the Waiting filter finds it (#3)', async ({ page, request }) => { const created = await request.post('/api/workflows', { data: { name: `UI wait ${Date.now()}`, definition: { steps: [ { id: 'ask', type: 'prompt', message: 'Proceed?', options: ['Yes'] },