Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

CI flakes: measured; update.sh Podman race, installer rate limit, and three tests made deterministic (#6857)

Milind Sonicaa36ce5f94a
diff --git a/.github/workflows/server-installer.yml b/.github/workflows/server-installer.yml
index 08cc1a1406..d68ad7a21c 100644
--- a/.github/workflows/server-installer.yml
+++ b/.github/workflows/server-installer.yml
@@ -75,6 +75,9 @@ jobs:
env:
OUT: ${{ runner.temp }}/server-installer
OMB_INSTALL_IMAGE: ${{ steps.image.outputs.image }}
+ # The installer's lookup of the newest release, authenticated: unauthenticated, api.github.com refuses this
+ # runner's shared address once others have used up its hourly reads. A person's install sends no token.
+ OMB_INSTALL_GITHUB_TOKEN: ${{ github.token }}
run: bash deploy/e2e/run.sh
- name: Keep the evidence
if: always()
diff --git a/deploy/e2e/run.sh b/deploy/e2e/run.sh
index 905a2eb89d..10879104fb 100755
--- a/deploy/e2e/run.sh
+++ b/deploy/e2e/run.sh
@@ -17,12 +17,17 @@ mkdir -p "$OUT"
DOMAIN=installer-e2e.internal
DIR=/opt/openmausbot
SETTINGS=(OMB_INSTALL_SKIP_DNS=1 OMB_INSTALL_HTTPS_WAIT_S=20 "OMB_INSTALL_SOURCE=file://$ROOT")
+# The workflow's token, when it gives one, reaches the installer's lookup of the newest release (deploy/install.sh
+# newest_release): api.github.com answers few reads without one from a runner's shared address. sudo keeps it out of the
+# command line.
+AS_ROOT=(sudo)
+if [ -n "${OMB_INSTALL_GITHUB_TOKEN:-}" ]; then AS_ROOT=(sudo --preserve-env=OMB_INSTALL_GITHUB_TOKEN); fi
# Without a version asked for: what a person's later run is, which must keep the version update.sh pinned.
# Under umask 000, as a root shell may have it: what the installer makes must not take its modes from there.
UMASK_000=(sh -c "umask 000; exec sh \"\$0\" \"\$@\"")
-PLAIN_INSTALL=(sudo env "${SETTINGS[@]}" "${UMASK_000[@]}" "$ROOT/deploy/install.sh")
+PLAIN_INSTALL=("${AS_ROOT[@]}" env "${SETTINGS[@]}" "${UMASK_000[@]}" "$ROOT/deploy/install.sh")
if [ -n "${OMB_INSTALL_IMAGE:-}" ]; then SETTINGS+=("OMB_INSTALL_IMAGE=$OMB_INSTALL_IMAGE"); fi
-INSTALL=(sudo env "${SETTINGS[@]}" "${UMASK_000[@]}" "$ROOT/deploy/install.sh")
+INSTALL=("${AS_ROOT[@]}" env "${SETTINGS[@]}" "${UMASK_000[@]}" "$ROOT/deploy/install.sh")
box_check() { (cd "$DIR" && sudo docker compose exec -T omb node dist-server/bot-box/box-check.js --public=none "$@"); }
as_root() { sudo "$@"; }
@@ -103,7 +108,7 @@ prepare_like_a_server
step "the checks alone, with a name that points nowhere: one thing to fix, nothing changed"
status=0
containers_before=$(sudo docker ps -aq | sort)
-as_root sh "$ROOT/deploy/install.sh" --check --domain "$DOMAIN" >"$OUT/check.txt" 2>&1 || status=$?
+"${AS_ROOT[@]}" sh "$ROOT/deploy/install.sh" --check --domain "$DOMAIN" >"$OUT/check.txt" 2>&1 || status=$?
cat "$OUT/check.txt"
[ "$status" = 1 ] || fail "--check exited $status, not 1"
[ "$(grep -c '^ FIX ' "$OUT/check.txt")" = 1 ] || fail "--check found more than the DNS record to fix"
diff --git a/deploy/install.sh b/deploy/install.sh
index 65202d567b..c43b74f24e 100755
--- a/deploy/install.sh
+++ b/deploy/install.sh
@@ -511,7 +511,13 @@ note_sandbox() { # tag or sha256:digest
}
newest_release() {
- curl -fsS --max-time 15 "$RELEASES_URL" 2>/dev/null | sed -n 's/.*"tag_name": *"\(v[0-9][0-9.]*\)".*/\1/p' | head -n 1
+ # OMB_INSTALL_GITHUB_TOKEN, for a test run on a shared CI machine only: api.github.com answers few reads without one
+ # from an address many others share. A person's run sends none. The token goes to curl on its standard input.
+ if [ -n "${OMB_INSTALL_GITHUB_TOKEN:-}" ]; then
+ printf 'header = "Authorization: Bearer %s"\n' "$OMB_INSTALL_GITHUB_TOKEN" | curl -K - -fsS --max-time 15 "$RELEASES_URL" 2>/dev/null
+ else
+ curl -fsS --max-time 15 "$RELEASES_URL" 2>/dev/null
+ fi | sed -n 's/.*"tag_name": *"\(v[0-9][0-9.]*\)".*/\1/p' | head -n 1
}
# The stable channel when it is published, else the newest release. Never `latest`, which follows every commit.
diff --git a/deploy/update.sh b/deploy/update.sh
index 1c53c0e17f..8adb139fb5 100755
--- a/deploy/update.sh
+++ b/deploy/update.sh
@@ -559,6 +559,13 @@ wait_healthy() {
if [ -z "$cid" ] && [ -n "$UNIT" ]; then WHY="it stopped as it started ($(last_words))"; return 1; fi
if [ -z "$cid" ]; then WHY="its container is gone"; return 1; fi
state=$(inspect '{{.State.Status}} {{.RestartCount}} {{.Image}}' "$cid")
+ # Gone between the two reads: Podman removes a container that exits as it starts, so the next read says what became
+ # of it. An empty answer is never taken for a container on another image.
+ if [ -z "$state" ]; then
+ if [ "$(date +%s)" -ge "$deadline" ]; then WHY="its container is gone"; return 1; fi
+ sleep "$POLL_S"
+ continue
+ fi
status=${state%% *}
restarts=$(printf '%s' "$state" | cut -d' ' -f2)
image=${state##* }
diff --git a/scripts/server-installer.test.ts b/scripts/server-installer.test.ts
index 93a102d80a..d1975818db 100644
--- a/scripts/server-installer.test.ts
+++ b/scripts/server-installer.test.ts
@@ -62,6 +62,7 @@ esac`,
curl: `echo "curl $*" >> "$FAKE_LOG"
blocked() { case " \${FAKE_BLOCKED:-} " in *" $1 "*) return 0 ;; esac; return 1; }
case "$*" in
+ *"-K -"*releases/latest*) cat >> "$FAKE_LOG.stdin"; printf '{\\n "tag_name": "%s",\\n "name": "x"\\n}\\n' "$FAKE_RELEASE" ;;
*"-K - -fsSL"*) cat >> "$FAKE_LOG.stdin"
case "$*" in
*/manifests/sha256:*) printf '%s' "\${FAKE_MANIFEST:-}" ;;
@@ -356,6 +357,20 @@ describe.skipIf(!posix)("deploy/install.sh", () => {
expect(run(["--check", "--domain", "maus.example.com"]).stdout).not.toContain("no bots' sandbox");
});
+ it("reads the newest release without a token, and sends one only when a test run's OMB_INSTALL_GITHUB_TOKEN gives it, never on a command line", () => {
+ const stdin = (dir: string) => (existsSync(join(dir, "calls.log.stdin")) ? readFileSync(join(dir, "calls.log.stdin"), "utf8") : "");
+ const plain = run(["--check", "--domain", "maus.example.com"]);
+ expect(plain.stdout).toContain(" ok version: v0.1.151, the newest release");
+ expect(plain.calls.filter((call) => call.includes("releases/latest"))).toEqual(["curl -fsS --max-time 15 https://api.github.com/repos/milind-soni/OpenMausBot/releases/latest"]);
+ expect(stdin(plain.dir)).not.toContain("api-token");
+
+ const token = run(["--check", "--domain", "maus.example.com"], { env: { OMB_INSTALL_GITHUB_TOKEN: "api-token-123" } });
+ expect(token.stdout).toContain(" ok version: v0.1.151, the newest release");
+ expect(token.calls.filter((call) => call.includes("releases/latest"))).toEqual(["curl -K - -fsS --max-time 15 https://api.github.com/repos/milind-soni/OpenMausBot/releases/latest"]);
+ expect(token.calls.some((call) => call.includes("api-token-123"))).toBe(false);
+ expect(stdin(token.dir)).toContain('header = "Authorization: Bearer api-token-123"\n');
+ });
+
it("uses the stable channel once it is published, and never the latest tag", () => {
const result = run(["--domain", "maus.example.com"], { env: { FAKE_STABLE: "200" } });
expect(result.stdout).toContain(" ok version: the stable channel");
diff --git a/scripts/testing/deploy-update-podman.test.ts b/scripts/testing/deploy-update-podman.test.ts
index 4d10a21284..d6ecb32e61 100644
--- a/scripts/testing/deploy-update-podman.test.ts
+++ b/scripts/testing/deploy-update-podman.test.ts
@@ -153,6 +153,19 @@ describe.skipIf(!posix)("deploy/update.sh on a Podman install", () => {
expect(tree(box.data)).toEqual({ ...before, "started-by.txt": "0.1.150\n0.1.150\n" });
});
+ it("says why in the server's own words when the new version exits at once and Podman removes its container before it is looked at", () => {
+ const box = install({ behaviour: "exits", lastWords: "broken on purpose" });
+ const failed = box.run();
+ expect(failed.status, failed.stdout + failed.stderr).toBe(1);
+ expect(failed.said.slice(-3)).toEqual([
+ "The update to 0.1.151 did not work: it stopped as it started (broken on purpose).",
+ "Putting back the version and the data from before the update…",
+ "Your server runs 0.1.150 again, with its data as it was before the update.",
+ ]);
+ expect(box.unit()).toBe(unitText(OLD.refs[1]!));
+ expect(box.state().containers.omb).toMatchObject({ image: OLD.id, status: "running" });
+ });
+
it("names systemctl and journalctl, never docker compose, when a person has to step in", () => {
// The data cannot be put back: the way to run the server on the data as it is.
const restore = install({ behaviour: "silent" }, { failRestore: true });
diff --git a/scripts/testing/fake-compose-docker.mjs b/scripts/testing/fake-compose-docker.mjs
index 86f31de3ae..44acd809ab 100644
--- a/scripts/testing/fake-compose-docker.mjs
+++ b/scripts/testing/fake-compose-docker.mjs
@@ -43,6 +43,10 @@ function composeUp() {
// `repairable`: it crashes until its doctor has repaired the data (`doctor --data --fix`, below).
const crashes = wanted.behaviour === "crashes" || (wanted.behaviour === "repairable" && !state.repaired);
state.containers.omb = { id: `omb-${++state.serial}`, image: wanted.id, status: crashes ? "restarting" : "running", restarts: crashes ? 5 : 0, started: `start-${state.serial}` };
+ // `exits`: it stops as it starts, and Podman removes the container (--rm): it is listed once, then gone before anyone
+ // inspects it. Its unit's log keeps its last words.
+ if (wanted.behaviour === "exits") Object.assign(state.containers.omb, { status: "exited", vanishes: true });
+ state.lastImage = wanted.id;
state.containers.caddy = { id: `caddy-${state.serial}`, status: wanted.behaviour === "no-caddy" ? "exited" : "running" };
// A server that starts writes to its data, as a new version's migrations do.
if (!crashes) appendFileSync(join(volume(state.dataVolume), "started-by.txt"), `${wanted.version}\n`);
@@ -53,7 +57,10 @@ function compose(rest) {
const omb = state.containers.omb;
if (verb === "version") return out("Docker Compose version v2.40.0");
if (verb === "config") return out(`services:\n omb:\n image: ${composeImage()}`);
- if (verb === "ps" && more.includes("-aq")) return omb ? out(omb.id) : undefined;
+ if (verb === "ps" && more.includes("-aq")) {
+ if (omb?.vanishes) delete state.containers.omb;
+ return omb ? out(omb.id) : undefined;
+ }
if (verb === "ps") return Object.entries(state.containers).filter(([, container]) => container?.status === "running").forEach(([name]) => out(name));
if (verb === "stop") {
if (state.failStop) fail("Error response from daemon: cannot stop container: permission denied");
@@ -61,7 +68,7 @@ function compose(rest) {
return;
}
if (verb === "up") return composeUp();
- if (verb === "logs") return out(image(omb?.image)?.lastWords ?? "");
+ if (verb === "logs") return out(image(omb?.image ?? state.lastImage)?.lastWords ?? "");
if (more.includes("doctor") && more.includes("--fix")) return doctor(verb, omb);
if (verb === "exec") {
// As the real one does: `docker compose exec` forwards its standard input to the container, so it takes whatever is
diff --git a/server/digest.e2e.test.ts b/server/digest.e2e.test.ts
index aa235c8199..5ed636a3f6 100644
--- a/server/digest.e2e.test.ts
+++ b/server/digest.e2e.test.ts
@@ -173,9 +173,11 @@ posixOnly("work digest e2e (every fake engine)", () => {
// no message yet: the folder is read into the bot's checkpoint, and no snapshot is taken
const shadows = join(home, ".openmausbot", "checkpoints", created.id);
- const shadow = () => (existsSync(shadows) ? readdirSync(shadows) : []).map((name) => join(shadows, name, ".git")).find((dir) => existsSync(join(dir, "index")));
- await waitFor(async () => shadow() !== undefined, "the project to be read ahead of the first message");
+ // A shadow is made as <name>.<pid>.new and renamed into place, and the read-ahead stages the folder after that: wait for
+ // the staged folder in the shadow itself, not for the first index that appears (the draft's, before the rename).
+ const shadow = () => (existsSync(shadows) ? readdirSync(shadows) : []).filter((name) => !name.endsWith(".new")).map((name) => join(shadows, name, ".git")).find((dir) => existsSync(join(dir, "index")));
const shadowGit = (...args: string[]) => execFileSync("git", args, { encoding: "utf8", env: { ...process.env, GIT_DIR: shadow()! } }).trim();
+ await waitFor(async () => shadow() !== undefined && shadowGit("ls-files") !== "", "the project to be read ahead of the first message");
expect(shadowGit("ls-files")).toBe("README.md");
expect(shadowGit("log", "--format=%s")).toBe("checkpoint base");
diff --git a/server/drivers/acp/acp.test.ts b/server/drivers/acp/acp.test.ts
index efaf3de621..249cf098ae 100644
--- a/server/drivers/acp/acp.test.ts
+++ b/server/drivers/acp/acp.test.ts
@@ -2162,7 +2162,8 @@ describe("ACP turns (fake CLI)", () => {
process.env.FAKE_ACP_RPC_DUMP = rpc;
await create(GrokAgentDriver, "hang");
await instance.adapter.sendTurn({ threadId: "t-stop-end-turn", text: "go" });
- await vi.waitFor(() => expect(JSON.parse(readFileSync(rpc, "utf8"))).toContain("session/prompt"));
+ // The fake CLI starts as a new process and shakes hands before the prompt: the file's other waits on it allow 10 s.
+ await vi.waitFor(() => expect(JSON.parse(readFileSync(rpc, "utf8"))).toContain("session/prompt"), { timeout: 10_000 });
await instance.adapter.interruptTurn("t-stop-end-turn");
const done = await recorder.until((e) => e.type === "turn.completed");
expect(done).toMatchObject({ ok: true, stopReason: "cancelled" });
@@ -2903,7 +2904,7 @@ describe("ACP turns (fake CLI)", () => {
const kill = vi.spyOn(procs, "killCliTree");
const pending = instance.adapter.sendTurn({ threadId: "unreached", text: "go", startupRecovery: true });
const settled = acknowledged(pending);
- await vi.waitFor(() => expect(readFileSync(process.env.FAKE_ACP_RPC_DUMP!, "utf8")).toContain("session/prompt"));
+ await vi.waitFor(() => expect(readFileSync(process.env.FAKE_ACP_RPC_DUMP!, "utf8")).toContain("session/prompt"), { timeout: 10_000 });
await new Promise((resolve) => setTimeout(resolve, 50));
expect(settled()).toBe(false);
releaseFailure();
diff --git a/shared/app-frame/jsx-page.test.ts b/shared/app-frame/jsx-page.test.ts
index 317195612b..479ca9825c 100644
--- a/shared/app-frame/jsx-page.test.ts
+++ b/shared/app-frame/jsx-page.test.ts
@@ -55,7 +55,12 @@ async function start(source: string, more: Record<string, unknown> = {}) {
...more,
}) as { unmount(): void } | null;
if (root) roots.push(root);
- await new Promise((resolve) => setTimeout(resolve, 30));
+ // React renders on its own schedule: wait until the page shows something, its content or a problem, not for a fixed time.
+ if (root) {
+ await vi.waitFor(() => {
+ if (!document.getElementById("mausbot-root")!.hasChildNodes() && !document.querySelector("[data-page-problem]")) throw new Error("the page has not rendered yet");
+ }, { timeout: 10_000 });
+ }
return { problems, loads, overlay: document.querySelector<HTMLElement>("[data-page-problem]"), rendered: document.getElementById("mausbot-root")! };
}
@@ -79,8 +84,8 @@ describe("a jsx page in the shell", () => {
expect([...rendered.querySelectorAll("h2")].map((heading) => heading.textContent)).toEqual(["Starter", "Pro"]);
expect(rendered.querySelectorAll("svg")).toHaveLength(2);
rendered.querySelectorAll("button")[1]!.click();
- await new Promise((resolve) => setTimeout(resolve, 10));
- expect(rendered.querySelector("#picked")?.textContent).toBe("Pro");
+ // React applies the click's state on its own schedule: wait for the change, not for a fixed time.
+ await vi.waitFor(() => expect(rendered.querySelector("#picked")?.textContent).toBe("Pro"), { timeout: 10_000 });
});
it("shows a syntax error as a readable overlay with the line, and tells the bot through the page's context", async () => {
@@ -129,6 +134,8 @@ export default function Page() { const theme = useTheme(); return <div><p id="th
expect(loads).toContain("echarts");
expect(rendered.querySelector("#theme")?.textContent).toBe("dark");
expect(rendered.querySelector("[role=img]")?.getAttribute("aria-label")).toBe("Sales");
+ // The chart is drawn in an effect after the render: wait for it, not for a fixed time.
+ await vi.waitFor(() => expect(fakeEcharts.made).toHaveLength(1), { timeout: 10_000 });
expect(fakeEcharts.made[0]).toMatchObject({ theme: "dark", options: [{ backgroundColor: "transparent", series: [{ type: "bar", data: [1, 2] }] }] });
});