161 lines
9.5 KiB
JavaScript
161 lines
9.5 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
|
|
module.exports = async ({ page, go, shot }) => {
|
|
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 capture = async label => { await page.waitForTimeout(350); await shot(label); };
|
|
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 page.waitForTimeout(250);
|
|
}
|
|
};
|
|
for (const width of [360, 390]) {
|
|
await page.setViewportSize({ width, height: 844 });
|
|
for (const workflow of ['implement', 'feasibility']) {
|
|
await go(`/workflows?workflow=${workflow}`);
|
|
const canvas = page.locator('.workflow-canvas');
|
|
await canvas.waitFor();
|
|
const dimensions = await page.evaluate(() => ({
|
|
height: innerHeight, width: innerWidth,
|
|
scrollHeight: document.documentElement.scrollHeight,
|
|
scrollWidth: document.documentElement.scrollWidth,
|
|
}));
|
|
assert.equal(dimensions.scrollHeight, dimensions.height, 'workflow page scrolls vertically');
|
|
assert.equal(dimensions.scrollWidth, dimensions.width, 'workflow page scrolls horizontally');
|
|
const topbar = page.locator('header').first();
|
|
const bar = await topbar.boundingBox();
|
|
assert.equal(bar.y, 0, 'blank band above topbar');
|
|
assert.equal(await topbar.evaluate(el => getComputedStyle(el).backdropFilter), 'none');
|
|
assert.ok(!await canvas.getByText('Works on a repository', { exact: true }).count());
|
|
const run = page.getByRole('button', { name: new RegExp(`^(Run|Test) ${workflow}$`) });
|
|
assert.ok(await run.isVisible(), 'Run hidden on phone');
|
|
const box = await canvas.boundingBox();
|
|
const start = await page.locator('.vue-flow__node[data-id="start"]').boundingBox();
|
|
assert.ok(start.y >= box.y && start.y < box.y + box.height, 'start is outside initial viewport');
|
|
const nodes = await page.locator('.vue-flow__node').evaluateAll(elements => elements.map(el => ({
|
|
left: el.getBoundingClientRect().left, right: el.getBoundingClientRect().right,
|
|
})));
|
|
assert.ok(nodes.every(node => node.left >= box.x && node.right <= box.x + box.width), 'branch lanes clipped horizontally');
|
|
const controls = await page.getByRole('button', { name: 'Zoom in', exact: true }).boundingBox();
|
|
const flow = await canvas.locator('.vue-flow').boundingBox();
|
|
assert.ok(controls.y >= flow.y + flow.height, 'zoom control overlays graph');
|
|
await capture(`${workflow}-${width}`);
|
|
const step = page.locator('.vue-flow__node').filter({ hasText: 'Prepare worktree' }).first();
|
|
assert.equal(await step.locator('[data-slot="badge"]').innerText(), 'Prepare worktree');
|
|
await step.click();
|
|
const dialog = page.getByRole('dialog');
|
|
await dialog.waitFor();
|
|
const dialogBox = await dialog.boundingBox();
|
|
assert.ok(dialogBox.x >= 0 && dialogBox.x + dialogBox.width <= width, 'step editor exceeds phone width');
|
|
const input = dialog.getByRole('textbox').first();
|
|
if (await input.count()) assert.ok(await input.evaluate(el => el.getBoundingClientRect().height) >= 24, 'step form scaled down');
|
|
await capture(`${workflow}-step-${width}`);
|
|
await page.keyboard.press('Escape');
|
|
await run.click();
|
|
await page.getByRole('dialog').waitFor();
|
|
await capture(`${workflow}-run-${width}`);
|
|
await page.keyboard.press('Escape');
|
|
}
|
|
}
|
|
// 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: prd\b/, 'id: Write a Product Requirement Document').replaceAll('steps.prd.', 'steps.Write a Product Requirement Document.');
|
|
await page.route('**/api/control-plane/resources/workflow-definitions', route => route.fulfill({ json: resource }));
|
|
await page.setViewportSize({ width: 320, height: 700 });
|
|
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.summary'));
|
|
assert.ok(!yaml.includes('steps.Write a Product Requirement Document'));
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollHeight), 700, 'YAML causes page scroll');
|
|
await page.getByRole('tab', { name: 'Canvas', exact: true }).click();
|
|
const approval = page.locator('.vue-flow__node').filter({ hasText: 'Human 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 capture('legacy-reference-320');
|
|
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));
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth), 320, 'invalid toolbar overflows phone');
|
|
await capture('validation-320');
|
|
// 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/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 capture('run-picker-320');
|
|
await page.locator('.vue-flow').hover();
|
|
await page.mouse.wheel(0, 550);
|
|
await page.waitForTimeout(300);
|
|
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 capture('historical-run-320');
|
|
await page.keyboard.press('Escape');
|
|
await picker.click();
|
|
await page.getByRole('option', { name: 'Definition', exact: true }).click();
|
|
assert.equal(await picker.innerText(), 'Definition');
|
|
await capture('definition-picker-320');
|
|
await go('/workflows?workflow=triage');
|
|
await page.locator('.vue-flow').hover();
|
|
await page.mouse.wheel(0, 650);
|
|
await page.waitForTimeout(300);
|
|
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 capture('dynamic-handoff-320');
|
|
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.getByRole('tab', { name: 'YAML', exact: true }).click();
|
|
assert.ok((await page.getByLabel('Workflow YAML', { exact: true }).inputValue()).includes('workflow: implement'));
|
|
};
|