56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { Effort } from "@oh-my-pi/pi-ai";
|
|
import { getBundledModel } from "@oh-my-pi/pi-catalog/models";
|
|
import { resolvePrimaryModel, resolveSmolModel } from "@oh-my-pi/pi-coding-agent/commit/model-selection";
|
|
|
|
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;
|
|
},
|
|
setModelRole(role: string, value: string) {
|
|
modelRoles[role] = value;
|
|
},
|
|
get(path: string) {
|
|
if (path === "modelRoles") return modelRoles;
|
|
return undefined;
|
|
},
|
|
} as never;
|
|
}
|
|
|
|
describe("commit role thinking selection", () => {
|
|
it("returns explicit thinking for commit and smol roles, including alias overrides", async () => {
|
|
const defaultModel = getModelOrThrow("claude-sonnet-4-5");
|
|
const commitModel = getModelOrThrow("claude-opus-4-5");
|
|
const settings = createSettings({
|
|
default: `${defaultModel.provider}/${defaultModel.id}:high`,
|
|
commit: `${commitModel.provider}/${commitModel.id}:low`,
|
|
smol: "pi/default:minimal",
|
|
});
|
|
const registry = {
|
|
getAvailable: () => [defaultModel, commitModel],
|
|
getApiKey: async () => "test-key",
|
|
getApiKeyForProvider: async () => "test-key",
|
|
authStorage: { rotateSessionCredential: async () => false as const },
|
|
resolver: () => async () => "test-key",
|
|
};
|
|
|
|
const primary = await resolvePrimaryModel(undefined, settings, registry);
|
|
expect(primary.model.id).toBe(commitModel.id);
|
|
expect(primary.thinkingLevel).toBe(Effort.Low);
|
|
|
|
const smol = await resolveSmolModel(settings, registry, commitModel, "fallback-key");
|
|
expect(smol.model.id).toBe(defaultModel.id);
|
|
expect(smol.thinkingLevel).toBe(Effort.Minimal);
|
|
});
|
|
});
|