Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

11.8 KB
Raw Blame
import { expect } from "@playwright/test";

async function call(page, body) {
  return page.evaluate(async (body) => {
    const response = await fetch("/api/v1/workflows", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
    return { status: response.status, body: await response.json() };
  }, body);
}
async function get(page, query) {
  return page.evaluate(async (query) => { const response = await fetch(`/api/v1/workflows?${query}`); return { status: response.status, body: await response.json() }; }, query);
}

export async function workflowCanvasJourney(page, fixture) {
  let response = await call(page, {
    action: "create",
    graph: {
      name: "E2E Canvas Workflow", description: "Canvas/runtime integration fixture", status: "draft", inputs: {}, metadata: { provenance: "user" },
      nodes: [
        { id: "manual", name: "Manual Trigger", type: "manual", position: { x: 40, y: 260 }, config: {} },
        { id: "cache", name: "Cache Context", type: "cache", position: { x: 300, y: 260 }, config: { mode: "get_or_set", key: "e2e-canvas-cache", ttlSeconds: 60, value: { $ref: "input" } } },
        { id: "memory", name: "Memory Search", type: "memory", position: { x: 560, y: 260 }, config: { scope: "agent", mode: "search", query: "e2e-canvas", limit: 4 } },
        { id: "session", name: "Current Session", type: "session", position: { x: 820, y: 260 }, config: { mode: "current" } },
        { id: "directory", name: "Tool Directory", type: "directory", position: { x: 1080, y: 260 }, config: { source: "tools", query: "memory", limit: 20 } },
        { id: "condition", name: "Route OK", type: "condition", position: { x: 1340, y: 260 }, config: { path: "input.ok" } },
        { id: "yes", name: "Success Output", type: "output", position: { x: 1620, y: 160 }, config: { value: { ok: true } } },
        { id: "no", name: "Fallback Output", type: "output", position: { x: 1620, y: 380 }, config: { value: { ok: false } } },
      ],
      edges: [
        { id: "edge-manual-cache", source: "manual", target: "cache" },
        { id: "edge-cache-memory", source: "cache", target: "memory" },
        { id: "edge-memory-session", source: "memory", target: "session" },
        { id: "edge-session-directory", source: "session", target: "directory" },
        { id: "edge-directory-condition", source: "directory", target: "condition" },
        { id: "edge-true", source: "condition", target: "yes", sourceHandle: "true" },
        { id: "edge-false", source: "condition", target: "no", sourceHandle: "false" },
      ],
    },
  });
  expect(response.status).toBe(200);
  let graph = response.body.graph;

  await page.goto(fixture.base + "/workflows");
  const canvas = page.getByRole("application", { name: "Workflow canvas" }).last();
  await expect(canvas).toBeVisible();
  for (const name of ["Select mode", "Pan mode", "Zoom in", "Zoom out", "Fit view"]) await expect(canvas.getByRole("button", { name })).toBeVisible();
  await expect(canvas.getByRole("button", { name: "Tidy up" })).toBeVisible();
  const minimap = canvas.getByLabel("Workflow canvas minimap");
  await expect(minimap).toBeVisible();
  await expect(minimap.locator(".react-flow__minimap-node")).toHaveCount(8);
  const manualNode = canvas.locator(".react-flow__node", { hasText: "Manual Trigger" });
  await expect(manualNode).toBeVisible();

  // n8n-style fast construction: a node output exposes +, opens the contextual
  // node creator without trigger types, and inserts+connects the chosen next step.
  await manualNode.hover();
  await canvas.getByRole("button", { name: "Add after Manual Trigger", exact: true }).click();
  await expect(page.getByText("What happens next?", { exact: true })).toBeVisible();
  await expect(page.getByPlaceholder("Search nodes…")).toBeFocused();
  await expect(page.getByRole("button", { name: "Flow", exact: true })).toBeVisible();
  await expect(page.getByRole("button", { name: "Triggers", exact: true })).toHaveCount(0);
  await page.getByPlaceholder("Search nodes…").fill("Wait");
  await page.getByText("Wait", { exact: true }).click();
  const insertedWait = canvas.locator(".react-flow__node", { hasText: "Wait" });
  await expect(insertedWait).toBeVisible();
  await expect(canvas.locator(".react-flow__edge")).toHaveCount(8);
  await page.getByRole("button", { name: "Delete node", exact: true }).click();
  await expect(insertedWait).toHaveCount(0);
  await expect(canvas.locator(".react-flow__edge")).toHaveCount(7);

  const workflowName = page.getByLabel("Workflow name");
  const saveWorkflow = page.locator('[data-slot="workflows-feature"] [data-slot="app-frame-toolbar"]').getByRole("button", { name: "Save", exact: true });
  const originalName = await workflowName.inputValue();
  await workflowName.fill(originalName + " unsaved");
  for (const viewport of [{ width: 390, height: 844 }, { width: 1280, height: 900 }]) {
    await page.setViewportSize(viewport);
    await expect(page.locator("#main-content")).toHaveAttribute("data-shell", viewport.width < 768 ? "ios" : "macos");
    await expect(page.getByLabel("Workflow name")).toHaveValue(originalName + " unsaved");
  }
  await page.getByLabel("Workflow name").fill(originalName);
  await saveWorkflow.click();
  await expect(saveWorkflow).toBeDisabled();

  // Responsive contract: on a phone-sized pane the wide graph starts focused on
  // the trigger at a readable zoom, side panels become drawers, and the toolbar
  // collapses secondary actions without horizontal feature overflow.
  for (const viewport of [{ width: 390, height: 844 }, { width: 844, height: 390 }]) {
    await page.setViewportSize(viewport);
    await page.goto(fixture.base + "/workflows");
    const feature = page.locator('[data-slot="workflows-feature"]');
    await expect(feature).toBeVisible();
    expect(await feature.evaluate((el) => el.scrollWidth <= el.clientWidth + 1)).toBe(true);
    await expect(page.getByLabel("Workflow name")).toBeVisible();
    const trigger = canvas.locator(".react-flow__node", { hasText: "Manual Trigger" });
    await expect(trigger).toBeVisible();
    // Measure settled geometry, not a lucky intermediate fit animation frame.
    let previousWidth = 0, stableSamples = 0;
    await expect.poll(async () => {
      const width = (await trigger.boundingBox())?.width ?? 0;
      stableSamples = Math.abs(width - previousWidth) < 0.5 ? stableSamples + 1 : 0;
      previousWidth = width;
      return stableSamples >= 3 ? width : 0;
    }, { timeout: 10000, intervals: [100] }).toBeGreaterThan(viewport.width < 700 ? 140 : 95);
    if (viewport.width < 700) {
      await expect(page.getByRole("button", { name: "New workflow" })).toBeVisible();
      await expect(page.getByRole("button", { name: "More actions" })).toBeVisible();
    }
  }
  await page.setViewportSize({ width: 1280, height: 900 });
  await page.goto(fixture.base + "/workflows");

  const normalPath = page.locator('[data-testid="rf__edge-edge-manual-cache"] .react-flow__edge-path');
  const branchPath = page.locator('[data-testid="rf__edge-edge-true"] .react-flow__edge-path');
  await expect(normalPath).toHaveAttribute("marker-end", /url/);
  await expect(branchPath).toHaveAttribute("marker-end", /url/);
  expect(await normalPath.evaluate((el) => getComputedStyle(el).strokeDasharray)).toBe("none");
  expect(await branchPath.evaluate((el) => getComputedStyle(el).strokeDasharray)).not.toBe("none");

  await canvas.getByRole("button", { name: "Pan mode" }).click();
  await expect(canvas.getByRole("button", { name: "Pan mode" })).toHaveClass(/is-active/);
  await canvas.getByRole("button", { name: "Select mode" }).click();
  await expect(canvas.getByRole("button", { name: "Select mode" })).toHaveClass(/is-active/);
  await canvas.getByRole("button", { name: "Zoom in" }).click();
  await canvas.getByRole("button", { name: "Zoom out" }).click();
  await canvas.getByRole("button", { name: "Fit view" }).click();

  await page.getByRole("button", { name: "Directory", exact: true }).click();
  const directory = page.locator('[data-slot="workflow-directory-panel"]');
  await expect(directory.getByPlaceholder("Search tools…")).toBeVisible();
  await expect(directory.getByText("agent_memory_search", { exact: true })).toBeVisible();
  await directory.getByRole("button", { name: "projects", exact: true }).click();
  await expect(directory.getByText("fixture-project", { exact: true })).toBeVisible();
  await directory.getByRole("button", { name: "skills", exact: true }).click();
  await expect(directory.getByText("No matching skills.", { exact: true })).toBeHidden();
  await page.getByRole("button", { name: "Builder", exact: true }).click();

  // Connection controls are persisted graph metadata, not temporary React Flow styling.
  await page.locator(".react-flow__node", { hasText: "Manual Trigger" }).click();
  const connectionPanel = page.getByText("Connections", { exact: true }).locator("..");
  const lineStyle = connectionPanel.getByLabel("Line style").first();
  await expect(lineStyle).toHaveValue("auto");
  await lineStyle.selectOption("dashed");
  const connectionActive = connectionPanel.getByRole("switch", { name: "Active" }).first();
  await expect(connectionActive).toBeChecked();
  await connectionActive.click();
  await expect(connectionActive).not.toBeChecked();
  await connectionActive.click();
  await lineStyle.selectOption("solid");

  // Reverse is available for ordinary action edges, then reversible back before execution.
  await page.locator(".react-flow__node", { hasText: "Cache Context" }).click();
  await page.getByRole("button", { name: "Reverse Cache Context to Memory Search" }).click();
  await page.locator(".react-flow__node", { hasText: "Memory Search" }).click();
  await expect(page.getByText(/→ Cache Context/)).toBeVisible();
  await page.getByRole("button", { name: "Reverse Memory Search to Cache Context" }).click();

  const statusSelect = page.getByLabel("Workflow status");
  await expect(statusSelect).toHaveValue("draft");
  await statusSelect.selectOption("active");
  await expect(statusSelect).toHaveValue("active");
  await saveWorkflow.click();
  await expect(page.getByText("Unsaved", { exact: true })).toBeHidden();
  response = await get(page, `graph_id=${encodeURIComponent(graph.id)}`);
  expect(response.status).toBe(200); graph = response.body.graph;
  expect(graph.status).toBe("active");

  response = await call(page, { action: "run", graph_id: graph.id, input: { ok: true, payload: "cached-value" }, idempotency_key: `e2e-canvas-${Date.now()}` });
  expect(response.status).toBe(200);
  let run = response.body;
  for (let i = 0; i < 12 && run.state === "running"; i += 1) {
    const polled = await get(page, `run_id=${encodeURIComponent(run.id)}&wait_ms=1500`); expect(polled.status).toBe(200); run = polled.body;
  }
  expect(run.state).toBe("completed");
  for (const id of ["cache", "memory", "session", "directory", "condition", "yes"]) expect(run.nodes.find((node) => node.id === id)?.state).toBe("completed");
  expect(run.nodes.find((node) => node.id === "no")?.state).toBe("skipped");
  expect(run.edges.find((edge) => edge.id === "edge-true")?.state).toBe("enabled");
  expect(run.edges.find((edge) => edge.id === "edge-false")?.state).toBe("disabled");

  await page.getByRole("button", { name: "Tidy up" }).click();
  await expect(page.getByText("Unsaved", { exact: true })).toBeVisible();
  expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1)).toBe(true);

  // Delete using the last persisted revision; the local tidy is intentionally unsaved.
  response = await call(page, { action: "delete", graph_id: graph.id, expected_revision: graph.revision });
  expect(response.status).toBe(200);
  console.log("PASS Workflow n8n-like contextual node creator/quick-add, responsive toolbar/drawers, readable compact trigger focus, 5/5 canvas controls, minimap, persistent edge style/active/reverse controls, project/skill directory, active mode, cache/memory/session/directory runtime and cleanup");
}