-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathlaunchd-recovery-policy.test.ts
More file actions
137 lines (127 loc) · 4.58 KB
/
Copy pathlaunchd-recovery-policy.test.ts
File metadata and controls
137 lines (127 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { describe, expect, it } from "vitest";
import {
decideLaunchdRecovery,
detectStaleLaunchdSession,
} from "../../apps/desktop/main/lifecycle/launchd-recovery-policy";
describe("launchd recovery policy", () => {
it("treats old Electron metadata as stale after the threshold", () => {
const writtenAt = new Date(Date.now() - 10 * 60 * 1000).toISOString();
const result = detectStaleLaunchdSession({
metadata: {
writtenAt,
electronPid: 123,
controllerPort: 50800,
openclawPort: 18790,
webPort: 50810,
nexuHome: "/tmp/nexu-home",
isDev: false,
},
isElectronAlive: false,
});
expect(result.stale).toBe(true);
expect(result.reason).toContain("Stale session detected");
});
it("tears down packaged services when runtime identity path changes", () => {
const result = decideLaunchdRecovery({
recovered: {
writtenAt: new Date().toISOString(),
electronPid: 123,
controllerPort: 50800,
openclawPort: 18790,
webPort: 50810,
nexuHome: "/Users/test/.nexu",
isDev: false,
appVersion: "0.1.11",
openclawStateDir:
"/Users/test/Library/Application Support/@nexu/desktop/runtime/openclaw/state",
userDataPath: "/Users/test/Library/Application Support/@nexu/desktop",
buildSource: "packaged",
runtimeIdentityPath: "/tmp/build-A/Nexu.app/Contents/Resources",
},
env: {
isDev: false,
appVersion: "0.1.11",
nexuHome: "/Users/test/.nexu",
openclawStateDir:
"/Users/test/Library/Application Support/@nexu/desktop/runtime/openclaw/state",
userDataPath: "/Users/test/Library/Application Support/@nexu/desktop",
buildSource: "packaged",
runtimeIdentityPath: "/tmp/build-B/Nexu.app/Contents/Resources",
},
anyRunning: true,
runningNexuHome: "/Users/test/.nexu",
defaultWebPort: 50810,
previousElectronAlive: true,
});
expect(result.action).toBe("teardown-stale-services");
expect(result.reason).toContain("runtimeIdentityPath");
});
it("tears down packaged services when recovered metadata is missing runtime identity path", () => {
const result = decideLaunchdRecovery({
recovered: {
writtenAt: new Date().toISOString(),
electronPid: 123,
controllerPort: 50800,
openclawPort: 18790,
webPort: 50810,
nexuHome: "/Users/test/.nexu",
isDev: false,
appVersion: "0.1.11",
openclawStateDir:
"/Users/test/Library/Application Support/@nexu/desktop/runtime/openclaw/state",
userDataPath: "/Users/test/Library/Application Support/@nexu/desktop",
buildSource: "packaged",
},
env: {
isDev: false,
appVersion: "0.1.11",
nexuHome: "/Users/test/.nexu",
openclawStateDir:
"/Users/test/Library/Application Support/@nexu/desktop/runtime/openclaw/state",
userDataPath: "/Users/test/Library/Application Support/@nexu/desktop",
buildSource: "packaged",
runtimeIdentityPath: "/tmp/build-B/Nexu.app/Contents/Resources",
},
anyRunning: true,
runningNexuHome: "/Users/test/.nexu",
defaultWebPort: 50810,
previousElectronAlive: true,
});
expect(result.action).toBe("teardown-stale-services");
expect(result.reason).toContain("runtimeIdentityPath missing");
});
it("reuses controller and openclaw ports when only Electron died", () => {
const result = decideLaunchdRecovery({
recovered: {
writtenAt: new Date().toISOString(),
electronPid: 123,
controllerPort: 50800,
openclawPort: 18790,
webPort: 50810,
nexuHome: "/Users/test/.nexu",
isDev: false,
appVersion: "0.1.11",
buildSource: "packaged",
runtimeIdentityPath: "/tmp/build-A/Nexu.app/Contents/Resources",
},
env: {
isDev: false,
appVersion: "0.1.11",
nexuHome: "/Users/test/.nexu",
buildSource: "packaged",
runtimeIdentityPath: "/tmp/build-A/Nexu.app/Contents/Resources",
},
anyRunning: true,
runningNexuHome: "/Users/test/.nexu",
defaultWebPort: 50999,
previousElectronAlive: false,
});
expect(result.action).toBe("reuse-ports");
if (result.action !== "reuse-ports") {
throw new Error("expected reuse-ports");
}
expect(result.effectivePorts.controllerPort).toBe(50800);
expect(result.effectivePorts.openclawPort).toBe(18790);
expect(result.effectivePorts.webPort).toBe(50999);
});
});