Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/lib/state/gateway-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ describe("host gateway registry index", () => {
}
});

it("treats a zero persisted dashboard port as no dashboard instead of blocking the registry", () => {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-index-zero-port-"));
try {
const root = path.join(home, ".nemoclaw", "gateways", "9123");
fs.mkdirSync(root, { recursive: true });
fs.writeFileSync(
path.join(root, "sandboxes.json"),
JSON.stringify({
defaultSandbox: "instance-a",
sandboxes: {
"instance-a": {
name: "instance-a",
gatewayName: "nemoclaw-9123",
gatewayPort: 9123,
dashboardPort: 0,
},
},
}),
);

const entries = listHostGatewayRegistryEntries(home);

expect(entries).toHaveLength(1);
expect(entries[0].entry.name).toBe("instance-a");
expect(entries[0].entry.dashboardPort).toBeNull();
} finally {
fs.rmSync(home, { recursive: true, force: true });
}
});

it("rejects sandbox names that could escape a gateway-owned snapshot directory", () => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-gateway-index-name-"));
try {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/state/gateway-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,17 @@ function parseRegistry(filePath: string, raw: string): GatewayRegistryDocument {
value.dashboardPort !== null &&
(typeof value.dashboardPort !== "number" ||
!Number.isInteger(value.dashboardPort) ||
value.dashboardPort < 1 ||
value.dashboardPort < 0 ||
value.dashboardPort > 65535)
) {
throw stateError(
`${filePath} has an invalid dashboardPort for sandbox ${JSON.stringify(name)}`,
);
}
sandboxes[name] = value as GatewayRegistryEntry;
sandboxes[name] =
value.dashboardPort === 0
? { ...(value as GatewayRegistryEntry), dashboardPort: null }
: (value as GatewayRegistryEntry);
}
return {
...parsed,
Expand Down
Loading