// Workflow definition behaviour at desktop width: legacy title IDs migrate // to slugs, invalid expressions flag the node and toolbar alike, a pinned // historical run keeps its original step IDs inspectable, and handoff // targets round-trip between the step form and YAML. const assert = require('node:assert/strict'); module.exports = async ({ page, go, shot, settled }) => { await page.route('**/api/control-plane/resources/workflow-drafts', async route => { const response = await route.fetch(); const data = await response.json(); data.resource.value = { drafts: [] }; await route.fulfill({ json: data }); }); const panTo = async node => { const flow = page.locator('.vue-flow'); await flow.hover(); for (let adjustment = 0; adjustment < 3; adjustment++) { const target = await node.boundingBox(), viewport = await flow.boundingBox(); const delta = target.y + target.height / 2 - viewport.y - viewport.height / 2; if (Math.abs(delta) < 30) break; await page.mouse.wheel(0, delta * 2); await settled(); } }; // Reproduce a previously stored title ID without changing the test server. const response = await page.request.get(new URL('/api/control-plane/resources/workflow-definitions', page.url()).href); const resource = await response.json(); const definition = resource.resource.value.definitions.find(entry => entry.id === 'feasibility'); definition.yaml = definition.yaml.replace(/\bid: assess\b/, 'id: Write a Product Requirement Document').replaceAll('steps.assess.', 'steps.Write a Product Requirement Document.'); await page.route('**/api/control-plane/resources/workflow-definitions', route => route.fulfill({ json: resource })); await go('/workflows?workflow=feasibility'); await page.getByRole('tab', { name: 'YAML', exact: true }).click(); const yaml = await page.getByLabel('Workflow YAML', { exact: true }).inputValue(); assert.ok(yaml.includes('id: write-a-product-requirement-document')); assert.ok(yaml.includes('steps.write-a-product-requirement-document.result')); assert.ok(!yaml.includes('steps.Write a Product Requirement Document')); await page.getByRole('tab', { name: 'Canvas', exact: true }).click(); const approval = page.locator('.vue-flow__node').filter({ hasText: 'Approval' }).first(); await panTo(approval); await approval.click(); const dialog = page.getByRole('dialog'); await dialog.waitFor(); const chip = dialog.getByRole('button', { name: 'write-a-product-requirement-document', exact: true }); await chip.waitFor(); await chip.click(); await shot('legacy-reference'); await page.keyboard.press('Escape'); await page.getByRole('tab', { name: 'YAML', exact: true }).click(); const field = page.getByLabel('Workflow YAML', { exact: true }); await field.fill((await field.inputValue()).replace('type: repo.prepare', 'type: repo.prepare\n when: not-a-valid-expression')); await page.getByRole('tab', { name: 'Canvas', exact: true }).click(); const problem = page.locator('.vue-flow__node').filter({ hasText: 'Prepare worktree' }).first().locator('svg.text-danger'); await problem.waitFor(); const toolbarProblem = page.getByRole('status').filter({ has: page.locator('svg') }); assert.equal(await problem.evaluate(el => getComputedStyle(el).color), await toolbarProblem.evaluate(el => getComputedStyle(el).color)); const invalidPage = await page.evaluate(() => ({ scrollWidth: document.documentElement.scrollWidth, width: innerWidth, })); assert.equal(invalidPage.scrollWidth, invalidPage.width, 'invalid toolbar overflows'); await shot('validation'); // A pinned historical run keeps its original step IDs and remains inspectable. const snapshot = definition.yaml; await page.route('**/api/tasks?*', route => { const workflow = new URL(route.request().url()).searchParams.get('workflow'); return workflow === 'feasibility' ? route.fulfill({ json: [{ id: 999999, workflow, title: 'Historical run', status: 'failed', workflow_definition_yaml: snapshot }] }) : route.continue(); }); await page.route('**/api/tasks/999999/*?*', route => route.fulfill({ json: {} })); await page.route('**/api/tasks/999999/debug', route => route.fulfill({ json: {} })); await page.route('**/api/tasks/999999/attempts', route => route.fulfill({ json: { attempts: [{ attempt: 1, stages: [{ name: 'Write a Product Requirement Document', status: 'failed', error: 'Historical failure' }] }] } })); await go('/workflows?workflow=feasibility'); const picker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); await picker.waitFor(); assert.match(await picker.innerText(), /Run #999999/); const root = await page.locator('.vue-flow__node[data-id="workflow"]').boundingBox(); const pinnedCanvas = await page.locator('.workflow-canvas').boundingBox(); assert.ok(root.y >= pinnedCanvas.y, 'historical workflow header clipped above canvas'); await shot('run-picker'); await page.locator('.vue-flow').hover(); await page.mouse.wheel(0, 550); await settled(); const historicalStep = page.locator('.vue-flow__node').filter({ hasText: 'Write a Product Requirement Document' }).first(); await panTo(historicalStep); await historicalStep.click(); await page.getByRole('dialog').waitFor(); await page.getByText('Historical failure', { exact: true }).first().waitFor(); await shot('historical-run'); await page.keyboard.press('Escape'); await picker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); assert.equal(await picker.innerText(), 'Definition'); await shot('definition-picker'); await go('/workflows?workflow=triage'); const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); } await page.locator('.vue-flow').hover(); await page.mouse.wheel(0, 650); await settled(); const handoff = page.locator('.vue-flow__node').filter({ hasText: 'Hand off' }).first(); await panTo(handoff); await handoff.click(); const target = page.getByRole('dialog').getByLabel('Workflow', { exact: true }); await target.waitFor(); assert.equal(await target.inputValue(), '{{ steps.classify.result.workflow }}'); await target.fill('{{ steps.classify.result.alternative }}'); await target.press('Home'); await shot('dynamic-handoff'); await page.keyboard.press('Escape'); await page.getByRole('tab', { name: 'YAML', exact: true }).click(); assert.ok((await page.getByLabel('Workflow YAML', { exact: true }).inputValue()).includes('steps.classify.result.alternative')); await page.getByRole('tab', { name: 'Canvas', exact: true }).click(); await panTo(handoff); await handoff.click(); await target.fill('implement'); await page.keyboard.press('Escape'); await page.keyboard.press('Escape'); await page.getByRole('tab', { name: 'YAML', exact: true }).click(); assert.ok((await page.getByLabel('Workflow YAML', { exact: true }).inputValue()).includes('workflow: implement')); };