Files
gbrain/test/autopilot-resolve-cli.test.ts
T
Garry TanandClaude Opus 4.7 27762abb7a Merge origin/master into garrytan/gbrain-evals
Master landed significant work since this branch was cut (v0.15.x → v0.16.x →
v0.17.0 gbrain dream + runCycle → v0.18.0 multi-source brains → v0.18.1 RLS
hardening). Bumped this branch's version from the claimed 0.18.0 to 0.19.0
because master already owns 0.18.x.

Conflicts resolved:
- VERSION: 0.19.0 (was 0.18.0 on HEAD vs 0.18.1 on master)
- package.json: 0.19.0, kept all 11 eval-facing exports, merged master's
  typescript devDep + postinstall script + test script (typecheck added)
- src/core/types.ts: union of both PageType additions. Master had added
  `meeting | note`; this branch added `email | slack | calendar-event`
  for inbox/chat/calendar ingest. Final enum carries all five.
- CHANGELOG.md: renumbered the BrainBench-extraction entry to 0.19.0 and
  placed it above master's 0.18.1 RLS entry. Tweaked copy ("In v0.17 it
  lived inside this repo" → "Previously it lived inside this repo") to
  stop implying a specific version that never shipped.
- CLAUDE.md: adjusted "BrainBench in a sibling repo" heading from
  (v0.18+) → (v0.19+).
- docs/benchmarks/2026-04-18-minions-vs-openclaw-production.md:
  resolved modify-vs-delete conflict in favor of delete (the extraction).
- scripts/llms-config.ts: dropped the docs/benchmarks/ entry (directory
  no longer exists here; lives in gbrain-evals).
- llms.txt / llms-full.txt: regenerated after the config change.
- bun.lock: accepted master's (master already dropped pdf-parse as a
  drive-by; aligned with our removal).

Tests: 2094 pass, 236 skip, 18 fail. Spot-checked failures — build-llms,
dream, orphans tests all pass in isolation. Failures reproduce only under
full-suite parallel load and are pre-existing master flakiness (matches the
graph-quality flake noted in the earlier summary). Not merge-introduced.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 10:45:02 -07:00

84 lines
3.4 KiB
TypeScript

/**
* Tests for resolveGbrainCliPath() — picks the right executable to supervise
* as the Minions worker child.
*
* Iron rule (regression guard for Bug 4, v0.14.0 upgrade night): the resolver
* must NEVER return a `.ts` path. TypeScript source files are not executable;
* spawning them fails with EACCES and autopilot silently loses its worker.
* Earlier versions short-circuited on `argv[1].endsWith('/cli.ts')`, which
* caused the bug. The canonical resolution is the `gbrain` shim on PATH.
*/
import { describe, test, expect } from 'bun:test';
import { resolveGbrainCliPath } from '../src/commands/autopilot.ts';
describe('resolveGbrainCliPath', () => {
test('returns a non-empty string or throws with a clear install hint', () => {
let path: string;
try {
path = resolveGbrainCliPath();
} catch (e) {
// Machine without gbrain on PATH and no compiled binary: throw is
// expected. The error message must point the user at the install step.
expect((e as Error).message).toMatch(/PATH|resolve/i);
return;
}
expect(typeof path).toBe('string');
expect(path.length).toBeGreaterThan(0);
});
test('NEVER returns a path ending in .ts (regression guard — Bug 4)', () => {
// Simulate the exact production break: bun-source install puts
// `/path/to/src/cli.ts` in argv[1]. The resolver must not hand that back.
const origArg1 = process.argv[1];
const origExec = (process as { execPath?: string }).execPath;
process.argv[1] = '/some/project/src/cli.ts';
try {
const path = resolveGbrainCliPath();
// Either we got a real executable (shim on PATH from the test machine)
// or the throw path fires. Either way, the return value is never .ts.
expect(path.endsWith('.ts')).toBe(false);
expect(path.endsWith('.tsx')).toBe(false);
} catch (e) {
expect((e as Error).message).toMatch(/PATH|resolve/i);
} finally {
process.argv[1] = origArg1;
if (origExec) (process as { execPath?: string }).execPath = origExec;
}
});
test('shim on PATH wins over argv[1]=cli.ts', () => {
// If `which gbrain` resolves (most dev machines), the resolver should
// return that shim path, not argv[1]=cli.ts. This is the canonical
// install shape.
const origArg1 = process.argv[1];
process.argv[1] = '/some/project/src/cli.ts';
try {
const path = resolveGbrainCliPath();
// On a machine where `which gbrain` resolves, path ends in /gbrain.
// On a machine without, we throw. Both outcomes prove the resolver
// did not short-circuit on the .ts suffix.
expect(path.endsWith('/cli.ts')).toBe(false);
} catch (e) {
expect((e as Error).message).toMatch(/PATH|resolve/i);
} finally {
process.argv[1] = origArg1;
}
});
test('accepts argv[1]=/gbrain when shim is absent (compiled binary)', () => {
// If the machine has neither shim nor compiled exec, but argv[1]
// happens to be a literal /gbrain path (direct invocation), accept it.
const origArg1 = process.argv[1];
process.argv[1] = '/usr/local/bin/gbrain';
try {
const path = resolveGbrainCliPath();
// On a machine with `which gbrain`, we get the shim. On a machine
// without, argv[1] fallback fires. Either way the result is valid.
expect(path.endsWith('/gbrain') || path.endsWith('\\gbrain.exe')).toBe(true);
} finally {
process.argv[1] = origArg1;
}
});
});