1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Merge branch 'master' into turn-on-strict

This commit is contained in:
Sebastian Malton 2022-05-13 16:26:15 -04:00
commit ec092848d6
2 changed files with 45 additions and 114 deletions

View File

@ -8,122 +8,63 @@ import semver from "semver";
import { isCompatibleExtension } from "../extension-discovery/is-compatible-extension/is-compatible-extension"; import { isCompatibleExtension } from "../extension-discovery/is-compatible-extension/is-compatible-extension";
import type { LensExtensionManifest } from "../lens-extension"; import type { LensExtensionManifest } from "../lens-extension";
export function semverCoerce(from: string): semver.SemVer { describe("Extension/App versions compatibility checks", () => {
const parsed = semver.coerce(from);
assert(parsed, `"${from}" cannot be coerced to a SemVer value`);
return parsed;
}
describe("Extension/App versions compatibility check", () => {
it("is compatible with exact version matching", () => { it("is compatible with exact version matching", () => {
expect(isCompatibleExtension({ expect(isCompatible({ extLensEngineVersion: "5.5.0", appVersion: "5.5.0" })).toBeTruthy();
appSemVer: semverCoerce("5.5.0"),
})(getExtensionManifestMock({
lensEngine: "5.5.0",
}))).toBeTruthy();
}); });
it("is compatible with upper %PATCH versions of base app", () => { it("is compatible with upper %PATCH versions of base app", () => {
expect(isCompatibleExtension({ expect(isCompatible({ extLensEngineVersion: "5.5.0", appVersion: "5.5.5" })).toBeTruthy();
appSemVer: semverCoerce("5.5.5"),
})(getExtensionManifestMock({
lensEngine: "5.5.0",
}))).toBeTruthy();
}); });
it("is compatible with upper %MINOR version of base app", () => { it("is compatible with higher %MINOR version of base app", () => {
expect(isCompatibleExtension({ expect(isCompatible({ extLensEngineVersion: "5.5.0", appVersion: "5.6.0" })).toBeTruthy();
appSemVer: semverCoerce("5.6.0"),
})(getExtensionManifestMock({
lensEngine: "5.5.0",
}))).toBeTruthy();
expect(isCompatibleExtension({
appSemVer: semverCoerce("5.5.0-alpha.0"),
})(getExtensionManifestMock({
lensEngine: "^5.5.0",
}))).toBeTruthy();
expect(isCompatibleExtension({
appSemVer: semverCoerce("5.5"),
})(getExtensionManifestMock({
lensEngine: "^5.6.0",
}))).toBeFalsy();
}); });
it("is not compatible with upper %MAJOR version of base app", () => { it("is not compatible with higher %MAJOR version of base app", () => {
expect(isCompatibleExtension({ expect(isCompatible({ extLensEngineVersion: "5.6.0", appVersion: "6.0.0" })).toBeFalsy(); // extension for lens@5 not compatible with lens@6
appSemVer: semverCoerce("5.5.0"), // current lens-version expect(isCompatible({ extLensEngineVersion: "6.0.0", appVersion: "5.6.0" })).toBeFalsy();
})(getExtensionManifestMock({
lensEngine: "6.0.0",
}))).toBeFalsy(); // extension with lens@6.0 is not compatible with app@5.5
expect(isCompatibleExtension({
appSemVer: semverCoerce("6.0.0"), // current lens-version
})(getExtensionManifestMock({
lensEngine: "5.5.0",
}))).toBeFalsy(); // extension with lens@5.5 is not compatible with app@6.0
}); });
it("is compatible with lensEngine with prerelease", () => { it("is compatible with lensEngine with prerelease", () => {
expect(isCompatibleExtension({ expect(isCompatible({
appSemVer: new semver.SemVer("5.5.0-alpha.0"), extLensEngineVersion: "^5.4.0-alpha.0",
})(getExtensionManifestMock({ appVersion: "5.5.0-alpha.0",
lensEngine: "^5.4.0-alpha.0", })).toBeTruthy();
}))).toBeTruthy();
}); });
describe("supported formats for manifest.engines.lens", () => { it("supports short version format for manifest.engines.lens", () => {
it("short version format for engines.lens", () => { expect(isCompatible({ extLensEngineVersion: "5.5", appVersion: "5.5.1" })).toBeTruthy();
expect(isCompatibleExtension({ });
appSemVer: semverCoerce("5.5.0"),
})(getExtensionManifestMock({
lensEngine: "5.5",
}))).toBeTruthy();
});
it("validates version and throws if incorrect format", () => { it("throws for incorrect or not supported version format", () => {
expect(() => isCompatibleExtension({ expect(() => isCompatible({
appSemVer: semverCoerce("1.0.0"), extLensEngineVersion: ">=2.0",
})(getExtensionManifestMock({ appVersion: "2.0",
lensEngine: "1.0", })).toThrow(/Invalid format/i);
}))).not.toThrow();
expect(() => isCompatibleExtension({ expect(() => isCompatible({
appSemVer: semverCoerce("1.0.0"), extLensEngineVersion: "~2.0",
})(getExtensionManifestMock({ appVersion: "2.0",
lensEngine: "^1.0", })).toThrow(/Invalid format/i);
}))).not.toThrow();
expect(() => isCompatibleExtension({ expect(() => isCompatible({
appSemVer: semverCoerce("1.0.0"), extLensEngineVersion: "*",
})(getExtensionManifestMock({ appVersion: "1.0",
lensEngine: ">=2.0", })).toThrow(/Invalid format/i);
}))).toThrow(/Invalid format/i);
expect(() => isCompatibleExtension({
appSemVer: semverCoerce("1.0.0"),
})(getExtensionManifestMock({
lensEngine: ">=2.0 <3.0",
}))).toThrow(/Invalid format/i);
});
it("'*' cannot be used for any version matching (at least in the prefix)", () => {
expect(() => isCompatibleExtension({
appSemVer: semverCoerce("1.0.0"),
})(getExtensionManifestMock({
lensEngine: "*",
}))).toThrowError(/Invalid format/i);
});
}); });
}); });
function getExtensionManifestMock( function isCompatible({ extLensEngineVersion = "^1.0", appVersion = "1.0" } = {}): boolean {
{ const appSemVer = semver.coerce(appVersion);
lensEngine = "1.0", const extensionManifestMock = getExtensionManifestMock(extLensEngineVersion);
} = {}): LensExtensionManifest {
assert(appSemVer);
return isCompatibleExtension({ appSemVer })(extensionManifestMock);
}
function getExtensionManifestMock(lensEngine = "1.0"): LensExtensionManifest {
return { return {
name: "some-extension", name: "some-extension",
version: "1.0", version: "1.0",

View File

@ -28,10 +28,9 @@ function handleAutoUpdateBackChannel(event: Electron.IpcMainEvent, ...[arg]: Upd
autoUpdater.quitAndInstall(true, true); autoUpdater.quitAndInstall(true, true);
} else { } else {
logger.info(`${AutoUpdateLogPrefix}: User chose to update on quit`); logger.info(`${AutoUpdateLogPrefix}: User chose to update on quit`);
autoUpdater.autoInstallOnAppQuit = true;
} }
} else { } else {
logger.info(`${AutoUpdateLogPrefix}: User chose not to update`); logger.info(`${AutoUpdateLogPrefix}: User chose not to update, will update on quit anyway`);
} }
} }
@ -44,9 +43,9 @@ autoUpdater.logger = {
/** /**
* starts the automatic update checking * starts the automatic update checking
* @param interval milliseconds between interval to check on, defaults to 24h * @param interval milliseconds between interval to check on, defaults to 2h
*/ */
export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24): void { export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 2): void {
if (!isAutoUpdateEnabled() || isTestEnv) { if (!isAutoUpdateEnabled() || isTestEnv) {
return; return;
} }
@ -54,26 +53,17 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
const userStore = UserStore.getInstance(); const userStore = UserStore.getInstance();
autoUpdater.autoDownload = false; autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false; autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.channel = userStore.updateChannel; autoUpdater.channel = userStore.updateChannel;
autoUpdater.allowDowngrade = userStore.isAllowedToDowngrade; autoUpdater.allowDowngrade = userStore.isAllowedToDowngrade;
autoUpdater autoUpdater
.on("update-available", (info: UpdateInfo) => { .on("update-available", (info: UpdateInfo) => {
if (autoUpdater.autoInstallOnAppQuit) { if (installVersion === info.version) {
// a previous auto-update loop was completed with YES+LATER, check if same version // same version, don't broadcast
if (installVersion === info.version) { return;
// same version, don't broadcast
return;
}
} }
/**
* This should be always set to false here because it is the reasonable
* default. Namely, if a don't auto update to a version that the user
* didn't ask for.
*/
autoUpdater.autoInstallOnAppQuit = false;
installVersion = info.version; installVersion = info.version;
autoUpdater.downloadUpdate() autoUpdater.downloadUpdate()