Files
oh-my-pi/packages/coding-agent/test/commit-agentic-attribution.test.ts
T
can1357 afc2276a12 refactor(ai): extracted OpenAI compat logic into dedicated module
- Extracted OpenAI compatibility detection and resolution logic into dedicated `openai-completions-compat` module.
- Refactored `detectCompat()` and `getCompat()` to delegate to new compat module functions with simplified conditional logic.
- Fixed OAuth redirect URI validation to preserve exact configured values without trailing slash normalization.
- Improved session deletion to return boolean status and display error messages in UI instead of silently failing.
- Added `/session delete` command with Delete key support and confirmation dialogs for session management.
2026-03-17 16:07:26 +01:00

51 lines
1.6 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import { getBundledModel } from "@oh-my-pi/pi-ai";
import { runCommitAgentSession } from "../src/commit/agentic/agent";
import * as toolsModule from "../src/commit/agentic/tools";
import { Settings } from "../src/config/settings";
import type { CreateAgentSessionResult } from "../src/sdk";
import * as sdkModule from "../src/sdk";
import type { PromptOptions } from "../src/session/agent-session";
describe("commit agent prompt attribution", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("marks generated commit prompts and reminders as agent-attributed", async () => {
const prompts: Array<{ text: string; options?: PromptOptions }> = [];
const session = {
prompt: async (text: string, options?: PromptOptions) => {
prompts.push({ text, options });
},
subscribe: () => () => {},
dispose: async () => {},
};
vi.spyOn(sdkModule, "createAgentSession").mockResolvedValue({ session } as unknown as CreateAgentSessionResult);
vi.spyOn(toolsModule, "createCommitTools").mockReturnValue([]);
const model = getBundledModel("anthropic", "claude-sonnet-4-5");
if (!model) {
throw new Error("Expected claude-sonnet-4-5 model to exist");
}
await runCommitAgentSession({
cwd: "/tmp",
git: {} as never,
model,
settings: Settings.isolated(),
modelRegistry: {} as never,
authStorage: {} as never,
changelogTargets: [],
requireChangelog: false,
});
expect(prompts).toHaveLength(4);
for (const prompt of prompts) {
expect(prompt.options?.attribution).toBe("agent");
expect(prompt.options?.expandPromptTemplates).toBe(false);
}
});
});