Files
oh-my-pi/packages/coding-agent/test/commit-model-selection-role-thinking.test.ts
T
can1357 cba6641299 feat: enabled resolver-based API key retries with refresh and rotation
- Added `ApiKeyResolver`/`ApiKey` types and exported auth-retry helpers.
- Changed stream and gateway auth retry handling to use resolver steps.
- Added initial-key, force-refresh, and rotate credential retries for auth failures.
- Updated agent and coding-agent integrations to use context-aware API-key resolvers.
2026-06-07 04:20:48 +02:00

54 lines
1.8 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { Effort, getBundledModel } from "@oh-my-pi/pi-ai";
import { resolvePrimaryModel, resolveSmolModel } from "../src/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 },
};
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);
});
});