From cfca2d4051dce6b135b00de24e59f313b145f85a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 28 Apr 2026 03:40:48 +0100 Subject: [PATCH] refactor: move remaining agent test contract files --- .../delivery-no-reply-runtime-contract.ts | 0 .../schema-normalization-runtime-contract.ts | 0 .../transcript-repair-runtime-contract.ts | 0 .../agents/auth-profile-runtime-contract.ts | 60 ------------ .../openclaw-owned-tool-runtime-contract.ts | 94 ------------------- .../outcome-fallback-runtime-contract.ts | 48 ---------- .../agents/prompt-overlay-runtime-contract.ts | 48 ---------- test/helpers/sandbox-fixtures.ts | 48 ---------- 8 files changed, 298 deletions(-) rename {test/helpers => src/plugin-sdk/test-helpers}/agents/delivery-no-reply-runtime-contract.ts (100%) rename {test/helpers => src/plugin-sdk/test-helpers}/agents/schema-normalization-runtime-contract.ts (100%) rename {test/helpers => src/plugin-sdk/test-helpers}/agents/transcript-repair-runtime-contract.ts (100%) delete mode 100644 test/helpers/agents/auth-profile-runtime-contract.ts delete mode 100644 test/helpers/agents/openclaw-owned-tool-runtime-contract.ts delete mode 100644 test/helpers/agents/outcome-fallback-runtime-contract.ts delete mode 100644 test/helpers/agents/prompt-overlay-runtime-contract.ts delete mode 100644 test/helpers/sandbox-fixtures.ts diff --git a/test/helpers/agents/delivery-no-reply-runtime-contract.ts b/src/plugin-sdk/test-helpers/agents/delivery-no-reply-runtime-contract.ts similarity index 100% rename from test/helpers/agents/delivery-no-reply-runtime-contract.ts rename to src/plugin-sdk/test-helpers/agents/delivery-no-reply-runtime-contract.ts diff --git a/test/helpers/agents/schema-normalization-runtime-contract.ts b/src/plugin-sdk/test-helpers/agents/schema-normalization-runtime-contract.ts similarity index 100% rename from test/helpers/agents/schema-normalization-runtime-contract.ts rename to src/plugin-sdk/test-helpers/agents/schema-normalization-runtime-contract.ts diff --git a/test/helpers/agents/transcript-repair-runtime-contract.ts b/src/plugin-sdk/test-helpers/agents/transcript-repair-runtime-contract.ts similarity index 100% rename from test/helpers/agents/transcript-repair-runtime-contract.ts rename to src/plugin-sdk/test-helpers/agents/transcript-repair-runtime-contract.ts diff --git a/test/helpers/agents/auth-profile-runtime-contract.ts b/test/helpers/agents/auth-profile-runtime-contract.ts deleted file mode 100644 index c51a2457393..00000000000 --- a/test/helpers/agents/auth-profile-runtime-contract.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { - resolveProviderIdForAuth, - type ProviderAuthAliasLookupParams, -} from "../../../src/agents/provider-auth-aliases.js"; -import type { PluginManifestRegistry } from "../../../src/plugins/manifest-registry.js"; - -export const AUTH_PROFILE_RUNTIME_CONTRACT = { - sessionId: "session-auth-contract", - sessionKey: "agent:main:auth-contract", - runId: "run-auth-contract", - workspacePrompt: "continue with the bound Codex profile", - openAiProvider: "openai", - openAiCodexProvider: "openai-codex", - codexCliProvider: "codex-cli", - codexHarnessProvider: "codex", - claudeCliProvider: "claude-cli", - openAiProfileId: "openai:work", - openAiCodexProfileId: "openai-codex:work", - anthropicProfileId: "anthropic:work", -} as const; - -export function createAuthAliasManifestRegistry(): PluginManifestRegistry { - return { - plugins: [ - { - id: "openai", - origin: "bundled", - channels: [], - providers: [], - cliBackends: [], - skills: [], - hooks: [], - rootDir: "/tmp/openclaw-auth-contract-plugin", - source: "test", - manifestPath: "/tmp/openclaw-auth-contract-plugin/plugin.json", - providerAuthChoices: [ - { - provider: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProvider, - method: "oauth", - choiceId: AUTH_PROFILE_RUNTIME_CONTRACT.openAiCodexProvider, - deprecatedChoiceIds: [AUTH_PROFILE_RUNTIME_CONTRACT.codexCliProvider], - }, - ], - }, - ], - diagnostics: [], - }; -} - -export function expectedForwardedAuthProfile(params: { - provider: string; - authProfileProvider: string; - aliasLookupParams: ProviderAuthAliasLookupParams; - sessionAuthProfileId: string | undefined; -}): string | undefined { - return resolveProviderIdForAuth(params.provider, params.aliasLookupParams) === - resolveProviderIdForAuth(params.authProfileProvider, params.aliasLookupParams) - ? params.sessionAuthProfileId - : undefined; -} diff --git a/test/helpers/agents/openclaw-owned-tool-runtime-contract.ts b/test/helpers/agents/openclaw-owned-tool-runtime-contract.ts deleted file mode 100644 index a3aee98491a..00000000000 --- a/test/helpers/agents/openclaw-owned-tool-runtime-contract.ts +++ /dev/null @@ -1,94 +0,0 @@ -import type { AgentToolResult } from "@mariozechner/pi-agent-core"; -import { vi } from "vitest"; -import { __testing as beforeToolCallTesting } from "../../../src/agents/pi-tools.before-tool-call.js"; -import type { - CodexAppServerExtensionFactory, - CodexAppServerToolResultEvent, -} from "../../../src/plugins/codex-app-server-extension-types.js"; -import { - initializeGlobalHookRunner, - resetGlobalHookRunner, -} from "../../../src/plugins/hook-runner-global.js"; -import { createMockPluginRegistry } from "../../../src/plugins/hooks.test-helpers.js"; -import { createEmptyPluginRegistry } from "../../../src/plugins/registry-empty.js"; -import { - resetPluginRuntimeStateForTest, - setActivePluginRegistry, -} from "../../../src/plugins/runtime.js"; - -export function textToolResult( - text: string, - details: Record = {}, -): AgentToolResult { - return { - content: [{ type: "text", text }], - details, - }; -} - -export function mediaToolResult( - text: string, - mediaUrl: string, - audioAsVoice = false, -): AgentToolResult { - return textToolResult(text, { - media: { - mediaUrl, - ...(audioAsVoice ? { audioAsVoice } : {}), - }, - }); -} - -export function installOpenClawOwnedToolHooks(params?: { - adjustedParams?: Record; - blockReason?: string; -}) { - const beforeToolCall = vi.fn(async () => { - if (params?.blockReason) { - return { - block: true, - blockReason: params.blockReason, - }; - } - return params?.adjustedParams ? { params: params.adjustedParams } : {}; - }); - const afterToolCall = vi.fn(async () => {}); - initializeGlobalHookRunner( - createMockPluginRegistry([ - { hookName: "before_tool_call", handler: beforeToolCall }, - { hookName: "after_tool_call", handler: afterToolCall }, - ]), - ); - return { beforeToolCall, afterToolCall }; -} - -/** - * Installs only the Codex app-server `tool_result` middleware fixture. - * Pair with `installOpenClawOwnedToolHooks()` when a test asserts before/after hook behavior. - */ -export function installCodexToolResultMiddleware( - handler: (event: CodexAppServerToolResultEvent) => AgentToolResult, -) { - const middleware = vi.fn(async (event: CodexAppServerToolResultEvent) => ({ - result: handler(event), - })); - const registry = createEmptyPluginRegistry(); - const factory: CodexAppServerExtensionFactory = async (codex) => { - codex.on("tool_result", middleware); - }; - registry.codexAppServerExtensionFactories.push({ - pluginId: "runtime-contract", - pluginName: "Runtime Contract", - rawFactory: factory, - factory, - source: "test", - }); - setActivePluginRegistry(registry); - return { middleware }; -} - -export function resetOpenClawOwnedToolHooks(): void { - resetGlobalHookRunner(); - resetPluginRuntimeStateForTest(); - beforeToolCallTesting.adjustedParamsByToolCallId.clear(); -} diff --git a/test/helpers/agents/outcome-fallback-runtime-contract.ts b/test/helpers/agents/outcome-fallback-runtime-contract.ts deleted file mode 100644 index 81ad1f8c303..00000000000 --- a/test/helpers/agents/outcome-fallback-runtime-contract.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { EmbeddedPiRunResult } from "../../../src/agents/pi-embedded-runner/types.js"; - -export const OUTCOME_FALLBACK_RUNTIME_CONTRACT = { - primaryProvider: "openai-codex", - primaryModel: "gpt-5.4", - fallbackProvider: "anthropic", - fallbackModel: "claude-haiku-3-5", - sessionId: "session-outcome-contract", - sessionKey: "agent:main:outcome-contract", - runId: "run-outcome-contract", - prompt: "finish the contract turn", - reasoningOnlyText: "I need to reason about this before answering.", - planningOnlyText: "Inspect state, then decide the next step.", -} as const; - -export function createContractRunResult( - overrides: Partial = {}, -): EmbeddedPiRunResult { - const { meta, ...rest } = overrides; - return { - payloads: [], - didSendViaMessagingTool: false, - messagingToolSentTexts: [], - messagingToolSentMediaUrls: [], - messagingToolSentTargets: [], - successfulCronAdds: 0, - ...rest, - meta: { - durationMs: 1, - ...meta, - }, - }; -} - -export function createContractFallbackConfig() { - return { - agents: { - defaults: { - model: { - primary: `${OUTCOME_FALLBACK_RUNTIME_CONTRACT.primaryProvider}/${OUTCOME_FALLBACK_RUNTIME_CONTRACT.primaryModel}`, - fallbacks: [ - `${OUTCOME_FALLBACK_RUNTIME_CONTRACT.fallbackProvider}/${OUTCOME_FALLBACK_RUNTIME_CONTRACT.fallbackModel}`, - ], - }, - }, - }, - } as const; -} diff --git a/test/helpers/agents/prompt-overlay-runtime-contract.ts b/test/helpers/agents/prompt-overlay-runtime-contract.ts deleted file mode 100644 index 5ff5fc610a5..00000000000 --- a/test/helpers/agents/prompt-overlay-runtime-contract.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { OpenClawConfig } from "../../../src/config/types.openclaw.js"; -import type { ProviderSystemPromptContributionContext } from "../../../src/plugins/types.js"; - -export const GPT5_CONTRACT_MODEL_ID = "gpt-5.4"; -export const GPT5_PREFIXED_CONTRACT_MODEL_ID = "openai/gpt-5.4"; -export const NON_GPT5_CONTRACT_MODEL_ID = "gpt-4.1"; -export const OPENAI_CONTRACT_PROVIDER_ID = "openai"; -export const OPENAI_CODEX_CONTRACT_PROVIDER_ID = "openai-codex"; -export const CODEX_CONTRACT_PROVIDER_ID = "codex"; -export const NON_OPENAI_CONTRACT_PROVIDER_ID = "openrouter"; - -export function openAiPluginPersonalityConfig(personality: "friendly" | "off"): OpenClawConfig { - return { - plugins: { - entries: { - openai: { - config: { personality }, - }, - }, - }, - } satisfies OpenClawConfig; -} - -export function sharedGpt5PersonalityConfig(personality: "friendly" | "off"): OpenClawConfig { - return { - agents: { - defaults: { - promptOverlays: { - gpt5: { personality }, - }, - }, - }, - } satisfies OpenClawConfig; -} - -export function codexPromptOverlayContext(params?: { - modelId?: string; - config?: OpenClawConfig; -}): ProviderSystemPromptContributionContext { - return { - provider: CODEX_CONTRACT_PROVIDER_ID, - modelId: params?.modelId ?? GPT5_CONTRACT_MODEL_ID, - promptMode: "full", - agentDir: "/tmp/openclaw-codex-prompt-contract-agent", - workspaceDir: "/tmp/openclaw-codex-prompt-contract-workspace", - ...(params?.config ? { config: params.config } : {}), - }; -} diff --git a/test/helpers/sandbox-fixtures.ts b/test/helpers/sandbox-fixtures.ts deleted file mode 100644 index 782bd6cbf67..00000000000 --- a/test/helpers/sandbox-fixtures.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { - SandboxBrowserConfig, - SandboxPruneConfig, - SandboxSshConfig, -} from "../../src/agents/sandbox/types.js"; - -export function createSandboxBrowserConfig( - overrides: Partial = {}, -): SandboxBrowserConfig { - return { - enabled: false, - image: "openclaw-browser", - containerPrefix: "openclaw-browser-", - network: "bridge", - cdpPort: 9222, - vncPort: 5900, - noVncPort: 6080, - headless: true, - enableNoVnc: false, - allowHostControl: false, - autoStart: false, - autoStartTimeoutMs: 1000, - ...overrides, - }; -} - -export function createSandboxPruneConfig( - overrides: Partial = {}, -): SandboxPruneConfig { - return { - idleHours: 24, - maxAgeDays: 7, - ...overrides, - }; -} - -export function createSandboxSshConfig( - workspaceRoot: string, - overrides: Partial = {}, -): SandboxSshConfig { - return { - command: "ssh", - workspaceRoot, - strictHostKeyChecking: true, - updateHostKeys: true, - ...overrides, - }; -}