AkurAI Build
Menu

popagent

public

Latest change dc4b371554df3a78c40c29085ead1db3de7e24f8 - Add model routing policy, companyStatus tool, Markdown channel output, compact Runtime settings by AkurAI Build

import { describe, expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import type { AgentSettings } from "../api-types";
import { AgentIdentityCard, AgentRosterRow, agentRosterGroups, AgentWorkSource, BrowserProviderLeds, ModelRoutingEditor, RuntimeModelSource, scheduleTimingLabel, scheduleWorkspaceName } from "./AgentSettingsPage";

describe("global schedule view", () => {
  test("labels each schedule with its execution workspace", () => {
    expect(scheduleWorkspaceName("simulation", [
      { id: "default", name: "popagent", repositoryPath: "popagent", createdAt: "", updatedAt: "" },
      { id: "simulation", name: "Market Simulation", repositoryPath: "simulation", createdAt: "", updatedAt: "" },
    ])).toBe("Market Simulation");
    expect(scheduleTimingLabel({ source: "self-update", cron: "0 * * * *", nextRunAt: "2099-01-01T00:00:00Z" })).toBe("When idle");
  });
});

describe("agent work source", () => {
  test("labels user, self-update, and Build maintenance work explicitly", () => {
    expect(renderToStaticMarkup(<AgentWorkSource source="user" />)).toContain("source user");
    expect(renderToStaticMarkup(<AgentWorkSource source="self-update" />)).toContain("source self-update");
    expect(renderToStaticMarkup(<AgentWorkSource source="build-maintenance" />)).toContain("source build-maintenance");
  });
});

describe("runtime model source", () => {
  test("offers configured, local Titan, and OpenRouter free routes", () => {
    const markup = renderToStaticMarkup(
      <RuntimeModelSource value="local" onChange={() => {}} />,
    );
    expect(markup).toContain("Configured model");
    expect(markup).toContain("Titan local 9B");
    expect(markup).toContain("OpenRouter free router");
  });
});

describe("agent identity card", () => {
  test("shows the assigned person's portrait, title, department, and email", () => {
    const markup = renderToStaticMarkup(
      <AgentIdentityCard
        agentId="orchistrator"
        model="cx/gpt-5.6-luna-max"
        delegationEnabled={true}
      />,
    );
    expect(markup).toContain("Embla Náttsól");
    expect(markup).toContain("Operations Coordinator");
    expect(markup).toContain("Operations");
    expect(markup).toContain("mailto:embla@olibuijr.com");
    expect(markup).toContain("/api/company/avatars/6766bf84-a89a-4b01-bf21-94777efb2e7c");
    expect(markup).toContain("cx/gpt-5.6-luna-max");
  });
});

describe("agent roster row", () => {
  test("presents each agent as a compact identity row", () => {
    const markup = renderToStaticMarkup(
      <AgentRosterRow
        agent={{
          id: "researcher",
          name: "Researcher",
          description: "Evidence investigator",
          instructions: "Investigate.",
          model: "codex/gpt-5.6-luna-medium",
          sourceUrls: [],
          workspaceAccess: "read-only",
          browserAccess: "read-only",
          delegationEnabled: true,
          tools: [],
          createdAt: "",
          updatedAt: "",
        }}
        selected={true}
        onChoose={() => {}}
      />,
    );
    expect(markup).toContain("Salka Valgerðardóttir");
    expect(markup).toContain("Technical Documentation Lead");
    expect(markup).not.toContain("Evidence investigator");
    expect(markup).toContain("size-8");
    expect(markup).toContain('aria-pressed="true"');
  });

  test("does not repeat generated role copy beneath the staff title", () => {
    const markup = renderToStaticMarkup(
      <AgentRosterRow
        agent={{
          id: "staff-soley",
          name: "Mail API Engineer",
          description: "Mail API Engineer for AkurAI Communications, responsible for evidence-backed work within that specialty.",
          instructions: "Own mail API work.",
          model: "codex/gpt-5.6-luna-medium",
          sourceUrls: [],
          workspaceAccess: "read-write",
          browserAccess: "read-only",
          delegationEnabled: true,
          tools: [],
          createdAt: "",
          updatedAt: "",
        }}
        selected={false}
        onChoose={() => {}}
      />,
    );
    expect(markup).toContain("Sóley Hvannberg");
    expect(markup).toContain("Mail API Engineer");
    expect(markup).not.toContain("responsible for evidence-backed work");
  });
});

describe("agent roster groups", () => {
  const agent = (id: string, name: string): AgentSettings => ({
    id,
    name,
    description: "",
    instructions: "",
    model: null,
    sourceUrls: [],
    workspaceAccess: "none",
    browserAccess: "none",
    delegationEnabled: true,
    tools: [],
    createdAt: "",
    updatedAt: "",
  });

  test("groups agents by department and filters by name, role, or department", () => {
    const agents = [agent("orchistrator", "Orchistrator"), agent("staff-soley", "Mail API Engineer"), agent("custom", "Custom agent")];
    expect(agentRosterGroups(agents).map((group) => group.name)).toEqual(["Communications", "Operations", "Other agents"]);
    expect(agentRosterGroups(agents, "sóley")).toEqual([{ name: "Communications", members: [agents[1]!] }]);
    expect(agentRosterGroups(agents, "operations")).toEqual([{ name: "Operations", members: [agents[0]!] }]);
    expect(agentRosterGroups(agents, "nobody")).toEqual([]);
  });
});

describe("browser provider LEDs", () => {
  test("shows a green LED for working browsers, red for unavailable, and marks the selected provider", () => {
    const markup = renderToStaticMarkup(
      <BrowserProviderLeds selected="bifrost-navigator" health={{
        provider: "BifrOSt Navigator", healthy: false, headless: false, selected: "bifrost-navigator",
        providers: [
          { id: "agent-browser", label: "Headless AgentBrowser", healthy: true, headless: true, detail: "Chromium installed" },
          { id: "bifrost-navigator", label: "BifrOSt Navigator", healthy: false, headless: false, detail: "MCP socket unreachable" },
        ],
        enabled: true, scope: "thread", activeSessions: 0, profileConfigured: false, screencastEnabled: true, recordingEnabled: false,
      }} />,
    );
    expect(markup).toContain('aria-label="Headless AgentBrowser: working"');
    expect(markup).toContain("bg-emerald-500");
    expect(markup).toContain('aria-label="BifrOSt Navigator: unavailable"');
    expect(markup).toContain("bg-red-500");
    expect(markup).toContain("Selected");
    expect(markup).toContain("MCP socket unreachable");
  });

  test("pulses amber while health is still loading", () => {
    const markup = renderToStaticMarkup(<BrowserProviderLeds selected="agent-browser" />);
    expect(markup).toContain("bg-amber-400");
    expect(markup).toContain('aria-label="BifrOSt Navigator: checking"');
  });
});

describe("model routing editor", () => {
  test("renders ordered routes with effort, strategy, and per-route LEDs, and tolerates a missing value", () => {
    const markup = renderToStaticMarkup(
      <ModelRoutingEditor
        models={["policy/routing", "cc/claude-sonnet-5", "cx/gpt-5.6-sol"]}
        value={{ enabled: true, strategy: "fallback", cooldownMs: 900_000, routes: [
          { model: "cc/claude-sonnet-5", reasoningEffort: "low" },
          { model: "cx/gpt-5.6-sol", reasoningEffort: "low" },
        ] }}
        health={[
          { spec: "cc/claude-sonnet-5@low", cooldownUntil: "2099-01-01T00:00:00Z", lastError: "429 usage limit", picks: 3 },
          { spec: "cx/gpt-5.6-sol@low", cooldownUntil: null, lastError: null, picks: 1 },
        ]}
        onChange={() => {}}
      />,
    );
    expect(markup).toContain("Primary");
    expect(markup).toContain("Route 2");
    expect(markup).toContain('aria-label="Route 1: cooling down until');
    expect(markup).toContain('aria-label="Route 2: available"');
    expect(markup).toContain("Last failure: 429 usage limit");
    expect(markup).not.toContain('<option value="policy/routing"');
    expect(renderToStaticMarkup(<ModelRoutingEditor models={[]} onChange={() => {}} />)).toContain("No routes yet");
  });
});