fix: integrate updater downgrade guard
This commit is contained in:
@@ -11,11 +11,19 @@ const loggerMocks = vi.hoisted(() => ({
|
||||
|
||||
const updaterMocks = vi.hoisted(() => {
|
||||
const listeners = new Map<string, Array<(...args: unknown[]) => void>>();
|
||||
let channel = 'latest';
|
||||
const autoUpdater = {
|
||||
autoDownload: false,
|
||||
autoInstallOnAppQuit: true,
|
||||
allowDowngrade: false,
|
||||
logger: null as unknown,
|
||||
channel: 'latest',
|
||||
get channel() {
|
||||
return channel;
|
||||
},
|
||||
set channel(value: string) {
|
||||
channel = value;
|
||||
autoUpdater.allowDowngrade = true;
|
||||
},
|
||||
on: vi.fn((event: string, listener: (...args: unknown[]) => void) => {
|
||||
const current = listeners.get(event) ?? [];
|
||||
current.push(listener);
|
||||
@@ -95,6 +103,7 @@ describe('AppUpdater feed delegation', () => {
|
||||
vi.clearAllMocks();
|
||||
electronMocks.getVersion.mockReturnValue('0.9.1');
|
||||
updaterMocks.autoUpdater.channel = 'latest';
|
||||
updaterMocks.autoUpdater.allowDowngrade = false;
|
||||
updaterMocks.autoUpdater.checkForUpdates.mockResolvedValue(null);
|
||||
});
|
||||
|
||||
@@ -131,6 +140,28 @@ describe('AppUpdater feed delegation', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('ignores an older stable feed version even when electron-updater reports it as available', async () => {
|
||||
electronMocks.getVersion.mockReturnValue('2.0.0');
|
||||
updaterMocks.autoUpdater.checkForUpdates.mockImplementation(async () => ({
|
||||
isUpdateAvailable: updaterMocks.autoUpdater.allowDowngrade,
|
||||
updateInfo: { version: '1.1.9' },
|
||||
}));
|
||||
const updater = new AppUpdater();
|
||||
|
||||
await updater.checkForUpdates();
|
||||
|
||||
expect(updaterMocks.autoUpdater.allowDowngrade).toBe(false);
|
||||
expect(updater.getStatus()).toMatchObject({ status: 'not-available' });
|
||||
});
|
||||
|
||||
it('keeps downgrade disabled when changing update channels', () => {
|
||||
const updater = new AppUpdater();
|
||||
|
||||
updater.setChannel('beta');
|
||||
|
||||
expect(updaterMocks.autoUpdater.allowDowngrade).toBe(false);
|
||||
});
|
||||
|
||||
it('reports a concise actionable error when the stable feed has no latest manifest', async () => {
|
||||
const rawError = new Error(
|
||||
'Cannot find channel "latest.yml" update info: HttpError: 404\n' +
|
||||
|
||||
Reference in New Issue
Block a user