Workflow parameters: types, defaults, checked before a run (#23, #11)
CI / Test (jest) (pull_request) Successful in 26s
CI / Lint (eslint) (pull_request) Successful in 29s
CI / Security (npm audit) (pull_request) Successful in 13s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 1m36s
CI / Integration (api) (pull_request) Successful in 2m26s
CI / UI (playwright) (pull_request) Successful in 2m25s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 2m3s

#23
- Parameters can be text (default), number (min, max), select
  (options), boolean, or worker, with a default. The Run dialog shows a
  matching field, the allowed characters for text, and the range for
  numbers; worker parameters choose from the connected workers.
- Values are checked before anything starts: in the dialog, naming the
  characters that are not allowed, and by the server (resolveParams),
  which answers 400 "Invalid parameters: ..." and creates no execution.
  A bad value used to fail mid-run as "Unsafe value for workflow
  parameter". Server errors now show in the dialog instead of a toast.

#11
- Saving a workflow checks its shape (definitionErrors): known step
  types and their required fields, unique ids, prompt routes that match
  options, route conditions, and parameter definitions. Unknown step
  types were silently skipped at run time.
- README documents the parameter types and the checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-23 18:11:49 -05:00
1 parent 7204c806df
commit a6d693c13e
8 files changed
+477 -39

No files matched your search

+28 -3
View File
@@ -98,9 +98,10 @@ test('parameters are substituted, and unsafe values are refused', async () => {
expect(ok.status).toBe('completed');
expect(outputs(ok)).toEqual(['host=db-01.lan']);
const bad = await waitForExecution(await start(wf, { params: { host: 'x; reboot' } }));
expect(bad.status).toBe('failed');
expect(outputs(bad)).toEqual([]);
// Refused up front (#23), rather than starting a run that fails mid-way.
const bad = await sso('POST', '/api/executions', { workflow_id: wf, params: { host: 'x; reboot' } });
expect(bad.status).toBe(400);
expect(bad.json.error).toMatch(/host may only contain/);
});
test('a dry run logs the commands without running them', async () => {
@@ -265,3 +266,27 @@ test('a rejected definition says what is wrong in the error itself (#25)', async
expect(res.json.error).toBe('Invalid workflow definition: step check: no step with id "nope"');
expect(res.json.problems).toHaveLength(1);
});
test('bad parameters are refused before a run is created (#23)', async () => {
const wf = await createWorkflow([{ id: 'e', type: 'execute', command: 'echo {{host}} {{count}}', targets: ['node-01'] }], {
params: [{ name: 'host', required: true }, { name: 'count', type: 'number', max: 5, default: '2' }],
});
const before = (await sso('GET', `/api/executions?search=${wf}&limit=5`)).json.total;
const r = await sso('POST', '/api/executions', { workflow_id: wf, params: { host: 'web 01', count: '9' } });
expect(r.status).toBe(400);
expect(r.json.error).toBe('Invalid parameters: host may only contain letters, digits and . _ : @ / -; count must be at most 5');
expect((await sso('GET', `/api/executions?search=${wf}&limit=5`)).json.total).toBe(before);
// Defaults fill in, and the run uses them.
const ex = await waitForExecution(await start(wf, { params: { host: 'web-01' } }));
expect(ex.status).toBe('completed');
expect(outputs(ex)).toEqual(['web-01 2']);
});
test('saving a definition with structural mistakes is refused (#11)', async () => {
const r = await sso('POST', '/api/workflows', { name: `bad ${unique()}`, definition: { steps: [
{ id: 'a', type: 'exec', command: 'true' },
] } });
expect(r.status).toBe(400);
expect(r.json.error).toBe('Invalid workflow definition: step a: unknown type "exec" (use execute, prompt, wait, parse, route)');
});
+38
View File
@@ -121,3 +121,41 @@ test('a workflow execution re-runs as the whole workflow with its parameters (#1
return list.executions.filter(e => e.workflow_id === wf).length;
}).toBe(2);
});
test('the Run dialog has a field for each parameter type and checks values up front (#23)', async ({ page, request, problems }) => {
const name = `UI params ${Date.now()}`;
await request.post('/api/workflows', { data: { name, definition: {
params: [
{ name: 'host', label: 'Host', required: true },
{ name: 'mode', type: 'select', options: ['fast', 'safe'], default: 'safe' },
{ name: 'count', type: 'number', min: 1, max: 5, default: '2' },
{ name: 'force', type: 'boolean' },
{ name: 'node', type: 'worker', default: 'node-02' },
],
steps: [{ id: 'e', type: 'execute', command: 'echo {{host}} {{mode}} {{count}} {{force}} {{node}}', targets: ['node-01'] }],
} } });
await page.goto('/workflows');
await page.locator('#wf-list tr', { hasText: name }).getByRole('button', { name: 'Execute' }).click();
const modal = page.locator('#wf-run-modal');
await expect(modal.locator('#wf-run-param-mode')).toHaveValue('safe');
await expect(modal.locator('#wf-run-param-count')).toHaveValue('2');
await expect(modal.locator('#wf-run-param-force')).not.toBeChecked();
await expect(modal.locator('#wf-run-param-node')).toHaveValue('node-02');
await expect(modal).toContainText('Letters, digits and . _ : @ / - only');
// A bad value is caught in the dialog, before anything is sent.
let posted = false;
page.on('request', r => { if (r.method() === 'POST' && r.url().endsWith('/api/executions')) posted = true; });
await modal.locator('#wf-run-param-host').fill('web 01');
await modal.getByRole('button', { name: /Run/ }).click();
await expect(modal.locator('#wf-run-err-host')).toHaveText('Not allowed: space');
expect(posted).toBe(false);
await modal.locator('#wf-run-param-host').fill('web-01');
await modal.locator('#wf-run-param-mode').selectOption('fast');
await modal.locator('#wf-run-param-force').check();
await modal.getByRole('button', { name: /Run/ }).click();
await expect(page).toHaveURL(/\/executions\?open=/);
await expect(page.locator('#ex-detail-body')).toContainText('web-01 fast 2 true node-02', { timeout: 20_000 });
expect(problems).toEqual([]);
});
+104
View File
@@ -164,3 +164,107 @@ describe('calculateNextRun', () => {
expect(() => calculateNextRun('weekly', '1')).toThrow('Unknown schedule type');
});
});
describe('resolveParams (#23)', () => {
const { resolveParams } = require('../lib/utils');
const defs = [
{ name: 'host', label: 'Host', required: true },
{ name: 'count', type: 'number', min: 1, max: 10, default: '3' },
{ name: 'mode', type: 'select', options: ['fast', 'safe'], default: 'safe' },
{ name: 'force', type: 'boolean' },
{ name: 'node', type: 'worker' },
];
test('fills defaults and normalises values', () => {
expect(resolveParams(defs, { host: ' web-01 ', force: true })).toEqual({
params: { host: 'web-01', count: '3', mode: 'safe', force: 'true' }, errors: [],
});
});
test('reports every problem before the run starts', () => {
const { errors } = resolveParams(defs, { count: '99', mode: 'yolo', force: 'maybe', node: 'a b' });
expect(errors).toEqual([
'Host is required',
'count must be at most 10',
'mode must be one of: fast, safe',
'force must be true or false',
'node may only contain letters, digits and . _ : @ / -',
]);
});
test('text values with spaces or shell characters are refused', () => {
expect(resolveParams(defs, { host: 'web-01; rm -rf /' }).errors).toEqual(['Host may only contain letters, digits and . _ : @ / -']);
});
test('numbers must be numbers', () => {
for (const bad of ['abc', '1e3', '--1', 'Infinity']) {
expect(resolveParams([{ name: 'n', type: 'number' }], { n: bad }).errors).toEqual(['n must be a number']);
}
expect(resolveParams([{ name: 'n', type: 'number' }], { n: '-2.5' }).params).toEqual({ n: '-2.5' });
});
test('undeclared keys (e.g. an old re-run) must still be safe', () => {
expect(resolveParams([], { extra: 'ok' }).params).toEqual({ extra: 'ok' });
expect(resolveParams([], { extra: '$(id)' }).errors).toHaveLength(1);
});
});
describe('definitionErrors (#11)', () => {
const { definitionErrors } = require('../lib/utils');
const msgs = def => definitionErrors(def).map(p => `${p.where || 'step ' + p.step}: ${p.error}`);
test('a good definition has no problems', () => {
expect(definitionErrors({
params: [{ name: 'host', required: true }, { name: 'mode', type: 'select', options: ['a', 'b'], default: 'a' }],
steps: [
{ id: 'run', type: 'execute', command: 'echo {{host}}', targets: ['all'] },
{ id: 'p', type: 'parse' },
{ id: 'r', type: 'route', conditions: [{ if: 'state.x === "1"', goto: 'end' }, { default: true, goto: 'ask' }] },
{ id: 'ask', type: 'prompt', message: 'Go?', options: ['Yes', 'No'], routes: { No: 'end' } },
{ id: 'w', type: 'wait', duration: 2 },
],
})).toEqual([]);
});
test('catches the typos the issue lists', () => {
expect(msgs({ steps: [
{ id: 'a', type: 'exec', command: 'x' },
{ id: 'b', type: 'prompt', message: 'Go?' },
{ id: 'a', type: 'execute' },
{ type: 'wait', duration: 'soon' },
{ id: 'r', type: 'route', conditions: [] },
{ id: 'q', type: 'prompt', message: 'Go?', options: ['Yes'], routes: { No: 'end' } },
] })).toEqual([
'step a: unknown type "exec" (use execute, prompt, wait, parse, route)',
'step b: "options" must be a non-empty list of strings',
'step a: id "a" is used more than once',
'step a: "command" is required',
'step 4: "duration" must be a number of seconds',
'step r: "conditions" must be a non-empty list',
'step q: route for "No", which is not one of the options',
]);
});
test('steps must be a non-empty list', () => {
expect(msgs({ steps: {} })).toEqual(['definition: "steps" must be a non-empty list']);
expect(msgs([])).toEqual(['definition: must be a JSON object']);
});
test('checks parameter definitions', () => {
expect(msgs({ steps: [{ type: 'parse' }], params: [
{ name: 'bad name' },
{ name: 'x', type: 'colour' },
{ name: 's', type: 'select' },
{ name: 'n', type: 'number', default: 'many' },
{ name: 'n' },
{ name: 'o', type: 'select', options: ['ok', 'not ok'] },
] })).toEqual([
'param "bad name": "name" must be letters, digits or _',
'param "x": unknown type "colour" (use text, number, select, boolean, worker)',
'param "s": "options" must be a non-empty list for a select',
'param "n": default must be a number',
'param "n": is declared more than once',
'param "o": options may only contain letters, digits and . _ : @ / -: not ok',
]);
});
});