From 52d18e23fbc69fd01051ce7f9114e59c6ae20923 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 28 Jul 2026 16:56:42 +0000 Subject: [PATCH] test(frontend): pin that topologicalSort tolerates a missing parent node --- .../lib/components/graph/graphBuilder.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 frontend/src/lib/components/graph/graphBuilder.test.ts diff --git a/frontend/src/lib/components/graph/graphBuilder.test.ts b/frontend/src/lib/components/graph/graphBuilder.test.ts new file mode 100644 index 0000000000..1203ab57cd --- /dev/null +++ b/frontend/src/lib/components/graph/graphBuilder.test.ts @@ -0,0 +1,23 @@ +import { describe, it, expect, vi } from 'vitest' + +// Mock modules that transitively import CSS/Monaco +vi.mock('monaco-editor', () => ({})) +vi.mock('@xyflow/svelte', () => ({})) +vi.mock('./renderers/nodes/AssetNode.svelte', () => ({ + assetDisplaysAsOutputInFlowGraph: () => false +})) +vi.mock('../modulesTest.svelte', () => ({})) + +import { topologicalSort } from './graphBuilder.svelte' + +describe('topologicalSort', () => { + it('skips parent ids with no node instead of throwing', () => { + const sorted = topologicalSort([ + { id: 'a' }, + { id: 'b', parentIds: ['a'] }, + { id: 'orphan', parentIds: ['deleted'] } + ]) + + expect(sorted.map((n) => n.id)).toEqual(['orphan', 'b', 'a']) + }) +})