Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions tests/helpers/browser-capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,43 @@ describe('explicit browser capabilities', () => {
expect(Object.getOwnPropertyDescriptor(detail, 'toJSON')).toBeUndefined();
});

test.each(['30m', '12h'] as const)('preserves browser breakpoint TTL %s on the wire', async (ttl) => {
const breakpoint = { mode: 'explicit' as const, ttl };
const image = {
type: 'input_image' as const,
file_id: 'file_fixture',
prompt_cache_breakpoint: breakpoint,
};
const browser = new BrowserToolset({ state, screenshot: () => image });
const output = await browser.execute(call('screenshot', { tab_id: null }));
breakpoint.ttl = ttl === '12h' ? '30m' : '12h';
const received: unknown[] = [];
const client = new OpenAI({
apiKey: 'synthetic-test-key',
maxRetries: 0,
fetch: async (url, init) => {
received.push(await new Request(url, init).json());
return Response.json({ id: 'resp_fixture', object: 'response', status: 'completed', output: [] });
},
});
await client.responses.create({ model: 'fixture', input: [output] });
expect(received).toMatchObject([
{
input: [
{
output: expect.arrayContaining([
{
type: 'input_image',
file_id: 'file_fixture',
prompt_cache_breakpoint: { mode: 'explicit', ttl },
},
]),
},
],
},
]);
});

test.each(['image', 'declined', 'failed'] as const)(
'direct browser %s output keeps its owned structure through a native Responses request',
async (kind) => {
Expand Down Expand Up @@ -1121,8 +1158,10 @@ describe('explicit browser capabilities', () => {
{ image_url: ' ' },
{ file_id: 'file_ok', prompt_cache_breakpoint: { mode: 'automatic' } },
{ file_id: 'file_ok', prompt_cache_breakpoint: {} },
{ file_id: 'file_ok', prompt_cache_breakpoint: { mode: 'explicit', ttl: '1h' } },
{ file_id: 'file_ok', prompt_cache_breakpoint: { mode: 'explicit', ttl: null } },
...[null, 42, 'invalid', '1h'].map((ttl) => ({
file_id: 'file_ok',
prompt_cache_breakpoint: { mode: 'explicit', ttl },
})),
{ file_id: 'file_ok', prompt_cache_breakpoint: { mode: 'explicit', private: 'omit' } },
].map(async (invalid) => {
const image = { type: 'input_image' as const, detail: 'auto' as const };
Expand Down
41 changes: 29 additions & 12 deletions tests/helpers/browser-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8779,8 +8779,8 @@ describe('ResponsesToolRunner iteration', () => {
},
);

test.each(['30m', '12h'] as const)(
'supplies native results with ttl %s without changing call IDs, mixed order or pending arguments',
test.each([undefined, '30m', '12h'] as const)(
'supplies native results with TTL %s without changing call IDs or order',
async (ttl) => {
const effects: string[] = [];
const browser = new BrowserToolset(
Expand Down Expand Up @@ -8813,26 +8813,31 @@ describe('ResponsesToolRunner iteration', () => {
if (first.done) {
throw new Error('Missing turn');
}
const breakpoint = { mode: 'explicit' as const, ...(ttl === undefined ? {} : { ttl }) };
const expectedBreakpoint = { ...breakpoint };
const supplied = [
{
type: 'input_text' as const,
text: 'human result',
prompt_cache_breakpoint: { mode: 'explicit' as const, ttl },
prompt_cache_breakpoint: breakpoint,
},
{
type: 'input_image' as const,
image_url: 'https://fixture.invalid/image',
detail: 'original' as const,
prompt_cache_breakpoint: breakpoint,
},
{ type: 'input_file' as const, file_id: 'file_fixture' },
{ type: 'input_file' as const, file_id: 'file_fixture', prompt_cache_breakpoint: breakpoint },
];
first.value.supplyOutputs([{ type: 'function_call_output', call_id: 'call_record', output: supplied }]);
const [text] = supplied;
if (text?.type !== 'input_text') {
throw new Error('Missing text output');
}
text.text = 'changed later';
Reflect.set(text.prompt_cache_breakpoint, 'ttl', 'changed');
if (ttl !== undefined) {
breakpoint.ttl = ttl === '12h' ? '30m' : '12h';
}
const [, pending] = first.value.response.output;
if (pending?.type !== 'function_call') {
throw new Error('Missing pending call');
Expand All @@ -8852,9 +8857,14 @@ describe('ResponsesToolRunner iteration', () => {
type: 'function_call_output',
call_id: 'call_record',
output: [
{ type: 'input_text', text: 'human result', prompt_cache_breakpoint: { mode: 'explicit', ttl } },
{ type: 'input_image', image_url: 'https://fixture.invalid/image', detail: 'original' },
{ type: 'input_file', file_id: 'file_fixture' },
{ type: 'input_text', text: 'human result', prompt_cache_breakpoint: expectedBreakpoint },
{
type: 'input_image',
image_url: 'https://fixture.invalid/image',
detail: 'original',
prompt_cache_breakpoint: expectedBreakpoint,
},
{ type: 'input_file', file_id: 'file_fixture', prompt_cache_breakpoint: expectedBreakpoint },
],
});
expect(JSON.stringify(h.bodies[1]?.['input'])).not.toContain('retargeted');
Expand Down Expand Up @@ -8946,19 +8956,26 @@ describe('ResponsesToolRunner iteration', () => {
[allowed, { ...allowed, call_id: 'unknown' }],
[{ ...allowed, output: [{ type: 'input_text', text: 42 }] }],
[{ ...allowed, output: [{ type: 'input_image', image_url: { private: true } }] }],
[
...[null, 42, 'invalid', '1h'].map((ttl) => [
{
...allowed,
output: [
{ type: 'input_text', text: 'value', prompt_cache_breakpoint: { mode: 'explicit', ttl: '1h' } },
{ type: 'input_text', text: 'fixture', prompt_cache_breakpoint: { mode: 'explicit', ttl } },
],
},
],
]),
[
{
...allowed,
output: [
{ type: 'input_text', text: 'value', prompt_cache_breakpoint: { mode: 'explicit', ttl: null } },
{
type: 'input_text',
text: 'fixture',
prompt_cache_breakpoint: Object.defineProperty({ mode: 'explicit' }, 'ttl', {
get: getter,
enumerable: true,
}),
},
],
},
],
Expand Down
33 changes: 33 additions & 0 deletions tests/lib/responses-output-ttl-types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, test, vi } from 'vitest';
import type { ResponsesRunnerTurn } from 'openai/helpers/responses-tool-runner';

test.each(['30m', '12h'] as const)('accepts inline native outputs with TTL %s without casts', (ttl) => {
const supplyOutputs = vi.fn<ResponsesRunnerTurn['supplyOutputs']>();

supplyOutputs([
{
type: 'function_call_output',
call_id: 'call_fixture',
output: [
{
type: 'input_text',
text: 'fixture',
prompt_cache_breakpoint: { mode: 'explicit', ttl },
},
{
type: 'input_image',
image_url: 'https://fixture.invalid/image',
detail: 'auto',
prompt_cache_breakpoint: { mode: 'explicit', ttl },
},
{
type: 'input_file',
file_id: 'file_fixture',
prompt_cache_breakpoint: { mode: 'explicit', ttl },
},
],
},
]);

expect(supplyOutputs).toHaveBeenCalledOnce();
});
Loading