Skip to content

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

TypeScript

test(mcp-host): pin one image source projection shared by both providers

Alfredo Lopez2d79f0f81f03
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 26b13eb7d..3aa545b8f 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.467",
+ "version": "0.1.468",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.467",
+ "version": "0.1.468",
"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 23c13306d..dcc62db72 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.467",
+ "version": "0.1.468",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/llm/__tests__/imageSource.test.ts b/mcp-host/src/llm/__tests__/imageSource.test.ts
new file mode 100644
index 000000000..ee1614ede
--- /dev/null
+++ b/mcp-host/src/llm/__tests__/imageSource.test.ts
@@ -0,0 +1,87 @@
+import { describe, expect, it } from 'vitest'
+import type { MessageContentPart } from '../../core/types'
+import { IMAGE_SOURCE_INVALID, projectImageSource } from '../imageSource'
+import { CodexAuthorizeError } from '../providerAttemptAuthorizer'
+
+// #784: the image provenance projection shared by the Codex and Grok providers.
+
+type ImagePart = Extract<MessageContentPart, { type: 'image' }>
+
+const imagePart = (source: unknown): ImagePart =>
+ ({ type: 'image', mimeType: 'image/png', data: 'AAAA', source }) as ImagePart
+
+const gfs = (ids: { attachmentId?: string; toolCallId?: string }) => ({
+ kind: 'gfs',
+ ...ids,
+ drive: 'drive-1',
+ resourceId: 'resource-1',
+ gfsUri: 'gfs://drive-1/resource-1',
+ version: 3,
+ name: 'chart.png',
+})
+
+const refusal = (detail: string) =>
+ `image part has no usable provenance source (${detail}); host producers must attach the attachment or tool call it came from`
+
+describe('projectImageSource (#784)', () => {
+ it('projects an attachment source to its attachment and message ids', () => {
+ expect(
+ projectImageSource(
+ imagePart({ kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1', extra: 'x' })
+ )
+ ).toEqual({ kind: 'attachment', attachmentId: 'att-1', messageId: 'msg-1' })
+ })
+
+ it('projects a tool source to its attachment and tool call ids', () => {
+ expect(
+ projectImageSource(imagePart({ kind: 'tool', attachmentId: 'att-2', toolCallId: 'call-2' }))
+ ).toEqual({ kind: 'tool', attachmentId: 'att-2', toolCallId: 'call-2' })
+ })
+
+ it('projects a GFS read to its tool-call source and drops the GFS fields', () => {
+ expect(
+ projectImageSource(imagePart(gfs({ attachmentId: 'att-3', toolCallId: 'call-3' })))
+ ).toEqual({ kind: 'tool', attachmentId: 'att-3', toolCallId: 'call-3' })
+ })
+
+ it.each([
+ ['a missing source', undefined, 'missing source'],
+ [
+ 'an attachment with an empty attachmentId',
+ { kind: 'attachment', attachmentId: ' ', messageId: 'msg-1' },
+ 'empty attachmentId',
+ ],
+ [
+ 'an attachment with an empty messageId',
+ { kind: 'attachment', attachmentId: 'att-1', messageId: '' },
+ 'empty messageId',
+ ],
+ [
+ 'a tool source with an empty attachmentId',
+ { kind: 'tool', attachmentId: '', toolCallId: 'call-1' },
+ 'empty attachmentId',
+ ],
+ [
+ 'a tool source with an empty toolCallId',
+ { kind: 'tool', attachmentId: 'att-1', toolCallId: ' ' },
+ 'empty toolCallId',
+ ],
+ ['a GFS read with no attachmentId', gfs({ toolCallId: 'call-1' }), 'empty attachmentId'],
+ ['a GFS read with no toolCallId', gfs({ attachmentId: 'att-1' }), 'empty toolCallId'],
+ ['an unknown kind', { kind: 'upload', attachmentId: 'att-1' }, 'unknown source kind'],
+ ])('refuses %s with image_source_invalid', (_label, source, detail) => {
+ let thrown: unknown
+ try {
+ projectImageSource(imagePart(source))
+ } catch (err) {
+ thrown = err
+ }
+ expect(thrown).toBeInstanceOf(CodexAuthorizeError)
+ expect((thrown as CodexAuthorizeError).code).toBe(IMAGE_SOURCE_INVALID)
+ expect((thrown as CodexAuthorizeError).message).toBe(refusal(detail))
+ })
+
+ it('names the code both providers classify as a non-retryable pre-authorize refusal', () => {
+ expect(IMAGE_SOURCE_INVALID).toBe('image_source_invalid')
+ })
+})
diff --git a/scripts/tests/test-codex-subscription-t0.sh b/scripts/tests/test-codex-subscription-t0.sh
index 1acedeb08..146f9e2b0 100755
--- a/scripts/tests/test-codex-subscription-t0.sh
+++ b/scripts/tests/test-codex-subscription-t0.sh
@@ -304,6 +304,7 @@ run_group "codex-llm-proxy" "codex-llm-proxy" \
run_group "mcp-host" "mcp-host" \
"src/__tests__/bodylimits.test.ts" \
+ "src/llm/__tests__/imageSource.test.ts" \
"src/capabilities/toolCatalogTools.test.ts" \
"src/core/orchestration/__tests__/approvedToolsLifecycle.integration.test.ts" \
"src/core/orchestration/__tests__/toolUseLoop.spillover.test.ts" \
diff --git a/scripts/tests/test-grok-subscription-t0.sh b/scripts/tests/test-grok-subscription-t0.sh
index f702f8151..5430faf94 100755
--- a/scripts/tests/test-grok-subscription-t0.sh
+++ b/scripts/tests/test-grok-subscription-t0.sh
@@ -292,6 +292,7 @@ require_real_pg_suite "control-api/test/services.llmProviderAttemptAuthorization
run_group "mcp-host grok" "mcp-host" \
"src/llm/__tests__/grokSubscription.test.ts" \
"src/llm/__tests__/attachmentBudgetRefusal.test.ts" \
+ "src/llm/__tests__/imageSource.test.ts" \
"src/llm/__tests__/grokLlmProxyClient.test.ts" \
"src/llm/__tests__/imageInput.test.ts" \
"src/llm/__tests__/providerAttemptAuthorizer.test.ts" \