mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-08 22:22:52 +00:00
* feat(lbug): add ensureEmbeddingRowDmlSafe VECTOR gate for embedding-row DML LadybugDB refuses every mutation of a table carrying an HNSW index while the VECTOR extension is not loaded on that connection: DELETE and CREATE raise a Binder exception, DROP TABLE is refused while the index references it, and SET segfaults the process. Dropping the index is not an available recovery either — CALL DROP_VECTOR_INDEX is itself a VECTOR-extension function and is undefined in exactly that state. Add a single primitive that loads VECTOR under the analyze install policy and, only when that fails, reads CALL SHOW_INDEXES (which works without the extension) to decide whether an index actually exists to trip over. No call sites yet. Refs #2623 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(lbug): pin the #2623 VECTOR gate for embedding-row DML Three cases: no index + VECTOR unavailable stays safe (no needless escalation); index present + VECTOR unavailable is reported blocked AND the raw deleteNodesForFiles genuinely throws 'extension is not loaded' (proving the hazard is real, not theoretical); index present + VECTOR loadable is safe, the delete works, and the HNSW index survives — the invariant run-analyze relies on when it keeps the index across a surgical incremental run. Refs #2623 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(analyze): load VECTOR before the incremental writeback touches embedding rows Incremental analyze died on every content change once a repo had built code_embedding_idx: Analysis failed: Binder exception: Trying to delete from an index on table CodeEmbedding but its extension is not loaded. The surgical writeback's first statement is deleteNodesForFiles' CodeEmbedding join-delete, but nothing on that path loaded VECTOR until Phase 4 — so the engine refused the delete. This is an ordering defect, not an environment one: it reproduces on machines where VECTOR loads fine. The dirty-flag recovery then forced a full rebuild on the next run, which is why it read as 'just slow'. Call ensureEmbeddingRowDmlSafe() once, before the escalation gate and before any row is touched — the same 'index lifecycle before row DML' seam dropSearchFTSIndexes occupies for FTS (#2589). Unconditional, because a DB carrying the index from an earlier --embeddings run hits the same wall on a plain incremental run. When VECTOR truly cannot load the table is immutable (the index cannot be dropped without the extension either), so the run falls through to the existing wipe-and-COPY escalation with a message naming cause, consequence and remedy. Fixes #2623 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(analyze): pin the #2623 VECTOR-before-embedding-DML ordering end-to-end Sibling of the #2589 FTS drop-before-delete suite, same shape: drive the real runFullAnalysis incremental path over a real git repo and a real LadybugDB, seed real embedding rows, build the HNSW index, then assert the index state at the exact moment deleteNodesForFiles is invoked. Both cases were confirmed to discriminate — with the run-analyze change reverted they fail with the reported 'Trying to delete from an index on table CodeEmbedding but its extension is not loaded', and pass with it: - surgical path: the run completes, the index is still present AND extension_loaded at delete time, exactly one row per nodeId survives, and the untouched file's rows are preserved - blocked path: with GITNEXUS_LBUG_EXTENSION_INSTALL=never the run escalates to a full DB write and says so, instead of crashing Also applies prettier's reindent to the run-analyze log ternary. Refs #2623 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(lbug): cite the pinned LadybugDB version in the #2623 probe note The probe matrix behind ensureEmbeddingRowDmlSafe was first recorded on 0.18.0, but gitnexus/package-lock.json pins 0.18.2 (#2587). Re-ran every case on 0.18.2: refused DELETE, refused CREATE, SIGSEGV on SET, DROP_VECTOR_INDEX undefined, DROP TABLE refused, SHOW_INDEXES readable with extension_loaded intact. Identical on both, so the design is unchanged — only the citation was wrong. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(analyze): preserve embeddings across the VECTOR-blocked rebuild, and check the catalog before loading Three follow-ups from reviewing the fix itself. 1. Data loss on the blocked path. Escalating wipes the DB files, and Phase 3.5 restores embedding rows from cachedEmbeddings — which deriveEmbeddingMode only populates when meta.stats.embeddings > 0. A DB holding embedding rows that its meta does not account for therefore had every vector destroyed silently by a rebuild it never asked for. Probe on a 3-file repo: 3 rows before, 0 after, no warning. Read the rows before escalating (a plain MATCH, no extension needed) so the existing restore has something to restore, and say so in the log. The blocked-path test now asserts the seeded rows survive exactly once, and that assertion fails without this rescue. 2. Catalog before extension. ensureEmbeddingRowDmlSafe loaded VECTOR first and only read SHOW_INDEXES on failure, so every incremental analyze on a machine without VECTOR paid a bounded out-of-process INSTALL attempt plus an 'extension unavailable' warning — including repos that never built an embedding index and can never hit this bug. One local catalog read settles that case first; the load is attempted only when an index actually gates DML, or when the catalog cannot be read. 3. Dead branch. targetConn is always the module singleton there, so the isSharedSingletonConn ternary could never take its second arm. Collapsed to withConnLock. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(doctor): live-probe the VECTOR extension instead of printing the static platform capability Review finding on #2624 (MEDIUM), and exactly what #2623's reporter hit: doctor printed 'VECTOR index: available' — derived from a static platform check — while every incremental analyze on the same machine was dying on an unloaded VECTOR extension. The FTS line was switched to a live LOAD probe for the identical contradiction under #2374; VECTOR now gets the same treatment. probeVectorExtensionLoad shares the FTS probe's implementation (bounded, offline-safe, never runs the installer) and doctor's semantic-mode line now follows the probe, not the platform: without a loadable extension the vector index can be neither built nor queried, so search really is on exact scan. The load-error classifier's remedies are label-parameterized so the VECTOR row stops dispensing FTS-specific advice — 'run analyze --repair-fts' repairs FTS indexes only and was actively wrong for a missing vector extension. Default label stays 'FTS'; every existing caller and pinned remedy string is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(lbug): remove the stale Windows VECTOR gate — the extension ships for win_amd64 The codebase categorically refused VECTOR on Windows (platform !== 'win32' in isVectorExtensionSupportedByPlatform, plus a hard early-return in loadVectorExtension) on the strength of an early-era report that in-process INSTALL VECTOR could SIGSEGV (#1365). That belief is stale, verified directly: - the extension server hosts win_amd64 VECTOR artifacts for every 0.18.x extension version — v0.18.0 and v0.18.1 both serve a real 14 MB PE32+ DLL (curl-probed; 'file' confirms PE32+ x86-64) - the pinned 0.18.2 core resolves its extension directory to 0.18.1 (strace-verified LOAD open()), so the pinned version's Windows artifact exists too - INSTALL now runs in a spawned child (installDuckDbExtensionOutOfProcess), so even a crashing installer kills only the child and degrades to unavailable — the original hazard cannot reach the parent process any more Windows now takes the same runtime path as every other OS: try LOAD, install out-of-process when policy allows, degrade to exact scan when it truly fails. The MCP semantic-search lane loses its static platform gate too — it always attempts the vector index and falls back to the exact scan on runtime failure, with a once-per-backend diagnostic naming the real error instead of a platform-policy message. isVectorExtensionSupportedByPlatform is deleted; getRuntimeCapabilities reports the platform capability as available everywhere and defers machine truth to the live probe. Windows CI is the enforcement: the vector suites skip visibly only when the extension genuinely cannot load, so green Windows lanes now actually exercise VECTOR instead of silently skipping by policy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(lbug): pin the catalog-read-failure fallback in ensureEmbeddingRowDmlSafe Review finding on #2624 (LOW): the one branch where the gate cannot cheaply prove safety — SHOW_INDEXES itself erroring — was exercised only by inference. Force it with a Connection.prototype.query spy over the real DB: the catalog read fails, and the gate must fall through to actually attempting the extension load (asserted via the recorded statement stream) rather than guessing, returning true here because the extension is loadable. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(mcp): load VECTOR on the pool's shared Database so the semantic vector lane actually works Review finding on #2624 (MEDIUM): extension load scope is per-Database (probe-verified — LOAD on one connection enables QUERY_VECTOR_INDEX on every connection of the same Database), and the pool pre-warm loaded only FTS. So LocalBackend's vector lane has ALWAYS raised 'Catalog exception: function QUERY_VECTOR_INDEX is not defined' through the pool and silently fallen back to the exact scan — repos above the 10k exact-scan cap got empty semantic results. The serve path was unaffected (the embedding pipeline loads the extension itself). Mirror the FTS line at BOTH load sites — doInitLbug's pre-warm and initLbugWithDb's external-Database adoption — under the same load-only contract (the read pool never triggers a network install), tracked by a new SharedDB.vectorLoaded flag reset where ftsLoaded resets. The new pool test is discriminating and deliberately closes the writable core adapter before the pool opens: a shared/injected Database would inherit the VECTOR load from test seeding and pass either way, so the case forces the pool onto its OWN fresh read-only Database where only the pre-warm can make the lane legal. Verified: fails at the pre-fix tree with the exact Catalog exception, passes with the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * ci: run the #2623 ordering suite on Windows/macOS and pre-install VECTOR alongside FTS Two review findings on #2624, both landing in existing seams: - scripts/cross-platform-tests.ts gains incremental-vector-extension-ordering .test.ts: the win32 VECTOR gate is gone in this PR, so the #2623 drop-ordering + blocked-path escalation must be proven on the windows-latest native addon, not just Ubuntu. (The review's claim that lbug-delete-nodes-for-files.test.ts was also missing was wrong — it has been on the roster since #2409.) - scripts/ensure-fts.ts now pre-installs VECTOR under the same best-effort auto-policy contract, so every sharded CI process LOADs from ~/.lbdb instead of racing its own bounded out-of-process INSTALL; the workflow's extension cache already covers it (path is the whole extension dir — key kept for cache continuity). The cross-platform job sets GITNEXUS_REQUIRE_VECTOR=1 beside GITNEXUS_REQUIRE_FTS so a genuinely unavailable VECTOR is a loud failure, never a silent skip. Windows/macOS cannot be executed locally; the PR's CI lanes are the proof for this commit. Linux smoke: ensure-fts.ts reports both extensions ready; all 79 roster entries resolve. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(pool): register loadVectorExtension in the pool unit-suite mocks The pool adapter's new loadVectorExtension import surfaced in four suites that mock lbug-adapter.js with explicit factories (vitest fails loudly on a missing mocked export). Register the export in each — resolving false where the suite's world assumes no vector, true where it mirrors FTS — and extend lbug-pool-fts-load.test.ts, the suite that owns pre-warm extension loading, with the vector pair: successful load cached per shared Database, failed load retried on the next open, both pinned to policy load-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(analyze): use POSIX literals for graph paths in the #2623 ordering suite First Windows CI run of this suite (it joined the cross-platform roster this PR) failed with 'Parser exception: Invalid input <MATCH (n:Function) WHERE n.filePath = '>' — path.join produces backslashes on Windows, and a backslash inside the seed helper's single-quoted Cypher literal breaks the parser. The graph stores repo-relative filePaths with forward slashes on every OS, so graph-side paths are POSIX literals now (the incremental-orchestration convention); path.join stays only for real filesystem access. The same Windows lane also proved the substance this suite exists for: lbug-vector-extension passed 7/7 on windows-latest — the extension installed, loaded, and built a real HNSW index there — and the pool vector-lane and DML gate suites passed too. This commit fixes the harness, not the fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Gergo Magyar <abhigyan1.patwari@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
267 lines
12 KiB
TypeScript
267 lines
12 KiB
TypeScript
/**
|
|
* #2623: the incremental writeback must have the VECTOR extension loaded
|
|
* BEFORE `deleteNodesForFiles` runs — its very first statement is the
|
|
* `CodeEmbedding` join-delete, and LadybugDB refuses every mutation of a
|
|
* table carrying an HNSW index while the extension is unloaded:
|
|
*
|
|
* Binder exception: Trying to delete from an index on table CodeEmbedding
|
|
* but its extension is not loaded.
|
|
*
|
|
* Nothing on that path loaded VECTOR until Phase 4, so any repo that had
|
|
* built `code_embedding_idx` crashed on the next content change — on machines
|
|
* where VECTOR loads perfectly well. This is the sibling of the #2589 FTS
|
|
* drop-before-delete ordering test and deliberately mirrors its shape: drive
|
|
* the real `runFullAnalysis` incremental path against a real git repo and a
|
|
* real LadybugDB, and assert the index state at the exact moment
|
|
* `deleteNodesForFiles` is invoked.
|
|
*/
|
|
import { readFile, writeFile } from 'fs/promises';
|
|
import { execSync } from 'child_process';
|
|
import path from 'path';
|
|
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { setupMiniRepo } from '../helpers/mini-repo.js';
|
|
import { seedEmbeddingsForFiles, stampEmbeddingCount } from '../helpers/embedding-seed.js';
|
|
import { getStoragePaths } from '../../src/storage/repo-manager.js';
|
|
import { createTempDir } from '../helpers/test-db.js';
|
|
import { EMBEDDING_TABLE_NAME } from '../../src/core/lbug/schema.js';
|
|
import { resolveAnalyzeInstallPolicy } from '../../src/core/lbug/extension-loader.js';
|
|
|
|
const vectorMustBeAvailable = process.env.GITNEXUS_REQUIRE_VECTOR === '1';
|
|
|
|
const commitAll = (cwd: string, message: string): void => {
|
|
execSync('git -c user.name=test -c user.email=t@t -c commit.gpgsign=false add -A', {
|
|
cwd,
|
|
stdio: 'pipe',
|
|
});
|
|
execSync(
|
|
`git -c user.name=test -c user.email=t@t -c commit.gpgsign=false commit -q -m "${message}"`,
|
|
{ cwd, stdio: 'pipe' },
|
|
);
|
|
};
|
|
|
|
describe('runFullAnalysis incremental writeback — VECTOR loaded before embedding-row DML (#2623)', () => {
|
|
let vectorAvailable = true;
|
|
let skipWarned = false;
|
|
|
|
beforeAll(async () => {
|
|
const lbugAdapter = await import('../../src/core/lbug/lbug-adapter.js');
|
|
// Cheap standalone probe, matching the #2589 suite's convention: settle
|
|
// availability once, up front, not inside the expensive test body.
|
|
const probe = await createTempDir('gitnexus-2623-vector-probe-');
|
|
try {
|
|
await lbugAdapter.initLbug(probe.dbPath);
|
|
vectorAvailable = await lbugAdapter.loadVectorExtension(undefined, {
|
|
policy: resolveAnalyzeInstallPolicy(),
|
|
});
|
|
} finally {
|
|
await lbugAdapter.closeLbug();
|
|
await probe.cleanup();
|
|
}
|
|
}, 120_000);
|
|
|
|
// Skip VISIBLY: a silent `return` would report a false pass and hide an
|
|
// ordering regression in exactly the environments least likely to notice.
|
|
beforeEach((ctx) => {
|
|
if (!vectorAvailable) {
|
|
if (vectorMustBeAvailable) {
|
|
throw new Error(
|
|
'GITNEXUS_REQUIRE_VECTOR=1 but the VECTOR extension is unavailable — cannot verify the #2623 ordering fix.',
|
|
);
|
|
}
|
|
if (!skipWarned) {
|
|
skipWarned = true;
|
|
console.warn(
|
|
'[incremental-vector-extension-ordering] Skipping — the LadybugDB VECTOR extension is unavailable.',
|
|
);
|
|
}
|
|
ctx.skip();
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.doUnmock('../../src/core/lbug/lbug-adapter.js');
|
|
vi.resetModules();
|
|
});
|
|
|
|
it('completes the surgical incremental run with the HNSW index present, and VECTOR is loaded by the time deleteNodesForFiles runs', async () => {
|
|
const lbugAdapter = await import('../../src/core/lbug/lbug-adapter.js');
|
|
const { runFullAnalysis } = await import('../../src/core/run-analyze.js');
|
|
|
|
const repo = await setupMiniRepo('gitnexus-2623-vector-order-');
|
|
try {
|
|
// First run: full rebuild, real graph.
|
|
await runFullAnalysis(repo.dbPath, { skipAgentsMd: true }, { onProgress: () => {} });
|
|
|
|
// Seed real embedding rows for two files, then build the HNSW index —
|
|
// the state a prior `analyze --embeddings` leaves behind. Zero vectors
|
|
// need no extension for the TABLE; only the index is extension-gated.
|
|
// POSIX literals, NOT path.join: the graph stores repo-relative
|
|
// filePaths with forward slashes on every OS, and a Windows backslash
|
|
// inside the seed helper's single-quoted Cypher literal is a parser
|
|
// error ("Invalid input <... n.filePath = '>"). path.join stays only
|
|
// for real filesystem access below.
|
|
const changedFile = 'src/handler.ts';
|
|
const untouchedFile = 'src/validator.ts';
|
|
const seeded = await seedEmbeddingsForFiles(repo.dbPath, [changedFile, untouchedFile], 2);
|
|
const changedIds = seeded.get(changedFile) ?? [];
|
|
const untouchedIds = seeded.get(untouchedFile) ?? [];
|
|
expect(changedIds.length).toBeGreaterThan(0);
|
|
expect(untouchedIds.length).toBeGreaterThan(0);
|
|
|
|
const { lbugPath, storagePath } = getStoragePaths(repo.dbPath);
|
|
// Without this, deriveEmbeddingMode sees a repo with no embeddings, the
|
|
// Phase 3.5 restore never engages, and rows deleted by the importer-BFS
|
|
// write-set expansion simply never come back — which would make the
|
|
// preservation assertion below measure the wrong thing.
|
|
await stampEmbeddingCount(storagePath, changedIds.length + untouchedIds.length);
|
|
|
|
const readEmbeddingIndexRows = async (): Promise<Array<Record<string, unknown>>> => {
|
|
const rows = (await lbugAdapter.executeQuery('CALL SHOW_INDEXES() RETURN *')) as Array<
|
|
Record<string, unknown>
|
|
>;
|
|
return rows.filter((r) => r.table_name === EMBEDDING_TABLE_NAME && r.index_type !== 'HASH');
|
|
};
|
|
|
|
await lbugAdapter.initLbug(lbugPath);
|
|
const indexBuilt = await lbugAdapter.createVectorIndex();
|
|
const indexRowsBefore = await readEmbeddingIndexRows();
|
|
await lbugAdapter.closeLbug();
|
|
|
|
// The beforeEach gate already proved VECTOR loads here, so a failure to
|
|
// build the index is a real bug, not an environment gap.
|
|
expect(indexBuilt).toBe(true);
|
|
expect(indexRowsBefore.length).toBeGreaterThan(0);
|
|
|
|
// Record the index's extension state at the exact moment the embedding
|
|
// join-delete is about to run. Pre-fix this is `false` and the run then
|
|
// throws; post-fix the gate has already loaded VECTOR.
|
|
let embeddingIndexAtDeleteTime: Array<Record<string, unknown>> | undefined;
|
|
const originalDeleteNodesForFiles = lbugAdapter.deleteNodesForFiles;
|
|
vi.spyOn(lbugAdapter, 'deleteNodesForFiles').mockImplementation(async (filePaths, opts) => {
|
|
embeddingIndexAtDeleteTime = await readEmbeddingIndexRows();
|
|
return originalDeleteNodesForFiles(filePaths, opts);
|
|
});
|
|
|
|
// One-file change keeps this well under the 50-file escalation
|
|
// threshold on a 7-file repo, so it takes the surgical branch.
|
|
const handlerPath = path.join(repo.dbPath, changedFile);
|
|
await writeFile(
|
|
handlerPath,
|
|
(await readFile(handlerPath, 'utf-8')) + '\n// #2623 ordering-test touch\n',
|
|
'utf-8',
|
|
);
|
|
commitAll(repo.dbPath, '#2623 ordering touch');
|
|
|
|
// THE regression: before the fix this rejects with
|
|
// "Trying to delete from an index on table CodeEmbedding".
|
|
await expect(
|
|
runFullAnalysis(repo.dbPath, { skipAgentsMd: true }, { onProgress: () => {} }),
|
|
).resolves.toBeDefined();
|
|
|
|
// Ordering proof: the index was still there AND its extension was
|
|
// loaded when the delete ran — the fix loads VECTOR rather than
|
|
// dropping the index (run-analyze relies on HNSW self-maintaining
|
|
// across a surgical run).
|
|
expect(embeddingIndexAtDeleteTime).toBeDefined();
|
|
expect(embeddingIndexAtDeleteTime!.length).toBeGreaterThan(0);
|
|
for (const row of embeddingIndexAtDeleteTime!) {
|
|
expect(row.extension_loaded).toBe(true);
|
|
}
|
|
|
|
// Data outcome: the untouched file's rows survive, and nothing is
|
|
// duplicated. (The changed file's rows are removed by the join-delete
|
|
// and restored by Phase 3.5, so their count must stay at exactly one
|
|
// per nodeId — a PK duplicate would mean the delete silently no-op'd.)
|
|
await lbugAdapter.initLbug(lbugPath);
|
|
try {
|
|
const perNode = (await lbugAdapter.executeQuery(
|
|
`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId, count(e) AS c`,
|
|
)) as Array<{ nodeId: string; c: number | bigint }>;
|
|
const counts = new Map(perNode.map((r) => [String(r.nodeId), Number(r.c)]));
|
|
for (const id of untouchedIds) {
|
|
expect(counts.get(id)).toBe(1);
|
|
}
|
|
for (const [, c] of counts) {
|
|
expect(c).toBe(1);
|
|
}
|
|
// The index is still there — the surgical path keeps it.
|
|
expect((await readEmbeddingIndexRows()).length).toBeGreaterThan(0);
|
|
} finally {
|
|
await lbugAdapter.closeLbug();
|
|
}
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
}, 300_000);
|
|
|
|
it('escalates to a full DB write instead of crashing when VECTOR cannot be loaded', async () => {
|
|
const lbugAdapter = await import('../../src/core/lbug/lbug-adapter.js');
|
|
const { runFullAnalysis } = await import('../../src/core/run-analyze.js');
|
|
|
|
const repo = await setupMiniRepo('gitnexus-2623-vector-blocked-');
|
|
const previousPolicy = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
try {
|
|
await runFullAnalysis(repo.dbPath, { skipAgentsMd: true }, { onProgress: () => {} });
|
|
// POSIX literal for the graph-side path (see the note in the first case).
|
|
const seeded = await seedEmbeddingsForFiles(repo.dbPath, ['src/handler.ts'], 2);
|
|
const seededIds = seeded.get('src/handler.ts') ?? [];
|
|
expect(seededIds.length).toBeGreaterThan(0);
|
|
// Deliberately NOT stampEmbeddingCount: this pins the case where the DB
|
|
// holds embedding rows that meta does not account for. The escalation
|
|
// wipes the DB, so without an explicit rescue read those rows would be
|
|
// destroyed silently — the run would still "succeed" and the loss would
|
|
// be invisible.
|
|
|
|
const { lbugPath } = getStoragePaths(repo.dbPath);
|
|
await lbugAdapter.initLbug(lbugPath);
|
|
const indexBuilt = await lbugAdapter.createVectorIndex();
|
|
await lbugAdapter.closeLbug();
|
|
expect(indexBuilt).toBe(true);
|
|
|
|
const handlerPath = path.join(repo.dbPath, 'src', 'handler.ts');
|
|
await writeFile(
|
|
handlerPath,
|
|
(await readFile(handlerPath, 'utf-8')) + '\n// #2623 blocked-path touch\n',
|
|
'utf-8',
|
|
);
|
|
commitAll(repo.dbPath, '#2623 blocked touch');
|
|
|
|
// VECTOR becomes unloadable for this run. The table is now immutable
|
|
// (the index cannot be dropped without the extension either), so the
|
|
// run must abandon surgery rather than fail mid-writeback.
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = 'never';
|
|
const logs: string[] = [];
|
|
await expect(
|
|
runFullAnalysis(
|
|
repo.dbPath,
|
|
{ skipAgentsMd: true },
|
|
{ onProgress: () => {}, onLog: (m: string) => logs.push(m) },
|
|
),
|
|
).resolves.toBeDefined();
|
|
|
|
expect(logs.some((m) => m.includes('full DB write'))).toBe(true);
|
|
expect(logs.some((m) => m.includes('VECTOR'))).toBe(true);
|
|
|
|
// The forced rebuild must NOT eat the embeddings it never asked to touch.
|
|
await lbugAdapter.initLbug(lbugPath);
|
|
try {
|
|
const surviving = (await lbugAdapter.executeQuery(
|
|
`MATCH (e:${EMBEDDING_TABLE_NAME}) RETURN e.nodeId AS nodeId`,
|
|
)) as Array<{ nodeId: string }>;
|
|
const survivingIds = new Set(surviving.map((r) => String(r.nodeId)));
|
|
for (const id of seededIds) {
|
|
expect(survivingIds.has(id)).toBe(true);
|
|
}
|
|
// …and exactly once each — the restore must not double-insert.
|
|
expect(surviving.length).toBe(survivingIds.size);
|
|
} finally {
|
|
await lbugAdapter.closeLbug();
|
|
}
|
|
expect(logs.some((m) => m.includes('Preserving'))).toBe(true);
|
|
} finally {
|
|
if (previousPolicy === undefined) delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
else process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = previousPolicy;
|
|
await repo.cleanup();
|
|
}
|
|
}, 300_000);
|
|
});
|