/** Exercise both real pi-ai transports and their catalog prices, without provider SDK mocks. */ import { proxyModels } from './proxy-models'; import { fs } from './extensions'; const readProxy=()=>Deno.core.ops.op_model_proxy(); const models = await proxyModels(await readProxy(),readProxy); for (const [provider, id] of [['openai', 'gpt-6.1-sol'], ['anthropic', 'claude-opus-5-5']]) { const model = models.getModel(provider, id); if (model.cost.input !== 2 || model.cost.cacheWrite !== 3) throw new Error('catalog prices lost'); const result = await models.completeSimple(model, {messages: [{role: 'user', content: 'Say hello.', timestamp: Date.now()}]}, {reasoning: 'low', maxTokens: 128}); if (result.stopReason === 'error' || !result.content.some(block => block.type === 'text' && block.text === 'hello')) { throw new Error(`${provider}: ${result.errorMessage ?? JSON.stringify(result.content)}`); } if (!(result.usage.cost.total > 0)) throw new Error('turn cost missing'); } const fallback = await proxyModels({...globalThis.testProxy, base_url: `${globalThis.testProxy.base_url}/offline`}); for (const [provider, api] of [['openai', 'openai-responses'], ['anthropic', 'anthropic-messages']]) { const model = fallback.getModels(provider)[0]; if (model.api !== api || model.cost.input !== 0) throw new Error('offline transport fallback failed'); } await fs.write('/etc/sausage/config.yaml',JSON.stringify({proxy:{base_url:`${globalThis.testProxy.base_url}/edited`,api_key:'next-key'}})); const auth=await models.getAuth(models.getModel('openai','gpt-6.1-sol')); if(auth.auth.apiKey!=='next-key'||auth.auth.baseUrl!==`${globalThis.testProxy.base_url}/edited/v1`) throw new Error('Proxy edits did not reach the next request'); await fs.write('/etc/sausage/config.yaml',JSON.stringify({proxy:{base_url:'',api_key:''}})); const empty=await proxyModels(await readProxy(),readProxy); let failure=''; try { const result=await empty.completeSimple(empty.getModels('openai')[0],{messages:[{role:'user',content:'Missing key',timestamp:Date.now()}]}); failure=result.errorMessage??''; } catch(error) {failure=String(error)} if(!failure.includes('/etc/sausage/config.yaml')) throw new Error(`Missing proxy settings must name the config file: ${failure}`);