Menu
popagent
publicLatest change 1ce5ab5f17eefb3cef070f9d98b28f2bb1e5c879 - Secure agent secrets behind origin-bound browser use 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";
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(["popagent", "researcher", "implementer", "reviewer"]),
);
expect(roles.find(({ id }) => id === "popagent")?.tools).toContain("useBrowserSecret");
for (const role of roles) {
expect(role.tools).not.toEqual(expect.arrayContaining([
"storeSecret",
"recallSecret",
"updateSecret",
]));
}
for (const role of roles) {
expect(role.description.length).toBeGreaterThan(0);
expect(role.instructions).toStartWith("# Role:");
expect(role.sourceUrls).toEqual(
expect.arrayContaining([expect.stringContaining("msitarzewski/agency-agents")]),
);
}
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,
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("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,
tools: ["webSearch"],
})).toBeUndefined();
});
test("rejects runtime instructions beyond the storage contract", async () => {
await expect(store.update("popagent", {
name: "popagent",
description: "Supervisor",
instructions: "x".repeat(MAX_AGENT_INSTRUCTIONS_CHARACTERS + 1),
workspaceAccess: "read-write",
browserAccess: "interactive",
delegationEnabled: false,
tools: ["webSearch"],
})).rejects.toThrow(`Agent instructions exceed ${MAX_AGENT_INSTRUCTIONS_CHARACTERS} characters`);
});
test("rejects empty runtime identity fields", async () => {
await expect(store.update("popagent", {
name: " ",
description: "Supervisor",
instructions: "Instructions",
workspaceAccess: "read-write",
browserAccess: "interactive",
delegationEnabled: false,
tools: ["webSearch"],
})).rejects.toThrow("Agent name, description, and instructions must not be empty");
});
});