75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { createWindowsHelper } from "../../src/server/windowsHelper.js";
|
|
|
|
test("windows helper sends action and payload as JSON", async () => {
|
|
const calls = [];
|
|
const helper = createWindowsHelper({
|
|
helperPath: "scripts/windows/helper.ps1",
|
|
runner: async (command, args, options) => {
|
|
calls.push({ command, args, input: options.input });
|
|
return {
|
|
status: 0,
|
|
stdout: JSON.stringify({
|
|
success: true,
|
|
action: "status.get",
|
|
result: { proxifyre: "Running" },
|
|
}),
|
|
stderr: "",
|
|
};
|
|
},
|
|
});
|
|
|
|
const result = await helper.run("status.get", { service: "ProxiFyre" });
|
|
|
|
assert.deepEqual(result, {
|
|
success: true,
|
|
action: "status.get",
|
|
result: { proxifyre: "Running" },
|
|
});
|
|
assert.equal(calls[0].command, "pwsh");
|
|
assert.deepEqual(calls[0].args, [
|
|
"-NoProfile",
|
|
"-ExecutionPolicy",
|
|
"Bypass",
|
|
"-File",
|
|
"scripts/windows/helper.ps1",
|
|
]);
|
|
assert.deepEqual(JSON.parse(calls[0].input), {
|
|
action: "status.get",
|
|
payload: { service: "ProxiFyre" },
|
|
});
|
|
});
|
|
|
|
test("windows helper normalizes non-zero exit into structured error", async () => {
|
|
const helper = createWindowsHelper({
|
|
helperPath: "scripts/windows/helper.ps1",
|
|
runner: async () => ({
|
|
status: 1,
|
|
stdout: "",
|
|
stderr: "service failed",
|
|
}),
|
|
});
|
|
|
|
await assert.rejects(
|
|
() => helper.run("service.restart", { name: "proxifyre" }),
|
|
/Windows helper failed: service failed/,
|
|
);
|
|
});
|
|
|
|
test("windows helper rejects invalid JSON stdout", async () => {
|
|
const helper = createWindowsHelper({
|
|
helperPath: "scripts/windows/helper.ps1",
|
|
runner: async () => ({
|
|
status: 0,
|
|
stdout: "not-json",
|
|
stderr: "",
|
|
}),
|
|
});
|
|
|
|
await assert.rejects(
|
|
() => helper.run("status.get", {}),
|
|
/Windows helper returned invalid JSON/,
|
|
);
|
|
});
|