Files
SenMeshNet/electron/bridges/systemManager/serviceOps.test.cjs
zhaolei 2f9f8da48e
Some checks failed
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
Initial commit: NetMesh smart ops platform with 3D topology, inspection reports, RCA and AI ops assistant
2026-10-15 13:53:04 +08:00

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");
});