Repository navigation
feat(litegraph): prove a node's widget form rather than deriving it #22007
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
Changes from all commits
93da152
8cfcda4
3adac83
cc6195e
01d923f
aa73dff
6ad64a7
a5b081e
2101005
73cf472
e4521af
f3149fd
1f5804a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||||
| import { describe, expect, it } from 'vitest' | ||||||||||
|
|
||||||||||
| import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' | ||||||||||
| import { proveWidgetForm } from '@/lib/litegraph/src/widgets/widgetFormProof' | ||||||||||
|
christian-byrne marked this conversation as resolved.
Resolved
|
||||||||||
|
|
||||||||||
| function nodeInGraph(): LGraphNode { | ||||||||||
| const graph = new LGraph() | ||||||||||
| const node = new LGraphNode('test') | ||||||||||
| node.serialize_widgets = true | ||||||||||
| graph.add(node) | ||||||||||
| return node | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function coreIsLastWriter(node: LGraphNode): boolean { | ||||||||||
| return ( | ||||||||||
| node.serialize === LGraphNode.prototype.serialize && | ||||||||||
| node.serializeFromStoreState === | ||||||||||
| LGraphNode.prototype.serializeFromStoreState | ||||||||||
| ) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function proveRealSerialization(node: LGraphNode) { | ||||||||||
| const serialised = node.serialize() | ||||||||||
| return { | ||||||||||
| serialised, | ||||||||||
| proof: proveWidgetForm( | ||||||||||
| node.widgets, | ||||||||||
| serialised, | ||||||||||
| serialised.widgets_values, | ||||||||||
| { | ||||||||||
| serializeWidgets: node.serialize_widgets, | ||||||||||
| replayed: node.last_serialization !== undefined, | ||||||||||
| coreIsLastWriter: coreIsLastWriter(node) | ||||||||||
| } | ||||||||||
| ) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| describe('proveWidgetForm, driven through LGraphNode.serialize', () => { | ||||||||||
| it('counts a widget flagged only in its options bag, because widgets_values does', () => { | ||||||||||
| const node = nodeInGraph() | ||||||||||
| node.addWidget('number', 'seed', 1, () => undefined, {}) | ||||||||||
| node.addWidget( | ||||||||||
| 'combo', | ||||||||||
| 'control_after_generate', | ||||||||||
| 'randomize', | ||||||||||
| () => undefined, | ||||||||||
| { serialize: false, values: ['randomize', 'fixed'] } | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| const { serialised, proof } = proveRealSerialization(node) | ||||||||||
|
|
||||||||||
| expect(serialised.widgets_values).toEqual([1, 'randomize']) | ||||||||||
| expect(proof.provable).toBe(true) | ||||||||||
| expect(proof.order).toEqual(['seed', 'control_after_generate']) | ||||||||||
| expect(proof.refusal).toBeNull() | ||||||||||
|
Comment on lines
+54
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 Nit: I would keep this integration test focused on the real serialized values and corresponding order. A non-null order already implies success under
Suggested change
|
||||||||||
| }) | ||||||||||
|
|
||||||||||
| it('excludes a widget flagged on the widget itself, because widgets_values does too', () => { | ||||||||||
| const node = nodeInGraph() | ||||||||||
| node.addWidget('text', 'audio', 'clip.mp3', () => undefined, {}) | ||||||||||
| const widgetFlagged = node.addWidget( | ||||||||||
| 'button', | ||||||||||
| 'audioUI', | ||||||||||
| '', | ||||||||||
| () => undefined, | ||||||||||
| {} | ||||||||||
| ) | ||||||||||
| widgetFlagged.serialize = false | ||||||||||
|
|
||||||||||
| const { serialised, proof } = proveRealSerialization(node) | ||||||||||
|
|
||||||||||
| expect(serialised.widgets_values).toEqual(['clip.mp3']) | ||||||||||
| expect(proof.provable).toBe(true) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 Nit: As in the preceding case, the retained values and non-null order assertions cover this serializer integration. The pure acceptance test already checks the full success verdict, so I would remove this repeated field assertion.
Suggested change
|
||||||||||
| expect(proof.order).toEqual(['audio']) | ||||||||||
| }) | ||||||||||
| }) | ||||||||||
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.
P3: I reproduced
values_not_positionalfor null, string, number and boolean payloads as well as dictionaries. All are admitted by the helper'sunknowninput. Calling this refusal object-only could make a census reader infer a dictionary write from a scalar result. Keep VHS as an example without making it the exclusive classification.