Skip to content

Commit 55848e2

Browse files
committed
fix: centralize local runtime targets
Signed-off-by: zebbern <185730623+zebbern@users.noreply.github.com>
1 parent bdc0489 commit 55848e2

16 files changed

Lines changed: 404 additions & 268 deletions

File tree

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@opensearch-project/opensearch": "^3.5.1",
3636
"@sentris/backend-client": "workspace:*",
3737
"@sentris/component-sdk": "workspace:*",
38+
"@sentris/local-runtime": "workspace:*",
3839
"@sentris/shared": "workspace:*",
3940
"@sentris/worker": "workspace:*",
4041
"@temporalio/client": "^1.14.1",

backend/scripts/__tests__/script-database-target.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,26 @@ describe('script database target resolver', () => {
201201
);
202202
}
203203
});
204+
205+
it('prevents DB-backed integration tests from falling back to the legacy local database', () => {
206+
const integrationTestFiles = [
207+
join(repoRoot, 'backend', 'src', '__tests__', 'backend-integration.test.ts'),
208+
join(repoRoot, 'worker', 'src', '__tests__', 'worker-integration.test.ts'),
209+
join(repoRoot, 'worker', 'src', 'adapters', '__tests__', 'file-storage.adapter.test.ts'),
210+
];
211+
212+
for (const file of integrationTestFiles) {
213+
const source = readFileSync(file, 'utf-8');
214+
expect(source, `${file} should use the shared script database resolver`).toContain(
215+
'getScriptDatabaseTarget',
216+
);
217+
expect(
218+
source,
219+
`${file} should not read DATABASE_URL directly for its fallback`,
220+
).not.toContain('process.env.DATABASE_URL ||');
221+
expect(source, `${file} should not fall back to the legacy sentris database`).not.toContain(
222+
'postgresql://sentris:sentris@localhost:5433/sentris',
223+
);
224+
}
225+
});
204226
});

backend/src/__tests__/backend-integration.test.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,25 @@ import {
1515
} from '../workflows/dto/workflow-graph.dto';
1616
import { WorkflowDefinition } from '../dsl/types';
1717
import { UploadedFile } from '../storage/storage.service';
18+
import {
19+
formatDatabaseTarget,
20+
getScriptDatabaseTarget,
21+
readActiveInstance,
22+
} from '@sentris/local-runtime';
1823

1924
const 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

2738
const 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

backend/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
{
2828
"path": "../packages/component-sdk"
2929
},
30+
{
31+
"path": "../packages/local-runtime"
32+
},
3033
{
3134
"path": "../packages/backend-client"
3235
},

bun.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"packages/backend-client",
1111
"packages/component-sdk",
1212
"packages/contracts",
13+
"packages/local-runtime",
1314
"packages/shared"
1415
],
1516
"scripts": {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@sentris/local-runtime",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"packageManager": "bun@1.3.10",
6+
"main": "src/index.ts",
7+
"types": "src/index.ts",
8+
"license": "MIT",
9+
"scripts": {
10+
"typecheck": "tsc --noEmit"
11+
},
12+
"devDependencies": {
13+
"@types/node": "^25.1.0",
14+
"bun-types": "^1.3.6",
15+
"typescript": "^5.9.3"
16+
}
17+
}

0 commit comments

Comments
 (0)