Skip to content

Commit bdadf95

Browse files
authored
Merge pull request #17 from japer-technology/copilot/debug-this
Return an error when the local chat runtime is unavailable
2 parents 442edce + 72f5d20 commit bdadf95

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

.github-minimum-intelligence/lifecycle/local-chat.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* 5. EOF safety: closed stdin (non-TTY / Ctrl-D) must never hang an
1515
* interactive prompt.
1616
* 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.
1718
*/
1819

1920
import { describe, expect, test } from "bun:test";
2021
import { spawnSync } from "child_process";
21-
import { existsSync, mkdtempSync } from "fs";
22+
import { existsSync, mkdtempSync, renameSync } from "fs";
2223
import { tmpdir } from "os";
2324
import { join, resolve } from "path";
2425

@@ -134,4 +135,32 @@ describe("local-chat regression tests", () => {
134135
expect(rm.status).toBe(0);
135136
}
136137
});
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+
});
137166
});

.github-minimum-intelligence/lifecycle/local-chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,7 @@ async function main(): Promise<void> {
19341934
const m = msg.match(/not found in any of: ([^\n]+)/);
19351935
const candidates = m ? m[1].split(", ") : [];
19361936
guidePiNotInstalled(candidates);
1937+
process.exitCode = 1;
19371938
return;
19381939
}
19391940

0 commit comments

Comments
 (0)