Skip to content

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

fix(team-owners): hide unavailable bots before reading handoff bodies

Sebastian Bec834e08e7f1
diff --git a/server/body-thread-guards.e2e.test.ts b/server/body-thread-guards.e2e.test.ts
index 40fd52f6ce..86aa49555c 100644
--- a/server/body-thread-guards.e2e.test.ts
+++ b/server/body-thread-guards.e2e.test.ts
@@ -3,6 +3,24 @@ import { expect, it } from "vitest";
import { launchCloudSendFixture } from "../scripts/testing/cloud-send-fixture.ts";
import { hostTimeout } from "./testing/host-timeout.ts";
+it("gives a member the same 404 for missing and hidden bots with invalid handoff bodies", async () => {
+ const fixture = await launchCloudSendFixture({ onePasswordToken: "synthetic-owner-lookup-token",
+ team: { id: "team-owner-lookup", name: "Owner lookup" } });
+ try {
+ const team = fixture.team!;
+ const owner = await team.pair({ email: "[email protected]", role: "owner" });
+ const member = await team.pair({ email: "[email protected]", role: "member" });
+ const created = await team.as(owner.token!, "POST", "/api/bots", { name: "Private Scout", visibility: "admins" });
+ expect(created.status).toBe(201);
+ for (const id of [created.body.bot.id, "missing-bot"]) {
+ const response = await team.as(member.token!, "PUT", `/api/bots/${id}/reports-to`, {});
+ expect(response, id).toEqual({ status: 404, body: { error: "no such bot" } });
+ }
+ } finally {
+ await fixture.close();
+ }
+}, hostTimeout(120_000));
+
it("keeps a Team Cloud server alive when a member posts request-sized threadIds arrays", async () => {
const fixture = await launchCloudSendFixture({ onePasswordToken: "synthetic-route-guard-token",
team: { id: "team-guards", name: "Guards" } });
diff --git a/server/routes/team-owner-handoff.test.ts b/server/routes/team-owner-handoff.test.ts
index 0308e561af..c8a1692af3 100644
--- a/server/routes/team-owner-handoff.test.ts
+++ b/server/routes/team-owner-handoff.test.ts
@@ -14,6 +14,25 @@ const auth: RequestAuth = { kind: "session", scopes: ["client"], via: "bearer",
} };
describe("a handoff while the previous owner's request body is held", () => {
+ it.each(["missing", "hidden"] as const)("returns 404 for a %s bot without reading an invalid body", async (availability) => {
+ const store = new Store(() => ({ instanceId: "claude", model: "sonnet" }));
+ const bot = store.createBot({ name: "Scout", createdBy: BOB });
+ const people = createTeamPeople(DATA_DIR);
+ const route = createTeamOwnerRoutes({ team: { id: "acme", name: "Acme" } as never, people, store,
+ sees: () => availability !== "hidden", publicBot: (record) => record });
+ const path = `/api/bots/${availability === "missing" ? `${bot.id}-missing` : bot.id}/reports-to`;
+ let answer: unknown;
+ let reads = 0;
+ await route({ req: {} as IncomingMessage, res: {} as ServerResponse,
+ path, url: new URL(path, "http://localhost"), method: "PUT", auth,
+ json: ((_res: ServerResponse, status: number, body: unknown) => { answer = { status, body }; }) as never,
+ readBody: async () => { reads += 1; return {}; },
+ });
+ expect(answer).toEqual({ status: 404, body: { error: "no such bot" } });
+ expect(reads).toBe(0);
+ expect(store.bot(bot.id)?.reportsTo).toBeUndefined();
+ });
+
it.each([["owner", 403], ["visibility", 404], ["personal", 409]] as const)("rechecks the bot's current %s after reading the body", async (change, expectedStatus) => {
const store = new Store(() => ({ instanceId: "claude", model: "sonnet" }));
const bot = store.createBot({ name: "Scout", createdBy: BOB });
diff --git a/server/routes/team-owners.ts b/server/routes/team-owners.ts
index 7c4f933786..f3d40070d5 100644
--- a/server/routes/team-owners.ts
+++ b/server/routes/team-owners.ts
@@ -117,6 +117,8 @@ export function createTeamOwnerRoutes(deps: TeamOwnerRouteDeps): RouteHandler {
return json(res, 200, { bots: changed.bots.map((bot) => deps.publicBot(bot)) });
}
+ const beforeRead = deps.store.bot(one![1]!);
+ if (!beforeRead || !deps.sees(auth, beforeRead.id)) return json(res, 404, { error: "no such bot" });
const parsed = ownerBody.safeParse(await readBody(req));
if (!parsed.success) return json(res, 400, { error: "Send the email of the person it reports to." });
const bot = deps.store.bot(one![1]!);