|
14 | 14 | * 5. EOF safety: closed stdin (non-TTY / Ctrl-D) must never hang an |
15 | 15 | * interactive prompt. |
16 | 16 | * 6. A failed one-shot model turn must exit 1 rather than reporting success. |
| 17 | + * 7. A missing `pi` binary must exit 1 as an environment problem. |
17 | 18 | */ |
18 | 19 |
|
19 | 20 | import { describe, expect, test } from "bun:test"; |
20 | 21 | import { spawnSync } from "child_process"; |
21 | | -import { existsSync, mkdtempSync } from "fs"; |
| 22 | +import { existsSync, mkdtempSync, renameSync } from "fs"; |
22 | 23 | import { tmpdir } from "os"; |
23 | 24 | import { join, resolve } from "path"; |
24 | 25 |
|
@@ -134,4 +135,32 @@ describe("local-chat regression tests", () => { |
134 | 135 | expect(rm.status).toBe(0); |
135 | 136 | } |
136 | 137 | }); |
| 138 | + |
| 139 | + test("missing pi binary exits 1", () => { |
| 140 | + const alias = `gmi-missing-pi-${Date.now()}-${process.pid}`; |
| 141 | + const piBin = join(MI_DIR, "node_modules", ".bin", "pi"); |
| 142 | + const piBins = (process.platform === "win32" |
| 143 | + ? [`${piBin}.exe`, `${piBin}.cmd`, piBin] |
| 144 | + : [piBin] |
| 145 | + ).filter(existsSync); |
| 146 | + const hiddenPiBins = piBins.map((path) => `${path}.gmi-test-hidden`); |
| 147 | + |
| 148 | + try { |
| 149 | + const created = runChat(["--new", "--name", alias], MI_DIR); |
| 150 | + expect(created.status).toBe(0); |
| 151 | + |
| 152 | + piBins.forEach((path, index) => renameSync(path, hiddenPiBins[index])); |
| 153 | + const result = runChat(["--thread", alias], MI_DIR, { |
| 154 | + LOCAL_PROVIDER: "lmstudio", |
| 155 | + }); |
| 156 | + expect(result.status).toBe(1); |
| 157 | + expect(result.stdout).toContain("isn't installed yet"); |
| 158 | + } finally { |
| 159 | + hiddenPiBins.forEach((path, index) => { |
| 160 | + if (existsSync(path)) renameSync(path, piBins[index]); |
| 161 | + }); |
| 162 | + const rm = runChat(["--rm", alias], MI_DIR); |
| 163 | + expect(rm.status).toBe(0); |
| 164 | + } |
| 165 | + }); |
137 | 166 | }); |
0 commit comments