Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(llm-proxy): keep complete deltas across a blank close (#739)
Alfredo Lopezf08877eac096
diff --git a/codex-llm-proxy/test/bodyAdmission.test.ts b/codex-llm-proxy/test/bodyAdmission.test.tsindex df3004d44..02ba0eb6c 100644--- a/codex-llm-proxy/test/bodyAdmission.test.ts+++ b/codex-llm-proxy/test/bodyAdmission.test.ts@@ -31,6 +31,8 @@ import { CODEX_CATALOG_ORIGIN, CODEX_COMPLETIONS_ORIGIN } from '../src/originPolimport {BODY_READ_DEADLINE_MS,DEFAULT_MAX_BODY_BYTES,+ // The admission budget holds this many bodies of the configured maximum size.+ IN_FLIGHT_BODY_BUDGET_BODIES as BUDGET_BODIES,STREAM_LIMITS,} from '../src/requestLimits.js'import { type ProxyRuntimeDeps, createProxyApps } from '../src/server.js'@@ -46,8 +48,6 @@ const { privateKey, publicKey } = generateKeyPairSync('rsa', {const HOST_REF = 'research-host'const COMPLETIONS_PATH = '/internal/runtime/v1/codex/completions'-/** The admission budget holds this many bodies of the configured maximum size. */-const BUDGET_BODIES = 3function sign(payload: Record<string, unknown>, audience: string): string {return jwt.sign(payload, privateKey, {diff --git a/codex-llm-proxy/test/codexTransport.conformance.test.ts b/codex-llm-proxy/test/codexTransport.conformance.test.tsindex 237db9f1d..cd3c3d8b3 100644--- a/codex-llm-proxy/test/codexTransport.conformance.test.ts+++ b/codex-llm-proxy/test/codexTransport.conformance.test.ts@@ -1704,6 +1704,54 @@ describe('streamCodexCompletion', () => {})+ // R9-9 (L-12): the positive twin of the case above. A blank close carries+ // nothing new, so complete deltas survive it and the call runs with them.+ const closeWith: Record<string, (rawArguments: string) => string> = {+ 'response.output_item.done': rawArguments =>+ sse({+ type: 'response.output_item.done',+ item: {+ type: 'function_call',+ id: 'item-1',+ call_id: 'call-9',+ name: 'lookup',+ arguments: rawArguments,+ },+ }),+ 'response.function_call_arguments.done': rawArguments =>+ sse({+ type: 'response.function_call_arguments.done',+ item_id: 'item-1',+ arguments: rawArguments,+ }),+ }+ it.each([+ ['response.output_item.done', 'an empty string', ''],+ ['response.output_item.done', 'a whitespace-only string', ' \n '],+ ['response.function_call_arguments.done', 'an empty string', ''],+ ['response.function_call_arguments.done', 'a whitespace-only string', ' \n '],+ ])(+ 'T-R9-9a keeps complete argument deltas when %s closes the call with %s',+ async (event, _label, rawArguments) => {+ const { settled, frames, fetchFn, finalize } = await runUpstream([+ textBefore,+ openCall,+ truncatedDelta,+ sse({ type: 'response.function_call_arguments.delta', item_id: 'item-1', delta: '"x"}' }),+ closeWith[event]!(rawArguments),+ completed,+ ])+ expect(fetchFn).toHaveBeenCalledTimes(1)+ expect(settled).toMatchObject({ rejected: false, result: { outcome: 'success' } })+ expect(frames).toEqual([+ { type: 'text', text: 'before' },+ { type: 'tool_call', id: 'call-9', name: 'lookup', arguments: { q: 'x' } },+ ])+ expect(finalize).toHaveBeenCalledTimes(1)+ expect(finalize.mock.calls[0]?.[0]?.receipt.outcome).toBe('success')+ }+ )+it('refuses a call opened with empty arguments and never closed before the stream ends', async () => {await expectRefused([textBefore, openCall, completed])})diff --git a/grok-llm-proxy/test/bodyAdmission.test.ts b/grok-llm-proxy/test/bodyAdmission.test.tsindex 21278b7d1..86de347df 100644--- a/grok-llm-proxy/test/bodyAdmission.test.ts+++ b/grok-llm-proxy/test/bodyAdmission.test.ts@@ -31,6 +31,8 @@ import { GROK_CATALOG_ORIGIN, GROK_COMPLETIONS_ORIGIN } from '../src/originPolicimport {BODY_READ_DEADLINE_MS,DEFAULT_MAX_BODY_BYTES,+ // The admission budget holds this many bodies of the configured maximum size.+ IN_FLIGHT_BODY_BUDGET_BODIES as BUDGET_BODIES,STREAM_LIMITS,} from '../src/requestLimits.js'import { type ProxyRuntimeDeps, createProxyApps } from '../src/server.js'@@ -46,8 +48,6 @@ const { privateKey, publicKey } = generateKeyPairSync('rsa', {const HOST_REF = 'research-host'const COMPLETIONS_PATH = '/internal/runtime/v1/grok/completions'-/** The admission budget holds this many bodies of the configured maximum size. */-const BUDGET_BODIES = 3function sign(payload: Record<string, unknown>, audience: string): string {return jwt.sign(payload, privateKey, {diff --git a/grok-llm-proxy/test/grokTransport.conformance.test.ts b/grok-llm-proxy/test/grokTransport.conformance.test.tsindex 07ff7619e..12777044c 100644--- a/grok-llm-proxy/test/grokTransport.conformance.test.ts+++ b/grok-llm-proxy/test/grokTransport.conformance.test.ts@@ -1600,6 +1600,54 @@ describe('streamGrokCompletion', () => {})+ // R9-9 (L-12): the positive twin of the case above. A blank close carries+ // nothing new, so complete deltas survive it and the call runs with them.+ const closeWith: Record<string, (rawArguments: string) => string> = {+ 'response.output_item.done': rawArguments =>+ sse({+ type: 'response.output_item.done',+ item: {+ type: 'function_call',+ id: 'item-1',+ call_id: 'call-9',+ name: 'lookup',+ arguments: rawArguments,+ },+ }),+ 'response.function_call_arguments.done': rawArguments =>+ sse({+ type: 'response.function_call_arguments.done',+ item_id: 'item-1',+ arguments: rawArguments,+ }),+ }+ it.each([+ ['response.output_item.done', 'an empty string', ''],+ ['response.output_item.done', 'a whitespace-only string', ' \n '],+ ['response.function_call_arguments.done', 'an empty string', ''],+ ['response.function_call_arguments.done', 'a whitespace-only string', ' \n '],+ ])(+ 'T-R9-9a-grok keeps complete argument deltas when %s closes the call with %s',+ async (event, _label, rawArguments) => {+ const { settled, frames, fetchFn, finalize } = await runUpstream([+ textBefore,+ openCall,+ truncatedDelta,+ sse({ type: 'response.function_call_arguments.delta', item_id: 'item-1', delta: '"x"}' }),+ closeWith[event]!(rawArguments),+ completed,+ ])+ expect(fetchFn).toHaveBeenCalledTimes(1)+ expect(settled).toMatchObject({ rejected: false, result: { outcome: 'success' } })+ expect(frames).toEqual([+ { type: 'text', text: 'before' },+ { type: 'tool_call', id: 'call-9', name: 'lookup', arguments: { q: 'x' } },+ ])+ expect(finalize).toHaveBeenCalledTimes(1)+ expect(finalize.mock.calls[0]?.[0]?.receipt.outcome).toBe('success')+ }+ )+it('refuses a call opened with empty arguments and never closed before the stream ends', async () => {await expectRefused([textBefore, openCall, completed])})