* Build a gbrain shim that responds to specific subcommands with canned * output, then return PATH-prepend value. Lets us run helpers in-process * (which spawn `gbrain` from PATH) without a real gbrain CLI.
(bindir: string, responses: Record<string, { stdout?: string; stderr?: string; exit?: number }>)
| 563 | * (which spawn `gbrain` from PATH) without a real gbrain CLI. |
| 564 | */ |
| 565 | function makeShim(bindir: string, responses: Record<string, { stdout?: string; stderr?: string; exit?: number }>): string { |
| 566 | const shim = join(bindir, "gbrain"); |
| 567 | const cases = Object.entries(responses).map(([key, r]) => { |
| 568 | const exit = r.exit ?? 0; |
| 569 | const stdout = (r.stdout || "").replace(/'/g, "'\\''"); |
| 570 | const stderr = (r.stderr || "").replace(/'/g, "'\\''"); |
| 571 | // Patterns with spaces MUST be double-quoted in sh case statements, |
| 572 | // otherwise the shell parses the second word as the start of the next |
| 573 | // pattern and errors out. |
| 574 | return ` "${key}") printf '%s' '${stdout}'; printf '%s' '${stderr}' >&2; exit ${exit} ;;`; |
| 575 | }).join("\n"); |
| 576 | // Match on the full argument string, joined with literal spaces. |
| 577 | const script = `#!/bin/sh\nARGS="$*"\ncase "$ARGS" in\n${cases}\n *) echo "shim: no match for [$ARGS]" >&2; exit 1 ;;\nesac\n`; |
| 578 | writeFileSync(shim, script); |
| 579 | chmodSync(shim, 0o755); |
| 580 | return shim; |
| 581 | } |
| 582 | |
| 583 | describe("derivePathOnlyHashLegacyId", () => { |
| 584 | it("returns the pre-#1468 form (path-only sha1, no hostname)", () => { |
no outgoing calls
no test coverage detected