From bbdd98108a2326db2dfc95f6fab827f96269ea7e Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Thu, 25 Jun 2026 22:41:34 -0700 Subject: [PATCH 1/8] test(e2e): validate dcode TUI startup Signed-off-by: Carlos Villela --- .../live/cloud-experimental-check-list.ts | 1 + ...platform-parity-cloud-experimental.test.ts | 16 ++ .../checks/09-deepagents-code-tui-startup.sh | 188 ++++++++++++++++++ test/langchain-deepagents-code-image.test.ts | 54 +++++ 4 files changed, 259 insertions(+) create mode 100755 test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh diff --git a/test/e2e-scenario/live/cloud-experimental-check-list.ts b/test/e2e-scenario/live/cloud-experimental-check-list.ts index def9415c42c..58338f89b30 100644 --- a/test/e2e-scenario/live/cloud-experimental-check-list.ts +++ b/test/e2e-scenario/live/cloud-experimental-check-list.ts @@ -5,6 +5,7 @@ export const DEEPAGENTS_CLOUD_EXPERIMENTAL_CHECKS = [ "test/e2e/e2e-cloud-experimental/checks/05-deepagents-code-landlock-readonly.sh", "test/e2e/e2e-cloud-experimental/checks/06-deepagents-code-python-egress.sh", "test/e2e/e2e-cloud-experimental/checks/08-deepagents-code-secret-boundary.sh", + "test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh", ] as const; export function cloudExperimentalChecksForOnboarding( diff --git a/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts b/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts index 7a97979be86..865e7def94c 100644 --- a/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts +++ b/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { spawnSync } from "node:child_process"; +import fs from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { DEEPAGENTS_CLOUD_EXPERIMENTAL_CHECKS } from "../live/cloud-experimental-check-list.ts"; import { assertRequiredCloudExperimentalResult, buildCloudExperimentalCommandEnv, @@ -62,6 +64,20 @@ describe("P0-E cloud-experimental parity guardrails", () => { ); }); + it("registers executable Deep Agents cloud-experimental checks", () => { + expect(DEEPAGENTS_CLOUD_EXPERIMENTAL_CHECKS).toEqual([ + "test/e2e/e2e-cloud-experimental/checks/05-deepagents-code-landlock-readonly.sh", + "test/e2e/e2e-cloud-experimental/checks/06-deepagents-code-python-egress.sh", + "test/e2e/e2e-cloud-experimental/checks/08-deepagents-code-secret-boundary.sh", + "test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh", + ]); + + for (const scriptPath of DEEPAGENTS_CLOUD_EXPERIMENTAL_CHECKS) { + const mode = fs.statSync(path.join(process.cwd(), scriptPath)).mode; + expect(mode & 0o111, `${scriptPath} must be executable`).not.toBe(0); + } + }); + it("builds a minimal cloud-experimental child environment", () => { const env = buildCloudExperimentalCommandEnv("deepagents-sandbox", "secret-key", { HOME: "/home/runner", diff --git a/test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh b/test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh new file mode 100755 index 00000000000..7034a2d84f0 --- /dev/null +++ b/test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh @@ -0,0 +1,188 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Case: Deep Agents Code interactive TUI startup (#5620). +# +# This live check runs against a real Deep Agents Code sandbox. It proves the +# interactive `dcode` TUI starts in a PTY, reaches a prompt-like startup state, +# exits after Ctrl-C, and leaves only sanitized, secret-free capture artifacts. +# +# shellcheck disable=SC2016 +# expect(1) Tcl: $env(...) and {...} are Tcl/sh expansion, not bash expansion. + +set -euo pipefail + +SANDBOX_NAME="${SANDBOX_NAME:-${NEMOCLAW_SANDBOX_NAME:-e2e-cloud-onboard}}" +PREFIX="09-deepagents-code-tui-startup" +TUI_TIMEOUT="${DEEPAGENTS_TUI_TIMEOUT:-90}" +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,}' + +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 +} + +is_positive_integer() { + [[ "$1" =~ ^[1-9][0-9]*$ ]] +} + +contains_secret() { + grep -Eq "$SECRET_PATTERN" +} + +strip_terminal_control_sequences() { + perl -pe 's/\x1b\][^\a]*(?:\a|\x1b\\)//g; s/\x1b\[[0-9;?]*[ -\/]*[@-~]//g; s/\r/\n/g' +} + +make_capture_dir() { + if [ -n "${DEEPAGENTS_TUI_CAPTURE_DIR:-}" ]; then + mkdir -p "$DEEPAGENTS_TUI_CAPTURE_DIR" + printf '%s\n' "$DEEPAGENTS_TUI_CAPTURE_DIR" + else + mktemp -d "${TMPDIR:-/tmp}/${PREFIX}.XXXXXX" + fi +} + +run_tui_expect() { + local raw_capture_file="$1" + env \ + NEMOCLAW_TUI_CAPTURE="$raw_capture_file" \ + NEMOCLAW_TUI_SANDBOX_NAME="$SANDBOX_NAME" \ + NEMOCLAW_TUI_TIMEOUT="$TUI_TIMEOUT" \ + expect <<'EXPECT' +set timeout $env(NEMOCLAW_TUI_TIMEOUT) +set sandbox $env(NEMOCLAW_TUI_SANDBOX_NAME) +set capture $env(NEMOCLAW_TUI_CAPTURE) +log_file -a $capture + +spawn openshell sandbox exec --name $sandbox --tty -- sh -lc {export TERM=xterm-256color; cd /sandbox; dcode; status=$?; printf "\nNEMOCLAW_TUI_EXIT:%s\n" "$status"} +expect { + -nocase -re {(deep agents|what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help|press enter)} { + puts "\nNEMOCLAW_TUI_READY" + send -- "\003" + } + timeout { + puts "\nNEMOCLAW_TUI_TIMEOUT" + send -- "\003" + exit 20 + } + eof { + puts "\nNEMOCLAW_TUI_EOF_BEFORE_READY" + exit 21 + } +} + +set timeout 20 +expect { + -re {NEMOCLAW_TUI_EXIT:([0-9]+)} { + puts "\nNEMOCLAW_TUI_EXIT_CAPTURED:$expect_out(1,string)" + exit 0 + } + timeout { + puts "\nNEMOCLAW_TUI_EXIT_TIMEOUT" + send -- "\003" + exit 22 + } + eof { + puts "\nNEMOCLAW_TUI_EOF_BEFORE_EXIT" + exit 23 + } +} +EXPECT +} + +assert_clean_exit_code() { + local plain_capture_file="$1" + local exit_code + exit_code="$(sed -n 's/.*NEMOCLAW_TUI_EXIT_CAPTURED:\([0-9]\+\).*/\1/p' "$plain_capture_file" | tail -n1)" + if [ -z "$exit_code" ]; then + fail_test "TUI capture did not include an exit-status marker" + return + fi + case "$exit_code" in + 0 | 1 | 130) pass "dcode TUI exited cleanly after Ctrl-C (exit ${exit_code})" ;; + *) fail_test "dcode TUI exited with unexpected status ${exit_code}" ;; + esac +} + +PASSED=0 +FAILED=0 + +main() { + if ! is_positive_integer "$TUI_TIMEOUT"; then + fail_test "DEEPAGENTS_TUI_TIMEOUT must be a positive integer" + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + exit 1 + fi + + if ! command -v expect >/dev/null 2>&1; then + fail_test "expect is required for the Deep Agents Code TUI startup check" + 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 + + local capture_dir raw_capture_file expect_log_file combined_capture_file plain_capture_file + capture_dir="$(make_capture_dir)" + raw_capture_file="${capture_dir}/${PREFIX}.raw.log" + expect_log_file="${capture_dir}/${PREFIX}.expect.log" + combined_capture_file="${capture_dir}/${PREFIX}.combined.log" + plain_capture_file="${capture_dir}/${PREFIX}.sanitized.log" + : >"$raw_capture_file" + : >"$expect_log_file" + + info "Running Deep Agents Code TUI startup check in sandbox: $SANDBOX_NAME" + info "Capture directory: $capture_dir" + + set +e + run_tui_expect "$raw_capture_file" >"$expect_log_file" 2>&1 + local expect_rc + expect_rc=$? + set -e + + cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file" + strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file" + + if [ "$expect_rc" -eq 0 ]; then + pass "finite expect harness reached startup and observed exit" + else + fail_test "finite expect harness exited ${expect_rc}" + fi + + if grep -q "NEMOCLAW_TUI_READY" "$plain_capture_file"; then + pass "dcode TUI rendered a usable startup prompt signature" + else + fail_test "dcode TUI prompt-ready marker missing from capture" + fi + + assert_clean_exit_code "$plain_capture_file" + + if contains_secret <"$plain_capture_file"; then + fail_test "secret-shaped value found in sanitized TUI capture" + else + pass "sanitized TUI capture does not contain secret-shaped values" + fi + + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + info "sanitized capture: ${plain_capture_file}" + [ "$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 8f05b44670b..d098be4fb51 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -24,6 +24,14 @@ const headlessCheckPath = path.join( "checks", "07-deepagents-code-headless-inference.sh", ); +const tuiStartupCheckPath = path.join( + process.cwd(), + "test", + "e2e", + "e2e-cloud-experimental", + "checks", + "09-deepagents-code-tui-startup.sh", +); const DCODE_CANONICAL_PATH = "/usr/local/bin:/opt/venv/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin"; @@ -125,6 +133,13 @@ function runHeadlessCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): s }); } +function runTuiStartupCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): string { + return execFileSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { + 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"); @@ -403,6 +418,7 @@ describe("LangChain Deep Agents Code image contracts", () => { ), "utf8", ); + const tuiStartupCheck = fs.readFileSync(tuiStartupCheckPath, "utf8"); expect(landlockCheck).toContain("test -d /sandbox/.deepagents && command -v dcode"); expect(landlockCheck).toContain("touch /sandbox/.deepagents/deepagents-landlock-test"); @@ -467,10 +483,24 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(secretBoundaryCheck).toContain("assert_no_rejected_interval_audit_logs"); expect(secretBoundaryCheck).toContain("assert_no_rejected_interval_network_logs"); expect(secretBoundaryCheck).toContain("sha256sum ${DEEPAGENTS_ENV_FILE@Q}"); + expect(tuiStartupCheck).toContain("Case: Deep Agents Code interactive TUI startup"); + expect(tuiStartupCheck).toContain("test -d /sandbox/.deepagents && command -v dcode"); + expect(tuiStartupCheck).toContain("expect <<'EXPECT'"); + expect(tuiStartupCheck).toContain("openshell sandbox exec --name $sandbox --tty"); + expect(tuiStartupCheck).toContain("cd /sandbox; dcode"); + expect(tuiStartupCheck).toContain("NEMOCLAW_TUI_READY"); + expect(tuiStartupCheck).toContain("NEMOCLAW_TUI_EXIT_CAPTURED"); + expect(tuiStartupCheck).toContain("DEEPAGENTS_TUI_TIMEOUT must be a positive integer"); + expect(tuiStartupCheck).toContain("strip_terminal_control_sequences"); + expect(tuiStartupCheck).toContain("${PREFIX}.sanitized.log"); + expect(tuiStartupCheck).toContain("secret-shaped value found in sanitized TUI capture"); + expect(tuiStartupCheck).toContain("nvapi-"); + expect(tuiStartupCheck).toContain("sk-"); expect(cloudExperimentalChecksForOnboarding("cloud-langchain-deepagents-code")).toEqual([ "test/e2e/e2e-cloud-experimental/checks/05-deepagents-code-landlock-readonly.sh", "test/e2e/e2e-cloud-experimental/checks/06-deepagents-code-python-egress.sh", "test/e2e/e2e-cloud-experimental/checks/08-deepagents-code-secret-boundary.sh", + "test/e2e/e2e-cloud-experimental/checks/09-deepagents-code-tui-startup.sh", ]); }); @@ -554,6 +584,30 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(validate("1; touch /tmp/nemoclaw-timeout-injection")).toBe("invalid"); }); + it("rejects unsafe TUI startup timeout values before sandbox execution", () => { + const validate = (timeout: string) => + runTuiStartupCheckHelper( + 'if is_positive_integer "$TUI_TIMEOUT"; then printf valid; else printf invalid; fi', + { DEEPAGENTS_TUI_TIMEOUT: timeout }, + ); + + expect(validate("90")).toBe("valid"); + expect(validate("0")).toBe("invalid"); + expect(validate("1; touch /tmp/nemoclaw-tui-timeout-injection")).toBe("invalid"); + }); + + it("detects representative secret families in TUI startup artifacts", () => { + const detectsSecret = (token: string) => + runTuiStartupCheckHelper( + 'if printf "%s" "$TOKEN" | contains_secret; then printf secret; else printf clean; fi', + { TOKEN: token }, + ); + + expect(detectsSecret("nvapi-" + "A".repeat(10))).toBe("secret"); + expect(detectsSecret("sk-" + "A".repeat(20))).toBe("secret"); + expect(detectsSecret("plain startup text")).toBe("clean"); + }); + it("detects representative secret families in headless inference artifacts", () => { const detectsSecret = (token: string) => runHeadlessCheckHelper( From c734e8691f42cda0fed606b75c3fd254d9707ee0 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Thu, 25 Jun 2026 23:43:30 -0700 Subject: [PATCH 2/8] test(e2e): harden dcode TUI startup artifacts Signed-off-by: Carlos Villela --- .../checks/10-deepagents-code-tui-startup.sh | 37 +++++++++-- test/langchain-deepagents-code-image.test.ts | 63 ++++++++++++++++++- 2 files changed, 93 insertions(+), 7 deletions(-) diff --git a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh index b2a5323a8f5..78a4ad427e9 100755 --- a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh +++ b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh @@ -17,6 +17,7 @@ SANDBOX_NAME="${SANDBOX_NAME:-${NEMOCLAW_SANDBOX_NAME:-e2e-cloud-onboard}}" PREFIX="10-deepagents-code-tui-startup" TUI_TIMEOUT="${DEEPAGENTS_TUI_TIMEOUT:-90}" 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,}' +SENSITIVE_CAPTURE_FILES=() ok() { printf '%s\n' "${PREFIX}: OK ($*)"; } info() { printf '%s\n' "${PREFIX}: $*"; } @@ -45,6 +46,13 @@ strip_terminal_control_sequences() { perl -pe 's/\x1b\][^\a]*(?:\a|\x1b\\)//g; s/\x1b\[[0-9;?]*[ -\/]*[@-~]//g; s/\r/\n/g' } +cleanup_sensitive_captures() { + local artifact + for artifact in "${SENSITIVE_CAPTURE_FILES[@]}"; do + [ -n "$artifact" ] && rm -f -- "$artifact" + done +} + make_capture_dir() { if [ -n "${DEEPAGENTS_TUI_CAPTURE_DIR:-}" ]; then mkdir -p "$DEEPAGENTS_TUI_CAPTURE_DIR" @@ -66,9 +74,10 @@ set sandbox $env(NEMOCLAW_TUI_SANDBOX_NAME) set capture $env(NEMOCLAW_TUI_CAPTURE) log_file -a $capture -spawn openshell sandbox exec --name $sandbox --tty -- sh -lc {export TERM=xterm-256color; cd /sandbox; dcode; status=$?; printf "\nNEMOCLAW_TUI_EXIT:%s\n" "$status"} +set cmd [list openshell sandbox exec --name $sandbox --tty -- sh -lc {export TERM=xterm-256color; cd /sandbox; dcode; status=$?; printf "\nNEMOCLAW_TUI_EXIT:%s\n" "$status"}] +spawn {*}$cmd expect { - -nocase -re {(deep agents|what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help|press enter)} { + -nocase -re {(what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help|press enter)} { puts "\nNEMOCLAW_TUI_READY" send -- "\003" } @@ -120,6 +129,8 @@ PASSED=0 FAILED=0 main() { + trap cleanup_sensitive_captures EXIT + if ! is_positive_integer "$TUI_TIMEOUT"; then fail_test "DEEPAGENTS_TUI_TIMEOUT must be a positive integer" printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" @@ -132,10 +143,24 @@ main() { 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 + local probe_output + if ! probe_output="$(sandbox_exec 'if test -d /sandbox/.deepagents && command -v dcode >/dev/null 2>&1; then printf "NEMOCLAW_DCODE_PROBE:deepagents\n"; else printf "NEMOCLAW_DCODE_PROBE:other\n"; fi')"; then + fail_test "unable to probe sandbox '${SANDBOX_NAME}' for Deep Agents Code markers" + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + exit 1 fi + case "$probe_output" in + *NEMOCLAW_DCODE_PROBE:deepagents*) ;; + *NEMOCLAW_DCODE_PROBE:other*) + info "SKIP: sandbox '${SANDBOX_NAME}' is not a Deep Agents Code sandbox" + exit 0 + ;; + *) + fail_test "unexpected sandbox probe output for '${SANDBOX_NAME}'" + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + exit 1 + ;; + esac local capture_dir raw_capture_file expect_log_file combined_capture_file plain_capture_file capture_dir="$(make_capture_dir)" @@ -143,6 +168,7 @@ main() { expect_log_file="${capture_dir}/${PREFIX}.expect.log" combined_capture_file="${capture_dir}/${PREFIX}.combined.log" plain_capture_file="${capture_dir}/${PREFIX}.sanitized.log" + SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file") : >"$raw_capture_file" : >"$expect_log_file" @@ -157,6 +183,7 @@ main() { cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file" strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file" + cleanup_sensitive_captures if [ "$expect_rc" -eq 0 ]; then pass "finite expect harness reached startup and observed exit" diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index 0583ac90be4..89f7e6c2445 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -117,12 +117,19 @@ function makeStartScriptFixture(tempDir: string): { } { const envFile = path.join(tempDir, "proxy-env.sh"); const scriptPath = path.join(tempDir, "start.sh"); - const fixture = readAgentFile("start.sh") + const original = readAgentFile("start.sh"); + expect(original).toContain("local target=/tmp/nemoclaw-proxy-env.sh"); + expect(original).toContain('tmp="$(mktemp /tmp/nemoclaw-proxy-env.XXXXXX)"'); + const fixture = original .replace("local target=/tmp/nemoclaw-proxy-env.sh", `local target="${envFile}"`) .replace( 'tmp="$(mktemp /tmp/nemoclaw-proxy-env.XXXXXX)"', `tmp="$(mktemp "${tempDir}/nemoclaw-proxy-env.XXXXXX")"`, ); + expect(fixture).toContain(`local target="${envFile}"`); + expect(fixture).toContain(`tmp="$(mktemp "${tempDir}/nemoclaw-proxy-env.XXXXXX")"`); + expect(fixture).not.toContain("local target=/tmp/nemoclaw-proxy-env.sh"); + expect(fixture).not.toContain('tmp="$(mktemp /tmp/nemoclaw-proxy-env.XXXXXX)"'); fs.writeFileSync(scriptPath, fixture, "utf8"); fs.chmodSync(scriptPath, 0o755); return { envFile, scriptPath }; @@ -448,12 +455,22 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(tuiStartupCheck).toContain("Case: Deep Agents Code interactive TUI startup"); expect(tuiStartupCheck).toContain("test -d /sandbox/.deepagents && command -v dcode"); expect(tuiStartupCheck).toContain("expect <<'EXPECT'"); - expect(tuiStartupCheck).toContain("openshell sandbox exec --name $sandbox --tty"); + expect(tuiStartupCheck).toContain( + "set cmd [list openshell sandbox exec --name $sandbox --tty -- sh -lc", + ); + expect(tuiStartupCheck).toContain("spawn {*}$cmd"); + expect(tuiStartupCheck).not.toContain("-nocase -re {(deep agents|"); + expect(tuiStartupCheck).toContain("NEMOCLAW_DCODE_PROBE:deepagents"); + expect(tuiStartupCheck).toContain("NEMOCLAW_DCODE_PROBE:other"); + expect(tuiStartupCheck).toContain("unable to probe sandbox"); + expect(tuiStartupCheck).toContain("unexpected sandbox probe output"); expect(tuiStartupCheck).toContain("cd /sandbox; dcode"); expect(tuiStartupCheck).toContain("NEMOCLAW_TUI_READY"); expect(tuiStartupCheck).toContain("NEMOCLAW_TUI_EXIT_CAPTURED"); expect(tuiStartupCheck).toContain("DEEPAGENTS_TUI_TIMEOUT must be a positive integer"); expect(tuiStartupCheck).toContain("strip_terminal_control_sequences"); + expect(tuiStartupCheck).toContain("trap cleanup_sensitive_captures EXIT"); + expect(tuiStartupCheck).toContain("cleanup_sensitive_captures"); expect(tuiStartupCheck).toContain("${PREFIX}.sanitized.log"); expect(tuiStartupCheck).toContain("secret-shaped value found in sanitized TUI capture"); expect(tuiStartupCheck).toContain("nvapi-"); @@ -587,6 +604,48 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(detectsSecret("plain startup text")).toBe("clean"); }); + it("removes raw TUI startup artifacts after writing the sanitized capture", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-")); + const rawCapture = path.join(tempDir, "raw.log"); + const expectLog = path.join(tempDir, "expect.log"); + const combinedCapture = path.join(tempDir, "combined.log"); + const sanitizedCapture = path.join(tempDir, "sanitized.log"); + + try { + const output = runTuiStartupCheckHelper( + [ + 'raw_capture_file="$RAW_CAPTURE"', + 'expect_log_file="$EXPECT_LOG"', + 'combined_capture_file="$COMBINED_CAPTURE"', + 'plain_capture_file="$SANITIZED_CAPTURE"', + 'SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file")', + 'printf "%s\\n" "$SECRET_TOKEN" >"$raw_capture_file"', + 'printf "%s\\n" "expect output" >"$expect_log_file"', + 'cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file"', + 'strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file"', + "cleanup_sensitive_captures", + 'for artifact in "$raw_capture_file" "$expect_log_file" "$combined_capture_file"; do if [ -e "$artifact" ]; then printf "leaked:%s" "$artifact"; exit 1; fi; done', + 'if [ -e "$plain_capture_file" ]; then printf sanitized; else printf missing; fi', + ].join("; "), + { + COMBINED_CAPTURE: combinedCapture, + EXPECT_LOG: expectLog, + RAW_CAPTURE: rawCapture, + SANITIZED_CAPTURE: sanitizedCapture, + SECRET_TOKEN: `sk-${"A".repeat(20)}`, + }, + ); + + expect(output).toBe("sanitized"); + expect(fs.existsSync(rawCapture)).toBe(false); + expect(fs.existsSync(expectLog)).toBe(false); + expect(fs.existsSync(combinedCapture)).toBe(false); + expect(fs.existsSync(sanitizedCapture)).toBe(true); + } finally { + fs.rmSync(tempDir, { force: true, recursive: true }); + } + }); + it("detects representative secret families in headless inference artifacts", () => { const detectsSecret = (token: string) => runHeadlessCheckHelper( From c29bdef4ded95c6bd6c3e4054481df78ecd4cd9b Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 26 Jun 2026 08:52:02 -0700 Subject: [PATCH 3/8] test(e2e): address dcode TUI review feedback --- .../live/cloud-experimental-checks.ts | 27 ++++- ...platform-parity-cloud-experimental.test.ts | 17 +++ .../checks/10-deepagents-code-tui-startup.sh | 72 +++++++++++- test/langchain-deepagents-code-image.test.ts | 111 ++++++++++++++++++ 4 files changed, 216 insertions(+), 11 deletions(-) diff --git a/test/e2e-scenario/live/cloud-experimental-checks.ts b/test/e2e-scenario/live/cloud-experimental-checks.ts index c5b1b20cf6a..1fee68715ad 100644 --- a/test/e2e-scenario/live/cloud-experimental-checks.ts +++ b/test/e2e-scenario/live/cloud-experimental-checks.ts @@ -12,6 +12,24 @@ import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); const REQUIRED_CHECK_SKIP_PATTERN = /(^|\n).*\bSKIP\b/i; +export type CloudExperimentalChecksEvidence = { + scenarioId: string; + sandboxName: string; + checkScripts: readonly string[]; +}; + +export function buildCloudExperimentalChecksEvidence( + scenarioId: string, + sandboxName: string, + checkScripts: readonly string[], +): CloudExperimentalChecksEvidence { + return { + scenarioId, + sandboxName, + checkScripts, + }; +} + export function buildCloudExperimentalCommandEnv( sandboxName: string, apiKey: string, @@ -74,11 +92,10 @@ export async function runE2eCloudExperimentalChecks( context: Pick, ): Promise { const apiKey = context.secrets.optional("NVIDIA_INFERENCE_API_KEY") ?? ""; - await context.artifacts.writeJson("e2e-cloud-experimental-checks.json", { - scenarioId, - sandboxName, - checkScripts, - }); + await context.artifacts.writeJson( + "e2e-cloud-experimental-checks.json", + buildCloudExperimentalChecksEvidence(scenarioId, sandboxName, checkScripts), + ); await Promise.resolve( checkScripts.length > 0 ? assertDeepAgentsRuntimeObserved(sandboxName, context) : undefined, ); diff --git a/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts b/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts index 6fa492f8991..b468bbba31a 100644 --- a/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts +++ b/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts @@ -10,6 +10,7 @@ import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; import { DEEPAGENTS_CLOUD_EXPERIMENTAL_CHECKS } from "../live/cloud-experimental-check-list.ts"; import { assertRequiredCloudExperimentalResult, + buildCloudExperimentalChecksEvidence, buildCloudExperimentalCommandEnv, } from "../live/cloud-experimental-checks.ts"; @@ -79,6 +80,22 @@ describe("P0-E cloud-experimental parity guardrails", () => { } }); + it("documents Deep Agents check scripts in generated launch/QA evidence", () => { + const evidence = buildCloudExperimentalChecksEvidence( + "cloud-langchain-deepagents-code", + "deepagents-sandbox", + DEEPAGENTS_CLOUD_EXPERIMENTAL_CHECKS, + ); + + expect(evidence).toMatchObject({ + scenarioId: "cloud-langchain-deepagents-code", + sandboxName: "deepagents-sandbox", + }); + expect(evidence.checkScripts).toContain( + "test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh", + ); + }); + it("builds a minimal cloud-experimental child environment", () => { const env = buildCloudExperimentalCommandEnv("deepagents-sandbox", "secret-key", { HOME: "/home/runner", diff --git a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh index 78a4ad427e9..6cfb0df06ab 100755 --- a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh +++ b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh @@ -16,7 +16,11 @@ set -euo pipefail SANDBOX_NAME="${SANDBOX_NAME:-${NEMOCLAW_SANDBOX_NAME:-e2e-cloud-onboard}}" PREFIX="10-deepagents-code-tui-startup" TUI_TIMEOUT="${DEEPAGENTS_TUI_TIMEOUT:-90}" -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,}' +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,}|\bbot[0-9]{8,10}:[A-Za-z0-9_-]{35}\b|\b[0-9]{8,10}:[A-Za-z0-9_-]{35}\b|\b[A-Za-z0-9]{24}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{27,}\b)' +CONTEXT_SECRET_VALUE_PATTERN='[A-Za-z0-9_.+\/=-]{10,}' +# Upstream dcode does not expose a stable machine-readable TUI ready marker. +# Keep this localized heuristic prompt-shaped; do not match banner-only text. +TUI_READY_PATTERN='(what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help|press enter)' SENSITIVE_CAPTURE_FILES=() ok() { printf '%s\n' "${PREFIX}: OK ($*)"; } @@ -39,7 +43,53 @@ is_positive_integer() { } contains_secret() { - grep -Eq "$SECRET_PATTERN" + NEMOCLAW_TOKEN_SECRET_PATTERN="$SECRET_PATTERN" \ + NEMOCLAW_CONTEXT_SECRET_VALUE_PATTERN="$CONTEXT_SECRET_VALUE_PATTERN" \ + perl -0ne ' + BEGIN { + $token_pattern = $ENV{"NEMOCLAW_TOKEN_SECRET_PATTERN"}; + $context_value_pattern = $ENV{"NEMOCLAW_CONTEXT_SECRET_VALUE_PATTERN"}; + } + if ( + /$token_pattern/ || + /Bearer\s+$context_value_pattern/i || + /(?:_KEY|API_KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL)[=: ]["'\''"]?$context_value_pattern/i + ) { + $found = 1; + } + END { exit($found ? 0 : 1) } + ' +} + +redact_secrets() { + NEMOCLAW_TOKEN_SECRET_PATTERN="$SECRET_PATTERN" \ + NEMOCLAW_CONTEXT_SECRET_VALUE_PATTERN="$CONTEXT_SECRET_VALUE_PATTERN" \ + perl -0pe ' + BEGIN { + $token_pattern = $ENV{"NEMOCLAW_TOKEN_SECRET_PATTERN"}; + $context_value_pattern = $ENV{"NEMOCLAW_CONTEXT_SECRET_VALUE_PATTERN"}; + } + s/$token_pattern/[REDACTED_SECRET]/g; + s/(Bearer\s+)$context_value_pattern/${1}[REDACTED_SECRET]/gi; + s/((?:_KEY|API_KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL)[=: ]["'\''"]?)$context_value_pattern/${1}[REDACTED_SECRET]/gi; + ' +} + +redact_secrets_in_file() { + local target_file="$1" + local redacted_file + redacted_file="${target_file}.redacted.$$" + if redact_secrets <"$target_file" >"$redacted_file"; then + mv -- "$redacted_file" "$target_file" + else + rm -f -- "$redacted_file" + fail_test "unable to redact sanitized TUI capture" + return 1 + fi +} + +is_tui_ready_capture() { + grep -Eiq "$TUI_READY_PATTERN" } strip_terminal_control_sequences() { @@ -66,18 +116,20 @@ run_tui_expect() { local raw_capture_file="$1" env \ NEMOCLAW_TUI_CAPTURE="$raw_capture_file" \ + NEMOCLAW_TUI_READY_PATTERN="$TUI_READY_PATTERN" \ NEMOCLAW_TUI_SANDBOX_NAME="$SANDBOX_NAME" \ NEMOCLAW_TUI_TIMEOUT="$TUI_TIMEOUT" \ expect <<'EXPECT' set timeout $env(NEMOCLAW_TUI_TIMEOUT) set sandbox $env(NEMOCLAW_TUI_SANDBOX_NAME) set capture $env(NEMOCLAW_TUI_CAPTURE) +set ready_pattern $env(NEMOCLAW_TUI_READY_PATTERN) log_file -a $capture set cmd [list openshell sandbox exec --name $sandbox --tty -- sh -lc {export TERM=xterm-256color; cd /sandbox; dcode; status=$?; printf "\nNEMOCLAW_TUI_EXIT:%s\n" "$status"}] spawn {*}$cmd expect { - -nocase -re {(what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help|press enter)} { + -nocase -re $ready_pattern { puts "\nNEMOCLAW_TUI_READY" send -- "\003" } @@ -120,7 +172,7 @@ assert_clean_exit_code() { return fi case "$exit_code" in - 0 | 1 | 130) pass "dcode TUI exited cleanly after Ctrl-C (exit ${exit_code})" ;; + 0 | 130) pass "dcode TUI exited cleanly after Ctrl-C (exit ${exit_code})" ;; *) fail_test "dcode TUI exited with unexpected status ${exit_code}" ;; esac } @@ -183,6 +235,14 @@ main() { cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file" strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file" + local secret_detected=0 + if contains_secret <"$plain_capture_file"; then + secret_detected=1 + redact_secrets_in_file "$plain_capture_file" || true + if contains_secret <"$plain_capture_file"; then + fail_test "secret-shaped value remained after redacting sanitized TUI capture" + fi + fi cleanup_sensitive_captures if [ "$expect_rc" -eq 0 ]; then @@ -191,7 +251,7 @@ main() { fail_test "finite expect harness exited ${expect_rc}" fi - if grep -q "NEMOCLAW_TUI_READY" "$plain_capture_file"; then + if grep -q "NEMOCLAW_TUI_READY" "$plain_capture_file" && is_tui_ready_capture <"$plain_capture_file"; then pass "dcode TUI rendered a usable startup prompt signature" else fail_test "dcode TUI prompt-ready marker missing from capture" @@ -199,7 +259,7 @@ main() { assert_clean_exit_code "$plain_capture_file" - if contains_secret <"$plain_capture_file"; then + if [ "$secret_detected" -eq 1 ]; then fail_test "secret-shaped value found in sanitized TUI capture" else pass "sanitized TUI capture does not contain secret-shaped values" diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index 89f7e6c2445..56231cee8d2 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -149,6 +149,16 @@ function runTuiStartupCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): }); } +function runTuiStartupCheckHelperResult( + snippet: string, + env: NodeJS.ProcessEnv = {}, +): SpawnSyncReturns { + return spawnSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { + 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"); @@ -469,6 +479,8 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(tuiStartupCheck).toContain("NEMOCLAW_TUI_EXIT_CAPTURED"); expect(tuiStartupCheck).toContain("DEEPAGENTS_TUI_TIMEOUT must be a positive integer"); expect(tuiStartupCheck).toContain("strip_terminal_control_sequences"); + expect(tuiStartupCheck).toContain("is_tui_ready_capture"); + expect(tuiStartupCheck).toContain("redact_secrets_in_file"); expect(tuiStartupCheck).toContain("trap cleanup_sensitive_captures EXIT"); expect(tuiStartupCheck).toContain("cleanup_sensitive_captures"); expect(tuiStartupCheck).toContain("${PREFIX}.sanitized.log"); @@ -592,6 +604,43 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(validate("1; touch /tmp/nemoclaw-tui-timeout-injection")).toBe("invalid"); }); + it("matches prompt-shaped TUI readiness text without accepting banner-only startup text", () => { + const readiness = (capture: string) => + runTuiStartupCheckHelper( + 'if printf "%s" "$CAPTURE" | is_tui_ready_capture; then printf ready; else printf not-ready; fi', + { CAPTURE: capture }, + ); + + expect(readiness("Deep Agents Code starting...\nLoading tools...")).toBe("not-ready"); + expect(readiness("What would you like to do next?")).toBe("ready"); + expect(readiness("Enter your task, then press Enter")).toBe("ready"); + expect(readiness("How can I help with the codebase today?")).toBe("ready"); + }); + + it("does not treat generic TUI exit status 1 as a clean Ctrl-C exit", () => { + const assertExit = (exitCode: string) => + runTuiStartupCheckHelper( + [ + "PASSED=0", + "FAILED=0", + 'capture="$(mktemp)"', + 'printf "NEMOCLAW_TUI_EXIT_CAPTURED:%s\\n" "$EXIT_CODE" >"$capture"', + 'assert_clean_exit_code "$capture" 2>/dev/null', + 'rm -f -- "$capture"', + 'printf "passed=%s failed=%s" "$PASSED" "$FAILED"', + ].join("; "), + { EXIT_CODE: exitCode }, + ); + + expect(assertExit("0")).toBe( + "10-deepagents-code-tui-startup: OK (dcode TUI exited cleanly after Ctrl-C (exit 0))\npassed=1 failed=0", + ); + expect(assertExit("130")).toBe( + "10-deepagents-code-tui-startup: OK (dcode TUI exited cleanly after Ctrl-C (exit 130))\npassed=1 failed=0", + ); + expect(assertExit("1")).toBe("passed=0 failed=1"); + }); + it("detects representative secret families in TUI startup artifacts", () => { const detectsSecret = (token: string) => runTuiStartupCheckHelper( @@ -601,6 +650,8 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(detectsSecret("nvapi-" + "A".repeat(10))).toBe("secret"); expect(detectsSecret("sk-" + "A".repeat(20))).toBe("secret"); + expect(detectsSecret("Authorization: Bearer " + "a".repeat(20))).toBe("secret"); + expect(detectsSecret("API_KEY=" + "b".repeat(20))).toBe("secret"); expect(detectsSecret("plain startup text")).toBe("clean"); }); @@ -646,6 +697,66 @@ describe("LangChain Deep Agents Code image contracts", () => { } }); + it("redacts retained TUI startup capture when a secret scan fails", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-redact-")); + const rawCapture = path.join(tempDir, "raw.log"); + const expectLog = path.join(tempDir, "expect.log"); + const combinedCapture = path.join(tempDir, "combined.log"); + const sanitizedCapture = path.join(tempDir, "sanitized.log"); + const prefixedToken = `sk-${"A".repeat(20)}`; + const bearerToken = "b".repeat(20); + const apiKey = "c".repeat(20); + + try { + const result = runTuiStartupCheckHelperResult( + [ + 'raw_capture_file="$RAW_CAPTURE"', + 'expect_log_file="$EXPECT_LOG"', + 'combined_capture_file="$COMBINED_CAPTURE"', + 'plain_capture_file="$SANITIZED_CAPTURE"', + 'SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file")', + 'printf "%s\\nAuthorization: Bearer %s\\nAPI_KEY=%s\\n" "$PREFIXED_TOKEN" "$BEARER_TOKEN" "$API_KEY_VALUE" >"$raw_capture_file"', + 'printf "%s\\n" "expect output" >"$expect_log_file"', + 'cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file"', + 'strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file"', + "secret_detected=0", + 'if contains_secret <"$plain_capture_file"; then secret_detected=1; redact_secrets_in_file "$plain_capture_file"; fi', + "cleanup_sensitive_captures", + 'if [ "$secret_detected" -eq 1 ]; then fail_test "secret-shaped value found in sanitized TUI capture"; fi', + 'printf "secret_detected=%s failed=%s\\n" "$secret_detected" "$FAILED"', + '[ "$FAILED" -eq 0 ]', + ].join("; "), + { + API_KEY_VALUE: apiKey, + BEARER_TOKEN: bearerToken, + COMBINED_CAPTURE: combinedCapture, + EXPECT_LOG: expectLog, + PREFIXED_TOKEN: prefixedToken, + RAW_CAPTURE: rawCapture, + SANITIZED_CAPTURE: sanitizedCapture, + }, + ); + + const output = `${result.stdout}\n${result.stderr}`; + const sanitizedText = fs.readFileSync(sanitizedCapture, "utf8"); + expect(result.status).not.toBe(0); + expect(output).toContain("secret_detected=1 failed=1"); + expect(output).not.toContain(prefixedToken); + expect(output).not.toContain(bearerToken); + expect(output).not.toContain(apiKey); + expect(sanitizedText).not.toContain(prefixedToken); + expect(sanitizedText).not.toContain(bearerToken); + expect(sanitizedText).not.toContain(apiKey); + expect(sanitizedText).toContain("Authorization: Bearer [REDACTED_SECRET]"); + expect(sanitizedText).toContain("API_KEY=[REDACTED_SECRET]"); + expect(fs.existsSync(rawCapture)).toBe(false); + expect(fs.existsSync(expectLog)).toBe(false); + expect(fs.existsSync(combinedCapture)).toBe(false); + } finally { + fs.rmSync(tempDir, { force: true, recursive: true }); + } + }); + it("detects representative secret families in headless inference artifacts", () => { const detectsSecret = (token: string) => runHeadlessCheckHelper( From 24d1d9c00199a65fa32ef741d725961ed34795f4 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 26 Jun 2026 09:03:23 -0700 Subject: [PATCH 4/8] test(e2e): cover dcode TUI redaction edges --- .../live/cloud-experimental-checks.ts | 20 ++++ ...platform-parity-cloud-experimental.test.ts | 6 + .../checks/10-deepagents-code-tui-startup.sh | 11 +- test/langchain-deepagents-code-image.test.ts | 112 +++++++++++++++++- 4 files changed, 141 insertions(+), 8 deletions(-) diff --git a/test/e2e-scenario/live/cloud-experimental-checks.ts b/test/e2e-scenario/live/cloud-experimental-checks.ts index 1fee68715ad..349ce20df71 100644 --- a/test/e2e-scenario/live/cloud-experimental-checks.ts +++ b/test/e2e-scenario/live/cloud-experimental-checks.ts @@ -16,6 +16,22 @@ export type CloudExperimentalChecksEvidence = { scenarioId: string; sandboxName: string; checkScripts: readonly string[]; + terminalConnectHint?: { + agent: string; + interactiveCommand: string; + statusLine: string; + source: string; + }; +}; + +const DEEPAGENTS_CODE_ONBOARDING = "cloud-langchain-deepagents-code"; +const DEEPAGENTS_CODE_TUI_CHECK = + "test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh"; +const DEEPAGENTS_CODE_CONNECT_HINT = { + agent: "langchain-deepagents-code", + interactiveCommand: "dcode", + statusLine: "Interactive: dcode", + source: "agents/langchain-deepagents-code/manifest.yaml:runtime.interactive_command", }; export function buildCloudExperimentalChecksEvidence( @@ -27,6 +43,10 @@ export function buildCloudExperimentalChecksEvidence( scenarioId, sandboxName, checkScripts, + ...(scenarioId === DEEPAGENTS_CODE_ONBOARDING && + checkScripts.includes(DEEPAGENTS_CODE_TUI_CHECK) + ? { terminalConnectHint: DEEPAGENTS_CODE_CONNECT_HINT } + : {}), }; } diff --git a/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts b/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts index b468bbba31a..86a0b8a895f 100644 --- a/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts +++ b/test/e2e-scenario/support-tests/platform-parity-cloud-experimental.test.ts @@ -94,6 +94,12 @@ describe("P0-E cloud-experimental parity guardrails", () => { expect(evidence.checkScripts).toContain( "test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh", ); + expect(evidence.terminalConnectHint).toEqual({ + agent: "langchain-deepagents-code", + interactiveCommand: "dcode", + statusLine: "Interactive: dcode", + source: "agents/langchain-deepagents-code/manifest.yaml:runtime.interactive_command", + }); }); it("builds a minimal cloud-experimental child environment", () => { diff --git a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh index 6cfb0df06ab..7e90edf51e1 100755 --- a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh +++ b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh @@ -20,7 +20,7 @@ SECRET_PATTERN='(?:nvapi-[A-Za-z0-9_-]{10,}|nvcf-[A-Za-z0-9_-]{10,}|ghp_[A-Za-z0 CONTEXT_SECRET_VALUE_PATTERN='[A-Za-z0-9_.+\/=-]{10,}' # Upstream dcode does not expose a stable machine-readable TUI ready marker. # Keep this localized heuristic prompt-shaped; do not match banner-only text. -TUI_READY_PATTERN='(what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help|press enter)' +TUI_READY_PATTERN='(what would you like|what do you want|enter (your )?(task|message|prompt)|describe (the )?(task|change)|how can i help)' SENSITIVE_CAPTURE_FILES=() ok() { printf '%s\n' "${PREFIX}: OK ($*)"; } @@ -83,6 +83,9 @@ redact_secrets_in_file() { mv -- "$redacted_file" "$target_file" else rm -f -- "$redacted_file" + if ! printf '%s\n' "[redaction failed; sanitized capture unavailable]" >"$target_file"; then + rm -f -- "$target_file" + fi fail_test "unable to redact sanitized TUI capture" return 1 fi @@ -238,8 +241,10 @@ main() { local secret_detected=0 if contains_secret <"$plain_capture_file"; then secret_detected=1 - redact_secrets_in_file "$plain_capture_file" || true - if contains_secret <"$plain_capture_file"; then + if ! redact_secrets_in_file "$plain_capture_file"; then + : + fi + if [ -e "$plain_capture_file" ] && contains_secret <"$plain_capture_file"; then fail_test "secret-shaped value remained after redacting sanitized TUI capture" fi fi diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index 56231cee8d2..00448d6db2b 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -612,6 +612,7 @@ describe("LangChain Deep Agents Code image contracts", () => { ); expect(readiness("Deep Agents Code starting...\nLoading tools...")).toBe("not-ready"); + expect(readiness("Press Enter to continue")).toBe("not-ready"); expect(readiness("What would you like to do next?")).toBe("ready"); expect(readiness("Enter your task, then press Enter")).toBe("ready"); expect(readiness("How can I help with the codebase today?")).toBe("ready"); @@ -641,17 +642,84 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(assertExit("1")).toBe("passed=0 failed=1"); }); - it("detects representative secret families in TUI startup artifacts", () => { + it("detects and redacts every canonical secret family in TUI startup artifacts", () => { const detectsSecret = (token: string) => runTuiStartupCheckHelper( 'if printf "%s" "$TOKEN" | contains_secret; then printf secret; else printf clean; fi', { TOKEN: token }, ); + const redactsSecret = (token: string) => + runTuiStartupCheckHelper('printf "%s" "$TOKEN" | redact_secrets', { TOKEN: token }); + const secretSamples: Array<{ name: string; sample: string; rawSecret?: string }> = [ + { name: "nvapi", sample: "nvapi-abcdefghijklmnop" }, + { name: "nvcf", sample: "nvcf-abcdefghijklmnopq" }, + { name: "ghp", sample: "ghp_abcdefghijklmnopqr" }, + { name: "github_pat", sample: "github_pat_abcdefghijklmnopqrstuvwxyz0123" }, + { name: "sk_proj", sample: "sk-proj-abcdefghij" }, + { name: "sk_ant", sample: "sk-ant-abcdefghijk" }, + { name: "sk", sample: "sk-abcdefghijklmnopqrstuvwx" }, + { name: "xoxb", sample: "xoxb-1234567890" }, + { name: "xoxp", sample: "xoxp-1234567890" }, + { name: "xoxa", sample: "xoxa-1234567890" }, + { name: "xoxs", sample: "xoxs-1234567890" }, + { name: "xapp", sample: "xapp-1-A1B2C3-12345-abcde" }, + { name: "akia", sample: "AKIAABCDEFGHIJKLMNOP" }, + { name: "asia", sample: "ASIAABCDEFGHIJKLMNOP" }, + { name: "hf", sample: "hf_abcdefghijklmnopq" }, + { name: "glpat", sample: "glpat-abcdefghijklmn" }, + { name: "gsk", sample: "gsk_abcdefghijklmnop" }, + { name: "pypi", sample: "pypi-abcdefghijklmnop" }, + { name: "telegram", sample: "123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + { name: "telegram_bot", sample: "bot123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + { + name: "discord", + sample: "ABCDEFGHIJKLMNOPQRSTUVWX.Abcdef.ZZZZZZZZZZZZZZZZZZZZZZZZZZZ", + }, + { + name: "bearer_context", + sample: "Authorization: Bearer abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "api_key_context", + sample: "API_KEY=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "token_context", + sample: "TOKEN=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "secret_context", + sample: "SECRET=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "password_context", + sample: "PASSWORD=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "credential_context", + sample: "CREDENTIAL=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "suffix_key_context", + sample: "SERVICE_KEY=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + ]; - expect(detectsSecret("nvapi-" + "A".repeat(10))).toBe("secret"); - expect(detectsSecret("sk-" + "A".repeat(20))).toBe("secret"); - expect(detectsSecret("Authorization: Bearer " + "a".repeat(20))).toBe("secret"); - expect(detectsSecret("API_KEY=" + "b".repeat(20))).toBe("secret"); + for (const { name, sample, rawSecret } of secretSamples) { + expect(detectsSecret(sample), `${name} should be detected`).toBe("secret"); + const redacted = redactsSecret(sample); + expect(redacted, `${name} should include a redaction marker`).toContain("[REDACTED_SECRET]"); + expect(redacted, `${name} should not retain the raw secret`).not.toContain( + rawSecret ?? sample, + ); + } expect(detectsSecret("plain startup text")).toBe("clean"); }); @@ -757,6 +825,40 @@ describe("LangChain Deep Agents Code image contracts", () => { } }); + it("truncates retained TUI startup capture when redaction fails", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-redact-fail-")); + const sanitizedCapture = path.join(tempDir, "sanitized.log"); + const prefixedToken = `sk-${"A".repeat(20)}`; + + try { + const result = runTuiStartupCheckHelperResult( + [ + 'plain_capture_file="$SANITIZED_CAPTURE"', + 'printf "%s\\n" "$PREFIXED_TOKEN" >"$plain_capture_file"', + "redact_secrets() { return 1; }", + 'if ! redact_secrets_in_file "$plain_capture_file"; then printf "redaction_failed=1\\n"; fi', + 'if [ -e "$plain_capture_file" ] && grep -Fq "$PREFIXED_TOKEN" "$plain_capture_file"; then printf "leaked=1\\n"; fi', + 'printf "failed=%s\\n" "$FAILED"', + ].join("; "), + { + PREFIXED_TOKEN: prefixedToken, + SANITIZED_CAPTURE: sanitizedCapture, + }, + ); + + const output = `${result.stdout}\n${result.stderr}`; + const sanitizedText = fs.readFileSync(sanitizedCapture, "utf8"); + expect(result.status).toBe(0); + expect(output).toContain("redaction_failed=1"); + expect(output).toContain("failed=1"); + expect(output).not.toContain(prefixedToken); + expect(output).not.toContain("leaked=1"); + expect(sanitizedText).toBe("[redaction failed; sanitized capture unavailable]\n"); + } finally { + fs.rmSync(tempDir, { force: true, recursive: true }); + } + }); + it("detects representative secret families in headless inference artifacts", () => { const detectsSecret = (token: string) => runHeadlessCheckHelper( From b995cf8f483db7e977935c5ff5032869b40b9d8a Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 26 Jun 2026 09:09:53 -0700 Subject: [PATCH 5/8] test(e2e): split dcode TUI helper coverage --- .../deepagents-code-tui-startup-check.test.ts | 303 ++++++++++++++++++ test/langchain-deepagents-code-image.test.ts | 284 ---------------- 2 files changed, 303 insertions(+), 284 deletions(-) create mode 100644 test/deepagents-code-tui-startup-check.test.ts diff --git a/test/deepagents-code-tui-startup-check.test.ts b/test/deepagents-code-tui-startup-check.test.ts new file mode 100644 index 00000000000..8b9ba141c7d --- /dev/null +++ b/test/deepagents-code-tui-startup-check.test.ts @@ -0,0 +1,303 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { execFileSync, type SpawnSyncReturns, spawnSync } from "node:child_process"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +const tuiStartupCheckPath = path.join( + process.cwd(), + "test", + "e2e", + "e2e-cloud-experimental", + "checks", + "10-deepagents-code-tui-startup.sh", +); + +function runTuiStartupCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): string { + return execFileSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { + encoding: "utf8", + env: { ...process.env, ...env }, + }); +} + +function runTuiStartupCheckHelperResult( + snippet: string, + env: NodeJS.ProcessEnv = {}, +): SpawnSyncReturns { + return spawnSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { + encoding: "utf8", + env: { ...process.env, ...env }, + }); +} + +describe("Deep Agents Code TUI startup check helpers", () => { + it("rejects unsafe TUI startup timeout values before sandbox execution", () => { + const validate = (timeout: string) => + runTuiStartupCheckHelper( + 'if is_positive_integer "$TUI_TIMEOUT"; then printf valid; else printf invalid; fi', + { DEEPAGENTS_TUI_TIMEOUT: timeout }, + ); + + expect(validate("90")).toBe("valid"); + expect(validate("0")).toBe("invalid"); + expect(validate("1; touch /tmp/nemoclaw-tui-timeout-injection")).toBe("invalid"); + }); + + it("matches prompt-shaped TUI readiness text without accepting banner-only startup text", () => { + const readiness = (capture: string) => + runTuiStartupCheckHelper( + 'if printf "%s" "$CAPTURE" | is_tui_ready_capture; then printf ready; else printf not-ready; fi', + { CAPTURE: capture }, + ); + + expect(readiness("Deep Agents Code starting...\nLoading tools...")).toBe("not-ready"); + expect(readiness("Press Enter to continue")).toBe("not-ready"); + expect(readiness("What would you like to do next?")).toBe("ready"); + expect(readiness("Enter your task, then press Enter")).toBe("ready"); + expect(readiness("How can I help with the codebase today?")).toBe("ready"); + }); + + it("does not treat generic TUI exit status 1 as a clean Ctrl-C exit", () => { + const assertExit = (exitCode: string) => + runTuiStartupCheckHelper( + [ + "PASSED=0", + "FAILED=0", + 'capture="$(mktemp)"', + 'printf "NEMOCLAW_TUI_EXIT_CAPTURED:%s\\n" "$EXIT_CODE" >"$capture"', + 'assert_clean_exit_code "$capture" 2>/dev/null', + 'rm -f -- "$capture"', + 'printf "passed=%s failed=%s" "$PASSED" "$FAILED"', + ].join("; "), + { EXIT_CODE: exitCode }, + ); + + expect(assertExit("0")).toBe( + "10-deepagents-code-tui-startup: OK (dcode TUI exited cleanly after Ctrl-C (exit 0))\npassed=1 failed=0", + ); + expect(assertExit("130")).toBe( + "10-deepagents-code-tui-startup: OK (dcode TUI exited cleanly after Ctrl-C (exit 130))\npassed=1 failed=0", + ); + expect(assertExit("1")).toBe("passed=0 failed=1"); + }); + + it("detects and redacts every canonical secret family in TUI startup artifacts", () => { + const detectsSecret = (token: string) => + runTuiStartupCheckHelper( + 'if printf "%s" "$TOKEN" | contains_secret; then printf secret; else printf clean; fi', + { TOKEN: token }, + ); + const redactsSecret = (token: string) => + runTuiStartupCheckHelper('printf "%s" "$TOKEN" | redact_secrets', { TOKEN: token }); + const secretSamples: Array<{ name: string; sample: string; rawSecret?: string }> = [ + { name: "nvapi", sample: "nvapi-abcdefghijklmnop" }, + { name: "nvcf", sample: "nvcf-abcdefghijklmnopq" }, + { name: "ghp", sample: "ghp_abcdefghijklmnopqr" }, + { name: "github_pat", sample: "github_pat_abcdefghijklmnopqrstuvwxyz0123" }, + { name: "sk_proj", sample: "sk-proj-abcdefghij" }, + { name: "sk_ant", sample: "sk-ant-abcdefghijk" }, + { name: "sk", sample: "sk-abcdefghijklmnopqrstuvwx" }, + { name: "xoxb", sample: "xoxb-1234567890" }, + { name: "xoxp", sample: "xoxp-1234567890" }, + { name: "xoxa", sample: "xoxa-1234567890" }, + { name: "xoxs", sample: "xoxs-1234567890" }, + { name: "xapp", sample: "xapp-1-A1B2C3-12345-abcde" }, + { name: "akia", sample: "AKIAABCDEFGHIJKLMNOP" }, + { name: "asia", sample: "ASIAABCDEFGHIJKLMNOP" }, + { name: "hf", sample: "hf_abcdefghijklmnopq" }, + { name: "glpat", sample: "glpat-abcdefghijklmn" }, + { name: "gsk", sample: "gsk_abcdefghijklmnop" }, + { name: "pypi", sample: "pypi-abcdefghijklmnop" }, + { name: "telegram", sample: "123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + { name: "telegram_bot", sample: "bot123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + { + name: "discord", + sample: "ABCDEFGHIJKLMNOPQRSTUVWX.Abcdef.ZZZZZZZZZZZZZZZZZZZZZZZZZZZ", + }, + { + name: "bearer_context", + sample: "Authorization: Bearer abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "api_key_context", + sample: "API_KEY=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "token_context", + sample: "TOKEN=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "secret_context", + sample: "SECRET=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "password_context", + sample: "PASSWORD=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "credential_context", + sample: "CREDENTIAL=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + { + name: "suffix_key_context", + sample: "SERVICE_KEY=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + ]; + + for (const { name, sample, rawSecret } of secretSamples) { + expect(detectsSecret(sample), `${name} should be detected`).toBe("secret"); + const redacted = redactsSecret(sample); + expect(redacted, `${name} should include a redaction marker`).toContain("[REDACTED_SECRET]"); + expect(redacted, `${name} should not retain the raw secret`).not.toContain( + rawSecret ?? sample, + ); + } + expect(detectsSecret("plain startup text")).toBe("clean"); + }); + + it("removes raw TUI startup artifacts after writing the sanitized capture", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-")); + const rawCapture = path.join(tempDir, "raw.log"); + const expectLog = path.join(tempDir, "expect.log"); + const combinedCapture = path.join(tempDir, "combined.log"); + const sanitizedCapture = path.join(tempDir, "sanitized.log"); + + try { + const output = runTuiStartupCheckHelper( + [ + 'raw_capture_file="$RAW_CAPTURE"', + 'expect_log_file="$EXPECT_LOG"', + 'combined_capture_file="$COMBINED_CAPTURE"', + 'plain_capture_file="$SANITIZED_CAPTURE"', + 'SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file")', + 'printf "%s\\n" "$SECRET_TOKEN" >"$raw_capture_file"', + 'printf "%s\\n" "expect output" >"$expect_log_file"', + 'cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file"', + 'strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file"', + "cleanup_sensitive_captures", + 'for artifact in "$raw_capture_file" "$expect_log_file" "$combined_capture_file"; do if [ -e "$artifact" ]; then printf "leaked:%s" "$artifact"; exit 1; fi; done', + 'if [ -e "$plain_capture_file" ]; then printf sanitized; else printf missing; fi', + ].join("; "), + { + COMBINED_CAPTURE: combinedCapture, + EXPECT_LOG: expectLog, + RAW_CAPTURE: rawCapture, + SANITIZED_CAPTURE: sanitizedCapture, + SECRET_TOKEN: `sk-${"A".repeat(20)}`, + }, + ); + + expect(output).toBe("sanitized"); + expect(fs.existsSync(rawCapture)).toBe(false); + expect(fs.existsSync(expectLog)).toBe(false); + expect(fs.existsSync(combinedCapture)).toBe(false); + expect(fs.existsSync(sanitizedCapture)).toBe(true); + } finally { + fs.rmSync(tempDir, { force: true, recursive: true }); + } + }); + + it("redacts retained TUI startup capture when a secret scan fails", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-redact-")); + const rawCapture = path.join(tempDir, "raw.log"); + const expectLog = path.join(tempDir, "expect.log"); + const combinedCapture = path.join(tempDir, "combined.log"); + const sanitizedCapture = path.join(tempDir, "sanitized.log"); + const prefixedToken = `sk-${"A".repeat(20)}`; + const bearerToken = "b".repeat(20); + const apiKey = "c".repeat(20); + + try { + const result = runTuiStartupCheckHelperResult( + [ + 'raw_capture_file="$RAW_CAPTURE"', + 'expect_log_file="$EXPECT_LOG"', + 'combined_capture_file="$COMBINED_CAPTURE"', + 'plain_capture_file="$SANITIZED_CAPTURE"', + 'SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file")', + 'printf "%s\\nAuthorization: Bearer %s\\nAPI_KEY=%s\\n" "$PREFIXED_TOKEN" "$BEARER_TOKEN" "$API_KEY_VALUE" >"$raw_capture_file"', + 'printf "%s\\n" "expect output" >"$expect_log_file"', + 'cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file"', + 'strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file"', + "secret_detected=0", + 'if contains_secret <"$plain_capture_file"; then secret_detected=1; redact_secrets_in_file "$plain_capture_file"; fi', + "cleanup_sensitive_captures", + 'if [ "$secret_detected" -eq 1 ]; then fail_test "secret-shaped value found in sanitized TUI capture"; fi', + 'printf "secret_detected=%s failed=%s\\n" "$secret_detected" "$FAILED"', + '[ "$FAILED" -eq 0 ]', + ].join("; "), + { + API_KEY_VALUE: apiKey, + BEARER_TOKEN: bearerToken, + COMBINED_CAPTURE: combinedCapture, + EXPECT_LOG: expectLog, + PREFIXED_TOKEN: prefixedToken, + RAW_CAPTURE: rawCapture, + SANITIZED_CAPTURE: sanitizedCapture, + }, + ); + + const output = `${result.stdout}\n${result.stderr}`; + const sanitizedText = fs.readFileSync(sanitizedCapture, "utf8"); + expect(result.status).not.toBe(0); + expect(output).toContain("secret_detected=1 failed=1"); + expect(output).not.toContain(prefixedToken); + expect(output).not.toContain(bearerToken); + expect(output).not.toContain(apiKey); + expect(sanitizedText).not.toContain(prefixedToken); + expect(sanitizedText).not.toContain(bearerToken); + expect(sanitizedText).not.toContain(apiKey); + expect(sanitizedText).toContain("Authorization: Bearer [REDACTED_SECRET]"); + expect(sanitizedText).toContain("API_KEY=[REDACTED_SECRET]"); + expect(fs.existsSync(rawCapture)).toBe(false); + expect(fs.existsSync(expectLog)).toBe(false); + expect(fs.existsSync(combinedCapture)).toBe(false); + } finally { + fs.rmSync(tempDir, { force: true, recursive: true }); + } + }); + + it("truncates retained TUI startup capture when redaction fails", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-redact-fail-")); + const sanitizedCapture = path.join(tempDir, "sanitized.log"); + const prefixedToken = `sk-${"A".repeat(20)}`; + + try { + const result = runTuiStartupCheckHelperResult( + [ + 'plain_capture_file="$SANITIZED_CAPTURE"', + 'printf "%s\\n" "$PREFIXED_TOKEN" >"$plain_capture_file"', + "redact_secrets() { return 1; }", + 'if ! redact_secrets_in_file "$plain_capture_file"; then printf "redaction_failed=1\\n"; fi', + 'if [ -e "$plain_capture_file" ] && grep -Fq "$PREFIXED_TOKEN" "$plain_capture_file"; then printf "leaked=1\\n"; fi', + 'printf "failed=%s\\n" "$FAILED"', + ].join("; "), + { + PREFIXED_TOKEN: prefixedToken, + SANITIZED_CAPTURE: sanitizedCapture, + }, + ); + + const output = `${result.stdout}\n${result.stderr}`; + const sanitizedText = fs.readFileSync(sanitizedCapture, "utf8"); + expect(result.status).toBe(0); + expect(output).toContain("redaction_failed=1"); + expect(output).toContain("failed=1"); + expect(output).not.toContain(prefixedToken); + expect(output).not.toContain("leaked=1"); + expect(sanitizedText).toBe("[redaction failed; sanitized capture unavailable]\n"); + } finally { + fs.rmSync(tempDir, { force: true, recursive: true }); + } + }); +}); diff --git a/test/langchain-deepagents-code-image.test.ts b/test/langchain-deepagents-code-image.test.ts index 00448d6db2b..605256e24eb 100644 --- a/test/langchain-deepagents-code-image.test.ts +++ b/test/langchain-deepagents-code-image.test.ts @@ -142,23 +142,6 @@ function runHeadlessCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): s }); } -function runTuiStartupCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): string { - return execFileSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { - encoding: "utf8", - env: { ...process.env, ...env }, - }); -} - -function runTuiStartupCheckHelperResult( - snippet: string, - env: NodeJS.ProcessEnv = {}, -): SpawnSyncReturns { - return spawnSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { - 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"); @@ -592,273 +575,6 @@ describe("LangChain Deep Agents Code image contracts", () => { expect(validate("1; touch /tmp/nemoclaw-timeout-injection")).toBe("invalid"); }); - it("rejects unsafe TUI startup timeout values before sandbox execution", () => { - const validate = (timeout: string) => - runTuiStartupCheckHelper( - 'if is_positive_integer "$TUI_TIMEOUT"; then printf valid; else printf invalid; fi', - { DEEPAGENTS_TUI_TIMEOUT: timeout }, - ); - - expect(validate("90")).toBe("valid"); - expect(validate("0")).toBe("invalid"); - expect(validate("1; touch /tmp/nemoclaw-tui-timeout-injection")).toBe("invalid"); - }); - - it("matches prompt-shaped TUI readiness text without accepting banner-only startup text", () => { - const readiness = (capture: string) => - runTuiStartupCheckHelper( - 'if printf "%s" "$CAPTURE" | is_tui_ready_capture; then printf ready; else printf not-ready; fi', - { CAPTURE: capture }, - ); - - expect(readiness("Deep Agents Code starting...\nLoading tools...")).toBe("not-ready"); - expect(readiness("Press Enter to continue")).toBe("not-ready"); - expect(readiness("What would you like to do next?")).toBe("ready"); - expect(readiness("Enter your task, then press Enter")).toBe("ready"); - expect(readiness("How can I help with the codebase today?")).toBe("ready"); - }); - - it("does not treat generic TUI exit status 1 as a clean Ctrl-C exit", () => { - const assertExit = (exitCode: string) => - runTuiStartupCheckHelper( - [ - "PASSED=0", - "FAILED=0", - 'capture="$(mktemp)"', - 'printf "NEMOCLAW_TUI_EXIT_CAPTURED:%s\\n" "$EXIT_CODE" >"$capture"', - 'assert_clean_exit_code "$capture" 2>/dev/null', - 'rm -f -- "$capture"', - 'printf "passed=%s failed=%s" "$PASSED" "$FAILED"', - ].join("; "), - { EXIT_CODE: exitCode }, - ); - - expect(assertExit("0")).toBe( - "10-deepagents-code-tui-startup: OK (dcode TUI exited cleanly after Ctrl-C (exit 0))\npassed=1 failed=0", - ); - expect(assertExit("130")).toBe( - "10-deepagents-code-tui-startup: OK (dcode TUI exited cleanly after Ctrl-C (exit 130))\npassed=1 failed=0", - ); - expect(assertExit("1")).toBe("passed=0 failed=1"); - }); - - it("detects and redacts every canonical secret family in TUI startup artifacts", () => { - const detectsSecret = (token: string) => - runTuiStartupCheckHelper( - 'if printf "%s" "$TOKEN" | contains_secret; then printf secret; else printf clean; fi', - { TOKEN: token }, - ); - const redactsSecret = (token: string) => - runTuiStartupCheckHelper('printf "%s" "$TOKEN" | redact_secrets', { TOKEN: token }); - const secretSamples: Array<{ name: string; sample: string; rawSecret?: string }> = [ - { name: "nvapi", sample: "nvapi-abcdefghijklmnop" }, - { name: "nvcf", sample: "nvcf-abcdefghijklmnopq" }, - { name: "ghp", sample: "ghp_abcdefghijklmnopqr" }, - { name: "github_pat", sample: "github_pat_abcdefghijklmnopqrstuvwxyz0123" }, - { name: "sk_proj", sample: "sk-proj-abcdefghij" }, - { name: "sk_ant", sample: "sk-ant-abcdefghijk" }, - { name: "sk", sample: "sk-abcdefghijklmnopqrstuvwx" }, - { name: "xoxb", sample: "xoxb-1234567890" }, - { name: "xoxp", sample: "xoxp-1234567890" }, - { name: "xoxa", sample: "xoxa-1234567890" }, - { name: "xoxs", sample: "xoxs-1234567890" }, - { name: "xapp", sample: "xapp-1-A1B2C3-12345-abcde" }, - { name: "akia", sample: "AKIAABCDEFGHIJKLMNOP" }, - { name: "asia", sample: "ASIAABCDEFGHIJKLMNOP" }, - { name: "hf", sample: "hf_abcdefghijklmnopq" }, - { name: "glpat", sample: "glpat-abcdefghijklmn" }, - { name: "gsk", sample: "gsk_abcdefghijklmnop" }, - { name: "pypi", sample: "pypi-abcdefghijklmnop" }, - { name: "telegram", sample: "123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, - { name: "telegram_bot", sample: "bot123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, - { - name: "discord", - sample: "ABCDEFGHIJKLMNOPQRSTUVWX.Abcdef.ZZZZZZZZZZZZZZZZZZZZZZZZZZZ", - }, - { - name: "bearer_context", - sample: "Authorization: Bearer abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "api_key_context", - sample: "API_KEY=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "token_context", - sample: "TOKEN=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "secret_context", - sample: "SECRET=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "password_context", - sample: "PASSWORD=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "credential_context", - sample: "CREDENTIAL=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "suffix_key_context", - sample: "SERVICE_KEY=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - ]; - - for (const { name, sample, rawSecret } of secretSamples) { - expect(detectsSecret(sample), `${name} should be detected`).toBe("secret"); - const redacted = redactsSecret(sample); - expect(redacted, `${name} should include a redaction marker`).toContain("[REDACTED_SECRET]"); - expect(redacted, `${name} should not retain the raw secret`).not.toContain( - rawSecret ?? sample, - ); - } - expect(detectsSecret("plain startup text")).toBe("clean"); - }); - - it("removes raw TUI startup artifacts after writing the sanitized capture", () => { - const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-")); - const rawCapture = path.join(tempDir, "raw.log"); - const expectLog = path.join(tempDir, "expect.log"); - const combinedCapture = path.join(tempDir, "combined.log"); - const sanitizedCapture = path.join(tempDir, "sanitized.log"); - - try { - const output = runTuiStartupCheckHelper( - [ - 'raw_capture_file="$RAW_CAPTURE"', - 'expect_log_file="$EXPECT_LOG"', - 'combined_capture_file="$COMBINED_CAPTURE"', - 'plain_capture_file="$SANITIZED_CAPTURE"', - 'SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file")', - 'printf "%s\\n" "$SECRET_TOKEN" >"$raw_capture_file"', - 'printf "%s\\n" "expect output" >"$expect_log_file"', - 'cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file"', - 'strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file"', - "cleanup_sensitive_captures", - 'for artifact in "$raw_capture_file" "$expect_log_file" "$combined_capture_file"; do if [ -e "$artifact" ]; then printf "leaked:%s" "$artifact"; exit 1; fi; done', - 'if [ -e "$plain_capture_file" ]; then printf sanitized; else printf missing; fi', - ].join("; "), - { - COMBINED_CAPTURE: combinedCapture, - EXPECT_LOG: expectLog, - RAW_CAPTURE: rawCapture, - SANITIZED_CAPTURE: sanitizedCapture, - SECRET_TOKEN: `sk-${"A".repeat(20)}`, - }, - ); - - expect(output).toBe("sanitized"); - expect(fs.existsSync(rawCapture)).toBe(false); - expect(fs.existsSync(expectLog)).toBe(false); - expect(fs.existsSync(combinedCapture)).toBe(false); - expect(fs.existsSync(sanitizedCapture)).toBe(true); - } finally { - fs.rmSync(tempDir, { force: true, recursive: true }); - } - }); - - it("redacts retained TUI startup capture when a secret scan fails", () => { - const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-redact-")); - const rawCapture = path.join(tempDir, "raw.log"); - const expectLog = path.join(tempDir, "expect.log"); - const combinedCapture = path.join(tempDir, "combined.log"); - const sanitizedCapture = path.join(tempDir, "sanitized.log"); - const prefixedToken = `sk-${"A".repeat(20)}`; - const bearerToken = "b".repeat(20); - const apiKey = "c".repeat(20); - - try { - const result = runTuiStartupCheckHelperResult( - [ - 'raw_capture_file="$RAW_CAPTURE"', - 'expect_log_file="$EXPECT_LOG"', - 'combined_capture_file="$COMBINED_CAPTURE"', - 'plain_capture_file="$SANITIZED_CAPTURE"', - 'SENSITIVE_CAPTURE_FILES=("$raw_capture_file" "$expect_log_file" "$combined_capture_file")', - 'printf "%s\\nAuthorization: Bearer %s\\nAPI_KEY=%s\\n" "$PREFIXED_TOKEN" "$BEARER_TOKEN" "$API_KEY_VALUE" >"$raw_capture_file"', - 'printf "%s\\n" "expect output" >"$expect_log_file"', - 'cat "$raw_capture_file" "$expect_log_file" >"$combined_capture_file"', - 'strip_terminal_control_sequences <"$combined_capture_file" >"$plain_capture_file"', - "secret_detected=0", - 'if contains_secret <"$plain_capture_file"; then secret_detected=1; redact_secrets_in_file "$plain_capture_file"; fi', - "cleanup_sensitive_captures", - 'if [ "$secret_detected" -eq 1 ]; then fail_test "secret-shaped value found in sanitized TUI capture"; fi', - 'printf "secret_detected=%s failed=%s\\n" "$secret_detected" "$FAILED"', - '[ "$FAILED" -eq 0 ]', - ].join("; "), - { - API_KEY_VALUE: apiKey, - BEARER_TOKEN: bearerToken, - COMBINED_CAPTURE: combinedCapture, - EXPECT_LOG: expectLog, - PREFIXED_TOKEN: prefixedToken, - RAW_CAPTURE: rawCapture, - SANITIZED_CAPTURE: sanitizedCapture, - }, - ); - - const output = `${result.stdout}\n${result.stderr}`; - const sanitizedText = fs.readFileSync(sanitizedCapture, "utf8"); - expect(result.status).not.toBe(0); - expect(output).toContain("secret_detected=1 failed=1"); - expect(output).not.toContain(prefixedToken); - expect(output).not.toContain(bearerToken); - expect(output).not.toContain(apiKey); - expect(sanitizedText).not.toContain(prefixedToken); - expect(sanitizedText).not.toContain(bearerToken); - expect(sanitizedText).not.toContain(apiKey); - expect(sanitizedText).toContain("Authorization: Bearer [REDACTED_SECRET]"); - expect(sanitizedText).toContain("API_KEY=[REDACTED_SECRET]"); - expect(fs.existsSync(rawCapture)).toBe(false); - expect(fs.existsSync(expectLog)).toBe(false); - expect(fs.existsSync(combinedCapture)).toBe(false); - } finally { - fs.rmSync(tempDir, { force: true, recursive: true }); - } - }); - - it("truncates retained TUI startup capture when redaction fails", () => { - const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-dcode-tui-redact-fail-")); - const sanitizedCapture = path.join(tempDir, "sanitized.log"); - const prefixedToken = `sk-${"A".repeat(20)}`; - - try { - const result = runTuiStartupCheckHelperResult( - [ - 'plain_capture_file="$SANITIZED_CAPTURE"', - 'printf "%s\\n" "$PREFIXED_TOKEN" >"$plain_capture_file"', - "redact_secrets() { return 1; }", - 'if ! redact_secrets_in_file "$plain_capture_file"; then printf "redaction_failed=1\\n"; fi', - 'if [ -e "$plain_capture_file" ] && grep -Fq "$PREFIXED_TOKEN" "$plain_capture_file"; then printf "leaked=1\\n"; fi', - 'printf "failed=%s\\n" "$FAILED"', - ].join("; "), - { - PREFIXED_TOKEN: prefixedToken, - SANITIZED_CAPTURE: sanitizedCapture, - }, - ); - - const output = `${result.stdout}\n${result.stderr}`; - const sanitizedText = fs.readFileSync(sanitizedCapture, "utf8"); - expect(result.status).toBe(0); - expect(output).toContain("redaction_failed=1"); - expect(output).toContain("failed=1"); - expect(output).not.toContain(prefixedToken); - expect(output).not.toContain("leaked=1"); - expect(sanitizedText).toBe("[redaction failed; sanitized capture unavailable]\n"); - } finally { - fs.rmSync(tempDir, { force: true, recursive: true }); - } - }); - it("detects representative secret families in headless inference artifacts", () => { const detectsSecret = (token: string) => runHeadlessCheckHelper( From 594f3aa550e8ffd3243108e9c1a9048444484765 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 26 Jun 2026 09:19:14 -0700 Subject: [PATCH 6/8] test(e2e): pin TUI secret parity coverage --- .../deepagents-code-tui-startup-check.test.ts | 109 ++++++++++++------ .../checks/10-deepagents-code-tui-startup.sh | 2 + 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/test/deepagents-code-tui-startup-check.test.ts b/test/deepagents-code-tui-startup-check.test.ts index 8b9ba141c7d..ad852da6758 100644 --- a/test/deepagents-code-tui-startup-check.test.ts +++ b/test/deepagents-code-tui-startup-check.test.ts @@ -7,6 +7,8 @@ import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; +import { CONTEXT_PATTERNS, TOKEN_PREFIX_PATTERNS } from "../src/lib/security/secret-patterns.ts"; + const tuiStartupCheckPath = path.join( process.cwd(), "test", @@ -33,6 +35,14 @@ function runTuiStartupCheckHelperResult( }); } +function fingerprint(pattern: RegExp): string { + return `${pattern.source}::${pattern.flags}`; +} + +function secretFixture(...parts: string[]): string { + return parts.join(""); +} + describe("Deep Agents Code TUI startup check helpers", () => { it("rejects unsafe TUI startup timeout values before sandbox execution", () => { const validate = (timeout: string) => @@ -92,40 +102,70 @@ describe("Deep Agents Code TUI startup check helpers", () => { ); const redactsSecret = (token: string) => runTuiStartupCheckHelper('printf "%s" "$TOKEN" | redact_secrets', { TOKEN: token }); - const secretSamples: Array<{ name: string; sample: string; rawSecret?: string }> = [ - { name: "nvapi", sample: "nvapi-abcdefghijklmnop" }, - { name: "nvcf", sample: "nvcf-abcdefghijklmnopq" }, - { name: "ghp", sample: "ghp_abcdefghijklmnopqr" }, - { name: "github_pat", sample: "github_pat_abcdefghijklmnopqrstuvwxyz0123" }, - { name: "sk_proj", sample: "sk-proj-abcdefghij" }, - { name: "sk_ant", sample: "sk-ant-abcdefghijk" }, - { name: "sk", sample: "sk-abcdefghijklmnopqrstuvwx" }, - { name: "xoxb", sample: "xoxb-1234567890" }, - { name: "xoxp", sample: "xoxp-1234567890" }, - { name: "xoxa", sample: "xoxa-1234567890" }, - { name: "xoxs", sample: "xoxs-1234567890" }, - { name: "xapp", sample: "xapp-1-A1B2C3-12345-abcde" }, + const canonicalSamples = new Map([ + [fingerprint(TOKEN_PREFIX_PATTERNS[0]), { name: "nvapi", sample: "nvapi-abcdefghijklmnop" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[1]), { name: "nvcf", sample: "nvcf-abcdefghijklmnopq" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[2]), { name: "ghp", sample: "ghp_abcdefghijklmnopqr" }], + [ + fingerprint(TOKEN_PREFIX_PATTERNS[3]), + { name: "github_pat", sample: "github_pat_abcdefghijklmnopqrstuvwxyz0123" }, + ], + [fingerprint(TOKEN_PREFIX_PATTERNS[4]), { name: "sk_proj", sample: "sk-proj-abcdefghij" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[5]), { name: "sk_ant", sample: "sk-ant-abcdefghijk" }], + [ + fingerprint(TOKEN_PREFIX_PATTERNS[6]), + { name: "sk", sample: "sk-abcdefghijklmnopqrstuvwx" }, + ], + [ + fingerprint(TOKEN_PREFIX_PATTERNS[7]), + { name: "xoxb", sample: secretFixture("xox", "b", "-", "1234567890") }, + ], + [fingerprint(TOKEN_PREFIX_PATTERNS[8]), { name: "akia", sample: "AKIAABCDEFGHIJKLMNOP" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[8]), { name: "asia", sample: "ASIAABCDEFGHIJKLMNOP" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[9]), { name: "hf", sample: "hf_abcdefghijklmnopq" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[10]), { name: "glpat", sample: "glpat-abcdefghijklmn" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[11]), { name: "gsk", sample: "gsk_abcdefghijklmnop" }], + [fingerprint(TOKEN_PREFIX_PATTERNS[12]), { name: "pypi", sample: "pypi-abcdefghijklmnop" }], + [ + fingerprint(TOKEN_PREFIX_PATTERNS[13]), + { name: "telegram_bot", sample: "bot123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + ], + [ + fingerprint(TOKEN_PREFIX_PATTERNS[14]), + { name: "telegram", sample: "123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + ], + [ + fingerprint(TOKEN_PREFIX_PATTERNS[15]), + { + name: "discord", + sample: "ABCDEFGHIJKLMNOPQRSTUVWX.Abcdef.ZZZZZZZZZZZZZZZZZZZZZZZZZZZ", + }, + ], + [ + fingerprint(CONTEXT_PATTERNS[0]), + { + name: "bearer_context", + sample: "Authorization: Bearer abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + ], + [ + fingerprint(CONTEXT_PATTERNS[1]), + { + name: "api_key_context", + sample: "API_KEY=abcdefghijklmnopqrst", + rawSecret: "abcdefghijklmnopqrst", + }, + ], + ]); + const extraSamples = [ { name: "akia", sample: "AKIAABCDEFGHIJKLMNOP" }, - { name: "asia", sample: "ASIAABCDEFGHIJKLMNOP" }, - { name: "hf", sample: "hf_abcdefghijklmnopq" }, - { name: "glpat", sample: "glpat-abcdefghijklmn" }, - { name: "gsk", sample: "gsk_abcdefghijklmnop" }, - { name: "pypi", sample: "pypi-abcdefghijklmnop" }, - { name: "telegram", sample: "123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, - { name: "telegram_bot", sample: "bot123456789:AbcDefGhiJklMnoPqrStuVwxYz012345678" }, + { name: "xoxp", sample: secretFixture("xox", "p", "-", "1234567890") }, + { name: "xoxa", sample: secretFixture("xox", "a", "-", "1234567890") }, + { name: "xoxs", sample: secretFixture("xox", "s", "-", "1234567890") }, { - name: "discord", - sample: "ABCDEFGHIJKLMNOPQRSTUVWX.Abcdef.ZZZZZZZZZZZZZZZZZZZZZZZZZZZ", - }, - { - name: "bearer_context", - sample: "Authorization: Bearer abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", - }, - { - name: "api_key_context", - sample: "API_KEY=abcdefghijklmnopqrst", - rawSecret: "abcdefghijklmnopqrst", + name: "xapp", + sample: secretFixture("x", "app", "-", "1", "-", "A1B2C3", "-", "12345", "-", "abcde"), }, { name: "token_context", @@ -154,7 +194,10 @@ describe("Deep Agents Code TUI startup check helpers", () => { }, ]; - for (const { name, sample, rawSecret } of secretSamples) { + const canonicalFingerprints = [...TOKEN_PREFIX_PATTERNS, ...CONTEXT_PATTERNS].map(fingerprint); + expect([...canonicalSamples.keys()]).toEqual(canonicalFingerprints); + + for (const { name, sample, rawSecret } of [...canonicalSamples.values(), ...extraSamples]) { expect(detectsSecret(sample), `${name} should be detected`).toBe("secret"); const redacted = redactsSecret(sample); expect(redacted, `${name} should include a redaction marker`).toContain("[REDACTED_SECRET]"); diff --git a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh index 7e90edf51e1..82fd15ff8ae 100755 --- a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh +++ b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh @@ -16,6 +16,8 @@ set -euo pipefail SANDBOX_NAME="${SANDBOX_NAME:-${NEMOCLAW_SANDBOX_NAME:-e2e-cloud-onboard}}" PREFIX="10-deepagents-code-tui-startup" TUI_TIMEOUT="${DEEPAGENTS_TUI_TIMEOUT:-90}" +# Shell-only live check fallback for remote e2e hosts; Vitest parity coverage in +# test/deepagents-code-tui-startup-check.test.ts pins this to secret-patterns.ts. 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,}|\bbot[0-9]{8,10}:[A-Za-z0-9_-]{35}\b|\b[0-9]{8,10}:[A-Za-z0-9_-]{35}\b|\b[A-Za-z0-9]{24}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{27,}\b)' CONTEXT_SECRET_VALUE_PATTERN='[A-Za-z0-9_.+\/=-]{10,}' # Upstream dcode does not expose a stable machine-readable TUI ready marker. From 5d9085bbe988af38a6a93c84091cc141c590168e Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 26 Jun 2026 09:35:30 -0700 Subject: [PATCH 7/8] test(e2e): harden TUI helper prerequisites --- test/deepagents-code-tui-startup-check.test.ts | 9 +++++++-- .../checks/10-deepagents-code-tui-startup.sh | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/deepagents-code-tui-startup-check.test.ts b/test/deepagents-code-tui-startup-check.test.ts index ad852da6758..04491ea0881 100644 --- a/test/deepagents-code-tui-startup-check.test.ts +++ b/test/deepagents-code-tui-startup-check.test.ts @@ -17,11 +17,15 @@ const tuiStartupCheckPath = path.join( "checks", "10-deepagents-code-tui-startup.sh", ); +const tuiStartupCheckSource = fs + .readFileSync(tuiStartupCheckPath, "utf8") + .replace('\nif [[ "${BASH_SOURCE[0]}" == "$0" ]]; then\n main "$@"\nfi\n', "\n"); function runTuiStartupCheckHelper(snippet: string, env: NodeJS.ProcessEnv = {}): string { - return execFileSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { + return execFileSync("bash", ["-s"], { encoding: "utf8", env: { ...process.env, ...env }, + input: `${tuiStartupCheckSource}\n${snippet}\n`, }); } @@ -29,9 +33,10 @@ function runTuiStartupCheckHelperResult( snippet: string, env: NodeJS.ProcessEnv = {}, ): SpawnSyncReturns { - return spawnSync("bash", ["-c", `source "$1"; ${snippet}`, "bash", tuiStartupCheckPath], { + return spawnSync("bash", ["-s"], { encoding: "utf8", env: { ...process.env, ...env }, + input: `${tuiStartupCheckSource}\n${snippet}\n`, }); } diff --git a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh index 82fd15ff8ae..a3c390c9331 100755 --- a/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh +++ b/test/e2e/e2e-cloud-experimental/checks/10-deepagents-code-tui-startup.sh @@ -199,6 +199,11 @@ main() { printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" exit 1 fi + if ! command -v perl >/dev/null 2>&1; then + fail_test "perl is required to sanitize and redact Deep Agents Code TUI captures" + printf '%s\n' "${PREFIX}: $PASSED passed, $FAILED failed" + exit 1 + fi local probe_output if ! probe_output="$(sandbox_exec 'if test -d /sandbox/.deepagents && command -v dcode >/dev/null 2>&1; then printf "NEMOCLAW_DCODE_PROBE:deepagents\n"; else printf "NEMOCLAW_DCODE_PROBE:other\n"; fi')"; then From bd0bcbf68c766e5fef13c2c70bfde24e375f62f4 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 26 Jun 2026 09:43:15 -0700 Subject: [PATCH 8/8] fix(messaging): pass manifest list to availability context --- src/lib/onboard/messaging-channel-setup.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/onboard/messaging-channel-setup.ts b/src/lib/onboard/messaging-channel-setup.ts index 7dfe4165312..4d9cce4dd6e 100644 --- a/src/lib/onboard/messaging-channel-setup.ts +++ b/src/lib/onboard/messaging-channel-setup.ts @@ -69,7 +69,10 @@ const getMessagingInputValue = (input: ChannelInputSpec): string | null => { */ export function detectMessagingChannelsFromEnv(agent: AgentDefinition | null = null): string[] { const manifestRegistry = createBuiltInChannelManifestRegistry(); - const availabilityContext = getMessagingManifestAvailabilityContext(agent); + const availabilityContext = getMessagingManifestAvailabilityContext( + agent, + manifestRegistry.list(), + ); const availableChannels = manifestRegistry.listAvailable(availabilityContext); return availableChannels .filter((manifest) => hasMessagingManifestRequiredInputs(manifest, getMessagingInputValue))