GitNexus/gitnexus/test/unit/cli-entry.test.ts
Gergő Magyar ddc0632df7
fix(analyze): harden recovery, vector readiness, and RAM admission (#3842)
* fix(analyze): harden recovery and query state

* fix(analyze): bound automatic admission (U7)

* refactor: remove redundant review comments

* fix: preserve reads during count recovery

Keep capability receipts unverified until count repair. Align memory defaults in the README with aggregate admission. Refs #3842.

* test: isolate admission and cover watch heap

Exercise the real watch admission and refresh path, including environment restoration. Pin the local provider in heap-rejection cases. Refs #3842.

* test: run parser drain checks after build

Move the real-worker drain regression to the integration tier, whose pretest hook builds the worker. Keep it in the cross-platform matrix. Refs #3842.

* fix: qualify memory admission guidance

* fix: enforce admitted analysis allocations

* fix: complete checkpoint test fixtures

* test: use admitted heaps in CLI fixtures

* test: auto-size package smoke memory

* fix: handle Windows probe and cleanup delays

---------

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

107 lines
3.3 KiB
TypeScript

/**
* Locks the CLI-spawn entry-point resolution used by every e2e/integration suite
* (test/helpers/cli-entry.ts). The branch logic decides whether tests exercise the
* built `dist/cli/index.js` or tsx-on-source, so a regression here silently changes
* what every spawn-based test actually runs — worth a direct, env-free unit test.
*/
import { afterEach, describe, it, expect, vi } from 'vitest';
import { cliAnalysisEnv, computeSpawnPrefix, CLI_SPAWN_PREFIX } from '../helpers/cli-entry.js';
const DIST = '/repo/dist/cli/index.js';
const SRC = '/repo/src/cli/index.ts';
const TSX = 'file:///repo/node_modules/tsx/dist/loader.mjs';
describe('cliAnalysisEnv', () => {
afterEach(() => vi.unstubAllEnvs());
it('keeps Vitest manual mode out of real CLI children without changing the parent', () => {
vi.stubEnv('GITNEXUS_MEMORY', 'off');
expect(cliAnalysisEnv().GITNEXUS_MEMORY).toBeUndefined();
expect(process.env.GITNEXUS_MEMORY).toBe('off');
});
it('preserves an explicit per-case memory policy', () => {
expect(cliAnalysisEnv({ GITNEXUS_MEMORY: 'off' }).GITNEXUS_MEMORY).toBe('off');
});
});
describe('computeSpawnPrefix', () => {
it('selects the built dist entry when mode=dist and dist exists', () => {
expect(
computeSpawnPrefix({
mode: 'dist',
distEntry: DIST,
srcEntry: SRC,
distExists: true,
tsxLoaderUrl: TSX,
}),
).toEqual([DIST]);
});
it('throws an actionable "run npm run build" error when mode=dist but dist is missing', () => {
expect(() =>
computeSpawnPrefix({
mode: 'dist',
distEntry: DIST,
srcEntry: SRC,
distExists: false,
tsxLoaderUrl: TSX,
}),
).toThrow(/run `npm run build`/);
});
it('falls back to tsx-on-source when mode is unset (the local default)', () => {
expect(
computeSpawnPrefix({
mode: undefined,
distEntry: DIST,
srcEntry: SRC,
distExists: false,
tsxLoaderUrl: TSX,
}),
).toEqual(['--import', TSX, SRC]);
});
it('forces tsx-on-source when mode=src even if dist exists', () => {
expect(
computeSpawnPrefix({
mode: 'src',
distEntry: DIST,
srcEntry: SRC,
distExists: true,
tsxLoaderUrl: TSX,
}),
).toEqual(['--import', TSX, SRC]);
});
it('throws on an unknown mode — never dist without opt-in, never a silent tsx fallback', () => {
expect(() =>
computeSpawnPrefix({
mode: 'production',
distEntry: DIST,
srcEntry: SRC,
distExists: true,
tsxLoaderUrl: TSX,
}),
).toThrow(/Unknown GITNEXUS_E2E_CLI/);
});
it('ignores distExists off the dist branch (mode unset, dist present) — still tsx', () => {
expect(
computeSpawnPrefix({
mode: undefined,
distEntry: DIST,
srcEntry: SRC,
distExists: true,
tsxLoaderUrl: TSX,
}),
).toEqual(['--import', TSX, SRC]);
});
});
describe('CLI_SPAWN_PREFIX (resolved from the current environment)', () => {
it('is a non-empty argv prefix ending at a gitnexus CLI entry point', () => {
expect(CLI_SPAWN_PREFIX.length).toBeGreaterThan(0);
expect(CLI_SPAWN_PREFIX[CLI_SPAWN_PREFIX.length - 1]).toMatch(/cli[/\\]index\.(ts|js)$/);
});
});