Files
oh-my-pi/packages/coding-agent/test/role-thinking-helper-propagation.test.ts
T
can1357 f08e6397db test: added tiny-model role-propagation and title routing tests
- Added `get(path)` support in test `createSettings` to return tiny model setting for `providers.tinyModel`.
- Updated `createSettings` in tests to accept optional `tinyModel` with default `"online"`.
- Added `flushMicrotasks()` and helper factories for test settings, registry stubs, and online model mocks.
- Added tests for `raceFirstNonNull`, `generateSessionTitle` routing, and providers tinyModel enum validation.
2026-05-30 16:55:54 +02:00

87 lines
2.6 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 {
get(path: string) {
if (path === "providers.tinyModel") return "online";
return undefined;
},
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 });
});
});