Skip to content

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

2.1 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { taggedAnswerRow } from "./tagged-answer.ts";

const chief = { id: "chief", name: "Chief", color: "red" as const };
const answered = { id: "h1", botId: "chief", mode: "consult" as const, status: "completed" as const, result: " $4.20 today. " };
const wesChat = { botId: "wes" };
const is = (...ids: string[]) => (botId: string) => ids.includes(botId);

describe("a teammate tagged in another bot's one-to-one chat", () => {
  it("answers there under its own name", () => {
    expect(taggedAnswerRow(answered, wesChat, chief, is("chief"))).toEqual({
      role: "bot", kind: "text", text: "$4.20 today.",
      from: { botId: "chief", name: "Chief", color: "red" }, roomRequest: { id: "h1", phase: "result" },
    });
  });

  it("keeps the teammate row for everything else", () => {
    expect(taggedAnswerRow(answered, wesChat, chief, is())).toBeNull();
    expect(taggedAnswerRow(answered, { ...wesChat, groupId: "room" }, chief, is("chief"))).toBeNull();
    expect(taggedAnswerRow(answered, { ...wesChat, parentId: "p" }, chief, is("chief"))).toBeNull();
    expect(taggedAnswerRow({ ...answered, mode: "work" }, wesChat, chief, is("chief"))).toBeNull();
    expect(taggedAnswerRow({ ...answered, status: "failed" }, wesChat, chief, is("chief"))).toBeNull();
    expect(taggedAnswerRow({ ...answered, result: "  " }, wesChat, chief, is("chief"))).toBeNull();
    expect(taggedAnswerRow(answered, wesChat, undefined, is("chief"))).toBeNull();
    expect(taggedAnswerRow({ ...answered, botId: "wes" }, wesChat, chief, is("wes"))).toBeNull();
  });
});

describe("the tagged teammate's reply", () => {
  it("belongs to the person's request, so Stop still finds that request", () => {
    expect(taggedAnswerRow(answered, wesChat, chief, is("chief"), "u1")?.requestMessageId).toBe("u1");
    expect(taggedAnswerRow(answered, wesChat, chief, is("chief"))).not.toHaveProperty("requestMessageId");
  });


  it("hides secrets like the teammate row does", () => {
    const key = "sk-ant-api03-" + "x".repeat(40);
    expect(taggedAnswerRow({ ...answered, result: `key ${key}` }, wesChat, chief, is("chief"))?.text).not.toContain(key);
  });
});