11import { describe , expect , it } from 'bun:test' ;
22
3- import { PhasicClient } from '../../src/phasic' ;
4- import { createNodeWebSocketFactory } from '../../src/node ' ;
3+ // Native WebSocket is available in Node.js 22+, Bun, and browsers
4+ import { PhasicClient } from '../../src/index ' ;
55
6- function requireEnv ( name : string ) : string {
7- const v = process . env [ name ] ;
6+ function getEnv ( name : string , fallback ?: string ) : string | undefined {
7+ return process . env [ name ] ?? fallback ;
8+ }
9+
10+ function requireEnv ( name : string , altName ?: string ) : string {
11+ const v = process . env [ name ] ?? ( altName ? process . env [ altName ] : undefined ) ;
812 if ( ! v ) {
913 throw new Error (
1014 `Missing ${ name } . Create an API key in Settings → API Keys and run: ${ name } =<key> bun run test:integration` ,
@@ -13,21 +17,20 @@ function requireEnv(name: string): string {
1317 return v ;
1418}
1519
16- const describeIntegration =
17- process . env . VIBESDK_RUN_INTEGRATION_TESTS === '1' &&
18- process . env . VIBESDK_INTEGRATION_API_KEY
19- ? describe
20- : describe . skip ;
20+ // Support both VIBESDK_API_KEY (from .env) and VIBESDK_INTEGRATION_API_KEY
21+ const apiKeyAvailable = ! ! ( process . env . VIBESDK_API_KEY || process . env . VIBESDK_INTEGRATION_API_KEY ) ;
22+ const runIntegration = process . env . VIBESDK_RUN_INTEGRATION_TESTS === '1' || apiKeyAvailable ;
23+
24+ const describeIntegration = runIntegration ? describe : describe . skip ;
2125
2226function previewUrlFromState ( state : { previewUrl ?: string ; preview ?: { status : string ; previewURL ?: string } } ) : string | undefined {
2327 if ( state . preview ?. status === 'complete' && state . preview . previewURL ) return state . preview . previewURL ;
2428 return state . previewUrl ;
2529}
2630
2731describeIntegration ( 'SDK integration (local platform)' , ( ) => {
28- const apiKey = requireEnv ( 'VIBESDK_INTEGRATION_API_KEY' ) ;
29- const baseUrl = process . env . VIBESDK_INTEGRATION_BASE_URL ?? 'http://localhost:5173' ;
30- const wsFactory = createNodeWebSocketFactory ( ) ;
32+ const apiKey = requireEnv ( 'VIBESDK_API_KEY' , 'VIBESDK_INTEGRATION_API_KEY' ) ;
33+ const baseUrl = getEnv ( 'VIBESDK_BASE_URL' , getEnv ( 'VIBESDK_INTEGRATION_BASE_URL' , 'http://localhost:5173' ) ) as string ;
3134
3235 const fetchFn : typeof fetch = async ( input : RequestInfo | URL , init ?: RequestInit ) => {
3336 return await fetch ( input , init ) ;
@@ -56,7 +59,6 @@ describeIntegration('SDK integration (local platform)', () => {
5659 baseUrl,
5760 apiKey,
5861 fetchFn,
59- webSocketFactory : wsFactory ,
6062 } ) ;
6163
6264 console . log ( '[integration] build: creating agent' ) ;
0 commit comments