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
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
const test = require("node:test");
|
|
const {
|
|
parseSystemctlListUnits,
|
|
parseServiceList,
|
|
sanitizeUnitName,
|
|
} = require("./serviceOps.cjs");
|
|
|
|
test("sanitizeUnitName rejects shell metacharacters", () => {
|
|
assert.equal(sanitizeUnitName("nginx.service"), "nginx.service");
|
|
assert.equal(sanitizeUnitName("user@1000.service"), "user@1000.service");
|
|
assert.equal(sanitizeUnitName("evil;rm -rf /"), null);
|
|
assert.equal(sanitizeUnitName(""), null);
|
|
});
|
|
|
|
test("parseSystemctlListUnits reads plain list-units rows", () => {
|
|
const sample = `
|
|
nginx.service loaded active running A high performance web server
|
|
● broken.service loaded failed failed Broken unit
|
|
cron.service loaded inactive dead Regular background program processing daemon
|
|
`;
|
|
const units = parseSystemctlListUnits(sample, "system");
|
|
assert.equal(units.length, 3);
|
|
assert.equal(units[0].name, "nginx.service");
|
|
assert.equal(units[0].activeState, "active");
|
|
assert.equal(units[1].name, "broken.service");
|
|
assert.equal(units[1].activeState, "failed");
|
|
assert.equal(units[2].activeState, "inactive");
|
|
});
|
|
|
|
test("parseSystemctlListUnits keeps units with an empty description", () => {
|
|
const sample = `
|
|
● broken.service loaded failed failed
|
|
quiet.service loaded active running
|
|
`;
|
|
const units = parseSystemctlListUnits(sample, "system");
|
|
assert.equal(units.length, 2);
|
|
assert.equal(units.find((u) => u.name === "broken.service")?.description, "");
|
|
assert.equal(units.find((u) => u.name === "quiet.service")?.activeState, "active");
|
|
});
|
|
|
|
test("parseServiceList merges system and user scopes and sorts failed first", () => {
|
|
const stdout = `
|
|
__NC_SERVICES_BEGIN__
|
|
__NC_SYSTEM__
|
|
broken.service loaded failed failed Broken
|
|
nginx.service loaded active running Nginx
|
|
__NC_USER__
|
|
podman.service loaded active running Podman
|
|
nginx.service loaded active running User nginx
|
|
__NC_SERVICES_END__
|
|
`;
|
|
const units = parseServiceList(stdout);
|
|
assert.equal(units[0].name, "broken.service");
|
|
assert.equal(units.find((u) => u.name === "nginx.service")?.scope, "system");
|
|
assert.equal(units.find((u) => u.name === "podman.service")?.scope, "user");
|
|
});
|