From 2e36216e62408a67354bb311becb5afdd66e3b53 Mon Sep 17 00:00:00 2001 From: Abhimanyu Kumar Date: Tue, 23 Jun 2026 13:04:26 +0530 Subject: [PATCH 1/3] test(e2e): add Deep Agents Code headless inference acceptance check (#5619) Add a skip-aware live check (07-deepagents-code-headless-inference.sh) that runs `dcode -n` inside a built Deep Agents Code sandbox and asserts: - config.toml routes through the managed https://inference.local endpoint - headless `dcode -n` returns a deterministic response or actionable provider/model error within a timeout (no hang/ambiguous failure) - no real provider/proxy credentials (nvapi-/sk-/xox.-/AKIA shapes) appear in config.toml, .env, .mcp.json, /tmp/nemoclaw-proxy-env.sh, or the captured output The script self-skips when the sandbox is not a Deep Agents Code sandbox, mirroring the existing 05/06 checks. A unit assertion in the image test registers the check and verifies its skip guard, prompt, inference route, and secret-scan content. The live green run requires a built sandbox plus the managed inference endpoint and is gated to the live e2e environment. Signed-off-by: Abhimanyu Kumar --- .../07-deepagents-code-headless-inference.sh | 79 +++++++++++++++++++ test/langchain-deepagents-code-image.test.ts | 20 +++++ 2 files changed, 99 insertions(+) create mode 100644 test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh diff --git a/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh b/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh new file mode 100644 index 00000000000..51ea07b98bd --- /dev/null +++ b/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Case: Deep Agents Code headless inference (#5619). +# +# Headless `dcode -n ""`, run inside a built Deep Agents Code sandbox, +# must route through the managed https://inference.local/v1 endpoint using the +# placeholder OpenAI-compatible key NemoClaw writes into config.toml, and either +# return a response or a deterministic, actionable provider/model error (never a +# hang or ambiguous failure). No real provider/proxy credentials may appear in +# config.toml, .env, .mcp.json, /tmp/nemoclaw-proxy-env.sh, or the captured output. + +set -euo pipefail + +SANDBOX_NAME="${SANDBOX_NAME:-${NEMOCLAW_SANDBOX_NAME:-e2e-cloud-onboard}}" +PREFIX="07-deepagents-code-headless-inference" +HEADLESS_TIMEOUT="${DEEPAGENTS_HEADLESS_TIMEOUT:-120}" + +ok() { printf '%s\n' "${PREFIX}: OK ($*)"; } +info() { printf '%s\n' "${PREFIX}: $*"; } +fail_test() { + printf '%s\n' "${PREFIX}: FAIL: $1" >&2 + FAILED=$((FAILED + 1)) +} +pass() { + ok "$1" + PASSED=$((PASSED + 1)) +} + +sandbox_exec() { + openshell sandbox exec --name "$SANDBOX_NAME" -- bash -c "$1" 2>&1 +} + +# Secret-shaped patterns that must never appear in managed config or output. +SECRET_PATTERN='nvapi-[A-Za-z0-9_-]{12,}|sk-[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{10,}|AKIA[A-Z0-9]{16}' + +PASSED=0 +FAILED=0 + +if ! sandbox_exec "test -d /sandbox/.deepagents && command -v dcode >/dev/null 2>&1" >/dev/null; then + info "SKIP: sandbox '${SANDBOX_NAME}' is not a Deep Agents Code sandbox" + exit 0 +fi + +info "Running Deep Agents Code headless inference checks in sandbox: $SANDBOX_NAME" + +# 1. config.toml points at the managed inference route, not a real provider host. +config_output="$(sandbox_exec "cat /sandbox/.deepagents/config.toml 2>/dev/null")" +if printf '%s' "$config_output" | grep -q "inference.local"; then + pass "config.toml routes through the managed inference.local endpoint" +else + fail_test "config.toml does not reference inference.local: ${config_output:0:200}" +fi + +# 2. Headless dcode -n returns a response or a deterministic, actionable error. +headless_output="$(sandbox_exec "cd /sandbox && timeout ${HEADLESS_TIMEOUT} dcode -n 'Reply with exactly one word: PONG'; echo \"DCODE_EXIT:\$?\"")" +dcode_exit="$(printf '%s' "$headless_output" | sed -n 's/.*DCODE_EXIT:\([0-9]\+\).*/\1/p' | tail -n1)" +if [ "${dcode_exit:-1}" = "124" ]; then + fail_test "dcode -n hung past ${HEADLESS_TIMEOUT}s (timeout); not a deterministic outcome" +elif [ -n "$(printf '%s' "$headless_output" | sed 's/DCODE_EXIT:[0-9]*//' | tr -d '[:space:]')" ]; then + pass "dcode -n produced a deterministic response or actionable error (exit ${dcode_exit:-unknown})" +else + fail_test "dcode -n produced no output and no actionable error" +fi + +# 3. No real secrets in managed config, runtime env files, or the captured output. +leak_scan="$(sandbox_exec "cat /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh 2>/dev/null")" +combined="${config_output} +${leak_scan} +${headless_output}" +if printf '%s' "$combined" | grep -Eq "$SECRET_PATTERN"; then + fail_test "secret-shaped value found in config/env/output (redacted from log)" +else + pass "no real provider/proxy credentials in config, runtime env, or output" +fi + +printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" +[ "$FAILED" -eq 0 ] || exit 1 diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index d1d1184c6b8..5172c71d332 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -268,6 +268,26 @@ describe("LangChain Deep Agents Code image contracts", () => { ); }); + it("ships a headless inference acceptance check for Deep Agents Code", () => { + const headlessCheck = fs.readFileSync( + path.join( + process.cwd(), + "test", + "e2e", + "e2e-cloud-experimental", + "checks", + "07-deepagents-code-headless-inference.sh", + ), + "utf8", + ); + + expect(headlessCheck).toContain("test -d /sandbox/.deepagents && command -v dcode"); + expect(headlessCheck).toContain("dcode -n 'Reply with exactly one word: PONG'"); + expect(headlessCheck).toContain("inference.local"); + expect(headlessCheck).toContain("nvapi-"); + expect(headlessCheck).toContain("/tmp/nemoclaw-proxy-env.sh"); + }); + it("hash-locks Deep Agents Code base image PyPI installs", () => { const baseDockerfile = readAgentFile("Dockerfile.base"); const requirementsLock = readAgentFile("requirements.lock"); From f0b27cbcc95fc83c6380c3f39a3a217a7d8660f1 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Thu, 25 Jun 2026 14:07:50 -0700 Subject: [PATCH 2/3] test(e2e): harden dcode headless check --- .../checks/07-deepagents-code-headless-inference.sh | 4 ++-- test/langchain-deepagents-code-image.test.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) mode change 100644 => 100755 test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh diff --git a/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh b/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh old mode 100644 new mode 100755 index 51ea07b98bd..220919b9955 --- a/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh +++ b/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh @@ -46,7 +46,7 @@ fi info "Running Deep Agents Code headless inference checks in sandbox: $SANDBOX_NAME" # 1. config.toml points at the managed inference route, not a real provider host. -config_output="$(sandbox_exec "cat /sandbox/.deepagents/config.toml 2>/dev/null")" +config_output="$(sandbox_exec "cat /sandbox/.deepagents/config.toml 2>/dev/null" || true)" if printf '%s' "$config_output" | grep -q "inference.local"; then pass "config.toml routes through the managed inference.local endpoint" else @@ -65,7 +65,7 @@ else fi # 3. No real secrets in managed config, runtime env files, or the captured output. -leak_scan="$(sandbox_exec "cat /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh 2>/dev/null")" +leak_scan="$(sandbox_exec "cat /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh 2>/dev/null" || true)" combined="${config_output} ${leak_scan} ${headless_output}" diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index 5172c71d332..396406dc45c 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -286,6 +286,10 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(headlessCheck).toContain("inference.local"); expect(headlessCheck).toContain("nvapi-"); expect(headlessCheck).toContain("/tmp/nemoclaw-proxy-env.sh"); + expect(headlessCheck).toContain('cat /sandbox/.deepagents/config.toml 2>/dev/null" || true'); + expect(headlessCheck).toContain( + 'cat /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh 2>/dev/null" || true', + ); }); it("hash-locks Deep Agents Code base image PyPI installs", () => { From de08c4f821832c598d1740f23c4842e89769a996 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Thu, 25 Jun 2026 18:52:32 -0700 Subject: [PATCH 3/3] test(e2e): harden dcode headless inference check Signed-off-by: Carlos Villela --- .../07-deepagents-code-headless-inference.sh | 153 ++++++++++++++---- test/langchain-deepagents-code-image.test.ts | 123 ++++++++++++-- 2 files changed, 229 insertions(+), 47 deletions(-) diff --git a/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh b/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh index 220919b9955..0b8daf74076 100755 --- a/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh +++ b/test/e2e/e2e-cloud-experimental/checks/07-deepagents-code-headless-inference.sh @@ -32,48 +32,135 @@ sandbox_exec() { openshell sandbox exec --name "$SANDBOX_NAME" -- bash -c "$1" 2>&1 } +sandbox_artifact_scan_command() { + cat <<'SCAN' +for path in /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh; do + if [ -e "$path" ]; then + cat "$path" 2>/dev/null || true + fi +done +while IFS= read -r -d "" artifact; do + cat "$artifact" 2>/dev/null || true +done < <(find /sandbox/.deepagents -maxdepth 3 -type f \( -name "*.log" -o -name "*.json" -o -name "*.toml" -o -name ".env" \) -print0 2>/dev/null) +SCAN +} + # Secret-shaped patterns that must never appear in managed config or output. -SECRET_PATTERN='nvapi-[A-Za-z0-9_-]{12,}|sk-[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{10,}|AKIA[A-Z0-9]{16}' +SECRET_PATTERN='nvapi-[A-Za-z0-9_-]{10,}|nvcf-[A-Za-z0-9_-]{10,}|ghp_[A-Za-z0-9_-]{10,}|github_pat_[A-Za-z0-9_]{30,}|sk-proj-[A-Za-z0-9_-]{10,}|sk-ant-[A-Za-z0-9_-]{10,}|sk-[A-Za-z0-9_-]{20,}|(xox[bpas]|xapp)-[A-Za-z0-9-]{10,}|A(K|S)IA[A-Z0-9]{16}|hf_[A-Za-z0-9]{10,}|glpat-[A-Za-z0-9_-]{10,}|gsk_[A-Za-z0-9]{10,}|pypi-[A-Za-z0-9_-]{10,}|bot[0-9]{8,10}:[A-Za-z0-9_-]{35}|[0-9]{8,10}:[A-Za-z0-9_-]{35}|[A-Za-z0-9]{24}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{27,}' PASSED=0 FAILED=0 -if ! sandbox_exec "test -d /sandbox/.deepagents && command -v dcode >/dev/null 2>&1" >/dev/null; then - info "SKIP: sandbox '${SANDBOX_NAME}' is not a Deep Agents Code sandbox" - exit 0 -fi +is_positive_integer() { + [[ "$1" =~ ^[1-9][0-9]*$ ]] +} -info "Running Deep Agents Code headless inference checks in sandbox: $SANDBOX_NAME" +contains_secret() { + grep -Eq "$SECRET_PATTERN" +} -# 1. config.toml points at the managed inference route, not a real provider host. -config_output="$(sandbox_exec "cat /sandbox/.deepagents/config.toml 2>/dev/null" || true)" -if printf '%s' "$config_output" | grep -q "inference.local"; then - pass "config.toml routes through the managed inference.local endpoint" -else - fail_test "config.toml does not reference inference.local: ${config_output:0:200}" -fi +references_managed_inference_route() { + grep -Eq 'https://inference\.local(/v1)?' +} -# 2. Headless dcode -n returns a response or a deterministic, actionable error. -headless_output="$(sandbox_exec "cd /sandbox && timeout ${HEADLESS_TIMEOUT} dcode -n 'Reply with exactly one word: PONG'; echo \"DCODE_EXIT:\$?\"")" -dcode_exit="$(printf '%s' "$headless_output" | sed -n 's/.*DCODE_EXIT:\([0-9]\+\).*/\1/p' | tail -n1)" -if [ "${dcode_exit:-1}" = "124" ]; then - fail_test "dcode -n hung past ${HEADLESS_TIMEOUT}s (timeout); not a deterministic outcome" -elif [ -n "$(printf '%s' "$headless_output" | sed 's/DCODE_EXIT:[0-9]*//' | tr -d '[:space:]')" ]; then - pass "dcode -n produced a deterministic response or actionable error (exit ${dcode_exit:-unknown})" -else - fail_test "dcode -n produced no output and no actionable error" -fi +references_managed_placeholder_key() { + grep -Eq 'api_key_env[[:space:]]*=[[:space:]]*"DEEPAGENTS_CODE_OPENAI_API_KEY"' +} + +is_local_execution_failure() { + grep -Eiq '(^|[[:space:]])(usage:|Traceback|SyntaxError|ImportError|ModuleNotFoundError|No module named|command not found|No such file or directory|Permission denied|invalid option)([[:space:]]|$)|DCODE_EXIT:12[67]' +} + +is_actionable_inference_error() { + grep -Eiq 'inference\.local|provider|model|NVIDIA|OpenAI|API key|authentication|authorization|unauthorized|forbidden|rate[ -]?limit|quota|HTTP[[:space:]]*(401|403|404|429|5[0-9]{2})|status[[:space:]]*(401|403|404|429|5[0-9]{2})' +} + +classify_headless_output() { + local dcode_exit="$1" + local headless_output="$2" + local payload + payload="$(printf '%s' "$headless_output" | sed 's/DCODE_EXIT:[0-9]*//g')" + + if [ "$dcode_exit" = "124" ]; then + printf '%s\n' "timeout" + return 1 + fi -# 3. No real secrets in managed config, runtime env files, or the captured output. -leak_scan="$(sandbox_exec "cat /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh 2>/dev/null" || true)" -combined="${config_output} + if [ -z "$(printf '%s' "$payload" | tr -d '[:space:]')" ]; then + printf '%s\n' "empty-output" + return 1 + fi + + if printf '%s' "$payload" | is_local_execution_failure; then + printf '%s\n' "local-execution-failure" + return 1 + fi + + if printf '%s' "$payload" | grep -Eiq '(^|[^[:alnum:]_])PONG([^[:alnum:]_]|$)'; then + printf '%s\n' "pong" + return 0 + fi + + if printf '%s' "$payload" | is_actionable_inference_error; then + printf '%s\n' "actionable-inference-error" + return 0 + fi + + printf '%s\n' "ambiguous-output" + return 1 +} + +main() { + if ! is_positive_integer "$HEADLESS_TIMEOUT"; then + fail_test "DEEPAGENTS_HEADLESS_TIMEOUT must be a positive integer" + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + exit 1 + fi + + if ! sandbox_exec "test -d /sandbox/.deepagents && command -v dcode >/dev/null 2>&1" >/dev/null; then + info "SKIP: sandbox '${SANDBOX_NAME}' is not a Deep Agents Code sandbox" + exit 0 + fi + + info "Running Deep Agents Code headless inference checks in sandbox: $SANDBOX_NAME" + + # 1. config.toml points at the managed inference route, not a real provider host. + config_output="$(sandbox_exec "cat /sandbox/.deepagents/config.toml 2>/dev/null" || true)" + if printf '%s' "$config_output" | references_managed_inference_route; then + pass "config.toml routes through the managed inference.local endpoint" + else + fail_test "config.toml does not reference the managed inference.local route (captured config redacted from log)" + fi + if printf '%s' "$config_output" | references_managed_placeholder_key; then + pass "config.toml uses the managed Deep Agents Code placeholder API key" + else + fail_test "config.toml does not use the managed placeholder API key env reference (captured config redacted from log)" + fi + + # 2. Headless dcode -n returns PONG or a deterministic, actionable inference error. + headless_output="$(sandbox_exec "cd /sandbox && timeout ${HEADLESS_TIMEOUT} dcode -n 'Reply with exactly one word: PONG'; echo \"DCODE_EXIT:\$?\"")" + dcode_exit="$(printf '%s' "$headless_output" | sed -n 's/.*DCODE_EXIT:\([0-9]\+\).*/\1/p' | tail -n1)" + if classification="$(classify_headless_output "${dcode_exit:-unknown}" "$headless_output")"; then + pass "dcode -n reached managed inference with ${classification} (exit ${dcode_exit:-unknown})" + else + fail_test "dcode -n did not produce PONG or an allowlisted provider/model/inference error (${classification}, exit ${dcode_exit:-unknown})" + fi + + # 3. No real secrets in managed config, runtime env files, artifacts, logs, or captured output. + leak_scan="$(sandbox_exec "$(sandbox_artifact_scan_command)" || true)" + combined="${config_output} ${leak_scan} ${headless_output}" -if printf '%s' "$combined" | grep -Eq "$SECRET_PATTERN"; then - fail_test "secret-shaped value found in config/env/output (redacted from log)" -else - pass "no real provider/proxy credentials in config, runtime env, or output" -fi + if printf '%s' "$combined" | contains_secret; then + fail_test "secret-shaped value found in config/env/output (redacted from log)" + else + pass "no real provider/proxy credentials in config, runtime env, or output" + fi -printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" -[ "$FAILED" -eq 0 ] || exit 1 + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + [ "$FAILED" -eq 0 ] || exit 1 +} + +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + main "$@" +fi diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index 266ad91824e..2bfd42aac04 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -9,6 +9,14 @@ import path from "node:path"; import { describe, expect, it } from "vitest"; const agentDir = path.join(process.cwd(), "agents", "langchain-deepagents-code"); +const headlessCheckPath = path.join( + process.cwd(), + "test", + "e2e", + "e2e-cloud-experimental", + "checks", + "07-deepagents-code-headless-inference.sh", +); const DCODE_CANONICAL_PATH = "/usr/local/bin:/opt/venv/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin"; @@ -36,6 +44,13 @@ function makeStartScriptFixture(tempDir: string): { return { envFile, messagingEnvFile, scriptPath }; } +function runHeadlessCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): string { + return execFileSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", headlessCheckPath], { + encoding: "utf8", + env: { ...process.env, ...env }, + }); +} + describe("LangChain Deep Agents Code image contracts", () => { it("hardens copied NemoClaw blueprints against sandbox-user mutation", () => { const dockerfile = readAgentFile("Dockerfile"); @@ -322,27 +337,107 @@ describe("LangChain Deep Agents Code image contracts", () => { }); it("ships a headless inference acceptance check for Deep Agents Code", () => { - const headlessCheck = fs.readFileSync( - path.join( - process.cwd(), - "test", - "e2e", - "e2e-cloud-experimental", - "checks", - "07-deepagents-code-headless-inference.sh", - ), - "utf8", - ); + const headlessCheck = fs.readFileSync(headlessCheckPath, "utf8"); expect(headlessCheck).toContain("test -d /sandbox/.deepagents && command -v dcode"); expect(headlessCheck).toContain("dcode -n 'Reply with exactly one word: PONG'"); - expect(headlessCheck).toContain("inference.local"); + expect(headlessCheck).toContain("https://inference\\.local(/v1)?"); + expect(headlessCheck).toContain("references_managed_placeholder_key"); + expect(headlessCheck).toContain( + 'api_key_env[[:space:]]*=[[:space:]]*"DEEPAGENTS_CODE_OPENAI_API_KEY"', + ); + expect(headlessCheck).toContain("classify_headless_output"); + expect(headlessCheck).toContain("DEEPAGENTS_HEADLESS_TIMEOUT must be a positive integer"); expect(headlessCheck).toContain("nvapi-"); + expect(headlessCheck).toContain("nvcf-"); + expect(headlessCheck).toContain("ghp_"); + expect(headlessCheck).toContain("github_pat_"); + expect(headlessCheck).toContain("sk-proj-"); + expect(headlessCheck).toContain("sk-ant-"); + expect(headlessCheck).toContain("xapp"); + expect(headlessCheck).toContain("A(K|S)IA"); expect(headlessCheck).toContain("/tmp/nemoclaw-proxy-env.sh"); + expect(headlessCheck).toContain("sandbox_artifact_scan_command"); expect(headlessCheck).toContain('cat /sandbox/.deepagents/config.toml 2>/dev/null" || true'); - expect(headlessCheck).toContain( - 'cat /sandbox/.deepagents/config.toml /sandbox/.deepagents/.env /sandbox/.deepagents/.mcp.json /tmp/nemoclaw-proxy-env.sh 2>/dev/null" || true', + expect(headlessCheck).toContain("find /sandbox/.deepagents -maxdepth 3 -type f"); + expect(headlessCheck).toContain('-name "*.log"'); + expect(headlessCheck).not.toContain("config_output:0:200"); + }); + + it("requires the managed inference route and placeholder key in Deep Agents Code config", () => { + expect( + runHeadlessCheckHelper( + 'printf "%s" "$CONFIG" | references_managed_inference_route && printf route', + { CONFIG: 'base_url = "https://inference.local/v1"' }, + ), + ).toBe("route"); + expect( + runHeadlessCheckHelper( + 'printf "%s" "$CONFIG" | references_managed_placeholder_key && printf key', + { CONFIG: 'api_key_env = "DEEPAGENTS_CODE_OPENAI_API_KEY"' }, + ), + ).toBe("key"); + }); + + it("classifies Deep Agents Code headless output without accepting local failures", () => { + const classify = (exitCode: string, output: string) => + runHeadlessCheckHelper( + [ + 'if classification="$(classify_headless_output "$DCODE_EXIT" "$HEADLESS_OUTPUT")"; then', + ' printf "pass:%s" "$classification";', + "else", + ' printf "fail:%s" "$classification";', + "fi", + ].join(" "), + { DCODE_EXIT: exitCode, HEADLESS_OUTPUT: output }, + ); + + expect(classify("0", "PONG\nDCODE_EXIT:0")).toBe("pass:pong"); + expect( + classify("1", "OpenAI provider returned HTTP 401 for inference.local\nDCODE_EXIT:1"), + ).toBe("pass:actionable-inference-error"); + expect(classify("124", "still waiting\nDCODE_EXIT:124")).toBe("fail:timeout"); + expect(classify("1", "usage: dcode [-h]\nDCODE_EXIT:1")).toBe("fail:local-execution-failure"); + expect(classify("1", "Traceback (most recent call last):\nDCODE_EXIT:1")).toBe( + "fail:local-execution-failure", ); + expect(classify("1", "something happened\nDCODE_EXIT:1")).toBe("fail:ambiguous-output"); + }); + + it("rejects unsafe headless timeout values before sandbox execution", () => { + const validate = (timeout: string) => + runHeadlessCheckHelper( + 'if is_positive_integer "$HEADLESS_TIMEOUT"; then printf valid; else printf invalid; fi', + { DEEPAGENTS_HEADLESS_TIMEOUT: timeout }, + ); + + expect(validate("120")).toBe("valid"); + expect(validate("0")).toBe("invalid"); + expect(validate("1; touch /tmp/nemoclaw-timeout-injection")).toBe("invalid"); + }); + + it("detects representative secret families in headless inference artifacts", () => { + const detectsSecret = (token: string) => + runHeadlessCheckHelper( + 'if printf "%s" "$TOKEN" | contains_secret; then printf secret; else printf clean; fi', + { TOKEN: token }, + ); + const secretSamples = [ + "nvapi-" + "A".repeat(10), + "nvcf-" + "A".repeat(10), + "ghp_" + "A".repeat(10), + "github_pat_" + "A".repeat(30), + "sk-proj-" + "A".repeat(10), + "sk-ant-" + "A".repeat(10), + "sk-" + "A".repeat(20), + "xapp-" + "A".repeat(10), + "ASIA" + "A".repeat(16), + ]; + + for (const sample of secretSamples) { + expect(detectsSecret(sample)).toBe("secret"); + } + expect(detectsSecret("managed-placeholder-key")).toBe("clean"); }); it("hash-locks Deep Agents Code base image PyPI installs", () => {