Skip to content

Commit 305bb74

Browse files
committed
test(impact): assert relationships sidecar before impact
1 parent 18b1f01 commit 305bb74

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

tests/impact-2hop.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import { promises as fs } from 'fs';
33
import path from 'path';
4-
import os from 'os';
54
import { CodebaseIndexer } from '../src/core/indexer.js';
65
import { dispatchTool } from '../src/tools/index.js';
76
import type { ToolContext } from '../src/tools/types.js';
@@ -10,14 +9,16 @@ import {
109
INTELLIGENCE_FILENAME,
1110
KEYWORD_INDEX_FILENAME,
1211
VECTOR_DB_DIRNAME,
13-
MEMORY_FILENAME
12+
MEMORY_FILENAME,
13+
RELATIONSHIPS_FILENAME
1414
} from '../src/constants/codebase-context.js';
1515

1616
describe('Impact candidates (2-hop)', () => {
1717
let tempRoot: string | null = null;
1818

1919
beforeEach(async () => {
20-
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'impact-2hop-'));
20+
// Keep test artifacts under CWD (mirrors other indexer tests and avoids OS tmp quirks)
21+
tempRoot = await fs.mkdtemp(path.join(process.cwd(), '.tmp-impact-2hop-'));
2122
const srcDir = path.join(tempRoot, 'src');
2223
await fs.mkdir(srcDir, { recursive: true });
2324
await fs.writeFile(path.join(tempRoot, 'package.json'), JSON.stringify({ name: 'impact-2hop' }));
@@ -62,6 +63,23 @@ describe('Impact candidates (2-hop)', () => {
6263
performIndexing: () => {}
6364
};
6465

66+
const relationshipsPath = path.join(rootPath, CODEBASE_CONTEXT_DIRNAME, RELATIONSHIPS_FILENAME);
67+
const relationshipsRaw = await fs.readFile(relationshipsPath, 'utf-8');
68+
const relationships = JSON.parse(relationshipsRaw) as {
69+
graph?: { imports?: Record<string, string[]> };
70+
};
71+
const imports = relationships.graph?.imports ?? {};
72+
const hasInternalEdge =
73+
(imports['src/b.ts'] ?? []).some((d) => d.endsWith('src/c.ts') || d === 'src/c.ts') &&
74+
(imports['src/a.ts'] ?? []).some((d) => d.endsWith('src/b.ts') || d === 'src/b.ts');
75+
if (!hasInternalEdge) {
76+
throw new Error(
77+
`Expected relationships graph to include src/a.ts -> src/b.ts and src/b.ts -> src/c.ts, got imports keys=${JSON.stringify(
78+
Object.keys(imports)
79+
)}`
80+
);
81+
}
82+
6583
const resp = await dispatchTool(
6684
'search_codebase',
6785
{ query: 'UNIQUE_TOKEN_123', intent: 'edit', includeSnippets: false, limit: 1 },

0 commit comments

Comments
 (0)