Skip to content

Commit eef74bd

Browse files
DrJKLampagent
andcommitted
refactor: un-export isLinkedPromotion, assert demotion via link state
isLinkedPromotion has no production callers outside promotionUtils. Drop its dedicated direct-unit describe block and rewrite the demoteWidget tests that used it as an assertion oracle to check observable interior link state instead. Amp-Thread-ID: https://ampcode.com/threads/T-019f2964-7a96-7579-8883-caeb3b2b07da Co-authored-by: Amp <amp@ampcode.com>
1 parent 28995ec commit eef74bd

2 files changed

Lines changed: 7 additions & 62 deletions

File tree

src/core/graph/subgraph/promotionUtils.test.ts

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import {
5757
demoteWidget,
5858
getPromotableWidgets,
5959
hasUnpromotedWidgets,
60-
isLinkedPromotion,
6160
isPreviewPseudoWidget,
6261
promoteValueWidgetViaSubgraphInput,
6362
promoteRecommendedWidgets,
@@ -541,53 +540,6 @@ describe('hasUnpromotedWidgets', () => {
541540
})
542541
})
543542

544-
describe('isLinkedPromotion', () => {
545-
beforeEach(() => {
546-
setActivePinia(createTestingPinia({ stubActions: false }))
547-
})
548-
549-
function promoteSource(host: SubgraphNode, widgetName: string): LGraphNode {
550-
const node = new LGraphNode('Source')
551-
const input = node.addInput(widgetName, 'STRING')
552-
const widget = node.addWidget('text', widgetName, '', () => {})
553-
input.widget = { name: widget.name }
554-
host.subgraph.add(node)
555-
promoteValueWidgetViaSubgraphInput(host, node, widget)
556-
return node
557-
}
558-
559-
it('returns true for a linked promotion', () => {
560-
const host = createTestSubgraphNode(createTestSubgraph())
561-
const node = promoteSource(host, 'text')
562-
563-
expect(isLinkedPromotion(host, String(node.id), 'text')).toBe(true)
564-
})
565-
566-
it('returns false when no promotion exists', () => {
567-
const host = createTestSubgraphNode(createTestSubgraph())
568-
569-
expect(isLinkedPromotion(host, '999', 'nonexistent')).toBe(false)
570-
})
571-
572-
it('returns false when sourceWidgetName does not match', () => {
573-
const host = createTestSubgraphNode(createTestSubgraph())
574-
const node = promoteSource(host, 'text')
575-
576-
expect(isLinkedPromotion(host, String(node.id), 'wrong_name')).toBe(false)
577-
})
578-
579-
it('identifies linked widgets across different inputs', () => {
580-
const host = createTestSubgraphNode(createTestSubgraph())
581-
const nodeA = promoteSource(host, 'string_a')
582-
const nodeB = promoteSource(host, 'value')
583-
584-
expect(isLinkedPromotion(host, String(nodeA.id), 'string_a')).toBe(true)
585-
expect(isLinkedPromotion(host, String(nodeB.id), 'value')).toBe(true)
586-
expect(isLinkedPromotion(host, String(nodeA.id), 'value')).toBe(false)
587-
expect(isLinkedPromotion(host, '5', 'string_a')).toBe(false)
588-
})
589-
})
590-
591543
describe('reorderSubgraphInputsByName', () => {
592544
beforeEach(() => {
593545
setActivePinia(createTestingPinia({ stubActions: false }))
@@ -812,9 +764,7 @@ describe('demoteWidget — axiomatic projection retraction', () => {
812764
expect(host.subgraph.inputs).toHaveLength(1)
813765
expect(host.inputs[0]?.link).toBe(9999)
814766
expect(host.inputs[0]?._widget).toBeUndefined()
815-
expect(
816-
isLinkedPromotion(host, String(interiorNode.id), interiorWidget.name)
817-
).toBe(false)
767+
expect(interiorNode.inputs[0]?.link).toBeNull()
818768
expect(host.widgets).toHaveLength(0)
819769
if (!promotedInputId) throw new Error('Missing promoted input widgetId')
820770
expect(useWidgetValueStore().getWidget(promotedInputId)).toBeUndefined()
@@ -832,14 +782,13 @@ describe('demoteWidget — axiomatic projection retraction', () => {
832782
})
833783

834784
it('demotes the second of two promoted widgets sharing a source widget name', () => {
835-
const { host, nodeA, widgetA, nodeB, widgetB } =
836-
buildDuplicateNamePromotion()
785+
const { host, nodeA, nodeB, widgetB } = buildDuplicateNamePromotion()
837786

838787
demoteWidget(nodeB, widgetB, [host])
839788

840789
expect(host.subgraph.inputs.map((i) => i.name)).toEqual(['text'])
841-
expect(isLinkedPromotion(host, String(nodeB.id), widgetB.name)).toBe(false)
842-
expect(isLinkedPromotion(host, String(nodeA.id), widgetA.name)).toBe(true)
790+
expect(nodeB.inputs[0]?.link).toBeNull()
791+
expect(nodeA.inputs[0]?.link).not.toBeNull()
843792
})
844793

845794
it('demotes the correct slot when widget lives on a nested SubgraphNode with same-named deep sources', () => {
@@ -866,12 +815,8 @@ describe('demoteWidget — axiomatic projection retraction', () => {
866815
demoteWidget(innerHost, promotedWidgetRef(innerHost, 'text_1'), [outerHost])
867816

868817
expect(outerHost.subgraph.inputs.map((i) => i.name)).toEqual(['text'])
869-
expect(isLinkedPromotion(outerHost, String(innerHost.id), 'text_1')).toBe(
870-
false
871-
)
872-
expect(isLinkedPromotion(outerHost, String(innerHost.id), 'text')).toBe(
873-
true
874-
)
818+
expect(innerHost.inputs.find((i) => i.name === 'text_1')?.link).toBeNull()
819+
expect(innerHost.inputs.find((i) => i.name === 'text')?.link).not.toBeNull()
875820
})
876821
})
877822

src/core/graph/subgraph/promotionUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function getWidgetName(w: IBaseWidget): string {
3434
return w.name
3535
}
3636

37-
export function isLinkedPromotion(
37+
function isLinkedPromotion(
3838
subgraphNode: SubgraphNode,
3939
sourceNodeId: SerializedNodeId,
4040
sourceWidgetName: string

0 commit comments

Comments
 (0)