Merge pull request #33914 from backstage/cursor/fix-embedded-postgres-config-path-resolution

cli: fix config path resolution for embedded-postgres detection
This commit is contained in:
Patrik Oldsberg
2026-04-15 11:32:08 +02:00
committed by GitHub
4 changed files with 35 additions and 3 deletions
@@ -0,0 +1,5 @@
---
'@backstage/cli-module-build': patch
---
Fixed config path resolution for the embedded-postgres database client detection to resolve paths relative to the target package directory rather than the workspace root.
+1
View File
@@ -0,0 +1 @@
Fix config path resolution for embedded-postgres detection in `repo start`
@@ -50,10 +50,11 @@ jest.mock('ctrlc-windows', () => ({
}));
const mockToConfig = jest.fn();
const mockConfigSourcesDefault = jest.fn().mockReturnValue({});
jest.mock('@backstage/config-loader', () => ({
ConfigSources: {
default: () => ({}),
default: (...args: any[]) => mockConfigSourcesDefault(...args),
toConfig: (...args: any[]) => mockToConfig(...args),
},
}));
@@ -216,6 +217,26 @@ describe('runBackend', () => {
});
});
it('should resolve config paths relative to targetDir', async () => {
mockToConfig.mockResolvedValue({
close: jest.fn(),
getOptionalString: () => undefined,
});
runBackend({
entry: 'src/index',
targetDir: '/root/packages/backend',
configPaths: ['../../config/local.yaml'],
});
await jest.advanceTimersByTimeAsync(100);
expect(mockConfigSourcesDefault).toHaveBeenCalledWith(
expect.objectContaining({
argv: ['--config', '/root/config/local.yaml'],
}),
);
});
it('should not start embedded DB for other database clients', async () => {
mockToConfig.mockResolvedValue({
close: jest.fn(),
@@ -68,7 +68,10 @@ export async function runBackend(options: RunBackendOptions) {
let embeddedDb: Awaited<ReturnType<typeof startEmbeddedDb>> | undefined;
const dbClient = await readDatabaseClient(options.configPaths);
const dbClient = await readDatabaseClient(
options.configPaths,
options.targetDir,
);
if (dbClient === 'embedded-postgres') {
embeddedDb = await startEmbeddedDb();
extraEnv.APP_CONFIG_backend_database = JSON.stringify({
@@ -220,14 +223,16 @@ export async function runBackend(options: RunBackendOptions) {
async function readDatabaseClient(
configPaths?: string[],
targetDir?: string,
): Promise<string | undefined> {
const rootDir = targetPaths.rootDir;
const configBaseDir = targetDir ?? rootDir;
const source = ConfigSources.default({
rootDir,
allowMissingDefaultConfig: true,
argv: (configPaths ?? []).flatMap(p => [
'--config',
isAbsolutePath(p) ? p : resolvePath(rootDir, p),
isAbsolutePath(p) ? p : resolvePath(configBaseDir, p),
]),
});