Files
codewhale/npm/deepseek-tui/test/artifacts.test.js
T
Hunter Bown f8a3c6619e fix(npm): map openharmony platform to linux binaries (#1072)
Node's `os.platform()` returns `openharmony` on HarmonyPC and on
OpenHarmony's Linux ABI-compatible userspace. The npm wrapper's
platform-asset matrix only covered `linux` / `darwin` / `win32`,
so `npm i -g deepseek-tui` aborted on those hosts with

    Unsupported platform: openharmony. Supported platforms: …

even though the existing Linux x64 / arm64 binaries run unchanged
on that environment (OpenHarmony is Linux-ABI-compatible at the
ELF level).

Added a `PLATFORM_ALIASES = { openharmony: "linux" }` indirection
that resolves the raw platform name through the alias map before
the `ASSET_MATRIX` lookup. Genuinely unsupported platforms still
report the raw `os.platform()` value in the error so OS-mismatch
bug reports stay diagnostic.

Four pure-JS regression tests pin the behaviour:

- openharmony x64 → linux x64 binaries
- openharmony arm64 → linux arm64 binaries
- known platforms unchanged by the alias map
- freebsd still reports `Unsupported platform: freebsd`

Harvested from PR #1499 by @CrepuscularIRIS

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 01:39:44 -05:00

67 lines
2.0 KiB
JavaScript

const assert = require("node:assert/strict");
const path = require("node:path");
const test = require("node:test");
const os = require("os");
const ARTIFACTS_PATH = path.join(__dirname, "..", "scripts", "artifacts.js");
function withMockedOs(platform, arch, fn) {
const origPlatform = os.platform;
const origArch = os.arch;
os.platform = () => platform;
os.arch = () => arch;
delete require.cache[ARTIFACTS_PATH];
try {
return fn();
} finally {
os.platform = origPlatform;
os.arch = origArch;
delete require.cache[ARTIFACTS_PATH];
}
}
test("openharmony x64 resolves to linux x64 binaries", () => {
withMockedOs("openharmony", "x64", () => {
const { detectBinaryNames } = require(ARTIFACTS_PATH);
const result = detectBinaryNames();
assert.equal(result.deepseek, "deepseek-linux-x64");
assert.equal(result.tui, "deepseek-tui-linux-x64");
});
});
test("openharmony arm64 resolves to linux arm64 binaries", () => {
withMockedOs("openharmony", "arm64", () => {
const { detectBinaryNames } = require(ARTIFACTS_PATH);
const result = detectBinaryNames();
assert.equal(result.deepseek, "deepseek-linux-arm64");
assert.equal(result.tui, "deepseek-tui-linux-arm64");
});
});
test("genuinely unsupported platform throws with raw platform name", () => {
withMockedOs("freebsd", "x64", () => {
const { detectBinaryNames } = require(ARTIFACTS_PATH);
assert.throws(
() => detectBinaryNames(),
(err) => {
assert.match(err.message, /Unsupported platform: freebsd/);
return true;
},
);
});
});
test("known platforms are unaffected by alias map", () => {
for (const [platform, arch, expectedDeepseek] of [
["linux", "x64", "deepseek-linux-x64"],
["darwin", "arm64", "deepseek-macos-arm64"],
["win32", "x64", "deepseek-windows-x64.exe"],
]) {
withMockedOs(platform, arch, () => {
const { detectBinaryNames } = require(ARTIFACTS_PATH);
const result = detectBinaryNames();
assert.equal(result.deepseek, expectedDeepseek);
});
}
});