mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-14 00:48:18 +00:00
* feat(bootstrap): TTY DX exploration harness + Krug onboarding fix wave Add a real-PTY exploration harness and land 16 verified "Don't Make Me Think" fixes on the paste-in install experience for Claude Code and Codex. Harness: - test/helpers/tty-harness.ts — spawns any CLI (gbrain/claude/codex) under a real pseudo-terminal (Bun terminal: spawn), timestamps every output burst, and turns silence windows into a measurable stall report. Hermetic; pure helpers unit-tested in test/tty-harness.test.ts. - scripts/dx-explore.ts — drives the fresh-user funnel (help / init / real claude-install / real codex-install / manual drive mode), writing transcripts to .context/dx-runs/ (gitignored). Fixes (all adversarially verified against the code first): - Keyless bare `gbrain init` completes in keyless mode instead of exit 1; multi-key non-TTY auto-picks the canonical default; typo stays fail-loud. - Provider picker probe-gates ollama (daemon-up != model-pulled) and offers an explicit "continue keyless" option that is the bare-Enter default. - Fresh-brain init prints one schema-setup line instead of ~240 migration names (GBRAIN_MIGRATE_VERBOSE=1 restores detail). - Init epilogue: memory-verbs funnel is last-on-screen; skills advisory compacted for init; Mod Status trimmed. - PGLite live-serve lock error names the fix (close the agent session). - Mode-picker banner interpolates the applied mode; expansion-key gate is Anthropic/OpenAI/Google, not OpenAI-only. - Missing `claude` binary skips MCP but still installs hooks; honest copy. - Foreign MCP-registration removal targets the conflicting scope and fails loud if it does not land. - Upgrade marker compares the running binary to latest and self-spawns via execPath, so a current/newer binary no longer nags from a stale cache. - interview --set/--skip after --confirm warns it voided the confirmation. - init --help matches behavior; init --supabase fails loud on non-TTY. - Provider capabilities attributed per provider across README / runbook / questions bank / bootstrap.md. - First-run tour: restart-first, prompt 3 true on day one, withheld on FAIL; README gives Codex the same scripted magic moment. - Empty-brain "0 takes" onboard nudge suppressed. - Broken settings.local.json aborts the hooks write fail-closed instead of silently dropping the user's permissions. Regenerated cli-flag-registry.generated.ts and llms-full.txt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(bootstrap): second DX polish wave — clean the success screen + honest copy (F17-F21) Follow-up to the DX fix wave, closing the top-5 remaining gaps the scorecard flagged (all human-facing polish, not survival): F17 — machine markers no longer leak to humans: - verify report drops the `[D3.6]` plan-tag from the first_run_tour detail. - the raw `UPGRADE_AVAILABLE <cur> <latest>` marker line prints ONLY on a non-TTY stderr (parsers still get it); an interactive human sees just the "gbrain X -> Y available" sentence. - per-migration "what changed" notices (v123/v124, incl. the #2704 ref) are suppressed on a FRESH-install replay via a module quiet flag; upgrades still narrate. (GBRAIN_MIGRATE_VERBOSE=1 restores them.) F18 — one obvious next action on the init success screen: the memory-verbs demo is the single "→ Do this next" hero, last on screen; import/migrate/doctor collapse into one terse "More:" footer; the graph block only shows for a non-empty brain. F19 — README "moment it clicks" is now the genuine cross-session brain round-trip (remember → restart → recall), explicitly distinguished from the identity-file recall, on both the Codex and Claude Code paths. F20 — the compact init skills advisory is human-voiced (no `[AGENT]` stage-direction on the human-facing success screen; the mode-picker's agent-directed block stays gated to the non-TTY channel). F21 — time promise reconciled: headline is ~15 min (personal-agent path) / ~30 min (always-on OpenClaw/Hermes); the runbook's search-mode line no longer claims "balanced" when keyless applies "conservative". README hooks copy says "on by default, with an opt-out" to match the runbook. Regenerated llms-full.txt. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(bootstrap): address two-model adversarial review of the DX wave Fixes the regressions the 5-specialist + red-team + Claude/Codex adversarial pass found in the F1–F21 changes, each with a test: - Keyless upgrade hint pointed at `config set embedding_model`, which config.ts hard-refuses as a schema-sizing no-op — now names the working re-init recipe (`gbrain init --force --pglite --embedding-model <id>`), zero-key AND multi-key paths. - Multi-key TTY picker offered "continue keyless" but the caller aborted on it — now honors keyless like the zero-key path. - Detached update-refresh spawn used a `/gbrain$/` basename check that misfires for a renamed/official-named compiled binary (`gbrain-darwin-arm64`) and prepends the /$bunfs entrypoint — now detects dev-vs-compiled by the runtime basename (bun|node) so the refresh always runs. - `bootstrap status` reported the wire phase "done" on a hooks-only receipt (host CLI missing at wire time) — now "partial" with a re-run hint, so a resuming agent doesn't trust a false complete. - Post-repair MCP mismatch re-verifies and aborts instead of blessing a registration a racing writer may have re-claimed. - probeOpenAICompat's abort timer now spans the body read (was cleared before it), so a stalled `/v1/models` body can't hang init past the 1s cap. - Centralized the 4-copy stale-cache upgrade predicate into `pendingUpgradeVersion`; UPGRADE_AVAILABLE gains a GBRAIN_FORCE_UPGRADE_MARKER override for PTY-based agent harnesses. - Mode picker's expansion-key gate adds GEMINI_API_KEY; picker prompt is article-aware ("an embedding" / "a chat"); dead `!brainEmpty` clause removed; migrate.ts try/finally widened + stamp failures named in quiet mode. - DX harness: credential copies scrubbed even on SIGINT/interrupt (+chmod 600), child process TREE reaped on teardown, advisory made fail-open, KEY_MAP typed as a literal union. New tests: migrate quiet-replay, self-upgrade pending predicate + negative cache cases, bootstrap 127/scoped-remove/broken-settings dispatch, interview invalidation flag, verify tour-withheld-on-FAIL, init keyless/supabase/multi-key, init-nudge branches, ai-probes model parsing. Regenerated flag registry + template-repo. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * v0.45.8.0 fix(bootstrap): onboarding DX polish wave (F17-F21) + review fixes DX fix wave on the paste-in install/first-run experience for Claude Code and Codex, driven by a new real-PTY exploration harness. Keyless init completes instead of erroring, the migration wall collapses to one line, the success screen leads with one action, and the "magic moment" copy points at the genuine cross-session round-trip. Full detail in CHANGELOG. Version trio + openclaw manifest + runbook stamp bumped to 0.45.8.0; CHANGELOG release entry; TODOS onboarding-DX follow-ups filed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(bootstrap): OOBE hand-off — you own the brain, cold-start is skill #1 A working install now ends by making the two facts that matter actually land: - `gbrain bootstrap verify` prints (and returns as `handoff` in --json) an ownership block — the actual private-repo URL with what owning it means (read it, `gbrain bootstrap attach` on machine two, delete it and the brain is gone), or the local-only variant pointing at `gbrain bootstrap repo` — followed by the ONE next action: run the cold-start skill (Gmail/calendar/ contacts via ClawVisor, an OAuth vault so the agent never holds raw tokens; or offline archives), one consented phase at a time. Withheld on FAIL like the tour; shape stays unconditional for machine consumers. - cold-start ships in the downstream bundle (61 skills): its plugin exclusion ("host onboarding flow") predated the v0.45 personal-agent bootstrap and is deliberately reversed — the paste-in audience is exactly who day-one onboarding is for. It now LEADS the recommended set (ahead of book-mirror: every flagship skill only becomes magical once the brain holds the user's real life). - New drift guard: every recommended slug must be scaffoldable from the plugin bundle — recommended-but-unscaffoldable is a dead-end CTA and now fails the suite. - Runbook Hand off rewritten around the two must-land facts + the on-the-spot cold-start offer; README's Codex and Claude Code paths carry the same two follow-ups. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * v0.45.10.0 feat(bootstrap): the OOBE hand-off release Version trio + runbook stamp + template tree to 0.45.10.0; CHANGELOG entry; llms bundles regenerated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(ci): stop memory-verbs-conformance leaking a fake-keyed gateway into shard-mates The deterministic-embedder helper configures the MODULE-GLOBAL gateway with a fake OpenAI key; the file's afterAll never reset it. The bunfig preload's per-test restore only fires when the gateway is UNCONFIGURED, so the fake-keyed config persisted for every later file in the shard process — turn-context's corpus writes then embedded against real OpenAI and 401'd (CI shard-8 failure; shard re-binning from this branch's new test files exposed it). Fix both sides: conformance's afterAll now resetGateway()s back to the preload baseline and nulls both test transports; turn-context's beforeAll does the same defensively so it stays hermetic regardless of shard composition. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
373 lines
16 KiB
TypeScript
373 lines
16 KiB
TypeScript
/**
|
|
* T12 — fresh PGLite init E2E for the v0.37 env-detection + picker + D6 wave.
|
|
*
|
|
* Subprocess-driven so we exercise the real CLI argv parsing, env handling,
|
|
* exit codes, and config persistence — exactly the failure modes the bug
|
|
* reporter hit. Each test gets its own throw-away `GBRAIN_HOME` so test runs
|
|
* are hermetic.
|
|
*
|
|
* Scope covered:
|
|
* - Happy path: OPENAI_API_KEY set → auto-pick OpenAI, persists embedding_model + dim
|
|
* - Fail-loud non-TTY no-key (D3 regression)
|
|
* - D6 regression: bug-reporter's three no-op config keys exit 1 with Levenshtein
|
|
* - `--no-embedding` D9 opt-in: init succeeds with sentinel; gbrain import refuses
|
|
* - D11 preflight: explicit bad --embedding-dimensions refuses BEFORE touching disk
|
|
*
|
|
* Picker interactive flow (multi-key TTY) needs the real-PTY harness from
|
|
* test/helpers/cli-pty-runner.ts — that path is exercised by the unit tests
|
|
* for `init-provider-picker.ts` (T4) plus the env-detection helpers (T5).
|
|
* Adding PTY here is mostly orthogonal scope.
|
|
*/
|
|
|
|
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
|
|
import { mkdtempSync, rmSync, existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
|
|
import { tmpdir } from 'os';
|
|
import { join } from 'path';
|
|
|
|
const REPO_ROOT = join(import.meta.dir, '..', '..');
|
|
const CLI = `bun run ${REPO_ROOT}/src/cli.ts`;
|
|
|
|
/** Run a CLI invocation with a clean GBRAIN_HOME + chosen env. Returns { stdout, stderr, exitCode }. */
|
|
async function runCli(args: string[], opts: { env?: NodeJS.ProcessEnv; gbrainHome: string; cwd?: string; stdinIsTTY?: boolean } = { gbrainHome: '' }): Promise<{ stdout: string; stderr: string; exitCode: number }> {
|
|
const { spawn } = await import('child_process');
|
|
return new Promise((resolve) => {
|
|
const child = spawn('bun', ['run', `${REPO_ROOT}/src/cli.ts`, ...args], {
|
|
env: {
|
|
// Start from a minimal env to avoid the ambient host env (which
|
|
// might have OPENAI_API_KEY already set, contaminating our tests).
|
|
PATH: process.env.PATH,
|
|
HOME: process.env.HOME,
|
|
// GBRAIN_HOME isolates state per test.
|
|
GBRAIN_HOME: opts.gbrainHome,
|
|
...opts.env,
|
|
},
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
cwd: opts.cwd ?? REPO_ROOT,
|
|
});
|
|
let stdout = '';
|
|
let stderr = '';
|
|
child.stdout?.on('data', (b) => { stdout += b.toString(); });
|
|
child.stderr?.on('data', (b) => { stderr += b.toString(); });
|
|
child.on('close', (code) => {
|
|
resolve({ stdout, stderr, exitCode: code ?? -1 });
|
|
});
|
|
});
|
|
}
|
|
|
|
function makeTempHome(): string {
|
|
return mkdtempSync(join(tmpdir(), 'gbrain-e2e-init-'));
|
|
}
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.37 T12 — fresh init env-detection (D1, D2, D3) + persistence (D5)', () => {
|
|
let tmpHome: string;
|
|
|
|
beforeAll(() => { tmpHome = makeTempHome(); });
|
|
afterAll(() => { rmSync(tmpHome, { recursive: true, force: true }); });
|
|
|
|
test('OPENAI_API_KEY auto-picks OpenAI, persists embedding_model + embedding_dimensions', async () => {
|
|
const r = await runCli(['init', '--pglite'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test-only-for-init-resolution-NOT-CALLED' },
|
|
});
|
|
// Init may or may not succeed (depends on whether OpenAI key is real for
|
|
// any side effect — but init.ts has no live embed call, just config
|
|
// writes + schema). Assert the auto-pick stderr notice fired.
|
|
expect(r.stderr).toMatch(/Detected OPENAI_API_KEY|Using openai:text-embedding-3-large/);
|
|
expect(r.exitCode).toBe(0);
|
|
|
|
// Config persisted with the right embedding fields.
|
|
const cfgPath = join(tmpHome, '.gbrain', 'config.json');
|
|
expect(existsSync(cfgPath)).toBe(true);
|
|
const cfg = JSON.parse(readFileSync(cfgPath, 'utf-8'));
|
|
expect(cfg.embedding_model).toBe('openai:text-embedding-3-large');
|
|
expect(cfg.embedding_dimensions).toBe(1536);
|
|
expect(cfg.engine).toBe('pglite');
|
|
}, 240000);
|
|
});
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.45 DX wave — non-TTY no-key defaults to keyless (typo still fail-loud)', () => {
|
|
let tmpHome: string;
|
|
let typoHome: string;
|
|
|
|
beforeAll(() => { tmpHome = makeTempHome(); typoHome = makeTempHome(); });
|
|
afterAll(() => {
|
|
rmSync(tmpHome, { recursive: true, force: true });
|
|
rmSync(typoHome, { recursive: true, force: true });
|
|
});
|
|
|
|
test('--non-interactive with zero provider keys → keyless init succeeds with loud notice', async () => {
|
|
const r = await runCli(['init', '--pglite', '--non-interactive'], {
|
|
gbrainHome: tmpHome,
|
|
env: {}, // no provider keys
|
|
});
|
|
// Keyless is a first-class posture: the naive first command completes.
|
|
expect(r.exitCode).toBe(0);
|
|
expect(r.stderr).toContain('keyless mode');
|
|
// The notice names the upgrade affordance — the re-init recipe that
|
|
// actually works, NOT `config set embedding_model` (which config.ts
|
|
// hard-refuses as a schema-sizing no-op).
|
|
expect(r.stderr).toContain('gbrain init --force --pglite --embedding-model');
|
|
expect(r.stderr).not.toContain('config set embedding_model');
|
|
// Config persisted with the deferred-embedding sentinel.
|
|
const cfg = JSON.parse(readFileSync(join(tmpHome, '.gbrain', 'config.json'), 'utf-8'));
|
|
expect(cfg.embedding_disabled).toBe(true);
|
|
expect(cfg.engine).toBe('pglite');
|
|
}, 240000);
|
|
|
|
test('--non-interactive with env-key typo stays fail-loud with Levenshtein hint', async () => {
|
|
const r = await runCli(['init', '--pglite', '--non-interactive'], {
|
|
gbrainHome: typoHome,
|
|
env: { OPENAPI_API_KEY: 'sk-test-typo' },
|
|
});
|
|
// A near-miss key signals the user MEANT to configure a provider —
|
|
// completing keyless would silently bury their typo.
|
|
expect(r.exitCode).toBe(1);
|
|
// D13 typo detection: surfaces "did you mean OPENAI_API_KEY"
|
|
expect(r.stderr).toMatch(/did you mean OPENAI_API_KEY/i);
|
|
// The hint leads with the keyless-continue option.
|
|
expect(r.stderr).toContain('--no-embedding');
|
|
}, 60000);
|
|
|
|
test('--non-interactive with multiple provider keys auto-picks the canonical default', async () => {
|
|
const multiHome = makeTempHome();
|
|
try {
|
|
const r = await runCli(['init', '--pglite', '--non-interactive'], {
|
|
gbrainHome: multiHome,
|
|
env: {
|
|
OPENAI_API_KEY: 'sk-test-only-for-init-resolution-NOT-CALLED',
|
|
ZEROENTROPY_API_KEY: 'ze-test-only-for-init-resolution-NOT-CALLED',
|
|
},
|
|
});
|
|
expect(r.exitCode).toBe(0);
|
|
expect(r.stderr).toContain('Multiple embedding providers env-ready');
|
|
expect(r.stderr).toContain('Override with --embedding-model');
|
|
const cfg = JSON.parse(readFileSync(join(multiHome, '.gbrain', 'config.json'), 'utf-8'));
|
|
// Canonical default (DEFAULT_EMBEDDING_MODEL) wins when its key is present.
|
|
expect(cfg.embedding_model).toBe('zeroentropyai:zembed-1');
|
|
} finally {
|
|
rmSync(multiHome, { recursive: true, force: true });
|
|
}
|
|
}, 240000);
|
|
});
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.45 DX wave — --supabase non-TTY guard + multi-key no-canonical fail-loud', () => {
|
|
test('init --supabase without a TTY fails loud and names the --url escape hatch', async () => {
|
|
// Legacy behavior was a silent exit-0 no-op (stdin closed → readLine
|
|
// never resolved → process ended with NO config written) — the worst
|
|
// failure shape for a scripted/agent caller.
|
|
const home = makeTempHome();
|
|
try {
|
|
const r = await runCli(['init', '--supabase'], { gbrainHome: home, env: {} });
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toContain('needs an interactive terminal');
|
|
expect(r.stderr).toContain('--url');
|
|
} finally {
|
|
rmSync(home, { recursive: true, force: true });
|
|
}
|
|
}, 120000);
|
|
|
|
test('multiple provider keys with NO canonical candidate stays fail-loud with disambiguation hint', async () => {
|
|
// The canonical default provider (zeroentropyai) has no key here, so the
|
|
// non-TTY auto-pick cannot resolve the ambiguity — it must fail loud
|
|
// (D2/D3), not guess between openai and voyage.
|
|
const home = makeTempHome();
|
|
try {
|
|
const r = await runCli(['init', '--pglite', '--non-interactive'], {
|
|
gbrainHome: home,
|
|
env: {
|
|
OPENAI_API_KEY: 'sk-test-only-for-init-resolution-NOT-CALLED',
|
|
VOYAGE_API_KEY: 'pa-test-only-for-init-resolution-NOT-CALLED',
|
|
},
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toMatch(/Multiple embedding providers env-ready/);
|
|
expect(r.stderr).toMatch(/Disambiguate by passing --embedding-model/);
|
|
// Fail-loud path exits BEFORE any config write.
|
|
expect(existsSync(join(home, '.gbrain', 'config.json'))).toBe(false);
|
|
} finally {
|
|
rmSync(home, { recursive: true, force: true });
|
|
}
|
|
}, 120000);
|
|
});
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.37 T12 — D6 regression: bug-reporter no-op keys exit 1 with Levenshtein', () => {
|
|
let tmpHome: string;
|
|
|
|
beforeAll(async () => {
|
|
tmpHome = makeTempHome();
|
|
// Bootstrap a brain so `gbrain config set` has somewhere to write.
|
|
await runCli(['init', '--pglite', '--embedding-model', 'openai:text-embedding-3-large'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
});
|
|
afterAll(() => { rmSync(tmpHome, { recursive: true, force: true }); });
|
|
|
|
test('gbrain config set embedding.provider openai → exit 1 with suggestion', async () => {
|
|
const r = await runCli(['config', 'set', 'embedding.provider', 'openai'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toContain('Unknown config key');
|
|
}, 60000);
|
|
|
|
test('gbrain config set embedding.model openai:text-embedding-3-large → suggests embedding_model', async () => {
|
|
const r = await runCli(['config', 'set', 'embedding.model', 'openai:text-embedding-3-large'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toMatch(/Did you mean "embedding_model"/);
|
|
}, 60000);
|
|
|
|
test('gbrain config set embedding.dimensions 1536 → suggests embedding_dimensions', async () => {
|
|
const r = await runCli(['config', 'set', 'embedding.dimensions', '1536'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toMatch(/Did you mean "embedding_dimensions"/);
|
|
}, 60000);
|
|
|
|
test('gbrain config set --force foo.bar baz → accepts with WARN', async () => {
|
|
const r = await runCli(['config', 'set', 'foo.bar.unknown', 'somevalue', '--force'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(0);
|
|
expect(r.stderr).toContain('writing unknown key');
|
|
}, 60000);
|
|
|
|
test('gbrain config set search.mode conservative → accepts (known key)', async () => {
|
|
const r = await runCli(['config', 'set', 'search.mode', 'conservative'], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(0);
|
|
}, 60000);
|
|
});
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.37 T12 — D9 --no-embedding deferred-setup mode', () => {
|
|
let tmpHome: string;
|
|
|
|
beforeAll(() => { tmpHome = makeTempHome(); });
|
|
afterAll(() => { rmSync(tmpHome, { recursive: true, force: true }); });
|
|
|
|
test('init --pglite --no-embedding succeeds with embedding_disabled sentinel', async () => {
|
|
const r = await runCli(['init', '--pglite', '--no-embedding'], {
|
|
gbrainHome: tmpHome,
|
|
env: {}, // no provider keys — opt-in mode shouldn't care
|
|
});
|
|
expect(r.exitCode).toBe(0);
|
|
expect(r.stdout).toContain('--no-embedding: deferred setup');
|
|
|
|
const cfgPath = join(tmpHome, '.gbrain', 'config.json');
|
|
const cfg = JSON.parse(readFileSync(cfgPath, 'utf-8'));
|
|
expect(cfg.embedding_disabled).toBe(true);
|
|
// Mutually exclusive with embedding_model being set.
|
|
expect(cfg.embedding_model).toBeUndefined();
|
|
}, 120000);
|
|
|
|
test('gbrain import refuses with config-set hint after --no-embedding init', async () => {
|
|
// Seed a markdown file to import.
|
|
const repoDir = join(tmpHome, 'sample-repo');
|
|
mkdirSync(repoDir, { recursive: true });
|
|
writeFileSync(join(repoDir, 'test.md'), '# test\nhello world');
|
|
|
|
const r = await runCli(['import', repoDir], {
|
|
gbrainHome: tmpHome,
|
|
env: {},
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toMatch(/deferred setup|no-embedding|gbrain config set embedding_model/);
|
|
}, 120000);
|
|
|
|
test('gbrain import --no-embed flag bypasses the refusal (chunks land without vectors)', async () => {
|
|
// The CLI flag --no-embed (existing, separate from --no-embedding init flag)
|
|
// should still work after --no-embedding init — import succeeds, just doesn't
|
|
// embed. Validates we didn't accidentally block all imports.
|
|
const repoDir = join(tmpHome, 'sample-repo');
|
|
const r = await runCli(['import', repoDir, '--no-embed'], {
|
|
gbrainHome: tmpHome,
|
|
env: {},
|
|
});
|
|
expect(r.exitCode).toBe(0);
|
|
}, 120000);
|
|
});
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.37 T12 — D11 preflight refuses BEFORE disk writes', () => {
|
|
let tmpHome: string;
|
|
|
|
beforeAll(() => { tmpHome = makeTempHome(); });
|
|
afterAll(() => { rmSync(tmpHome, { recursive: true, force: true }); });
|
|
|
|
test('--embedding-dimensions 9999 (invalid for OpenAI text-3-large) refuses early', async () => {
|
|
const r = await runCli([
|
|
'init', '--pglite',
|
|
'--embedding-model', 'openai:text-embedding-3-large',
|
|
'--embedding-dimensions', '9999',
|
|
], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toMatch(/Refusing to init|rejects custom dimensions 9999|accepts dimensions 1\.\.3072/);
|
|
// No brain file written on failure path.
|
|
expect(existsSync(join(tmpHome, 'brain.pglite'))).toBe(false);
|
|
// No config persisted either (preflight runs BEFORE saveConfig).
|
|
expect(existsSync(join(tmpHome, '.gbrain', 'config.json'))).toBe(false);
|
|
}, 60000);
|
|
|
|
test('--embedding-dimensions 99999 (above pgvector cap) refuses', async () => {
|
|
const r = await runCli([
|
|
'init', '--pglite',
|
|
'--embedding-model', 'openai:text-embedding-3-large',
|
|
'--embedding-dimensions', '99999',
|
|
], {
|
|
gbrainHome: tmpHome,
|
|
env: { OPENAI_API_KEY: 'sk-test' },
|
|
});
|
|
expect(r.exitCode).toBe(1);
|
|
expect(r.stderr).toMatch(/exceed pgvector|Refusing to init/);
|
|
}, 60000);
|
|
});
|
|
|
|
// ============================================================================
|
|
|
|
describe('v0.37 T12 — happy path with picker-bypassing explicit flag', () => {
|
|
let tmpHome: string;
|
|
|
|
beforeAll(() => { tmpHome = makeTempHome(); });
|
|
afterAll(() => { rmSync(tmpHome, { recursive: true, force: true }); });
|
|
|
|
test('explicit --embedding-model wins over env detection', async () => {
|
|
const r = await runCli([
|
|
'init', '--pglite',
|
|
'--embedding-model', 'voyage:voyage-3-large',
|
|
'--embedding-dimensions', '1024',
|
|
], {
|
|
gbrainHome: tmpHome,
|
|
// OpenAI key set, but explicit Voyage flag overrides per precedence chain.
|
|
env: { OPENAI_API_KEY: 'sk-test', VOYAGE_API_KEY: 'pa-test' },
|
|
});
|
|
expect(r.exitCode).toBe(0);
|
|
|
|
const cfg = JSON.parse(readFileSync(join(tmpHome, '.gbrain', 'config.json'), 'utf-8'));
|
|
expect(cfg.embedding_model).toBe('voyage:voyage-3-large');
|
|
expect(cfg.embedding_dimensions).toBe(1024);
|
|
}, 120000);
|
|
});
|