mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix(coding-agent): keep unit model stores in memory
This commit is contained in:
parent
4d68d93551
commit
ce5d98cc00
6 changed files with 25 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ import { discoverAndLoadExtensions } from "../src/core/extensions/loader.ts";
|
|||
import { ExtensionRunner } from "../src/core/extensions/runner.ts";
|
||||
import { SessionManager } from "../src/core/session-manager.ts";
|
||||
|
||||
import { createModelRegistry } from "./model-runtime-test-utils.ts";
|
||||
import { createInMemoryModelRegistry } from "./model-runtime-test-utils.ts";
|
||||
|
||||
describe("Input Event", () => {
|
||||
let tempDir: string;
|
||||
|
|
@ -30,7 +30,7 @@ describe("Input Event", () => {
|
|||
for (let i = 0; i < extensions.length; i++) fs.writeFileSync(path.join(extensionsDir, `e${i}.ts`), extensions[i]);
|
||||
const result = await discoverAndLoadExtensions([], tempDir, tempDir);
|
||||
const sm = SessionManager.inMemory();
|
||||
const mr = await createModelRegistry(AuthStorage.create(path.join(tempDir, "auth.json")));
|
||||
const mr = await createInMemoryModelRegistry(AuthStorage.inMemory());
|
||||
return new ExtensionRunner(result.extensions, result.runtime, tempDir, sm, mr);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createModelRegistry } from "./model-runtime-test-utils.ts";
|
||||
import { createInMemoryModelRegistry } from "./model-runtime-test-utils.ts";
|
||||
/**
|
||||
* Tests for ExtensionRunner - conflict detection, error handling, tool wrapping.
|
||||
*/
|
||||
|
|
@ -33,8 +33,7 @@ describe("ExtensionRunner", () => {
|
|||
extensionsDir = path.join(tempDir, "extensions");
|
||||
fs.mkdirSync(extensionsDir);
|
||||
sessionManager = SessionManager.inMemory();
|
||||
const authStorage = AuthStorage.create(path.join(tempDir, "auth.json"));
|
||||
modelRegistry = await createModelRegistry(authStorage);
|
||||
modelRegistry = await createInMemoryModelRegistry(AuthStorage.inMemory());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ describe("ModelRegistry", () => {
|
|||
tempDir = join(tmpdir(), `pi-test-model-registry-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
||||
mkdirSync(tempDir, { recursive: true });
|
||||
modelsJsonPath = join(tempDir, "models.json");
|
||||
authStorage = AuthStorage.create(join(tempDir, "auth.json"));
|
||||
authStorage = AuthStorage.inMemory();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { CredentialStore } from "@earendil-works/pi-ai";
|
||||
import { ModelRegistry } from "../src/core/model-registry.ts";
|
||||
import { ModelRuntime } from "../src/core/model-runtime.ts";
|
||||
import { InMemoryCodingAgentModelsStore } from "../src/core/models-store.ts";
|
||||
|
||||
const runtimes = new WeakMap<ModelRegistry, ModelRuntime>();
|
||||
|
||||
|
|
@ -10,8 +11,16 @@ function wrap(runtime: ModelRuntime): ModelRegistry {
|
|||
return registry;
|
||||
}
|
||||
|
||||
/** Load optional models.json configuration without introducing file-backed catalog locks into unit tests. */
|
||||
export async function createModelRegistry(credentials: CredentialStore, modelsPath?: string): Promise<ModelRegistry> {
|
||||
return wrap(await ModelRuntime.create({ credentials, modelsPath, allowModelNetwork: false }));
|
||||
return wrap(
|
||||
await ModelRuntime.create({
|
||||
credentials,
|
||||
modelsPath,
|
||||
modelsStore: new InMemoryCodingAgentModelsStore(),
|
||||
allowModelNetwork: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function createInMemoryModelRegistry(credentials: CredentialStore): Promise<ModelRegistry> {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import { createAgentSession } from "../src/core/sdk.ts";
|
|||
import { SessionManager } from "../src/core/session-manager.ts";
|
||||
import { SettingsManager } from "../src/core/settings-manager.ts";
|
||||
|
||||
import { createModelRegistry, getModelRuntime } from "./model-runtime-test-utils.ts";
|
||||
import { createInMemoryModelRegistry, getModelRuntime } from "./model-runtime-test-utils.ts";
|
||||
|
||||
describe("createAgentSession provider attribution headers", () => {
|
||||
let tempDir: string;
|
||||
|
|
@ -96,9 +96,10 @@ describe("createAgentSession provider attribution headers", () => {
|
|||
settingsManager.setEnableInstallTelemetry(false);
|
||||
}
|
||||
|
||||
const authStorage = AuthStorage.create(join(agentDir, "auth.json"));
|
||||
await authStorage.modify(model.provider, async () => ({ type: "api_key", key: "test-api-key" }));
|
||||
const modelRegistry = await createModelRegistry(authStorage, join(agentDir, "models.json"));
|
||||
const authStorage = AuthStorage.inMemory({
|
||||
[model.provider]: { type: "api_key", key: "test-api-key" },
|
||||
});
|
||||
const modelRegistry = await createInMemoryModelRegistry(authStorage);
|
||||
let capturedOptions: SimpleStreamOptions | undefined;
|
||||
|
||||
modelRegistry.registerProvider(model.provider, {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createModelRegistry, getModelRuntime } from "./model-runtime-test-utils.ts";
|
||||
import { createInMemoryModelRegistry, getModelRuntime } from "./model-runtime-test-utils.ts";
|
||||
/**
|
||||
* Test harness for AgentSession runtime testing.
|
||||
*
|
||||
|
|
@ -395,9 +395,10 @@ async function createHarnessWithResourceLoader(
|
|||
settingsManager.applyOverrides(options.settings);
|
||||
}
|
||||
|
||||
const authStorage = AuthStorage.create(join(tempDir, "auth.json"));
|
||||
await authStorage.modify(model.provider, async () => ({ type: "api_key", key: "faux-key" }));
|
||||
const modelRegistry = await createModelRegistry(authStorage, tempDir);
|
||||
const authStorage = AuthStorage.inMemory({
|
||||
[model.provider]: { type: "api_key", key: "faux-key" },
|
||||
});
|
||||
const modelRegistry = await createInMemoryModelRegistry(authStorage);
|
||||
modelRegistry.registerProvider(model.provider, {
|
||||
baseUrl: model.baseUrl,
|
||||
api: model.api,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue