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

+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',
]);
});
});