mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 20:49:41 +02:00
Post-merge follow-ups for PR #329 (shared CLI executable resolution): - Negative-cache resolution misses with a doubling backoff (1min -> 5min cap, cliResolveRetryDelayMs, mirroring claudeVersionRetryDelayMs): the shared resolver cached success only, so a missing CLI re-ran the whole chain - ending in a synchronous interactive login-shell spawn bounded by the 5s EXEC_TIMEOUT_MS - on every /api/<cli>/status request and Run attempt, stalling the event loop each time, forever. Success still caches for the process lifetime, so an installed CLI is picked up within minutes without a restart. Tests drive the backoff via an injectable clock (createCliExecutableResolver `now` option, threaded through the createPiResolverForTest / createAntigravityResolverForTest wrappers). - Pass killSignal: 'SIGKILL' on the resolver's login-shell spawn and on the pi/claude --version probes: execFileSync's timeout only SENDS the kill signal and then keeps waiting for the child to exit, and interactive bash ignores SIGTERM, so a login shell stuck in a blocking .bash_profile survived the timeout and blocked the server permanently. - Restore test hermeticity (PR #329 deleted pi's VITEST guards, and one test pinned the deletion): under vitest the production resolver host now replaces un-injected IO primitives with inert stubs - no real PATH scanning, no login-shell spawns - and probePiVersion never executes a `pi` candidate again (`pi` is a generic binary name, so route tests hitting /api/pi/status executed whatever binary the machine carried). Tests opt in through the runCommand/isExecutableFile injection hooks or allowRealIoUnderVitest for real-filesystem fixtures. The deletion-pinning test is replaced by behavioral pins, including a real-executable fixture in the new test/pi-cli-resolver.test.ts that fails loudly if the pi gate is ever removed again. - Wire the six get*NotFoundMessage() exports (previously dead) into their intended call sites: the createSession throws in tmux-manager and the availability gates on POST /api/sessions and POST /api/quick-start in session-routes, replacing a third hardcoded copy of the text. A not-found error now names where resolution looked (server PATH, login shell, checked directories). npm run knip no longer reports any unused export from the resolver modules. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
122 lines
4.2 KiB
TypeScript
122 lines
4.2 KiB
TypeScript
/**
|
|
* @fileoverview Tests for the Antigravity CLI resolver wrapper.
|
|
*/
|
|
import { homedir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { createAntigravityResolverForTest, isAntigravityAvailable } from '../src/utils/antigravity-cli-resolver.js';
|
|
import {
|
|
cliResolveRetryDelayMs,
|
|
type CliResolution,
|
|
type CliResolverHost,
|
|
} from '../src/utils/cli-executable-resolver.js';
|
|
|
|
const availabilityResolution = vi.hoisted(() => ({ current: null as CliResolution | null }));
|
|
|
|
vi.mock('../src/utils/cli-executable-resolver.js', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('../src/utils/cli-executable-resolver.js')>();
|
|
return {
|
|
...actual,
|
|
createCliExecutableResolver: (options: { binary: string; searchDirs: string[] }, host?: CliResolverHost) =>
|
|
host
|
|
? actual.createCliExecutableResolver(options, host)
|
|
: {
|
|
resolve: () => availabilityResolution.current,
|
|
diagnostics: () => ({
|
|
binary: options.binary,
|
|
processPath: '/service/bin',
|
|
shellPath: '/bin/zsh',
|
|
shellArgs: ['-l'],
|
|
searchDirs: [...options.searchDirs],
|
|
}),
|
|
},
|
|
};
|
|
});
|
|
|
|
function createHost(
|
|
options: {
|
|
processPathResult?: string | null;
|
|
loginShellResults?: Array<string | null>;
|
|
existingPaths?: string[];
|
|
} = {}
|
|
): CliResolverHost {
|
|
const loginShellResults = [...(options.loginShellResults ?? [])];
|
|
const existingPaths = new Set(options.existingPaths ?? []);
|
|
return {
|
|
processPath: '/service/bin',
|
|
shellPath: '/bin/zsh',
|
|
shellArgs: ['-l'],
|
|
findOnProcessPath: () => options.processPathResult ?? null,
|
|
findInLoginShell: () => loginShellResults.shift() ?? null,
|
|
exists: (path) => existingPaths.has(path),
|
|
};
|
|
}
|
|
|
|
describe('Antigravity CLI resolver', () => {
|
|
beforeEach(() => {
|
|
availabilityResolution.current = null;
|
|
});
|
|
|
|
it('resolves agy from the service PATH', () => {
|
|
const binaryPath = '/service/bin/agy';
|
|
const resolver = createAntigravityResolverForTest(
|
|
createHost({ processPathResult: binaryPath, existingPaths: [binaryPath] })
|
|
);
|
|
|
|
expect(resolver.resolve()?.directory).toBe('/service/bin');
|
|
});
|
|
|
|
it('falls back to a common install directory', () => {
|
|
const binaryPath = join(homedir(), '.local', 'bin', 'agy');
|
|
const resolver = createAntigravityResolverForTest(createHost({ existingPaths: [binaryPath] }));
|
|
|
|
expect(resolver.resolve()?.directory).toBe(join(homedir(), '.local', 'bin'));
|
|
});
|
|
|
|
it('resolves agy found only by the login shell', () => {
|
|
const binaryPath = '/login-shell/bin/agy';
|
|
const resolver = createAntigravityResolverForTest(
|
|
createHost({ loginShellResults: [binaryPath], existingPaths: [binaryPath] })
|
|
);
|
|
|
|
expect(resolver.resolve()?.directory).toBe('/login-shell/bin');
|
|
});
|
|
|
|
it('returns null when agy is unavailable', () => {
|
|
const resolver = createAntigravityResolverForTest(createHost());
|
|
|
|
expect(resolver.resolve()).toBeNull();
|
|
});
|
|
|
|
it('retries a failed lookup after the backoff and caches the first successful login-shell discovery', () => {
|
|
const binaryPath = '/late-login-shell/bin/agy';
|
|
let now = 0;
|
|
const resolver = createAntigravityResolverForTest(
|
|
createHost({ loginShellResults: [null, binaryPath], existingPaths: [binaryPath] }),
|
|
() => now
|
|
);
|
|
|
|
expect(resolver.resolve()).toBeNull();
|
|
// A miss is negative-cached: within the backoff window nothing re-runs the
|
|
// chain (its login-shell tail is a synchronous bounded spawn in production).
|
|
expect(resolver.resolve()).toBeNull();
|
|
now = cliResolveRetryDelayMs(1);
|
|
expect(resolver.resolve()?.binaryPath).toBe(binaryPath);
|
|
expect(resolver.resolve()?.binaryPath).toBe(binaryPath);
|
|
});
|
|
|
|
it('reports the public wrapper as available when agy resolves', () => {
|
|
availabilityResolution.current = {
|
|
binaryPath: '/service/bin/agy',
|
|
directory: '/service/bin',
|
|
source: 'process-path',
|
|
};
|
|
|
|
expect(isAntigravityAvailable()).toBe(true);
|
|
});
|
|
|
|
it('reports the public wrapper as unavailable when agy does not resolve', () => {
|
|
expect(isAntigravityAvailable()).toBe(false);
|
|
});
|
|
});
|