Skip to content

Commit 72bec0c

Browse files
authored
Check the runtime health with Bun instead of python3 (#659)
Step 3 of scripts/start.sh was a python3 heredoc. On a machine without Python, and on Windows, where python3 is usually the Microsoft Store alias that exits 49, the run stopped there with the server and worker up and the app never started. The check now runs with bun run -, which the script already requires, with the same output and exit status, and python3 is gone from the prerequisites.
1 parent 820c5d5 commit 72bec0c

4 files changed

Lines changed: 65 additions & 17 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ The computer now mints a run for each Bot's browser session, mints a new one whe
6363
and answers which run it is on. Nothing changes for a deployment that already reports one, and a
6464
computer too old to answer leaves the ordering exactly where it was rather than refusing anything.
6565

66+
### `scripts/start.sh` no longer needs python3
67+
68+
The runtime health check in step 3 was a `python3` heredoc. On a machine without Python, and on
69+
Windows, where `python3` is usually the Microsoft Store alias that exits 49, the run stopped there
70+
with the server and worker up and the app never started. The check now runs in Bun, which the
71+
script already requires, with the same output and exit status, and `python3` is gone from the
72+
prerequisites in `docs/development.md`.
73+
6674
### An MCP tool that answers with a resource link is no longer read as an empty name
6775

6876
A tool that points at a file or a page often returns a `resource_link`: a URI, a name, and a

‎docs/development.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Setup
44

5-
Install Docker, [Bun](https://bun.sh) 1.3+, `lsof`, `python3`, `openssl`, and `curl`. The
5+
Install Docker, [Bun](https://bun.sh) 1.3+, `lsof`, `openssl`, and `curl`. The
66
Intelligence provisioning below also needs `npx` (Node); `scripts/start.sh` uses `openssl` to mint
77
the generated secrets on a first run.
88

‎scripts/start-restart-guard.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,26 @@ exit 0
133133
join(fakeBin, "sleep"),
134134
"#!/usr/bin/env bash\nexit 0\n",
135135
);
136-
await writeExecutable(join(fakeBin, "bun"), "#!/usr/bin/env bash\nexit 0\n");
136+
// The runtime health check is a script piped into `bun run -`, so that one invocation is the real
137+
// Bun: it is what decides whether the run carries on. Everything else Bun would start is faked.
138+
await writeExecutable(
139+
join(fakeBin, "bun"),
140+
'#!/usr/bin/env bash\nif [ "$1" = run ] && [ "$2" = - ]; then exec "$REAL_BUN" "$@"; fi\nexit 0\n',
141+
);
142+
// What `python3` is on a stock Windows machine: the Microsoft Store alias, which runs nothing. A
143+
// script that still needed it would stop at the health check in every test in this file.
144+
await writeExecutable(
145+
join(fakeBin, "python3"),
146+
'#!/usr/bin/env bash\necho "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Apps > Advanced app settings > App execution aliases." >&2\nexit 49\n',
147+
);
137148

138149
try {
139150
const child = Bun.spawn({
140151
cmd: [shell, "scripts/start.sh"],
141152
cwd: directory,
142153
env: {
143154
PATH: `${fakeBin}:${process.env.PATH ?? ""}`,
155+
REAL_BUN: process.execPath,
144156
PKILL_LOG: logPath,
145157
DOCKER_LOG: dockerLogPath,
146158
CURL_LOG: curlLogPath,
@@ -189,6 +201,28 @@ describe("start.sh server restart guard", () => {
189201
);
190202
});
191203

204+
describe("start.sh runtime health", () => {
205+
/**
206+
* THE LICENCE IS CHECKED WITHOUT PYTHON.
207+
*
208+
* The check used to be a `python3` heredoc. On Windows `python3` is usually the Microsoft Store
209+
* alias, which exits 49, so `set -e` ended the run at "3/4 Runtime health" with the server and
210+
* worker already up and the app never started. The fake `python3` beside this file's other fakes
211+
* is that alias; the line below is only printed if the check ran, in Bun, and passed.
212+
*/
213+
test("checks the licence and names the Bots without python3", async () => {
214+
const result = await runStartWithStaleServerProbe(401);
215+
216+
expect({ exitCode: result.exitCode, stderr: result.stderr }).toEqual({
217+
exitCode: 0,
218+
stderr: "",
219+
});
220+
expect(result.stdout).toContain(
221+
"licence valid · mode test · Bots: analyst",
222+
);
223+
});
224+
});
225+
192226
describe("start.sh under the wrong shell", () => {
193227
/**
194228
* THE WRONG INVOCATION SAYS SO, AND SAYING NOTHING IS THE DEFECT.

‎scripts/start.sh‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ holder() {
147147
#
148148
# When that happened here the cost was not a wrong answer, it was a wrong answer three stages later.
149149
# `require_free_or_ours` reported "already up", the server was therefore never started, `wait_for`
150-
# printed a green "server ready", and the run died at stage 3 in `json.loads` on a mouthful of HTML —
150+
# printed a green "server ready", and the run died at stage 3 parsing a mouthful of HTML as JSON —
151151
# a JSON parse error standing in for "that port belongs to something else".
152152
#
153153
# So each surface is asked for something only it can produce.
@@ -381,20 +381,26 @@ fi
381381

382382
info "3/4 Runtime health"
383383
INFO="$(curl -fsS --max-time 8 "http://localhost:$SERVER_PORT/api/copilotkit/info")"
384-
python3 - "$INFO" <<'PY'
385-
import json, sys
386-
info = json.loads(sys.argv[1])
387-
status, agents = info.get("licenseStatus"), list(info.get("agents", {}))
388-
if status != "valid":
389-
print(f"\033[31m licence is '{status}', not 'valid'.\033[0m")
390-
print("\033[31m Check INTELLIGENCE_API_KEY: npx copilotkit@latest login && npx copilotkit@latest project select\033[0m")
391-
print("\033[31m See README.md for Intelligence setup.\033[0m")
392-
raise SystemExit(1)
393-
if not agents:
394-
print("\033[31m No Bots registered.\033[0m")
395-
raise SystemExit(1)
396-
print(f"\033[32m licence valid · mode {info.get('mode')} · Bots: {', '.join(agents)}\033[0m")
397-
PY
384+
# Read with Bun, which every run of this script already needs, rather than python3, which not every
385+
# machine has. On Windows `python3` is usually the Microsoft Store alias, which prints "Python was not
386+
# found" and exits 49, so the run stopped here with the server and worker up and the app never
387+
# started.
388+
bun run - "$INFO" <<'JS'
389+
const info = JSON.parse(process.argv[2]);
390+
const status = info.licenseStatus;
391+
const agents = Object.keys(info.agents ?? {});
392+
if (status !== "valid") {
393+
console.log(`\x1b[31m licence is '${status}', not 'valid'.\x1b[0m`);
394+
console.log("\x1b[31m Check INTELLIGENCE_API_KEY: npx copilotkit@latest login && npx copilotkit@latest project select\x1b[0m");
395+
console.log("\x1b[31m See README.md for Intelligence setup.\x1b[0m");
396+
process.exit(1);
397+
}
398+
if (agents.length === 0) {
399+
console.log("\x1b[31m No Bots registered.\x1b[0m");
400+
process.exit(1);
401+
}
402+
console.log(`\x1b[32m licence valid · mode ${info.mode} · Bots: ${agents.join(", ")}\x1b[0m`);
403+
JS
398404

399405
info "4/4 App"
400406
require_free_or_ours "$APP_PORT" app

0 commit comments

Comments
 (0)