diff --git a/apps/fabro-web/app/components/automation-form.tsx b/apps/fabro-web/app/components/automation-form.tsx index 4788557ec..6160c7f3b 100644 --- a/apps/fabro-web/app/components/automation-form.tsx +++ b/apps/fabro-web/app/components/automation-form.tsx @@ -86,7 +86,7 @@ export function automationFormValuesFromRun( name, repository, ref: cloneBranch ?? EMPTY_AUTOMATION_FORM.ref, - workflow: run.workflow.slug?.trim() || snakeify(workflowName), + workflow: run.workflow.slug?.trim() || kebabify(workflowName), }; } @@ -116,7 +116,7 @@ export function isFormValid(values: AutomationFormValues): boolean { ); } -export function kebabify(value: string): string { +function kebabify(value: string): string { return value .toLowerCase() .replace(/[^a-z0-9-]+/g, "-") @@ -124,14 +124,6 @@ export function kebabify(value: string): string { .replace(/^-|-$/g, ""); } -export function snakeify(value: string): string { - return value - .toLowerCase() - .replace(/[^a-z0-9_]+/g, "_") - .replace(/_+/g, "_") - .replace(/^_|_$/g, ""); -} - function firstPresentString(...values: Array): string { for (const value of values) { const trimmed = value?.trim(); @@ -300,15 +292,15 @@ export function AutomationFormFields({ Workflow slug} - help="Snake-case identifier used in the workflow file name (e.g. fix_build.fabro)." + help="Dash-separated identifier matching the workflow directory name (e.g. patch-cves)." > patch({ workflow: snakeify(e.target.value) })} - placeholder="fix_build" + onChange={(e) => patch({ workflow: kebabify(e.target.value) })} + placeholder="patch-cves" autoComplete="off" spellCheck={false} className={`${INPUT_CLASS} font-mono`} diff --git a/apps/fabro-web/app/routes/automations-new.test.tsx b/apps/fabro-web/app/routes/automations-new.test.tsx index 32a88dccc..f3d4ef5e4 100644 --- a/apps/fabro-web/app/routes/automations-new.test.tsx +++ b/apps/fabro-web/app/routes/automations-new.test.tsx @@ -100,6 +100,7 @@ mock.module("swr", () => ({ })); const { default: AutomationsNew } = await import("./automations-new"); +const { automationFormValuesFromRun } = await import("../components/automation-form"); mock.restore(); function makeRun(overrides: Record = {}) { @@ -109,7 +110,7 @@ function makeRun(overrides: Record = {}) { goal: "Fix CI", title: "Fix failing tests", workflow: { - slug: "fix_ci", + slug: "fix-ci", name: "Fix CI", graph_name: "ci_graph", node_count: 0, @@ -215,12 +216,26 @@ async function renderAutomationsNew(initialEntry: string) { return { renderer, router }; } +function byLabel(renderer: TestRenderer.ReactTestRenderer, label: string) { + return renderer.root.findByProps({ "aria-label": label }); +} + function fieldValue(renderer: TestRenderer.ReactTestRenderer, label: string) { - return renderer.root.findByProps({ "aria-label": label }).props.value; + return byLabel(renderer, label).props.value; +} + +function changeField( + renderer: TestRenderer.ReactTestRenderer, + label: string, + value: string, +) { + act(() => { + byLabel(renderer, label).props.onChange({ target: { value } }); + }); } function switchChecked(renderer: TestRenderer.ReactTestRenderer, label: string) { - const props = renderer.root.findByProps({ "aria-label": label }).props; + const props = byLabel(renderer, label).props; return props["aria-checked"] ?? props.checked; } @@ -265,6 +280,16 @@ describe("AutomationsNew", () => { expect(switchChecked(renderer, "Enable scheduled triggers")).toBe(false); }); + test("workflow slug input normalizes to kebab-case and preserves dashes", async () => { + const { renderer } = await renderAutomationsNew("/automations/new"); + + changeField(renderer, "Workflow slug", "patch-cves"); + expect(fieldValue(renderer, "Workflow slug")).toBe("patch-cves"); + + changeField(renderer, "Workflow slug", "Patch CVEs"); + expect(fieldValue(renderer, "Workflow slug")).toBe("patch-cves"); + }); + test("/automations/new?from_run=run_1 pre-populates from run and settings data", async () => { currentRun = makeRun(); currentRunSettings = makeRunSettings(); @@ -275,7 +300,7 @@ describe("AutomationsNew", () => { expect(fieldValue(renderer, "Automation slug")).toBe("fix-failing-tests"); expect(fieldValue(renderer, "Repository")).toBe("qltysh/fabro"); expect(fieldValue(renderer, "Default branch")).toBe("feature/from-run"); - expect(fieldValue(renderer, "Workflow slug")).toBe("fix_ci"); + expect(fieldValue(renderer, "Workflow slug")).toBe("fix-ci"); expect(switchChecked(renderer, "Enable manual and API triggers")).toBe(true); expect(switchChecked(renderer, "Enable scheduled triggers")).toBe(false); expect( @@ -285,6 +310,20 @@ describe("AutomationsNew", () => { expect(queryCalls).toContainEqual({ hook: "useRunSettings", id: "run_1" }); }); + test("automationFormValuesFromRun kebab-cases the workflow name fallback", () => { + const run = makeRun({ + workflow: { + slug: "", + name: "Patch CVEs", + graph_name: "PatchCves", + node_count: 0, + edge_count: 0, + }, + }); + + expect(automationFormValuesFromRun(run as any).workflow).toBe("patch-cves"); + }); + test("missing source run data renders an editable empty form with a non-blocking error", async () => { currentRun = null; currentRunError = new Error("not found");