Files
oh-my-pi/packages/coding-agent/test/session-manager/rewrite-tool-call.test.ts
T
can1357 cb5bbbf382 refactor(coding-agent): flattened directory structure, eliminated core/ folder
- Eliminated core/ directory (252 files, 23 subdirs → distributed)
- Reduced max nesting from 9 levels to 5 levels
- Promoted tool subdirs to top level: exa/, lsp/, patch/, task/, web/
- Merged web-scrapers/ + web-search/ into web/{scrapers,search}/
- Flattened modes/interactive/ to modes/
- Split execution/ into: ipy/ (python), exec/ (bash), ssh/
- Renamed ipy/python-*.ts to ipy/*.ts (executor, kernel, etc.)
- Flattened cursor/exec-bridge.ts to cursor.ts
- Created logical groupings: config/, session/, extensibility/, export/
- Updated all imports across 500+ files
2026-01-23 12:24:47 +01:00

53 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import type { AssistantMessage, ToolCall } from "@oh-my-pi/pi-ai";
import { SessionManager } from "$c/session/session-manager";
function buildAssistantMessage(content: AssistantMessage["content"]): AssistantMessage {
return {
role: "assistant",
content,
api: "anthropic-messages",
provider: "anthropic",
model: "test",
usage: {
input: 1,
output: 1,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 2,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
},
stopReason: "stop",
timestamp: 1,
};
}
describe("SessionManager tool call rewrite", () => {
it("rewrites assistant toolCall arguments in context", async () => {
const session = SessionManager.inMemory();
const toolCallId = "toolu_rewrite_1";
const toolCall = {
type: "toolCall",
id: toolCallId,
name: "edit",
arguments: { path: "file.ts", op: "update", diff: "@@\n-old\n+new" },
} satisfies ToolCall;
session.appendMessage(buildAssistantMessage([toolCall]));
const updated = await session.rewriteAssistantToolCallArgs(toolCallId, {
path: "file.ts",
op: "update",
diff: "@@\n-old\n+newer",
});
expect(updated).toBe(true);
const ctx = session.buildSessionContext();
const assistant = ctx.messages.find((m) => m.role === "assistant") as AssistantMessage;
const updatedCall = assistant.content.find((b) => b.type === "toolCall") as ToolCall;
expect(updatedCall.arguments).toEqual({ path: "file.ts", op: "update", diff: "@@\n-old\n+newer" });
});
});