Files
ComfyUI_frontend/browser_tests/helpers/subgraphTestUtils.ts
Arthur R Longbottom 0fa937205c [backport cloud/1.41] fix: subgraph promoted widget input label rename (#10422)
Backport of #10195 to cloud/1.41.

Cherry-picked from the core/1.41 backport commit with the same test fix:
`renameWidget` test passes `parents` explicitly since 1.41 uses
`parents?.length` (not `node.isSubgraphNode()` fallback). Includes
negative test for subgraph node without parents.

All 14 unit tests pass locally.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-10422-backport-cloud-1-41-fix-subgraph-promoted-widget-input-label-rename-32d6d73d36508133bdd1d37ebd2e542e)
by [Unito](https://www.unito.io)

Co-authored-by: Alexander Brown <drjkl@comfy.org>
2026-03-24 17:23:20 -07:00

46 lines
1.4 KiB
TypeScript

import type { Page } from '@playwright/test'
import type { LGraph, Subgraph } from '../../src/lib/litegraph/src/litegraph'
import { isSubgraph } from '../../src/utils/typeGuardUtil'
/**
* Assertion helper for tests where being in a subgraph is a precondition.
* Throws a clear error if the graph is not a Subgraph.
*/
export function assertSubgraph(
graph: LGraph | Subgraph | null | undefined
): asserts graph is Subgraph {
if (!isSubgraph(graph)) {
throw new Error(
'Expected to be in a subgraph context, but graph is not a Subgraph'
)
}
}
/**
* Returns the widget-input slot Y position and the node title height
* for the promoted "text" input on the SubgraphNode.
*
* The slot Y should be at the widget row, not the header. A value near
* zero or negative indicates the slot is positioned at the header (the bug).
*/
export function getTextSlotPosition(page: Page, nodeId: string) {
return page.evaluate((id) => {
const node = window.app!.canvas.graph!.getNodeById(id)
if (!node) return null
const titleHeight = window.LiteGraph!.NODE_TITLE_HEIGHT
for (const input of node.inputs) {
if (!input.widget || input.type !== 'STRING') continue
return {
hasPos: !!input.pos,
posY: input.pos?.[1] ?? null,
widgetName: input.widget.name,
titleHeight
}
}
return null
}, nodeId)
}