Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(mcp-host): require the ContextManager log component and pin refusal labels (#731)
Alfredo Lopez772d475c3138
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 640fbe173..f610e7241 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.391",+ "version": "0.1.392","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.391",+ "version": "0.1.392","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 86cf2d996..bf3dd2bc0 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.391",+ "version": "0.1.392","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/__tests__/fixtures/minifiedMcpResult.ts b/mcp-host/src/__tests__/fixtures/minifiedMcpResult.tsindex 862d2f0d7..8f9a96cd9 100644--- a/mcp-host/src/__tests__/fixtures/minifiedMcpResult.ts+++ b/mcp-host/src/__tests__/fixtures/minifiedMcpResult.ts@@ -57,7 +57,7 @@ function contact(rnd: () => number, index: number): Record<string, unknown> {firstName: first,lastName: last,headline: `${pick(rnd, TITLES)} at ${company}`,- linkedinUrl: `https://www.linkedin.com/in/${first.toLowerCase()}-${last+ linkedinUrl: `https://linkedin.example/in/${first.toLowerCase()}-${last.toLowerCase().replace(/ /g, '-')}-${index}`,company: {diff --git a/mcp-host/src/core/extensions/__tests__/contextManager.antiThrash.test.ts b/mcp-host/src/core/extensions/__tests__/contextManager.antiThrash.test.tsindex b12d049e6..bccce34be 100644--- a/mcp-host/src/core/extensions/__tests__/contextManager.antiThrash.test.ts+++ b/mcp-host/src/core/extensions/__tests__/contextManager.antiThrash.test.ts@@ -183,11 +183,17 @@ describe('PressureContextManager — T1.4 anti-thrash', () => {expect(warnSpy).toHaveBeenCalledTimes(1)expect(warnSpy).toHaveBeenCalledWith(expect.objectContaining({+ component: 'ContextManager',taskId: 'task-E1',- conversationId: conv.id,}),'Compaction backoff: history cannot be shrunk; proceeding uncompacted')+ // `component` is the field the Loki queries for this service filter on; the+ // `[ContextManager]` prefix it replaces carried it before the logger+ // migration. The conversation id is left out: on the email channel it+ // embeds the sender's address, and key-based redaction does not catch a+ // value. `taskId` above is the positive witness that the call was made+ // with its identifying fields.// The three numbers are asserted as numbers, not as `expect.any(Number)`,// which `NaN` satisfies - and a gauge reading `NaN` is the exact failure@@ -197,6 +203,7 @@ describe('PressureContextManager — T1.4 anti-thrash', () => {// passed through untouched, `pressure` cleared a tier threshold or no tier// would have run, and `lastRatio` is a ratio.const [fields] = warnSpy.mock.calls[0] as [Record<string, unknown>, string]+ expect(fields).not.toHaveProperty('conversationId')expect(fields.messageCount).toBe(msgs.length)expect(fields.pressure).toBeGreaterThan(0.8)expect(fields.lastRatio).toBeGreaterThan(0)diff --git a/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts b/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.tsindex 08c17c8e3..50fe5e3e5 100644--- a/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts+++ b/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts@@ -5,7 +5,7 @@* delta histogram and tier-mismatch counter are still emitted;* - when `dryRun: false`, the counter drives the tier directly.*/-import { beforeEach, describe, expect, it, vi } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { logger } from '../../../logger'import { makeFakeConversation } from '../../conversation/__testing__/makeFakeConversation'import { PressureContextManager } from '../../extensions/contextManager'@@ -53,6 +53,13 @@ describe('PressureContextManager dry-run', () => {tokenizerDryrunTierMismatchTotal.reset()})+ // T-E1b silences `logger.warn` and `console.warn`. Restoring them here rather+ // than at the end of the test body keeps a failing assertion from leaking+ // silenced spies into every later test in the file.+ afterEach(() => {+ vi.restoreAllMocks()+ })+it('keeps heuristic-driven tier selection when dryRun=true', async () => {const msgs = tinyMessages()const heuristic = heuristicCount(msgs)@@ -110,13 +117,10 @@ describe('PressureContextManager dry-run', () => {expect(warnSpy).toHaveBeenCalledTimes(1)expect(warnSpy).toHaveBeenCalledWith(- expect.objectContaining({ err: expect.any(Error) }),+ expect.objectContaining({ component: 'ContextManager', err: expect.any(Error) }),'dryrun counter failed; using heuristic')expect(consoleSpy).not.toHaveBeenCalled()-- warnSpy.mockRestore()- consoleSpy.mockRestore()})it('falls back to heuristic when no counter is provided', async () => {diff --git a/mcp-host/src/llm/__tests__/codexSubscription.test.ts b/mcp-host/src/llm/__tests__/codexSubscription.test.tsindex add9efc94..69606d1f2 100644--- a/mcp-host/src/llm/__tests__/codexSubscription.test.ts+++ b/mcp-host/src/llm/__tests__/codexSubscription.test.ts@@ -327,7 +327,13 @@ describe('CodexSubscriptionProvider', () => {expect(wired.stream).not.toHaveBeenCalled()const err = await rejected.catch((e: unknown) => e)- expect(provider.classifyError(err).code).not.toBe(LlmErrorCode.ContextLengthExceeded)+ // The positive label, not only "not context-length": a remap of+ // `invalid_request` to a retryable class would send the same refusal back+ // to the contract on every retry.+ expect(provider.classifyError(err)).toMatchObject({+ code: LlmErrorCode.ApiCallFailed,+ retryable: false,+ })// Liveness witness: the same shape at a legal depth authorizes and streams,// so the refusal is the depth and not the arguments payload as such.@@ -369,7 +375,10 @@ describe('CodexSubscriptionProvider', () => {expect(wired.stream).not.toHaveBeenCalled()const err = await rejected.catch((e: unknown) => e)- expect(provider.classifyError(err).code).not.toBe(LlmErrorCode.ContextLengthExceeded)+ expect(provider.classifyError(err)).toMatchObject({+ code: LlmErrorCode.ApiCallFailed,+ retryable: false,+ })// Liveness witness: the bound itself authorizes and streams, so the refusal// is the range check and not the presence of `max_tokens` in the request.diff --git a/mcp-host/src/llm/__tests__/grokSubscription.test.ts b/mcp-host/src/llm/__tests__/grokSubscription.test.tsindex b23f7b289..db74d0905 100644--- a/mcp-host/src/llm/__tests__/grokSubscription.test.ts+++ b/mcp-host/src/llm/__tests__/grokSubscription.test.ts@@ -521,7 +521,13 @@ describe('GrokSubscriptionProvider', () => {expect(wired.proxy.stream).not.toHaveBeenCalled()const err = await rejected.catch((e: unknown) => e)- expect(provider.classifyError(err).code).not.toBe(LlmErrorCode.ContextLengthExceeded)+ // The positive label, not only "not context-length": a remap of+ // `invalid_request` to a retryable class would send the same refusal back+ // to the contract on every retry.+ expect(provider.classifyError(err)).toMatchObject({+ code: LlmErrorCode.ApiCallFailed,+ retryable: false,+ })// Liveness witness: the bound itself authorizes and streams, so the refusal// is the range check and not the presence of `max_tokens` in the request.