-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: propagate SANDBOX_NAME to telegram bridge and resolve openshell path #222
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e8a2bbb
fix: propagate sandbox name to bridge and resolve openshell path
brianwtaylor e037bfa
fix: validate resolveOpenshell returns absolute path
brianwtaylor e1e7e46
fix: pass default sandbox name from registry to start-services.sh
brianwtaylor 78b31be
test: add resolveOpenshell and SANDBOX_NAME defaulting tests
brianwtaylor 8be5329
fix: address CodeRabbit review comments
brianwtaylor 689b4ee
fix: harden HOME fallback and make SANDBOX_NAME tests hermetic
brianwtaylor 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,49 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const { execSync } = require("child_process"); | ||
| const fs = require("fs"); | ||
|
|
||
| /** | ||
| * Resolve the openshell binary path. | ||
| * | ||
| * Checks `command -v` first (must return an absolute path to prevent alias | ||
| * injection), then falls back to common installation directories. | ||
| * | ||
| * @param {object} [opts] DI overrides for testing | ||
| * @param {string|null} [opts.commandVResult] Mock result (undefined = run real command) | ||
| * @param {function} [opts.checkExecutable] (path) => boolean | ||
| * @param {string} [opts.home] HOME override | ||
| * @returns {string|null} Absolute path to openshell, or null if not found | ||
| */ | ||
| function resolveOpenshell(opts = {}) { | ||
| const home = opts.home ?? process.env.HOME; | ||
|
|
||
| // Step 1: command -v | ||
| if (opts.commandVResult === undefined) { | ||
| try { | ||
| const found = execSync("command -v openshell", { encoding: "utf-8" }).trim(); | ||
| if (found.startsWith("/")) return found; | ||
| } catch {} | ||
| } else if (opts.commandVResult && opts.commandVResult.startsWith("/")) { | ||
| return opts.commandVResult; | ||
| } | ||
|
|
||
| // Step 2: fallback candidates | ||
| const checkExecutable = opts.checkExecutable || ((p) => { | ||
| try { fs.accessSync(p, fs.constants.X_OK); return true; } catch { return false; } | ||
| }); | ||
|
|
||
| const candidates = [ | ||
| ...(home && home.startsWith("/") ? [`${home}/.local/bin/openshell`] : []), | ||
| "/usr/local/bin/openshell", | ||
| "/usr/bin/openshell", | ||
| ]; | ||
| for (const p of candidates) { | ||
| if (checkExecutable(p)) return p; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| module.exports = { resolveOpenshell }; |
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
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
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
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,119 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const { describe, it } = require("node:test"); | ||
| const assert = require("node:assert/strict"); | ||
| const { execSync } = require("child_process"); | ||
| const { resolveOpenshell } = require("../bin/lib/resolve-openshell"); | ||
|
|
||
| describe("service environment", () => { | ||
| describe("resolveOpenshell logic", () => { | ||
| it("returns command -v result when absolute path", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ commandVResult: "/usr/bin/openshell" }), | ||
| "/usr/bin/openshell" | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects non-absolute command -v result (alias)", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ commandVResult: "openshell", checkExecutable: () => false }), | ||
| null | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects alias definition from command -v", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ commandVResult: "alias openshell='echo pwned'", checkExecutable: () => false }), | ||
| null | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back to ~/.local/bin when command -v fails", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ | ||
| commandVResult: null, | ||
| checkExecutable: (p) => p === "/fakehome/.local/bin/openshell", | ||
| home: "/fakehome", | ||
| }), | ||
| "/fakehome/.local/bin/openshell" | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back to /usr/local/bin", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ | ||
| commandVResult: null, | ||
| checkExecutable: (p) => p === "/usr/local/bin/openshell", | ||
| }), | ||
| "/usr/local/bin/openshell" | ||
| ); | ||
| }); | ||
|
|
||
| it("falls back to /usr/bin", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ | ||
| commandVResult: null, | ||
| checkExecutable: (p) => p === "/usr/bin/openshell", | ||
| }), | ||
| "/usr/bin/openshell" | ||
| ); | ||
| }); | ||
|
|
||
| it("prefers ~/.local/bin over /usr/local/bin", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ | ||
| commandVResult: null, | ||
| checkExecutable: (p) => p === "/fakehome/.local/bin/openshell" || p === "/usr/local/bin/openshell", | ||
| home: "/fakehome", | ||
| }), | ||
| "/fakehome/.local/bin/openshell" | ||
| ); | ||
| }); | ||
|
|
||
| it("returns null when openshell not found anywhere", () => { | ||
| assert.equal( | ||
| resolveOpenshell({ | ||
| commandVResult: null, | ||
| checkExecutable: () => false, | ||
| }), | ||
| null | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("SANDBOX_NAME defaulting", () => { | ||
| it("start-services.sh preserves existing SANDBOX_NAME", () => { | ||
| const result = execSync( | ||
| 'bash -c \'SANDBOX_NAME="${NEMOCLAW_SANDBOX:-${SANDBOX_NAME:-default}}"; export SANDBOX_NAME; bash -c "echo \\$SANDBOX_NAME"\'', | ||
| { | ||
| encoding: "utf-8", | ||
| env: { ...process.env, NEMOCLAW_SANDBOX: "", SANDBOX_NAME: "my-box" }, | ||
| } | ||
| ).trim(); | ||
| assert.equal(result, "my-box"); | ||
| }); | ||
|
|
||
| it("start-services.sh uses NEMOCLAW_SANDBOX over SANDBOX_NAME", () => { | ||
| const result = execSync( | ||
| 'bash -c \'SANDBOX_NAME="${NEMOCLAW_SANDBOX:-${SANDBOX_NAME:-default}}"; export SANDBOX_NAME; bash -c "echo \\$SANDBOX_NAME"\'', | ||
| { | ||
| encoding: "utf-8", | ||
| env: { ...process.env, NEMOCLAW_SANDBOX: "from-env", SANDBOX_NAME: "old" }, | ||
| } | ||
| ).trim(); | ||
| assert.equal(result, "from-env"); | ||
| }); | ||
|
|
||
| it("start-services.sh falls back to default when both unset", () => { | ||
| const result = execSync( | ||
| 'bash -c \'SANDBOX_NAME="${NEMOCLAW_SANDBOX:-${SANDBOX_NAME:-default}}"; export SANDBOX_NAME; bash -c "echo \\$SANDBOX_NAME"\'', | ||
| { | ||
| encoding: "utf-8", | ||
| env: { ...process.env, NEMOCLAW_SANDBOX: "", SANDBOX_NAME: "" }, | ||
| } | ||
| ).trim(); | ||
| assert.equal(result, "default"); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.