Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(host): witness the page collapse in the loop test and cover Grok
Alfredo Lopez6504865dcdde
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 8549293fa..5e766e243 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.494",+ "version": "0.1.495","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.494",+ "version": "0.1.495","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 0076aed62..17741ccc8 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.494",+ "version": "0.1.495","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/orchestration/__tests__/loopInjectedProviderProjection.test.ts b/mcp-host/src/core/orchestration/__tests__/loopInjectedProviderProjection.test.tsindex 34f91e4d4..6ff2efed3 100644--- a/mcp-host/src/core/orchestration/__tests__/loopInjectedProviderProjection.test.ts+++ b/mcp-host/src/core/orchestration/__tests__/loopInjectedProviderProjection.test.ts@@ -11,6 +11,7 @@import { describe, expect, it, vi } from 'vitest'import { ClaudeProvider } from '../../../llm/claude'import { CodexSubscriptionProvider } from '../../../llm/codexSubscription'+import { GrokSubscriptionProvider } from '../../../llm/grokSubscription'import { OpenAIProvider } from '../../../llm/openai'import type { ChatMessage } from '../../types'import { isLoopInjectedMessage, loopInjectedUserMessage } from '../toolUseLoopMessages'@@ -90,6 +91,35 @@ describe('LM1 the loopInjected marker never reaches a provider request body', ()expectNoMarker(streamed)})+ it('Grok subscription authorize request and proxy stream request', async () => {+ const authorize = vi.fn().mockResolvedValue({+ providerAttemptId: 'attempt-1',+ requestHash: 'a'.repeat(64),+ executionTicket: 'ticket-123456',+ expiresAt: '2026-08-20T10:00:00.000Z',+ })+ const stream = vi.fn().mockResolvedValue({ text: 'ok', toolCalls: [], outcome: 'success' })+ const provider = new GrokSubscriptionProvider('grok-4.6', {+ authorizer: { authorize },+ proxy: { stream },+ attemptContext: () => ({ policyRevision: 1, policyHash: 'b'.repeat(64), hostRef: 'chatllm' }),+ } as never)++ await provider.completeSingleTurnWithTools(conversation(), TOOLS)++ expect(authorize).toHaveBeenCalledTimes(1)+ expect(stream).toHaveBeenCalledTimes(1)+ const authorized = authorize.mock.calls[0]![0] as { request: { messages: unknown[] } }+ expect(authorized.request.messages).toEqual([+ { role: 'user', content: GENUINE_TEXT },+ { role: 'assistant', content: ASSISTANT_TEXT },+ { role: 'user', content: INJECTED_TEXT },+ ])+ expectNoMarker(authorized)+ const { signal: _signal, ...streamed } = stream.mock.calls[0]![0] as Record<string, unknown>+ expectNoMarker(streamed)+ })+it('Claude messages', async () => {const create = vi.fn().mockResolvedValue({content: [{ type: 'text', text: 'ok' }],diff --git a/mcp-host/src/core/orchestration/__tests__/toolUseLoop.loopInjectedTurn.test.ts b/mcp-host/src/core/orchestration/__tests__/toolUseLoop.loopInjectedTurn.test.tsindex 313cdc5bb..f8aa81c41 100644--- a/mcp-host/src/core/orchestration/__tests__/toolUseLoop.loopInjectedTurn.test.ts+++ b/mcp-host/src/core/orchestration/__tests__/toolUseLoop.loopInjectedTurn.test.ts@@ -5,7 +5,9 @@* The loop runs for real: a page is read, the loop injects a `role: 'user'`* message, a second page is read, and the context manager applies `prePrune`* under qualifying pressure on every iteration. Both pages belong to the same- * user turn, so neither may be collapsed before the model answers.+ * user turn, so neither may be collapsed before the model answers. A page read+ * in an earlier user turn is collapsed in the same run, which shows the pass+ * was active.*/import { describe, expect, it, vi } from 'vitest'import { makeFakeConversation } from '../../conversation/__testing__/makeFakeConversation'@@ -162,7 +164,17 @@ async function runScenario(scenario: Scenario) {contextManager: { manage },})+ // An earlier user turn already read a page. It is the collapse candidate the+ // pass must act on in this same run, under the same pressure.const outcome = await runToolUseLoop(config, [+ { role: 'user', content: 'Read the start of the attached file.' },+ {+ role: 'assistant',+ content: '',+ tool_calls: [{ id: 'tc_p0', name: READ_TOOL, arguments: { attachmentId: 'att_1' } }],+ },+ { role: 'tool', name: READ_TOOL, tool_call_id: 'tc_p0', content: nativePage(0) },+ { role: 'assistant', content: 'Read the first page.' },{ role: 'user', content: 'Summarize the attached file.' },])return { outcome, sent, manage, collapseRuns }@@ -174,7 +186,7 @@ describe('LM1 loop-injected user messages keep the current turn for page collaps['a nudge from onTextRejected', nudgeScenario],])('keeps both same-turn pages across %s under pressure', async (_, build) => {const scenario = build()- const { outcome, sent, manage } = await runScenario(scenario)+ const { outcome, sent, manage, collapseRuns } = await runScenario(scenario)// Witnesses: the loop ran the whole script, the context manager ran on// every iteration, and the injected user message sits between the pages.@@ -182,6 +194,13 @@ describe('LM1 loop-injected user messages keep the current turn for page collapsexpect(sent).toHaveLength(4)expect(manage.mock.calls.length).toBeGreaterThanOrEqual(4)const final = sent[3]!++ // Witness that the collapse pass ran in this run: the earlier turn's page+ // reached the model collapsed.+ expect(collapseRuns.flat()).toContain('attachment_page_collapse')+ const earlierPage = final.findIndex(m => m.role === 'tool' && m.tool_call_id === 'tc_p0')+ expect(earlierPage).toBeGreaterThan(0)+ expect(pageText(final[earlierPage]!)).toBe(COLLAPSE_MARKER)const firstPage = final.findIndex(m => m.role === 'tool' && m.tool_call_id === 'tc_p1')const injected = final.findIndex(m => m.role === 'user' && m.content === scenario.injected)const secondPage = final.findIndex(m => m.role === 'tool' && m.tool_call_id === 'tc_p2')