Skip to content
Closed
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
10 changes: 9 additions & 1 deletion src/stores/nodeDataStore.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTestingPinia } from '@pinia/testing'
import { setActivePinia } from 'pinia'
import { assert, beforeEach, describe, expect, it } from 'vitest'
import { assert, beforeEach, describe, expect, it, vi } from 'vitest'
import { computed } from 'vue'

import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
Expand Down Expand Up @@ -66,28 +66,36 @@ describe('useNodeDataStore', () => {
const store = useNodeDataStore()
const first = node(1)
const duplicate = node(1, 'sub-1')
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})

const registered = store.registerNode(graphScope(rootA, rootA), first)
const rejected = store.registerNode(graphScope(rootA, 'sub-1'), duplicate)

expect(registered?.id).toBe(first.id)
expect(rejected).toBeUndefined()
expect(errorSpy).toHaveBeenCalledOnce()
expect(errorSpy.mock.calls[0][0]).toMatch(/belongs to graph/)
expect(duplicate.graphId).toBe('sub-1')
expect(store.getGraphNodesFor(rootA, rootA)).toEqual([registered])
expect(store.getGraphNodesFor(rootA, 'sub-1')).toEqual([])
errorSpy.mockRestore()
})

it('rejects the registered node identity from a sibling owner', () => {
const store = useNodeDataStore()
const registered = node(1)
store.registerNode(graphScope(rootA, rootA), registered)
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})

expect(
store.registerNode(graphScope(rootA, 'sub-1'), registered)
).toBeUndefined()
expect(errorSpy).toHaveBeenCalledOnce()
expect(errorSpy.mock.calls[0][0]).toMatch(/belongs to graph/)
expect(registered.graphId).toBe(rootA)
expect(store.getGraphNodesFor(rootA, rootA)).toEqual([registered])
expect(store.getGraphNodesFor(rootA, 'sub-1')).toEqual([])
errorSpy.mockRestore()
})

it('only deletes the registered identity from its owning graph', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/stores/nodeDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const useNodeDataStore = defineStore('nodeData', () => {
incumbent.graphId === graphScope.owningGraphId
)
return incumbent
if (incumbent) return undefined
if (incumbent) {
console.error(
`Node ${state.id} belongs to graph ${incumbent.graphId}; graph ${graphScope.owningGraphId} cannot overwrite it.`
)
return undefined
}
const bucket = existingBucket ?? rootBucket(graphScope.rootGraphId)
const registered: NodeState = reactive(
Object.assign(state, { graphId: graphScope.owningGraphId })
Expand Down
Loading