-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpipeline.test.ts
More file actions
80 lines (68 loc) · 2.89 KB
/
Copy pathpipeline.test.ts
File metadata and controls
80 lines (68 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Unit tests for the pipeline orchestrator.
*
* Verifies that buildGraph from the new pipeline produces the same results
* as the integration tests expect — correct return shape, phase timing, etc.
*/
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { buildGraph } from '../../src/domain/graph/builder/pipeline.js';
const FIXTURE_DIR = path.join(import.meta.dirname, '..', 'fixtures', 'sample-project');
let tmpDir: string;
beforeAll(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-pipeline-'));
fs.cpSync(FIXTURE_DIR, tmpDir, {
recursive: true,
filter: (src) => path.basename(src) !== '.codegraph',
});
});
afterAll(() => {
if (tmpDir) fs.rmSync(tmpDir, { recursive: true, force: true });
});
describe('buildGraph pipeline', () => {
it('returns phases timing object', async () => {
const result = await buildGraph(tmpDir, { incremental: false });
expect(result).toBeDefined();
expect(result.phases).toBeDefined();
expect(typeof result.phases.setupMs).toBe('number');
expect(typeof result.phases.parseMs).toBe('number');
expect(typeof result.phases.insertMs).toBe('number');
expect(typeof result.phases.resolveMs).toBe('number');
expect(typeof result.phases.edgesMs).toBe('number');
expect(typeof result.phases.structureMs).toBe('number');
expect(typeof result.phases.rolesMs).toBe('number');
expect(typeof result.phases.finalizeMs).toBe('number');
});
it('returns undefined on early exit (no changes)', async () => {
// First build
await buildGraph(tmpDir, { incremental: false });
// Second build — incremental, no changes
const result = await buildGraph(tmpDir, { incremental: true });
expect(result).toBeUndefined();
});
it('creates expected nodes and edges', async () => {
await buildGraph(tmpDir, { incremental: false });
const Database = (await import('better-sqlite3')).default;
const db = new Database(path.join(tmpDir, '.codegraph', 'graph.db'), { readonly: true });
const nodeCount = db.prepare('SELECT COUNT(*) as c FROM nodes').get().c;
const edgeCount = db.prepare('SELECT COUNT(*) as c FROM edges').get().c;
expect(nodeCount).toBeGreaterThan(0);
expect(edgeCount).toBeGreaterThan(0);
// Should have file nodes for all 3 fixture files
const fileNodes = db
.prepare("SELECT name FROM nodes WHERE kind = 'file'")
.all()
.map((r) => r.name);
expect(fileNodes).toContain('math.js');
expect(fileNodes).toContain('utils.js');
expect(fileNodes).toContain('index.js');
db.close();
});
it('exports from barrel are identical to direct import', async () => {
// Verify the barrel re-export works
const { buildGraph: fromBarrel } = await import('../../src/domain/graph/builder.js');
expect(fromBarrel).toBe(buildGraph);
});
});