Files
gbrain/test/status-autopilot-lock.test.ts
testandGBrain Contributor 5087507de0 fix(autopilot): ignore foreign PIDs in stale locks (#2503) (#3860)
Wave-assembled from PR #3860 by @javieraldape.

Co-Authored-By: GBrain Contributor <contributor@example.com>
2026-08-13 12:18:13 -07:00

46 lines
1.3 KiB
TypeScript

import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { buildAutopilotStatus } from '../src/commands/status.ts';
let tmp: string;
let lockPath: string;
beforeEach(() => {
tmp = mkdtempSync(join(tmpdir(), 'gbrain-status-autopilot-lock-'));
lockPath = join(tmp, 'autopilot.lock');
});
afterEach(() => {
rmSync(tmp, { recursive: true, force: true });
});
describe('buildAutopilotStatus', () => {
test('reports a reused foreign PID lock as stale, not running', () => {
writeFileSync(lockPath, '1234');
const status = buildAutopilotStatus(lockPath, {
isPidAlive: (pid) => pid === 1234,
readProcessCommand: () => '/sbin/launchd',
});
expect(status).toEqual({
installed: true,
lockfile_present: true,
pid: 1234,
running: false,
});
});
test('reports a live gbrain autopilot process as running', () => {
writeFileSync(lockPath, '1234');
const status = buildAutopilotStatus(lockPath, {
isPidAlive: (pid) => pid === 1234,
readProcessCommand: () => 'gbrain autopilot --repo repo',
});
expect(status.running).toBe(true);
expect(status.pid).toBe(1234);
});
});