AkurAI Build
Menu

popagent

public

Latest change fd6993822f5e0eaf74f85cc59cb51bd66bc2f1a4 - Migrate model route to cc/claude-sonnet-5 for native 9Router by AkurAI Build

import { beforeAll, describe, expect, test } from "bun:test";
import { MAX_AGENT_INSTRUCTIONS_CHARACTERS, type AgentSettingsInput } from "./api-types";
import { AgentSettingsStore } from "./agent-settings";
import { companyAgentProfiles } from "./company-roster";

const store = new AgentSettingsStore();

beforeAll(() => store.init());

describe("AgentSettingsStore", () => {
  test("bootstraps database-backed roles and persists complete role edits", async () => {
    const roles = await store.list();
    expect(roles.map((settings) => settings.id)).toEqual(
      expect.arrayContaining([
        "orchistrator", "researcher", "implementer", "reviewer",
        "build-maintainer", "build-release-manager", "community-steward",
      ]),
    );
    expect(roles).toHaveLength(companyAgentProfiles.length);
    expect(roles.map(({ id }) => id)).toEqual(
      expect.arrayContaining(companyAgentProfiles.map(({ id }) => id)),
    );
    expect(roles.map((settings) => settings.id)).not.toContain("popagent");
    expect(roles.find(({ id }) => id === "orchistrator")?.tools).toContain("useBrowserSecret");
    expect(roles.find(({ id }) => id === "orchistrator")?.tools).not.toContain("bifrostNavigator");
    expect(roles.find(({ id }) => id === "orchistrator")?.tools).toEqual(expect.arrayContaining([
      "codeContext",
      "symbolContext",
      "changeImpact",
    ]));
    expect(await store.storage.db.one<{ migrated: boolean }>(`
      SELECT EXISTS (
        SELECT 1 FROM popagent_data_migrations
        WHERE id = '2026-08-15-akurai-build-agents-v1'
      ) AS migrated
    `)).toEqual({ migrated: true });
    expect(await store.storage.db.one<{ migrated: boolean }>(`
      SELECT EXISTS (
        SELECT 1 FROM popagent_data_migrations
        WHERE id = '2026-08-16-company-specialist-agents-v1'
      ) AS migrated
    `)).toEqual({ migrated: true });
    expect(await store.storage.db.one<{ migrated: boolean }>(`
      SELECT EXISTS (
        SELECT 1 FROM popagent_data_migrations
        WHERE id = '2026-08-16-code-intelligence-tools-v1'
      ) AS migrated
    `)).toEqual({ migrated: true });
    expect(roles.find(({ id }) => id === "researcher")?.tools).not.toContain("bifrostNavigator");
    for (const role of roles.filter(({ workspaceAccess }) => workspaceAccess !== "none")) {
      expect(role.tools).toEqual(expect.arrayContaining([
        "codeContext",
        "symbolContext",
        "changeImpact",
      ]));
      expect(role.instructions).toContain("## Local code intelligence");
    }
    for (const role of roles) {
      expect(role.tools).not.toEqual(expect.arrayContaining([
        "storeSecret",
        "recallSecret",
        "updateSecret",
      ]));
      expect(role.description.length).toBeGreaterThan(0);
      expect(role.instructions).toStartWith("# Role:");
      expect(role.sourceUrls.length).toBeGreaterThan(0);
    }
    expect(roles.find(({ id }) => id === "orchistrator")?.sourceUrls)
      .toEqual(expect.arrayContaining([expect.stringContaining("msitarzewski/agency-agents")]));
    expect(roles.find(({ id }) => id === "orchistrator")?.model).toBeNull();
    expect(roles.find(({ id }) => id === "researcher")?.model).toBe("cc/claude-sonnet-5");
    expect(roles.find(({ id }) => id === "implementer")?.model).toBeNull();
    expect(roles.find(({ id }) => id === "reviewer")?.model).toBe("cc/claude-sonnet-5");
    expect(roles.find(({ id }) => id === "build-maintainer")?.model)
      .toBe("cc/claude-sonnet-5");
    expect(roles.find(({ id }) => id === "build-release-manager")?.model)
      .toBe("cc/claude-sonnet-5");
    expect(roles.find(({ id }) => id === "community-steward")?.model)
      .toBe("cc/claude-sonnet-5");
    expect(roles.find(({ id }) => id === "build-maintainer")?.workspaceAccess).toBe("read-write");
    expect(roles.find(({ id }) => id === "build-release-manager")?.workspaceAccess).toBe("none");
    expect(roles.find(({ id }) => id === "community-steward")?.workspaceAccess).toBe("none");

    const original = await store.get("researcher");
    if (!original) throw new Error("researcher settings missing");
    const input: AgentSettingsInput = {
      workspaceAccess: original.workspaceAccess === "none" ? "read-only" : "none",
      browserAccess: original.browserAccess === "none" ? "read-only" : "none",
      delegationEnabled: !original.delegationEnabled,
      model: original.model,
      tools: original.tools.includes("getTime") ? ["webSearch"] : ["getTime"],
      name: `Test Researcher ${crypto.randomUUID().slice(0, 8)}`,
      description: "Delegated test research",
      instructions: `# Role: Test Researcher\n\nTest instructions ${crypto.randomUUID()}`,
    };
    try {
      expect(await store.update("researcher", input)).toMatchObject(input);
      expect(await new AgentSettingsStore().get("researcher")).toMatchObject(input);
    } finally {
      await store.update("researcher", original);
    }
  });

  test("keeps Build operations inside their persisted role allowlists", async () => {
    const maintainer = await store.get("build-maintainer");
    if (!maintainer) throw new Error("Build maintainer settings missing");
    expect(maintainer.tools).toContain("akuraiRunQueue");
    expect(maintainer.tools).not.toContain("akuraiRunPromote");
    await expect(store.update("orchistrator", {
      name: "Orchistrator",
      description: "Supervisor",
      instructions: "# Role: Supervisor",
      workspaceAccess: "read-write",
      browserAccess: "interactive",
      delegationEnabled: false,
      model: null,
      tools: ["akuraiRunPromote"],
    })).rejects.toThrow("Non-Build agents cannot use AkurAI Build tools");
    await expect(store.update("build-maintainer", {
      ...maintainer,
      tools: ["akuraiRunPromote"],
    })).rejects.toThrow("Build agent tools exceed its role allowlist");
    const shared = await store.update("build-maintainer", { ...maintainer });
    expect(shared?.tools).toEqual(maintainer.tools);
    expect(shared?.tools).toContain("codeContext");
  });

  test("does not update an unknown agent", async () => {
    expect(await store.update("missing", {
      name: "Missing",
      description: "Missing role",
      instructions: "Missing instructions",
      workspaceAccess: "read-only",
      browserAccess: "none",
      delegationEnabled: true,
      model: null,
      tools: ["webSearch"],
    })).toBeUndefined();
  });

  test("rejects runtime instructions beyond the storage contract", async () => {
    await expect(store.update("orchistrator", {
      name: "Orchistrator",
      description: "Supervisor",
      instructions: "x".repeat(MAX_AGENT_INSTRUCTIONS_CHARACTERS + 1),
      workspaceAccess: "read-write",
      browserAccess: "interactive",
      delegationEnabled: false,
      model: null,
      tools: ["webSearch"],
    })).rejects.toThrow(`Agent instructions exceed ${MAX_AGENT_INSTRUCTIONS_CHARACTERS} characters`);
  });

  test("rejects empty runtime identity fields", async () => {
    await expect(store.update("orchistrator", {
      name: " ",
      description: "Supervisor",
      instructions: "Instructions",
      workspaceAccess: "read-write",
      browserAccess: "interactive",
      delegationEnabled: false,
      model: null,
      tools: ["webSearch"],
    })).rejects.toThrow("Agent name, description, and instructions must not be empty");
  });
});