Skip to content

Conversation

@arjansingh
Copy link
Contributor

@arjansingh arjansingh commented Sep 3, 2025

GLIGENLoader

Summary

This is in preparation for getting them to work with our new ModelBrowser component.

Also wrote test suite for the store.

Changes

Nothing should be noticeable to the user.

Review Focus

  1. Make sure the test suite makes sense please.

┆Issue is synchronized with this Notion page by Unito

@arjansingh arjansingh requested review from a team as code owners September 3, 2025 19:27
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 3, 2025
@github-actions
Copy link

github-actions bot commented Sep 3, 2025

🎭 Playwright Test Results

comfy-loading-gif Tests are starting...

⏰ Started at: 09/04/2025, 01:15:47 AM UTC

🚀 Running Tests

  • 🧪 chromium: Running tests...
  • 🧪 chromium-0.5x: Running tests...
  • 🧪 chromium-2x: Running tests...
  • 🧪 mobile-chrome: Running tests...

⏱️ Please wait while tests are running across all browsers...

@arjansingh arjansingh force-pushed the feat/register-more-nodes branch from be8e192 to d0b6a76 Compare September 3, 2025 20:41
Comment on lines 11 to 12
let store: ReturnType<typeof useModelToNodeStore>
let nodeDefStore: ReturnType<typeof useNodeDefStore>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely necessary, but you might want to check out the comments I left in here.
I generally prefer to minimize how much mutable state there is ever, but especially in test suites.

The initializing of the stores feels like a pretty important part of the Arrange section for any given test, so it'd be nice to have it directly in the it() block.

// Create minimal mock for testing - only includes 'name' field since that's
// the only property ModelNodeProvider constructor uses and tests verify
const createMockNodeDef = (name: string): ComfyNodeDefImpl => {
return { name } as ComfyNodeDefImpl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a cast?

Comment on lines 25 to 40
const mockNodeNames = [
'CheckpointLoaderSimple',
'ImageOnlyCheckpointLoader',
'LoraLoader',
'LoraLoaderModelOnly',
'VAELoader',
'ControlNetLoader',
'UNETLoader',
'UpscaleModelLoader',
'StyleModelLoader',
'GLIGENLoader'
]

const mockNodeDefs: Record<string, ComfyNodeDefImpl> = Object.fromEntries(
mockNodeNames.map((name) => [name, createMockNodeDef(name)])
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is going to be the same every time, it could be worth extracting as a CONSTANT.
Or if it needs to be regenerated because it is mutable/mutated, an extracted method.

Comment on lines 52 to 53
expect(Object.keys(store.modelToNodeMap)).toContain('checkpoints')
expect(Object.keys(store.modelToNodeMap)).toContain('unet')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://vitest.dev/api/expect.html#expect-arraycontaining
Might be clearer than having separate expectations, unless these are each separately important to check.

const provider = store.getNodeProvider('checkpoints')
expect(provider).toBeDefined()
// Optional chaining used because getNodeProvider() can return undefined for unregistered types
expect(provider?.nodeDef.name).toBe('CheckpointLoaderSimple')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one piece is possibly undefined, the chain should usually go to the terminus.
Otherwise you'll get that node isn't present on undefined.

Comment on lines 22 to 23
store = useModelToNodeStore()
nodeDefStore = useNodeDefStore()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why is one store and the other nodeDefStore? Feels like playing favorites 😛

Comment on lines 93 to 134
expect(checkpointProviders.map((p) => p.nodeDef.name)).toContain(
'CheckpointLoaderSimple'
)
expect(checkpointProviders.map((p) => p.nodeDef.name)).toContain(
'ImageOnlyCheckpointLoader'
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]

expectedTypes.forEach((modelType) => {
expect(store.getNodeProvider(modelType)).toBeDefined()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're looping like this, you usually want to add .soft so that you don't have to keep re-running it if there are multiple violations.

@arjansingh arjansingh force-pushed the feat/register-more-nodes branch from 1e5282c to 68bd05e Compare September 3, 2025 23:28
// Mock nodeDefStore dependency - modelToNodeStore relies on this for registration
// Most tests expect this to be populated; tests that need empty state can override
const nodeDefStore = useNodeDefStore()
nodeDefStore.nodeDefsByName = Object.fromEntries(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use vitest mocking

const modelToNodeStore = useModelToNodeStore()
modelToNodeStore.registerDefaults()

EXPECTED_DEFAULT_TYPES.forEach((modelType) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for of

Copy link
Contributor

@DrJKL DrJKL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@arjansingh arjansingh enabled auto-merge (squash) September 4, 2025 01:18
@arjansingh arjansingh merged commit ad64dbb into main Sep 4, 2025
19 checks passed
@arjansingh arjansingh deleted the feat/register-more-nodes branch September 4, 2025 01:24
@christian-byrne
Copy link
Contributor

christian-byrne commented Sep 4, 2025

Oh I never got a chance to review. I think for the model selector dialog, we will need a mapping in the other direction as well so we will need to add a method in the store for that.

@benceruleanlu benceruleanlu mentioned this pull request Sep 4, 2025
snomiao pushed a commit that referenced this pull request Sep 12, 2025
…5324)

* [feat] register UNETLoader, UpscaleModelLoader, StylemModelLoader, GLIGENLoader

Also added tests for modelToNodeStore

* [fix] code review feedback on tests

* [fix] typescript bikeshedding

* [fix] remove unnecessary interface mocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:assets size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants