1b9d9d0851
Move bundled models, model cache/manager, thinking metadata, effort helpers, provider descriptors/discovery, wire constants, and model identity utilities into the new @oh-my-pi/pi-catalog package. Update pi-ai to keep provider runtime/auth concerns, move catalog provider metadata into CATALOG_PROVIDERS, and migrate coding-agent, agent, stats, docs, and tests to import catalog values from pi-catalog. Split coding-agent model registry helpers into discovery, roles, and models config modules while preserving registry orchestration. BREAKING CHANGE: @oh-my-pi/pi-ai no longer exports catalog subpaths such as /models, /model-cache, /model-manager, /model-thinking, /effort, /provider-models*, discovery helpers, and provider wire constants; use the matching @oh-my-pi/pi-catalog subpaths instead.
112 lines
3.7 KiB
TypeScript
112 lines
3.7 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { Agent } from "@oh-my-pi/pi-agent-core";
|
|
import { createMockModel, type MockModel } from "@oh-my-pi/pi-ai/providers/mock";
|
|
import { getBundledModel } from "@oh-my-pi/pi-catalog/models";
|
|
import { ModelRegistry } from "@oh-my-pi/pi-coding-agent/config/model-registry";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { AgentSession } from "@oh-my-pi/pi-coding-agent/session/agent-session";
|
|
import { AuthStorage } from "@oh-my-pi/pi-coding-agent/session/auth-storage";
|
|
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
|
|
import { queueResolveHandler } from "@oh-my-pi/pi-coding-agent/tools/resolve";
|
|
import { buildNamedToolChoice } from "@oh-my-pi/pi-coding-agent/utils/tool-choice";
|
|
import { Snowflake } from "@oh-my-pi/pi-utils";
|
|
|
|
describe("AgentSession resolve reminder", () => {
|
|
let session: AgentSession;
|
|
let tempDir: string;
|
|
let mock: MockModel;
|
|
let authStorage: AuthStorage | undefined;
|
|
|
|
beforeEach(async () => {
|
|
tempDir = path.join(os.tmpdir(), `pi-resolve-reminder-test-${Snowflake.next()}`);
|
|
fs.mkdirSync(tempDir, { recursive: true });
|
|
|
|
const model = getBundledModel("anthropic", "claude-sonnet-4-5");
|
|
if (!model) {
|
|
throw new Error("Test model not found in registry");
|
|
}
|
|
|
|
authStorage = await AuthStorage.create(path.join(tempDir, "testauth.db"));
|
|
authStorage.setRuntimeApiKey("anthropic", "test-key");
|
|
const modelRegistry = new ModelRegistry(authStorage, path.join(tempDir, "models.yml"));
|
|
|
|
mock = createMockModel({
|
|
handler: () => {
|
|
if (mock.calls.length === 1) {
|
|
queueResolveHandler(
|
|
{
|
|
getToolChoiceQueue: () => session.toolChoiceQueue,
|
|
buildToolChoice: (name: string) => buildNamedToolChoice(name, session.model!),
|
|
steer: (msg: { customType: string; content: string; details?: unknown }) =>
|
|
session.agent.steer({
|
|
role: "custom",
|
|
customType: msg.customType,
|
|
content: msg.content,
|
|
display: false,
|
|
details: msg.details,
|
|
attribution: "agent",
|
|
timestamp: Date.now(),
|
|
}),
|
|
} as unknown as ToolSession,
|
|
{
|
|
label: "AST Edit: 1 replacement in 1 file",
|
|
sourceToolName: "ast_edit",
|
|
apply: async () => ({ content: [{ type: "text", text: "Applied" }] }),
|
|
},
|
|
);
|
|
}
|
|
return { content: ["Done"] };
|
|
},
|
|
});
|
|
|
|
const agent = new Agent({
|
|
initialState: {
|
|
model,
|
|
systemPrompt: ["Test"],
|
|
tools: [],
|
|
messages: [],
|
|
},
|
|
streamFn: mock.stream,
|
|
});
|
|
|
|
session = new AgentSession({
|
|
agent,
|
|
sessionManager: SessionManager.inMemory(),
|
|
settings: Settings.isolated(),
|
|
modelRegistry,
|
|
});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await session.dispose();
|
|
authStorage?.close();
|
|
authStorage = undefined;
|
|
if (fs.existsSync(tempDir)) {
|
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
}
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("forces an immediate steering turn and injects resolve reminder before second assistant response", async () => {
|
|
await session.prompt("run preview");
|
|
|
|
expect(mock.calls).toHaveLength(2);
|
|
|
|
const messages = session.agent.state.messages;
|
|
const assistantIndices = messages
|
|
.map((message, index) => (message.role === "assistant" ? index : -1))
|
|
.filter(index => index >= 0);
|
|
const reminderIndex = messages.findIndex(
|
|
message => message.role === "custom" && message.customType === "resolve-reminder",
|
|
);
|
|
|
|
expect(assistantIndices.length).toBe(2);
|
|
expect(reminderIndex).toBeGreaterThan(assistantIndices[0]!);
|
|
expect(reminderIndex).toBeLessThan(assistantIndices[1]!);
|
|
});
|
|
});
|