Menu
popagent
publicLatest change 4565eb356975518dfc0202eab29b56dff51e8f71 - add deterministic agent health validation by AkurAI Build
import { describe, expect, test } from "bun:test";
import type { RequestContext } from "@mastra/core/request-context";
import { join, resolve } from "node:path";
import { createAgentRequestContext } from "../agent-context";
import { createCodeIntelligenceTools } from "./code-intelligence";
const autonomousPath = resolve(
process.env.POPAGENT_DATA_DIR ?? join(process.cwd(), "data"),
"self-update",
"task-a",
);
const service = {
codeContext: async (workspaceId: string, query: string, limit: number, repositoryPath?: string) => ({
evidence: `${workspaceId}:${query}:${limit}:${repositoryPath ?? "registered"}`,
}),
symbolContext: async (workspaceId: string, symbol: string, filePath?: string, repositoryPath?: string) => ({
definition: `${workspaceId}:${symbol}:${filePath ?? "any"}:${repositoryPath ?? "registered"}`,
callers: "callers",
callees: "callees",
}),
changeImpact: async (workspaceId: string, paths: string[], repositoryPath?: string) => ({
paths,
branchImpact: `${workspaceId}:${repositoryPath ?? "registered"}`,
files: [],
unresolved: [],
}),
};
function requestContext(overrides: { workspaceId?: string; executionSource?: "chat" | "self-update"; selfUpdateWorkspacePath?: string } = {}) {
return createAgentRequestContext({
resourceId: "popagent-user",
sessionId: "code-intelligence",
turnId: "code-intelligence-turn",
model: "test-model",
workspaceId: overrides.workspaceId,
executionSource: overrides.executionSource,
selfUpdateWorkspacePath: overrides.selfUpdateWorkspacePath,
}) as unknown as RequestContext;
}
describe("code intelligence agent tools", () => {
test("bind workspace identity rather than accepting repository paths", async () => {
const tools = createCodeIntelligenceTools(service as never);
await expect(tools.codeContext.execute!(
{ query: "browser policy", limit: 6 },
{ requestContext: requestContext({ workspaceId: "workspace-a" }) } as never,
)).resolves.toEqual({ evidence: "workspace-a:browser policy:6:registered" });
});
test("use the trusted autonomous checkout path from request context", async () => {
const tools = createCodeIntelligenceTools(service as never);
await expect(tools.changeImpact.execute!(
{ paths: ["src/server.ts"] },
{
requestContext: requestContext({
workspaceId: "workspace-a",
executionSource: "self-update",
selfUpdateWorkspacePath: autonomousPath,
}),
} as never,
)).resolves.toEqual({
paths: ["src/server.ts"],
branchImpact: `workspace-a:${autonomousPath}`,
files: [],
unresolved: [],
});
});
});