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
35 changes: 35 additions & 0 deletions src/components/node/NodePreviewCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { ComfyNodeDefImpl } from '@/core/graph/nodeDef/ComfyNodeDefImpl'

import NodePreviewCard from './NodePreviewCard.vue'

vi.mock(import('@/platform/distribution/types'), () => ({
DISTRIBUTION: 'cloud' as const,
isCloud: true,
isDesktop: false,
isNightly: false
}))

vi.mock<unknown>(
import('@/renderer/extensions/vueNodes/components/LGraphNodePreview.vue'),

Expand Down Expand Up @@ -88,6 +95,34 @@ describe('NodePreviewCard', () => {
expect(screen.getByText('sync_mode')).toBeInTheDocument()
})

it('renders blueprint boundary inputs on Cloud without dynamic templates', () => {
const nodeDef = new ComfyNodeDefImpl(
{
name: 'SubgraphBlueprint.boundaries',
display_name: 'Blueprint boundaries',
category: 'Subgraph Blueprints',
python_module: 'blueprint',
description: '',
input: {
required: {
autogrow: ['COMFY_AUTOGROW_V3', undefined],
group: ['COMFY_DYNAMICGROUP_V3', undefined],
match: ['COMFY_MATCHTYPE_V3', undefined]
}
},
output: [],
output_node: false
},
{ validateInputs: true }
)

renderComponent(nodeDef)

expect(screen.getByText('autogrow')).toBeInTheDocument()
expect(screen.getByText('group')).toBeInTheDocument()
expect(screen.getByText('match')).toBeInTheDocument()
})

it('renders no inputs section when the node has no inputs', () => {
const nodeDefImpl = new ComfyNodeDefImpl({
name: 'NoInputsNode',
Expand Down
2 changes: 1 addition & 1 deletion src/core/graph/nodeDef/inputSpecInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ export const {
dynamicComboOptionTypes,
flattenInputSpecs,
collectSearchableOutputTypes
} = inputSpecInterpreter
} = validatedInputSpecInterpreter
45 changes: 43 additions & 2 deletions src/stores/subgraphStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createTestSubgraphNode
} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers'
import { useToast } from '@/components/ui/toast/toastStore'
import { reportError } from '@comfyorg/telemetry/reportError'
import type { ExportedSubgraph } from '@comfyorg/graph-model/serialisation'
import { TemplateIncludeOnDistributionEnum } from '@comfyorg/api-client/templateTypes'
import type { ComfyNodeDef as ComfyNodeDefV1 } from '@comfyorg/object-info-parser'
Expand Down Expand Up @@ -123,11 +124,16 @@ describe('useSubgraphStore', () => {
{ confirmed: true, storeCalls: 1 },
{ confirmed: false, storeCalls: 0 }
])(
'should publish over an existing blueprint only when overwrite is confirmed (confirmed: $confirmed)',
'requires confirmation before replacing an unloaded blueprint (confirmed: $confirmed)',
async ({ confirmed, storeCalls }) => {
selectSubgraphNodeToPublish()
vi.mocked(useDialogService().confirm).mockResolvedValue(confirmed)
await mockFetch({ 'testname.json': mockGraph })
vi.mocked(api.listUserDataFullInfo).mockResolvedValue([
{ path: 'testname.json', modified: 1, size: 1 }
])
vi.mocked(api.getUserData).mockImplementation(async () =>
Response.json(mockGraph)
)
await store.publishSubgraph()
expect(useDialogService().confirm).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -138,6 +144,41 @@ describe('useSubgraphStore', () => {
expect(api.storeUserData).toHaveBeenCalledTimes(storeCalls)
}
)
it('publishes a new filename without overwrite confirmation', async () => {
selectSubgraphNodeToPublish()
vi.mocked(api.listUserDataFullInfo).mockResolvedValue([
{ path: 'another-blueprint.json', modified: 1, size: 1 }
])
vi.mocked(api.getUserData).mockImplementation(async () =>
Response.json(mockGraph)
)

await store.publishSubgraph()

expect(useDialogService().confirm).not.toHaveBeenCalled()
expect(api.storeUserData).toHaveBeenCalledTimes(1)
})

it('does not publish when existing filenames cannot be checked', async () => {
selectSubgraphNodeToPublish()
const listingError = new Error('Blueprint listing unavailable')
vi.mocked(api.listUserDataFullInfo).mockRejectedValue(listingError)

await store.publishSubgraph()

expect(reportError).toHaveBeenCalledExactlyOnceWith(listingError, {
errorType: 'error_checking_blueprint_overwrite',
surface: 'graph'
})
expect(api.storeUserData).not.toHaveBeenCalled()
expect(useToast().toasts).toEqual([
expect.objectContaining({
kind: 'error',
description: 'Blueprint listing unavailable'
})
])
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})

it('should display published nodes in the node library', async () => {
await mockFetch({ 'test.json': mockGraph })
expect(userBlueprintNames()).toEqual(['SubgraphBlueprint.test'])
Expand Down
21 changes: 14 additions & 7 deletions src/stores/subgraphStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'

import { t } from '@/i18n'
import { reportError } from '@comfyorg/telemetry/reportError'
import { SubgraphNode } from '@/lib/litegraph/src/litegraph'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useToast } from '@/components/ui/toast/toastStore'
Expand Down Expand Up @@ -335,7 +336,6 @@ export const useSubgraphStore = defineStore('subgraph', () => {
throw new TypeError('Must have single SubgraphNode selected to publish')
}

//create minimal workflow
const workflowData = {
revision: 0,
last_node_id: subgraphNode.id,
Expand All @@ -345,7 +345,6 @@ export const useSubgraphStore = defineStore('subgraph', () => {
version: 0.4,
definitions: { subgraphs }
}
//prompt name
const name =
providedName ??
(await useDialogService().prompt({
Expand All @@ -354,14 +353,24 @@ export const useSubgraphStore = defineStore('subgraph', () => {
defaultValue: subgraphNode.title
}))
if (!name) return
const savedBlueprints = await api
.listUserDataFullInfo(SubgraphBlueprint.basePath)
.catch((error: unknown) => {
reportError(error, {
errorType: 'error_checking_blueprint_overwrite',
surface: 'graph'
})
useToast().error(t('subgraphStore.loadFailure'), {
description: getErrorMessage(error) ?? t('g.unknownError')
})
})
if (!savedBlueprints) return
if (
nodeDefStore.blueprintNodeDefsByName.has(BLUEPRINT_TYPE_PREFIX + name) &&
savedBlueprints.some((file) => file.path === `${name}.json`) &&
!(await confirmOverwrite(name))
)
//User has chosen not to overwrite.
return

//upload file
const path = SubgraphBlueprint.basePath + name + '.json'
const workflow = new SubgraphBlueprint({
path,
Expand All @@ -370,10 +379,8 @@ export const useSubgraphStore = defineStore('subgraph', () => {
})
workflow.originalContent = JSON.stringify(workflowData)
const loadedWorkflow = await workflow.load()
//Mark non-temporary
workflow.size = 1
await workflow.save()
//add to files list?
useWorkflowStore().attachWorkflow(loadedWorkflow)
useToast().success(t('subgraphStore.publishSuccess'), {
description: t('subgraphStore.publishSuccessMessage'),
Expand Down
Loading