Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tests to ensure registered SO types aren't removed #207142

Merged
merged 7 commits into from
Jan 22, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/type

/**
* Types that are no longer registered and need to be removed
* As of 8.8, no new types are allowed to be removed.
* Removing saved object types is not backward compatible
*/
export const REMOVED_TYPES: string[] = [
'apm-services-telemetry',
Expand Down
1 change: 1 addition & 0 deletions src/core/packages/saved-objects/server-internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
MIGRATION_CLIENT_OPTIONS,
SavedObjectsService,
CoreSavedObjectsRouteHandlerContext,
SAVED_OBJECT_TYPES_COUNT,
} from './src';
export type {
InternalSavedObjectsServiceStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export type {
InternalSavedObjectsRequestHandlerContext,
InternalSavedObjectRouter,
} from './internal_types';
export { SAVED_OBJECT_TYPES_COUNT } from './object_types';
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
*/

export { registerCoreObjectTypes } from './registration';

// set minimum number of registered saved objects to ensure no object types are removed after 8.8
// declared in internal implementation exclicilty to prevent unintended changes.
export const SAVED_OBJECT_TYPES_COUNT = 127 as const;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import type { SavedObjectsType } from './saved_objects_type';

/**
* Registry holding information about all the registered {@link SavedObjectsType | saved object types}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { SAVED_OBJECT_TYPES_COUNT } from '@kbn/core-saved-objects-server-internal';

describe('checking migration metadata changes on all registered SO types', () => {
let esServer: TestElasticsearchUtils;
Expand Down Expand Up @@ -46,6 +47,8 @@ describe('checking migration metadata changes on all registered SO types', () =>
// This test is meant to fail when any change is made in registered types that could potentially impact the SO migration.
// Just update the snapshot by running this test file via jest_integration with `-u` and push the update.
// The intent is to trigger a code review from the Core team to review the SO type changes.
// The number of types in the hashMap should never be reduced, it can only increase.
// Removing saved object types is forbidden after 8.8.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are ment to warn against removing saved object types for anyone who ends up having to make changes to the tests to get them to pass.

it('detecting migration related changes in registered types', () => {
const allTypes = typeRegistry.getAllTypes();

Expand Down Expand Up @@ -185,5 +188,6 @@ describe('checking migration metadata changes on all registered SO types', () =>
"workplace_search_telemetry": "52b32b47ee576f554ac77cb1d5896dfbcfe9a1fb",
}
`);
expect(Object.keys(hashMap).length).toEqual(SAVED_OBJECT_TYPES_COUNT);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
preset: '@kbn/test/jest_integration',
rootDir: '../../../../..',
roots: [
'<rootDir>/src/core/server/integration_tests/saved_objects/registration',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the type_registration to its own subfolder because it was getting "lost" within group3 in the migrations integration tests.

'<rootDir>/src/core/server/integration_tests/saved_objects/routes',
'<rootDir>/src/core/server/integration_tests/saved_objects/service',
'<rootDir>/src/core/server/integration_tests/saved_objects/validation',
Expand Down
Loading