82b70ead61
- Added automatic Ollama model context window discovery from metadata for accurate token limits. - Added `attribution` option to `PromptOptions` for explicit billing and initiator attribution control. - Added automatic clearing of completed and abandoned todo tasks after ~1 minute. - Changed session directory migration to use `-tmp-` prefix instead of double-dash format. - Updated Ollama model registration to use discovered context window instead of hardcoded 128000 token default. Fixes #440
60 lines
1.8 KiB
TypeScript
60 lines
1.8 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 * as sdkModule from "../src/sdk";
|
|
import type { PromptOptions } from "../src/session/agent-session";
|
|
|
|
vi.mock("../src/sdk", () => ({
|
|
createAgentSession: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("../src/commit/agentic/tools", () => ({
|
|
createCommitTools: vi.fn(() => []),
|
|
}));
|
|
|
|
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 () => {},
|
|
};
|
|
|
|
(sdkModule.createAgentSession as unknown as { mockResolvedValue: (value: unknown) => void }).mockResolvedValue({
|
|
session,
|
|
});
|
|
(toolsModule.createCommitTools as unknown as { mockReturnValue: (value: unknown) => void }).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);
|
|
}
|
|
});
|
|
});
|