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
6 changes: 6 additions & 0 deletions browser_tests/fixtures/data/byteDanceReferenceNodeDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export const BYTEDANCE_REFERENCE_NODE_TYPE = 'ByteDance2ReferenceNode'

export const REFERENCE_IMAGES_PREFIX = 'model.reference_images.'

/** The workflow fixture that exercises this node's autogrow input group. */
export const AUTOGROW_REFERENCE_WORKFLOW = 'subgraphs/autogrow-reference-images'

/** Id of the reference node inside `AUTOGROW_REFERENCE_WORKFLOW`. */
export const AUTOGROW_REFERENCE_NODE_ID = '26'

function ordinalNames(prefix: string, count: number): string[] {
return Array.from({ length: count }, (_, index) => `${prefix}_${index + 1}`)
}
Expand Down
42 changes: 41 additions & 1 deletion browser_tests/fixtures/utils/nodeInputLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { toNodeId } from '@/types/nodeId'

import type { ComfyPage } from '@e2e/fixtures/ComfyPage'

interface ConnectedInput {
/** A connected input slot, paired with the node its link originates from. */
export interface ConnectedInput {
name: string
originNodeId: string
}
Expand Down Expand Up @@ -55,3 +56,42 @@ export async function getConnectedInputs(
{ nodeId: toNodeId(nodeId), namePrefix }
)
}

export interface AutogrowInputGroup {
/** Slot names in the group, in order, including the empty trailing slot. */
slotNames: string[]
/** Connected slots, in order, with the node each link originates from. */
connections: ConnectedInput[]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/**
* Index of the empty trailing slot autogrow maintains, which is also the
* count of connected slots.
*/
trailingSlotIndex: number
}

/**
* The current state of an autogrow input group, read from the graph.
*
* Exists so a test can describe what it is exercising - "fill the trailing
* slot, expect one more" - instead of hard-coding the workflow fixture's
* contents. A spec that restates those contents breaks the next time the
* fixture gains a link, and the failure looks like a product regression rather
* than a stale expectation. That is not hypothetical: it is how
* `autogrowInputPersistence.spec.ts` came to assert two links against a fixture
* that had grown to three.
*/
export async function readAutogrowInputGroup(
comfyPage: ComfyPage,
nodeId: string,
namePrefix: string
): Promise<AutogrowInputGroup> {
const [slotNames, connections] = await Promise.all([
getInputNames(comfyPage, nodeId, namePrefix),
getConnectedInputs(comfyPage, nodeId, namePrefix)
])
return {
slotNames,
connections,
trailingSlotIndex: connections.length
}
}
107 changes: 107 additions & 0 deletions browser_tests/tests/links/autogrowInputPersistence.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {
comfyExpect as expect,
comfyPageFixture as baseTest
} from '@e2e/fixtures/ComfyPage'
import {
AUTOGROW_REFERENCE_NODE_ID,
AUTOGROW_REFERENCE_WORKFLOW,
BYTEDANCE_REFERENCE_NODE_TYPE,
REFERENCE_IMAGES_PREFIX,
byteDanceReferenceNodeDef
} from '@e2e/fixtures/data/byteDanceReferenceNodeDef'
import { readAutogrowInputGroup } from '@e2e/fixtures/utils/nodeInputLinks'
import { routeObjectInfoFromSetupApi } from '@e2e/fixtures/utils/objectInfo'

const test = baseTest.extend({
page: async ({ page }, use) => {
const unrouteObjectInfo = await routeObjectInfoFromSetupApi(
page,
(objectInfo) => {
objectInfo[BYTEDANCE_REFERENCE_NODE_TYPE] = byteDanceReferenceNodeDef
}
)
try {
await use(page)
} finally {
await unrouteObjectInfo()
}
}
})

test.describe(
'Autogrow input persistence',
{ tag: ['@canvas', '@node'] },
() => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.workflow.loadWorkflow(AUTOGROW_REFERENCE_WORKFLOW)
})

test('grown slots and their links survive a serialize round-trip', async ({
comfyPage
}) => {
// Read the starting state instead of restating it. The workflow is shared
// with the subgraph-unpack tests and has already gained a link once; a
// spec that hard-codes its contents fails the next time that happens, and
// the failure reads as a product regression rather than a stale
// expectation.
const before = await readAutogrowInputGroup(
comfyPage,
AUTOGROW_REFERENCE_NODE_ID,
REFERENCE_IMAGES_PREFIX
)

// The invariant under test, stated as one: autogrow keeps exactly one
// empty slot after the connected ones.
expect(before.connections.length).toBeGreaterThan(0)
expect(before.slotNames).toHaveLength(before.connections.length + 1)

const loadImage = await comfyPage.nodeOps.getNodeRefById('18')
const referenceNode = await comfyPage.nodeOps.getNodeRefById(
AUTOGROW_REFERENCE_NODE_ID
)
await loadImage.connectOutput(0, referenceNode, before.trailingSlotIndex)

const grownConnections = [
...before.connections,
{
name: before.slotNames[before.trailingSlotIndex],
originNodeId: '18'
}
]
const grownSlotCount = before.slotNames.length + 1

await expect
.poll(async () => {
const grown = await readAutogrowInputGroup(
comfyPage,
AUTOGROW_REFERENCE_NODE_ID,
REFERENCE_IMAGES_PREFIX
)
return {
connections: grown.connections,
slotCount: grown.slotNames.length
}
})
.toEqual({
connections: grownConnections,
slotCount: grownSlotCount
})

const serialized = await comfyPage.workflow.getExportedWorkflow()
await comfyPage.workflow.loadGraphData(serialized)

// The point of the test: the grown slot and its link are still there
// after a round trip, and the group still ends in exactly one empty slot.
const after = await readAutogrowInputGroup(
comfyPage,
AUTOGROW_REFERENCE_NODE_ID,
REFERENCE_IMAGES_PREFIX
)
expect(after.connections).toEqual(grownConnections)
expect(after.slotNames).toHaveLength(grownSlotCount)
expect(after.slotNames.slice(0, before.slotNames.length)).toEqual(
before.slotNames
)
})
}
)
Loading