fix(desktop): prevent updates to unsupported macOS versions (#12115)

This commit is contained in:
Jasper
2026-09-16 16:06:47 +00:00
committed by GitHub
parent 2f1ae3ccaf
commit 9915fda42f
8 changed files with 429 additions and 2 deletions
+10 -1
View File
@@ -292,6 +292,13 @@ jobs:
run: node scripts/verify-mac-update-resources.js "$APP_PATH"
working-directory: ui/desktop
- name: Record macOS update requirements
env:
APP_PATH: ${{ inputs.target == 'x86_64-apple-darwin' && 'out/Goose-darwin-x64/Goose.app' || 'out/Goose-darwin-arm64/Goose.app' }}
METADATA_PATH: ${{ inputs.target == 'x86_64-apple-darwin' && 'out/Goose-darwin-x64/Goose_intel_mac.zip.macos.json' || 'out/Goose-darwin-arm64/Goose.zip.macos.json' }}
run: node scripts/mac-update-requirements.js "$APP_PATH" "$METADATA_PATH"
working-directory: ui/desktop
- name: Clean up signing keychain
if: always()
run: |
@@ -309,7 +316,9 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ inputs.target == 'x86_64-apple-darwin' && 'Goose-darwin-x64' || 'Goose-darwin-arm64' }}
path: ${{ inputs.target == 'x86_64-apple-darwin' && 'ui/desktop/out/Goose-darwin-x64/Goose_intel_mac.zip' || 'ui/desktop/out/Goose-darwin-arm64/Goose.zip' }}
path: |
${{ inputs.target == 'x86_64-apple-darwin' && 'ui/desktop/out/Goose-darwin-x64/Goose_intel_mac.zip' || 'ui/desktop/out/Goose-darwin-arm64/Goose.zip' }}
${{ inputs.target == 'x86_64-apple-darwin' && 'ui/desktop/out/Goose-darwin-x64/Goose_intel_mac.zip.macos.json' || 'ui/desktop/out/Goose-darwin-arm64/Goose.zip.macos.json' }}
if-no-files-found: error
overwrite: true
+4
View File
@@ -372,6 +372,10 @@ jobs:
run: source ../../bin/activate-hermit && pnpm run test:run
working-directory: ui/desktop
- name: Test macOS update manifests
run: source ../../bin/activate-hermit && node --test scripts/mac-update-requirements.test.cjs
working-directory: ui/desktop
desktop-updater-install:
name: Test Desktop Updater Install (${{ matrix.os }})
runs-on: ${{ matrix.os }}
+3 -1
View File
@@ -131,7 +131,6 @@ jobs:
merge-multiple: true
- name: Generate macOS update manifest
if: ${{ env.ENABLE_MAC_NATIVE_AUTO_UPDATE == 'true' }}
run: node ui/desktop/scripts/generate-mac-update-manifest.js --version "${GITHUB_REF_NAME}" --directory .
- name: Attest macOS update manifest
@@ -152,6 +151,7 @@ jobs:
*.rpm
*.flatpak
download_cli.sh
mac-update-requirements.json
# Create/update the versioned release
- name: Release versioned
@@ -167,6 +167,7 @@ jobs:
*.rpm
*.flatpak
download_cli.sh
mac-update-requirements.json
allowUpdates: true
omitBody: true
omitPrereleaseDuringUpdate: true
@@ -187,6 +188,7 @@ jobs:
*.rpm
*.flatpak
download_cli.sh
mac-update-requirements.json
allowUpdates: true
omitBody: true
omitPrereleaseDuringUpdate: true
@@ -3,6 +3,7 @@
const crypto = require('node:crypto');
const fs = require('node:fs');
const path = require('node:path');
const { macUpdateRequirements } = require('./mac-update-requirements');
function usage() {
console.error(
@@ -74,6 +75,24 @@ function writeManifest({ directory, version }) {
},
];
const requirements = files.map(({ sourceName }) => {
const metadata = JSON.parse(
fs.readFileSync(path.join(directory, `${sourceName}.macos.json`), 'utf8')
);
return macUpdateRequirements(metadata.minimumMacOSVersion, metadata.minimumMacOSVersion);
});
const minimum = requirements.reduce((highest, current) =>
Number(current.minimumSystemVersion.split('.')[0]) >
Number(highest.minimumSystemVersion.split('.')[0])
? current
: highest
);
fs.writeFileSync(
path.join(directory, 'mac-update-requirements.json'),
`${JSON.stringify({ version, ...minimum })}\n`
);
const entries = files.map(({ sourceName, updateName }) => {
const sourcePath = path.join(directory, sourceName);
const updatePath = path.join(directory, updateName);
@@ -89,6 +108,7 @@ function writeManifest({ directory, version }) {
const manifest = [
`version: ${yamlString(version)}`,
`minimumSystemVersion: ${yamlString(minimum.minimumSystemVersion)}`,
'files:',
...entries.flatMap((entry) => [
` - url: ${yamlString(entry.url)}`,
@@ -0,0 +1,37 @@
#!/usr/bin/env node
const { execFileSync } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
function macUpdateRequirements(appMinimum, deploymentTarget) {
const versions = [appMinimum, deploymentTarget].map((version) => {
if (!/^\d+\.0(?:\.0)?$/.test(version)) {
throw new Error(`Expected a macOS major-release minimum, got ${version}`);
}
return Number(version.split('.')[0]);
});
const major = Math.max(...versions);
// Darwin 20–24 correspond to macOS 11–15; macOS switched to year-based names at 26.
const darwinMajor = major >= 26 ? major - 1 : major >= 11 && major <= 15 ? major + 9 : null;
if (darwinMajor === null) {
throw new Error(`Unknown Darwin version for macOS ${major}`);
}
return {
minimumMacOSVersion: `${major}.0.0`,
minimumSystemVersion: `${darwinMajor}.0.0`,
};
}
if (require.main === module) {
const [appPath, outputPath] = process.argv.slice(2);
const appMinimum = execFileSync(
'/usr/bin/plutil',
['-extract', 'LSMinimumSystemVersion', 'raw', path.join(appPath, 'Contents', 'Info.plist')],
{ encoding: 'utf8' }
).trim();
const requirements = macUpdateRequirements(appMinimum, process.env.MACOSX_DEPLOYMENT_TARGET);
fs.writeFileSync(outputPath, `${JSON.stringify(requirements)}\n`);
}
module.exports = { macUpdateRequirements };
@@ -0,0 +1,154 @@
const assert = require('node:assert/strict');
const { execFileSync } = require('node:child_process');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { test } = require('node:test');
const { AppUpdater } = require('electron-updater/out/AppUpdater');
const { parseUpdateInfo } = require('electron-updater/out/providers/Provider');
function workspace(t) {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'goose-manifest-test-'));
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
return directory;
}
function recordBundle(directory, name, appMinimum, deploymentTarget) {
const appPath = path.join(directory, `${name}.app`);
fs.mkdirSync(path.join(appPath, 'Contents'), { recursive: true });
fs.writeFileSync(
path.join(appPath, 'Contents', 'Info.plist'),
`<?xml version="1.0"?><plist version="1.0"><dict><key>LSMinimumSystemVersion</key><string>${appMinimum}</string></dict></plist>`
);
fs.writeFileSync(path.join(directory, name), 'archive fixture');
execFileSync(
process.execPath,
[
path.join(__dirname, 'mac-update-requirements.js'),
appPath,
path.join(directory, `${name}.macos.json`),
],
{ env: { ...process.env, MACOSX_DEPLOYMENT_TARGET: deploymentTarget }, stdio: 'pipe' }
);
}
function generateManifest(directory) {
execFileSync(
process.execPath,
[
path.join(__dirname, 'generate-mac-update-manifest.js'),
'--version',
'v1.51.0',
'--directory',
directory,
],
{ stdio: 'pipe' }
);
}
for (const {
name,
appMinimum,
backendMinimum,
intelMinimum,
minimumMacOS,
blockedDarwin,
allowedDarwin,
} of [
{
name: 'still allows macOS 12 for a compatible release',
appMinimum: '12.0',
backendMinimum: '12.0',
intelMinimum: '12.0',
minimumMacOS: '12.0.0',
blockedDarwin: '20.6.0',
allowedDarwin: '21.0.0',
},
{
name: 'blocks macOS 12 when Electron requires macOS 13',
appMinimum: '13.0',
backendMinimum: '12.0',
intelMinimum: '13.0',
minimumMacOS: '13.0.0',
blockedDarwin: '21.6.0',
allowedDarwin: '22.0.0',
},
{
name: 'blocks macOS 12 when the backend requires macOS 13',
appMinimum: '12.0',
backendMinimum: '13.0',
intelMinimum: '12.0',
minimumMacOS: '13.0.0',
blockedDarwin: '21.6.0',
allowedDarwin: '22.0.0',
},
{
name: 'honors the stricter Intel bundle requirement',
appMinimum: '12.0',
backendMinimum: '12.0',
intelMinimum: '13.0',
minimumMacOS: '13.0.0',
blockedDarwin: '21.6.0',
allowedDarwin: '22.0.0',
},
{
name: 'handles the macOS 26 naming change',
appMinimum: '26.0',
backendMinimum: '13.0',
intelMinimum: '26.0',
minimumMacOS: '26.0.0',
blockedDarwin: '24.6.0',
allowedDarwin: '25.0.0',
},
]) {
test(name, { skip: process.platform !== 'darwin' }, async (t) => {
const directory = workspace(t);
recordBundle(directory, 'Goose.zip', appMinimum, backendMinimum);
recordBundle(directory, 'Goose_intel_mac.zip', intelMinimum, backendMinimum);
generateManifest(directory);
const updateInfo = parseUpdateInfo(
fs.readFileSync(path.join(directory, 'latest-mac.yml'), 'utf8'),
'latest-mac.yml',
new URL('https://example.invalid/latest-mac.yml')
);
const updater = new AppUpdater(undefined, { version: '1.50.0' });
updater.logger = null;
t.mock.method(os, 'release', () => blockedDarwin);
assert.equal(await updater.isUpdateSupported(updateInfo), false);
os.release.mock.mockImplementation(() => allowedDarwin);
assert.equal(await updater.isUpdateSupported(updateInfo), true);
const fallbackMetadata = JSON.parse(
fs.readFileSync(path.join(directory, 'mac-update-requirements.json'))
);
assert.equal(fallbackMetadata.version, updateInfo.version);
assert.equal(fallbackMetadata.minimumMacOSVersion, minimumMacOS);
});
}
test('does not publish a manifest if one architecture has no compatibility metadata', (t) => {
const directory = workspace(t);
fs.writeFileSync(
path.join(directory, 'Goose.zip.macos.json'),
JSON.stringify({ minimumMacOSVersion: '12.0.0' })
);
for (const name of ['Goose.zip', 'Goose_intel_mac.zip']) {
fs.writeFileSync(path.join(directory, name), 'archive fixture');
}
assert.throws(() => generateManifest(directory));
assert.equal(fs.existsSync(path.join(directory, 'latest-mac.yml')), false);
assert.equal(fs.existsSync(path.join(directory, 'mac-update-requirements.json')), false);
});
test(
'stops packaging rather than silently rounding down unsupported OS minima',
{ skip: process.platform !== 'darwin' },
(t) => {
for (const minimum of ['13.1', '13.0.1', '16.0']) {
const directory = workspace(t);
assert.throws(() => recordBundle(directory, 'Goose.zip', minimum, '12.0'));
assert.equal(fs.existsSync(path.join(directory, 'Goose.zip.macos.json')), false);
}
}
);
@@ -0,0 +1,172 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { execFileSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { GitHubUpdater } from './githubUpdater';
vi.mock('electron', () => ({ app: { getVersion: () => '1.50.0' } }));
vi.mock('./logger', () => ({
default: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
}));
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')!;
const originalArch = Object.getOwnPropertyDescriptor(process, 'arch')!;
const originalSystemVersion = Object.getOwnPropertyDescriptor(process, 'getSystemVersion');
const metadataUrl = 'https://example.invalid/mac-update-requirements.json';
const assets = [
{ name: 'mac-update-requirements.json', browser_download_url: metadataUrl, size: 100 },
{ name: 'Goose.zip', browser_download_url: 'https://example.invalid/Goose.zip', size: 100 },
{
name: 'Goose_intel_mac.zip',
browser_download_url: 'https://example.invalid/Goose_intel_mac.zip',
size: 100,
},
{
name: 'Goose-win32-x64.zip',
browser_download_url: 'https://example.invalid/Goose-win32-x64.zip',
size: 100,
},
{
name: 'Goose-linux-x64.zip',
browser_download_url: 'https://example.invalid/Goose-linux-x64.zip',
size: 100,
},
];
const release = { tag_name: 'v1.51.0', name: 'Goose', assets };
function generatedRequirements(minimumMacOSVersion: string) {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'goose-fallback-release-test-'));
try {
for (const name of ['Goose.zip', 'Goose_intel_mac.zip']) {
fs.writeFileSync(path.join(directory, name), 'archive fixture');
fs.writeFileSync(
path.join(directory, `${name}.macos.json`),
JSON.stringify({ minimumMacOSVersion })
);
}
execFileSync(process.execPath, [
path.resolve('scripts/generate-mac-update-manifest.js'),
'--version',
'v1.51.0',
'--directory',
directory,
]);
return JSON.parse(
fs.readFileSync(path.join(directory, 'mac-update-requirements.json'), 'utf8')
) as unknown;
} finally {
fs.rmSync(directory, { recursive: true, force: true });
}
}
const macOS12Release = generatedRequirements('12.0.0');
const macOS13Release = generatedRequirements('13.0.0');
function mockRelease(metadata: unknown = macOS13Release, releaseAssets = assets) {
vi.stubGlobal(
'fetch',
vi.fn(async (url: string) => {
if (url === 'https://api.github.com/repos/aaif-goose/goose/releases/latest') {
return new Response(JSON.stringify({ ...release, assets: releaseAssets }));
}
if (url === metadataUrl) {
return metadata instanceof Response ? metadata : new Response(JSON.stringify(metadata));
}
throw new Error(`Unexpected request: ${url}`);
})
);
}
beforeEach(() => {
Object.defineProperty(process, 'platform', { value: 'darwin' });
Object.defineProperty(process, 'arch', { value: 'arm64' });
Object.defineProperty(process, 'getSystemVersion', {
value: vi.fn(() => '12.7.6'),
configurable: true,
});
});
afterEach(() => {
Object.defineProperty(process, 'platform', originalPlatform);
Object.defineProperty(process, 'arch', originalArch);
if (originalSystemVersion) {
Object.defineProperty(process, 'getSystemVersion', originalSystemVersion);
} else {
Reflect.deleteProperty(process, 'getSystemVersion');
}
vi.unstubAllGlobals();
});
describe('GitHub updater macOS compatibility', () => {
it.each(['arm64', 'x64'])('does not offer a macOS 13 update on macOS 12 (%s)', async (arch) => {
Object.defineProperty(process, 'arch', { value: arch });
mockRelease();
const result = await new GitHubUpdater().checkForUpdates();
expect(result).toEqual({ updateAvailable: false, latestVersion: '1.51.0' });
expect(result.downloadUrl).toBeUndefined();
});
it.each([
['arm64', '13.0', 'Goose.zip'],
['x64', '13.0', 'Goose_intel_mac.zip'],
['arm64', '26.0', 'Goose.zip'],
])('offers the %s download on macOS %s', async (arch, version, asset) => {
Object.defineProperty(process, 'arch', { value: arch });
vi.mocked(process.getSystemVersion).mockReturnValue(version);
mockRelease();
expect(await new GitHubUpdater().checkForUpdates()).toMatchObject({
updateAvailable: true,
downloadUrl: `https://example.invalid/${asset}`,
});
});
it('still offers a macOS 12-compatible release on macOS 12', async () => {
mockRelease(macOS12Release);
expect(await new GitHubUpdater().checkForUpdates()).toMatchObject({ updateAvailable: true });
});
it.each([
{},
{ version: '1.51.0', minimumMacOSVersion: 'invalid' },
{ version: '1.50.0', minimumMacOSVersion: '12.0.0' },
])('rejects malformed or mismatched requirements: %j', async (metadata) => {
mockRelease(metadata);
expect(await new GitHubUpdater().checkForUpdates()).toMatchObject({
updateAvailable: false,
error: expect.any(String),
});
});
it('does not offer an update without compatibility metadata', async () => {
mockRelease(
macOS13Release,
assets.filter((asset) => asset.name !== 'mac-update-requirements.json')
);
expect(await new GitHubUpdater().checkForUpdates()).toMatchObject({
updateAvailable: false,
error: expect.stringContaining('compatibility information'),
});
});
it('does not offer an update when the compatibility file cannot be retrieved', async () => {
mockRelease(new Response('', { status: 503 }));
expect(await new GitHubUpdater().checkForUpdates()).toMatchObject({
updateAvailable: false,
error: expect.any(String),
});
});
it.each(['win32', 'linux'])('leaves %s updates unchanged', async (platform) => {
Object.defineProperty(process, 'platform', { value: platform });
Object.defineProperty(process, 'arch', { value: 'x64' });
mockRelease(
undefined,
assets.filter((asset) => asset.name !== 'mac-update-requirements.json')
);
expect(await new GitHubUpdater().checkForUpdates()).toMatchObject({
updateAvailable: true,
downloadUrl: `https://example.invalid/Goose-${platform}-x64.zip`,
});
});
});
+29
View File
@@ -1,5 +1,6 @@
import { app } from 'electron';
import { compareVersions } from 'compare-versions';
import { z } from 'zod';
import { spawn } from 'child_process';
import * as fs from 'fs/promises';
import * as path from 'path';
@@ -523,6 +524,34 @@ export class GitHubUpdater {
// Find the appropriate download URL based on platform
const platform = process.platform;
const arch = process.arch;
if (platform === 'darwin') {
const requirementsAsset = release.assets.find(
(asset) => asset.name === 'mac-update-requirements.json'
);
if (!requirementsAsset) {
throw new Error('This release does not include macOS compatibility information.');
}
const requirementsResponse = await fetch(requirementsAsset.browser_download_url, {
signal: AbortSignal.timeout(30000),
});
if (!requirementsResponse.ok) {
throw new Error('Unable to check macOS update compatibility. Please try again later.');
}
const requirements = z
.object({
version: z.literal(latestVersion),
minimumMacOSVersion: z.string().regex(/^\d+\.\d+\.\d+$/),
})
.safeParse(await requirementsResponse.json());
if (!requirements.success) {
throw new Error('This release has invalid macOS compatibility information.');
}
if (
compareVersions(process.getSystemVersion(), requirements.data.minimumMacOSVersion) < 0
) {
return { updateAvailable: false, latestVersion };
}
}
let downloadUrl: string | undefined;
let assetName: string;