test: tighten usage reporting assertions

This commit is contained in:
Peter Steinberger
2026-05-09 17:09:45 +01:00
parent fa04cc3526
commit e77dbe875f

View File

@@ -83,11 +83,10 @@ describe("runEmbeddedPiAgent usage reporting", () => {
workspaceDir: "/tmp/workspace",
allowGatewaySubagentBinding: true,
});
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledWith(
expect.objectContaining({
allowGatewaySubagentBinding: true,
}),
);
const attemptInput = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as
| { allowGatewaySubagentBinding?: boolean }
| undefined;
expect(attemptInput?.allowGatewaySubagentBinding).toBe(true);
});
it("forwards sender identity fields into embedded attempts", async () => {
@@ -111,14 +110,18 @@ describe("runEmbeddedPiAgent usage reporting", () => {
senderE164: "+15551234567",
});
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledWith(
expect.objectContaining({
senderId: "user-123",
senderName: "Josh Lehman",
senderUsername: "josh",
senderE164: "+15551234567",
}),
);
const attemptInput = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as
| {
senderId?: string;
senderName?: string;
senderUsername?: string;
senderE164?: string;
}
| undefined;
expect(attemptInput?.senderId).toBe("user-123");
expect(attemptInput?.senderName).toBe("Josh Lehman");
expect(attemptInput?.senderUsername).toBe("josh");
expect(attemptInput?.senderE164).toBe("+15551234567");
});
it("forwards memory flush write paths into memory-triggered attempts", async () => {
@@ -140,12 +143,11 @@ describe("runEmbeddedPiAgent usage reporting", () => {
memoryFlushWritePath: "memory/2026-03-10.md",
});
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledWith(
expect.objectContaining({
trigger: "memory",
memoryFlushWritePath: "memory/2026-03-10.md",
}),
);
const attemptInput = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as
| { trigger?: string; memoryFlushWritePath?: string }
| undefined;
expect(attemptInput?.trigger).toBe("memory");
expect(attemptInput?.memoryFlushWritePath).toBe("memory/2026-03-10.md");
});
it("reports total usage from the last turn instead of accumulated total", async () => {
@@ -186,7 +188,9 @@ describe("runEmbeddedPiAgent usage reporting", () => {
// Check usage in meta
const usage = result.meta.agentMeta?.usage;
expect(usage).toMatchObject({ input: 250, output: 100, total: 200 });
expect(usage?.input).toBe(250);
expect(usage?.output).toBe(100);
expect(usage?.total).toBe(200);
// Check if total matches the last turn's total (200)
// If the bug exists, it will likely be 350