backend-app-api: add test for circular module dependency check
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -250,4 +250,48 @@ describe('BackendInitializer', () => {
|
||||
"Module 'mod' for plugin 'test' is already registered",
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject modules with circular dependencies', async () => {
|
||||
const extA = createExtensionPoint<string>({ id: 'a' });
|
||||
const extB = createExtensionPoint<string>({ id: 'b' });
|
||||
const init = new BackendInitializer(
|
||||
new ServiceRegistry([
|
||||
rootLifecycleServiceFactory(),
|
||||
createServiceFactory({
|
||||
service: coreServices.rootLogger,
|
||||
deps: {},
|
||||
factory: () => new MockLogger(),
|
||||
})(),
|
||||
]),
|
||||
);
|
||||
init.add(
|
||||
createBackendModule({
|
||||
pluginId: 'test',
|
||||
moduleId: 'modA',
|
||||
register(reg) {
|
||||
reg.registerExtensionPoint(extA, 'a');
|
||||
reg.registerInit({
|
||||
deps: { ext: extB },
|
||||
async init() {},
|
||||
});
|
||||
},
|
||||
})(),
|
||||
);
|
||||
init.add(
|
||||
createBackendModule({
|
||||
pluginId: 'test',
|
||||
moduleId: 'modB',
|
||||
register(reg) {
|
||||
reg.registerExtensionPoint(extB, 'b');
|
||||
reg.registerInit({
|
||||
deps: { ext: extA },
|
||||
async init() {},
|
||||
});
|
||||
},
|
||||
})(),
|
||||
);
|
||||
await expect(init.start()).rejects.toThrow(
|
||||
"Circular dependency detected for modules of plugin 'test', 'modA' -> 'modB' -> 'modA'",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ import { EnumerableServiceHolder, ServiceOrExtensionPoint } from './types';
|
||||
// Direct internal import to avoid duplication
|
||||
// eslint-disable-next-line @backstage/no-forbidden-package-imports
|
||||
import { InternalBackendFeature } from '@backstage/backend-plugin-api/src/wiring/types';
|
||||
import { ForwardedError, InputError } from '@backstage/errors';
|
||||
import { ForwardedError, ConflictError } from '@backstage/errors';
|
||||
import { featureDiscoveryServiceRef } from '@backstage/backend-plugin-api/alpha';
|
||||
import { DependencyTree } from '../lib/DependencyTree';
|
||||
|
||||
@@ -225,7 +225,7 @@ export class BackendInitializer {
|
||||
);
|
||||
const circular = tree.detectCircularDependency();
|
||||
if (circular) {
|
||||
throw new InputError(
|
||||
throw new ConflictError(
|
||||
`Circular dependency detected for modules of plugin '${pluginId}', '${circular.join(
|
||||
"' -> '",
|
||||
)}'`,
|
||||
|
||||
Reference in New Issue
Block a user