跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

setup-script.sh

372 行 · 21.7 KB历史下载
1#!/usr/bin/env bash
2#
3# Checks of agent-vm.setup.sh, the script `agent-vm setup` runs in the base
4# VM: its blocks lifted out and run against stubs, nothing installed. Run by
5# TestSetupScript (setup_script_test.go), or alone:
6#
7# tests/setup-script.sh
8
9set -uo pipefail
10
11SELF_DIR="$(CDPATH= cd -- "$(dirname "${BASH_SOURCE[0]:-$0}")/.." >/dev/null && pwd)"
12SETUP_SH="${SETUP_SH:-$SELF_DIR/agent-vm.setup.sh}"
13
14FAIL=0
15PASSED=0
16pass() { PASSED=$((PASSED + 1)); printf ' ok %s\n' "$1"; }
17fail() { FAIL=$((FAIL + 1)); printf ' FAIL %s\n' "$1"; }
18check() {
19 if [ "$2" = "$3" ]; then pass "$1"
20 else fail "$1"; printf ' expected: %s\n actual: %s\n' "$3" "$2"; fi
21}
22section() { printf '\n%s\n' "$1"; }
23
24SB="$(mktemp -d)"
25# Physical path: macOS reaches its temp dir through /private.
26SB="$(CDPATH= cd -P -- "$SB" >/dev/null && pwd)"
27trap 'rm -rf "$SB"' EXIT
28
29# =============================================================================
30section "setup script: apt runs with a working debconf frontend"
31# =============================================================================
32# `export DEBIAN_FRONTEND=noninteractive` does not survive sudo's env_reset,
33# so an apt call that does not carry the variable itself prints debconf's
34# "unable to initialize frontend: Dialog" block on every install step.
35if grep -qE '^[^#]*sudo apt-get' "$SETUP_SH"; then
36 fail "an apt call bypasses apt_get: $(grep -nE '^[^#]*sudo apt-get' "$SETUP_SH" | head -1)"
37else
38 pass "every apt call goes through apt_get"
39fi
40# The script reaches bash on its stdin: a command that reads stdin swallows the
41# lines after it. Here sudo stands for a dpkg prompt, reading all it can.
42apt_fn="$(sed -n '/^apt_get() {/,/^}/p' "$SETUP_SH")"
43check "apt_get does not read the script's stdin" \
44 "$({ printf 'sudo() { cat >/dev/null; }\n%s\napt_get update\necho after\n' "$apt_fn"; } | bash 2>/dev/null)" "after"
45check "npm installs do not read it either" \
46 "$(grep -E '^[^#]*npm i ' "$SETUP_SH" | grep -vc '</dev/null$')" "0"
47if grep -q 'sudo env DEBIAN_FRONTEND=noninteractive apt-get' "$SETUP_SH"; then
48 pass "apt_get hands the frontend to sudo"
49else
50 fail "apt_get no longer passes DEBIAN_FRONTEND through sudo"
51fi
52# Recommends pull in Samba, avahi-daemon, printer config... via Chromium.
53if grep -qv -- '--no-install-recommends' <<< "$(grep -E '^[^#]*apt_get install' "$SETUP_SH")"; then
54 fail "an install pulls in Recommends: $(grep -nE '^[^#]*apt_get install' "$SETUP_SH" | grep -v -- '--no-install-recommends' | head -1)"
55else
56 pass "every apt install skips Recommends"
57fi
58if grep -qE '^[^#]*\| *sudo( -E)? bash' "$SETUP_SH"; then
59 fail "a remote script is piped to a root shell: $(grep -nE '^[^#]*\| *sudo( -E)? bash' "$SETUP_SH" | head -1)"
60else
61 pass "no remote script runs as root"
62fi
63
64# Exercise the real package transaction without installing on the host.
65chromium_block="$(awk '/^if \[\[ "\$INSTALL_CHROMIUM" == "1" \]\]; then/,/^fi$/' "$SETUP_SH")"
66chromium_install="$(
67 INSTALL_CHROMIUM=1 CLAUDE_CAGE=1
68 sudo() { :; }
69 apt_get() { printf 'install: %s\n' "$*"; }
70 cage_is_ubuntu() { return 1; }
71 cage_cache_chromium() { printf 'cache: %s\n' "$*"; }
72 eval "$chromium_block"
73)"
74case "$chromium_install" in
75 *'install: install -y --no-install-recommends chromium chromium-l10n '*) pass "Chromium explicitly installs its language packs";;
76 *) fail "Chromium install omits language packs: $chromium_install";;
77esac
78
79# Behind a proxy, sudo must keep the proxy settings Lima puts in the guest's
80# environment (#25): installed before the first apt call, and checked by
81# visudo first, since a broken sudoers file breaks sudo.
82proxy_line="$(grep -n '/etc/sudoers.d/10-agent-vm-proxy' "$SETUP_SH" | head -1 | cut -d: -f1)"
83visudo_line="$(grep -n 'sudo visudo -cqf /tmp/agent-vm-proxy.sudoers' "$SETUP_SH" | head -1 | cut -d: -f1)"
84apt_line="$(grep -nE '^[^#]*apt_get (update|install)' "$SETUP_SH" | head -1 | cut -d: -f1)"
85if [ -n "$proxy_line" ] && [ -n "$visudo_line" ] && [ "$visudo_line" -lt "$proxy_line" ] && [ "$proxy_line" -lt "$apt_line" ]; then
86 pass "sudo keeps the proxy settings from before the first apt call, checked by visudo"
87else
88 fail "proxy sudoers drop-in: visudo at ${visudo_line:-none}, install at ${proxy_line:-none}, first apt at ${apt_line:-none}"
89fi
90kept=" $(grep -o 'env_keep += "[^"]*"' "$SETUP_SH" | cut -d'"' -f2) "
91dropped=""
92for v in http_proxy https_proxy ftp_proxy no_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY NO_PROXY; do
93 case "$kept" in *" $v "*) ;; *) dropped="$dropped $v" ;; esac
94done
95check "sudo keeps every proxy variable, both cases" "$dropped" ""
96
97# Shell history in the VM (#20): the block setup appends to ~/.zshrc, run by
98# zsh itself.
99sed -n "/^cat >> ~\/.zshrc <<'ZSHRC'/,/^ZSHRC\$/p" "$SETUP_SH" | sed '1d;$d' > "$SB/zshrc-history"
100if command -v zsh >/dev/null 2>&1; then
101 check "zsh history: saved to a file, space-prefixed commands left out" \
102 "$(HOME="$SB" zsh -fc '. "$1"; print -r -- "$HISTFILE $SAVEHIST"; [[ -o histignorespace && -o incappendhistory ]] && print opts' _ "$SB/zshrc-history")" \
103 "$SB/.zsh_history 10000
104opts"
105else
106 printf ' skip zsh history (zsh not installed)\n'
107fi
108
109# The sshfs wrapper, run against a stub that stands for /usr/bin/sshfs:
110# no_contain_symlinks is added only when that sshfs knows it (#22).
111sed -n '/^sudo tee \/usr\/local\/bin\/sshfs/,/^EOF$/p' "$SETUP_SH" | sed '1d;$d' \
112 | sed "s|/usr/bin/sshfs|$SB/sshfs-real|g" > "$SB/sshfs-wrapper"
113sshfs_stub() { # <help text>
114 printf '#!/bin/sh\n[ "$1" = -h ] && { echo "%s"; exit 1; }\necho "$*"\n' "$1" > "$SB/sshfs-real"
115 chmod +x "$SB/sshfs-real"
116}
117sshfs_stub ' -o no_contain_symlinks allow all symlink targets'
118check "sshfs wrapper: turns contain_symlinks off where it exists" \
119 "$(sh "$SB/sshfs-wrapper" ':/p' /p -o slave -o allow_other)" ":/p /p -o slave -o allow_other -o no_contain_symlinks"
120sshfs_stub ' -o follow_symlinks'
121check "sshfs wrapper: an older sshfs gets the arguments unchanged" \
122 "$(sh "$SB/sshfs-wrapper" ':/p' /p -o slave)" ":/p /p -o slave"
123
124# An agent is there as a command, as an extension, or both: either way its
125# config (managed settings, MCP servers) is written. The lines setup derives
126# it with, run as setup does.
127has_block="$(awk '/^HAS_CLAUDE=0 HAS_OPENCODE=0 HAS_CODEX=0 HAS_VIBE=0$/,/HAS_VIBE=1$/' "$SETUP_SH")"
128# shellcheck disable=SC2034 # read by the eval'd block
129has() { ( INSTALL_CLAUDE="$1" INSTALL_CODE_CLAUDE="$2" INSTALL_OPENCODE="$3" INSTALL_CODE_OPENCODE="$4" INSTALL_CODEX="$5" INSTALL_CODE_CODEX="$6" INSTALL_VIBE="$7" INSTALL_CODE_VIBE="$8"
130 eval "$has_block"; echo "$HAS_CLAUDE$HAS_OPENCODE$HAS_CODEX$HAS_VIBE" ); }
131check "setup: the agents' config, for a command or an extension" \
132 "$(has 1 0 0 0 0 0 0 0) $(has 0 1 0 0 0 0 0 0) $(has 0 0 1 0 0 0 0 0) $(has 0 0 0 1 0 0 0 0) $(has 0 0 0 0 1 0 0 0) $(has 0 0 0 0 0 1 0 0) $(has 0 0 0 0 0 0 1 1) $(has 0 0 0 0 0 0 0 0)" "1000 1000 0100 0100 0010 0010 0001 0000"
133
134# =============================================================================
135section "MCP config writer"
136# =============================================================================
137# configure_mcp lives in the in-VM setup script, whose top level performs the
138# actual installs, so lift just that function out rather than sourcing it.
139if ! command -v jq >/dev/null 2>&1; then
140 printf ' skip configure_mcp tests (jq not installed)\n'
141else
142 MCPHOME="$SB/mcp"; mkdir -p "$MCPHOME"
143 (
144 HOME="$MCPHOME"
145 eval "$(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")"
146 HAS_CLAUDE=1 HAS_OPENCODE=1 HAS_VIBE=1 HAS_CODEX=1
147 for _ in 1 2; do # twice: the writer must be idempotent
148 configure_mcp chrome-devtools npx -y chrome-devtools-mcp@latest --headless=true
149 configure_mcp playwright env PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npx -y @playwright/mcp@latest
150 done
151 ) >/dev/null 2>&1
152
153 oc="$MCPHOME/.config/opencode/opencode.json"
154 check "opencode: two servers" "$(jq '.mcp | length' "$oc")" "2"
155 check "opencode: \$schema kept" "$(jq -r '."$schema"' "$oc")" "https://opencode.ai/config.json"
156 check "opencode: command starts with the launcher" \
157 "$(jq -r '.mcp.playwright.command[0]' "$oc")" "env"
158 check "opencode: env assignment survives as its own argv entry" \
159 "$(jq -r '.mcp.playwright.command[1]' "$oc")" "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1"
160 check "claude: two servers" \
161 "$(jq '.mcpServers | length' "$MCPHOME/.claude.json")" "2"
162 check "codex: no duplicate table after two runs" \
163 "$(grep -cF '[mcp_servers.playwright]' "$MCPHOME/.codex/config.toml")" "1"
164 check "vibe: no duplicate entry after two runs" \
165 "$(grep -c '^\[\[mcp_servers\]\]' "$MCPHOME/.vibe/config.toml")" "2"
166fi
167
168# =============================================================================
169section "Pi install block"
170# =============================================================================
171# Lifted out like configure_mcp, with sudo recorded instead of run.
172if ! command -v jq >/dev/null 2>&1; then
173 printf ' skip Pi install tests (jq not installed)\n'
174else
175 pi_block="$(awk '/^if \[\[ "\$INSTALL_PI" == "1" \]\]; then/,/^fi$/' "$SETUP_SH")"
176 # shellcheck disable=SC2034 # read by the eval'd block
177 run_pi_block() {
178 ( HOME="$1"; INSTALL_PI=1 INSTALL_NODE="$2"
179 sudo() { echo "sudo $*" >> "$HOME/sudo.log"; }
180 eval "$pi_block" ) >/dev/null 2>&1
181 }
182 PIH="$SB/pi-home"; mkdir -p "$PIH"
183 run_pi_block "$PIH" 1
184 check "pi: the maintained package, without install scripts" "$(cat "$PIH/sudo.log" 2>/dev/null)" \
185 "sudo npm i -g --ignore-scripts @earendil-works/pi-coding-agent"
186 # (The </dev/null is a redirection, which the recording sudo does not see.)
187 check "pi: project files trusted" \
188 "$(jq -r .defaultProjectTrust "$PIH/.pi/agent/settings.json" 2>/dev/null)" "always"
189 check "pi: telemetry off" \
190 "$(jq -r .enableInstallTelemetry "$PIH/.pi/agent/settings.json" 2>/dev/null)" "false"
191 PIH0="$SB/pi-home-nonode"; mkdir -p "$PIH0"
192 run_pi_block "$PIH0" 0
193 check "pi: skipped without node" "$( [ -e "$PIH0/sudo.log" ] || [ -e "$PIH0/.pi" ]; echo $?)" "1"
194fi
195
196# =============================================================================
197section "OpenCode install block"
198# =============================================================================
199# The extension needs the command line: either flag installs it.
200oc_block="$(awk '/^if \[\[ "\$INSTALL_OPENCODE" == "1" \|\| "\$INSTALL_CODE_OPENCODE" == "1" \]\]; then/,/^fi$/' "$SETUP_SH")"
201# shellcheck disable=SC2034 # read by the eval'd block
202run_oc_block() {
203 ( HOME="$SB/oc-home"; mkdir -p "$HOME"; rm -f "$HOME/curl.log"
204 INSTALL_OPENCODE="$1" INSTALL_CODE_OPENCODE="$2"
205 curl() { echo "curl $*" >> "$HOME/curl.log"; }
206 eval "$oc_block" ) >/dev/null 2>&1
207 cat "$SB/oc-home/curl.log" 2>/dev/null
208}
209check "opencode: installed for the command line" "$(run_oc_block 1 0)" "curl -fsSL https://opencode.ai/install"
210check "opencode: installed for the extension alone" "$(run_oc_block 0 1)" "curl -fsSL https://opencode.ai/install"
211check "opencode: not installed for neither" "$(run_oc_block 0 0)" ""
212
213# =============================================================================
214section "code-server JSON schemas"
215# =============================================================================
216# code_server_schemas against a fake code-server and a curl serving files of
217# $SCH/web, named after the URL, recording what it was asked for. It runs in
218# the VM, under bash 4 or later.
219if ! command -v jq >/dev/null 2>&1 || [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
220 printf ' skip code-server schema tests (needs jq and bash 4)\n'
221else
222 SCH="$SB/schemas"; mkdir -p "$SCH/ext/a" "$SCH/ext/b" "$SCH/web"
223 web() { printf '%s' "$1" | tr -c 'a-zA-Z0-9' _; }
224 echo '{"contributes":{"jsonValidation":[{"fileMatch":"a.json","url":"https://h.test/s/a"},{"fileMatch":"x","url":"vscode://schemas/x"}]}}' > "$SCH/ext/a/package.json"
225 echo '{"contributes":{"jsonValidation":[{"fileMatch":"b.json","url":"https://json.schemastore.org/b"},{"fileMatch":"g","url":"https://h.test/gone"}]}}' > "$SCH/ext/b/package.json"
226 # a: an absolute ref, a relative one with ./ and a fragment, a local one,
227 # and one to the editor's own schemas.
228 echo '{"$ref":"#/definitions/x","definitions":{"x":{"$ref":"https://h.test/abs.json"},"y":{"$ref":"./rel.json#/z"},"z":{"$ref":"vscode://schemas/settings"},"w":{"properties":{"$ref":{"type":"string"}}}}}' > "$SCH/web/$(web https://h.test/s/a)"
229 # abs refers to a schema that is no object: true is a valid schema.
230 echo '{"type":"object","properties":{"t":{"$ref":"https://h.test/true.json"}}}' > "$SCH/web/$(web https://h.test/abs.json)"
231 echo 'true' > "$SCH/web/$(web https://h.test/true.json)"
232 echo '{"$ref":"../top.json"}' > "$SCH/web/$(web https://h.test/s/rel.json)"
233 echo '{"type":"string"}' > "$SCH/web/$(web https://h.test/top.json)"
234 echo '{"type":"number"}' > "$SCH/web/$(web https://www.schemastore.org/b)"
235 # c: listed at one URL, its $id another, which its relative references
236 # follow, as the editor's do. d: references up two folders.
237 mkdir -p "$SCH/ext/c"
238 echo '{"contributes":{"jsonValidation":[{"fileMatch":"c.json","url":"https://www.schemastore.org/package"},{"fileMatch":"d.json","url":"https://h.test/s/a/b/d.json"}]}}' > "$SCH/ext/c/package.json"
239 echo '{"$id":"https://json.schemastore.org/package.json","properties":{"e":{"$ref":"eslintrc.json#"}}}' > "$SCH/web/$(web https://www.schemastore.org/package)"
240 echo '{"type":"boolean"}' > "$SCH/web/$(web https://www.schemastore.org/eslintrc.json)"
241 echo '{"$ref":"../../c.json"}' > "$SCH/web/$(web https://h.test/s/a/b/d.json)"
242 echo '{"type":"null"}' > "$SCH/web/$(web https://h.test/s/c.json)"
243 out="$( ( curl() {
244 local o="" st=0
245 echo call >> "$SCH/calls"
246 while [ $# -gt 0 ]; do
247 case "$1" in
248 -o) o="$2"; shift 2 ;;
249 --parallel-max|--max-time) shift 2 ;;
250 -*) shift ;;
251 *)
252 echo "$1" >> "$SCH/fetched"
253 if [ -f "$SCH/web/$(web "$1")" ]; then cp "$SCH/web/$(web "$1")" "$o"; else st=22; fi
254 shift ;;
255 esac
256 done
257 return "$st"
258 }
259 set -euo pipefail
260 eval "$(awk '/^(code_server_schemas|schema_url_resolve)\(\) \{/,/^\}/' "$SETUP_SH")"
261 code_server_schemas "$SCH/ext" "$SCH/machine/settings.json"; echo "rc=$?" ) 2>&1)"
262 check "every schema named, and every one they refer to, by the URL the editor asks" \
263 "$(jq -r '."json.schemas"[].url' "$SCH/machine/settings.json" 2>/dev/null | sort | tr '\n' ' ')" \
264 "https://h.test/abs.json https://h.test/s/a https://h.test/s/a/b/d.json https://h.test/s/c.json https://h.test/s/rel.json https://h.test/top.json https://h.test/true.json https://json.schemastore.org/b https://json.schemastore.org/eslintrc.json https://www.schemastore.org/package "
265 check "a level of references fetched in one call" "$(wc -l < "$SCH/calls" | tr -d ' ')" "3"
266 check "each with its content" \
267 "$(jq -r '."json.schemas"[] | select(.url == "https://h.test/top.json") | .schema.type' "$SCH/machine/settings.json" 2>/dev/null)" "string"
268 check "json.schemastore.org fetched from www.schemastore.org, where it redirects" \
269 "$(grep -c 'json.schemastore.org' "$SCH/fetched"; grep -c '^https://www.schemastore.org/b$' "$SCH/fetched")" "$(printf '0\n1')"
270 check "the editor's own schemas are left alone" "$(grep -c vscode "$SCH/fetched")" "0"
271 case "$out" in
272 *"could not download the JSON schema https://h.test/gone"*"rc=0") pass "a failed download is a warning, not a failure" ;;
273 *) fail "failed download: $out" ;;
274 esac
275fi
276
277# =============================================================================
278section "code-server install block"
279# =============================================================================
280# Lifted out like the Pi block, with curl and code-server recorded instead of
281# run, then the MCP writer after it, as in the script.
282if ! command -v jq >/dev/null 2>&1; then
283 printf ' skip code-server install tests (jq not installed)\n'
284else
285 cs_block="$(awk '/^toml_prepend\(\) \{/,/^\}/' "$SETUP_SH")
286$(awk '/^if \[\[ "\$INSTALL_CODE_SERVER" == "1" \]\]; then/,/^fi$/' "$SETUP_SH")
287$(awk '/^configure_mcp\(\) \{/,/^\}/' "$SETUP_SH")"
288 # <home> <claude> <opencode> <codex> <vibe>: the extensions asked for.
289 # Under set -e, as the script runs: a failing step must show here. Twice:
290 # what it writes must not pile up when it runs again in the same VM. The
291 # first run's state is kept in <home>/first.
292 # shellcheck disable=SC2034 # read by the eval'd block
293 run_cs_block() {
294 mkdir -p "$1/.config/code-server"; echo "password: from-the-base" > "$1/.config/code-server/config.yaml"
295 ( set -e
296 HOME="$1"; INSTALL_CODE_SERVER=1 INSTALL_CODE_CLAUDE="$2" INSTALL_CODE_OPENCODE="$3" INSTALL_CODE_CODEX="$4" INSTALL_CODE_VIBE="$5"
297 HAS_CLAUDE="$2" HAS_OPENCODE="$3" HAS_CODEX="$4" HAS_VIBE="$5"
298 curl() { echo "curl $*" >> "$HOME/calls.log"; }
299 code-server() { echo "code-server $*" >> "$HOME/calls.log"; }
300 code_server_schemas() { echo "schemas $*" >> "$HOME/calls.log"; mkdir -p "$(dirname "$2")"; echo '{"json.schemas":[]}' > "$2"; }
301 eval "$cs_block"
302 mkdir -p "$HOME/first"
303 for f in .codex/config.toml .vibe/config.toml; do [ ! -f "$HOME/$f" ] || cp "$HOME/$f" "$HOME/first/${f%%/*}"; done
304 configure_mcp chrome-devtools npx -y chrome-devtools-mcp@latest
305 eval "$cs_block"
306 configure_mcp chrome-devtools npx -y chrome-devtools-mcp@latest
307 echo 'done' > "$HOME/finished" ) >/dev/null 2>&1
308 }
309 CSB="$SB/cs-bare"; mkdir -p "$CSB"
310 run_cs_block "$CSB" 0 0 0 0
311 check "code-server alone: no extension installed" "$(grep -c '^code-server' "$CSB/calls.log")" "0"
312 check "code-server alone: Copilot off" \
313 "$(jq -r '."chat.disableAIFeatures"' "$CSB/.local/share/code-server/User/settings.json")" "true"
314 check "code-server alone: dark theme" \
315 "$(jq -r '."workbench.colorTheme"' "$CSB/.local/share/code-server/User/settings.json")" "Dark 2026"
316 check "code-server alone: no telemetry, no experiments" \
317 "$(jq -r '[."telemetry.telemetryLevel", ."workbench.enableExperiments"] | map(tostring) | join(" ")' \
318 "$CSB/.local/share/code-server/User/settings.json")" "off false"
319 check "code-server alone: the editor downloads no schema" \
320 "$(jq -r '."json.schemaDownload.enable"' "$CSB/.local/share/code-server/User/settings.json")" "false"
321 check "code-server alone: setup puts them in the machine settings" \
322 "$(grep '^schemas' "$CSB/calls.log" | head -n 1 | sed 's|^schemas [^ ]*/lib/vscode/extensions |schemas <ext> |')" \
323 "schemas <ext> $CSB/.local/share/code-server/Machine/settings.json"
324 check "code-server alone: no Claude settings" \
325 "$(jq -r 'keys | map(select(startswith("claudeCode"))) | length' "$CSB/.local/share/code-server/User/settings.json")" "0"
326 check "the password code-server wrote is not left in the base" \
327 "$([ -e "$CSB/.config/code-server" ] && echo left || echo gone)" "gone"
328
329 check "code-server alone: runs to the end under set -e" "$(cat "$CSB/finished" 2>/dev/null)" "done"
330
331 CSA="$SB/cs-all"; mkdir -p "$CSA"
332 run_cs_block "$CSA" 1 1 1 1
333 check "with the extensions: runs to the end under set -e" "$(cat "$CSA/finished" 2>/dev/null)" "done"
334 check "codex: written on a fresh home" "$(head -n 2 "$CSA/first/.codex" 2>/dev/null | sort | tr '\n' ' ')" \
335 'approval_policy = "never" sandbox_mode = "danger-full-access" '
336 check "vibe: written on a fresh home" "$(cat "$CSA/first/.vibe" 2>/dev/null)" 'default_agent = "auto-approve"'
337 check "the four extensions, in one call" \
338 "$(grep '^code-server' "$CSA/calls.log" | head -n 1)" \
339 "code-server --install-extension anthropic.claude-code --install-extension sst-dev.opencode --install-extension openai.chatgpt --install-extension mistralai.mistral-vibe-code"
340 # The permission keys are machine-scoped: code-server reads them from the
341 # machine settings only.
342 check "claude: bypass mode allowed and picked, in the machine settings" \
343 "$(jq -r '[."claudeCode.allowDangerouslySkipPermissions", ."claudeCode.initialPermissionMode"] | map(tostring) | join(" ")' \
344 "$CSA/.local/share/code-server/Machine/settings.json")" "true bypassPermissions"
345 check "claude: and not in the user settings, where they do nothing" \
346 "$(jq -r 'keys | map(select(startswith("claudeCode.") and . != "claudeCode.hideOnboarding")) | length' \
347 "$CSA/.local/share/code-server/User/settings.json")" "0"
348 check "claude: no onboarding checklist" \
349 "$(jq -r '."claudeCode.hideOnboarding"' "$CSA/.local/share/code-server/User/settings.json")" "true"
350 check "codex: full access, once, before any table" \
351 "$(head -n 2 "$CSA/.codex/config.toml" | sort | tr '\n' ' '; grep -c '^approval_policy' "$CSA/.codex/config.toml")" \
352 'approval_policy = "never" sandbox_mode = "danger-full-access" 1'
353 check "vibe: auto-approve, once, before any table" \
354 "$(head -n 1 "$CSA/.vibe/config.toml"; grep -c '^default_agent' "$CSA/.vibe/config.toml")" \
355 "$(printf 'default_agent = "auto-approve"\n1')"
356 check "opencode: everything allowed, next to the MCP server, written twice" \
357 "$(jq -r '[.permission, (.mcp | keys | join(","))] | join(" ")' "$CSA/.config/opencode/opencode.json")" "allow chrome-devtools"
358 check "code-server alone: no OpenCode config" "$([ -e "$CSB/.config/opencode" ]; echo $?)" "1"
359 if python3 -c 'import tomllib' 2>/dev/null; then
360 check "codex: the file parses, keys at the top level" \
361 "$(python3 -c 'import sys,tomllib; d=tomllib.load(open(sys.argv[1],"rb")); print(d["approval_policy"], "chrome-devtools" in d["mcp_servers"])' "$CSA/.codex/config.toml")" \
362 "never True"
363 check "vibe: the file parses, key at the top level" \
364 "$(python3 -c 'import sys,tomllib; d=tomllib.load(open(sys.argv[1],"rb")); print(d["default_agent"], len(d["mcp_servers"]))' "$CSA/.vibe/config.toml")" \
365 "auto-approve 1"
366 else
367 printf ' skip TOML parse checks (no python3 with tomllib)\n'
368 fi
369fi
370
371printf '\n%s passed, %s failed\n' "$PASSED" "$FAIL"
372[ "$FAIL" -eq 0 ] || exit 1