2020 * and show what errors are returned for invalid ones.
2121 */
2222
23- import { describe , it , expect , vi } from 'vitest' ;
23+ import { describe , it , expect , beforeAll , afterAll } from 'vitest' ;
2424import { forecast , FORECAST_TOOL } from '../../src/tools/forecast.js' ;
2525import * as clientModule from '../../src/utils/client.js' ;
2626
@@ -41,21 +41,22 @@ function createValidForecastRequest(overrides = {}) {
4141
4242describe ( 'forecast tool' , ( ) => {
4343 /**
44- * Mock client for testing
44+ * Real client initialization for testing
4545 *
46- * We mock the client to avoid actual API calls during testing .
47- * Real integration tests would use real API credentials .
46+ * We use a real client connection to the FAIM server .
47+ * This requires FAIM_API_KEY environment variable to be set .
4848 */
49- beforeEach ( ( ) => {
50- // Mock getClient to throw (simulating initialization error)
51- // Tests can override this for specific scenarios
52- vi . spyOn ( clientModule , 'getClient' ) . mockImplementation ( ( ) => {
53- throw new Error ( 'Client not initialized' ) ;
54- } ) ;
49+ beforeAll ( ( ) => {
50+ // Reset the client module state
51+ clientModule . resetClient ( ) ;
52+
53+ // Initialize with real client connection
54+ // This connects to the actual FAIM server
55+ clientModule . initializeClient ( ) ;
5556 } ) ;
5657
57- afterEach ( ( ) => {
58- vi . restoreAllMocks ( ) ;
58+ afterAll ( ( ) => {
59+ // Clean up is handled by the client module
5960 } ) ;
6061
6162 /**
@@ -198,27 +199,12 @@ describe('forecast tool', () => {
198199
199200 const result = await forecast ( request ) ;
200201
201- // Will fail due to client not initialized, but validation should pass
202- expect ( result . success ) . toBe ( false ) ;
202+ // Request is valid, result depends on API response
203203 if ( ! result . success ) {
204204 expect ( result . error . error_code ) . not . toBe ( 'INVALID_PARAMETER' ) ;
205205 }
206206 } ) ;
207207
208- /**
209- * Client Initialization Tests
210- *
211- * Verify proper handling when client is not initialized.
212- */
213-
214- it ( 'should return error when client is not initialized' , async ( ) => {
215- const request = createValidForecastRequest ( ) ;
216-
217- const result = await forecast ( request ) ;
218-
219- expect ( result . success ) . toBe ( false ) ;
220- } ) ;
221-
222208 /**
223209 * Tool Schema Tests
224210 *
@@ -347,7 +333,7 @@ describe('forecast tool', () => {
347333 expect ( result . success ) . toBe ( false ) ; // Client error
348334 } ) ;
349335
350- it ( 'should accept samples output type' , async ( ) => {
336+ it ( 'should reject samples output type (not supported by API) ' , async ( ) => {
351337 const request = {
352338 model : 'chronos2' ,
353339 x : [ 1 , 2 , 3 ] ,
@@ -357,7 +343,11 @@ describe('forecast tool', () => {
357343
358344 const result = await forecast ( request ) ;
359345
360- expect ( result . success ) . toBe ( false ) ; // Client error
346+ expect ( result . success ) . toBe ( false ) ;
347+ if ( ! result . success ) {
348+ expect ( result . error . error_code ) . toBe ( 'INVALID_PARAMETER' ) ;
349+ expect ( result . error . field ) . toBe ( 'output_type' ) ;
350+ }
361351 } ) ;
362352
363353 /**
@@ -378,14 +368,18 @@ describe('forecast tool', () => {
378368 const result = await forecast ( null ) ;
379369
380370 expect ( result . success ) . toBe ( false ) ;
381- expect ( result . error ) . toBeDefined ( ) ;
371+ if ( ! result . success ) {
372+ expect ( result . error ) . toBeDefined ( ) ;
373+ }
382374 } ) ;
383375
384376 it ( 'should handle undefined input gracefully' , async ( ) => {
385377 const result = await forecast ( undefined ) ;
386378
387379 expect ( result . success ) . toBe ( false ) ;
388- expect ( result . error ) . toBeDefined ( ) ;
380+ if ( ! result . success ) {
381+ expect ( result . error ) . toBeDefined ( ) ;
382+ }
389383 } ) ;
390384
391385 /**
0 commit comments