diff --git a/packages/compass/src/main/auto-update-manager.spec.ts b/packages/compass/src/main/auto-update-manager.spec.ts index c3e52a92764..ac6c5c89433 100644 --- a/packages/compass/src/main/auto-update-manager.spec.ts +++ b/packages/compass/src/main/auto-update-manager.spec.ts @@ -86,6 +86,18 @@ describe('CompassAutoUpdateManager', function () { sandbox.stub(autoUpdater); }); + it('attaches OS metadata as query params to the update request URL', async () => { + const url = await CompassAutoUpdateManager.getUpdateCheckURL(); + + expect(url.searchParams.get('release')).to.exist; + + const isLinux = process.platform === 'linux'; + if (isLinux) { + expect(url.searchParams.get('os_linux_dist')).to.exist; + expect(url.searchParams.get('os_linux_release')).to.exist; + } + }); + it('should check for update and transition to update not available if backend returned nothing', async function () { const stub = sandbox .stub(CompassAutoUpdateManager, 'checkForUpdate') diff --git a/packages/compass/src/main/auto-update-manager.ts b/packages/compass/src/main/auto-update-manager.ts index 4d11e7b4f04..b96eab278d4 100644 --- a/packages/compass/src/main/auto-update-manager.ts +++ b/packages/compass/src/main/auto-update-manager.ts @@ -9,6 +9,7 @@ import autoUpdater, { supportsAutoupdater } from './auto-updater'; import fetch from 'node-fetch'; import dl from 'electron-dl'; import type { CompassApplication } from './application'; +import { getOsInfo } from '@mongodb-js/get-os-info'; const { log, mongoLogId, debug, track } = createLoggerAndTelemetry( 'COMPASS-AUTO-UPDATES' @@ -447,11 +448,24 @@ class CompassAutoUpdateManager { }; } - static getUpdateCheckURL() { + static async getUpdateCheckURL() { const { endpoint, product, channel, platform, arch, version } = this.autoUpdateOptions; + const { + os_release: release, + os_linux_dist, + os_linux_release, + } = await getOsInfo(); + const url = new URL( + `${endpoint}/api/v2/update/${product}/${channel}/${platform}-${arch}/${version}/check` + ); + + release && url.searchParams.set('release', release); + os_linux_dist && url.searchParams.set('os_linux_dist', os_linux_dist); + os_linux_release && + url.searchParams.set('os_linux_release', os_linux_release); - return `${endpoint}/api/v2/update/${product}/${channel}/${platform}-${arch}/${version}/check`; + return url; } static async checkForUpdate(): Promise<{ @@ -460,7 +474,7 @@ class CompassAutoUpdateManager { to: string; } | null> { try { - const response = await fetch(this.getUpdateCheckURL()); + const response = await fetch(await this.getUpdateCheckURL()); if (response.status !== 200) { return null; }