Skip to content

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

TypeScript

test(mcp-host): keep each liveness witness inside the test it supports (#739)

Alfredo Lopez19f68ae45169
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 1fafbca65..26665d124 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.424",
+ "version": "0.1.425",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.424",
+ "version": "0.1.425",
"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 f738305ba..f3d1ea0b0 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.424",
+ "version": "0.1.425",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/agent/__tests__/taskExecutor.test.ts b/mcp-host/src/agent/__tests__/taskExecutor.test.ts
index d0f66dbc4..0b9028a03 100644
--- a/mcp-host/src/agent/__tests__/taskExecutor.test.ts
+++ b/mcp-host/src/agent/__tests__/taskExecutor.test.ts
@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { LIMITS as CODEX_LIMITS } from '@clerum/llm-provider-attempt-contract'
import { config as appConfig } from '../../config'
import { LlmPortAdapter } from '../../core/adapters/llmPortAdapter'
import { makeFakeConversation } from '../../core/conversation/__testing__/makeFakeConversation'
@@ -2410,21 +2411,27 @@ describe('TaskExecutor context manager message bound (#731)', () => {
}
it('T-R2-3c a codex-subscription task compacts past the contract message bound', async () => {
- const msgs = smallTurns(1_025)
+ const msgs = smallTurns(CODEX_LIMITS.maxMessages + 1)
const managed = await (
await loopContextManager('codex-subscription')
).manage(msgs, makeFakeConversation())
- expect(managed.length).toBeLessThan(1_024)
+ expect(managed.length).toBeLessThan(CODEX_LIMITS.maxMessages)
})
it('T-R2-3d an openai task, with no attempt contract, is not bounded by message count', async () => {
- const msgs = smallTurns(1_025)
+ const msgs = smallTurns(CODEX_LIMITS.maxMessages + 1)
const contextManager = await loopContextManager('openai')
- // Liveness witness: the loop's default manager always passes through, so the
- // passthrough below proves nothing unless this is the pressure manager.
+ // The loop's default manager always passes through, so the passthrough
+ // below proves nothing unless this is the pressure manager.
expect(contextManager).toBeInstanceOf(PressureContextManager)
const managed = await contextManager.manage(msgs, makeFakeConversation())
expect(managed).toBe(msgs)
+ // Liveness witness: the same history is compacted by a task whose provider
+ // carries the bound, so the passthrough above is the missing bound.
+ const bounded = await (
+ await loopContextManager('codex-subscription')
+ ).manage(msgs, makeFakeConversation())
+ expect(bounded.length).toBeLessThan(CODEX_LIMITS.maxMessages)
})
})
@@ -2574,14 +2581,14 @@ describe('TaskExecutor history compaction threshold follows the context window (
return call[1]?.find(m => m.role === 'tool')?.content
}
- it('T-R2-4b a 1M window leaves a 100k-token history untouched', async () => {
+ it('T-R2-4b/4c a 1M window leaves a 100k-token history untouched', async () => {
expect(await oldResultReachingLoop(1_000_000)).toBe(OLD_RESULT)
- })
-
- it('T-R2-4c witness: a 100k window pre-prunes the same history', async () => {
- const reached = await oldResultReachingLoop(100_000)
- expect(reached).toBeDefined()
- expect(reached!.length).toBeLessThan(OLD_RESULT.length / 10)
+ // Liveness witness: a 100k window pre-prunes the same history, so the
+ // untouched result above is the window's doing, not a compaction that
+ // never ran.
+ const pruned = await oldResultReachingLoop(100_000)
+ expect(pruned).toBeDefined()
+ expect(pruned!.length).toBeLessThan(OLD_RESULT.length / 10)
})
describe('R9-12 (M-D) rehydration measures with the context manager', () => {
diff --git a/mcp-host/src/core/conversation/__tests__/compaction.test.ts b/mcp-host/src/core/conversation/__tests__/compaction.test.ts
index d34f8cde4..fbe72d9d6 100644
--- a/mcp-host/src/core/conversation/__tests__/compaction.test.ts
+++ b/mcp-host/src/core/conversation/__tests__/compaction.test.ts
@@ -139,13 +139,12 @@ describe('compactConversation — pre-prune is gated at the threshold (#731)', (
expect(await compactConversation(messages, undefined, 1_000_000, undefined, prePruneOn)).toBe(
messages
)
- })
-
- it('T-R2-4a witness: the same history is pre-pruned above the threshold', async () => {
- const messages = prunableHistory()
+ // Liveness witness: the same history is pre-pruned above the threshold, so
+ // the passthrough above is the threshold's doing, not a pre-prune that
+ // never runs.
const compacted = await compactConversation(messages, undefined, 1_000, undefined, prePruneOn)
const oldResult = compacted.find(m => m.role === 'tool')
- expect(oldResult?.content).not.toBe(OLD_RESULT)
+ expect(oldResult).toBeDefined()
expect(oldResult!.content.length).toBeLessThan(OLD_RESULT.length / 10)
})
})
diff --git a/mcp-host/src/core/conversation/__tests__/compactionTranscriptInvariant.test.ts b/mcp-host/src/core/conversation/__tests__/compactionTranscriptInvariant.test.ts
index a078cade7..bd209cc0d 100644
--- a/mcp-host/src/core/conversation/__tests__/compactionTranscriptInvariant.test.ts
+++ b/mcp-host/src/core/conversation/__tests__/compactionTranscriptInvariant.test.ts
@@ -84,6 +84,9 @@ describe('compaction ↔ durable transcript invariant (FU2, spec §8 "does not a
const compacted = await compactConversation(messages, 2, 0)
expect(compacted).not.toBe(messages)
+ // The new array is the compaction's output: two turns of the twelve messages.
+ expect(compacted.length).toBeLessThan(messages.length)
+ expect(compacted.at(-1)).toEqual(messages.at(-1))
expect(messages).toEqual(inputSnapshot) // input array left intact
})
})
diff --git a/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts b/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts
index e97f85bde..80cef95ed 100644
--- a/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts
+++ b/mcp-host/src/core/tokenizer/__tests__/contextManagerDryRun.test.ts
@@ -34,6 +34,20 @@ function tinyMessages(): ChatMessage[] {
]
}
+/**
+ * `count` short user/assistant turns. The emergency tier keeps the last three,
+ * so a compaction of this history is visible in its length, not only in a new
+ * array reference.
+ */
+function turns(count: number): ChatMessage[] {
+ const msgs: ChatMessage[] = []
+ for (let i = 1; i <= count; i++) {
+ msgs.push({ role: 'user', content: `question ${i} a b c d e f` })
+ msgs.push({ role: 'assistant', content: `answer ${i} g h i j k l` })
+ }
+ return msgs
+}
+
function getMismatchCount(from: string, to: string): number {
const samples = (
tokenizerDryrunTierMismatchTotal as unknown as {
@@ -78,7 +92,7 @@ describe('PressureContextManager dry-run', () => {
})
it('lets the counter drive the tier when dryRun=false', async () => {
- const msgs = tinyMessages()
+ const msgs = turns(10)
const heuristic = heuristicCount(msgs)
// Same setup as above (heuristic would passthrough) but with dryRun
// disabled the counter's high value should trigger compaction.
@@ -89,6 +103,9 @@ describe('PressureContextManager dry-run', () => {
})
const result = await manager.manage(msgs, makeFakeConversation())
expect(result).not.toBe(msgs)
+ // The emergency tier ran: the last three turns remain, the newest intact.
+ expect(result.filter(m => m.role === 'user')).toHaveLength(3)
+ expect(result.at(-1)?.content).toBe(msgs.at(-1)?.content)
})
it('T-E1b a failing dry-run counter is reported through the service logger (#731)', async () => {
@@ -149,7 +166,7 @@ describe('PressureContextManager pressure includes the tool schemas', () => {
}
it('T-R2-2a tools push a conversation below 0.8 into compaction on the heuristic path', async () => {
- const msgs = tinyMessages()
+ const msgs = turns(10)
const tools = bulkyTools()
const maxTokens = Math.ceil(heuristicCount(msgs) / 0.7)
// Witness the arithmetic, so the two outcomes below can only differ by the tools term.
@@ -160,11 +177,15 @@ describe('PressureContextManager pressure includes the tool schemas', () => {
const manager = new PressureContextManager(maxTokens)
expect(await manager.manage(msgs, makeFakeConversation())).toBe(msgs)
- expect(await manager.manage(msgs, makeFakeConversation(), { tools })).not.toBe(msgs)
+ const result = await manager.manage(msgs, makeFakeConversation(), { tools })
+ expect(result).not.toBe(msgs)
+ // The emergency tier ran: the last three turns remain, the newest intact.
+ expect(result.filter(m => m.role === 'user')).toHaveLength(3)
+ expect(result.at(-1)?.content).toBe(msgs.at(-1)?.content)
})
it('T-R2-2b dry-run decides from messages plus tools and hands the tools to the counter', async () => {
- const msgs = tinyMessages()
+ const msgs = turns(10)
const tools = bulkyTools()
const maxTokens = Math.ceil(heuristicCount(msgs) / 0.7)
const counter = makeCounter(0) // would pass through if it decided
@@ -175,6 +196,7 @@ describe('PressureContextManager pressure includes the tool schemas', () => {
const result = await manager.manage(msgs, makeFakeConversation(), { tools })
expect(result).not.toBe(msgs)
+ expect(result.filter(m => m.role === 'user')).toHaveLength(3)
expect(counter.count).toHaveBeenCalledWith(msgs, tools)
})
@@ -200,14 +222,6 @@ describe('PressureContextManager pressure includes the tool schemas', () => {
// guidance. It is not part of `messages`, so the gauge must add it in every
// branch of `computePressure`, as it adds the tools (R9-14, L-6).
describe('PressureContextManager pressure includes the system prompt', () => {
- function turns(count: number): ChatMessage[] {
- const msgs: ChatMessage[] = []
- for (let i = 1; i <= count; i++) {
- msgs.push({ role: 'user', content: `question ${i} a b c d e f` })
- msgs.push({ role: 'assistant', content: `answer ${i} g h i j k l` })
- }
- return msgs
- }
const asSystemMessage = (content: string): ChatMessage => ({ role: 'system', content })
// Messages at 0.7 of the window; the system prompt alone is about one window.