aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/services/test_services.js
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/modules/services/test_services.js')
-rw-r--r--desktop/modules/services/test_services.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/desktop/modules/services/test_services.js b/desktop/modules/services/test_services.js
new file mode 100644
index 0000000..9f9be4e
--- /dev/null
+++ b/desktop/modules/services/test_services.js
@@ -0,0 +1,46 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Run: node desktop/modules/services/test_services.js
+// Both files are QML libraries, so their .pragma lines are stripped first.
+
+const fs = require("fs");
+const assert = require("assert");
+
+const lib = (f, names) => new Function(fs.readFileSync(f, "utf8").replace(/^\.pragma library$/m, "")
+ + `\nreturn { ${names} };`)();
+const A = lib(__dirname + "/../autostart/Autostart.js", "parse");
+const S = lib(__dirname + "/Services.js", "daemons, DAEMONS");
+
+const entries = A.parse([
+ 'hl.on("hyprland.start", function()',
+ ' hl.exec_cmd("[workspace special:dash silent] conky -c ~/.config/conky/conky.conf")',
+ ' -- hl.exec_cmd("hypridle")',
+ ' hl.exec_cmd("python3 -u ~/x/desktop-assistant/assistant.py >> \\"$XDG_RUNTIME_DIR/a.log\\" 2>&1")',
+ 'end)',
+].join("\n"));
+
+const d = Object.fromEntries(S.daemons(entries).map(x => [x.label, x]));
+assert.strictEqual(d.conky.start, "[workspace special:dash silent] conky -c ~/.config/conky/conky.conf");
+assert.strictEqual(d["desktop-assistant"].start,
+ 'python3 -u ~/x/desktop-assistant/assistant.py >> "$XDG_RUNTIME_DIR/a.log" 2>&1');
+assert.strictEqual(d.hypridle.start, ""); // commented out
+assert.strictEqual(d.notifyd.start, ""); // absent
+assert.deepStrictEqual(d.hypridle.args, ["-x", "hypridle"]);
+
+// Every -f pattern matches its line but not itself (the sh running pgrep).
+for (const [label, piece, [flag, pat]] of S.DAEMONS) {
+ if (flag !== "-f") continue;
+ const re = new RegExp(pat);
+ assert.ok(!re.test(pat), label + " matches its own pattern");
+ assert.ok(re.test(piece) || re.test("wl-paste --watch " + piece), label + " misses its line");
+}
+console.log("services ok");