Repository navigation
test(assets): partial graph cleanup #16248
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
6b19039
d69d103
5b364ba
fe13672
a6b157e
7f870b5
5deca7b
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,7 +18,12 @@ import type { IWidget } from '@/lib/litegraph/src/types/widgets' | |||||||||||||||||||||||
| import { MediaAssetKey } from '@/platform/assets/schemas/mediaAssetSchema' | ||||||||||||||||||||||||
| import type { AssetId, AssetItem } from '@/platform/assets/schemas/assetSchema' | ||||||||||||||||||||||||
| import type { AssetMeta } from '@/platform/assets/schemas/mediaAssetSchema' | ||||||||||||||||||||||||
| import { scanNodeMediaCandidates } from '@/platform/missingMedia/missingMediaScan' | ||||||||||||||||||||||||
| import { useMissingMediaStore } from '@/platform/missingMedia/missingMediaStore' | ||||||||||||||||||||||||
| import { api } from '@/scripts/api' | ||||||||||||||||||||||||
| import { clearDeletedAssetWidgetValues } from '../utils/clearDeletedAssetWidgetValues' | ||||||||||||||||||||||||
| import { clearNodePreviewCacheForValues } from '../utils/clearNodePreviewCacheForValues' | ||||||||||||||||||||||||
| import { markDeletedAssetsAsMissingMedia } from '../utils/markDeletedAssetsAsMissingMedia' | ||||||||||||||||||||||||
| import { resolveOutputAssetItems } from '../utils/outputAssetUtil' | ||||||||||||||||||||||||
| import { useMediaAssetActions as createMediaAssetActions } from './useMediaAssetActions' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -156,7 +161,9 @@ vi.mock<unknown>(import('@/scripts/api'), () => ({ | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const mockAppGraph = vi.hoisted(() => ({ value: { _nodes: [] as unknown[] } })) | ||||||||||||||||||||||||
| const mockAppGraph = vi.hoisted(() => ({ | ||||||||||||||||||||||||
| value: { nodes: [] as unknown[] } | ||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||
| vi.mock<unknown>(import('@/scripts/app'), () => ({ | ||||||||||||||||||||||||
| app: { | ||||||||||||||||||||||||
| nodeOutputs: {}, | ||||||||||||||||||||||||
|
|
@@ -175,21 +182,17 @@ const mockRemoveNodeOutputsForNode = vi.hoisted(() => vi.fn()) | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const mockCaptureCanvasState = vi.hoisted(() => vi.fn()) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const mockClearNodePreviewCache = vi.hoisted(() => vi.fn()) | ||||||||||||||||||||||||
| vi.mock(import('../utils/clearNodePreviewCacheForValues'), () => ({ | ||||||||||||||||||||||||
| clearNodePreviewCacheForValues: mockClearNodePreviewCache, | ||||||||||||||||||||||||
| findNodesReferencingValues: vi.fn(() => []) | ||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||
| vi.mock(import('../utils/clearNodePreviewCacheForValues'), { spy: true }) | ||||||||||||||||||||||||
| const mockClearNodePreviewCache = vi.mocked(clearNodePreviewCacheForValues) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const mockClearWidgetValues = vi.hoisted(() => vi.fn()) | ||||||||||||||||||||||||
| vi.mock(import('../utils/clearDeletedAssetWidgetValues'), () => ({ | ||||||||||||||||||||||||
| clearDeletedAssetWidgetValues: mockClearWidgetValues | ||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||
| vi.mock(import('../utils/clearDeletedAssetWidgetValues'), { spy: true }) | ||||||||||||||||||||||||
| const mockClearWidgetValues = vi.mocked(clearDeletedAssetWidgetValues) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const mockMarkMissingMedia = vi.hoisted(() => vi.fn()) | ||||||||||||||||||||||||
| vi.mock(import('../utils/markDeletedAssetsAsMissingMedia'), () => ({ | ||||||||||||||||||||||||
| markDeletedAssetsAsMissingMedia: mockMarkMissingMedia | ||||||||||||||||||||||||
| })) | ||||||||||||||||||||||||
| vi.mock(import('@/platform/missingMedia/missingMediaScan'), { spy: true }) | ||||||||||||||||||||||||
| const mockScanNodeMediaCandidates = vi.mocked(scanNodeMediaCandidates) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| vi.mock(import('../utils/markDeletedAssetsAsMissingMedia'), { spy: true }) | ||||||||||||||||||||||||
| const mockMarkMissingMedia = vi.mocked(markDeletedAssetsAsMissingMedia) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function createMockAsset(overrides: Partial<AssetItem> = {}): AssetItem { | ||||||||||||||||||||||||
| return fromPartial({ | ||||||||||||||||||||||||
|
|
@@ -1314,7 +1317,7 @@ describe('useMediaAssetActions', () => { | |||||||||||||||||||||||
| props.onConfirm(true) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| mockAppGraph.value = { _nodes: [] } | ||||||||||||||||||||||||
| mockAppGraph.value = { nodes: [] } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it('completes the lifecycle for one confirmed asset record', async () => { | ||||||||||||||||||||||||
|
|
@@ -1502,7 +1505,84 @@ describe('useMediaAssetActions', () => { | |||||||||||||||||||||||
| opts.props.onConfirm(true) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| mockAppGraph.value = { _nodes: [] } | ||||||||||||||||||||||||
| mockAppGraph.value = { nodes: [] } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it('cleans every shared reference only for successful assets after a partial deletion', async () => { | ||||||||||||||||||||||||
| mockDeleteAsset.mockImplementation(async (id: string) => { | ||||||||||||||||||||||||
| if (id === 'asset-failed') throw new Error('503 Service Unavailable') | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| const successfulCallbacks = [vi.fn(), vi.fn()] | ||||||||||||||||||||||||
| const failedCallback = vi.fn() | ||||||||||||||||||||||||
| const successfulNodes = successfulCallbacks.map((callback, index) => | ||||||||||||||||||||||||
| fromAny<LGraphNode, unknown>({ | ||||||||||||||||||||||||
| id: index + 10, | ||||||||||||||||||||||||
| widgets: [ | ||||||||||||||||||||||||
| { name: 'image', value: 'shared.png', callback }, | ||||||||||||||||||||||||
| ...(index === 0 | ||||||||||||||||||||||||
| ? [ | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| name: 'mask', | ||||||||||||||||||||||||
| value: 'failed.png', | ||||||||||||||||||||||||
| callback: failedCallback | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||
| : []) | ||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||
| imgs: [{ src: `blob:shared-preview-${index}` }], | ||||||||||||||||||||||||
| graph: { setDirtyCanvas: vi.fn() } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| mockAppGraph.value = { | ||||||||||||||||||||||||
| nodes: successfulNodes | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| mockScanNodeMediaCandidates.mockImplementation((_graph, node) => [ | ||||||||||||||||||||||||
|
Collaborator
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. SHOULD FIX — this stub only ever emits a candidate built from That filter — Emit a candidate per widget instead, so
Suggested change
I verified this still passes: While you are in here: the previous revision had a standalone
Contributor
Author
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. Tracked as FE-2608. The PR merged with this thread unresolved, so the finding is carried in Linear rather than lost here. Filed automatically; close the ticket if the finding is no longer true at |
||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| nodeId: String(node.id), | ||||||||||||||||||||||||
| nodeType: 'LoadImage', | ||||||||||||||||||||||||
| widgetName: 'image', | ||||||||||||||||||||||||
| mediaType: 'image', | ||||||||||||||||||||||||
| name: String(node.widgets?.[0].value), | ||||||||||||||||||||||||
| isMissing: undefined | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||
|
Comment on lines
+1539
to
+1548
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1490,1590p' src/platform/assets/composables/useMediaAssetActions.test.ts
sed -n '1,240p' src/platform/assets/utils/markDeletedAssetsAsMissingMedia.ts
rg -n 'markDeletedAssetsAsMissingMedia|scanNodeMediaCandidates|missingMediaCandidates' src/platform/assets/composables/useMediaAssetActions.ts src/platform/assets/composables/useMediaAssetActions.test.ts src/platform/assets/utils/markDeletedAssetsAsMissingMedia.tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 8006 🏁 Script executed: sed -n '680,770p' src/platform/assets/composables/useMediaAssetActions.ts
sed -n '1,220p' src/platform/assets/composables/useMediaAssetActions.test.ts
sed -n '1500,1580p' src/platform/assets/composables/useMediaAssetActions.test.tsRepository: Comfy-Org/ComfyUI_frontend Length of output: 13721 Include The mock reads only the first widget, so it emits 🤖 Prompt for AI Agents
Contributor
Author
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. Tracked as FE-2607. The PR merged with this thread unresolved, so the finding is carried in Linear rather than lost here. Filed automatically; close the ticket if the finding is no longer true at
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.
You are interacting with an AI system. |
||||||||||||||||||||||||
| const actions = useMediaAssetActions() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| await actions.deleteAssets([ | ||||||||||||||||||||||||
| createMockAsset({ id: 'asset-success', name: 'shared.png' }), | ||||||||||||||||||||||||
| createMockAsset({ id: 'asset-failed', name: 'failed.png' }) | ||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| expect(mockMarkMissingMedia).toHaveBeenCalledWith( | ||||||||||||||||||||||||
| mockAppGraph.value, | ||||||||||||||||||||||||
| new Set(['shared.png', 'shared.png [input]']) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||
| expect(useMissingMediaStore().missingMediaCandidates).toEqual( | ||||||||||||||||||||||||
| expect.arrayContaining([ | ||||||||||||||||||||||||
| expect.objectContaining({ | ||||||||||||||||||||||||
| name: 'shared.png', | ||||||||||||||||||||||||
| isMissing: true | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| expect(useMissingMediaStore().missingMediaCandidates).not.toEqual( | ||||||||||||||||||||||||
| expect.arrayContaining([ | ||||||||||||||||||||||||
| expect.objectContaining({ name: 'failed.png' }) | ||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| for (const [index, node] of successfulNodes.entries()) { | ||||||||||||||||||||||||
|
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: The repository's testing guidance disallows loops in test bodies and asks collection outcomes to be mapped into one complete assertion. Please map each node's observable state, callback calls, and canvas calls into a literal expected array. That also makes the intentional difference between the two nodes visible in the failure output.
Contributor
Author
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. Tracked as FE-2610. The PR merged with this thread unresolved, so the finding is carried in Linear rather than lost here. Filed automatically; close the ticket if the finding is no longer true at |
||||||||||||||||||||||||
| expect(mockRemoveNodeOutputsForNode).toHaveBeenCalledWith(node) | ||||||||||||||||||||||||
| expect(node.imgs).toBeUndefined() | ||||||||||||||||||||||||
| expect(node.widgets?.[0].value).toBe('') | ||||||||||||||||||||||||
| expect(successfulCallbacks[index]).toHaveBeenCalledWith('') | ||||||||||||||||||||||||
| expect(node.graph?.setDirtyCanvas).toHaveBeenCalledWith(true) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| expect(successfulNodes[0].widgets?.[1].value).toBe('failed.png') | ||||||||||||||||||||||||
| expect(failedCallback).not.toHaveBeenCalled() | ||||||||||||||||||||||||
| expect(mockCaptureCanvasState).toHaveBeenCalledTimes(1) | ||||||||||||||||||||||||
|
benjcooley marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||||
| expect(mockCaptureCanvasState).toHaveBeenCalledAfter( | ||||||||||||||||||||||||
| mockClearWidgetValues | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it('invokes clearNodePreviewCacheForValues with canonical widget-value variants', async () => { | ||||||||||||||||||||||||
|
|
@@ -1528,7 +1608,7 @@ describe('useMediaAssetActions', () => { | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| expect(typeof removeArg).toBe('function') | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const sampleNode = { id: 42 } | ||||||||||||||||||||||||
| const sampleNode = fromAny<LGraphNode, unknown>({ id: 42 }) | ||||||||||||||||||||||||
|
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: This check only needs node identity, and
Contributor
Author
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. Tracked as FE-2611. The PR merged with this thread unresolved, so the finding is carried in Linear rather than lost here. Filed automatically; close the ticket if the finding is no longer true at |
||||||||||||||||||||||||
| removeArg(sampleNode) | ||||||||||||||||||||||||
| expect(mockRemoveNodeOutputsForNode).toHaveBeenCalledWith(sampleNode) | ||||||||||||||||||||||||
| // Locator is resolved from the node's own graph, not from the raw id — | ||||||||||||||||||||||||
|
|
@@ -1637,7 +1717,7 @@ describe('useMediaAssetActions', () => { | |||||||||||||||||||||||
| ({ props }: { props: { onConfirm: (confirmed: boolean) => void } }) => | ||||||||||||||||||||||||
| props.onConfirm(true) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| mockAppGraph.value = { _nodes: [] } | ||||||||||||||||||||||||
| mockAppGraph.value = { nodes: [] } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it('keeps a failed asset listed and removes it once a retry succeeds', async () => { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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.
[P2] This central fixture uses
fromAnyto claim that a hand-built shell is a completeLGraphNodewhile three real graph helpers execute against it. The mock graph also declaresnodesasunknown[], so TypeScript cannot enforce the graph/node contract. Please construct realLGraphNode/LGraphinstances or use the shared typed node fixture with branded IDs. That keeps future node-contract changes visible to this integration test.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.
Tracked as FE-2609. The PR merged with this thread unresolved, so the finding is carried in Linear rather than lost here. Filed automatically; close the ticket if the finding is no longer true at
main.