Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions browser_tests/fixtures/agentInsertWorkflowOverlapFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { mergeTests } from '@playwright/test'

import { agentTest } from '@e2e/fixtures/agentPanelFixture'
import { bindPopulatedTab } from '@e2e/fixtures/utils/agentInsertWorkflowOverlap'
import { webSocketFixture } from '@e2e/fixtures/ws'

const test = mergeTests(agentTest, webSocketFixture)

export const insertOverlapTest = test.extend<{
populatedTab: Awaited<ReturnType<typeof bindPopulatedTab>>
}>({
populatedTab: async ({ page, getWebSocket }, use) => {
await use(await bindPopulatedTab(page, getWebSocket))
}
})
53 changes: 53 additions & 0 deletions browser_tests/fixtures/data/agentInsertWorkflowOverlap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Op, WidgetCatalog } from '@comfyorg/comfy-multi-player'

export const WORKFLOW_ID = 'b3e7d9c1-0000-4000-8000-000000000020'
export const MESSAGE_ID = 'b3e7d9c1-0000-4000-8000-000000000021'
export const THREAD_ID = 'b3e7d9c1-0000-4000-8000-000000000022'

function note(
id: number,
pos: [number, number],
size: [number, number],
text: string
) {
return {
id,
type: 'MarkdownNote',
pos,
size,
mode: 0,
order: 0,
flags: {},
inputs: [],
outputs: [],
properties: {},
widgets_values: [text]
}
}

export const EXISTING_NODES = [
note(1, [0, 180], [400, 300], 'Existing node A'),
note(2, [450, 180], [400, 300], 'Existing node B'),
note(3, [900, 180], [400, 300], 'Existing node C')
]

export const Z_IMAGE_TEMPLATE_NODES = [
note(35, [-420, 200], [510, 772], 'Template note'),
note(57, [130, 200], [400, 470], 'Template sampler'),
note(9, [570, 200], [780, 660], 'Template save')
]

export const OVERLAP_CATALOG: WidgetCatalog = {
types: { MarkdownNote: { widget_order: ['text'] } }
}

export const INSERT_TEMPLATE_OPS = [
{
op_id: 'agent-insert-workflow-overlap-op-0'.padEnd(32, '0'),
actor: 'agent:e2e:turn-1',
base_version: 1,
stamp: [1, 'agent:e2e:turn-1'],
op: 'insert_workflow',
workflow: { nodes: Z_IMAGE_TEMPLATE_NODES, links: [] }
}
] satisfies Op[]
117 changes: 117 additions & 0 deletions browser_tests/fixtures/utils/agentInsertWorkflowOverlap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import type { Page, WebSocketRoute } from '@playwright/test'
import { expect } from '@playwright/test'

import {
BLANK_WORKFLOW,
bootAgentApp,
loadIntoBootWorkflow,
mockAgentTurnApi,
mockWorkflowPersistence
} from '@e2e/fixtures/agentPanelFixture'
import { HostDoc } from '@e2e/fixtures/agentConversationHostDoc'
import { AgentPanel } from '@e2e/fixtures/components/AgentPanel'
import {
EXISTING_NODES,
INSERT_TEMPLATE_OPS,
MESSAGE_ID,
OVERLAP_CATALOG,
THREAD_ID,
WORKFLOW_ID,
Z_IMAGE_TEMPLATE_NODES
} from '@e2e/fixtures/data/agentInsertWorkflowOverlap'
import { subscribeAgentWorkflow } from '@e2e/fixtures/utils/subscribeAgentWorkflow'

function readNodeRects(page: Page) {
return page.evaluate(() =>
window.app!.graph.nodes.map((node) => ({
id: String(node.id),
text: String(node.widgets?.[0]?.value ?? ''),
x: node.pos[0],
y: node.pos[1],
width: node.size[0],
height: node.size[1]
}))
)
}

type NodeRect = Awaited<ReturnType<typeof readNodeRects>>[number]

function overlaps(a: NodeRect, b: NodeRect): boolean {
return (
a.x < b.x + b.width &&
b.x < a.x + a.width &&
a.y < b.y + b.height &&
b.y < a.y + a.height
)
}

export async function bindPopulatedTab(
page: Page,
getWebSocket: () => Promise<WebSocketRoute>
) {
await page.setViewportSize({ width: 1920, height: 1280 })
await bootAgentApp(page, true, {
beforeNavigate: async (page) => {
await mockAgentTurnApi(page, {
message_id: MESSAGE_ID,
thread_id: THREAD_ID,
workflow_id: WORKFLOW_ID
})
await mockWorkflowPersistence(page, WORKFLOW_ID)
}
})
await loadIntoBootWorkflow(page, BLANK_WORKFLOW)

const agentPanel = new AgentPanel(page)
await agentPanel.open()
const socket = await getWebSocket()
await subscribeAgentWorkflow({
agentPanel,
socket,
workflowId: WORKFLOW_ID,
prompt: 'Insert the Z-Image template into this tab'
})

const host = new HostDoc(
WORKFLOW_ID,
{ nodes: EXISTING_NODES, links: [] },
OVERLAP_CATALOG
)
for (const frame of host.initialSync()) socket.send(JSON.stringify(frame))
await expect
.poll(() => page.evaluate(() => window.app!.graph.nodes.length))
.toBe(EXISTING_NODES.length)
const existingIds = (await readNodeRects(page)).map((rect) => rect.id)

return {
async insertTemplate() {
socket.send(JSON.stringify(host.apply(INSERT_TEMPLATE_OPS)))
await expect
.poll(() => page.evaluate(() => window.app!.graph.nodes.length))
.toBe(EXISTING_NODES.length + Z_IMAGE_TEMPLATE_NODES.length)
},
async readPlacement() {
const rects = await readNodeRects(page)
const existing = rects.filter((rect) => existingIds.includes(rect.id))
const inserted = rects.filter((rect) => !existingIds.includes(rect.id))
const anchor = inserted.find((rect) => rect.text === 'Template note')
return {
overlaps: inserted.flatMap((node) =>
existing
.filter((other) => overlaps(node, other))
.map(
(other) =>
`inserted "${node.text}" at (${node.x}, ${node.y}) overlaps ` +
`existing "${other.text}" at (${other.x}, ${other.y})`
)
),
layoutFromNote: Object.fromEntries(
inserted.map((node) => [
node.text,
anchor ? [node.x - anchor.x, node.y - anchor.y] : null
])
)
}
}
}
}
31 changes: 31 additions & 0 deletions browser_tests/fixtures/utils/subscribeAgentWorkflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from '@playwright/test'
import type { WebSocketRoute } from '@playwright/test'

import type { AgentPanel } from '@e2e/fixtures/components/AgentPanel'

interface SubscribeAgentWorkflowInput {
agentPanel: AgentPanel
socket: WebSocketRoute
workflowId: string
prompt: string
}

export async function subscribeAgentWorkflow({
agentPanel,
socket,
workflowId,
prompt
}: SubscribeAgentWorkflowInput): Promise<string[]> {
const outboundFrames: string[] = []
socket.onMessage((message) => outboundFrames.push(String(message)))
await agentPanel.selectWorkflow()
await agentPanel.sendMessage(prompt)
await expect
.poll(() => outboundFrames, { timeout: 15_000 })
.toContainEqual(
expect.stringMatching(
new RegExp(`doc_subscribe.*${workflowId}|${workflowId}.*doc_subscribe`)
)
)
return outboundFrames
}
Loading
Loading