Menu
popagent
publicLatest change 6edc7e928c57dab23c0973ed3f7ee70b3ebb72d5 - Initial popagent baseline by AkurAI Build
import { beforeAll, describe, expect, test } from "bun:test";
import type { ChannelSettingsInput } from "./api-types";
import { ChannelStore } from "./channels";
import { AgentTaskStore } from "./tasks";
const store = new ChannelStore();
const tasks = new AgentTaskStore();
beforeAll(async () => {
await tasks.init();
await store.init();
});
describe("ChannelStore", () => {
test("persists the native channel configuration", async () => {
const original = await store.getSettings();
const input: ChannelSettingsInput = {
enabled: !original.enabled,
channelName: original.channelName === "#general" ? "#dispatch" : "#general",
dispatchMode: original.dispatchMode === "every-message" ? "mentions" : "every-message",
contextMessages: original.contextMessages === 20 ? 12 : 20,
streaming: !original.streaming,
toolDisplay: original.toolDisplay === "timeline" ? "compact" : "timeline",
};
try {
expect(await store.updateSettings(input)).toMatchObject(input);
expect(await new ChannelStore().getSettings()).toMatchObject(input);
} finally {
const { updatedAt: _updatedAt, ...restore } = original;
await store.updateSettings(restore);
}
});
test("atomically persists a channel message and its queued task", async () => {
const marker = `channel-test-${crypto.randomUUID()}`;
const before = await store.listMessages("general", { limit: 100 });
const result = await store.createDispatch({
channelId: "general",
workspaceId: "default",
content: marker,
model: "test/model",
authorId: "popagent-user",
authorName: "You",
});
try {
expect(result.task.status).toBe("queued");
expect(result.message).toMatchObject({
channelId: "general",
workspaceId: "default",
content: marker,
taskId: result.task.id,
authorName: "You",
});
expect(await store.listMessages("general", { limit: 100 })).toContainEqual(
expect.objectContaining({ id: result.message.id, taskId: result.task.id }),
);
} finally {
await store.storage.db.none("DELETE FROM popagent_channel_messages WHERE content=$1", [marker]);
await store.storage.db.none("DELETE FROM popagent_agent_tasks WHERE id=$1", [result.task.id]);
}
expect((await store.listMessages("general", { limit: 100 })).length).toBe(before.length);
});
test("rejects unknown channels and enforces bounded history", async () => {
await expect(store.createDispatch({
channelId: "missing",
workspaceId: "default",
content: "test",
model: "test/model",
authorId: "popagent-user",
authorName: "You",
})).rejects.toThrow("Channel not found");
await expect(store.listMessages("general", { limit: 0 })).rejects.toThrow("limit");
await expect(store.listMessages("general", { limit: 201 })).rejects.toThrow("limit");
});
});