Skip to content

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

Main green before 0.1.166 (#6278)

Milind Sonie61a0929715c
diff --git a/server/bot-api-as-owner.e2e.test.ts b/server/bot-api-as-owner.e2e.test.ts
index a3007a7ddc..58809141b3 100644
--- a/server/bot-api-as-owner.e2e.test.ts
+++ b/server/bot-api-as-owner.e2e.test.ts
@@ -2,7 +2,7 @@
// at the bot's own level, unconfined and with OpenMausBot's tools, as the owner's request; the never-list still denies
// what it names; once the mark is taken off the key can't go on in that thread; and a second admin switches it off.
import { randomUUID } from "node:crypto";
-import { readdirSync, readFileSync, rmSync } from "node:fs";
+import { readFileSync, rmSync } from "node:fs";
import { connect, type Socket } from "node:net";
import { join } from "node:path";
import { afterEach, expect, it } from "vitest";
@@ -89,9 +89,8 @@ it("runs a marked key's thread at the bot's level as the owner's work, keeps the
expect(await api("POST", `/api/bots/${bot.id}/bot-api/acts-as-owner`, { enabled: false })).toMatchObject({ actsAsOwner: false });
const refused = await call(on.url, on.key, { message: "More", thread: task.threadId });
expect(refused.status).toBe(403);
- const activity = readdirSync(join(dataDir, "admin-activity")).map((name) => readFileSync(join(dataDir, "admin-activity", name), "utf8")).join("\n");
- expect(activity).toContain("bot-api.acts-as-owner.on");
- expect(activity).toContain("bot-api.acts-as-owner.off");
+ const actions = ((await api("GET", "/api/admin-activity?what=all")).entries as Array<{ action?: string }>).map((entry) => entry.action);
+ expect(actions).toEqual(expect.arrayContaining(["bot-api.acts-as-owner.on", "bot-api.acts-as-owner.off"]));
// Only on one person's server, read live: a second admin, or a whole domain as admin, switches the mark off at once,
// and it is back when the server is one person's again.
diff --git a/server/bot-projects-api.test.ts b/server/bot-projects-api.test.ts
index 6ab65db627..e5952ce172 100644
--- a/server/bot-projects-api.test.ts
+++ b/server/bot-projects-api.test.ts
@@ -4,6 +4,7 @@ import { pathToFileURL } from "node:url";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { launchVerificationServer, type VerificationServer } from "../scripts/control-omb.ts";
+import { hostTimeout } from "./testing/host-timeout.ts";
describe("organizational folders through an isolated HTTP fixture", () => {
let fixture: VerificationServer;
@@ -58,7 +59,8 @@ describe("organizational folders through an isolated HTTP fixture", () => {
expect((await api("PATCH", `/api/bots/${bot.id}/tasks/${first.threadId}`, { modelSelection: selection(models[1]) })).status).toBe(200);
expect(first.cwd).toBeUndefined();
expect((await api("POST", `/api/bots/${bot.id}/messages`, { threadId: first.threadId, text: "Keep this project's conversation" })).status).toBe(202);
- await expect.poll(() => existsSync(join(fixture.info.dataDir, "fake-claude-dump.json"))).toBe(true);
+ // A cold engine start on a loaded Windows runner takes longer than expect.poll's default second.
+ await expect.poll(() => existsSync(join(fixture.info.dataDir, "fake-claude-dump.json")), { timeout: hostTimeout(15_000) }).toBe(true);
expect((await getBot(bot.id)).tasks.find((task: any) => task.threadId === first.threadId).busy).toBe(true);
expect((await api("PATCH", `/api/bots/${bot.id}/projects/${projectId}`, { name: "Site" })).status).toBe(200);
const moved = await api("PATCH", `/api/bots/${bot.id}/tasks/${first.threadId}`, { projectId: other.id });
@@ -78,7 +80,7 @@ describe("organizational folders through an isolated HTTP fixture", () => {
expect(next.cwd).toBeUndefined();
expect((await api("PATCH", `/api/bots/${bot.id}/projects/${projectId}`, { modelSelection: null })).status).toBe(400);
expect((await api("POST", `/api/bots/${bot.id}/interrupt`, { threadId: first.threadId })).status).toBe(200);
- await expect.poll(async () => (await getBot(bot.id)).busy).toBe(false);
+ await expect.poll(async () => (await getBot(bot.id)).busy, { timeout: hostTimeout(15_000) }).toBe(false);
expect((await getBot(bot.id)).tasks.some((task: any) => task.threadId === originalThread)).toBe(true);
});
diff --git a/server/routes/status.ts b/server/routes/status.ts
index 068d9e2c8d..2244609517 100644
--- a/server/routes/status.ts
+++ b/server/routes/status.ts
@@ -1,5 +1,5 @@
import { readBotActivity } from "../activity.ts";
-import { activityCsv, activityEntries, parseActivityWhat, readAdminActivityRange } from "../admin-activity.ts";
+import { activityCsv, activityEntries, flushAdminActivity, parseActivityWhat, readAdminActivityRange } from "../admin-activity.ts";
import { loadBrand } from "../brand.ts";
import { browserEngineStatus, ensureChrome, installAgentBrowserBinary, resolveAgentBrowserBinary } from "../browser-engine.ts";
import { DATA_DIR, EVENTS_DIR, NATIVE_DIR, instanceConfigs, type AppConfig } from "../config.ts";
@@ -188,6 +188,7 @@ export function createStatusRoutes(deps: StatusRouteDeps): RouteHandler {
if (!range) return json(res, 400, { error: "from and to must be dates (YYYY-MM-DD), from no later than to, at most a year apart" });
const what = parseActivityWhat(url.searchParams.get("what"));
if (!what) return json(res, 400, { error: "what must be all, approvals, decisions, config, people, session, webhook, mcp, engine, bot, budget or visibility" });
+ await flushAdminActivity(DATA_DIR); // rows are appended in the background; a change already answered is listed
const entries = activityEntries(readDecisionRange(DATA_DIR, range).map(decision), readAdminActivityRange(DATA_DIR, range).filter(deps.records?.adminActionShown(auth) ?? (() => true)), {
what,
who: (url.searchParams.get("who") ?? "").slice(0, 200),
diff --git a/server/vault-store.test.ts b/server/vault-store.test.ts
index 8cfc60def9..4655ea6730 100644
--- a/server/vault-store.test.ts
+++ b/server/vault-store.test.ts
@@ -264,6 +264,18 @@ describe("a Team Cloud member's own secrets", () => {
expect(store.listSecrets({ person: ADA, team: false }).map((one) => one.id)).toEqual([ada.id]);
});
+ it("win over the team's secret of the same name in that person's turns, saved in the same millisecond or before it", () => {
+ let at = 5;
+ const store = new VaultStore({ dataDir: dir, now: () => at });
+ const team = store.saveSecret({ name: "Stripe secret key", value: "sk_test_fake-team", source: "settings", bots: ["pepper"] });
+ const ada = own(store);
+ expect(store.usableSecret("Stripe secret key", "pepper", "ref", { person: ADA, team: true })?.id).toBe(ada.id);
+ at = 6;
+ store.updateSecret(team.id, { value: "sk_test_fake-team-2" });
+ expect(store.usableSecret("Stripe secret key", "pepper", "ref", { person: ADA, team: true })?.id).toBe(ada.id);
+ expect(store.usableSecret("Stripe secret key", "pepper", "ref", { person: BEN, team: true })?.id).toBe(team.id);
+ });
+
it("are another secret than the team's or another member's of the same name, and are never replaced from elsewhere", () => {
const store = new VaultStore({ dataDir: dir });
const team = store.saveSecret({ name: "Stripe secret key", value: "fake-team", source: "card", bots: ["pepper"], refOnly: true });
diff --git a/server/vault-store.ts b/server/vault-store.ts
index 21ea56f0d7..1e46a8482f 100644
--- a/server/vault-store.ts
+++ b/server/vault-store.ts
@@ -351,13 +351,15 @@ export class VaultStore {
return (this.read().secrets ?? []).filter((secret) => secretReadable(secret, reader)).map(summarizeSecret).sort((a, b) => a.name.localeCompare(b.name));
}
- /** The secret `botId` may use by this name, as a ref or a file, in a turn `reader` names: one kept to some bots before
- * one for every bot, then the newest. */
+ /** The secret `botId` may use by this name, as a ref or a file, in a turn `reader` names: the person's own before the
+ * team's of the same name, whichever was saved later; then one kept to some bots before one for every bot; then the
+ * newest. */
usableSecret(name: string, botId: string, delivery: "ref" | "file", reader: VaultReader): StoredSecret | null {
const key = vaultNameKey(name);
const matches = (this.read().secrets ?? []).filter((secret) => vaultNameKey(secret.name) === key && loginUsableBy(secret, botId) &&
secretReadable(secret, reader) && (delivery === "ref" || !secret.refOnly));
- return matches.sort((a, b) => Number(b.bots !== "all") - Number(a.bots !== "all") || b.updatedAt - a.updatedAt)[0] ?? null;
+ return matches.sort((a, b) => Number(Boolean(b.person)) - Number(Boolean(a.person)) || Number(b.bots !== "all") - Number(a.bots !== "all") ||
+ b.updatedAt - a.updatedAt)[0] ?? null;
}
secretNamesFor(botId: string, reader: VaultReader): Array<{ name: string; refOnly?: true }> {