Files
Netcatty/scripts/test-packaged-ssh-ciphers.cjs
T
陈大猫 8d826594d3 fix(ssh): support ChaCha20 in Electron crypto runtimes (#3992)
* fix(ssh): support ChaCha20 in Electron crypto runtimes

* test(ssh): verify packaged cipher transport across platforms

* test(ssh): isolate unused Electron UI APIs in packaged transport harness

* test(ssh): isolate packaged dependency resolution from the checkout
2026-10-27 01:59:11 +08:00

38 lines
1.7 KiB
JavaScript

// Exercise shipped JS/dependencies with the same Electron runtime, headlessly.
// No BrowserWindow, real accounts, or external SSH hosts are involved.
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { spawnSync } = require("node:child_process");
const releaseDir = path.resolve(process.argv[2] || "release");
const archives = fs.readdirSync(releaseDir, { recursive: true })
.filter((entry) => path.basename(entry) === "app.asar")
.map((entry) => path.join(releaseDir, entry));
if (archives.length === 0) throw new Error("No packaged app.asar found");
for (const appRoot of archives) {
// Outside the checkout, a missing packaged dependency cannot resolve from
// the checkout's node_modules. Copy the paired unpacked payload as shipped.
const detachedDir = fs.mkdtempSync(path.join(os.tmpdir(), "netcatty-packaged-ssh-"));
try {
const detachedRoot = path.join(detachedDir, "app.asar");
fs.copyFileSync(appRoot, detachedRoot);
fs.cpSync(`${appRoot}.unpacked`, `${detachedRoot}.unpacked`, { recursive: true });
const env = {
...process.env,
NETCATTY_SSH_TEST_APP_ROOT: detachedRoot,
NETCATTY_SSH_TEST_RUNTIME: require("electron"),
};
delete env.NODE_PATH;
console.log(`Testing detached packaged SSH transport: ${appRoot}`);
const result = spawnSync(process.execPath, ["--test", "electron/bridges/sshChaChaTransport.test.cjs"], {
env,
stdio: "inherit",
});
if (result.error) throw result.error;
if (result.status !== 0) throw new Error(`Packaged SSH transport tests failed (${result.status})`);
} finally {
fs.rmSync(detachedDir, { recursive: true, force: true });
}
}