Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions bin/gstack-gbrain-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,6 @@ function constrainSourceId(prefix: string, raw: string): string {
return tail ? `${prefix}-${tail}-${hash}` : `${prefix}-${hash}`;
}

function gbrainAvailable(): boolean {
try {
execSync("command -v gbrain", { stdio: "ignore" });
return true;
} catch {
return false;
}
}

// ── Lock file (D1) ─────────────────────────────────────────────────────────

interface LockInfo {
Expand Down Expand Up @@ -333,9 +324,6 @@ async function runCodeImport(args: CliArgs): Promise<StageResult> {
if (!root) {
return { name: "code", ran: false, ok: true, duration_ms: 0, summary: "skipped (not in git repo)" };
}
if (!gbrainAvailable()) {
return { name: "code", ran: false, ok: false, duration_ms: 0, summary: "skipped (gbrain CLI not in PATH)" };
}

const sourceId = deriveCodeSourceId(root);

Expand Down
3 changes: 1 addition & 2 deletions bin/gstack-memory-ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
rmSync,
} from "fs";
import { join, basename, dirname } from "path";
import { execSync, execFileSync, spawnSync, spawn, type ChildProcess } from "child_process";
import { execFileSync, spawnSync, spawn, type ChildProcess } from "child_process";
import { homedir } from "os";
import { createHash } from "crypto";

Expand Down Expand Up @@ -809,7 +809,6 @@ let _gbrainAvailability: boolean | null = null;
function gbrainAvailable(): boolean {
if (_gbrainAvailability !== null) return _gbrainAvailability;
try {
execSync("command -v gbrain", { stdio: "ignore" });
// Probe `--help` for the `import` subcommand. gbrain v0.20.0+ ships
// `import <dir>` (batch markdown import via path-authoritative slugs).
// If absent, we surface a single clean error here rather than failing
Expand Down
7 changes: 3 additions & 4 deletions lib/gbrain-local-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ export function resolveGbrainBin(env?: NodeJS.ProcessEnv): string | null {
if (_gbrainBinCache.has(key)) return _gbrainBinCache.get(key)!;
let result: string | null = null;
try {
const out = execFileSync("sh", ["-c", "command -v gbrain"], {
execFileSync("gbrain", ["--version"], {
encoding: "utf-8",
timeout: 2_000,
stdio: ["ignore", "pipe", "ignore"],
stdio: ["ignore", "ignore", "ignore"],
env: e,
});
result = out.trim() || null;
result = "gbrain";
} catch {
result = null;
}
Expand Down Expand Up @@ -266,4 +266,3 @@ export function localEngineStatus(opts: ClassifyOptions = {}): LocalEngineStatus
writeCache(fresh, key);
return fresh;
}

11 changes: 11 additions & 0 deletions test/gbrain-local-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { describe, it, expect, beforeEach, afterEach } from "bun:test";
import {
mkdtempSync,
writeFileSync,
readFileSync,
mkdirSync,
rmSync,
chmodSync,
Expand Down Expand Up @@ -160,6 +161,16 @@ describe("lib/gbrain-local-status — five status cases", () => {
restoreEnv = null;
});

it("probes the gbrain executable directly instead of shelling through command -v", () => {
const source = readFileSync(
join(import.meta.dir, "..", "lib", "gbrain-local-status.ts"),
"utf-8",
);

expect(source).not.toContain('command -v gbrain');
expect(source).toContain('execFileSync("gbrain", ["--version"]');
});

it("returns 'no-cli' when gbrain is not on PATH", () => {
env = makeEnv({ withGbrain: false });
restoreEnv = applyEnv(env);
Expand Down
7 changes: 7 additions & 0 deletions test/gstack-gbrain-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ describe("gstack-gbrain-sync CLI", () => {
expect(r.stderr).toContain("Unknown argument: --bogus");
});

it("uses the shared local gbrain status classifier instead of shelling through command -v", () => {
const source = readFileSync(SCRIPT, "utf-8");

expect(source).not.toContain('command -v gbrain');
expect(source).toContain("localEngineStatus");
});

it("--dry-run with --code-only reports the code import preview only", () => {
const home = makeTestHome();
const gstackHome = join(home, ".gstack");
Expand Down
7 changes: 7 additions & 0 deletions test/gstack-memory-ingest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ esac
}

describe("gstack-memory-ingest writer (gbrain v0.20+ batch `import` interface)", () => {
it("probes the gbrain executable directly instead of shelling through command -v", () => {
const source = readFileSync(SCRIPT, "utf-8");

expect(source).not.toContain('command -v gbrain');
expect(source).toContain('execFileSync("gbrain", ["--help"]');
});

it("invokes `gbrain import <dir> --no-embed --json` exactly once with hierarchical staging", () => {
const home = makeTestHome();
const gstackHome = join(home, ".gstack");
Expand Down
Loading