Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import { StoreProvider, type Group, type Message } from "@/state/store";
const mode = vi.hoisted(() => ({ advanced: false }));
vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => mode.advanced, setAdvancedMode: vi.fn() }));
// Replaced whole: its context default reads window.ogb at import time.
vi.mock("./DesktopCapabilities", () => ({
useDesktopCapabilities: () => ({ capabilities: { dictation: { available: false } } }),
useCaptionChrome: () => ({}),
}));
import { GroupView, RoomToolChip } from "./GroupView";
const chip = (patch: Partial<Message> = {}): Message => ({
id: "chip",
role: "bot",
kind: "activity",
at: 1,
tool: { name: "Posted in Standup", ok: true },
...patch,
});
const render = (message: Message) =>
renderToStaticMarkup(createElement(StoreProvider, null, createElement(RoomToolChip, { message })));
describe("RoomToolChip", () => {
it("turns a linked receipt into a button that opens the room it names", () => {
const markup = render(chip({
comm: { groupId: "room-standup", withBotId: "scout", withName: "Standup", withColor: "green" },
}));
expect(markup).toContain("<button");
expect(markup).toContain("Posted in Standup");
expect(markup).toContain('title="Open Standup"');
});
it("turns an opened-thread receipt into a button that opens that thread", () => {
const markup = render(chip({
tool: { name: "Opened thread #QA PR 245 on Scout", ok: true },
threadRef: { botId: "scout", threadId: "qa-245", title: "QA PR 245" },
}));
expect(markup).toContain("<button");
expect(markup).toContain("Opened thread #QA PR 245 on Scout");
expect(markup).toContain('title="Open #QA PR 245"');
});
it("leaves an ordinary step as a plain pill", () => {
const markup = render(chip());
expect(markup).not.toContain("<button");
expect(markup).toContain("Posted in Standup");
});
it("shows a same-room teammate avatar without adding a navigation button", () => {
const message = chip({
tool: { name: "Sent to Eli", ok: true },
comm: { groupId: "here", withBotId: "eli", withName: "Eli", withColor: "green" },
});
const markup = renderToStaticMarkup(createElement(StoreProvider, null,
createElement(RoomToolChip, { message, roomId: "here" })));
expect(markup).toContain("Sent to Eli");
expect(markup).toContain('aria-label="Eli"');
expect(markup).not.toContain("<button");
});
});
describe("room header", () => {
const room: Group = {
id: "room", threadId: "room-thread", name: "Launch planning", memberIds: [],
defaultResponder: { kind: "member", botId: "atlas" }, bulletin: "", unread: false,
createdAt: 1, setupCompletedAt: 1, messages: [],
};
it("wraps into a name line and a control line when the column is narrow in Advanced mode", () => {
vi.stubGlobal("window", { ogb: undefined });
mode.advanced = true;
let markup: string;
try {
markup = renderToStaticMarkup(createElement(StoreProvider, null, createElement(GroupView, { group: room })));
} finally {
vi.unstubAllGlobals();
mode.advanced = false;
}
expect(markup).toContain("@container/roomhead");
const row = /data-roomhead-row="[^"]*" class="([^"]*)"/.exec(markup)!;
expect(row[1].split(" ")).toContain("@max-3xl/roomhead:flex-wrap");
const identity = /data-roomhead-identity="[^"]*" class="([^"]*)"/.exec(markup)!;
expect(identity[1].split(" ")).toEqual(expect.arrayContaining(["min-w-0", "@max-3xl/roomhead:basis-full"]));
const controls = /data-roomhead-controls="[^"]*" class="([^"]*)"/.exec(markup)!;
expect(controls[1].split(" ")).toEqual(expect.arrayContaining(["@max-3xl/roomhead:ml-auto", "@max-3xl/roomhead:flex-wrap"]));
expect(markup).toContain("Launch planning");
});
});