mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-05 21:22:07 +00:00
865c3589bd
- Updated paths and configurations in doctor.mjs and prepare-nodecg-runtime.mjs to use new build-config.mjs imports. - Enhanced runtime installation checks and permissions validation. - Introduced new update configuration management in update-config.ts, including loading and validating update settings. - Implemented update service for managing update checks and downloads in update-service.ts. - Replaced update-utils.ts with update-schema.ts for better structure and clarity in update handling. - Added comprehensive tests for update download and settings management. - Ensured secure handling of download URLs and improved error handling in update processes.
106 lines
3.4 KiB
TypeScript
106 lines
3.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
|
|
import { AppRuntimeConfig } from "../main/config/runtime-config";
|
|
import { loadUpdateSettings, readUpdateFileConfig } from "../main/updates/update-config";
|
|
|
|
const baseConfig: AppRuntimeConfig = {
|
|
title: "Scoreko",
|
|
userModelId: "com.scoreko.desktop",
|
|
userDataDirectoryName: "scoreko",
|
|
nodecgPort: "9090",
|
|
bundleName: "scoreko-dev",
|
|
mainDashboardRoute: "dashboard/scoreko-dev/main.html?standalone=true",
|
|
loadingDashboardRoute: "dashboard/loading/main.html?standalone=true",
|
|
loadDelayMs: 0,
|
|
startupTimeoutMs: 30000,
|
|
nodecgKillTimeoutMs: 2500,
|
|
updatesEnabled: true,
|
|
updateCheckDelayMs: 5000,
|
|
};
|
|
|
|
test("loadUpdateSettings keeps updates disabled when the runtime config disables them", () => {
|
|
const rootPath = makeTempRoot({
|
|
enabled: true,
|
|
apiUrl: "https://gitea.local/releases/latest",
|
|
});
|
|
|
|
const settings = loadUpdateSettings({ ...baseConfig, updatesEnabled: false }, rootPath, () => undefined);
|
|
|
|
assert.equal(settings.enabled, false);
|
|
assert.equal(settings.apiUrl, "https://gitea.local/releases/latest");
|
|
});
|
|
|
|
test("loadUpdateSettings fails closed on insecure production update URLs", () => {
|
|
const rootPath = makeTempRoot({
|
|
enabled: true,
|
|
apiUrl: "http://gitea.local/releases/latest",
|
|
});
|
|
|
|
const settings = loadUpdateSettings(baseConfig, rootPath, () => undefined, { allowInsecureHttp: false });
|
|
|
|
assert.equal(settings.enabled, false);
|
|
assert.equal(settings.apiUrl, undefined);
|
|
});
|
|
|
|
test("loadUpdateSettings lets runtime config override file settings", () => {
|
|
const rootPath = makeTempRoot({
|
|
enabled: true,
|
|
apiUrl: "https://file.local/releases/latest",
|
|
releasePageUrl: "https://file.local/releases",
|
|
assetPattern: "File-.*\\.exe$",
|
|
});
|
|
|
|
const settings = loadUpdateSettings(
|
|
{
|
|
...baseConfig,
|
|
updateApiUrl: "https://env.local/releases/latest",
|
|
updateReleasePageUrl: "https://env.local/releases",
|
|
updateAssetPattern: "Env-.*\\.exe$",
|
|
},
|
|
rootPath,
|
|
() => undefined,
|
|
);
|
|
|
|
assert.deepEqual(settings, {
|
|
enabled: true,
|
|
apiUrl: "https://env.local/releases/latest",
|
|
releasePageUrl: "https://env.local/releases",
|
|
assetPattern: "Env-.*\\.exe$",
|
|
});
|
|
});
|
|
|
|
test("readUpdateFileConfig normalizes malformed config into an empty file config", () => {
|
|
const rootPath = makeTempRoot(["not", "an", "object"]);
|
|
|
|
assert.deepEqual(readUpdateFileConfig(baseConfig, rootPath, () => undefined), {});
|
|
});
|
|
|
|
test("readUpdateFileConfig logs invalid JSON and returns an empty file config", () => {
|
|
const rootPath = fs.mkdtempSync(path.join(os.tmpdir(), "scoreko-update-settings-"));
|
|
const staticPath = path.join(rootPath, "static");
|
|
fs.mkdirSync(staticPath, { recursive: true });
|
|
fs.writeFileSync(path.join(staticPath, "updates.json"), "{ invalid", "utf8");
|
|
const messages: unknown[][] = [];
|
|
|
|
const settings = readUpdateFileConfig(baseConfig, rootPath, (...args: unknown[]) => {
|
|
messages.push(args);
|
|
});
|
|
|
|
assert.deepEqual(settings, {});
|
|
assert.equal(messages.length, 1);
|
|
});
|
|
|
|
function makeTempRoot(config: unknown): string {
|
|
const rootPath = fs.mkdtempSync(path.join(os.tmpdir(), "scoreko-update-settings-"));
|
|
const staticPath = path.join(rootPath, "static");
|
|
|
|
fs.mkdirSync(staticPath, { recursive: true });
|
|
fs.writeFileSync(path.join(staticPath, "updates.json"), JSON.stringify(config), "utf8");
|
|
|
|
return rootPath;
|
|
}
|