| 1 | #!/bin/sh |
| 2 | # Run the TUI bin tests without reading or writing the developer's Codewhale |
| 3 | # settings/auth home. Rust toolchains remain real through explicit homes. |
| 4 | set -eu |
| 5 | |
| 6 | repo_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 7 | real_cargo_home=${CARGO_HOME:-${HOME}/.cargo} |
| 8 | real_rustup_home=${RUSTUP_HOME:-${HOME}/.rustup} |
| 9 | rustc_bin=$(RUSTUP_HOME="$real_rustup_home" rustup which rustc) |
| 10 | toolchain_bin=${rustc_bin%/*} |
| 11 | runs=${TUI_HERMETIC_RUNS:-2} |
| 12 | filter=${TUI_HERMETIC_FILTER:-} |
| 13 | |
| 14 | "$repo_root/scripts/check-tui-product-vocabulary.sh" |
| 15 | |
| 16 | cleanup_roots="" |
| 17 | cleanup() { |
| 18 | for root in $cleanup_roots; do |
| 19 | rm -rf -- "$root" |
| 20 | done |
| 21 | } |
| 22 | trap cleanup EXIT HUP INT TERM |
| 23 | |
| 24 | run=1 |
| 25 | while [ "$run" -le "$runs" ]; do |
| 26 | root=$(mktemp -d "${TMPDIR:-/tmp}/codewhale-tui-test.XXXXXX") |
| 27 | cleanup_roots="$cleanup_roots $root" |
| 28 | mkdir -p "$root/home" "$root/codewhale-home" "$root/xdg" |
| 29 | mkdir -p "$root/codex" "$root/grok" "$root/kimi-code" "$root/kimi-share" "$root/claude" |
| 30 | printf '%s\n' "hermetic TUI run $run/$runs: $root" |
| 31 | ( |
| 32 | cd "$repo_root" |
| 33 | HOME="$root/home" \ |
| 34 | USERPROFILE="$root/home" \ |
| 35 | CODEWHALE_HOME="$root/codewhale-home" \ |
| 36 | XDG_CONFIG_HOME="$root/xdg" \ |
| 37 | DEEPSEEK_CONFIG_PATH="$root/codewhale-home/config.toml" \ |
| 38 | CODEX_HOME="$root/codex" \ |
| 39 | GROK_HOME="$root/grok" \ |
| 40 | GROK_AUTH_PATH="$root/grok/auth.json" \ |
| 41 | KIMI_CODE_HOME="$root/kimi-code" \ |
| 42 | KIMI_SHARE_DIR="$root/kimi-share" \ |
| 43 | CLAUDE_CONFIG_DIR="$root/claude" \ |
| 44 | DEEPSEEK_API_KEY= \ |
| 45 | OPENAI_API_KEY= \ |
| 46 | ANTHROPIC_API_KEY= \ |
| 47 | XAI_API_KEY= \ |
| 48 | GROK_API_KEY= \ |
| 49 | MOONSHOT_API_KEY= \ |
| 50 | KIMI_API_KEY= \ |
| 51 | XIAOMI_MIMO_API_KEY= \ |
| 52 | XIAOMI_MIMO_TOKEN_PLAN_API_KEY= \ |
| 53 | MIMO_API_KEY= \ |
| 54 | MIMO_TOKEN_PLAN_API_KEY= \ |
| 55 | CARGO_HOME="$real_cargo_home" \ |
| 56 | RUSTUP_HOME="$real_rustup_home" \ |
| 57 | PATH="$toolchain_bin:$PATH" \ |
| 58 | sh -c ' |
| 59 | if [ -n "$1" ]; then |
| 60 | exec "$2" test --quiet -p codewhale-tui --bin codewhale-tui --locked "$1" |
| 61 | fi |
| 62 | exec "$2" test --quiet -p codewhale-tui --bin codewhale-tui --locked |
| 63 | ' sh "$filter" "$toolchain_bin/cargo" |
| 64 | ) |
| 65 | run=$((run + 1)) |
| 66 | done |
| 67 |