Fix Windows mosh reconnect output garbling

This commit is contained in:
bincxz committed 2026-06-29 11:22:13 +08:00
1 parent 30d78ebc5a
commit 2c953cd5cb
5 files changed
+64 -35

No files matched your search

+11 -11
View File
@@ -23,11 +23,9 @@
// MOSH_BIN_RES_DIR — override output dir for tests.
// MOSH_BIN_ALLOW_UNVERIFIED=true — explicit local escape hatch for mirrors
// without SHA256SUMS. Never use for release builds.
// MOSH_BIN_FORCE_WINDOWS_CYGWIN=true — debug escape hatch for the upstream
// Cygwin Windows bundle. The default Windows x64 asset
// is the FluentTerminal-pinned standalone client because
// the current Cygwin build clears the terminal and never
// renders remote output on Windows.
// MOSH_BIN_FORCE_WINDOWS_CYGWIN=true — legacy debug knob kept for older
// automation. Windows now prefers the released bundle
// with its runtime helpers when SHA256SUMS lists it.
// MOSH_BIN_WINDOWS_LEGACY_URL / MOSH_BIN_WINDOWS_LEGACY_SHA256 — test/mirror
// overrides for that pinned Windows fallback.
@@ -54,10 +52,8 @@ const WINDOWS_LEGACY_FLUENT_MOSH_CLIENT = {
// Using flat names in the release for SHA256SUMS readability, then
// fanning out into platform-arch subdirs locally.
//
// Linux/macOS targets are tar.gz bundles containing the binary plus the
// runtime helpers each platform needs. Windows x64 defaults to the
// SHA256-pinned FluentTerminal standalone exe because the tested Cygwin
// bundle clears the terminal and never renders remote output on Windows.
// Linux/macOS/Windows bundle targets are tar.gz archives containing the
// binary plus the runtime helpers each platform needs.
// Bundling terminfo lets bundled Posix mosh-client builds work on
// minimal hosts that don't have a
// system ncurses-base — see issue #890.
@@ -87,7 +83,6 @@ const TARGETS = [
platform: "win32", arch: "x64",
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
legacy: WINDOWS_LEGACY_FLUENT_MOSH_CLIENT,
preferLegacy: true,
},
];
@@ -115,7 +110,12 @@ function selectReleaseAsset(target, sums, opts = {}) {
if (sums.size === 0) return primary;
if (sums.has(target.file)) return primary;
if (sums.has(target.legacy.file)) {
return applyReleaseAssetOverrides({ file: target.legacy.file, local: target.legacy.local }, opts);
const expected = sums.get(target.legacy.file);
const fallback = applyReleaseAssetOverrides(target.legacy, opts);
if (fallback.id && fallback.sha256 && expected !== fallback.sha256) {
return fallback;
}
return { file: target.legacy.file, local: target.legacy.local, sha256: expected };
}
return primary;
}
+16 -23
View File
@@ -328,7 +328,7 @@ test("selectReleaseAsset stays on the primary when SHA256SUMS is empty (unverifi
assert.equal(selectReleaseAsset(target, new Map()).file, "mosh-client-linux-x64.tar.gz");
});
test("selectReleaseAsset prefers the pinned Windows standalone client by default", () => {
test("selectReleaseAsset prefers the released Windows bundle by default", () => {
const target = {
platform: "win32", arch: "x64",
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
@@ -339,15 +339,14 @@ test("selectReleaseAsset prefers the pinned Windows standalone client by default
url: "https://example.test/mosh-client.exe",
sha256: "abc",
},
preferLegacy: true,
};
const sums = new Map([["mosh-client-win32-x64.tar.gz", "def"]]);
assert.equal(selectReleaseAsset(target, sums).file, "mosh-client-win32-x64.exe");
assert.equal(selectReleaseAsset(target, sums).file, "mosh-client-win32-x64.tar.gz");
assert.equal(selectReleaseAsset(target, sums, { forceWindowsCygwin: true }).file, "mosh-client-win32-x64.tar.gz");
});
test("selectReleaseAsset uses the released Windows standalone asset when published", () => {
test("selectReleaseAsset falls back to the Windows standalone asset when the bundle is absent", () => {
const target = {
platform: "win32", arch: "x64",
file: "mosh-client-win32-x64.tar.gz", localDir: "win32-x64", extract: "tar.gz",
@@ -358,7 +357,6 @@ test("selectReleaseAsset uses the released Windows standalone asset when publish
url: "https://example.test/mosh-client.exe",
sha256: "abc",
},
preferLegacy: true,
};
const asset = selectReleaseAsset(target, new Map([["mosh-client-win32-x64.exe", "abc"]]));
@@ -379,7 +377,6 @@ test("selectReleaseAsset ignores a released Windows asset when its checksum is n
url: "https://example.test/mosh-client.exe",
sha256: "abc",
},
preferLegacy: true,
};
const asset = selectReleaseAsset(target, new Map([["mosh-client-win32-x64.exe", "def"]]));
@@ -389,18 +386,18 @@ test("selectReleaseAsset ignores a released Windows asset when its checksum is n
assert.equal(asset.sha256, "abc");
});
test("fetch-mosh-binaries downloads the pinned Windows standalone client", async (t) => {
test("fetch-mosh-binaries downloads the released Windows bundle by default", async (t) => {
const resDir = path.join(makeTmp(t), "resources", "mosh");
const flat = Buffer.from("working-windows-standalone");
fs.mkdirSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls"), { recursive: true });
fs.mkdirSync(path.join(resDir, "win32-x64", "terminfo", "78"), { recursive: true });
fs.writeFileSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll"), "stale");
fs.writeFileSync(path.join(resDir, "win32-x64", "terminfo", "78", "xterm-256color"), "stale");
const baseUrl = await serveAssets(t, {
SHA256SUMS: "",
const tar = makeTarGz(t, {
"mosh-client.exe": "exe",
"mosh-client-win32-x64-dlls/cygwin1.dll": "dll",
"terminfo/x/xterm-256color": "terminfo",
});
const legacyBaseUrl = await serveAssets(t, {
"mosh-client-win32-x64.exe": flat,
fs.mkdirSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls"), { recursive: true });
fs.writeFileSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll"), "stale");
const baseUrl = await serveAssets(t, {
"mosh-client-win32-x64.tar.gz": tar,
SHA256SUMS: `${sha256(tar)} mosh-client-win32-x64.tar.gz\n`,
});
await execFileAsync(process.execPath, [script, "--platform=win32", "--arch=x64"], {
@@ -409,18 +406,14 @@ test("fetch-mosh-binaries downloads the pinned Windows standalone client", async
MOSH_BIN_RELEASE: "test",
MOSH_BIN_BASE_URL: baseUrl,
MOSH_BIN_RES_DIR: resDir,
MOSH_BIN_WINDOWS_LEGACY_URL: `${legacyBaseUrl}/mosh-client-win32-x64.exe`,
MOSH_BIN_WINDOWS_LEGACY_SHA256: sha256(flat),
CI: "true",
},
stdio: "pipe",
});
const dest = path.join(resDir, "win32-x64", "mosh-client.exe");
assert.equal(fs.existsSync(dest), true);
assert.equal(fs.readFileSync(dest, "utf8"), "working-windows-standalone");
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls")), false);
assert.equal(fs.existsSync(path.join(resDir, "win32-x64", "terminfo")), false);
assert.equal(fs.readFileSync(path.join(resDir, "win32-x64", "mosh-client.exe"), "utf8"), "exe");
assert.equal(fs.readFileSync(path.join(resDir, "win32-x64", "mosh-client-win32-x64-dlls", "cygwin1.dll"), "utf8"), "dll");
assert.equal(fs.readFileSync(path.join(resDir, "win32-x64", "terminfo", "x", "xterm-256color"), "utf8"), "terminfo");
});
test("fetch-mosh-binaries falls back to the legacy flat asset for older releases", async (t) => {