macroclaw 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/system-service.test.ts +17 -1
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
|
|
4
|
+
// Capture real fs functions before mocking
|
|
5
|
+
const realFs = await import("node:fs");
|
|
6
|
+
const { existsSync: realExistsSync, mkdirSync, readFileSync, rmSync, writeFileSync } = realFs;
|
|
7
|
+
const existsSync = realExistsSync;
|
|
8
|
+
|
|
5
9
|
// Mock child_process and os — safe since no other tests depend on real execSync or userInfo
|
|
6
10
|
const mockExecSync = mock((_cmd: string, _opts?: object) => "");
|
|
7
11
|
const mockUserInfo = mock(() => ({ username: "testuser", homedir: "/home/testuser", uid: 1000, gid: 1000, shell: "/bin/bash" }));
|
|
12
|
+
const mockExistsSync = mock((path: string) => realExistsSync(path));
|
|
8
13
|
|
|
9
14
|
mock.module("node:child_process", () => ({
|
|
10
15
|
execSync: (...args: unknown[]) => mockExecSync(args[0] as string, args[1] as object),
|
|
@@ -15,6 +20,14 @@ mock.module("node:os", () => ({
|
|
|
15
20
|
tmpdir: () => "/tmp",
|
|
16
21
|
}));
|
|
17
22
|
|
|
23
|
+
mock.module("node:fs", () => {
|
|
24
|
+
const result: Record<string, unknown> = {};
|
|
25
|
+
for (const [key, value] of Object.entries(realFs)) {
|
|
26
|
+
result[key] = key === "existsSync" ? (path: string) => mockExistsSync(path) : value;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
});
|
|
30
|
+
|
|
18
31
|
const { SystemServiceManager } = await import("./system-service");
|
|
19
32
|
|
|
20
33
|
function createManager(opts?: { platform?: string; home?: string }): InstanceType<typeof SystemServiceManager> {
|
|
@@ -29,8 +42,10 @@ const SYSTEMD_INACTIVE = "inactive";
|
|
|
29
42
|
beforeEach(() => {
|
|
30
43
|
mockExecSync.mockClear();
|
|
31
44
|
mockUserInfo.mockClear();
|
|
45
|
+
mockExistsSync.mockClear();
|
|
32
46
|
mockExecSync.mockImplementation((_cmd: string, _opts?: object) => "");
|
|
33
47
|
mockUserInfo.mockImplementation(() => ({ username: "testuser", homedir: "/home/testuser", uid: 1000, gid: 1000, shell: "/bin/bash" }));
|
|
48
|
+
mockExistsSync.mockImplementation((path: string) => realExistsSync(path));
|
|
34
49
|
});
|
|
35
50
|
|
|
36
51
|
describe("constructor", () => {
|
|
@@ -662,6 +677,7 @@ describe("status", () => {
|
|
|
662
677
|
if (cmd === "systemctl is-active macroclaw") throw new Error("not found");
|
|
663
678
|
return "";
|
|
664
679
|
});
|
|
680
|
+
mockExistsSync.mockReturnValue(false);
|
|
665
681
|
const mgr = createManager({ home: "/nonexistent" });
|
|
666
682
|
const s = mgr.status();
|
|
667
683
|
expect(s.installed).toBe(false);
|