-
Notifications
You must be signed in to change notification settings - Fork 672
test: repair vacuous save/load round-trip tests for widget labels #15603
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
Merged
+109
−15
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
baf13a1
test: repair vacuous save/load round-trip tests for widget labels
christian-byrne bee1987
test: type serialized graph reload helper
ampagent df8cc3b
Apply suggestions from code review
DrJKL cf6cebe
test: share interior node type
ampagent 6e510a2
Merge branch 'feature/ecs-migration' into cb__roundtrip-vacuity-audit
DrJKL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| * Tests for SubgraphNode instances including construction, | ||
| * IO synchronization, and edge cases. | ||
| */ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest' | ||
| import { fromPartial } from '@total-typescript/shoehorn' | ||
|
|
||
| import { | ||
|
|
@@ -398,7 +398,13 @@ describe('SubgraphNode Synchronization', () => { | |
| ) | ||
| }) | ||
|
|
||
| it('should preserve renamed label through serialize/configure round-trip', () => { | ||
| // Not a round trip. `SubgraphNode.configure` rebuilds `this.inputs` from the | ||
| // live `subgraph.inputNode.slots`, and `widgetValueStore` is keyed | ||
| // `graphId:nodeId:name` while `configure` re-adopts the payload's graph id — | ||
| // so reconfiguring the same node in place reads live state, not JSON. This | ||
| // test survives `serialize()` dropping every input label. The reload | ||
| // assertion lives in the sibling test below. | ||
|
DrJKL marked this conversation as resolved.
Outdated
|
||
| it('keeps the renamed label after an in-place reconfigure', () => { | ||
| const subgraph = createTestSubgraph({ | ||
| inputs: [{ name: 'seed', type: 'INT' }] | ||
| }) | ||
|
|
@@ -440,6 +446,73 @@ describe('SubgraphNode Synchronization', () => { | |
| 'My Seed' | ||
| ) | ||
| }) | ||
|
|
||
| it('preserves a renamed label across a real definition reload', () => { | ||
| const subgraph = createTestSubgraph({ | ||
| inputs: [{ name: 'seed', type: 'INT' }] | ||
| }) | ||
|
|
||
| // A registered type: `configure` will not re-create an unregistered node, | ||
| // so an anonymous interior node makes the reload silently empty. | ||
| class InteriorNode extends LGraphNode { | ||
| static override title = 'Interior' | ||
| constructor() { | ||
| super('Interior') | ||
| const slot = this.addInput('value', 'INT') | ||
| slot.widget = { name: 'value' } | ||
| this.addOutput('out', 'INT') | ||
| this.addWidget('number', 'value', 0, () => {}) | ||
| } | ||
| } | ||
| LiteGraph.registerNodeType('test/interior-label-reload', InteriorNode) | ||
| onTestFinished(() => { | ||
| delete LiteGraph.registered_node_types['test/interior-label-reload'] | ||
| }) | ||
|
|
||
| const interiorNode = LiteGraph.createNode('test/interior-label-reload')! | ||
|
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. How do you feel about a |
||
| subgraph.add(interiorNode) | ||
| subgraph.inputNode.slots[0].connect(interiorNode.inputs[0], interiorNode) | ||
|
|
||
| const subgraphNode = createTestSubgraphNode(subgraph, { id: 101 }) | ||
| subgraph.inputs[0].label = 'My Seed' | ||
| subgraphNode.inputs[0].label = 'My Seed' | ||
| subgraph.events.dispatch('renaming-input', { | ||
| input: subgraph.inputs[0], | ||
| index: 0, | ||
| oldName: 'seed', | ||
| newName: 'My Seed' | ||
| }) | ||
|
|
||
| // The label must survive as JSON, not as a live object reference: the | ||
| // subgraph *definition* carries it, and the reloaded host reads it back | ||
| // through the reloaded definition. `SubgraphNode.configure` rebuilds | ||
| // `this.inputs` from the live subgraph slots and never reads | ||
| // `info.inputs`, so a same-object reconfigure proves nothing. | ||
|
DrJKL marked this conversation as resolved.
Outdated
|
||
| const definition = JSON.parse( | ||
| JSON.stringify(subgraph.asSerialisable()) | ||
| ) as ReturnType<typeof subgraph.asSerialisable> | ||
| const instance = JSON.parse( | ||
| JSON.stringify(subgraphNode.serialize()) | ||
| ) as ExportedSubgraphInstance | ||
|
|
||
| // Drop the live widget state so the reloaded host cannot re-adopt it: | ||
| // `configure` re-adopts the payload's graph id and `widgetValueStore` is | ||
| // keyed `graphId:nodeId:name`. | ||
|
DrJKL marked this conversation as resolved.
Outdated
|
||
| useWidgetValueStore().clearGraph(subgraphNode.rootGraph.id) | ||
|
|
||
| const reloadedSubgraph = createTestSubgraph({ | ||
| rootGraph: subgraphNode.rootGraph | ||
| }) | ||
| reloadedSubgraph.configure(definition) | ||
|
|
||
| const reloadedHost = createTestSubgraphNode(reloadedSubgraph, { id: 101 }) | ||
| reloadedHost.configure(instance) | ||
|
|
||
| expect(reloadedHost.widgets).toMatchObject([ | ||
| { name: 'seed', label: 'My Seed' } | ||
| ]) | ||
| expect(reloadedHost.inputs[0].label).toBe('My Seed') | ||
| }) | ||
| }) | ||
|
|
||
| describe('SubgraphNode widget name collision on rename', () => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,13 @@ import type { LGraphEventMap } from '@/lib/litegraph/src/infrastructure/LGraphEv | |
| import { Rectangle } from '@/lib/litegraph/src/infrastructure/Rectangle' | ||
| import type { | ||
| CanvasPointerEvent, | ||
| ISerialisedGraph, | ||
| LGraph, | ||
| LGraphCanvas, | ||
| LGraphGroup, | ||
| LinkNetwork, | ||
| LLink | ||
| LLink, | ||
| SerialisableGraph | ||
| } from '@/lib/litegraph/src/litegraph' | ||
| import { LGraphEventMode, LGraphNode } from '@/lib/litegraph/src/litegraph' | ||
| import { fromPartial } from '@total-typescript/shoehorn' | ||
|
|
@@ -25,6 +27,8 @@ import { toLinkId } from '@/types/linkId' | |
| import type { NodeId } from '@/types/nodeId' | ||
| import { toNodeId } from '@/types/nodeId' | ||
| import type { NodeState } from '@/types/nodeState' | ||
| import { usePreviewExposureStore } from '@/stores/previewExposureStore' | ||
| import { useWidgetValueStore } from '@/stores/widgetValueStore' | ||
| import { zeroUuid } from '@/utils/uuid' | ||
|
|
||
| /** Creates a node shell state with minimal required fields. */ | ||
|
|
@@ -395,3 +399,35 @@ export function createMockLinks(links: LLink[]): LGraph['links'] { | |
| } | ||
| return Object.assign(map, record) as LGraph['links'] | ||
| } | ||
|
|
||
| /** | ||
| * Reloads a serialized graph the way a fresh page would, and returns the new | ||
| * graph. | ||
| * | ||
| * Save/load assertions written as `configure(...serialize())` are vacuous by | ||
| * default. `LGraph.clear()` drops the widget store under the graph's | ||
| * *pre-configure* id, but `LGraph._configureBase` then re-adopts the *payload's* | ||
| * graph id — and `widgetValueStore` is keyed `graphId:nodeId:name`. The source | ||
| * graph's entries are therefore still live under exactly the key the reloaded | ||
| * node looks up, so `registerWidget` returns the existing state and the | ||
| * assertion passes without the serialized payload ever being read. | ||
| * | ||
| * This helper removes both escape hatches: the payload is forced through | ||
| * `JSON.parse(JSON.stringify(...))` (so live-object aliasing cannot leak) and | ||
| * the widget/preview stores are dropped for the payload's graph id before | ||
| * `configure()` runs. | ||
| * | ||
| * Verify with a mutation: a save/load test that still passes when the producer | ||
| * stops writing the field under test never read the payload. | ||
| */ | ||
|
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. THE COMMENTS...
DrJKL marked this conversation as resolved.
Outdated
|
||
| export function reloadSerializedGraph( | ||
| serialized: ISerialisedGraph | SerialisableGraph, | ||
| graphFactory: () => LGraph | ||
| ): LGraph { | ||
| const payload = JSON.parse(JSON.stringify(serialized)) as typeof serialized | ||
| useWidgetValueStore().clearGraph(payload.id) | ||
| usePreviewExposureStore().clearGraph(payload.id) | ||
| const reloaded = graphFactory() | ||
| reloaded.configure(payload) | ||
| return reloaded | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.