diff --git a/lib/gbrain-local-status.ts b/lib/gbrain-local-status.ts index f546a93bc..540b3e5d6 100644 --- a/lib/gbrain-local-status.ts +++ b/lib/gbrain-local-status.ts @@ -51,6 +51,12 @@ export interface ClassifyOptions { } interface CacheEntry { + // Local-cache schema version, controlled by gstack. Not to be confused + // with `gbrain doctor --json` output schema_version (gbrain v0.25+ emits + // schema_version: 2). Doctor-output parsing lives in + // lib/gstack-memory-helpers.ts:freshDetectEngineTier and accepts both + // doctor-output versions. This cache stays strictly at version 1 — a + // future shape change here requires an explicit migration. schema_version: 1; status: LocalEngineStatus; cached_at: number; diff --git a/test/gstack-memory-helpers.test.ts b/test/gstack-memory-helpers.test.ts index f1d2bf379..a881c153b 100644 --- a/test/gstack-memory-helpers.test.ts +++ b/test/gstack-memory-helpers.test.ts @@ -341,4 +341,41 @@ describe("detectEngineTier", () => { const result = detectEngineTier(); expect(result.engine).toBe("supabase"); }); + + it("parses schema_version:2 doctor JSON via the exec path (regression for #1418)", () => { + // Stronger pin than the PATH-stripped fallback above: install a fake + // gbrain shim that successfully exits with status 1 (health_score < 100, + // mirroring real-world Supabase brains) and emits the v2 doctor JSON + // shape — schema_version: 2, status: "warnings", no top-level `engine`. + // The parser must still produce a usable EngineDetect by falling back + // to GBRAIN_HOME/config.json when `engine` is absent from doctor output. + const binDir = mkdtempSync(join(tmpdir(), "gstack-gbrain-shim-")); + const shim = join(binDir, "gbrain"); + writeFileSync( + shim, + `#!/bin/sh +if [ "$1" = "doctor" ]; then + cat <<'JSON' +{"schema_version":2,"status":"warnings","health_score":90,"checks":[{"name":"resolver_health","status":"ok","message":"42 skills"}]} +JSON + exit 1 +fi +if [ "$1" = "--version" ]; then + echo "gbrain 0.35.0.0" + exit 0 +fi +exit 0 +`, + { mode: 0o755 } + ); + process.env.PATH = `${binDir}:${process.env.PATH || ""}`; + writeFileSync( + join(testGbrainHome, "config.json"), + JSON.stringify({ engine: "pglite" }), + "utf-8" + ); + const result = detectEngineTier(); + expect(result.engine).toBe("pglite"); + rmSync(binDir, { recursive: true, force: true }); + }); });