-
Notifications
You must be signed in to change notification settings - Fork 449
[feat] register UNETLoader, UpscaleModelLoader, StylemModelLoader... #5324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
be8e192 to
d0b6a76
Compare
| let store: ReturnType<typeof useModelToNodeStore> | ||
| let nodeDefStore: ReturnType<typeof useNodeDefStore> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
| 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)]) | ||
| ) |
There was a problem hiding this comment.
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.
| expect(Object.keys(store.modelToNodeMap)).toContain('checkpoints') | ||
| expect(Object.keys(store.modelToNodeMap)).toContain('unet') |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
| store = useModelToNodeStore() | ||
| nodeDefStore = useNodeDefStore() |
There was a problem hiding this comment.
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 😛
| expect(checkpointProviders.map((p) => p.nodeDef.name)).toContain( | ||
| 'CheckpointLoaderSimple' | ||
| ) | ||
| expect(checkpointProviders.map((p) => p.nodeDef.name)).toContain( | ||
| 'ImageOnlyCheckpointLoader' | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all of this style assertion: https://vitest.dev/api/expect.html#expect-objectcontaining
| ] | ||
|
|
||
| expectedTypes.forEach((modelType) => { | ||
| expect(store.getNodeProvider(modelType)).toBeDefined() |
There was a problem hiding this comment.
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.
…IGENLoader Also added tests for modelToNodeStore
1e5282c to
68bd05e
Compare
| // 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( |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for of
DrJKL
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
|
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. |
…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

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
┆Issue is synchronized with this Notion page by Unito