The browser half of M3. Flows open on a full-bleed canvas with their chrome floating over it: flow tabs top, dock bottom, node settings in a panel on the right that leaves the graph visible and running behind it. - Connections are derived, not stored. A node declares the messages it reads and publishes; every matching pair draws an edge, so two producers of one message converge on their consumer. Dragging output to input is shorthand for pointing that input at the producer's message, and asks before it replaces an existing one. - Values land on the edges as they flow, over a websocket that feeds a store outside React, so a value arriving re-renders its own chip and nothing else. Clicking an edge shows the last payload and when it arrived. - Node source is edited in Monaco, loaded only when a panel opens and themed from the design tokens. - Edits autosave; identical documents are skipped server-side, so a quiet canvas writes nothing. - Validation from the API shows on the node it belongs to and is summarised in the dock, where each entry pans to its node. - Works on a phone: touch-connect, 44px dock targets, and the node panel becomes a full-screen sheet. Two new tokens (--status-success, --font-mono) are mirrored in the website repo and recorded in DESIGN-GUIDELINES.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WzrvW7rjQbynnhF6pxh6i
105 lines
3.3 KiB
TypeScript
105 lines
3.3 KiB
TypeScript
import { expect, type Page, test } from "@playwright/test"
|
|
|
|
/**
|
|
* The flow editor's load-bearing behaviour: nodes are placed, connections come
|
|
* from matching message names, and everything survives a reload because the
|
|
* canvas autosaves.
|
|
*/
|
|
|
|
const flowName = `test_flow_${Date.now().toString(36)}`
|
|
|
|
test.use({ storageState: "playwright/.auth/user.json" })
|
|
|
|
test.describe.configure({ mode: "serial" })
|
|
|
|
const apiUrl = process.env.VITE_API_URL || "http://api.localhost"
|
|
|
|
/** Write a node's source through the API; typing code is not what we test. */
|
|
async function setNodeSource(page: Page, nodeId: string, code: string) {
|
|
const token = await page.evaluate(() => localStorage.getItem("access_token"))
|
|
const response = await page.request.put(
|
|
`${apiUrl}/api/v1/flows/${flowName}/nodes/${nodeId}/source`,
|
|
{ headers: { Authorization: `Bearer ${token}` }, data: { code } },
|
|
)
|
|
expect(response.ok()).toBeTruthy()
|
|
}
|
|
|
|
async function addFunctionNode(page: Page, expected: number) {
|
|
await page.getByTestId("add-node").click()
|
|
await page
|
|
.getByRole("option", { name: /function/i })
|
|
.first()
|
|
.click()
|
|
await expect(page.locator(".react-flow__node")).toHaveCount(expected)
|
|
await page.keyboard.press("Escape")
|
|
}
|
|
|
|
/** Name the message on a node's first input or output port. */
|
|
async function bindPort(
|
|
page: Page,
|
|
index: number,
|
|
side: "in" | "out",
|
|
message: string,
|
|
) {
|
|
await page.locator(".react-flow__node").nth(index).click()
|
|
const panel = page.getByTestId("node-panel")
|
|
await panel
|
|
.getByRole("button", { name: "Add" })
|
|
.nth(side === "in" ? 0 : 1)
|
|
.click()
|
|
await panel.getByLabel("Message name").fill(message)
|
|
await page.keyboard.press("Escape")
|
|
}
|
|
|
|
test("a flow can be created, wired up, and comes back after a reload", async ({
|
|
page,
|
|
}) => {
|
|
await page.goto("/flows")
|
|
|
|
// Create a flow of our own so the test does not lean on existing data.
|
|
await page.getByRole("button", { name: "New flow" }).click()
|
|
await page.getByTestId("flow-name-input").fill(flowName)
|
|
await page.getByRole("button", { name: "Create flow" }).click()
|
|
await page.waitForURL(`/flows/${flowName}`)
|
|
|
|
await addFunctionNode(page, 1)
|
|
await addFunctionNode(page, 2)
|
|
|
|
// The first node publishes "reading", the second consumes it. That match is
|
|
// the whole connection; no edge was drawn by hand.
|
|
await bindPort(page, 0, "out", "reading")
|
|
await bindPort(page, 1, "in", "reading")
|
|
await expect(page.locator(".react-flow__edge")).toHaveCount(1)
|
|
|
|
// Autosave, then prove it by coming back fresh.
|
|
await page.waitForTimeout(1500)
|
|
await page.reload()
|
|
await expect(page.locator(".react-flow__node")).toHaveCount(2)
|
|
await expect(page.locator(".react-flow__edge")).toHaveCount(1)
|
|
})
|
|
|
|
test("running a flow puts values on its edges", async ({ page }) => {
|
|
await page.goto(`/flows/${flowName}`)
|
|
await page.waitForSelector(".react-flow__node")
|
|
|
|
await setNodeSource(
|
|
page,
|
|
"python",
|
|
'def process(params):\n return {"reading": 42.0}\n',
|
|
)
|
|
await setNodeSource(
|
|
page,
|
|
"python_2",
|
|
"def process(reading, params):\n return {}\n",
|
|
)
|
|
|
|
await page.reload()
|
|
await page.waitForSelector(".react-flow__edge")
|
|
|
|
await page.getByTestId("run-flow").click()
|
|
await expect(page.locator(".react-flow__edgelabel-renderer")).toContainText(
|
|
"42",
|
|
{ timeout: 15000 },
|
|
)
|
|
})
|