mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
fix: harden console self-update for real release packages
- Copy the restart runner with every runtime import (restart-runner.js, code-swap.js, version.js, update-state.js) and fail the apply when the runner exits during the startup grace window instead of reporting a task that never restarted. - Accept official tar/zip relative symlinks that stay inside the extraction root while still refusing absolute, drive-qualified, escaping and hard-link entries. - Have the restart runner take over the update lock for the same task, keep live or unreadable locks, and copy EXDEV entries into a temporary name before renaming so a partial copy cannot replace the previous tree. - Disable console apply for Windows release packages with WINDOWS_APPLY_UNVERIFIED while still reporting available versions. - Clarify in zh/en docs and five-language console copy that SHA256SUMS.txt is an integrity checksum, not a signature, and that verification targets the official Linux x64 build-release.yml package. - Add tests for the failing EXDEV copy, live/unreadable/dead locks, same-task lock takeover, a real spawned runner compiled from source, and initialization leaving another live process's task untouched.
This commit is contained in:
1 parent
eb6c4ba857
commit
699e606da5
15 files changed
+793
-90
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn, type ChildProcess } from "node:child_process";
|
||||
import { once } from "node:events";
|
||||
import test, { type TestContext } from "node:test";
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
@@ -6,7 +8,7 @@ import path from "node:path";
|
||||
import type { UpdateTaskView } from "../shared/update.js";
|
||||
import {
|
||||
acquireUpdateLock, clearStaleUpdateLock, emptyUpdateState, isActiveTaskStatus, readUpdateState,
|
||||
reconcileInterruptedState, UpdateLockedError, writeUpdateState,
|
||||
reconcileInterruptedState, takeOverUpdateLock, UpdateLockedError, updateLockIsHeld, writeUpdateState,
|
||||
} from "./update-state.js";
|
||||
|
||||
function workspace(t: TestContext): string {
|
||||
@@ -32,6 +34,14 @@ function task(overrides: Partial<UpdateTaskView> = {}): UpdateTaskView {
|
||||
};
|
||||
}
|
||||
|
||||
/** A second process that stays alive while a lock records its pid. */
|
||||
async function liveProcess(t: TestContext): Promise<ChildProcess> {
|
||||
const child = spawn(process.execPath, ["-e", "setTimeout(() => {}, 60000)"], { stdio: "ignore" });
|
||||
t.after(() => { try { child.kill("SIGKILL"); } catch { /* Already gone. */ } });
|
||||
await once(child, "spawn");
|
||||
return child;
|
||||
}
|
||||
|
||||
test("state files round-trip and malformed files fall back to idle", t => {
|
||||
const directory = workspace(t), filename = path.join(directory, "state.json");
|
||||
assert.deepEqual(readUpdateState(filename), emptyUpdateState());
|
||||
@@ -89,6 +99,57 @@ test("locks left by dead processes are reclaimed while live locks are preserved"
|
||||
assert.equal(existsSync(lock), false);
|
||||
});
|
||||
|
||||
test("a live lock and an unreadable lock are never cleared, and count as held", async t => {
|
||||
const directory = workspace(t), lock = path.join(directory, "update.lock");
|
||||
const owner = await liveProcess(t);
|
||||
writeFileSync(lock, JSON.stringify({ pid: owner.pid, taskId: "live-task", createdAt: "2026-01-01T00:00:00.000Z" }));
|
||||
clearStaleUpdateLock(lock);
|
||||
assert.equal(existsSync(lock), true);
|
||||
assert.equal(updateLockIsHeld(lock), true);
|
||||
assert.equal(updateLockIsHeld(lock, "live-task"), true);
|
||||
assert.equal(updateLockIsHeld(lock, "other-task"), false);
|
||||
assert.throws(() => acquireUpdateLock(lock, "new-task"), (error: unknown) => error instanceof UpdateLockedError);
|
||||
|
||||
// A lock that cannot be parsed may belong to a live owner, so it must not
|
||||
// be deleted and must conservatively block new updates.
|
||||
writeFileSync(lock, "not a lock record");
|
||||
clearStaleUpdateLock(lock);
|
||||
assert.equal(existsSync(lock), true);
|
||||
assert.equal(updateLockIsHeld(lock), true);
|
||||
assert.throws(() => acquireUpdateLock(lock, "new-task"), (error: unknown) => error instanceof UpdateLockedError);
|
||||
});
|
||||
|
||||
test("a lock left by a dead process is reported free and reclaimed", t => {
|
||||
const directory = workspace(t), lock = path.join(directory, "update.lock");
|
||||
writeFileSync(lock, JSON.stringify({ pid: 0, taskId: "dead-task", createdAt: "2026-01-01T00:00:00.000Z" }));
|
||||
assert.equal(updateLockIsHeld(lock), false);
|
||||
clearStaleUpdateLock(lock);
|
||||
assert.equal(existsSync(lock), false);
|
||||
const release = acquireUpdateLock(lock, "new-task");
|
||||
assert.equal(JSON.parse(readFileSync(lock, "utf8")).taskId, "new-task");
|
||||
release();
|
||||
});
|
||||
|
||||
test("the restart runner can take over its own task but never another task's lock", async t => {
|
||||
const directory = workspace(t), lock = path.join(directory, "update.lock");
|
||||
const previousOwner = await liveProcess(t);
|
||||
writeFileSync(lock, JSON.stringify({ pid: previousOwner.pid, taskId: "task-shared", createdAt: "2026-01-01T00:00:00.000Z" }));
|
||||
assert.doesNotThrow(() => process.kill(previousOwner.pid!, 0), "the original owner is still alive");
|
||||
|
||||
const release = takeOverUpdateLock(lock, "task-shared");
|
||||
const record = JSON.parse(readFileSync(lock, "utf8"));
|
||||
assert.equal(record.pid, process.pid);
|
||||
assert.equal(record.taskId, "task-shared");
|
||||
assert.equal(updateLockIsHeld(lock, "task-shared"), true);
|
||||
release();
|
||||
assert.equal(existsSync(lock), false);
|
||||
|
||||
writeFileSync(lock, JSON.stringify({ pid: previousOwner.pid, taskId: "task-other", createdAt: "2026-01-01T00:00:00.000Z" }));
|
||||
assert.throws(() => takeOverUpdateLock(lock, "task-shared"), (error: unknown) => error instanceof UpdateLockedError);
|
||||
assert.equal(JSON.parse(readFileSync(lock, "utf8")).taskId, "task-other");
|
||||
assert.equal(updateLockIsHeld(lock, "task-other"), true);
|
||||
});
|
||||
|
||||
test("state writes replace the destination atomically", t => {
|
||||
const directory = workspace(t), filename = path.join(directory, "nested", "state.json");
|
||||
writeUpdateState(filename, { schemaVersion: 1, task: task({ id: "first" }) });
|
||||
|
||||
Reference in new issue
Block a user