Files
NetMesh/electron/portableData.test.cjs
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

136 lines
4.2 KiB
JavaScript

const test = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { applyPortableDataDirectory } = require("./portableData.cjs");
function createApp({ executablePath, packaged = true }) {
const paths = {
exe: executablePath,
userData: path.join(path.dirname(executablePath), "system-user-data"),
sessionData: path.join(path.dirname(executablePath), "system-session-data"),
};
const writes = [];
return {
app: {
isPackaged: packaged,
getPath(name) {
return paths[name];
},
setPath(name, value) {
writes.push([name, value]);
paths[name] = value;
},
},
writes,
};
}
test("Windows zip build uses a data directory beside Netcatty.exe when present", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-portable-data-"));
test.after(() => fs.rmSync(root, { recursive: true, force: true }));
const executablePath = path.join(root, "Netcatty.exe");
const dataDirectory = path.join(root, "data");
fs.mkdirSync(dataDirectory);
const { app, writes } = createApp({ executablePath });
const result = applyPortableDataDirectory({
app,
env: {},
platform: "win32",
});
assert.deepEqual(result, {
dataDirectory,
source: "executable-directory",
});
assert.deepEqual(writes, [
["userData", dataDirectory],
["sessionData", dataDirectory],
]);
});
test("Windows single-file build uses data beside the portable launcher", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-portable-launcher-"));
test.after(() => fs.rmSync(root, { recursive: true, force: true }));
const launcherDirectory = path.join(root, "usb-drive");
const runtimeDirectory = path.join(root, "temporary-runtime");
const dataDirectory = path.join(launcherDirectory, "data");
fs.mkdirSync(dataDirectory, { recursive: true });
fs.mkdirSync(runtimeDirectory, { recursive: true });
const { app, writes } = createApp({
executablePath: path.join(runtimeDirectory, "Netcatty.exe"),
});
const result = applyPortableDataDirectory({
app,
env: { PORTABLE_EXECUTABLE_DIR: launcherDirectory },
platform: "win32",
});
assert.deepEqual(result, {
dataDirectory,
source: "portable-launcher-directory",
});
assert.deepEqual(writes, [
["userData", dataDirectory],
["sessionData", dataDirectory],
]);
});
test("Windows builds keep the system profile when no data directory is present", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-standard-data-"));
test.after(() => fs.rmSync(root, { recursive: true, force: true }));
const { app, writes } = createApp({
executablePath: path.join(root, "Netcatty.exe"),
});
const result = applyPortableDataDirectory({
app,
env: { PORTABLE_EXECUTABLE_DIR: root },
platform: "win32",
});
assert.equal(result, null);
assert.deepEqual(writes, []);
});
test("development and non-Windows builds ignore a neighboring data directory", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-other-platform-data-"));
test.after(() => fs.rmSync(root, { recursive: true, force: true }));
fs.mkdirSync(path.join(root, "data"));
for (const options of [
{ packaged: false, platform: "win32" },
{ packaged: true, platform: "darwin" },
{ packaged: true, platform: "linux" },
]) {
const { app, writes } = createApp({
executablePath: path.join(root, "Netcatty.exe"),
packaged: options.packaged,
});
const result = applyPortableDataDirectory({
app,
env: {},
platform: options.platform,
});
assert.equal(result, null);
assert.deepEqual(writes, []);
}
});
test("a file named data does not enable portable mode", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-data-file-"));
test.after(() => fs.rmSync(root, { recursive: true, force: true }));
fs.writeFileSync(path.join(root, "data"), "not a directory");
const { app, writes } = createApp({
executablePath: path.join(root, "Netcatty.exe"),
});
assert.equal(applyPortableDataDirectory({ app, env: {}, platform: "win32" }), null);
assert.deepEqual(writes, []);
});