forked from NVIDIA/NemoClaw
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathprocess-recovery.test.ts
More file actions
92 lines (81 loc) · 2.73 KB
/
Copy pathprocess-recovery.test.ts
File metadata and controls
92 lines (81 loc) · 2.73 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
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it } from "vitest";
import {
classifySandboxForwardHealth,
resolveSandboxDashboardPort,
} from "../dist/lib/actions/sandbox/process-recovery.js";
describe("resolveSandboxDashboardPort", () => {
it("uses the recorded OpenClaw dashboard port for multi-sandbox recovery", () => {
expect(
resolveSandboxDashboardPort("beta", {
getSessionAgent: () => null,
getSandbox: () => ({ name: "beta", dashboardPort: 18790 }),
}),
).toBe(18790);
});
it("falls back to the default OpenClaw dashboard port when registry metadata is absent", () => {
expect(
resolveSandboxDashboardPort("legacy", {
getSessionAgent: () => null,
getSandbox: () => null,
}),
).toBe(18789);
});
it("uses the recorded dashboard port for non-OpenClaw agents when present", () => {
expect(
resolveSandboxDashboardPort("hermes-box", {
getSessionAgent: () => ({ forwardPort: 8642 }),
getSandbox: () => ({ name: "hermes-box", dashboardPort: 18790 }),
}),
).toBe(18790);
});
it("falls back to a non-OpenClaw agent's declared forward port without registry metadata", () => {
expect(
resolveSandboxDashboardPort("hermes-box", {
getSessionAgent: () => ({ forwardPort: 8642 }),
getSandbox: () => null,
}),
).toBe(8642);
});
it("ignores invalid agent forward ports and falls back to registry metadata", () => {
expect(
resolveSandboxDashboardPort("beta", {
getSessionAgent: () => ({ forwardPort: 0 }),
getSandbox: () => ({ name: "beta", dashboardPort: 18790 }),
}),
).toBe(18790);
});
});
describe("classifySandboxForwardHealth", () => {
it("returns true for a running forward owned by the target sandbox", () => {
expect(
classifySandboxForwardHealth(
[{ sandboxName: "beta", port: "18790", status: "running" }],
"beta",
"18790",
),
).toBe(true);
});
it("returns occupied when another sandbox owns the expected port", () => {
expect(
classifySandboxForwardHealth(
[{ sandboxName: "alpha", port: "18790", status: "running" }],
"beta",
"18790",
),
).toBe("occupied");
});
it("returns false for a missing forward", () => {
expect(classifySandboxForwardHealth([], "beta", "18790")).toBe(false);
});
it("returns false for a non-running forward owned by the target sandbox", () => {
expect(
classifySandboxForwardHealth(
[{ sandboxName: "beta", port: "18790", status: "dead" }],
"beta",
"18790",
),
).toBe(false);
});
});