From c3ea363e79e3309038949a0e80835ab029d2b9c5 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sat, 26 Sep 2026 07:07:59 +0000 Subject: [PATCH] test: add ECS feature sanity coverage (#17459) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds e2e coverage for four ECS migration behaviours, in both the Vue and legacy renderers: - **Node source badge Settings transitions** (`nodeSourceBadgeMode.spec.ts`). Drives the real Settings control through Show all, Hide built-in, None, Show all again, with no reload. Core `PreviewImage` and custom `DevToolsErrorRaiseNode` are expected to differ under Hide built-in. Vue asserts on visible badges; legacy observes actual `drawBadges`/`fillText` calls and waits for a completed frame. - **API pricing badge toggle** (`apiPricingBadge.spec.ts`). - **Link disconnect/reconnect at emulated DPR 1.5** (`links/deviceScaleFactor.spec.ts`). Exact endpoints and output-link count. - **Marquee selection at emulated DPR 1.5** (`selection/deviceScaleFactor.spec.ts`). Exact two-node selection. Both scaling tests use Playwright's emulated `deviceScaleFactor`, not physical display scaling or browser zoom. Physical display validation stays manual. Supporting fixtures: `LegacyNodeBadgeHelper` (legacy badge probe), `SettingDialog.selectSetting`. [QA plan](https://app.notion.com/p/comfy-org/3c56d73d365081629481ea0f1d09fc65) ยท [Migration](https://github.com/Comfy-Org/ComfyUI_frontend/pull/14246)
Rebase note, 2026-09-25 The branch had drifted 634 commits behind `main` and was red on `typecheck-aux`, `repo-checks`, `fallow` and `lint`. Rebased clean (no conflicts, diff unchanged at 551 lines across 7 files) and fixed the fallout in `e8ae9041a0`: - `Settings` moved out of `@/schemas/apiSchema`. The unresolved import was the single cause of the typecheck, knip and fallow failures. - `SettingDialog` already imports `comfyExpect as expect`; the added `@playwright/test` `expect` was a duplicate identifier. - `vueNodes.waitForNodes()` no longer takes a count. - `comfy(prefer-initial-settings)` landed after this branch was cut. Startup settings moved to `test.use({ initialSettings })`, and the settings-only `afterEach` teardown was removed: `comfyPageFixture` reseeds settings before each test, so the restores were dead code. That supersedes three earlier commits on this branch that added those restores in response to review. Dropping them also removes describe-scope mutable state shared across the renderer loop. Earlier body text referenced pre-rebase commit SHAs and out-of-scope claims (body zoom, API serialization, locale layout, download/re-import, Browse Templates undo, missing-model dialogs). None of that is in this PR; removed so it does not read as a spec.
--------- Co-authored-by: Amp --- .../fixtures/components/SettingDialog.ts | 9 ++ .../fixtures/helpers/LegacyNodeBadgeHelper.ts | 93 +++++++++++++ .../fixtures/legacyNodeBadgeFixture.ts | 15 ++ .../tests/links/deviceScaleFactor.spec.ts | 74 ++++++++++ .../tests/selection/deviceScaleFactor.spec.ts | 88 ++++++++++++ .../tests/widgets/apiPricingBadge.spec.ts | 85 ++++++++++++ .../tests/widgets/nodeSourceBadgeMode.spec.ts | 131 ++++++++++++++++++ 7 files changed, 495 insertions(+) create mode 100644 browser_tests/fixtures/helpers/LegacyNodeBadgeHelper.ts create mode 100644 browser_tests/fixtures/legacyNodeBadgeFixture.ts create mode 100644 browser_tests/tests/links/deviceScaleFactor.spec.ts create mode 100644 browser_tests/tests/selection/deviceScaleFactor.spec.ts create mode 100644 browser_tests/tests/widgets/apiPricingBadge.spec.ts create mode 100644 browser_tests/tests/widgets/nodeSourceBadgeMode.spec.ts diff --git a/browser_tests/fixtures/components/SettingDialog.ts b/browser_tests/fixtures/components/SettingDialog.ts index 3d466e1cceb..a6ace1474cc 100644 --- a/browser_tests/fixtures/components/SettingDialog.ts +++ b/browser_tests/fixtures/components/SettingDialog.ts @@ -42,6 +42,15 @@ export class SettingDialog extends BaseDialog { await this.root.locator(`button[role="switch"][id="${id}"]`).click() } + async selectSetting(id: string, value: string) { + await this.root + .locator(`[data-setting-id="${id}"]`) + .getByRole('combobox') + .click() + await this.page.getByRole('option', { name: value, exact: true }).click() + await expect.poll(() => this.comfyPage.settings.getSetting(id)).toBe(value) + } + category(name: string) { return this.root.locator('nav').getByRole('button', { name }) } diff --git a/browser_tests/fixtures/helpers/LegacyNodeBadgeHelper.ts b/browser_tests/fixtures/helpers/LegacyNodeBadgeHelper.ts new file mode 100644 index 00000000000..0fc3f845324 --- /dev/null +++ b/browser_tests/fixtures/helpers/LegacyNodeBadgeHelper.ts @@ -0,0 +1,93 @@ +import { expect } from '@playwright/test' +import type { Locator, Page } from '@playwright/test' + +type BadgeTarget = + | { key: string; title: string; type?: never } + | { key: string; title?: never; type: string } + +export class LegacyNodeBadgeHelper { + private readonly probe: Locator + + constructor(private readonly page: Page) { + this.probe = page.locator('#legacy-node-badge-draw-probe') + } + + async install(targets: readonly BadgeTarget[]) { + await this.page.evaluate((targets) => { + const probe = document.createElement('output') + probe.id = 'legacy-node-badge-draw-probe' + probe.hidden = true + probe.dataset.frames = '0' + document.body.append(probe) + + for (const target of targets) { + const node = window.app!.graph.nodes.find((node) => + target.title ? node.title === target.title : node.type === target.type + ) + if (!node) throw new Error(`Badge node not found: ${target.key}`) + + const drawBadges = node.drawBadges + node.drawBadges = function (ctx, options) { + const texts: string[] = [] + const fillText = ctx.fillText + ctx.fillText = function (text, ...args) { + fillText.call(this, text, ...args) + texts.push(text) + } + try { + drawBadges.call(this, ctx, options) + probe.setAttribute( + `data-${target.key}-texts`, + JSON.stringify(texts) + ) + probe.dataset.frames = String(Number(probe.dataset.frames) + 1) + } finally { + ctx.fillText = fillText + } + } + } + window.app!.graph.setDirtyCanvas(true, true) + }, targets) + } + + async redraw() { + const frame = Number(await this.probe.getAttribute('data-frames')) + await this.page.evaluate(() => window.app!.graph.setDirtyCanvas(true, true)) + await expect + .poll(async () => Number(await this.probe.getAttribute('data-frames'))) + .toBeGreaterThan(frame) + } + + async expectText(key: string, text: string, visible: boolean) { + const getTexts = async () => { + const serialized = await this.probe.getAttribute(`data-${key}-texts`) + // No frame has redrawn this node since install(). Return a value that + // matches neither `true` nor `false` so the poll keeps waiting: a probe + // that never draws must time out, not silently satisfy `visible: false`. + if (serialized === null) return null + const parsed: unknown = JSON.parse(serialized) + if ( + !Array.isArray(parsed) || + !parsed.every((value): value is string => typeof value === 'string') + ) { + throw new Error(`Invalid legacy badge probe value: ${key}`) + } + return parsed.some((value) => value.includes(text)) + } + + await expect.poll(getTexts).toBe(visible) + } + + async expectState( + expectations: readonly { key: string; text: string; visible: boolean }[] + ) { + await this.redraw() + for (const expectation of expectations) { + await this.expectText( + expectation.key, + expectation.text, + expectation.visible + ) + } + } +} diff --git a/browser_tests/fixtures/legacyNodeBadgeFixture.ts b/browser_tests/fixtures/legacyNodeBadgeFixture.ts new file mode 100644 index 00000000000..cc1d2225657 --- /dev/null +++ b/browser_tests/fixtures/legacyNodeBadgeFixture.ts @@ -0,0 +1,15 @@ +import { mergeTests } from '@playwright/test' +import { networkIsolationFixture as base } from '@e2e/fixtures/networkIsolationFixture' + +import { comfyPageFixture } from '@e2e/fixtures/ComfyPage' +import { LegacyNodeBadgeHelper } from '@e2e/fixtures/helpers/LegacyNodeBadgeHelper' + +const legacyNodeBadgeFixture = base.extend<{ + legacyNodeBadges: LegacyNodeBadgeHelper +}>({ + legacyNodeBadges: async ({ page }, use) => { + await use(new LegacyNodeBadgeHelper(page)) + } +}) + +export const test = mergeTests(comfyPageFixture, legacyNodeBadgeFixture) diff --git a/browser_tests/tests/links/deviceScaleFactor.spec.ts b/browser_tests/tests/links/deviceScaleFactor.spec.ts new file mode 100644 index 00000000000..3a4e1833351 --- /dev/null +++ b/browser_tests/tests/links/deviceScaleFactor.spec.ts @@ -0,0 +1,74 @@ +import { expect } from '@playwright/test' + +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' +import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' + +test.use({ + deviceScaleFactor: 1.5, + initialSettings: { 'Comfy.LinkRelease.Action': 'no action' } +}) + +test.describe('Link interaction at emulated display scaling', () => { + test( + 'disconnects and reconnects the exact endpoint at 150 percent in the legacy renderer', + { tag: '@canvas' }, + async ({ comfyPage }) => { + test.slow() + await expectExactEndpointRoundTrip(comfyPage) + } + ) + + test( + 'disconnects and reconnects the exact endpoint at 150 percent in the Vue renderer', + { tag: ['@canvas', '@vue-nodes'] }, + async ({ comfyPage }) => { + test.slow() + await expectExactEndpointRoundTrip(comfyPage) + } + ) +}) + +async function expectExactEndpointRoundTrip(comfyPage: ComfyPage) { + await comfyPage.workflow.loadWorkflow('default') + expect(await comfyPage.page.evaluate(() => window.devicePixelRatio)).toBe(1.5) + + const checkpoint = await comfyPage.nodeOps.getNodeRefById(4) + const prompt = await comfyPage.nodeOps.getNodeRefById(6) + const output = await checkpoint.getOutput(1) + const input = await prompt.getInput(0) + + await test.step('disconnect the prompt input', async () => { + await comfyPage.canvasOps.dragAndDrop(await input.getPosition(), { + x: 800, + y: 100 + }) + await input.expectLinkCount(0) + }) + + await test.step('reconnect the exact endpoint', async () => { + await comfyPage.canvasOps.dragAndDrop( + await output.getPosition(), + await input.getPosition() + ) + // Node ids serialise as strings, so normalise before comparing rather + // than asserting on the current runtime type. + await expect + .poll(async () => { + const link = await input.getLink() + if (!link) return null + return { + origin_id: String(link.origin_id), + origin_slot: link.origin_slot, + target_id: String(link.target_id), + target_slot: link.target_slot + } + }) + .toEqual({ + origin_id: '4', + origin_slot: 1, + target_id: '6', + target_slot: 0 + }) + await output.expectLinkCount(2) + }) +} diff --git a/browser_tests/tests/selection/deviceScaleFactor.spec.ts b/browser_tests/tests/selection/deviceScaleFactor.spec.ts new file mode 100644 index 00000000000..a45aab6ff6b --- /dev/null +++ b/browser_tests/tests/selection/deviceScaleFactor.spec.ts @@ -0,0 +1,88 @@ +import { expect } from '@playwright/test' + +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' +import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage' + +test.use({ + deviceScaleFactor: 1.5, + initialSettings: { 'Comfy.Canvas.LeftMouseClickBehavior': 'select' } +}) + +test.describe('Marquee selection at emulated display scaling', () => { + test( + 'tracks the cursor and selects the exact intersected nodes at 150 percent in the legacy renderer', + { tag: '@canvas' }, + async ({ comfyPage }) => { + test.slow() + await expectExactMarqueeSelection(comfyPage) + } + ) + + test( + 'tracks the cursor and selects the exact intersected nodes at 150 percent in the Vue renderer', + { tag: ['@canvas', '@vue-nodes'] }, + async ({ comfyPage }) => { + test.slow() + await expectExactMarqueeSelection(comfyPage) + } + ) +}) + +async function expectExactMarqueeSelection(comfyPage: ComfyPage) { + await comfyPage.workflow.loadWorkflow('default') + expect(await comfyPage.page.evaluate(() => window.devicePixelRatio)).toBe(1.5) + + const bounds = await comfyPage.page.evaluate(() => { + const nodes = window.app!.graph.nodes.filter((node) => + ['6', '7'].includes(String(node.id)) + ) + const positions = nodes.map((node) => node.pos) + return { + start: window.app!.canvasPosToClientPos([ + Math.min(...positions.map(([x]) => x)) - 64, + Math.min(...positions.map(([, y]) => y)) - 64 + ]), + end: window.app!.canvasPosToClientPos([ + Math.max(...positions.map(([x]) => x)) + 64, + Math.max(...positions.map(([, y]) => y)) + 64 + ]) + } + }) + const clientPosition = ([x, y]: number[]) => ({ x, y }) + const start = clientPosition(bounds.start) + const end = clientPosition(bounds.end) + + await test.step('track the marquee in client coordinates', async () => { + await comfyPage.page.mouse.move(start.x, start.y) + await comfyPage.page.mouse.down() + await comfyPage.page.mouse.move(end.x, end.y, { steps: 10 }) + await comfyPage.nextFrame() + const rectangle = await comfyPage.page.evaluate(() => { + const rectangle = window.app!.canvas.dragging_rectangle + if (!rectangle) return null + const start = window.app!.canvasPosToClientPos([ + rectangle[0], + rectangle[1] + ]) + const end = window.app!.canvasPosToClientPos([ + rectangle[0] + rectangle[2], + rectangle[1] + rectangle[3] + ]) + return { start, end } + }) + + await comfyPage.page.mouse.up() + expect(rectangle).toEqual({ + start: [expect.closeTo(start.x, 0), expect.closeTo(start.y, 0)], + end: [expect.closeTo(end.x, 0), expect.closeTo(end.y, 0)] + }) + }) + + await test.step('select exactly the intersected nodes', async () => { + await expect + .poll(async () => + (await comfyPage.nodeOps.getSelectedNodeIds()).map(String).sort() + ) + .toEqual(['6', '7']) + }) +} diff --git a/browser_tests/tests/widgets/apiPricingBadge.spec.ts b/browser_tests/tests/widgets/apiPricingBadge.spec.ts new file mode 100644 index 00000000000..b5339082476 --- /dev/null +++ b/browser_tests/tests/widgets/apiPricingBadge.spec.ts @@ -0,0 +1,85 @@ +import { expect } from '@playwright/test' + +import type { ComfyPage } from '@e2e/fixtures/ComfyPage' +import { test } from '@e2e/fixtures/legacyNodeBadgeFixture' + +const API_NODE_TITLE = 'Flux 1.1 [pro] Ultra Image' +const PRICE_TEXT = '12.7 credits/Run' + +test.use({ initialSettings: { 'Comfy.NodeBadge.ShowApiPricing': true } }) + +test.beforeEach(async ({ context }) => { + await context.route( + 'https://comfyanonymous.github.io/ComfyUI_examples/', + (route) => + route.fulfill({ contentType: 'text/html', body: '' }) + ) +}) + +test.describe( + 'API node pricing badge (Vue)', + { tag: ['@node', '@widget', '@vue-nodes'] }, + () => { + test('follows the Settings UI toggle', async ({ comfyPage }) => { + await comfyPage.workflow.loadWorkflow('partner_api_node') + const vueNode = await comfyPage.vueNodes.getFixtureByTitle(API_NODE_TITLE) + + await test.step('show pricing initially', async () => { + await expect(vueNode.priceBadge.required).toBeVisible() + }) + + await test.step('hide pricing through Settings', async () => { + await toggleApiPricing(comfyPage) + await expect(vueNode.priceBadge.required).toBeHidden() + }) + + await test.step('restore pricing through Settings', async () => { + await toggleApiPricing(comfyPage) + await expect(vueNode.priceBadge.required).toBeVisible() + }) + }) + } +) + +test.describe( + 'API node pricing badge (legacy)', + { tag: ['@node', '@widget'] }, + () => { + test('follows the Settings UI toggle', async ({ + comfyPage, + legacyNodeBadges + }) => { + await comfyPage.workflow.loadWorkflow('partner_api_node') + await legacyNodeBadges.install([{ key: 'price', title: API_NODE_TITLE }]) + + await test.step('show pricing initially', async () => { + await legacyNodeBadges.expectState([ + { key: 'price', text: PRICE_TEXT, visible: true } + ]) + }) + + await test.step('hide pricing through Settings', async () => { + await toggleApiPricing(comfyPage) + await legacyNodeBadges.expectState([ + { key: 'price', text: PRICE_TEXT, visible: false } + ]) + }) + + await test.step('restore pricing through Settings', async () => { + await toggleApiPricing(comfyPage) + await legacyNodeBadges.expectState([ + { key: 'price', text: PRICE_TEXT, visible: true } + ]) + }) + }) + } +) + +async function toggleApiPricing(comfyPage: ComfyPage) { + await comfyPage.settingDialog.open() + await comfyPage.settingDialog.category('Comfy').click() + await comfyPage.settingDialog.toggleBooleanSetting( + 'Comfy.NodeBadge.ShowApiPricing' + ) + await comfyPage.settingDialog.close() +} diff --git a/browser_tests/tests/widgets/nodeSourceBadgeMode.spec.ts b/browser_tests/tests/widgets/nodeSourceBadgeMode.spec.ts new file mode 100644 index 00000000000..ac64acf26a2 --- /dev/null +++ b/browser_tests/tests/widgets/nodeSourceBadgeMode.spec.ts @@ -0,0 +1,131 @@ +import { expect } from '@playwright/test' + +import { NodeBadgeMode } from '@/types/nodeSource' +import { test } from '@e2e/fixtures/legacyNodeBadgeFixture' + +const CORE_NODE_TITLE = 'Preview Image' +const CUSTOM_NODE_TITLE = 'Raise Error' +const CORE_BADGE_TEXT = 'nodes' +const CUSTOM_BADGE_TEXT = 'devtools' + +test.use({ + initialSettings: { + 'Comfy.NodeBadge.NodeSourceBadgeMode': NodeBadgeMode.ShowAll + } +}) + +test.describe( + 'Node source badge Settings transitions (Vue)', + { tag: ['@node', '@widget', '@vue-nodes'] }, + () => { + test('updates core and custom-node badges immediately without reload', async ({ + comfyPage + }) => { + await comfyPage.workflow.loadWorkflow('nodes/execution_error') + + const coreNode = + await comfyPage.vueNodes.getFixtureByTitle(CORE_NODE_TITLE) + const customNode = + await comfyPage.vueNodes.getFixtureByTitle(CUSTOM_NODE_TITLE) + const coreBadge = coreNode.root.getByTestId('comfy-badge') + const customBadge = customNode.root.getByText(CUSTOM_BADGE_TEXT, { + exact: true + }) + + await test.step('show all source badges initially', async () => { + await expect(coreBadge).toBeVisible() + await expect(customBadge).toBeVisible() + }) + + await comfyPage.settingDialog.open() + await comfyPage.settingDialog.category('Lite Graph').click() + + await test.step('hide built-in source badges', async () => { + await comfyPage.settingDialog.selectSetting( + 'Comfy.NodeBadge.NodeSourceBadgeMode', + NodeBadgeMode.HideBuiltIn + ) + await expect(coreBadge).toBeHidden() + await expect(customBadge).toBeVisible() + }) + + await test.step('hide all source badges', async () => { + await comfyPage.settingDialog.selectSetting( + 'Comfy.NodeBadge.NodeSourceBadgeMode', + NodeBadgeMode.None + ) + await expect(coreBadge).toBeHidden() + await expect(customBadge).toBeHidden() + }) + + await test.step('restore all source badges', async () => { + await comfyPage.settingDialog.selectSetting( + 'Comfy.NodeBadge.NodeSourceBadgeMode', + NodeBadgeMode.ShowAll + ) + await expect(coreBadge).toBeVisible() + await expect(customBadge).toBeVisible() + }) + }) + } +) + +test.describe( + 'Node source badge Settings transitions (legacy)', + { tag: ['@node', '@widget'] }, + () => { + test('updates core and custom-node badges immediately without reload', async ({ + comfyPage, + legacyNodeBadges + }) => { + await comfyPage.workflow.loadWorkflow('nodes/execution_error') + await legacyNodeBadges.install([ + { key: 'core', type: 'PreviewImage' }, + { key: 'custom', type: 'DevToolsErrorRaiseNode' } + ]) + + await test.step('show all source badges initially', async () => { + await legacyNodeBadges.expectState([ + { key: 'core', text: CORE_BADGE_TEXT, visible: true }, + { key: 'custom', text: CUSTOM_BADGE_TEXT, visible: true } + ]) + }) + + await comfyPage.settingDialog.open() + await comfyPage.settingDialog.category('Lite Graph').click() + + await test.step('hide built-in source badges', async () => { + await comfyPage.settingDialog.selectSetting( + 'Comfy.NodeBadge.NodeSourceBadgeMode', + NodeBadgeMode.HideBuiltIn + ) + await legacyNodeBadges.expectState([ + { key: 'core', text: CORE_BADGE_TEXT, visible: false }, + { key: 'custom', text: CUSTOM_BADGE_TEXT, visible: true } + ]) + }) + + await test.step('hide all source badges', async () => { + await comfyPage.settingDialog.selectSetting( + 'Comfy.NodeBadge.NodeSourceBadgeMode', + NodeBadgeMode.None + ) + await legacyNodeBadges.expectState([ + { key: 'core', text: CORE_BADGE_TEXT, visible: false }, + { key: 'custom', text: CUSTOM_BADGE_TEXT, visible: false } + ]) + }) + + await test.step('restore all source badges', async () => { + await comfyPage.settingDialog.selectSetting( + 'Comfy.NodeBadge.NodeSourceBadgeMode', + NodeBadgeMode.ShowAll + ) + await legacyNodeBadges.expectState([ + { key: 'core', text: CORE_BADGE_TEXT, visible: true }, + { key: 'custom', text: CUSTOM_BADGE_TEXT, visible: true } + ]) + }) + }) + } +)