fix(server): pass logger to agent clients in e2e tests

Update remaining e2e test files to pass logger to CodexMcpAgentClient
and OpenCodeAgentClient constructors.
This commit is contained in:
Mohamed Boudra
2026-01-17 13:10:15 +07:00
parent 07ca5222c1
commit a89c96ce0d
3 changed files with 38 additions and 35 deletions
@@ -129,8 +129,9 @@ describe("agent MCP end-to-end", () => {
: undefined; : undefined;
const daemonConfig: PaseoDaemonConfig = { const daemonConfig: PaseoDaemonConfig = {
port, listen: `${port}`,
paseoHome, paseoHome,
corsAllowedOrigins: [],
agentMcpRoute: "/mcp/agents", agentMcpRoute: "/mcp/agents",
agentMcpAllowedHosts: [`127.0.0.1:${port}`, `localhost:${port}`], agentMcpAllowedHosts: [`127.0.0.1:${port}`, `localhost:${port}`],
auth: { auth: {
@@ -170,9 +171,7 @@ describe("agent MCP end-to-end", () => {
process.env.CLAUDE_CONFIG_DIR = claudeConfigDir; process.env.CLAUDE_CONFIG_DIR = claudeConfigDir;
const daemon = await createPaseoDaemon(daemonConfig, pino({ level: "silent" })); const daemon = await createPaseoDaemon(daemonConfig, pino({ level: "silent" }));
await new Promise<void>((resolve) => { await daemon.start();
daemon.httpServer.listen(port, () => resolve());
});
const transport = new StreamableHTTPClientTransport( const transport = new StreamableHTTPClientTransport(
new URL(`http://127.0.0.1:${port}/mcp/agents`), new URL(`http://127.0.0.1:${port}/mcp/agents`),
@@ -283,7 +282,7 @@ describe("agent MCP end-to-end", () => {
await client.callTool({ name: "kill_agent", args: { agentId } }); await client.callTool({ name: "kill_agent", args: { agentId } });
} }
await client.close(); await client.close();
await daemon.close(); await daemon.stop();
if (previousCodexSessionDir === undefined) { if (previousCodexSessionDir === undefined) {
delete process.env.CODEX_SESSION_DIR; delete process.env.CODEX_SESSION_DIR;
} else { } else {
@@ -330,8 +329,9 @@ describe("agent MCP end-to-end", () => {
: undefined; : undefined;
const daemonConfig: PaseoDaemonConfig = { const daemonConfig: PaseoDaemonConfig = {
port, listen: `${port}`,
paseoHome, paseoHome,
corsAllowedOrigins: [],
agentMcpRoute: "/mcp/agents", agentMcpRoute: "/mcp/agents",
agentMcpAllowedHosts: [`127.0.0.1:${port}`, `localhost:${port}`], agentMcpAllowedHosts: [`127.0.0.1:${port}`, `localhost:${port}`],
auth: { auth: {
@@ -384,9 +384,7 @@ describe("agent MCP end-to-end", () => {
process.env.CLAUDE_CONFIG_DIR = claudeConfigDir; process.env.CLAUDE_CONFIG_DIR = claudeConfigDir;
const daemon = await createPaseoDaemon(daemonConfig, pino({ level: "silent" })); const daemon = await createPaseoDaemon(daemonConfig, pino({ level: "silent" }));
await new Promise<void>((resolve) => { await daemon.start();
daemon.httpServer.listen(port, () => resolve());
});
const transport = new StreamableHTTPClientTransport( const transport = new StreamableHTTPClientTransport(
new URL(`http://127.0.0.1:${port}/mcp/agents`), new URL(`http://127.0.0.1:${port}/mcp/agents`),
@@ -479,7 +477,7 @@ describe("agent MCP end-to-end", () => {
await client.callTool({ name: "kill_agent", args: { agentId } }); await client.callTool({ name: "kill_agent", args: { agentId } });
} }
await client.close(); await client.close();
await daemon.close(); await daemon.stop();
if (previousCodexSessionDir === undefined) { if (previousCodexSessionDir === undefined) {
delete process.env.CODEX_SESSION_DIR; delete process.env.CODEX_SESSION_DIR;
} else { } else {
@@ -6,6 +6,7 @@ import os from "node:os";
import path from "node:path"; import path from "node:path";
import { z } from "zod"; import { z } from "zod";
import { createTestLogger } from "../../../test-utils/test-logger.js";
import type { import type {
AgentPermissionRequest, AgentPermissionRequest,
AgentSession, AgentSession,
@@ -401,13 +402,15 @@ function getConversationIdFromMetadata(metadata: unknown): string | undefined {
} }
describe("CodexMcpAgentClient (MCP integration)", () => { describe("CodexMcpAgentClient (MCP integration)", () => {
const logger = createTestLogger();
test( test(
"provider does not emit user_message (agent-manager handles that), emits exactly one assistant_message", "provider does not emit user_message (agent-manager handles that), emits exactly one assistant_message",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -477,7 +480,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -507,7 +510,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -610,7 +613,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const mcpServerScript = writeTestMcpServerScript(cwd); const mcpServerScript = writeTestMcpServerScript(cwd);
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const nodeModulesPath = resolveNodeModulesPath(); const nodeModulesPath = resolveNodeModulesPath();
const config = { const config = {
provider: "codex", provider: "codex",
@@ -758,7 +761,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const mcpServerScript = writeTestMcpServerScript(cwd); const mcpServerScript = writeTestMcpServerScript(cwd);
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const nodeModulesPath = resolveNodeModulesPath(); const nodeModulesPath = resolveNodeModulesPath();
const config = { const config = {
provider: "codex", provider: "codex",
@@ -905,7 +908,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -963,7 +966,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1042,7 +1045,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1080,7 +1083,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1151,7 +1154,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1202,7 +1205,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1268,7 +1271,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1346,7 +1349,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1423,7 +1426,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const restoreSessionDir = useTempCodexSessionDir(); const restoreSessionDir = useTempCodexSessionDir();
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const config = { const config = {
provider: "codex", provider: "codex",
model: CODEX_TEST_MODEL, model: CODEX_TEST_MODEL,
@@ -1511,7 +1514,7 @@ describe("CodexMcpAgentClient (MCP integration)", () => {
"listModels returns models with required fields", "listModels returns models with required fields",
async () => { async () => {
const { CodexMcpAgentClient } = await loadCodexMcpAgentClient(); const { CodexMcpAgentClient } = await loadCodexMcpAgentClient();
const client = new CodexMcpAgentClient(); const client = new CodexMcpAgentClient(logger);
const models = await client.listModels(); const models = await client.listModels();
// HARD ASSERT: Returns an array // HARD ASSERT: Returns an array
@@ -3,6 +3,7 @@ import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import { createTestLogger } from "../../../test-utils/test-logger.js";
import { OpenCodeAgentClient } from "./opencode-agent.js"; import { OpenCodeAgentClient } from "./opencode-agent.js";
import type { import type {
AgentSessionConfig, AgentSessionConfig,
@@ -73,6 +74,7 @@ async function collectTurnEvents(
} }
describe("OpenCodeAgentClient", () => { describe("OpenCodeAgentClient", () => {
const logger = createTestLogger();
const buildConfig = (cwd: string): AgentSessionConfig => ({ const buildConfig = (cwd: string): AgentSessionConfig => ({
provider: "opencode", provider: "opencode",
cwd, cwd,
@@ -83,7 +85,7 @@ describe("OpenCodeAgentClient", () => {
"creates a session with valid id and provider", "creates a session with valid id and provider",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
// HARD ASSERT: Session has required fields // HARD ASSERT: Session has required fields
@@ -101,7 +103,7 @@ describe("OpenCodeAgentClient", () => {
"single turn completes with streaming deltas", "single turn completes with streaming deltas",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const iterator = session.stream("Say hello"); const iterator = session.stream("Say hello");
@@ -133,7 +135,7 @@ describe("OpenCodeAgentClient", () => {
"user prompt text never appears in assistant_message", "user prompt text never appears in assistant_message",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const userMarker = "UNIQUE_USER_MARKER_XYZ789"; const userMarker = "UNIQUE_USER_MARKER_XYZ789";
@@ -161,7 +163,7 @@ describe("OpenCodeAgentClient", () => {
"multi-turn preserves context", "multi-turn preserves context",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const secretCode = "ZEBRA_42"; const secretCode = "ZEBRA_42";
@@ -201,7 +203,7 @@ describe("OpenCodeAgentClient", () => {
const testFile = path.join(cwd, "test-file.txt"); const testFile = path.join(cwd, "test-file.txt");
writeFileSync(testFile, "original content\n"); writeFileSync(testFile, "original content\n");
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const iterator = session.stream(`Read the file at ${testFile}`); const iterator = session.stream(`Read the file at ${testFile}`);
@@ -228,7 +230,7 @@ describe("OpenCodeAgentClient", () => {
"can be interrupted during streaming", "can be interrupted during streaming",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const events: AgentStreamEvent[] = []; const events: AgentStreamEvent[] = [];
@@ -258,7 +260,7 @@ describe("OpenCodeAgentClient", () => {
"run() returns accumulated response text", "run() returns accumulated response text",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const marker = "OPENCODE_ACK_TOKEN"; const marker = "OPENCODE_ACK_TOKEN";
@@ -280,7 +282,7 @@ describe("OpenCodeAgentClient", () => {
"handles permission requests", "handles permission requests",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
const events: AgentStreamEvent[] = []; const events: AgentStreamEvent[] = [];
@@ -320,7 +322,7 @@ describe("OpenCodeAgentClient", () => {
test( test(
"listModels returns models with required fields", "listModels returns models with required fields",
async () => { async () => {
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const models = await client.listModels(); const models = await client.listModels();
// HARD ASSERT: Returns an array // HARD ASSERT: Returns an array
@@ -348,7 +350,7 @@ describe("OpenCodeAgentClient", () => {
"streamHistory returns exact conversation history after multi-turn session", "streamHistory returns exact conversation history after multi-turn session",
async () => { async () => {
const cwd = tmpCwd(); const cwd = tmpCwd();
const client = new OpenCodeAgentClient(); const client = new OpenCodeAgentClient(logger);
const session = await client.createSession(buildConfig(cwd)); const session = await client.createSession(buildConfig(cwd));
// Turn 1: Ask agent to remember a secret // Turn 1: Ask agent to remember a secret