mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat: add verified console self-update for release packages
Check official GitHub Releases, require SHA256SUMS, safely extract and swap release-package code, roll back on failed health checks, and persist task state across restarts. Docker and source deployments stay check-only. Add updater tests, route security tests and five-language admin copy.
This commit is contained in:
1 parent
ae6788a796
commit
2de2e23fd3
32 files changed
+3573
-16
No files matched your search
@@ -0,0 +1,90 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import {
|
||||
assetKindFor, detectDeployment, isReleasePackageRoot, releaseAssetName, upgradePathFor,
|
||||
} from "./deployment.js";
|
||||
|
||||
function temporary(t: test.TestContext): string {
|
||||
const directory = mkdtempSync(path.join(tmpdir(), "webspeak-deployment-"));
|
||||
t.after(() => rmSync(directory, { recursive: true, force: true }));
|
||||
return directory;
|
||||
}
|
||||
|
||||
function releasePackageRoot(t: test.TestContext, platform: "linux" | "win32" = "linux"): string {
|
||||
const root = temporary(t);
|
||||
const runtime = platform === "win32" ? "node.exe" : "node";
|
||||
for (const directory of ["runtime", "dist", "web/dist"]) mkdirSync(path.join(root, directory), { recursive: true });
|
||||
writeFileSync(path.join(root, "runtime", runtime), "");
|
||||
writeFileSync(path.join(root, "dist", "index.js"), "");
|
||||
writeFileSync(path.join(root, "web", "dist", "index.html"), "");
|
||||
writeFileSync(path.join(root, "package.json"), JSON.stringify({ version: "1.0.0" }));
|
||||
return root;
|
||||
}
|
||||
|
||||
test("deployment mode honours the explicit environment override", () => {
|
||||
const env = { WEBSPEAK_DEPLOYMENT_MODE: "release-package" };
|
||||
const info = detectDeployment({ rootDir: "/does/not/exist", env, isDocker: true, platform: "linux", architecture: "x64" });
|
||||
assert.equal(info.mode, "release-package");
|
||||
assert.equal(info.applyAllowed, true);
|
||||
assert.equal(info.reasonCode, null);
|
||||
assert.equal(info.upgradePath, "release-package");
|
||||
});
|
||||
|
||||
test("docker and source deployments never allow an in-console apply", () => {
|
||||
const docker = detectDeployment({ rootDir: "/does/not/exist", env: {}, isDocker: true, platform: "linux", architecture: "x64" });
|
||||
assert.deepEqual(
|
||||
{ mode: docker.mode, applyAllowed: docker.applyAllowed, reasonCode: docker.reasonCode, upgradePath: docker.upgradePath },
|
||||
{ mode: "docker", applyAllowed: false, reasonCode: "DEPLOYMENT_DOCKER", upgradePath: "docker-compose" },
|
||||
);
|
||||
const source = detectDeployment({ rootDir: "/does/not/exist", env: {}, isDocker: false, platform: "linux", architecture: "x64" });
|
||||
assert.deepEqual(
|
||||
{ mode: source.mode, applyAllowed: source.applyAllowed, reasonCode: source.reasonCode, upgradePath: source.upgradePath },
|
||||
{ mode: "source", applyAllowed: false, reasonCode: "DEPLOYMENT_SOURCE", upgradePath: "source" },
|
||||
);
|
||||
});
|
||||
|
||||
test("a complete packaged tree is detected as a release package", t => {
|
||||
const root = releasePackageRoot(t);
|
||||
assert.equal(isReleasePackageRoot(root, "linux"), true);
|
||||
const info = detectDeployment({ rootDir: root, env: {}, isDocker: false, platform: "linux", architecture: "arm64" });
|
||||
assert.equal(info.mode, "release-package");
|
||||
assert.equal(info.assetKind, "linux-arm64");
|
||||
assert.equal(info.applyAllowed, true);
|
||||
assert.equal(detectDeployment({ rootDir: root, env: { WEBSPEAK_DEPLOYMENT_MODE: "docker" }, isDocker: false, platform: "linux" }).mode, "docker");
|
||||
});
|
||||
|
||||
test("incomplete trees stay in source mode", t => {
|
||||
const root = temporary(t);
|
||||
assert.equal(isReleasePackageRoot(root, "linux"), false);
|
||||
mkdirSync(path.join(root, "runtime"), { recursive: true });
|
||||
writeFileSync(path.join(root, "runtime", "node"), "");
|
||||
assert.equal(isReleasePackageRoot(root, "linux"), false);
|
||||
});
|
||||
|
||||
test("asset names and platform support are pinned to official release shapes", () => {
|
||||
assert.equal(assetKindFor("linux", "x64"), "linux-x64");
|
||||
assert.equal(assetKindFor("linux", "arm64"), "linux-arm64");
|
||||
assert.equal(assetKindFor("win32", "x64"), "windows-x64");
|
||||
assert.equal(assetKindFor("linux", "riscv64"), null);
|
||||
assert.equal(assetKindFor("darwin", "arm64"), null);
|
||||
assert.equal(releaseAssetName("0.4.0", "linux-x64"), "webspeak-webclient-v0.4.0-linux-x64.tar.gz");
|
||||
assert.equal(releaseAssetName("0.4.0", "linux-arm64"), "webspeak-webclient-v0.4.0-linux-arm64.tar.gz");
|
||||
assert.equal(releaseAssetName("0.4.0", "windows-x64"), "webspeak-webclient-v0.4.0-windows-x64.zip");
|
||||
assert.equal(upgradePathFor("docker"), "docker-compose");
|
||||
assert.equal(upgradePathFor("release-package"), "release-package");
|
||||
assert.equal(upgradePathFor("source"), "source");
|
||||
});
|
||||
|
||||
test("unsupported platforms are visible but cannot apply", t => {
|
||||
const root = releasePackageRoot(t);
|
||||
const info = detectDeployment({ rootDir: root, env: {}, isDocker: false, platform: "linux", architecture: "s390x" });
|
||||
assert.equal(info.mode, "release-package");
|
||||
assert.equal(info.applyAllowed, false);
|
||||
assert.equal(info.reasonCode, "ARCH_UNSUPPORTED");
|
||||
const darwin = detectDeployment({ rootDir: root, env: {}, isDocker: false, platform: "darwin", architecture: "arm64" });
|
||||
assert.equal(darwin.applyAllowed, false);
|
||||
assert.equal(darwin.reasonCode, "PLATFORM_UNSUPPORTED");
|
||||
});
|
||||
Reference in new issue
Block a user