mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-05 02:43:32 +00:00
* feat(review): add PR reviewer swarm agents
Seven read-only subagents coordinated by an orchestration skill for
structured, evidence-grounded production-readiness PR reviews.
Agents: facts-historian, branch-hygiene, risk-architect, test-ci-verifier,
security-boundary, docs-dod, synthesis-critic. All use Read/Grep/Glob/Bash
only — no edit tools.
Skill invoked as /gitnexus-pr-swarm-review <PR>.
* fix: patch vector extension and uncaughtException for review findings
- Add { policy: 'auto' } to both loadVectorExtension() calls in
embedding-pipeline.ts so analyze --embeddings auto-installs VECTOR
- Add void to uncaughtException shutdown(1) call for Node v20+ safety
- Re-add getExtensionInstallPolicy export + default change + 4 tests
* fix(mcp,lbug): graceful shutdown exit codes + complete offline-first VECTOR policy
Completes the two live issues PR #1161 only partially addressed.
#1132 — MCP shutdown crash: SIGINT/SIGTERM were registered with `shutdown`
directly, so Node passed the signal NAME string into process.exit(), crashing
with ERR_INVALID_ARG_TYPE ('SIGTERM'). Map signals to numeric exit codes
(SIGINT->130, SIGTERM->143) via a testable installSignalShutdown(); add an
unref'd force-exit watchdog so a hung disconnect()/close() cannot wedge
shutdown; and void the stdin/stdout handlers so event payloads never reach
process.exit() as a non-number.
#1153 — offline-first extension loading:
- semanticSearch (a query/read path) no longer forces policy:'auto'; queries
use load-only and never spawn a network INSTALL (extension.ladybugdb.com).
- the analyze embedding WRITE path resolves the policy from
GITNEXUS_LBUG_EXTENSION_INSTALL (honoring never/load-only/auto; default auto)
instead of hard-forcing 'auto', so an offline/locked-down operator's override
is respected (the regression that re-broke #1153 for the VECTOR path).
- surface the active install policy in `gitnexus doctor` (was claimed but never
delivered; also gives the previously-dead getExtensionInstallPolicy a caller).
- emit an actionable message when VECTOR is unavailable.
Tests: regression for the signal->numeric mapping (reproduces the signal-string
crash condition) and for embedding install-policy resolution. tsc/prettier clean,
eslint 0 errors, 55 unit tests pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(analyze): degrade gracefully when FTS extension is unavailable
The load-only default made `gitnexus analyze` throw when the FTS
extension was not pre-installed, breaking CI and offline use. Make the
analyze write path opt into the `auto` install policy (LOAD-first then
bounded INSTALL — symmetric with the VECTOR/embeddings path and the #726
contract) and degrade gracefully when the extension still cannot load:
skip search-index creation, log a warning, and complete with a fully
queryable graph (only full-text/BM25 search is disabled). `--repair-fts`
still fails loudly.
- Surface the degraded state instead of reporting healthy:
AnalyzeResult.ftsSkipped, a persistent CLI summary warning, and
meta.json capabilities.fts.status = "unavailable".
- Skip the FTS-primitive integration tests when the extension is
unavailable (shared skipUnlessFtsAvailable helper).
- Add a unit test for the degradation branch; fix the existing
full-analyze test mock that omitted loadFTSExtension.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(lbug): skip FTS-seeding suites when extension is unavailable
The withTestLbugDB helper seeds FTS indexes in beforeAll via createFTSIndex,
which throws when the optional FTS extension cannot load — failing the whole
suite on machines where it is neither pre-installed nor installable (the
macOS platform-sensitive CI runner). Probe the extension once (mirroring the
analyze write path's `auto` policy), bypass FTS seeding when it is
unavailable, and skip the suite's tests via beforeEach with a one-time
warning so the skip is visible rather than a setup crash.
Fixes the macOS failures in search-core, search-pool, local-backend-calltool,
and staleness-and-stability. Suites still run normally where FTS is available.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
316 lines
11 KiB
TypeScript
316 lines
11 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
ExtensionManager,
|
|
getExtensionInstallChildProcessArgs,
|
|
getExtensionInstallPolicy,
|
|
getExtensionInstallTimeoutMs,
|
|
type ExtensionInstallResult,
|
|
} from '../../src/core/lbug/extension-loader.js';
|
|
|
|
const okInstall: ExtensionInstallResult = {
|
|
success: true,
|
|
timedOut: false,
|
|
message: 'installed',
|
|
};
|
|
const failedInstall: ExtensionInstallResult = {
|
|
success: false,
|
|
timedOut: false,
|
|
message: 'install failed',
|
|
};
|
|
const timedOutInstall: ExtensionInstallResult = {
|
|
success: false,
|
|
timedOut: true,
|
|
message: 'INSTALL vector timed out after 10ms',
|
|
};
|
|
|
|
const noopWarn = (): void => {};
|
|
|
|
describe('ExtensionManager — LOAD-first behavior', () => {
|
|
it('uses LOAD only and never invokes INSTALL when the extension is already available', async () => {
|
|
const installExtension = vi.fn();
|
|
const manager = new ExtensionManager({ policy: 'auto', installExtension });
|
|
const query = vi.fn().mockResolvedValue({});
|
|
|
|
await expect(manager.ensure(query, 'fts', 'FTS')).resolves.toBe(true);
|
|
|
|
expect(query.mock.calls.map(([sql]) => sql)).toEqual(['LOAD EXTENSION fts']);
|
|
expect(installExtension).not.toHaveBeenCalled();
|
|
expect(manager.getCapabilities()).toEqual([{ name: 'fts', loaded: true }]);
|
|
});
|
|
|
|
it('treats "already loaded" load errors as success', async () => {
|
|
const installExtension = vi.fn();
|
|
const manager = new ExtensionManager({ policy: 'auto', installExtension });
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension fts is already loaded'));
|
|
|
|
await expect(manager.ensure(query, 'fts', 'FTS')).resolves.toBe(true);
|
|
expect(installExtension).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('ExtensionManager — install policies', () => {
|
|
it('runs bounded out-of-process INSTALL and retries LOAD when policy=auto', async () => {
|
|
const installExtension = vi.fn().mockResolvedValue(okInstall);
|
|
const manager = new ExtensionManager({ policy: 'auto', installExtension });
|
|
const query = vi
|
|
.fn()
|
|
.mockRejectedValueOnce(new Error('Extension "fts" not found'))
|
|
.mockResolvedValueOnce({});
|
|
|
|
await expect(manager.ensure(query, 'fts', 'FTS', { installTimeoutMs: 1234 })).resolves.toBe(
|
|
true,
|
|
);
|
|
|
|
expect(installExtension).toHaveBeenCalledWith('fts', 1234);
|
|
expect(query.mock.calls.map(([sql]) => sql)).toEqual([
|
|
'LOAD EXTENSION fts',
|
|
'LOAD EXTENSION fts',
|
|
]);
|
|
expect(query.mock.calls.some(([sql]) => String(sql).startsWith('INSTALL '))).toBe(false);
|
|
});
|
|
|
|
it('skips INSTALL and warns when policy=load-only', async () => {
|
|
const installExtension = vi.fn();
|
|
const warn = vi.fn();
|
|
const manager = new ExtensionManager({ policy: 'load-only', installExtension, warn });
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension "fts" not found'));
|
|
|
|
await expect(manager.ensure(query, 'fts', 'FTS')).resolves.toBe(false);
|
|
|
|
expect(installExtension).not.toHaveBeenCalled();
|
|
expect(warn).toHaveBeenCalledWith(expect.stringContaining('continuing without FTS features'));
|
|
expect(manager.getCapabilities()).toEqual([
|
|
{ name: 'fts', loaded: false, reason: expect.stringContaining('load-only') },
|
|
]);
|
|
});
|
|
|
|
it('short-circuits LOAD and INSTALL when policy=never', async () => {
|
|
const installExtension = vi.fn();
|
|
const warn = vi.fn();
|
|
const manager = new ExtensionManager({ policy: 'never', installExtension, warn });
|
|
const query = vi.fn();
|
|
|
|
await expect(manager.ensure(query, 'vector', 'VECTOR')).resolves.toBe(false);
|
|
|
|
expect(query).not.toHaveBeenCalled();
|
|
expect(installExtension).not.toHaveBeenCalled();
|
|
expect(warn).toHaveBeenCalledWith(
|
|
expect.stringContaining('continuing without VECTOR features'),
|
|
);
|
|
});
|
|
|
|
it('per-call options override manager defaults', async () => {
|
|
const installExtension = vi.fn().mockResolvedValue(okInstall);
|
|
const manager = new ExtensionManager({
|
|
policy: 'auto',
|
|
installExtension,
|
|
warn: noopWarn,
|
|
});
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension "vector" not found'));
|
|
|
|
await expect(manager.ensure(query, 'vector', 'VECTOR', { policy: 'load-only' })).resolves.toBe(
|
|
false,
|
|
);
|
|
|
|
expect(installExtension).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('returns false and warns when bounded install times out', async () => {
|
|
const installExtension = vi.fn().mockResolvedValue(timedOutInstall);
|
|
const warn = vi.fn();
|
|
const manager = new ExtensionManager({ policy: 'auto', installExtension, warn });
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension "vector" not found'));
|
|
|
|
await expect(manager.ensure(query, 'vector', 'VECTOR', { installTimeoutMs: 10 })).resolves.toBe(
|
|
false,
|
|
);
|
|
|
|
expect(query.mock.calls.map(([sql]) => sql)).toEqual(['LOAD EXTENSION vector']);
|
|
expect(warn).toHaveBeenCalledWith(
|
|
expect.stringContaining('continuing without VECTOR features'),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('ExtensionManager — caching', () => {
|
|
it('caches install attempt outcome to avoid retrying within the same process', async () => {
|
|
const installExtension = vi.fn().mockResolvedValue(timedOutInstall);
|
|
const manager = new ExtensionManager({
|
|
policy: 'auto',
|
|
installExtension,
|
|
warn: noopWarn,
|
|
});
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension "vector" not found'));
|
|
|
|
await expect(manager.ensure(query, 'vector', 'VECTOR')).resolves.toBe(false);
|
|
await expect(manager.ensure(query, 'vector', 'VECTOR')).resolves.toBe(false);
|
|
|
|
expect(installExtension).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('reset() clears capability and install state so install is retried', async () => {
|
|
const installExtension = vi.fn().mockResolvedValue(failedInstall);
|
|
const manager = new ExtensionManager({
|
|
policy: 'auto',
|
|
installExtension,
|
|
warn: noopWarn,
|
|
});
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension "fts" not found'));
|
|
|
|
await manager.ensure(query, 'fts', 'FTS');
|
|
expect(manager.getCapabilities()).toHaveLength(1);
|
|
|
|
manager.reset();
|
|
expect(manager.getCapabilities()).toEqual([]);
|
|
|
|
await manager.ensure(query, 'fts', 'FTS');
|
|
expect(installExtension).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|
|
|
|
describe('ExtensionManager — observability', () => {
|
|
it('exposes per-extension capability snapshot', async () => {
|
|
const manager = new ExtensionManager({ policy: 'load-only', warn: noopWarn });
|
|
const okQuery = vi.fn().mockResolvedValue({});
|
|
const failQuery = vi.fn().mockRejectedValue(new Error('Extension "vector" not found'));
|
|
|
|
await manager.ensure(okQuery, 'fts', 'FTS');
|
|
await manager.ensure(failQuery, 'vector', 'VECTOR');
|
|
|
|
expect(manager.getCapabilities()).toEqual([
|
|
{ name: 'fts', loaded: true },
|
|
{ name: 'vector', loaded: false, reason: expect.stringContaining('load-only') },
|
|
]);
|
|
});
|
|
|
|
it('warns at most once per (extension, reason) pair', async () => {
|
|
const installExtension = vi.fn();
|
|
const warn = vi.fn();
|
|
const manager = new ExtensionManager({ policy: 'load-only', installExtension, warn });
|
|
const query = vi.fn().mockRejectedValue(new Error('Extension "fts" not found'));
|
|
|
|
await manager.ensure(query, 'fts', 'FTS');
|
|
await manager.ensure(query, 'fts', 'FTS');
|
|
|
|
expect(warn).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
|
|
describe('ExtensionManager — input validation', () => {
|
|
it('rejects extension names that are not bare identifiers', async () => {
|
|
const manager = new ExtensionManager({ policy: 'auto' });
|
|
const query = vi.fn();
|
|
|
|
await expect(manager.ensure(query, 'fts; DROP TABLE x', 'FTS')).rejects.toThrow(/Invalid/);
|
|
expect(query).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('installDuckDbExtensionOutOfProcess child process', () => {
|
|
it('spawns the stable packaged installer script instead of inline -e code', () => {
|
|
const args = getExtensionInstallChildProcessArgs('fts');
|
|
|
|
expect(args).not.toContain('-e');
|
|
expect(args).not.toContain('--input-type=module');
|
|
expect(args[0]).toContain('scripts');
|
|
expect(args[0]).toContain('install-duckdb-extension.mjs');
|
|
expect(args[1]).toBe('fts');
|
|
expect(Number(args[2])).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('passes the resolved LadybugDB max DB size to the installer child', () => {
|
|
expect(getExtensionInstallChildProcessArgs('fts', 1234).at(-1)).toBe('1234');
|
|
});
|
|
});
|
|
|
|
describe('getExtensionInstallPolicy', () => {
|
|
it('defaults to load-only when env var is unset', () => {
|
|
const original = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
try {
|
|
expect(getExtensionInstallPolicy()).toBe('load-only');
|
|
} finally {
|
|
if (original === undefined) {
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
} else {
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = original;
|
|
}
|
|
}
|
|
});
|
|
|
|
it('returns auto when env var is set to auto', () => {
|
|
const original = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = 'auto';
|
|
try {
|
|
expect(getExtensionInstallPolicy()).toBe('auto');
|
|
} finally {
|
|
if (original === undefined) {
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
} else {
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = original;
|
|
}
|
|
}
|
|
});
|
|
|
|
it('returns never when env var is set to never', () => {
|
|
const original = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = 'never';
|
|
try {
|
|
expect(getExtensionInstallPolicy()).toBe('never');
|
|
} finally {
|
|
if (original === undefined) {
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
} else {
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = original;
|
|
}
|
|
}
|
|
});
|
|
|
|
it('falls back to load-only for invalid env var values', () => {
|
|
const original = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = 'bogus';
|
|
try {
|
|
expect(getExtensionInstallPolicy()).toBe('load-only');
|
|
} finally {
|
|
if (original === undefined) {
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL;
|
|
} else {
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL = original;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('getExtensionInstallTimeoutMs', () => {
|
|
it('reads a positive override from the environment', () => {
|
|
const original = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS;
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS = '42';
|
|
try {
|
|
expect(getExtensionInstallTimeoutMs()).toBe(42);
|
|
} finally {
|
|
if (original === undefined) {
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS;
|
|
} else {
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS = original;
|
|
}
|
|
}
|
|
});
|
|
|
|
it('falls back to the default when the env var is missing or invalid', () => {
|
|
const original = process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS;
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS;
|
|
try {
|
|
expect(getExtensionInstallTimeoutMs()).toBe(15_000);
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS = 'notanumber';
|
|
expect(getExtensionInstallTimeoutMs()).toBe(15_000);
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS = '0';
|
|
expect(getExtensionInstallTimeoutMs()).toBe(15_000);
|
|
} finally {
|
|
if (original === undefined) {
|
|
delete process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS;
|
|
} else {
|
|
process.env.GITNEXUS_LBUG_EXTENSION_INSTALL_TIMEOUT_MS = original;
|
|
}
|
|
}
|
|
});
|
|
});
|