@@ -1409,10 +1409,7 @@ describe('Rate Limiting and Retry Logic', () => {
14091409 } )
14101410} )
14111411
1412- describe . skip ( 'Cost Field Handling' , ( ) => {
1413- // Skipped: These tests require complex env mocking that doesn't work well with bun test.
1414- // The cost calculation logic is tested via the pricing model tests in "Hosted Key Injection".
1415- // TODO: Set up proper integration test environment for these tests.
1412+ describe ( 'Cost Field Handling' , ( ) => {
14161413 let cleanupEnvVars : ( ) => void
14171414
14181415 beforeEach ( ( ) => {
@@ -1499,69 +1496,6 @@ describe.skip('Cost Field Handling', () => {
14991496 Object . assign ( tools , originalTools )
15001497 } )
15011498
1502- it ( 'should merge hosted key cost with existing output cost' , async ( ) => {
1503- const mockTool = {
1504- id : 'test_cost_merge' ,
1505- name : 'Test Cost Merge' ,
1506- description : 'A test tool that returns cost in output' ,
1507- version : '1.0.0' ,
1508- params : {
1509- apiKey : { type : 'string' , required : false } ,
1510- } ,
1511- hosting : {
1512- envKeys : [ 'TEST_HOSTED_KEY' ] ,
1513- apiKeyParam : 'apiKey' ,
1514- pricing : {
1515- type : 'per_request' as const ,
1516- cost : 0.002 ,
1517- } ,
1518- } ,
1519- request : {
1520- url : '/api/test/cost-merge' ,
1521- method : 'POST' as const ,
1522- headers : ( ) => ( { 'Content-Type' : 'application/json' } ) ,
1523- } ,
1524- transformResponse : vi . fn ( ) . mockResolvedValue ( {
1525- success : true ,
1526- output : {
1527- result : 'success' ,
1528- cost : {
1529- input : 0.001 ,
1530- output : 0.003 ,
1531- total : 0.004 ,
1532- } ,
1533- } ,
1534- } ) ,
1535- }
1536-
1537- const originalTools = { ...tools }
1538- ; ( tools as any ) . test_cost_merge = mockTool
1539-
1540- global . fetch = Object . assign (
1541- vi . fn ( ) . mockImplementation ( async ( ) => ( {
1542- ok : true ,
1543- status : 200 ,
1544- headers : new Headers ( ) ,
1545- json : ( ) => Promise . resolve ( { success : true } ) ,
1546- } ) ) ,
1547- { preconnect : vi . fn ( ) }
1548- ) as typeof fetch
1549-
1550- const mockContext = createToolExecutionContext ( {
1551- userId : 'user-123' ,
1552- } as any )
1553- const result = await executeTool ( 'test_cost_merge' , { } , false , mockContext )
1554-
1555- expect ( result . success ) . toBe ( true )
1556- expect ( result . output . cost ) . toBeDefined ( )
1557- // Should merge: existing 0.004 + hosted key 0.002 = 0.006
1558- expect ( result . output . cost . total ) . toBe ( 0.006 )
1559- expect ( result . output . cost . input ) . toBe ( 0.001 )
1560- expect ( result . output . cost . output ) . toBe ( 0.003 )
1561-
1562- Object . assign ( tools , originalTools )
1563- } )
1564-
15651499 it ( 'should not add cost when not using hosted key' , async ( ) => {
15661500 mockIsHosted . value = false
15671501
0 commit comments