-
Notifications
You must be signed in to change notification settings - Fork 2.8k
test(e2e): migrate dashboard remote bind #5186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+142
−9
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os from "node:os"; | ||
|
|
||
| import { expect, test } from "../fixtures/e2e-test.ts"; | ||
|
|
||
| // Migrated from test/e2e/test-dashboard-remote-bind.sh. | ||
| // Branch validation provisions and onboards a real remote sandbox first; this | ||
| // test restarts only that sandbox's dashboard forward and proves the explicit | ||
| // remote-bind opt-in is honored without adding another harness. | ||
|
|
||
| const runDashboardRemoteBindTest = | ||
| process.env.NEMOCLAW_E2E_DASHBOARD_REMOTE_BIND === "1" ? test : test.skip; | ||
|
|
||
| function matchingForwardLine(output: string, sandboxName: string, dashboardPort: string): string { | ||
| return ( | ||
| output | ||
| .split("\n") | ||
| .map((line) => line.trim()) | ||
| .find((line) => line.includes(sandboxName) && line.includes(dashboardPort)) ?? "" | ||
| ); | ||
| } | ||
|
|
||
| function bindsAllInterfaces(line: string, dashboardPort: string): boolean { | ||
| return ( | ||
| line.includes(`0.0.0.0:${dashboardPort}`) || | ||
| line.includes(`*:${dashboardPort}`) || | ||
| new RegExp(`\\b0\\.0\\.0\\.0\\s+${dashboardPort}\\b`).test(line) | ||
| ); | ||
| } | ||
|
|
||
| function bindsLoopback(line: string, dashboardPort: string): boolean { | ||
| return ( | ||
| line.includes(`127.0.0.1:${dashboardPort}`) || | ||
| line.includes(`localhost:${dashboardPort}`) || | ||
| new RegExp(`\\b127\\.0\\.0\\.1\\s+${dashboardPort}\\b`).test(line) | ||
| ); | ||
| } | ||
|
|
||
| function remoteHostCandidate(): string { | ||
| const externalIpv4 = Object.values(os.networkInterfaces()) | ||
| .flat() | ||
| .find((iface) => iface && iface.family === "IPv4" && !iface.internal)?.address; | ||
| return process.env.NEMOCLAW_E2E_REMOTE_HOST || externalIpv4 || os.hostname(); | ||
| } | ||
|
|
||
| runDashboardRemoteBindTest( | ||
| "dashboard forward binds all interfaces when remote bind is explicitly requested", | ||
| async ({ artifacts, host, sandbox }) => { | ||
| const sandboxName = process.env.NEMOCLAW_SANDBOX_NAME || "e2e-test"; | ||
| const dashboardPort = process.env.NEMOCLAW_DASHBOARD_PORT || "18789"; | ||
| const remoteHost = remoteHostCandidate(); | ||
|
|
||
| await artifacts.writeJson("scenario.json", { | ||
| id: "dashboard-remote-bind", | ||
| runner: "vitest", | ||
| migratedFrom: "test/e2e/test-dashboard-remote-bind.sh", | ||
| boundary: "remote-dashboard-forward", | ||
| optIn: "NEMOCLAW_E2E_DASHBOARD_REMOTE_BIND=1", | ||
| sandboxName, | ||
| dashboardPort, | ||
| remoteHost, | ||
| }); | ||
|
|
||
| const cliProbe = await host.command( | ||
| "bash", | ||
| ["-lc", "command -v nemoclaw && command -v openshell"], | ||
| { | ||
| artifactName: "dashboard-remote-bind-cli-probe", | ||
| inheritEnv: true, | ||
| timeoutMs: 30_000, | ||
| }, | ||
| ); | ||
| expect(cliProbe.exitCode, `required CLI probe failed\n${cliProbe.stderr}`).toBe(0); | ||
| expect(cliProbe.stdout).toContain("nemoclaw"); | ||
| expect(cliProbe.stdout).toContain("openshell"); | ||
|
|
||
| await sandbox.openshell(["forward", "stop", dashboardPort], { | ||
| artifactName: "dashboard-remote-bind-forward-stop", | ||
| inheritEnv: true, | ||
| timeoutMs: 30_000, | ||
| }); | ||
|
|
||
| const connect = await host.nemoclaw([sandboxName, "connect"], { | ||
| artifactName: "dashboard-remote-bind-connect", | ||
| inheritEnv: true, | ||
| env: { | ||
| NEMOCLAW_DASHBOARD_BIND: "0.0.0.0", | ||
| }, | ||
| timeoutMs: 120_000, | ||
| }); | ||
| expect(connect.exitCode, `nemoclaw connect failed\n${connect.stderr}`).toBe(0); | ||
|
|
||
| const forwardList = await sandbox.openshell(["forward", "list"], { | ||
| artifactName: "dashboard-remote-bind-forward-list", | ||
| inheritEnv: true, | ||
| timeoutMs: 30_000, | ||
| }); | ||
| expect(forwardList.exitCode, `openshell forward list failed\n${forwardList.stderr}`).toBe(0); | ||
| await artifacts.writeText("forward-list.txt", forwardList.stdout); | ||
|
|
||
| const forwardLine = matchingForwardLine(forwardList.stdout, sandboxName, dashboardPort); | ||
| expect( | ||
| forwardLine, | ||
| `No OpenShell forward found for ${sandboxName} on ${dashboardPort}`, | ||
| ).not.toBe(""); | ||
| expect( | ||
| bindsLoopback(forwardLine, dashboardPort), | ||
| `Dashboard forward is still localhost-only; expected an all-interface bind: ${forwardLine}`, | ||
| ).toBe(false); | ||
| expect( | ||
| bindsAllInterfaces(forwardLine, dashboardPort), | ||
| `Could not prove dashboard forward uses 0.0.0.0:${dashboardPort}: ${forwardLine}`, | ||
| ).toBe(true); | ||
| }, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Escape
dashboardPortbefore injecting intoRegExppatterns.dashboardPortis env-derived and interpolated directly into regex sources, so metacharacters can change match behavior and make this scenario pass/fail incorrectly.Suggested fix
📝 Committable suggestion
🧰 Tools
🪛 ast-grep (0.43.0)
[warning] 28-28: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(
\\b0\\.0\\.0\\.0\\s+${dashboardPort}\\b)Note: [CWE-1333] Inefficient Regular Expression Complexity
(regexp-from-variable)
[warning] 36-36: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(
\\b127\\.0\\.0\\.1\\s+${dashboardPort}\\b)Note: [CWE-1333] Inefficient Regular Expression Complexity
(regexp-from-variable)
🤖 Prompt for AI Agents
Source: Linters/SAST tools