From 991eb8c332e213d0dad6215727e0fe42821012cf Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Thu, 12 Nov 2026 18:40:34 -0600 Subject: [PATCH] fix(webui): SP6 review round, the writer's workflow name rule, no silent replace, preview redraw (#1873) The workflow editor checks the writer's PLAN_NAME (lowercase letters, digits and dashes, starting with a letter), so a name the bus would refuse no longer reaches it with step guidance. A new workflow under a name its scope already holds is refused on the page instead of replacing that workflow. A pack preview the page cannot draw says so rather than leaving Preview disabled. The browser test launches Chromium with --disable-extensions. --- packages/webui/src/public/packs.js | 3 ++- packages/webui/src/public/workflows.js | 10 +++++++--- .../webui/tests/packs-workflows-browser.test.mjs | 14 +++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/webui/src/public/packs.js b/packages/webui/src/public/packs.js index 9c6009563..3a9777614 100644 --- a/packages/webui/src/public/packs.js +++ b/packages/webui/src/public/packs.js @@ -125,7 +125,8 @@ s.status = `Applied. Added ${added}. Proposed hires are recorded for the chief to raise as decisions.`; } } catch (error) { s.status = error.message; } - redraw(org); + // A preview the page cannot draw says so, instead of leaving the button disabled with nothing shown. + try { redraw(org); } catch { s.preview = null; s.status = 'The preview could not be shown.'; redraw(org); } }); window.MosaicPacks = { load, section }; })(); diff --git a/packages/webui/src/public/workflows.js b/packages/webui/src/public/workflows.js index f83523b70..6fa82f5f4 100644 --- a/packages/webui/src/public/workflows.js +++ b/packages/webui/src/public/workflows.js @@ -10,7 +10,9 @@ const base = org => `/api/orgs/${encodeURIComponent(org)}`; const STATES = [['todo', 'To do'], ['in-progress', 'In progress'], ['in-review', 'Review'], ['blocked', 'Blocked'], ['done', 'Done']]; const STATE_LABEL = Object.fromEntries(STATES); - const NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/; + // The writer's workflow name rule (organization.mjs PLAN_NAME); a name it would refuse is refused here first. + const NAME = /^[a-z][a-z0-9-]{0,63}$/; + const NAME_RULE = 'A workflow name is 1 to 64 lowercase letters, digits or dashes, starting with a letter.'; const MISSING = 'names no current role'; const states = new Map(); const guidance = { @@ -77,7 +79,7 @@ const e = s.editing; if (!e) return ''; const scopeField = e.isNew - ? `` + ? `` : `

${e.scope ? `Project ${esc(e.scope)}` : 'Organization'}, ${esc(e.name)}

`; return `

${e.isNew ? 'New workflow' : 'Edit workflow'}

${scopeField} @@ -163,7 +165,9 @@ if (!s?.editing) return; capture(root, s); const e = s.editing; - if (!NAME.test(e.name)) { s.status = 'A workflow name is 1 to 64 lowercase letters, digits, dots, dashes or underscores, starting with a letter or digit.'; redraw(org); return; } + if (!NAME.test(e.name)) { s.status = NAME_RULE; redraw(org); return; } + // A save is a set: a new workflow under a name the scope already holds would replace it without a word. + if (e.isNew && Object.hasOwn(flowsIn(s, e.scope) ?? {}, e.name)) { s.status = `A workflow named ${e.name} already exists here. Edit it instead.`; redraw(org); return; } const workflow = { ...(e.draft.title.trim() ? { title: e.draft.title.trim() } : {}), ...(e.draft.description.trim() ? { description: e.draft.description.trim() } : {}), diff --git a/packages/webui/tests/packs-workflows-browser.test.mjs b/packages/webui/tests/packs-workflows-browser.test.mjs index 016daeda7..e0ffe67ef 100644 --- a/packages/webui/tests/packs-workflows-browser.test.mjs +++ b/packages/webui/tests/packs-workflows-browser.test.mjs @@ -83,7 +83,7 @@ async function fixture(t, { send = true } = {}) { }, }); t.after(() => close(server)); - const b = await browser({ machine: false }); + const b = await browser({ machine: false, args: ['--disable-extensions'] }); t.after(() => b.close()); await b.viewport(1440, 900); await b.navigate(`http://127.0.0.1:${server.address().port}/#/orgs/acme/organization`); @@ -174,6 +174,18 @@ test('SP6 workflows: list by scope, a step naming no current role, titles as tex await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.scope.value='site';f.elements.name.value='Bad Name';f.querySelector('[data-wf-edit-step="0"] [name=title]').value='Plan';f.querySelector('[data-wf-edit-step="0"] [name=roles]').value='human';f.requestSubmit()}true`); await waitFor(b, `/lowercase/.test(document.querySelector('[data-workflows-status]').textContent)`, 'name refusal'); assert.equal(sets(), before); + // The writer's name rule (PLAN_NAME): no underscore, dot or leading digit. Each is refused here, not at the bus. + for (const bad of ['release_1', 'v2.ship', '2nd-review']) { + await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value=${JSON.stringify(bad)};f.requestSubmit()}true`); + assert.equal(await b.evaluate(`document.querySelector('[data-workflows-status]').textContent`), 'A workflow name is 1 to 64 lowercase letters, digits or dashes, starting with a letter.', bad); + assert.equal(sets(), before, `${bad} sends nothing`); + } + assert.equal(await b.evaluate(`document.querySelector('[data-wf-editor] input[name=name]').placeholder`), 'lowercase letters, digits, dashes'); + // A new workflow under a name the scope already holds would replace it: refused, nothing sent. + await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value='ship';f.requestSubmit()}true`); + assert.equal(await b.evaluate(`document.querySelector('[data-workflows-status]').textContent`), 'A workflow named ship already exists here. Edit it instead.'); + assert.equal(sets(), before, 'an existing name sends nothing'); + assert.equal(await b.evaluate(`document.querySelector('[data-wf-editor] select[name=scope]').value`), 'site', 'the editor keeps the chosen scope'); await b.evaluate(`{const f=document.querySelector('[data-wf-editor]');f.elements.name.value='plan';f.requestSubmit()}true`); await waitFor(b, `document.querySelector('[data-workflows-status]').textContent==='Saved plan.'`, 'new save'); assert.deepEqual(verbs.filter(([v]) => v === 'workflow.set.console').at(-1)[1], { revision: REV('b'), name: 'plan', workflow: { steps: [{ title: 'Plan', state: 'todo', roles: ['human'] }] }, project: 'site' });