Files
oh-my-pi/packages/coding-agent/test/helpers/agent-session-setup.ts
T
can1357 b279db1790 test: refactored test suites to eliminate time-based sleeps and polling loops
- Replaced time-based sleeps and polling loops with event-driven promise resolvers and fake timers across agent and tool tests.
- Migrated test suites to share in-memory auth storage and fixtures using lifecycle hooks.
- Updated catalog model definitions, metadata, and configurations.
2026-08-13 19:32:22 +02:00

37 lines
1.1 KiB
TypeScript

import { Database } from "bun:sqlite";
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
import { AuthStorage, SqliteAuthCredentialStore } from "@oh-my-pi/pi-coding-agent/session/auth-storage";
/**
* Shared factory for building a minimal mock `AssistantMessage`
* used by AgentSession test suites.
*/
export function createAssistantMessage(text: string): AssistantMessage {
return {
role: "assistant",
content: [{ type: "text", text }],
api: "anthropic-messages",
provider: "anthropic",
model: "mock",
usage: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
totalTokens: 0,
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
},
stopReason: "stop",
timestamp: Date.now(),
};
}
/**
* Build isolated auth state without opening a filesystem-backed SQLite database.
* AgentSession unit tests that only need a runtime API key should not pay for
* database creation, journaling, and deletion on every case.
*/
export function createInMemoryAuthStorage(): AuthStorage {
return new AuthStorage(new SqliteAuthCredentialStore(new Database(":memory:")));
}