Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(codex): prove direct-first guidance across catalog changes

Alfredo Lopez90fd50bc56ae
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index 89acc163a..f0f668785 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -585,6 +585,8 @@ jobs:
run: bash scripts/tests/test-minikube-makefile.sh
- name: Test local Minikube T0/T1/T2 contract
+ # Includes test-minikube-docker-cli-env.sh: the real image-manifest
+ # writer's hermetic sequential-build and derived-base provenance checks.
run: bash scripts/tests/test-minikube-t2-contract.sh
- name: Test local Minikube T2 setup handoff
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index f1f03d41c..8afefb69d 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.328",
+ "version": "0.1.329",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.328",
+ "version": "0.1.329",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 5798accc1..e8e13a6e2 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.328",
+ "version": "0.1.329",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/config.codexToolPresentation.test.ts b/mcp-host/src/config.codexToolPresentation.test.ts
index 5fac89362..b9e0f67a8 100644
--- a/mcp-host/src/config.codexToolPresentation.test.ts
+++ b/mcp-host/src/config.codexToolPresentation.test.ts
@@ -2,11 +2,13 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
const originalEnv = process.env
-async function loadConfig(value: string | undefined) {
+async function loadConfig(value: string | undefined, discoveryBytes?: string) {
vi.resetModules()
process.env = { ...originalEnv }
if (value === undefined) delete process.env.CODEX_TOOL_PRESENTATION
else process.env.CODEX_TOOL_PRESENTATION = value
+ if (discoveryBytes === undefined) delete process.env.CODEX_TOOL_DISCOVERY_BYTES
+ else process.env.CODEX_TOOL_DISCOVERY_BYTES = discoveryBytes
return (await import('./config')).config
}
@@ -15,6 +17,28 @@ afterEach(() => {
vi.resetModules()
})
+describe('CODEX_TOOL_DISCOVERY_BYTES import-time configuration', () => {
+ it('defaults to 32768 bytes when unset', async () => {
+ expect((await loadConfig(undefined)).codexToolDiscoveryBytes).toBe(32_768)
+ })
+
+ it.each(['1', '32768', String(Number.MAX_SAFE_INTEGER)])(
+ 'loads the positive safe integer %s',
+ async value => {
+ expect((await loadConfig(undefined, value)).codexToolDiscoveryBytes).toBe(Number(value))
+ }
+ )
+
+ it.each(['', '0', '-1', '1.5', '01', '+1', ' 1', '1 ', '1e3', '3bytes', '9007199254740992'])(
+ 'refuses to import configuration with invalid byte limit %j',
+ async value => {
+ await expect(loadConfig(undefined, value)).rejects.toThrow(
+ 'CODEX_TOOL_DISCOVERY_BYTES must be a positive safe integer'
+ )
+ }
+ )
+})
+
describe('CODEX_TOOL_PRESENTATION import-time configuration', () => {
it('defaults to auto when unset', async () => {
expect((await loadConfig(undefined)).codexToolPresentation).toBe('auto')
diff --git a/mcp-host/src/core/orchestration/__tests__/approvedToolsLifecycle.integration.test.ts b/mcp-host/src/core/orchestration/__tests__/approvedToolsLifecycle.integration.test.ts
index a8983fb9f..65168fdc5 100644
--- a/mcp-host/src/core/orchestration/__tests__/approvedToolsLifecycle.integration.test.ts
+++ b/mcp-host/src/core/orchestration/__tests__/approvedToolsLifecycle.integration.test.ts
@@ -13,6 +13,7 @@ import { ApprovalController } from '../../extensions/approvalController'
import { InLoopContextManager, PressureContextManager } from '../../extensions/contextManager'
import { UnifiedApprovalGateController } from '../../extensions/mcpApprovalGateController'
import type { Tool } from '../../interfaces'
+import { DefaultPromptBuilder, TOOL_DISCOVERY_TEXT } from '../../reasoning/promptBuilder'
import { BasicSafety } from '../../safety/safety'
import { NativeToolRegistry } from '../../tools/nativeToolRegistry'
import { type ChatMessage, ConversationState, type ToolCall } from '../../types'
@@ -155,6 +156,68 @@ const bridgeCall = (name: string, id = 'selected-call', args = {}): ToolCall =>
})
describe('approved catalog across presentation and lifecycle', () => {
+ it.each([83, 150, 250])(
+ 'keeps direct-first guidance accurate in both prompt paths as auto grows to %i tools and shrinks',
+ async count => {
+ const { manager, registry, nativeNames } = await setup(1)
+ const controller = new DeferrableToolController(
+ new DefaultLoopController(),
+ nativeNames,
+ { dynamicToolsEnabled: false, dynamicToolsThreshold: 60, codexMode: 'auto' },
+ { get: () => undefined, set: () => {} }
+ )
+ const builder = new DefaultPromptBuilder()
+ const buildPrompts = async () => {
+ const presented = await controller.refreshTools(registry.listDefinitions())
+ const hasBridge = presented.some(tool => tool.name === 'clerum__tool_search')
+ const parts = builder.buildParts({
+ identityFiles: { identity: '', soul: '', agents: '', user: '' },
+ dailyLogSnapshot: '',
+ model: 'codex-test',
+ provider: 'codex-subscription',
+ platformHints: [],
+ capabilities: '',
+ workflowGuidance: '',
+ mcpServerGuidance: '',
+ toolDiscoveryGuidance: hasBridge ? TOOL_DISCOVERY_TEXT : '',
+ memoryGuidance: '',
+ })
+ const legacy = String(builder.buildSystemPrompt(presented).content)
+ for (const prompt of [legacy, parts.context]) {
+ expect(prompt).toContain('Use directly listed tools when available.')
+ expect(prompt).toContain('For additional approved tools,')
+ expect(prompt).not.toContain('not all listed directly')
+ }
+ expect(hasBridge).toBe(true)
+ return { presented, parts }
+ }
+ const direct = await buildPrompts()
+ expect(direct.presented).toEqual(registry.listDefinitions())
+ expect(direct.presented.some(tool => tool.name === 'alpha__record__read_000')).toBe(true)
+
+ remote.catalogs.set(
+ 'late',
+ Array.from({ length: count - 1 }, (_, i) => ({
+ name: `read_${i}`,
+ description: `Read record ${i}`,
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
+ }))
+ )
+ await manager.addServer(serverInfo('late'))
+ expect(manager.getAllTools()).toHaveLength(count)
+ const discovery = await buildPrompts()
+ expect(discovery.presented.every(tool => nativeNames.has(tool.name))).toBe(true)
+ expect(discovery.parts.contextHash).toBe(direct.parts.contextHash)
+ expect(discovery.parts.stableHash).toBe(direct.parts.stableHash)
+
+ await manager.removeServer('late')
+ const directAgain = await buildPrompts()
+ expect(directAgain.presented).toEqual(direct.presented)
+ expect(directAgain.parts.contextHash).toBe(direct.parts.contextHash)
+ expect(remote.calls).not.toHaveBeenCalled()
+ }
+ )
+
for (const mode of ['direct', 'auto', 'discovery'] as const) {
for (const count of [83, 90, 150, 250]) {
it.each([false, true])(`${mode}: ${count} MCP + 36 natives, reversed=%s`, async reverse => {
diff --git a/mcp-host/src/core/reasoning/promptBuilder.ts b/mcp-host/src/core/reasoning/promptBuilder.ts
index feae61447..932e74f02 100644
--- a/mcp-host/src/core/reasoning/promptBuilder.ts
+++ b/mcp-host/src/core/reasoning/promptBuilder.ts
@@ -108,9 +108,9 @@ export const MCP_SERVER_SELECTION_TEXT =
/**
* Tool-discovery guidance (dynamic-tool-loading, Phase F4.1). Emitted whenever
* the `clerum__tool_search` bridge tool is registered — i.e. when the stable
- * bridge is in play. Teaches the model the 3-step discovery flow so it knows
- * the deferred MCP catalog is reachable even though those tools are not listed
- * directly in `tools[]`.
+ * bridge is callable. Direct definitions take precedence; discovery is explained
+ * for additional approved tools. This applies both below and above the auto
+ * threshold without claiming that directly presented schemas are hidden.
*
* Single source of truth, shared by the legacy and tiered paths. It is a
* CONSTANT (the bridge tools are always present when active), so it lives in the
diff --git a/mcp-host/src/logger.test.ts b/mcp-host/src/logger.test.ts
index 073f260ac..1cdcc20a6 100644
--- a/mcp-host/src/logger.test.ts
+++ b/mcp-host/src/logger.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from 'vitest'
+import { describe, expect, it, vi } from 'vitest'
import { redactUnknown } from './logger.js'
describe('mcp-host structured logger redaction', () => {
@@ -34,4 +34,44 @@ describe('mcp-host structured logger redaction', () => {
const input = { ok: true, constructor: { evil: true }, prototype: { evil: true } }
expect(redactUnknown(input)).toEqual({ ok: true })
})
+
+ it('emits a structured fallback through the public logger when fields cannot be serialized', async () => {
+ const previousConsole = { log: console.log, error: console.error, warn: console.warn }
+ const output = vi.spyOn(console, 'log').mockImplementation(() => {})
+ vi.stubEnv('LOG_LEVEL', 'info')
+ vi.resetModules()
+ try {
+ // The module binds its sinks at import time, so capture the sink before
+ // loading it and restore its console adapters after this isolated check.
+ const { logger } = await import('./logger.js')
+ logger.info({ taskId: 'task-1' }, 'valid fields')
+ const fields = Object.defineProperty({ taskId: 'task-2' }, 'unreadable', {
+ enumerable: true,
+ get() {
+ throw new Error('fixture field cannot be read')
+ },
+ })
+ logger.info(fields, 'unserializable fields')
+
+ expect(output).toHaveBeenCalledTimes(2)
+ expect(JSON.parse(output.mock.calls[0]![0] as string)).toMatchObject({
+ taskId: 'task-1',
+ level: 'info',
+ msg: 'valid fields',
+ })
+ expect(JSON.parse(output.mock.calls[1]![0] as string)).toEqual({
+ fields: '[Unserializable]',
+ timestamp: expect.any(String),
+ level: 'info',
+ msg: 'unserializable fields',
+ })
+ } finally {
+ output.mockRestore()
+ console.log = previousConsole.log
+ console.error = previousConsole.error
+ console.warn = previousConsole.warn
+ vi.unstubAllEnvs()
+ vi.resetModules()
+ }
+ })
})