Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/domain/search/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function buildEmbeddings(
let overflowCount = 0;

for (const [file, fileNodes] of byFile) {
const fullPath = path.join(rootDir, file);
const fullPath = path.isAbsolute(file) ? file : path.join(rootDir, file);
let lines: string[];
try {
lines = fs.readFileSync(fullPath, 'utf-8').split('\n');
Expand Down
38 changes: 38 additions & 0 deletions tests/search/embedding-strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,44 @@ describe('FTS5 index built alongside embeddings', () => {
});
});

describe('absolute file paths in DB (#760)', () => {
let absDir: string, absDbPath: string;

beforeAll(() => {
absDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-abspath-test-'));
fs.writeFileSync(path.join(absDir, 'math.js'), 'export function add(a, b) { return a + b; }\n');

const absDbDir = path.join(absDir, '.codegraph');
fs.mkdirSync(absDbDir, { recursive: true });
absDbPath = path.join(absDbDir, 'graph.db');

const db = new Database(absDbPath);
db.pragma('journal_mode = WAL');
initSchema(db);

// Insert node with an absolute file path (as the native engine does)
const absFile = path.join(absDir, 'math.js');
insertNode(db, 'add', 'function', absFile, 1, 1);
db.close();
});

afterAll(() => {
if (absDir) fs.rmSync(absDir, { recursive: true, force: true });
});

test('produces embeddings when DB stores absolute paths', async () => {
EMBEDDED_TEXTS.length = 0;
await buildEmbeddings(absDir, 'minilm', absDbPath);

expect(EMBEDDED_TEXTS.length).toBe(1);

const db = new Database(absDbPath, { readonly: true });
const count = db.prepare('SELECT COUNT(*) as c FROM embeddings').get().c;
db.close();
expect(count).toBe(1);
});
});

describe('context window overflow detection', () => {
let bigDir: string, bigDbPath: string;

Expand Down
Loading