* Stand up a fake `gbrain` shim on PATH that: * - advertises `import` in `--help` output (gbrainAvailable() passes) * - records `import ` invocations, args, and a sample of staged files * - emits a valid `--json` summary on stdout (status, imported, etc.) * - optionally drops failures t
(
home: string,
opts: { failingPaths?: string[] } = {},
)
| 329 | * include `import` and the dir argument. |
| 330 | */ |
| 331 | function installFakeGbrain( |
| 332 | home: string, |
| 333 | opts: { failingPaths?: string[] } = {}, |
| 334 | ): { binDir: string; logFile: string; argsFile: string; stagingListFile: string } { |
| 335 | const binDir = join(home, "fake-bin"); |
| 336 | mkdirSync(binDir, { recursive: true }); |
| 337 | const logFile = join(home, "gbrain-calls.log"); |
| 338 | const argsFile = join(home, "gbrain-args.log"); |
| 339 | const stagingListFile = join(home, "gbrain-staging-list.log"); |
| 340 | // Bash-side: when failingPaths is set, append matching JSONL entries to |
| 341 | // ~/.gbrain/sync-failures.jsonl so D7's readNewFailures can read them. |
| 342 | const failingList = (opts.failingPaths || []).join("|"); |
| 343 | const script = `#!/usr/bin/env bash |
| 344 | set -euo pipefail |
| 345 | LOG="${logFile}" |
| 346 | ARGS_LOG="${argsFile}" |
| 347 | STAGING_LIST="${stagingListFile}" |
| 348 | FAILING_LIST="${failingList}" |
| 349 | case "\${1:-}" in |
| 350 | --help|-h) |
| 351 | cat <<EOF |
| 352 | Usage: gbrain <command> [options] |
| 353 | |
| 354 | Commands: |
| 355 | import <dir> Import markdown directory (batch, content-addressed) |
| 356 | search <query> Keyword search across pages |
| 357 | ask <question> Hybrid semantic + keyword query |
| 358 | EOF |
| 359 | exit 0 |
| 360 | ;; |
| 361 | import) |
| 362 | DIR="\${2:-}" |
| 363 | NO_EMBED=0 |
| 364 | JSON=0 |
| 365 | shift 2 || true |
| 366 | for arg in "\$@"; do |
| 367 | case "\$arg" in |
| 368 | --no-embed) NO_EMBED=1 ;; |
| 369 | --json) JSON=1 ;; |
| 370 | esac |
| 371 | done |
| 372 | echo "import \$DIR" >> "\$LOG" |
| 373 | { |
| 374 | echo "dir=\$DIR no_embed=\$NO_EMBED json=\$JSON" |
| 375 | } >> "\$ARGS_LOG" |
| 376 | # Capture file tree from staging dir for assertion-on-shape later. |
| 377 | if [ -d "\$DIR" ]; then |
| 378 | ( cd "\$DIR" && find . -type f | sort ) > "\$STAGING_LIST" 2>/dev/null || true |
| 379 | fi |
| 380 | # If failingPaths configured, drop fake entries to sync-failures.jsonl |
| 381 | # (mtime byte-offset snapshot lets the ingest's readNewFailures pick them up). |
| 382 | if [ -n "\$FAILING_LIST" ]; then |
| 383 | mkdir -p "\${HOME}/.gbrain" |
| 384 | IFS='|' read -ra FAIL_PATHS <<< "\$FAILING_LIST" |
| 385 | for p in "\${FAIL_PATHS[@]}"; do |
| 386 | echo "{\\"path\\":\\"\$p\\",\\"error\\":\\"File too large\\",\\"code\\":\\"FILE_TOO_LARGE\\",\\"commit\\":\\"\\",\\"ts\\":\\"2026-05-09T22:00:00Z\\"}" >> "\${HOME}/.gbrain/sync-failures.jsonl" |
| 387 | done |
| 388 | fi |
no outgoing calls
no test coverage detected