Skip to content

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

TypeScript

fix(ci): align Codex image tests with the 20-image contract

Alfredo Lopez9c633b23150e
diff --git a/desktop-app/test/e2e-playwright/codexImageChallenge.ts b/desktop-app/test/e2e-playwright/codexImageChallenge.ts
index ebb25a36e..658c6b907 100644
--- a/desktop-app/test/e2e-playwright/codexImageChallenge.ts
+++ b/desktop-app/test/e2e-playwright/codexImageChallenge.ts
@@ -2,23 +2,61 @@ import { randomBytes } from 'node:crypto'
import { createRequire } from 'node:module'
import path from 'node:path'
-const require = createRequire(path.resolve(__dirname, '../../../mcp-host/package.json'))
+const hostRequire = createRequire(path.resolve(__dirname, '../../../mcp-host/package.json'))
const fixtures = createRequire(__filename)(
'../../../packages/llm-provider-attempt-contract/testImageFixtures.cjs'
) as {
+ declaredHeaderPng: (width: number, height: number) => Buffer
+ jpegOfSize: (targetBytes: number, width?: number, height?: number) => Buffer
padJpegToSize: (jpeg: Buffer | string, targetBytes: number) => Buffer
padPngToSize: (png: Buffer | string, targetBytes: number) => Buffer
}
+function loadHostCreateCanvas():
+ | ((
+ width: number,
+ height: number
+ ) => {
+ getContext: (type: '2d') => {
+ fillStyle: string
+ fillRect: (x: number, y: number, width: number, height: number) => void
+ font: string
+ textBaseline: string
+ fillText: (text: string, x: number, y: number) => void
+ }
+ toBuffer: (mime: 'image/png' | 'image/jpeg') => Buffer
+ })
+ | null {
+ try {
+ return hostRequire('@napi-rs/canvas').createCanvas
+ } catch {
+ return null
+ }
+}
+
/** A neutral image with an answer absent from the filename and user prompt. */
export function challengeImageAt(
format: 'png' | 'jpeg',
width: number,
height: number
): { code: string; bytes: Buffer; width: number; height: number } {
- // Reuse the Host renderer installed for T0; do not add another dependency.
- const { createCanvas } = require('@napi-rs/canvas')
const code = randomBytes(8).toString('hex').toUpperCase()
+ // Prefer the Host renderer when mcp-host is installed (T0 / Playwright OCR).
+ // Desktop CI does not install that package; fall back to contract-framed
+ // containers so unit tests still prove size and pixel bounds.
+ const createCanvas = loadHostCreateCanvas()
+ if (!createCanvas) {
+ if (process.env.E2E_CODEX_IMAGE_INPUT === '1') {
+ throw new Error(
+ 'Codex image E2E requires mcp-host/@napi-rs/canvas so the hex is painted in pixels'
+ )
+ }
+ const bytes =
+ format === 'png'
+ ? fixtures.declaredHeaderPng(width, height)
+ : fixtures.jpegOfSize(256, width, height)
+ return { code, bytes, width, height }
+ }
const canvas = createCanvas(width, height)
const context = canvas.getContext('2d')
context.fillStyle = 'white'
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index cb1f6606a..41695a487 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.352",
+ "version": "0.1.353",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.352",
+ "version": "0.1.353",
"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 192838156..e1c19c5f0 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.352",
+ "version": "0.1.353",
"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__/codexSubscription.test.ts b/mcp-host/src/llm/__tests__/codexSubscription.test.ts
index bc6ff259c..045bbaf18 100644
--- a/mcp-host/src/llm/__tests__/codexSubscription.test.ts
+++ b/mcp-host/src/llm/__tests__/codexSubscription.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it, vi } from 'vitest'
import {
+ VISUAL_LIMITS,
hashCodexCompletionRequest,
parseCodexCompletionRequest,
} from '@clerum/llm-provider-attempt-contract'
@@ -658,7 +659,7 @@ describe('CodexSubscriptionProvider', () => {
const messages = userWithImage()
messages[0].contentParts = [
{ type: 'text', text: 'what is on screen?' },
- ...Array.from({ length: 4 }, (_, index) => ({
+ ...Array.from({ length: VISUAL_LIMITS.maxImages + 1 }, (_, index) => ({
type: 'image' as const,
mimeType: 'image/png' as const,
data: PNG_2X2_BASE64,
@@ -673,6 +674,7 @@ describe('CodexSubscriptionProvider', () => {
await expect(provider.completeSingleTurn(messages)).rejects.toMatchObject({
name: 'CodexAuthorizeError',
code: 'invalid_request',
+ message: expect.stringMatching(new RegExp(`${VISUAL_LIMITS.maxImages} images`)),
})
expect(wired.authorize).not.toHaveBeenCalled()
})