Menu
popagent
publicLatest change 295450e0deb3d491594ce60ac86509a1a1db44ce - Expand Popagent one-shot management CLI by Ólafur Búi Ólafsson
import { describe, expect, test } from "bun:test";
const run = async (args: string[], url?: string) => {
const process = Bun.spawn(["./popagent", ...args], {
stdout: "pipe",
stderr: "pipe",
env: { ...Bun.env, ...(url ? { POPAGENT_URL: url } : {}) },
});
return {
exitCode: await process.exited,
stdout: await new Response(process.stdout).text(),
stderr: await new Response(process.stderr).text(),
};
};
describe("popagent CLI", () => {
test("gives AI agents a complete one-shot command index", async () => {
const result = await run(["help"]);
expect(result.exitCode).toBe(0);
expect(result.stderr).toBe("");
for (const command of [
"popagent agent-update <agent> <json>",
"popagent skill-create <agent> <json>",
"popagent workspace-create <json>",
"popagent doc-save <workspace> <json>",
"popagent docs-reindex <workspace>",
"popagent task-create <workspace> <prompt> [model]",
"popagent task-delete <task-id>",
"popagent schedule-create <json>",
"popagent settings-update <section> <json>",
"popagent api <METHOD> <path> [json]",
]) expect(result.stdout).toContain(command);
expect(result.stdout).toContain("POPAGENT_URL");
expect(result.stdout).toContain("x-popagent-key");
expect(result.stdout).toContain("JSON arguments are passed unchanged");
});
test("routes named management commands without rewriting JSON", async () => {
const requests: Array<{ method: string; path: string; body: string }> = [];
const server = Bun.serve({
port: 0,
async fetch(request) {
requests.push({
method: request.method,
path: new URL(request.url).pathname,
body: await request.text(),
});
return Response.json({ ok: true });
},
});
try {
const body = '{"path":"guides/start.md","content":"# Start"}';
const result = await run(["doc-save", "team/a", body], server.url.toString());
expect(result.exitCode).toBe(0);
expect(JSON.parse(result.stdout)).toEqual({ ok: true });
expect(requests).toEqual([{
method: "POST",
path: "/api/workspaces/team%2Fa/docs",
body,
}]);
} finally {
server.stop(true);
}
});
});