(
params: {
appDir?: string;
httpPort?: number;
mcpPort?: number;
holabossUserId?: string;
workspaceId?: string;
resolvedApp?: ResolvedApplicationRuntime;
integrationEnv?: NodeJS.ProcessEnv;
}
)
| 340 | } |
| 341 | |
| 342 | function buildShellLifecycleEnv( |
| 343 | params: { |
| 344 | appDir?: string; |
| 345 | httpPort?: number; |
| 346 | mcpPort?: number; |
| 347 | holabossUserId?: string; |
| 348 | workspaceId?: string; |
| 349 | resolvedApp?: ResolvedApplicationRuntime; |
| 350 | integrationEnv?: NodeJS.ProcessEnv; |
| 351 | } |
| 352 | ): NodeJS.ProcessEnv { |
| 353 | const env: NodeJS.ProcessEnv = params.appDir ? buildAppSetupEnv(params.appDir) : { ...process.env }; |
| 354 | if (params.integrationEnv) { |
| 355 | Object.assign(env, params.integrationEnv); |
| 356 | } |
| 357 | if (params.httpPort !== undefined) { |
| 358 | env.PORT = String(params.httpPort); |
| 359 | } |
| 360 | if (params.mcpPort !== undefined) { |
| 361 | env.MCP_PORT = String(params.mcpPort); |
| 362 | } |
| 363 | if ( |
| 364 | params.holabossUserId && |
| 365 | params.resolvedApp && |
| 366 | params.resolvedApp.envContract.includes("HOLABOSS_USER_ID") |
| 367 | ) { |
| 368 | env.HOLABOSS_USER_ID = params.holabossUserId; |
| 369 | } |
| 370 | if ( |
| 371 | params.workspaceId && |
| 372 | params.resolvedApp && |
| 373 | params.resolvedApp.envContract.includes("HOLABOSS_WORKSPACE_ID") && |
| 374 | !env.HOLABOSS_WORKSPACE_ID |
| 375 | ) { |
| 376 | env.HOLABOSS_WORKSPACE_ID = params.workspaceId; |
| 377 | } |
| 378 | if ( |
| 379 | params.workspaceId && |
| 380 | params.resolvedApp && |
| 381 | params.resolvedApp.envContract.includes("WORKSPACE_DB_PATH") && |
| 382 | !env.WORKSPACE_DB_PATH |
| 383 | ) { |
| 384 | try { |
| 385 | // ensureWorkspaceDataDb() materializes the file with WAL + the |
| 386 | // _workspace_meta anchor row before the app process spawns. This |
| 387 | // closes the race where workspace-level data tools ran before |
| 388 | // any app had called getDb() and saw a missing file even though |
| 389 | // the app was about to write. |
| 390 | const dataDbPath = ensureWorkspaceDataDb(workspaceDirForId(params.workspaceId)); |
| 391 | env.WORKSPACE_DB_PATH = dataDbPath; |
| 392 | maybeApplyAppSchema(params.resolvedApp, dataDbPath); |
| 393 | } catch { |
| 394 | // sanitizeWorkspaceId throws on invalid ids; the caller will surface |
| 395 | // the underlying validation error elsewhere — don't crash env build. |
| 396 | } |
| 397 | } |
| 398 | return env; |
| 399 | } |
no test coverage detected