Files
oh-my-pi/packages/coding-agent/test/role-thinking-helper-propagation.test.ts
T
can1357andCan Bölük 2ebb55134e fix(coding-agent): adjusted reasoning-disable handling and title generation for reasoned models
- Updated OpenAI completions parameterization to honor `disableReasoning` on effort-based compatible models by sending the minimum supported effort.
- Expanded commit and title generation token budgets so reasoning models can return output after internal thinking while non-reasoning calls keep existing limits.
- Switched title generation to request a `set_title` tool call, added extraction from tool-call arguments, and updated tests for the new behavior.
2026-05-22 15:51:32 +09:00

83 lines
2.5 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
import * as ai from "@oh-my-pi/pi-ai";
import { Effort, getBundledModel } from "@oh-my-pi/pi-ai";
import { generateCommitMessage } from "../src/utils/commit-message-generator";
import { generateSessionTitle } from "../src/utils/title-generator";
function getModelOrThrow(id: string) {
const model = getBundledModel("anthropic", id);
if (!model) throw new Error(`Expected model ${id}`);
return model;
}
function createSettings(modelRoles: Record<string, string>) {
return {
getModelRole(role: string) {
return modelRoles[role];
},
getStorage() {
return undefined;
},
} as never;
}
beforeEach(() => {
vi.clearAllMocks();
});
afterEach(() => {
vi.restoreAllMocks();
});
describe("role thinking helper propagation", () => {
it("passes smol-role thinking to commit message generation", async () => {
const model = getModelOrThrow("claude-sonnet-4-5");
const settings = createSettings({
default: `${model.provider}/${model.id}:high`,
smol: "pi/default:minimal",
});
const registry = {
getAvailable: () => [model],
getApiKey: async () => "test-key",
};
const completeSimpleMock = vi.spyOn(ai, "completeSimple").mockResolvedValue({
stopReason: "end_turn",
content: [{ type: "text", text: "fix scope handling" }],
} as never);
const message = await generateCommitMessage(`diff --git a/x b/x\n+change\n`, registry as never, settings);
expect(message).toBe("fix scope handling");
expect(completeSimpleMock.mock.calls[0]?.[2]).toMatchObject({
reasoning: Effort.Minimal,
maxTokens: 1024,
});
});
it("disables reasoning for title generation even when smol role has thinking", async () => {
const model = getModelOrThrow("claude-sonnet-4-5");
const settings = createSettings({
default: `${model.provider}/${model.id}:high`,
smol: "pi/default:low",
});
const registry = {
getAvailable: () => [model],
getApiKey: async () => "test-key",
};
const completeSimpleMock = vi.spyOn(ai, "completeSimple").mockResolvedValue({
stopReason: "end_turn",
content: [
{
type: "toolCall",
id: "call-title",
name: "set_title",
arguments: { title: "Investigate resolver" },
},
],
} as never);
const title = await generateSessionTitle("Investigate resolver", registry as never, settings);
expect(title).toBe("Investigate resolver");
expect(completeSimpleMock.mock.calls[0]?.[2]).toMatchObject({ disableReasoning: true });
});
});