GitNexus/gitnexus/test/integration/fts-empty-tables.test.ts
Gergő Magyar 612136cadc
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
fix: compact incremental graphs adaptively (#3854)
* fix: rebuild changed graphs in fresh databases

Populated-table writes inflate LadybugDB storage (#3852). Bulk-load
fresh graphs while retaining parse caches, no-ops and logical counts.

Read prior graphs without writes so staging failures preserve their
bytes. Restore compatible vectors and rebuild derived layers and FTS
under the existing checkpoint and publication guards.

Keep the write policy, preservation guards and regressions together
so the replacement has one coherent publication contract.

Closes #3852

* perf: skip FTS builds for empty tables

* fix: align CI with compact graph writes

Validate populated-table FTS coverage and cached full writes while keeping the performance budget unchanged. Compare database bytes without enumerating Buffer keys, and retain native checkpoint failure details.

* perf: use bounded hybrid graph writes

Keep small edits selective and scale the mutation budget with graph size.
Compact accumulated native storage growth without copying every graph on
every edit. Preserve physical receipts across shared-store publication and
native resource limits during recovery.

Align CI assertions with selective writes and populated FTS tables.
Refs #3852

* fix: close hybrid compaction gaps

Count removed rows before selective writes and preserve the shared
graph's compaction receipt when publishing completed vectors.

* test: serialize compaction native suites

* test: declare capped count determinism

* test: mock persisted rows in FTS fixtures

* fix: address hybrid write review (#3854)

Retain unreadable graph bytes before recovery and stop destructive writes
when the real embedding cache probe fails.

Keep small deletions and renames selective, preserve healthy private
graphs through edit/revert cycles, and bound FTS presence probes.

Cover durability, footprint boundaries and vector restoration. Align
mock graph fixtures and fix the pre-existing WAL test's UUID false
positive found by full-suite validation; its nine-test suite now passes.

* test: clarify selective restore fixture (#3854)

* test: isolate recovery CI fixtures (#3854)

Cap embedding generation in the missing-graph recovery fixture so it does
not require optional model packages. Allow cold PowerShell startup in the
OS identity smoke test; retain the five-second production probe limit.

* test: finish review cleanup (#3854)

* test: strengthen graph integrity checks

Hash persisted node and edge properties; clean failed fixtures and gate FTS setup through the test lifecycle.

Refs #3854

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-09 20:57:07 +00:00

99 lines
4.1 KiB
TypeScript

import { expect, it } from 'vitest';
import { withTestLbugDB } from '../helpers/test-indexed-db.js';
import {
closeLbug,
createFTSIndex,
dropFTSIndex,
executeQuery,
initLbug,
} from '../../src/core/lbug/lbug-adapter.js';
import * as pool from '../../src/core/lbug/pool-adapter.js';
import { searchFTSFromLbug } from '../../src/core/search/bm25-index.js';
import {
createSearchFTSIndexes,
verifySearchFTSIndexes,
} from '../../src/core/search/fts-indexes.js';
import { FTS_INDEXES } from '../../src/core/search/fts-schema.js';
withTestLbugDB(
'fts-empty-tables',
(handle) => {
it('omits empty indexes, preserves core/pool search, and indexes newly populated tables', async () => {
expect(await createSearchFTSIndexes()).toEqual([]);
const catalog = await executeQuery('CALL SHOW_INDEXES() RETURN *');
expect(
catalog
.filter((row) => row.index_type === 'FTS')
.map((row) => row.table_name)
.sort(),
).toEqual(['File', 'Function']);
expect(await verifySearchFTSIndexes(executeQuery)).toEqual([]);
const before = await searchFTSFromLbug('resilient nebula', 20);
expect(before.ftsAvailable).toBe(true);
expect(before.missingIndexes).toBeUndefined();
expect(before.nonBenignErrors).toBeUndefined();
expect(before.results.map((row) => row.filePath)).toEqual(['a.ts']);
await closeLbug();
await pool.initLbug(handle.repoId, handle.dbPath);
try {
expect(await searchFTSFromLbug('resilient nebula', 20, handle.repoId)).toEqual(before);
} finally {
await pool.closeLbug(handle.repoId);
}
await initLbug(handle.dbPath);
// Independent control: explicitly create all configured native indexes,
// including empty tables, and compare complete ranked results/scores.
for (const index of FTS_INDEXES) {
await createFTSIndex(index.table, index.indexName, [...index.properties]);
}
expect(await searchFTSFromLbug('resilient nebula', 20)).toEqual(before);
await dropFTSIndex('Class', 'class_fts');
await executeQuery(
"CREATE (:Class {id: 'Class:b.ts:Quasar', name: 'Quasar', filePath: 'b.ts', " +
"startLine: 1, endLine: 2, content: 'class Quasar {}', description: 'orbital lighthouse'})",
);
// The previous empty-table result must not be cached across mutations.
expect(await verifySearchFTSIndexes(executeQuery)).toEqual(['Class.class_fts']);
expect((await searchFTSFromLbug('orbital lighthouse')).missingIndexes).toEqual([
'Class.class_fts',
]);
await closeLbug();
await pool.initLbug(handle.repoId, handle.dbPath);
try {
expect(
(await searchFTSFromLbug('orbital lighthouse', 20, handle.repoId)).missingIndexes,
).toEqual(['Class.class_fts']);
} finally {
await pool.closeLbug(handle.repoId);
}
await initLbug(handle.dbPath);
expect(await createSearchFTSIndexes()).toEqual([]);
expect(await verifySearchFTSIndexes(executeQuery)).toEqual([]);
const populated = await searchFTSFromLbug('orbital lighthouse');
expect(populated.missingIndexes).toBeUndefined();
expect(populated.results.map((row) => row.filePath)).toEqual(['b.ts']);
await dropFTSIndex('Class', 'class_fts');
await executeQuery('MATCH (n:Class) DELETE n');
expect(await createSearchFTSIndexes()).toEqual([]);
expect(await verifySearchFTSIndexes(executeQuery)).toEqual([]);
expect(await searchFTSFromLbug('resilient nebula', 20)).toEqual(before);
}, 120_000);
},
{
seed: [
"CREATE (:File {id: 'File:a.ts', name: 'a.ts', filePath: 'a.ts', content: 'resilient nebula'})",
"CREATE (:Function {id: 'Function:a.ts:alpha', name: 'alpha', filePath: 'a.ts', " +
"startLine: 1, endLine: 2, content: 'function alpha() {}', description: 'resilient nebula'})",
],
// Gate the suite on native FTS availability through the existing helper.
ftsIndexes: [
{ table: 'Function', indexName: 'function_fts', columns: ['name', 'content', 'description'] },
],
},
);