cli: fix config path resolution for embedded-postgres detection
Resolve config paths relative to the target package directory instead of the workspace root in readDatabaseClient, matching the behavior of the rest of the config loading system. Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Made-with: Cursor Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Made-with: Cursor
This commit is contained in:
@@ -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),
|
||||
]),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user