-
Notifications
You must be signed in to change notification settings - Fork 58
feat: refactor ddp publication registration into a PublicationRegistry #1785
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
Open
Julusian
wants to merge
2
commits into
Sofie-Automation:main
Choose a base branch
from
SuperFlyTV:refactor/ddp-publication-registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,965
−1,890
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { MethodRegistry } from '../../server/methodRegistry' | ||
| import { registerAllApiMethods } from '../../server/methodRegistrations' | ||
|
|
||
| /** | ||
| * Test helper: register all API methods on a fresh MethodRegistry and apply them to the (mock) | ||
| * Meteor server, mirroring what `main.ts` does at startup. | ||
| * | ||
| * Call this in suites that exercise Meteor methods (via `MeteorCall`, `Meteor.callAsync`, or by | ||
| * spying on `MeteorMock.mockMethods`). It is needed because the production registration now only | ||
| * runs explicitly from `main.ts`, rather than as an import-time side effect of each API file. | ||
| */ | ||
| export function registerAllMethodsForTest(): MethodRegistry { | ||
| const registry = new MethodRegistry() | ||
| registerAllApiMethods(registry) | ||
| registry.applyToMeteor() | ||
| return registry | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { PublicationRegistry } from '../../server/publicationRegistry' | ||
| import { registerAllPublications } from '../../server/publicationRegistrations' | ||
|
|
||
| /** | ||
| * Test helper: register all DDP publications on a fresh PublicationRegistry and apply them to the | ||
| * (mock) Meteor server, mirroring what `main.ts` does at startup. | ||
| * | ||
| * Call this in suites that exercise Meteor subscriptions. It is needed because the production | ||
| * registration now only runs explicitly from `main.ts`, rather than as an import-time side effect of | ||
| * each publication file. | ||
| */ | ||
| export function registerAllPublicationsForTest(): PublicationRegistry { | ||
| const registry = new PublicationRegistry() | ||
| registerAllPublications(registry) | ||
| registry.applyToMeteor() | ||
| return registry | ||
| } |
199 changes: 199 additions & 0 deletions
199
meteor/server/__tests__/__snapshots__/methodRegistry.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing | ||
|
|
||
| exports[`MethodRegistry the full set of registered method names is stable (drift guard) 1`] = ` | ||
| [ | ||
| "blueprint.assignSystem", | ||
| "client.callBackgroundPeripheralDeviceFunction", | ||
| "client.callPeripheralDeviceAction", | ||
| "client.callPeripheralDeviceFunction", | ||
| "client.clientErrorReport", | ||
| "client.clientLogNotification", | ||
| "client.clientLogger", | ||
| "debug_clearAllResetInstances", | ||
| "debug_forceClearAllCaches", | ||
| "debug_playlistRunBlueprints", | ||
| "debug_previewTrigger", | ||
| "debug_regenerateNextPartInstance", | ||
| "debug_removeAllPlaylists", | ||
| "debug_removePlaylist", | ||
| "debug_segmentRunBlueprints", | ||
| "debug_syncPlayheadInfinitesForNextPartInstance", | ||
| "debug_updateTimeline", | ||
| "externalMessages.remove", | ||
| "externalMessages.retry", | ||
| "externalMessages.toggleHold", | ||
| "migration.fixupConfigForShowStyleBase", | ||
| "migration.fixupConfigForStudio", | ||
| "migration.forceMigration", | ||
| "migration.getMigrationStatus", | ||
| "migration.ignoreFixupConfigForShowStyleBase", | ||
| "migration.ignoreFixupConfigForStudio", | ||
| "migration.resetDatabaseVersions", | ||
| "migration.runMigration", | ||
| "migration.runUpgradeForCoreSystem", | ||
| "migration.runUpgradeForShowStyleBase", | ||
| "migration.runUpgradeForStudio", | ||
| "migration.validateConfigForShowStyleBase", | ||
| "migration.validateConfigForStudio", | ||
| "mongo.insert", | ||
| "mongo.remove", | ||
| "mongo.update", | ||
| "peripheralDevice.functionReply", | ||
| "peripheralDevice.getPeripheralDevice", | ||
| "peripheralDevice.initialize", | ||
| "peripheralDevice.input.inputDeviceTrigger", | ||
| "peripheralDevice.killProcess", | ||
| "peripheralDevice.mediaScanner.clearMediaObjectCollection", | ||
| "peripheralDevice.mediaScanner.getMediaObjectRevisions", | ||
| "peripheralDevice.mediaScanner.updateMediaObject", | ||
| "peripheralDevice.mos.roCreate", | ||
| "peripheralDevice.mos.roDelete", | ||
| "peripheralDevice.mos.roFullStory", | ||
| "peripheralDevice.mos.roItemDelete", | ||
| "peripheralDevice.mos.roItemInsert", | ||
| "peripheralDevice.mos.roItemMove", | ||
| "peripheralDevice.mos.roItemReplace", | ||
| "peripheralDevice.mos.roItemStatus", | ||
| "peripheralDevice.mos.roItemSwap", | ||
| "peripheralDevice.mos.roMetadata", | ||
| "peripheralDevice.mos.roReadyToAir", | ||
| "peripheralDevice.mos.roReplace", | ||
| "peripheralDevice.mos.roStatus", | ||
| "peripheralDevice.mos.roStoryDelete", | ||
| "peripheralDevice.mos.roStoryInsert", | ||
| "peripheralDevice.mos.roStoryMove", | ||
| "peripheralDevice.mos.roStoryReplace", | ||
| "peripheralDevice.mos.roStoryStatus", | ||
| "peripheralDevice.mos.roStorySwap", | ||
| "peripheralDevice.packageManager.fetchPackageInfoMetadata", | ||
| "peripheralDevice.packageManager.removeAllExpectedPackageWorkStatusOfDevice", | ||
| "peripheralDevice.packageManager.removeAllPackageContainerPackageStatusesOfDevice", | ||
| "peripheralDevice.packageManager.removeAllPackageContainerStatusesOfDevice", | ||
| "peripheralDevice.packageManager.removePackageInfo", | ||
| "peripheralDevice.packageManager.updateExpectedPackageWorkStatuses", | ||
| "peripheralDevice.packageManager.updatePackageContainerPackageStatuses", | ||
| "peripheralDevice.packageManager.updatePackageContainerStatuses", | ||
| "peripheralDevice.packageManager.updatePackageInfo", | ||
| "peripheralDevice.ping", | ||
| "peripheralDevice.pingWithCommand", | ||
| "peripheralDevice.playlist.playlistGet", | ||
| "peripheralDevice.playout.playbackChanged", | ||
| "peripheralDevice.playout.reportExternalEvents", | ||
| "peripheralDevice.removePeripheralDevice", | ||
| "peripheralDevice.reportResolveDone", | ||
| "peripheralDevice.rundown.partCreate", | ||
| "peripheralDevice.rundown.partDelete", | ||
| "peripheralDevice.rundown.partUpdate", | ||
| "peripheralDevice.rundown.rundownCreate", | ||
| "peripheralDevice.rundown.rundownDelete", | ||
| "peripheralDevice.rundown.rundownGet", | ||
| "peripheralDevice.rundown.rundownList", | ||
| "peripheralDevice.rundown.rundownMetaDataUpdate", | ||
| "peripheralDevice.rundown.rundownUpdate", | ||
| "peripheralDevice.rundown.segmentCreate", | ||
| "peripheralDevice.rundown.segmentDelete", | ||
| "peripheralDevice.rundown.segmentGet", | ||
| "peripheralDevice.rundown.segmentRanksUpdate", | ||
| "peripheralDevice.rundown.segmentUpdate", | ||
| "peripheralDevice.spreadsheet.requestUserAuthToken", | ||
| "peripheralDevice.spreadsheet.storeAccessToken", | ||
| "peripheralDevice.status", | ||
| "peripheralDevice.testMethod", | ||
| "peripheralDevice.timeline.setTimelineTriggerTime", | ||
| "peripheralDevice.unInitialize", | ||
| "playout.shouldUpdateStudioBaseline", | ||
| "playout.updateStudioBaseline", | ||
| "rundown.rundownPlaylistNeedsResync", | ||
| "rundownLayout.createRundownLayout", | ||
| "rundownLayout.removeRundownLayout", | ||
| "showstyles.getCreateAdlibTestingRundownOptions", | ||
| "showstyles.importShowStyleVariant", | ||
| "showstyles.importShowStyleVariantAsNew", | ||
| "showstyles.insertBlueprint", | ||
| "showstyles.insertShowStyleBase", | ||
| "showstyles.insertShowStyleVariant", | ||
| "showstyles.removeBlueprint", | ||
| "showstyles.removeShowStyleBase", | ||
| "showstyles.removeShowStyleVariant", | ||
| "showstyles.reorderShowStyleVariant", | ||
| "snapshot.debugSnaphot", | ||
| "snapshot.removeSnaphot", | ||
| "snapshot.restoreSnaphot", | ||
| "snapshot.rundownPlaylistSnapshot", | ||
| "snapshot.systemSnapshot", | ||
| "studio.assignConfigToPeripheralDevice", | ||
| "studio.insertStudio", | ||
| "studio.removeStudio", | ||
| "system.cleanupIndexes", | ||
| "system.cleanupOldData", | ||
| "system.doSystemBenchmark", | ||
| "system.generateSingleUseToken", | ||
| "system.getTranslationBundle", | ||
| "system.runCronjob", | ||
| "systemStatus.getDebugStates", | ||
| "systemStatus.getSystemStatus", | ||
| "systemTime.determineDiffTime", | ||
| "systemTime.getTime", | ||
| "systemTime.getTimeDiff", | ||
| "triggeredActions.createTriggeredActions", | ||
| "triggeredActions.removeTriggeredActions", | ||
| "user.getUserPermissions", | ||
| "userAction.DEBUG_crashStudioWorker", | ||
| "userAction.activate", | ||
| "userAction.activateAdlibTestingMode", | ||
| "userAction.activateHold", | ||
| "userAction.baselineAdLibPieceStart", | ||
| "userAction.blurred", | ||
| "userAction.bucketAdlibImport", | ||
| "userAction.bucketAdlibStart", | ||
| "userAction.bucketsModifyBucketAdLib", | ||
| "userAction.bucketsModifyBucketAdLibAction", | ||
| "userAction.bucketsSaveActionIntoBucket", | ||
| "userAction.clearQuickLoop", | ||
| "userAction.createAdlibTestingRundownForShowStyleVariant", | ||
| "userAction.createBucket", | ||
| "userAction.deactivate", | ||
| "userAction.disableNextPiece", | ||
| "userAction.emptyBucket", | ||
| "userAction.executeAction", | ||
| "userAction.executeUserChangeOperation", | ||
| "userAction.focused", | ||
| "userAction.forceResetAndActivate", | ||
| "userAction.ingest.regenerateRundownPlaylist", | ||
| "userAction.modifyBucket", | ||
| "userAction.moveNext", | ||
| "userAction.moveRundown", | ||
| "userAction.packagemanager.abortExpectation", | ||
| "userAction.packagemanager.restartAllExpectations", | ||
| "userAction.packagemanager.restartExpectation", | ||
| "userAction.packagemanager.restartPackageContainer", | ||
| "userAction.pieceSetInOutPoints", | ||
| "userAction.pieceTakeNow", | ||
| "userAction.prepareForBroadcast", | ||
| "userAction.queueNextSegment", | ||
| "userAction.removeBucket", | ||
| "userAction.removeBucketAdLib", | ||
| "userAction.removeBucketAdLibAction", | ||
| "userAction.removeRundown", | ||
| "userAction.removeRundownPlaylist", | ||
| "userAction.resetAndActivate", | ||
| "userAction.resetRundownPlaylist", | ||
| "userAction.restoreRundownOrder", | ||
| "userAction.resyncRundown", | ||
| "userAction.resyncRundownPlaylist", | ||
| "userAction.saveEvaluation", | ||
| "userAction.segmentAdLibPieceStart", | ||
| "userAction.setNext", | ||
| "userAction.setNextSegment", | ||
| "userAction.setQuickLoopEnd", | ||
| "userAction.setQuickLoopStart", | ||
| "userAction.sourceLayerOnPartStop", | ||
| "userAction.sourceLayerStickyPieceStart", | ||
| "userAction.storeRundownSnapshot", | ||
| "userAction.switchRouteSet", | ||
| "userAction.system.disablePeripheralSubDevice", | ||
| "userAction.system.restartCore", | ||
| "userAction.take", | ||
| "userAction.unsyncRundown", | ||
| ] | ||
| `; |
76 changes: 76 additions & 0 deletions
76
meteor/server/__tests__/__snapshots__/publicationRegistry.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing | ||
|
|
||
| exports[`PublicationRegistry the full set of registered publication names is stable (drift guard) 1`] = ` | ||
| [ | ||
| "adLibActions", | ||
| "adLibActionsForPart", | ||
| "adLibPieces", | ||
| "adLibPiecesForPart", | ||
| "blueprints", | ||
| "bucketAdLibActions", | ||
| "bucketAdLibPieces", | ||
| "buckets", | ||
| "coreSystem", | ||
| "deviceTriggersPreview", | ||
| "evaluations", | ||
| "expectedPackageWorkStatuses", | ||
| "expectedPackages", | ||
| "expectedPlayoutItemsForDevice", | ||
| "externalEventSubscriptionsForDevice", | ||
| "externalMessageQueue", | ||
| "ingestDataCache", | ||
| "ingestDeviceRundownStatus", | ||
| "ingestDeviceRundownStatusTestTool", | ||
| "mappingsForDevice", | ||
| "mappingsForStudio", | ||
| "mountedTriggersForDevice", | ||
| "mountedTriggersForDevicePreview", | ||
| "notificationsForRundown", | ||
| "notificationsForRundownPlaylist", | ||
| "packageContainerStatuses", | ||
| "packageInfos", | ||
| "packageManagerExpectedPackages", | ||
| "packageManagerPackageContainers", | ||
| "packageManagerPlayoutContext", | ||
| "partInstances", | ||
| "partInstancesSimple", | ||
| "parts", | ||
| "peripheralDeviceCommands", | ||
| "peripheralDeviceForDevice", | ||
| "peripheralDevices", | ||
| "peripheralDevicesAndSubDevices", | ||
| "pieceInstances", | ||
| "pieceInstancesSimple", | ||
| "pieces", | ||
| "piecesInfiniteStartingBefore", | ||
| "rundownBaselineAdLibActions", | ||
| "rundownBaselineAdLibPieces", | ||
| "rundownLayouts", | ||
| "rundownPlaylistForStudio", | ||
| "rundownPlaylists", | ||
| "rundownsForDevice", | ||
| "rundownsInPlaylists", | ||
| "rundownsWithShowStyleBases", | ||
| "segments", | ||
| "showStyleBases", | ||
| "showStyleVariants", | ||
| "snapshots", | ||
| "studios", | ||
| "timelineDatastore", | ||
| "timelineDatastoreForDevice", | ||
| "timelineForDevice", | ||
| "timelineForStudio", | ||
| "translationsBundles", | ||
| "triggeredActions", | ||
| "uiBlueprintUpgradeStatuses", | ||
| "uiBucketContentStatuses", | ||
| "uiPartInstances", | ||
| "uiParts", | ||
| "uiPieceContentStatuses", | ||
| "uiSegmentPartNotes", | ||
| "uiShowStyleBase", | ||
| "uiStudio", | ||
| "uiTriggeredActions", | ||
| "userActionsLog", | ||
| ] | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { MethodApiRegistration, MethodRegistry } from '../methodRegistry' | ||
| import { METHOD_REGISTRATIONS, registerAllApiMethods } from '../methodRegistrations' | ||
|
|
||
| describe('MethodRegistry', () => { | ||
| test('registers all API methods without error', () => { | ||
| const registry = new MethodRegistry() | ||
| // registerApi throws if a class method has no matching wire name, so this is itself an assertion | ||
| // that every implemented method maps to an enum entry (the historical behaviour). | ||
| expect(() => registerAllApiMethods(registry)).not.toThrow() | ||
| }) | ||
|
|
||
| test('registered names are unique and only use known wire names', () => { | ||
| const registry = new MethodRegistry() | ||
| registerAllApiMethods(registry) | ||
| const names = registry.getAllMethodNames() | ||
|
|
||
| // No duplicate registrations across all APIs | ||
| expect(new Set(names).size).toBe(names.length) | ||
|
|
||
| // Every non-debug registered name must be a value from one of the method-name enums. | ||
| // (Debug methods are not enum-backed and are checked separately.) | ||
| const enumWireNames = new Set<string>() | ||
| for (const reg of Object.values<MethodApiRegistration<any>>(METHOD_REGISTRATIONS)) { | ||
| for (const wireName of Object.values<string>(reg.methods)) enumWireNames.add(wireName) | ||
| } | ||
| for (const name of names) { | ||
| if (registry.isDebugMethod(name)) continue | ||
| expect(enumWireNames.has(name)).toBe(true) | ||
| } | ||
|
|
||
| // A handful of representative names must be present, guarding against an API silently | ||
| // dropping out of the registry. | ||
| expect(names).toEqual( | ||
| expect.arrayContaining([ | ||
| 'userAction.take', | ||
| 'playout.updateStudioBaseline', | ||
| 'peripheralDevice.initialize', | ||
| 'system.cleanupIndexes', | ||
| ]) | ||
| ) | ||
| }) | ||
|
|
||
| test('the full set of registered method names is stable (drift guard)', () => { | ||
| const registry = new MethodRegistry() | ||
| registerAllApiMethods(registry) | ||
| // If this snapshot changes, a method's wire name was added, removed or renamed. That must be a | ||
| // deliberate change reviewed against the clients that depend on these exact names. | ||
| expect([...registry.getAllMethodNames()].sort()).toMatchSnapshot() | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.