mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-06 08:24:46 +00:00
test(omp): verify live session usage references
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { setImmediate as waitForImmediate } from "node:timers/promises";
|
||||
import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import type { AgentStreamEvent } from "../../agent-sdk-types.js";
|
||||
import type { PaseoToolCatalog } from "../../tools/types.js";
|
||||
@@ -144,6 +148,79 @@ function createToolCatalog(): PaseoToolCatalog {
|
||||
}
|
||||
|
||||
describe("OMP agent client and session", () => {
|
||||
test("usage reference reads current get_state provider and account on each call", async () => {
|
||||
const home = mkdtempSync(join(tmpdir(), "paseo-omp-reference-"));
|
||||
const agentDir = join(home, "agent");
|
||||
mkdirSync(agentDir);
|
||||
// Upstream: packages/ai/src/auth/sqlite-credential-store.ts:576-581,711-724.
|
||||
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite") as {
|
||||
DatabaseSync: new (path: string) => {
|
||||
exec(sql: string): void;
|
||||
prepare(sql: string): { run(...args: unknown[]): void };
|
||||
close(): void;
|
||||
};
|
||||
};
|
||||
const db = new DatabaseSync(join(agentDir, "agent.db"));
|
||||
db.exec(`
|
||||
CREATE TABLE cache (key TEXT PRIMARY KEY, value TEXT NOT NULL, expires_at INTEGER NOT NULL);
|
||||
CREATE INDEX idx_cache_expires ON cache(expires_at);
|
||||
CREATE TABLE auth_credentials (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
provider TEXT NOT NULL,
|
||||
credential_type TEXT NOT NULL,
|
||||
data TEXT NOT NULL,
|
||||
disabled_cause TEXT DEFAULT NULL,
|
||||
identity_key TEXT DEFAULT NULL,
|
||||
created_at INTEGER NOT NULL DEFAULT (CAST(strftime('%s','now') AS INTEGER)),
|
||||
updated_at INTEGER NOT NULL DEFAULT (CAST(strftime('%s','now') AS INTEGER))
|
||||
);
|
||||
`);
|
||||
const insert = db.prepare(
|
||||
"INSERT INTO auth_credentials (provider, credential_type, data) VALUES (?, 'oauth', ?)",
|
||||
);
|
||||
insert.run(
|
||||
"openai-codex",
|
||||
JSON.stringify({
|
||||
access: "codex-fixture",
|
||||
accountId: "codex-account",
|
||||
expires: Date.now() + 60_000,
|
||||
}),
|
||||
);
|
||||
insert.run(
|
||||
"anthropic",
|
||||
JSON.stringify({
|
||||
access: "claude-fixture",
|
||||
accountId: "claude-account",
|
||||
expires: Date.now() + 60_000,
|
||||
}),
|
||||
);
|
||||
db.close();
|
||||
try {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start({}, undefined, {
|
||||
OMP_PROFILE: "",
|
||||
PI_CODING_AGENT_DIR: agentDir,
|
||||
XDG_DATA_HOME: "",
|
||||
});
|
||||
const runtime = omp.runtime();
|
||||
runtime.state = { ...runtime.state, model: { provider: "openai-codex", id: "codex-model" } };
|
||||
const requestsBefore = runtime.getStateRequestCount;
|
||||
expect(await omp.getUsageReference()).toEqual({
|
||||
source: "codex",
|
||||
input: { accessToken: "codex-fixture", accountId: "codex-account" },
|
||||
});
|
||||
expect(runtime.getStateRequestCount).toBe(requestsBefore + 1);
|
||||
runtime.state = { ...runtime.state, model: { provider: "anthropic", id: "claude-model" } };
|
||||
expect(await omp.getUsageReference()).toEqual({
|
||||
source: "claude",
|
||||
input: { accessToken: "claude-fixture" },
|
||||
});
|
||||
expect(runtime.getStateRequestCount).toBe(requestsBefore + 2);
|
||||
await omp.close();
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
test("owns launch configuration and registers native host tools", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start({ modeId: "ask" }, createToolCatalog());
|
||||
|
||||
@@ -93,10 +93,11 @@ export class OmpHarness {
|
||||
async start(
|
||||
config: Partial<AgentSessionConfig> = {},
|
||||
paseoTools?: PaseoToolCatalog,
|
||||
env?: Record<string, string>,
|
||||
): Promise<void> {
|
||||
const session = await this.client.createSession(
|
||||
{ provider: "omp", cwd: CWD, ...config },
|
||||
paseoTools ? { paseoTools } : undefined,
|
||||
paseoTools || env ? { paseoTools, env } : undefined,
|
||||
);
|
||||
if (!(session instanceof OmpAgentSession)) {
|
||||
throw new Error("OMP client returned a non-OMP session");
|
||||
@@ -482,6 +483,10 @@ export class OmpHarness {
|
||||
return this.omp.latestSession();
|
||||
}
|
||||
|
||||
async getUsageReference() {
|
||||
return this.requireSession().getUsageReference();
|
||||
}
|
||||
|
||||
runningToolCallIds(): string[] {
|
||||
const statusByCall = new Map<string, string>();
|
||||
for (const item of this.timeline()) {
|
||||
|
||||
Reference in New Issue
Block a user