From d627537d881cd3970865c095ebc1e869ad1d2196 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Fri, 24 Apr 2026 05:27:34 +0700 Subject: [PATCH] chore(lint): no-explicit-any in codex-app-server-agent.test --- .../providers/codex-app-server-agent.test.ts | 89 +++++++++++++------ 1 file changed, 61 insertions(+), 28 deletions(-) diff --git a/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts b/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts index 66ac169c6..b35cb3d47 100644 --- a/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts +++ b/packages/server/src/server/agent/providers/codex-app-server-agent.test.ts @@ -19,6 +19,35 @@ import { } from "./codex-app-server-agent.js"; import { createTestLogger } from "../../../test-utils/test-logger.js"; +interface CollaborationModeRecord { + name: string; + mode?: string | null; + model?: string | null; + reasoning_effort?: string | null; + developer_instructions?: string | null; +} + +interface CodexSessionTestAccess { + handleToolApprovalRequest(params: unknown): Promise; + handleNotification(method: string, params: unknown): void; + refreshResolvedCollaborationMode(): void; + serviceTier: "fast" | null; + planModeEnabled: boolean; + collaborationModes: CollaborationModeRecord[]; + config: AgentSessionConfig; +} + +interface CodexClientLike { + request: (method: string, ...rest: unknown[]) => Promise; +} + +type CodexTestSession = AgentSession & { + connected: boolean; + currentThreadId: string | null; + activeForegroundTurnId: string | null; + client: CodexClientLike | null; +}; + const ONE_BY_ONE_PNG_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+X1r0AAAAASUVORK5CYII="; const CODEX_PROVIDER = "codex"; @@ -33,7 +62,7 @@ function createConfig(overrides: Partial = {}): AgentSession }; } -function createSession(configOverrides: Partial = {}) { +function createSession(configOverrides: Partial = {}): CodexTestSession { const session = new __codexAppServerInternals.CodexAppServerAgentSession( createConfig(configOverrides), null, @@ -41,13 +70,17 @@ function createSession(configOverrides: Partial = {}) { () => { throw new Error("Test session cannot spawn Codex app-server"); }, - ) as unknown as AgentSession & { [key: string]: unknown }; + ) as unknown as CodexTestSession; session.connected = true; session.currentThreadId = "test-thread"; session.activeForegroundTurnId = "test-turn"; return session; } +function asInternals(session: CodexTestSession): CodexSessionTestAccess { + return session as unknown as CodexSessionTestAccess; +} + describe("Codex app-server provider", () => { test("disposes an unresponsive app-server child with SIGKILL", async () => { vi.useFakeTimers(); @@ -255,7 +288,7 @@ describe("Codex app-server provider", () => { }); session.activeForegroundTurnId = null; - session.client = { request } as any; + session.client = { request } as unknown as CodexClientLike; await session.startTurn("Return JSON", { outputSchema: { @@ -436,7 +469,7 @@ describe("Codex app-server provider", () => { const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - void (session as any).handleToolApprovalRequest({ + void asInternals(session).handleToolApprovalRequest({ itemId: "call-question-1", threadId: "thread-1", turnId: "turn-1", @@ -526,7 +559,7 @@ describe("Codex app-server provider", () => { const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - const pendingResponse = (session as any).handleToolApprovalRequest({ + const pendingResponse = asInternals(session).handleToolApprovalRequest({ itemId: "call-question-2", threadId: "thread-1", turnId: "turn-1", @@ -607,16 +640,16 @@ describe("Codex app-server provider", () => { const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - (session as any).handleNotification("turn/started", { + asInternals(session).handleNotification("turn/started", { turn: { id: "turn-plan-1" }, }); - (session as any).handleNotification("turn/plan/updated", { + asInternals(session).handleNotification("turn/plan/updated", { plan: [ { step: "Inspect the existing auth flow", status: "completed" }, { step: "Implement the button behavior", status: "pending" }, ], }); - (session as any).handleNotification("turn/completed", { + asInternals(session).handleNotification("turn/completed", { turn: { status: "completed", error: null }, }); @@ -659,7 +692,7 @@ describe("Codex app-server provider", () => { const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - (session as any).handleNotification("thread/tokenUsage/updated", { + asInternals(session).handleNotification("thread/tokenUsage/updated", { tokenUsage: { model_context_window: 200000, last: { @@ -670,7 +703,7 @@ describe("Codex app-server provider", () => { }, }, }); - (session as any).handleNotification("turn/completed", { + asInternals(session).handleNotification("turn/completed", { turn: { status: "completed", error: null }, }); @@ -707,13 +740,13 @@ describe("Codex app-server provider", () => { const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - (session as any).handleNotification("turn/started", { + asInternals(session).handleNotification("turn/started", { turn: { id: "turn-plan-2" }, }); - (session as any).handleNotification("turn/plan/updated", { + asInternals(session).handleNotification("turn/plan/updated", { plan: [{ step: "Implement the new flow", status: "pending" }], }); - (session as any).handleNotification("turn/completed", { + asInternals(session).handleNotification("turn/completed", { turn: { status: "completed", error: null }, }); @@ -731,9 +764,9 @@ describe("Codex app-server provider", () => { selectedActionId: "implement", }); - expect((session as any).serviceTier).toBe("fast"); - expect((session as any).planModeEnabled).toBe(false); - expect((session as any).config.featureValues).toEqual({ + expect(asInternals(session).serviceTier).toBe("fast"); + expect(asInternals(session).planModeEnabled).toBe(false); + expect(asInternals(session).config.featureValues).toEqual({ plan_mode: false, fast_mode: true, }); @@ -761,13 +794,13 @@ describe("Codex app-server provider", () => { const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - (session as any).handleNotification("turn/started", { + asInternals(session).handleNotification("turn/started", { turn: { id: "turn-plan-3" }, }); - (session as any).handleNotification("turn/plan/updated", { + asInternals(session).handleNotification("turn/plan/updated", { plan: [{ step: "Implement the safe flow", status: "pending" }], }); - (session as any).handleNotification("turn/completed", { + asInternals(session).handleNotification("turn/completed", { turn: { status: "completed", error: null }, }); @@ -785,9 +818,9 @@ describe("Codex app-server provider", () => { selectedActionId: "implement", }); - expect((session as any).serviceTier).toBeNull(); - expect((session as any).planModeEnabled).toBe(false); - expect((session as any).config.featureValues).toEqual({ + expect(asInternals(session).serviceTier).toBeNull(); + expect(asInternals(session).planModeEnabled).toBe(false); + expect(asInternals(session).config.featureValues).toEqual({ plan_mode: false, fast_mode: false, }); @@ -800,7 +833,7 @@ describe("Codex app-server provider", () => { const session = createSession({ featureValues: { plan_mode: true, fast_mode: true }, }); - (session as any).collaborationModes = [ + asInternals(session).collaborationModes = [ { name: "Code", mode: "code", @@ -812,7 +845,7 @@ describe("Codex app-server provider", () => { developer_instructions: "Built-in plan mode", }, ]; - (session as any).refreshResolvedCollaborationMode(); + asInternals(session).refreshResolvedCollaborationMode(); const request = vi.fn(async (method: string) => { if (method === "thread/loaded/list") { return { data: ["test-thread"] }; @@ -824,18 +857,18 @@ describe("Codex app-server provider", () => { }); session.activeForegroundTurnId = null; - session.client = { request } as any; + session.client = { request } as unknown as CodexClientLike; const events: AgentStreamEvent[] = []; session.subscribe((event) => events.push(event)); - (session as any).handleNotification("turn/started", { + asInternals(session).handleNotification("turn/started", { turn: { id: "turn-plan-4" }, }); - (session as any).handleNotification("turn/plan/updated", { + asInternals(session).handleNotification("turn/plan/updated", { plan: [{ step: "Implement the fast flow", status: "pending" }], }); - (session as any).handleNotification("turn/completed", { + asInternals(session).handleNotification("turn/completed", { turn: { status: "completed", error: null }, });