@@ -15,14 +15,25 @@ import {
1515} from '../workflows/dto/workflow-graph.dto' ;
1616import { WorkflowDefinition } from '../dsl/types' ;
1717import { UploadedFile } from '../storage/storage.service' ;
18+ import {
19+ formatDatabaseTarget ,
20+ getScriptDatabaseTarget ,
21+ readActiveInstance ,
22+ } from '@sentris/local-runtime' ;
1823
1924const runIntegration = process . env . RUN_BACKEND_INTEGRATION === 'true' ;
2025
21- const baseUrl =
22- process . env . BACKEND_BASE_URL ??
23- `http://localhost:${ process . env . BACKEND_PORT ?? process . env . PORT ?? '3211' } ` ;
26+ function resolveBackendBaseUrl ( ) : string {
27+ if ( process . env . BACKEND_BASE_URL ) return process . env . BACKEND_BASE_URL ;
28+
29+ const explicitPort = process . env . BACKEND_PORT ?? process . env . PORT ;
30+ if ( explicitPort ) return `http://localhost:${ explicitPort } ` ;
31+
32+ const activeInstance = readActiveInstance ( ) ;
33+ return `http://localhost:${ 3211 + Number ( activeInstance . instance ) * 100 } ` ;
34+ }
2435
25- const api = ( path : string ) => `${ baseUrl } ${ path } ` ;
36+ const api = ( path : string ) => `${ resolveBackendBaseUrl ( ) } ${ path } ` ;
2637
2738const normalizeNode = ( override : Partial < WorkflowNodeDto > = { } ) : WorkflowNodeDto => ( {
2839 id : override . id ?? 'node-1' ,
@@ -140,6 +151,13 @@ interface Component {
140151 // eslint-disable-next-line no-console
141152 console . log ( '🚀 Starting backend integration test setup...' ) ;
142153
154+ const databaseTarget = getScriptDatabaseTarget ( {
155+ overrideEnvVar : 'BACKEND_INTEGRATION_DATABASE_URL' ,
156+ } ) ;
157+ process . env . DATABASE_URL = databaseTarget . connectionString ;
158+ // eslint-disable-next-line no-console
159+ console . log ( formatDatabaseTarget ( databaseTarget ) ) ;
160+
143161 const { AppModule } = await import ( '../app.module' ) ;
144162
145163 // Create NestJS test application
@@ -151,9 +169,7 @@ interface Component {
151169 await app . init ( ) ;
152170
153171 // Initialize database connection for cleanup
154- const connectionString =
155- process . env . DATABASE_URL || 'postgresql://sentris:sentris@localhost:5433/sentris' ;
156- pool = new Pool ( { connectionString } ) ;
172+ pool = new Pool ( { connectionString : databaseTarget . connectionString } ) ;
157173 db = drizzle ( pool ) ;
158174
159175 // Initialize MinIO client
0 commit comments