Skip to content

Commit 623d878

Browse files
committed
test(sandbox): source proxy vars from nemoclaw-start.sh instead of duplicating
extractProxyVars now uses sed to extract the PROXY_HOST/PROXY_PORT/HTTP_PROXY/ HTTPS_PROXY/NO_PROXY block directly from scripts/nemoclaw-start.sh and runs it in a minimal bash wrapper. This ensures that if the proxy configuration in nemoclaw-start.sh changes (different defaults, new variables, different NO_PROXY entries), the tests will catch the regression rather than passing against stale duplicated logic. All 17 tests pass. Addresses CodeRabbit nitpick in PR #704.
1 parent 88e573a commit 623d878

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

‎test/service-env.test.js‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,30 @@ describe("service environment", () => {
105105
// proxy and does not attempt to resolve DNS locally inside the sandbox.
106106

107107
function extractProxyVars(env = {}) {
108-
// Write the proxy-variable snippet from nemoclaw-start.sh to a temp script
109-
// and execute it so that bash variable assignments and expansions work
110-
// correctly without interference from JSON.stringify quote-escaping.
111-
const script = [
108+
// Source the proxy-variable block directly from scripts/nemoclaw-start.sh
109+
// so that tests always validate the actual implementation rather than a
110+
// hand-maintained copy. If the script changes its defaults or variable
111+
// names, these tests will catch the regression.
112+
//
113+
// Implementation: extract the proxy block (PROXY_HOST= through
114+
// export NO_PROXY=) via sed, then run it in a minimal bash wrapper that
115+
// echoes the three variables we care about.
116+
const scriptPath = join(import.meta.dirname, "../scripts/nemoclaw-start.sh");
117+
const proxyBlock = execFileSync(
118+
"sed",
119+
["-n", "/^PROXY_HOST=/,/^export NO_PROXY=/p", scriptPath],
120+
{ encoding: "utf-8" }
121+
);
122+
const wrapper = [
112123
"#!/usr/bin/env bash",
113-
'PROXY_HOST="${NEMOCLAW_PROXY_HOST:-10.200.0.1}"',
114-
'PROXY_PORT="${NEMOCLAW_PROXY_PORT:-3128}"',
115-
'HTTP_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"',
116-
'HTTPS_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"',
117-
'NO_PROXY="localhost,127.0.0.1,::1,inference.local,10.200.0.0/16"',
124+
proxyBlock.trimEnd(),
118125
'echo "HTTP_PROXY=${HTTP_PROXY}"',
119126
'echo "HTTPS_PROXY=${HTTPS_PROXY}"',
120127
'echo "NO_PROXY=${NO_PROXY}"',
121128
].join("\n");
122129
const tmpFile = join(tmpdir(), `nemoclaw-proxy-test-${process.pid}.sh`);
123130
try {
124-
writeFileSync(tmpFile, script, { mode: 0o700 });
131+
writeFileSync(tmpFile, wrapper, { mode: 0o700 });
125132
const out = execFileSync("bash", [tmpFile], {
126133
encoding: "utf-8",
127134
env: { ...process.env, ...env },

0 commit comments

Comments
 (0)