diff --git a/browser_tests/fixtures/ComfyPage.ts b/browser_tests/fixtures/ComfyPage.ts index 352477a986a..94f3d1db307 100644 --- a/browser_tests/fixtures/ComfyPage.ts +++ b/browser_tests/fixtures/ComfyPage.ts @@ -99,6 +99,43 @@ class ComfyPropertiesPanel { name: 'Toggle properties panel' }) } + + async open(): Promise { + if (!(await this.root.isVisible())) await this.toggleButton.click() + await comfyExpect(this.root).toBeVisible() + } + + async renameParameterLabel( + currentLabel: string, + nextLabel: string + ): Promise { + await this.root + .getByRole('tab', { name: 'Parameters', exact: true }) + .click() + await this.root.getByText(currentLabel, { exact: true }).click() + const labelInput = this.root.getByPlaceholder(currentLabel, { exact: true }) + await labelInput.fill(nextLabel) + await labelInput.press('Enter') + await comfyExpect( + this.root.getByText(nextLabel, { exact: true }) + ).toBeVisible() + } + + async clearParameterLabel( + currentLabel: string, + defaultLabel: string + ): Promise { + await this.root.getByText(currentLabel, { exact: true }).click() + const labelInput = this.root.getByPlaceholder(defaultLabel, { exact: true }) + await labelInput.clear() + await labelInput.press('Enter') + await comfyExpect( + this.root.getByText(defaultLabel, { exact: true }) + ).toBeVisible() + await comfyExpect( + this.root.getByText(currentLabel, { exact: true }) + ).toHaveCount(0) + } } class ComfyMenu { diff --git a/browser_tests/fixtures/components/SubgraphEditor.ts b/browser_tests/fixtures/components/SubgraphEditor.ts index 277c80ef9dc..88211e64599 100644 --- a/browser_tests/fixtures/components/SubgraphEditor.ts +++ b/browser_tests/fixtures/components/SubgraphEditor.ts @@ -4,6 +4,8 @@ import { comfyExpect as expect } from '@e2e/fixtures/ComfyPage' import type { ComfyPage } from '@e2e/fixtures/ComfyPage' import { TestIds } from '@e2e/fixtures/selectors' import { dragByIndex } from '@e2e/fixtures/utils/dragAndDrop' +import { fitToViewInstant } from '@e2e/fixtures/utils/fitToView' +import type { NodeReference } from '@e2e/fixtures/utils/litegraphUtils' import { VueNodeFixture } from '@e2e/fixtures/utils/vueNodeFixtures' export class SubgraphEditor { @@ -86,6 +88,30 @@ export class SubgraphEditor { const item = this.resolveItem(options) await this.togglePromotionOnItem(item, options.toState) } + + async promoteWidget( + host: NodeReference, + options: { + nodeName?: string + nodeId?: string + widgetName: string + } + ): Promise { + await fitToViewInstant(this.comfyPage, { zoom: 1 }) + if (this.comfyPage.isVueNodes) { + await this.ensureOpen( + this.comfyPage.vueNodes.getNodeLocator(String(host.id)) + ) + } else { + await host.clickContextMenuOption('Edit Subgraph Widgets') + await expect(this.root).toBeVisible() + } + await this.togglePromotionOnItem(this.resolveItem(options), true) + await this.comfyPage.menu.propertiesPanel.toggleButton.click() + await expect(this.root).toBeHidden() + await fitToViewInstant(this.comfyPage, { zoom: 1 }) + } + async dragItem(fromIndex: number, toIndex: number) { await dragByIndex(this.promotionItems, fromIndex, toIndex) await this.comfyPage.nextFrame() diff --git a/browser_tests/fixtures/data/subgraphTopologies.ts b/browser_tests/fixtures/data/subgraphTopologies.ts new file mode 100644 index 00000000000..c0632e576d5 --- /dev/null +++ b/browser_tests/fixtures/data/subgraphTopologies.ts @@ -0,0 +1,38 @@ +import type { GraphTopology } from '@e2e/fixtures/helpers/SubgraphHelper' + +export const nestedSubgraphTopologies = { + root: { + nodes: ['10', '8', '9'], + links: [ + ['10', 0, '8', 0], + ['10', 1, '8', 1], + ['8', 0, '9', 0] + ] + }, + outer: { + nodes: ['11', '3', '6'], + links: [ + ['11', 0, '3', 2], + ['11', 1, '3', 3], + ['11', 2, '3', 0], + ['11', 3, '6', 0], + ['11', 4, '-20', 1], + ['3', 0, '-20', 0], + ['6', 0, '3', 1] + ] + }, + inner: { + nodes: ['4', '5', '7'], + links: [ + ['4', 0, '-20', 2], + ['4', 1, '-20', 3], + ['4', 1, '7', 0], + ['4', 2, '-20', 4], + ['5', 0, '-20', 1], + ['7', 0, '-20', 0] + ] + } +} satisfies Record<'root' | 'outer' | 'inner', GraphTopology> + +export const outerSubgraphBreadcrumbId = + 'subgraph-8beb610f-ddd1-4489-ae0d-2f732a4042ae' diff --git a/browser_tests/fixtures/helpers/SubgraphHelper.ts b/browser_tests/fixtures/helpers/SubgraphHelper.ts index 7f0b69050b0..6b29b23bb4d 100644 --- a/browser_tests/fixtures/helpers/SubgraphHelper.ts +++ b/browser_tests/fixtures/helpers/SubgraphHelper.ts @@ -18,6 +18,16 @@ import { SubgraphSlotReference } from '@e2e/fixtures/utils/litegraphUtils' import { getAllHostPromotedWidgets } from '@e2e/fixtures/utils/promotedWidgets' import type { PromotedWidgetEntry } from '@e2e/fixtures/utils/promotedWidgets' +export interface GraphTopology { + nodes: string[] + links: [string, number, string, number][] +} + +export interface SubgraphHostIdentity { + type: string + subgraphId: string +} + interface SubgraphDefinitionRow { name: string nodes: number @@ -462,6 +472,24 @@ export class SubgraphHelper { } } + async enterSubgraph(node: NodeReference): Promise { + const subgraphId = await this.page.evaluate((id) => { + const host = window.app!.canvas.graph?.getNodeById(id) + if (!host?.isSubgraphNode()) { + throw new Error(`Expected visible subgraph node ${id}`) + } + return host.subgraph.id + }, node.id) + + if (this.comfyPage.isVueNodes) { + await this.comfyPage.vueNodes.enterSubgraph(String(node.id)) + await this.comfyPage.vueNodes.waitForNodes() + } else { + await node.navigateIntoSubgraph() + } + await expect.poll(() => this.getActiveGraphId()).toBe(subgraphId) + } + async isInSubgraph(): Promise { return this.page.evaluate(() => { const graph = window.app!.canvas.graph @@ -529,6 +557,85 @@ export class SubgraphHelper { return getAllHostPromotedWidgets(this.comfyPage) } + async getHostIdentity(node: NodeReference): Promise { + return this.page.evaluate((id) => { + const host = window.app!.rootGraph.getNodeById(id) + if (!host?.isSubgraphNode()) { + throw new Error(`Subgraph host ${id} not found`) + } + return { type: host.type, subgraphId: host.subgraph.id } + }, node.id) + } + + async expectPromotedWidget( + node: NodeReference, + name: string, + expected: SubgraphHostIdentity & { label: string | null; value: unknown } + ): Promise { + await expect + .poll(() => + this.page.evaluate( + ([id, widgetName]) => { + const host = window.app!.rootGraph.getNodeById(id) + if (!host?.isSubgraphNode()) return null + const widget = host.widgets.find( + (candidate) => candidate.name === widgetName + ) + return { + type: host.type, + subgraphId: host.subgraph.id, + label: widget?.label ?? null, + value: widget?.value + } + }, + [node.id, name] as const + ) + ) + .toEqual(expected) + } + + async expectPersistedHostIds( + workflowName: string, + expectedIds: string[] + ): Promise { + const workflow = + await this.comfyPage.workflow.getPersistedWorkflow(workflowName) + this.expectHostIds(workflow, expectedIds) + } + + expectHostIds(workflow: ComfyWorkflowJSON, expectedIds: string[]): void { + const hostIds = workflow.nodes + .filter((node) => + workflow.definitions?.subgraphs.some( + (subgraph) => subgraph.id === node.type + ) + ) + .map((node) => String(node.id)) + expect(hostIds).toEqual(expectedIds) + } + + async getActiveTopology(): Promise { + return this.page.evaluate(() => { + const graph = window.app!.canvas.graph + if (!graph) throw new Error('Canvas graph was not loaded') + return { + nodes: graph.nodes.map((node) => String(node.id)).sort(), + links: [...graph.links.values()] + .map<[string, number, string, number]>((link) => [ + String(link.origin_id), + link.origin_slot, + String(link.target_id), + link.target_slot + ]) + .sort((a, b) => a.join(':').localeCompare(b.join(':'))) + } + }) + } + + async expectActiveTopology(expected: GraphTopology): Promise { + await expect.poll(() => this.getActiveTopology()).toEqual(expected) + } + /** Reads from `window.app.canvas.graph` (viewed root or nested subgraph). */ async getNodeCount(): Promise { return this.page.evaluate(() => { diff --git a/browser_tests/fixtures/helpers/WorkflowHelper.ts b/browser_tests/fixtures/helpers/WorkflowHelper.ts index 546aa068a97..baf5d6970ab 100644 --- a/browser_tests/fixtures/helpers/WorkflowHelper.ts +++ b/browser_tests/fixtures/helpers/WorkflowHelper.ts @@ -8,6 +8,7 @@ import type { ComfyApiWorkflow, ComfyWorkflowJSON } from '@/platform/workflow/validation/schemas/workflowSchema' +import { zComfyWorkflow } from '@/platform/workflow/validation/schemas/workflowSchema' import type { WorkspaceStore } from '@e2e/types/globals' import type { ComfyPage } from '@e2e/fixtures/ComfyPage' import { assetPath } from '@e2e/fixtures/utils/paths' @@ -132,6 +133,39 @@ export class WorkflowHelper { } } + async getPersistedWorkflow(workflowName: string): Promise { + const workflowPath = `/api/userdata/${encodeURIComponent(`workflows/${workflowName}.json`)}` + const response = await this.comfyPage.request.get( + `${this.comfyPage.apiUrl}${workflowPath}`, + { headers: { 'Comfy-User': this.comfyPage.id } } + ) + expect(response.ok()).toBe(true) + return zComfyWorkflow.parse(await response.json()) + } + + async saveWorkflow(workflowName: string): Promise { + const workflowPath = `/api/userdata/${encodeURIComponent(`workflows/${workflowName}.json`)}` + const saveResponse = this.comfyPage.page.waitForResponse( + (response) => + new URL(response.url()).pathname === workflowPath && + response.request().method() === 'POST' + ) + await this.comfyPage.menu.topbar.saveWorkflow(workflowName) + const response = await saveResponse + expect(response.status()).toBe(200) + expect(response.request().headers()['comfy-user']).toBe(this.comfyPage.id) + return zComfyWorkflow.parse(response.request().postDataJSON()) + } + + async reloadAndOpenPersistedWorkflow(workflowName: string): Promise { + await this.reloadAndWaitForApp() + const { workflowsTab } = this.comfyPage.menu + await workflowsTab.open() + await workflowsTab.getPersistedItem(workflowName).click() + await this.waitForWorkflowIdle() + await workflowsTab.close() + } + async deleteWorkflow( workflowName: string, whenMissing: 'ignoreMissing' | 'throwIfMissing' = 'ignoreMissing' diff --git a/browser_tests/fixtures/utils/litegraphUtils.ts b/browser_tests/fixtures/utils/litegraphUtils.ts index 32c615dddd6..dd6ba5652f5 100644 --- a/browser_tests/fixtures/utils/litegraphUtils.ts +++ b/browser_tests/fixtures/utils/litegraphUtils.ts @@ -284,6 +284,9 @@ export class NodeReference { return !!node }, this.id) } + async expectExists(expected = true): Promise { + await expect.poll(() => this.exists()).toBe(expected) + } getType(): Promise { return this.getProperty('type') } @@ -414,6 +417,76 @@ export class NodeReference { return new NodeWidgetReference(index, this) } + async getPromotedTextWidget(name: string) { + const vueNode = this.comfyPage.vueNodes.getNodeLocator(String(this.id)) + if (this.comfyPage.isVueNodes) { + return vueNode.getByRole('textbox', { name, exact: true }) + } + + const position = await (await this.getWidgetByName(name)).getPosition() + const textboxes = this.comfyPage.page.getByRole('textbox', { + name, + exact: true + }) + const boxes = await textboxes.evaluateAll((elements) => + elements.map((element) => { + const { x, y, width, height } = element.getBoundingClientRect() + return { x, y, width, height } + }) + ) + const closestIndex = boxes.reduce( + (best, box, index) => { + const distance = Math.hypot( + box.x + box.width / 2 - position.x, + box.y + box.height / 2 - position.y + ) + return distance < best.distance ? { index, distance } : best + }, + { index: -1, distance: Number.POSITIVE_INFINITY } + ).index + if (closestIndex < 0) { + throw new Error( + `Text widget "${name}" for node ${this.id} was not rendered` + ) + } + return textboxes.nth(closestIndex) + } + async fillPromotedTextWidget(name: string, value: string): Promise { + const widget = await this.getPromotedTextWidget(name) + await widget.fill(value) + await expect(widget).toHaveValue(value) + await expect + .poll(async () => (await this.getWidgetByName(name)).getValue()) + .toBe(value) + } + async expectPromotedTextWidgetValue( + name: string, + value: string + ): Promise { + const widget = await this.getPromotedTextWidget(name) + await expect(widget).toHaveValue(value) + await expect + .poll(async () => (await this.getWidgetByName(name)).getValue()) + .toBe(value) + } + async expectPromotedWidgetCount(expected: number): Promise { + await expect + .poll(async () => (await this.getProperty('widgets')).length) + .toBe(expected) + } + async select(): Promise { + if (this.comfyPage.isVueNodes) { + await this.comfyPage.vueNodes.selectNode(String(this.id)) + } else { + await this.comfyPage.page.evaluate((id) => { + const node = window.app!.canvas.graph?.getNodeById(id) + if (!node) throw new Error(`Node ${id} not found`) + window.app!.canvas.deselectAll() + window.app!.canvas.selectNode(node) + }, this.id) + await this.comfyPage.nextFrame() + } + } async click( position: 'title' | 'collapse', options?: { @@ -450,10 +523,26 @@ export class NodeReference { await this.click('title') await this.comfyPage.clipboard.copy() } + async duplicate(): Promise { + const getNodeIds = () => + this.comfyPage.page.evaluate(() => + window.app!.canvas.graph!.nodes.map((node) => String(node.id)) + ) + const existingIds = new Set(await getNodeIds()) + + await this.copy() + await this.comfyPage.clipboard.paste() + + const getAddedIds = async () => + (await getNodeIds()).filter((id) => !existingIds.has(id)) + await expect.poll(getAddedIds).toHaveLength(1) + const [addedId] = await getAddedIds() + if (!addedId) throw new Error(`Copy of node ${this.id} was not created`) + return this.comfyPage.nodeOps.getNodeRefById(addedId) + } async delete(): Promise { - await this.click('title') - await this.comfyPage.page.keyboard.press('Delete') - await this.comfyPage.nextFrame() + await this.select() + await this.comfyPage.keyboard.delete() } async connectWidget( originSlotIndex: number, diff --git a/browser_tests/tests/nodeReplacement.spec.ts b/browser_tests/tests/nodeReplacement.spec.ts index fbaf00b8d16..473cf9e18c0 100644 --- a/browser_tests/tests/nodeReplacement.spec.ts +++ b/browser_tests/tests/nodeReplacement.spec.ts @@ -118,6 +118,9 @@ test.describe('Node replacement', { tag: ['@node', '@ui'] }, () => { test('Replace Node replaces a single group in-place', async ({ comfyPage }) => { + const before = await comfyPage.canvasOps.getNodeGeometry( + toNodeId(1) + ) const swapGroup = getSwapNodesGroup(comfyPage.page) await swapGroup .getByRole('button', { name: /replace node/i }) @@ -139,6 +142,8 @@ test.describe('Node replacement', { tag: ['@node', '@ui'] }, () => { ksampler?.id, 'Replaced node should keep the original id' ).toBe(1) + expect(ksampler?.pos).toEqual(before.pos) + expect(ksampler?.size).toEqual(before.size) const linkFromReplacedToDecode = workflow.links?.find( (l) => l[1] === 1 && l[3] === 2 diff --git a/browser_tests/tests/primitiveNode.spec.ts b/browser_tests/tests/primitiveNode.spec.ts index 7bf7fd10fd0..e44a1273ae7 100644 --- a/browser_tests/tests/primitiveNode.spec.ts +++ b/browser_tests/tests/primitiveNode.spec.ts @@ -1,5 +1,7 @@ import { expect } from '@playwright/test' +import { toNodeId } from '@/types/nodeId' + import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' import { TestIds } from '@e2e/fixtures/selectors' import type { NodeReference } from '@e2e/fixtures/utils/litegraphUtils' @@ -7,6 +9,96 @@ import type { NodeReference } from '@e2e/fixtures/utils/litegraphUtils' test.use({ initialSettings: { 'Comfy.UseNewMenu': 'Disabled' } }) test.describe('Primitive Node', { tag: ['@screenshot', '@node'] }, () => { + for (const renderer of [ + { name: 'LiteGraph', tag: '@ui' }, + { name: 'Vue', tag: ['@ui', '@vue-nodes'] } + ]) { + test.describe(`${renderer.name} renderer`, { tag: renderer.tag }, () => { + test('widget and socket coexist through connect and disconnect with the connected value', async ({ + comfyPage + }) => { + await comfyPage.workflow.loadWorkflow( + 'primitive/primitive_node_unconnected' + ) + const primitive = await comfyPage.nodeOps.getNodeRefById(1) + const ksampler = await comfyPage.nodeOps.getNodeRefById(2) + const seed = await ksampler.getWidgetByName('seed') + const originalValue = await seed.getValue() + expect(originalValue).toBe(0) + + await primitive.connectWidget(0, ksampler, 0) + const primitiveWidget = await primitive.getWidget(0) + if (renderer.name === 'Vue') { + const input = comfyPage.vueNodes + .getNodeLocator(primitive.id) + .getByRole('spinbutton') + await input.fill('222') + await input.press('Tab') + } else { + await primitiveWidget.click() + await comfyPage.nodeOps.fillLegacyWidgetDialog('222') + } + expect(await primitiveWidget.getValue()).toBe(222) + await expect + .poll(() => + comfyPage.page.evaluate( + ([nodeId, sourceNodeId]) => { + const node = window.app!.graph.getNodeById(nodeId) + return { + hasWidget: node?.widgets?.some( + (widget) => widget.name === 'seed' + ), + sourceValue: + window.app!.graph.getNodeById(sourceNodeId)?.widgets?.[0] + ?.value, + widgetValue: node?.widgets?.find( + (widget) => widget.name === 'seed' + )?.value, + socketLink: node?.inputs.find( + (input) => input.widget?.name === 'seed' + )?.link + } + }, + [toNodeId(2), toNodeId(1)] as const + ) + ) + .toEqual({ + hasWidget: true, + sourceValue: 222, + widgetValue: 222, + socketLink: expect.any(Number) + }) + + const disconnected = await comfyPage.page.evaluate((nodeId) => { + const node = window.app!.graph.getNodeById(nodeId) + const index = node?.inputs.findIndex( + (input) => input.widget?.name === 'seed' + ) + if (!node || index === undefined || index < 0) return false + return node.disconnectInput(index) + }, toNodeId(2)) + expect(disconnected).toBe(true) + await comfyPage.nextFrame() + await expect.poll(() => seed.getValue()).toBe(222) + await expect + .poll(() => + comfyPage.page.evaluate((nodeId) => { + const node = window.app!.graph.getNodeById(nodeId) + return { + hasWidget: node?.widgets?.some( + (widget) => widget.name === 'seed' + ), + socketLink: node?.inputs.find( + (input) => input.widget?.name === 'seed' + )?.link + } + }, toNodeId(2)) + ) + .toEqual({ hasWidget: true, socketLink: null }) + }) + }) + } + test('Can load with correct size', async ({ comfyPage }) => { await comfyPage.workflow.loadWorkflow('primitive/primitive_node') await expect(comfyPage.canvas).toHaveScreenshot('primitive_node.png') diff --git a/browser_tests/tests/subgraph/subgraphDuplicateIndependentValues.spec.ts b/browser_tests/tests/subgraph/subgraphDuplicateIndependentValues.spec.ts index 17429a82f21..c75890c457a 100644 --- a/browser_tests/tests/subgraph/subgraphDuplicateIndependentValues.spec.ts +++ b/browser_tests/tests/subgraph/subgraphDuplicateIndependentValues.spec.ts @@ -56,3 +56,66 @@ test.describe( }) } ) + +for (const renderer of [ + { name: 'LiteGraph', tag: ['@slow', '@subgraph', '@ui'] }, + { name: 'Vue', tag: ['@slow', '@subgraph', '@ui', '@vue-nodes'] } +]) { + test.describe(`${renderer.name} renderer`, { tag: renderer.tag }, () => { + for (const scenario of [ + { survivorName: 'copy', removedName: 'original' }, + { survivorName: 'original', removedName: 'copy' } + ] as const) { + test(`the ${scenario.survivorName} keeps its independent value after deleting the ${scenario.removedName} and reopening`, async ({ + comfyPage + }) => { + test.slow() + await comfyPage.workflow.setupWorkflowsDirectory({}) + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-promoted-text-widget' + ) + const original = await comfyPage.nodeOps.getNodeRefById('11') + const copy = await original.duplicate() + const survivor = scenario.survivorName === 'copy' ? copy : original + const removed = scenario.removedName === 'copy' ? copy : original + const survivorValue = `${scenario.survivorName} durable value` + const removedValue = `${scenario.removedName} discarded value` + + await test.step('Set independent host values', async () => { + await survivor.fillPromotedTextWidget('text', survivorValue) + await removed.fillPromotedTextWidget('text', removedValue) + await survivor.expectPromotedTextWidgetValue('text', survivorValue) + await removed.expectPromotedTextWidgetValue('text', removedValue) + }) + + await test.step(`Delete the ${scenario.removedName}`, async () => { + await removed.delete() + await removed.expectExists(false) + await survivor.expectPromotedTextWidgetValue('text', survivorValue) + }) + + const workflowName = `${renderer.name.toLowerCase()}-${scenario.survivorName}-host-value` + + await test.step('Save, reload, and reopen the workflow', async () => { + await comfyPage.workflow.saveWorkflow(workflowName) + await comfyPage.workflow.reloadAndOpenPersistedWorkflow(workflowName) + }) + + await test.step('Verify and edit the surviving host value', async () => { + const restored = await comfyPage.nodeOps.getNodeRefById( + String(survivor.id) + ) + await restored.expectPromotedTextWidgetValue('text', survivorValue) + await restored.fillPromotedTextWidget( + 'text', + `${survivorValue} edited after reopen` + ) + await restored.expectPromotedTextWidgetValue( + 'text', + `${survivorValue} edited after reopen` + ) + }) + }) + } + }) +} diff --git a/browser_tests/tests/subgraph/subgraphLifecycle.spec.ts b/browser_tests/tests/subgraph/subgraphLifecycle.spec.ts index 888f80056d2..32c98be3157 100644 --- a/browser_tests/tests/subgraph/subgraphLifecycle.spec.ts +++ b/browser_tests/tests/subgraph/subgraphLifecycle.spec.ts @@ -321,4 +321,70 @@ test.describe('Subgraph Lifecycle', { tag: ['@subgraph'] }, () => { ).toEqual([]) }) }) + + for (const renderer of [ + { name: 'LiteGraph', tag: ['@slow', '@ui'] }, + { name: 'Vue', tag: ['@slow', '@ui', '@vue-nodes'] } + ]) { + test.describe( + `${renderer.name} host persistence`, + { tag: renderer.tag }, + () => { + for (const scenario of [ + { survivorName: 'copy', removedName: 'original' }, + { survivorName: 'original', removedName: 'copy' } + ] as const) { + test(`the ${scenario.survivorName} remains editable after deleting the ${scenario.removedName} and reopening`, async ({ + comfyPage + }) => { + test.slow() + await comfyPage.workflow.setupWorkflowsDirectory({}) + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-promoted-text-widget' + ) + const original = await comfyPage.nodeOps.getNodeRefById('11') + const copy = await original.duplicate() + const survivor = scenario.survivorName === 'copy' ? copy : original + const removed = scenario.removedName === 'copy' ? copy : original + + await test.step(`Delete the ${scenario.removedName}`, async () => { + await removed.delete() + await removed.expectExists(false) + await survivor.expectExists() + }) + + const workflowName = `${renderer.name.toLowerCase()}-${scenario.survivorName}-survivor` + + await test.step('Save and reopen the workflow', async () => { + const savedWorkflow = + await comfyPage.workflow.saveWorkflow(workflowName) + comfyPage.subgraph.expectHostIds(savedWorkflow, [ + String(survivor.id) + ]) + await comfyPage.subgraph.expectPersistedHostIds(workflowName, [ + String(survivor.id) + ]) + await comfyPage.workflow.reloadAndOpenPersistedWorkflow( + workflowName + ) + await survivor.expectExists() + }) + + await test.step('Open and edit the surviving host', async () => { + await comfyPage.subgraph.enterSubgraph(survivor) + const inner = await comfyPage.nodeOps.getNodeRefByType( + 'CLIPTextEncode', + true + ) + const originalPosition = await inner.getPosition() + await inner.dragBy({ x: 40, y: 20 }) + await expect + .poll(() => inner.getPosition()) + .not.toEqual(originalPosition) + }) + }) + } + } + ) + } }) diff --git a/browser_tests/tests/subgraph/subgraphNavigation.spec.ts b/browser_tests/tests/subgraph/subgraphNavigation.spec.ts index 74f1714ecb3..0f46e668435 100644 --- a/browser_tests/tests/subgraph/subgraphNavigation.spec.ts +++ b/browser_tests/tests/subgraph/subgraphNavigation.spec.ts @@ -1,9 +1,16 @@ -import { expect } from '@playwright/test' - -import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' +import { expect, mergeTests } from '@playwright/test' + +import { comfyPageFixture } from '@e2e/fixtures/ComfyPage' +import { + nestedSubgraphTopologies, + outerSubgraphBreadcrumbId +} from '@e2e/fixtures/data/subgraphTopologies' +import { subgraphBreadcrumbFixture } from '@e2e/fixtures/helpers/SubgraphBreadcrumbHelper' import { TestIds } from '@e2e/fixtures/selectors' import { toNodeId } from '@/types/nodeId' +const test = mergeTests(comfyPageFixture, subgraphBreadcrumbFixture) + const UPDATED_SUBGRAPH_TITLE = 'Updated Subgraph Title' function hasVisibleNodeInViewport() { @@ -335,4 +342,53 @@ test.describe('Subgraph Navigation', { tag: ['@slow', '@subgraph'] }, () => { .toEqual({ exists: true, progress: undefined }) }) }) + + for (const renderer of [ + { name: 'LiteGraph', tag: '@ui' }, + { name: 'Vue', tag: ['@ui', '@vue-nodes'] } + ]) { + test.describe(`${renderer.name} renderer`, { tag: renderer.tag }, () => { + test('nested controls and breadcrumbs preserve exact topology', async ({ + comfyPage, + subgraphBreadcrumb + }) => { + await comfyPage.workflow.loadWorkflow('subgraphs/nested-subgraph') + await comfyPage.subgraph.expectActiveTopology( + nestedSubgraphTopologies.root + ) + + const outer = await comfyPage.nodeOps.getNodeRefById('10') + + await test.step('Open the outer subgraph', async () => { + await comfyPage.subgraph.enterSubgraph(outer) + await comfyPage.subgraph.expectActiveTopology( + nestedSubgraphTopologies.outer + ) + }) + + const inner = await comfyPage.nodeOps.getNodeRefById('11') + + await test.step('Open the inner subgraph', async () => { + await comfyPage.subgraph.enterSubgraph(inner) + await comfyPage.subgraph.expectActiveTopology( + nestedSubgraphTopologies.inner + ) + }) + + await test.step('Return to the outer subgraph', async () => { + await subgraphBreadcrumb.clickItem(outerSubgraphBreadcrumbId) + await comfyPage.subgraph.expectActiveTopology( + nestedSubgraphTopologies.outer + ) + }) + + await test.step('Return to the root graph', async () => { + await subgraphBreadcrumb.clickItem('root') + await comfyPage.subgraph.expectActiveTopology( + nestedSubgraphTopologies.root + ) + }) + }) + }) + } }) diff --git a/browser_tests/tests/subgraph/subgraphOperations.spec.ts b/browser_tests/tests/subgraph/subgraphOperations.spec.ts index 8fa759d88b7..e4e351a539d 100644 --- a/browser_tests/tests/subgraph/subgraphOperations.spec.ts +++ b/browser_tests/tests/subgraph/subgraphOperations.spec.ts @@ -160,5 +160,32 @@ test.describe('Subgraph Operations', { tag: ['@slow', '@subgraph'] }, () => { .poll(() => comfyPage.subgraph.getNodeCount()) .toBe(initialCount) }) + + for (const renderer of [ + { name: 'LiteGraph', tag: '@ui' }, + { name: 'Vue', tag: ['@ui', '@vue-nodes'] } + ]) { + test.describe(`${renderer.name} renderer`, { tag: renderer.tag }, () => { + test('root node movement is undoable', async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow('subgraphs/nested-subgraph') + const rootNode = await comfyPage.nodeOps.getNodeRefById('8') + const originalPosition = await rootNode.getPosition() + + await test.step('Move a root node', async () => { + await rootNode.dragBy({ x: 80, y: 40 }) + await expect + .poll(() => rootNode.getPosition()) + .not.toEqual(originalPosition) + }) + + await test.step('Undo the movement', async () => { + await comfyPage.keyboard.undo() + await expect + .poll(() => rootNode.getPosition()) + .toEqual(originalPosition) + }) + }) + }) + } }) }) diff --git a/browser_tests/tests/subgraph/subgraphPromotedLabelPersistence.spec.ts b/browser_tests/tests/subgraph/subgraphPromotedLabelPersistence.spec.ts new file mode 100644 index 00000000000..d8c291279bd --- /dev/null +++ b/browser_tests/tests/subgraph/subgraphPromotedLabelPersistence.spec.ts @@ -0,0 +1,75 @@ +import { + comfyExpect as expect, + comfyPageFixture as test +} from '@e2e/fixtures/ComfyPage' + +for (const renderer of [ + { name: 'LiteGraph', tag: ['@slow', '@subgraph', '@ui'] }, + { name: 'Vue', tag: ['@slow', '@subgraph', '@ui', '@vue-nodes'] } +]) { + test.describe( + `${renderer.name} promoted widget labels`, + { tag: renderer.tag }, + () => { + test('clearing a promoted label preserves its value after reopening', async ({ + comfyPage + }) => { + test.slow() + await comfyPage.workflow.setupWorkflowsDirectory({}) + await comfyPage.workflow.loadWorkflow( + 'subgraphs/subgraph-with-text-widget' + ) + const host = await comfyPage.nodeOps.getNodeRefById('11') + await host.expectPromotedWidgetCount(0) + + await test.step('Promote and edit the text widget', async () => { + await comfyPage.subgraph.editor.promoteWidget(host, { + nodeName: 'CLIP Text Encode (Prompt)', + widgetName: 'text' + }) + await host.fillPromotedTextWidget( + 'text', + 'Value must not be cleared with the label' + ) + }) + + const identity = await comfyPage.subgraph.getHostIdentity(host) + + await test.step('Rename and clear the promoted label', async () => { + await host.select() + await comfyPage.menu.propertiesPanel.open() + await comfyPage.menu.propertiesPanel.renameParameterLabel( + 'text', + 'Temporary promoted label' + ) + await comfyPage.menu.propertiesPanel.clearParameterLabel( + 'Temporary promoted label', + 'text' + ) + }) + + const workflowName = `${renderer.name.toLowerCase()}-cleared-promoted-label` + + await test.step('Save and reopen the workflow', async () => { + await comfyPage.workflow.saveWorkflow(workflowName) + await expect(comfyPage.toast.toastErrors).toHaveCount(0) + await comfyPage.workflow.reloadAndOpenPersistedWorkflow(workflowName) + }) + + await test.step('The host keeps its value without a custom label', async () => { + const restored = await comfyPage.nodeOps.getNodeRefById('11') + await comfyPage.subgraph.expectPromotedWidget(restored, 'text', { + ...identity, + label: null, + value: 'Value must not be cleared with the label' + }) + await restored.expectPromotedTextWidgetValue( + 'text', + 'Value must not be cleared with the label' + ) + await expect(comfyPage.toast.toastErrors).toHaveCount(0) + }) + }) + } + ) +} diff --git a/browser_tests/tests/subgraph/subgraphPromotion.spec.ts b/browser_tests/tests/subgraph/subgraphPromotion.spec.ts index 9c629173ce2..ecdaf11f8e7 100644 --- a/browser_tests/tests/subgraph/subgraphPromotion.spec.ts +++ b/browser_tests/tests/subgraph/subgraphPromotion.spec.ts @@ -91,6 +91,8 @@ test.describe( 'Promoted Widget Visibility in Vue Mode', { tag: ['@vue-nodes'] }, () => { + test.use({ initialSettings: { 'Comfy.UseNewMenu': 'Top' } }) + test('Promoted widget connected to the subgraph input is interactive on the host', async ({ comfyPage }) => { @@ -113,14 +115,34 @@ test.describe( test( 'Promoted advanced widget remains visible when global advanced widgets are disabled', - { tag: ['@node'] }, + { tag: ['@node', '@slow'] }, async ({ comfyPage }) => { + const settingId = 'Comfy.Node.AlwaysShowAdvancedWidgets' + const settingName = 'Always show advanced widgets on all nodes' + const parentValue = '2.25' + + test.setTimeout(120_000) + await comfyPage.workflow.setupWorkflowsDirectory({}) + await comfyPage.nodeOps.clearGraph() + await comfyPage.nodeOps.waitForGraphNodes(0) + + await test.step('Verify the named global setting is disabled', async () => { + await comfyPage.settings.setSetting(settingId, false) + await comfyPage.settingDialog.open() + await comfyPage.settingDialog.searchBox.fill(settingName) + const settingRow = comfyPage.settingDialog.root.locator( + `[data-setting-id="${settingId}"]` + ) + await expect(settingRow).toContainText(settingName) + await expect(settingRow.getByRole('switch')).toHaveAttribute( + 'aria-checked', + 'false' + ) + await comfyPage.settingDialog.close() + }) + const subgraphNodeId = await test.step('Convert a node with hidden advanced widgets to a subgraph', async () => { - await comfyPage.settings.setSetting( - 'Comfy.Node.AlwaysShowAdvancedWidgets', - false - ) const modelSamplingNode = await comfyPage.nodeOps.addNode( 'ModelSamplingFlux', {}, @@ -153,18 +175,75 @@ test.describe( await comfyPage.subgraph.exitViaBreadcrumb() }) - await test.step('Keep the promoted widget visible on the host', async () => { + await test.step('Edit the visible promoted widget on the host', async () => { await expectPromotedWidgetNamesToContain( comfyPage, subgraphNodeId, 'max_shift' ) - await expect( - comfyPage.vueNodes - .getNodeLocator(subgraphNodeId) - .getByLabel('max_shift', { exact: true }) - ).toBeVisible() + const promotedWidget = comfyPage.vueNodes + .getNodeLocator(subgraphNodeId) + .getByLabel('max_shift', { exact: true }) + await expect(promotedWidget).toBeVisible() + const promotedInput = promotedWidget.getByRole('spinbutton') + await promotedInput.fill(parentValue) + await promotedInput.press('Tab') + await expect(promotedInput).toHaveValue(parentValue) + }) + + const host = await comfyPage.nodeOps.getNodeRefById(subgraphNodeId) + const identity = await comfyPage.subgraph.getHostIdentity(host) + await comfyPage.subgraph.expectPromotedWidget(host, 'max_shift', { + ...identity, + label: 'max_shift', + value: Number(parentValue) }) + + const workflowName = `vue-advanced-promoted-host-value-${Date.now()}` + await comfyPage.workflow.saveWorkflow(workflowName) + await comfyPage.workflow.reloadAndOpenPersistedWorkflow( + workflowName + ) + + const restored = + await comfyPage.nodeOps.getNodeRefById(subgraphNodeId) + await comfyPage.subgraph.expectPromotedWidget( + restored, + 'max_shift', + { + ...identity, + label: 'max_shift', + value: Number(parentValue) + } + ) + + await comfyPage.menu.topbar.setVueNodesEnabled(false) + await fitToViewInstant(comfyPage, { zoom: 1 }) + const liteGraphWidget = await restored.getWidgetByName('max_shift') + expect(await liteGraphWidget.getValue()).toBe(Number(parentValue)) + await liteGraphWidget.click() + await comfyPage.nodeOps.fillLegacyWidgetDialog('2.5') + expect(await liteGraphWidget.getValue()).toBe(2.5) + + const saveResponse = comfyPage.page.waitForResponse( + (response) => + response.request().method() === 'POST' && + new URL(response.url()).pathname.includes( + encodeURIComponent(`workflows/${workflowName}.json`) + ) + ) + await comfyPage.menu.topbar.triggerTopbarCommand(['File', 'Save']) + expect((await saveResponse).status()).toBe(200) + await comfyPage.workflow.reloadAndOpenPersistedWorkflow( + workflowName + ) + const legacyRestored = + await comfyPage.nodeOps.getNodeRefById(subgraphNodeId) + expect( + await ( + await legacyRestored.getWidgetByName('max_shift') + ).getValue() + ).toBe(2.5) } ) diff --git a/src/lib/litegraph/src/subgraph/SubgraphDuplicateDeleteOrder.test.ts b/src/lib/litegraph/src/subgraph/SubgraphDuplicateDeleteOrder.test.ts index febae673688..ef9c6622048 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphDuplicateDeleteOrder.test.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphDuplicateDeleteOrder.test.ts @@ -5,12 +5,12 @@ import type { LGraph, LLink, Reroute, - Subgraph, - SubgraphNode + Subgraph } from '@/lib/litegraph/src/litegraph' import { LGraphNode as LGraphNodeClass, - LiteGraph + LiteGraph, + SubgraphNode } from '@/lib/litegraph/src/litegraph' import { createTestNode } from '@/lib/litegraph/src/__fixtures__/nodeHelpers' import { useWidgetValueStore } from '@/stores/widgetValueStore' @@ -167,16 +167,12 @@ function expectSurvivorUndamaged( const survivor = scenario.instances[survivorIndex] const survivorLink = scenario.links[survivorIndex] const survivorReroute = scenario.reroutes[survivorIndex] - const survivorValue = promotedValueOf(survivor) - const survivorWidgetId = survivor.inputs.find( - (input) => input.name === PROMOTED_INPUT - )?.widgetId + const survivorValue = [111, 222][survivorIndex] + const survivorWidgetId = promotedId(survivor) rootGraph.remove(removed) - expect(survivorWidgetId).not.toBe( - removed.inputs.find((input) => input.name === PROMOTED_INPUT)?.widgetId - ) + expect(survivorWidgetId).not.toBe(promotedId(removed)) expect(promotedValueOf(survivor)).toBe(survivorValue) const liveLink = rootGraph.links.get(survivorLink.id) @@ -189,6 +185,23 @@ function expectSurvivorUndamaged( expect(rootGraph.subgraphs.get(definition.id)).toBe(definition) + const serializedSurvivor = survivor.serialize() + useWidgetValueStore().clearNode(rootGraph.id, survivor.id) + const reloadedSurvivor = new SubgraphNode( + rootGraph, + definition, + serializedSurvivor + ) + reloadedSurvivor.configure(serializedSurvivor) + + expect(promotedValueOf(reloadedSurvivor)).toBe(survivorValue) + const reloadedWidgetId = promotedId(reloadedSurvivor) + if (!reloadedWidgetId) + throw new Error('expected a reloaded promoted widget id') + expect(useWidgetValueStore().setValue(reloadedWidgetId, 333)).toBe(true) + expect(promotedValueOf(reloadedSurvivor)).toBe(333) + expect(reloadedSurvivor.serialize().widgets_values).toEqual([333]) + rootGraph.remove(survivor) expect(rootGraph.subgraphs.has(definition.id)).toBe(false) }