Open-source, local-first AI agent for real work.
TypeScript agent-toolsai-agentbyokcoding-agentcross-platformdesktop-appdeveloper-toolselectronharnessknowledge-basellmwikilocal-firstmcpplugin-systemprivacy-firstskillstypescriptvettaworkflow-automation
import assert from "node:assert/strict";
import test from "node:test";
import { resolveMainBundleExternals, resolvePackagedNativeDependencies } from "./packaged-native-dependencies.mjs";
test("stages sherpa only for Windows targets", () => {
const windows = resolvePackagedNativeDependencies(new Set(["win32"]));
assert.ok(windows.required.includes("sherpa-onnx-win-x64"));
assert.ok(windows.asarUnpack.includes("node_modules/sherpa-onnx-win-x64/**/*"));
for (const platform of ["darwin", "linux"]) {
const result = resolvePackagedNativeDependencies(new Set([platform]));
assert.ok(!result.required.includes("sherpa-onnx-win-x64"));
assert.ok(!result.asarUnpack.some((pattern) => pattern.includes("sherpa")));
}
});
test("omits sherpa from a speech-disabled Windows artifact", () => {
const windows = resolvePackagedNativeDependencies(new Set(["win32"]), { speechInputEnabled: false });
assert.ok(!windows.required.includes("sherpa-onnx-win-x64"));
assert.ok(!windows.asarUnpack.some((pattern) => pattern.includes("sherpa")));
});
test("stages the node-pty wrapper everywhere and only matching-OS binary packages", () => {
// 壳是纯 JS、三平台都要;二进制包按 OS 分,串平台就等于把别的系统的 .node 带进产物。
const byPlatform = {
darwin: ["@lydell/node-pty-darwin-arm64", "@lydell/node-pty-darwin-x64"],
win32: ["@lydell/node-pty-win32-x64", "@lydell/node-pty-win32-arm64"],
linux: ["@lydell/node-pty-linux-x64"],
};
const all = Object.values(byPlatform).flat();
for (const [platform, expected] of Object.entries(byPlatform)) {
const result = resolvePackagedNativeDependencies(new Set([platform]));
assert.ok(result.required.includes("@lydell/node-pty"), `${platform} 产物缺少 node-pty 壳`);
for (const dep of expected) {
assert.ok(result.optional.includes(dep), `${platform} 产物缺少 ${dep}`);
assert.ok(result.asarUnpack.includes(`node_modules/${dep}/**/*`), `${dep} 的 pty.node 没有被 unpack`);
}
for (const dep of all.filter((name) => !expected.includes(name))) {
assert.ok(!result.optional.includes(dep), `${platform} 产物带上了别的系统的 ${dep}`);
}
}
});
test("stages every dependency the main bundle marks external", () => {
// staging 漏掉任何一个 external 都是「打包后应用起不来」级别的故障(ws 曾如此),
// 所以两个消费者必须来自同一份定义。
const externals = resolveMainBundleExternals();
const staged = new Set(
["darwin", "win32", "linux"].flatMap((platform) => {
const result = resolvePackagedNativeDependencies(new Set([platform]));
return [...result.required, ...result.optional];
}),
);
for (const dep of externals) {
assert.ok(staged.has(dep), `${dep} 被标成 external 却没有任何平台会 stage 它`);
}
});
test("keeps ws in every artifact and koffi only on Windows", () => {
for (const platform of ["darwin", "win32", "linux"]) {
const result = resolvePackagedNativeDependencies(new Set([platform]));
assert.ok(result.required.includes("ws"), `${platform} 产物缺少 ws`);
}
assert.ok(resolvePackagedNativeDependencies(new Set(["win32"])).required.includes("koffi"));
assert.ok(resolvePackagedNativeDependencies(new Set(["win32"])).asarUnpack.includes("node_modules/koffi/**/*"));
for (const platform of ["darwin", "linux"]) {
assert.ok(!resolvePackagedNativeDependencies(new Set([platform])).required.includes("koffi"));
}
});
test("keeps platform-specific packages external regardless of build target", () => {
// bundle 只构建一份:按平台过滤 external 会把原生模块打进 bundle 直接构建失败。
const externals = resolveMainBundleExternals();
assert.ok(externals.includes("koffi"));
assert.ok(externals.includes("sherpa-onnx-win-x64"));
assert.ok(!resolveMainBundleExternals({ speechInputEnabled: false }).includes("sherpa-onnx-win-x64"));
});