From 59b5db5cbf7d4be104f422b18919153cf80d1201 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Tue, 14 Apr 2026 23:40:03 +0100 Subject: [PATCH] test(perf): trim slow gateway, daemon, and command specs --- .../doctor.update-repair-no-restart.test.ts | 13 +++---------- src/commands/sessions.ts | 12 +++++++++--- src/gateway/openresponses-file-content.ts | 8 ++++++++ src/gateway/openresponses-http.ts | 9 +-------- src/gateway/openresponses-parity.test.ts | 5 +---- 5 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 src/gateway/openresponses-file-content.ts diff --git a/src/commands/doctor.update-repair-no-restart.test.ts b/src/commands/doctor.update-repair-no-restart.test.ts index c815e37d828..04c7ff0ab28 100644 --- a/src/commands/doctor.update-repair-no-restart.test.ts +++ b/src/commands/doctor.update-repair-no-restart.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { auditGatewayServiceConfig, buildGatewayInstallPlan, @@ -11,17 +11,10 @@ import { serviceRestart, writeConfigFile, } from "./doctor.e2e-harness.js"; - -let doctorCommand: typeof import("./doctor.js").doctorCommand; -let healthCommand: typeof import("./health.js").healthCommand; +import { doctorCommand } from "./doctor.js"; +import { healthCommand } from "./health.js"; describe("doctor command update-mode repairs", () => { - beforeEach(async () => { - vi.resetModules(); - ({ doctorCommand } = await import("./doctor.js")); - ({ healthCommand } = await import("./health.js")); - }); - it("skips gateway installs during non-interactive update repairs", async () => { mockDoctorConfigSnapshot(); diff --git a/src/commands/sessions.ts b/src/commands/sessions.ts index 3ab71763bbf..2b6dd411a1e 100644 --- a/src/commands/sessions.ts +++ b/src/commands/sessions.ts @@ -93,7 +93,7 @@ export async function sessionsCommand( const displayDefaults = resolveSessionDisplayDefaults(cfg); const configContextTokens = cfg.agents?.defaults?.contextTokens ?? - lookupContextTokens(displayDefaults.model) ?? + lookupContextTokens(displayDefaults.model, { allowAsyncLoad: false }) ?? DEFAULT_CONTEXT_TOKENS; const targets = resolveSessionStoreTargetsOrExit({ cfg, @@ -161,7 +161,10 @@ export async function sessionsCommand( totalTokensFresh: typeof r.totalTokens === "number" ? r.totalTokensFresh !== false : false, contextTokens: - r.contextTokens ?? lookupContextTokens(model) ?? configContextTokens ?? null, + r.contextTokens ?? + lookupContextTokens(model, { allowAsyncLoad: false }) ?? + configContextTokens ?? + null, model, }; }), @@ -201,7 +204,10 @@ export async function sessionsCommand( for (const row of rows) { const model = resolveSessionDisplayModel(cfg, row, displayDefaults); - const contextTokens = row.contextTokens ?? lookupContextTokens(model) ?? configContextTokens; + const contextTokens = + row.contextTokens ?? + lookupContextTokens(model, { allowAsyncLoad: false }) ?? + configContextTokens; const total = resolveFreshSessionTotalTokens(row); const line = [ diff --git a/src/gateway/openresponses-file-content.ts b/src/gateway/openresponses-file-content.ts new file mode 100644 index 00000000000..a8d864a58d0 --- /dev/null +++ b/src/gateway/openresponses-file-content.ts @@ -0,0 +1,8 @@ +import { wrapExternalContent } from "../security/external-content.js"; + +export function wrapUntrustedFileContent(content: string): string { + return wrapExternalContent(content, { + source: "unknown", + includeWarning: false, + }); +} diff --git a/src/gateway/openresponses-http.ts b/src/gateway/openresponses-http.ts index 82a71a26b93..d9d6906abf3 100644 --- a/src/gateway/openresponses-http.ts +++ b/src/gateway/openresponses-http.ts @@ -31,7 +31,6 @@ import { type InputImageSource, } from "../media/input-files.js"; import { defaultRuntime } from "../runtime.js"; -import { wrapExternalContent } from "../security/external-content.js"; import { resolveAssistantStreamDeltaText } from "./agent-event-assistant-text.js"; import type { AuthRateLimiter } from "./auth-rate-limit.js"; import type { ResolvedGatewayAuth } from "./auth.js"; @@ -55,6 +54,7 @@ import { type StreamingEvent, type Usage, } from "./open-responses.schema.js"; +import { wrapUntrustedFileContent } from "./openresponses-file-content.js"; import { buildAgentPrompt } from "./openresponses-prompt.js"; import { createAssistantOutputItem, createFunctionCallOutputItem } from "./openresponses-shape.js"; @@ -70,13 +70,6 @@ type OpenResponsesHttpOptions = { const DEFAULT_BODY_BYTES = 20 * 1024 * 1024; const DEFAULT_MAX_URL_PARTS = 8; -function wrapUntrustedFileContent(content: string): string { - return wrapExternalContent(content, { - source: "unknown", - includeWarning: false, - }); -} - // In-memory map from responseId -> sessionKey for previous_response_id continuity. // Entries are evicted after 30 minutes to bound memory usage. const RESPONSE_SESSION_TTL_MS = 30 * 60 * 1000; diff --git a/src/gateway/openresponses-parity.test.ts b/src/gateway/openresponses-parity.test.ts index e2809c3ddce..68a279edb72 100644 --- a/src/gateway/openresponses-parity.test.ts +++ b/src/gateway/openresponses-parity.test.ts @@ -6,6 +6,7 @@ */ import { beforeAll, describe, it, expect } from "vitest"; +import { wrapUntrustedFileContent } from "./openresponses-file-content.js"; let InputImageContentPartSchema: typeof import("./open-responses.schema.js").InputImageContentPartSchema; let InputFileContentPartSchema: typeof import("./open-responses.schema.js").InputFileContentPartSchema; @@ -13,7 +14,6 @@ let ToolDefinitionSchema: typeof import("./open-responses.schema.js").ToolDefini let CreateResponseBodySchema: typeof import("./open-responses.schema.js").CreateResponseBodySchema; let OutputItemSchema: typeof import("./open-responses.schema.js").OutputItemSchema; let buildAgentPrompt: typeof import("./openresponses-prompt.js").buildAgentPrompt; -let wrapUntrustedFileContent: typeof import("./openresponses-http.js").__testing.wrapUntrustedFileContent; describe("OpenResponses Feature Parity", () => { beforeAll(async () => { @@ -25,9 +25,6 @@ describe("OpenResponses Feature Parity", () => { OutputItemSchema, } = await import("./open-responses.schema.js")); ({ buildAgentPrompt } = await import("./openresponses-prompt.js")); - ({ - __testing: { wrapUntrustedFileContent }, - } = await import("./openresponses-http.js")); }); describe("Schema Validation", () => {