feat: per-route subgraph slicing — routes run only their needed providers/steps
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+82
-4
No files matched your search
+20
-2
@@ -1,5 +1,5 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { topoSort, GraphNode } from '../src/graph';
|
||||
import { describe, expect, it, test } from 'vitest';
|
||||
import { topoSort, GraphNode, subgraphFor } from '../src/graph';
|
||||
|
||||
const node = (name: string, needs: string[], provides: string[]): GraphNode =>
|
||||
({ name, needs, provides, origin: 'test' });
|
||||
@@ -23,3 +23,21 @@ test('throws on cycle', () => {
|
||||
const nodes = [node('a', ['b'], ['a']), node('b', ['a'], ['b'])];
|
||||
expect(() => topoSort(nodes, [])).toThrow(/cycle detected/);
|
||||
});
|
||||
|
||||
const N = (name: string, needs: string[] = []) => ({ name, needs, provides: [name], origin: 'm' });
|
||||
|
||||
describe('subgraphFor', () => {
|
||||
const ordered = [N('config'), N('db', ['config']), N('user', ['db', 'req']), N('audit', ['db'])];
|
||||
it('returns the transitive closure of needs, in the given order', () => {
|
||||
expect(subgraphFor(['user'], ordered).map((n) => n.name)).toEqual(['config', 'db', 'user']);
|
||||
});
|
||||
it('returns empty for no needs', () => {
|
||||
expect(subgraphFor([], ordered)).toEqual([]);
|
||||
});
|
||||
it('ignores tokens with no producer (seeds/envelope)', () => {
|
||||
expect(subgraphFor(['user', 'query', 'req'], ordered).map((n) => n.name)).toEqual(['config', 'db', 'user']);
|
||||
});
|
||||
it('does not pull in unrelated nodes', () => {
|
||||
expect(subgraphFor(['user'], ordered).map((n) => n.name)).not.toContain('audit');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user