From c3d6305418a428a36d3585484f926e5d52bae976 Mon Sep 17 00:00:00 2001 From: carlos-alm <127798846+carlos-alm@users.noreply.github.com> Date: Thu, 2 Apr 2026 22:01:20 -0600 Subject: [PATCH 1/2] fix(embed): handle absolute file paths from native engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The native engine stores absolute file paths in the DB. buildEmbeddings unconditionally joined rootDir + file, doubling the path and causing ENOENT for every symbol — producing 0 embeddings silently. Check path.isAbsolute() before joining, and add a regression test that inserts nodes with absolute paths to prevent recurrence. Closes #760 --- src/domain/search/generator.ts | 2 +- tests/search/embedding-strategy.test.ts | 41 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/domain/search/generator.ts b/src/domain/search/generator.ts index af87d5aa..69363367 100644 --- a/src/domain/search/generator.ts +++ b/src/domain/search/generator.ts @@ -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'); diff --git a/tests/search/embedding-strategy.test.ts b/tests/search/embedding-strategy.test.ts index a8e58828..62c5c0c2 100644 --- a/tests/search/embedding-strategy.test.ts +++ b/tests/search/embedding-strategy.test.ts @@ -289,6 +289,47 @@ 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; From 4a29207519ddfd89d4f0d17d6f2218416c21af48 Mon Sep 17 00:00:00 2001 From: carlos-alm <127798846+carlos-alm@users.noreply.github.com> Date: Thu, 2 Apr 2026 22:01:36 -0600 Subject: [PATCH 2/2] style: fix biome formatting in test --- tests/search/embedding-strategy.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/search/embedding-strategy.test.ts b/tests/search/embedding-strategy.test.ts index 62c5c0c2..58376569 100644 --- a/tests/search/embedding-strategy.test.ts +++ b/tests/search/embedding-strategy.test.ts @@ -294,10 +294,7 @@ describe('absolute file paths in DB (#760)', () => { 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', - ); + 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 });