feat(agents): прокси для Codex и Claude задаётся в их настройках
- Зачем: прокси из окружения запуска до API не доходил. Запросы Codex отправляет общий демон app-server, и маршрут зависел от того, кто запустил демон первым. Нужно было и обратное: Codex и Claude должны работать без прокси, даже если запускающее приложение его задало. - Что: шаблоны codex/proxy.env (копируется в ~/.codex/.env) и claude/proxy-settings.json (блок env добавляется в ~/.claude/settings.json). По умолчанию прокси 127.0.0.1:12334. install.sh не трогает выбор, уже сделанный на машине. В README описано, как переключить машину на работу без прокси. - Проверка: tests/test_install.sh и tests/test_proxy_env_sync.py проходят. Вручную: значения из ~/.codex/.env и из env в настройках Claude перекрывают унаследованные переменные; codex doctor проходит через Xray; очищенные адреса вместе с NO_PROXY=* дают прямое подключение. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d19239bf31
commit
d65403efb5
5 files changed
+213
-4
No files matched your search
+97
-1
@@ -39,7 +39,7 @@ setup_fixture() {
|
||||
# stow конфликтами, поэтому в тестовое дерево не попадает.
|
||||
git -C "$REPO_ROOT" ls-files -z --cached --others --exclude-standard -- \
|
||||
install.sh bash tmux vim zed kitty wezterm vscode agents opencode gemini \
|
||||
claude proxy-client chatgpt scripts \
|
||||
claude codex proxy-client chatgpt scripts \
|
||||
| tar -C "$REPO_ROOT" --null -T - -cf - \
|
||||
| tar -xf - -C "$repo_root"
|
||||
|
||||
@@ -245,6 +245,97 @@ test_codex_runtime_dir_is_unmanaged() {
|
||||
assert_file_contains "$home_dir/.codex/auth.json" "{}"
|
||||
}
|
||||
|
||||
test_codex_env_is_created_when_missing() {
|
||||
local fixture repo_root home_dir
|
||||
fixture="$(setup_fixture)"
|
||||
repo_root="$fixture/repo"
|
||||
home_dir="$fixture/home"
|
||||
mkdir -p "$home_dir"
|
||||
|
||||
run_install "$repo_root" "$home_dir" env WSL_DISTRO_NAME= INSTALL_INTERACTIVE_MODE=never >"$fixture/install.out"
|
||||
|
||||
[ -f "$home_dir/.codex/.env" ] && [ ! -L "$home_dir/.codex/.env" ] \
|
||||
|| fail "Expected ~/.codex/.env to be a regular file"
|
||||
cmp -s "$repo_root/codex/proxy.env" "$home_dir/.codex/.env" \
|
||||
|| fail "Expected ~/.codex/.env to match codex/proxy.env"
|
||||
}
|
||||
|
||||
test_codex_env_is_kept_when_present() {
|
||||
local fixture repo_root home_dir backup
|
||||
fixture="$(setup_fixture)"
|
||||
repo_root="$fixture/repo"
|
||||
home_dir="$fixture/home"
|
||||
# Машина, где Codex ходит без прокси: свой .env установщик не трогает.
|
||||
mkdir -p "$home_dir/.codex"
|
||||
printf '%s\n' 'HTTPS_PROXY=' > "$home_dir/.codex/.env"
|
||||
|
||||
run_install "$repo_root" "$home_dir" env WSL_DISTRO_NAME= INSTALL_INTERACTIVE_MODE=never >"$fixture/install.out"
|
||||
|
||||
[ "$(cat "$home_dir/.codex/.env")" = 'HTTPS_PROXY=' ] \
|
||||
|| fail "Expected existing ~/.codex/.env to stay unchanged"
|
||||
backup="$(find "$home_dir/.codex" -name '.env.bak.*' -print -quit)"
|
||||
[ -z "$backup" ] || fail "Existing ~/.codex/.env must not be backed up: $backup"
|
||||
}
|
||||
|
||||
claude_env_value() {
|
||||
python3 -I -c 'import json, sys; print(json.load(open(sys.argv[1]))["env"].get(sys.argv[2], "<нет>"))' "$1" "$2"
|
||||
}
|
||||
|
||||
test_claude_proxy_is_added_to_new_settings() {
|
||||
local fixture repo_root home_dir
|
||||
fixture="$(setup_fixture)"
|
||||
repo_root="$fixture/repo"
|
||||
home_dir="$fixture/home"
|
||||
mkdir -p "$home_dir"
|
||||
|
||||
run_install "$repo_root" "$home_dir" env WSL_DISTRO_NAME= INSTALL_INTERACTIVE_MODE=never >"$fixture/install.out"
|
||||
|
||||
[ "$(claude_env_value "$home_dir/.claude/settings.json" HTTPS_PROXY)" = 'http://127.0.0.1:12334' ] \
|
||||
|| fail "Expected HTTPS_PROXY in new ~/.claude/settings.json"
|
||||
[ "$(stat -c %a "$home_dir/.claude/settings.json")" = 600 ] \
|
||||
|| fail "Expected new ~/.claude/settings.json to be private"
|
||||
}
|
||||
|
||||
test_claude_proxy_is_merged_into_existing_settings() {
|
||||
local fixture repo_root home_dir
|
||||
fixture="$(setup_fixture)"
|
||||
repo_root="$fixture/repo"
|
||||
home_dir="$fixture/home"
|
||||
mkdir -p "$home_dir/.claude"
|
||||
printf '%s\n' '{"theme": "dark", "env": {"FOO": "bar"}}' > "$home_dir/.claude/settings.json"
|
||||
|
||||
run_install "$repo_root" "$home_dir" env WSL_DISTRO_NAME= INSTALL_INTERACTIVE_MODE=never >"$fixture/install.out"
|
||||
|
||||
[ "$(claude_env_value "$home_dir/.claude/settings.json" no_proxy)" != '<нет>' ] \
|
||||
|| fail "Expected no_proxy to be merged into ~/.claude/settings.json"
|
||||
[ "$(claude_env_value "$home_dir/.claude/settings.json" FOO)" = bar ] \
|
||||
|| fail "Expected existing env keys to be preserved"
|
||||
assert_file_contains "$home_dir/.claude/settings.json" '"theme": "dark"'
|
||||
}
|
||||
|
||||
test_claude_existing_proxy_choice_is_kept() {
|
||||
local fixture repo_root home_dir
|
||||
fixture="$(setup_fixture)"
|
||||
repo_root="$fixture/repo"
|
||||
home_dir="$fixture/home"
|
||||
# Машина без прокси: достаточно одной proxy-переменной, чтобы шаблон не применялся.
|
||||
mkdir -p "$home_dir/.claude"
|
||||
printf '%s\n' '{"env": {"no_proxy": "*"}}' > "$home_dir/.claude/settings.json"
|
||||
printf '%s\n' '{not json' > "$fixture/broken.json"
|
||||
|
||||
run_install "$repo_root" "$home_dir" env WSL_DISTRO_NAME= INSTALL_INTERACTIVE_MODE=never >"$fixture/install.out"
|
||||
|
||||
[ "$(cat "$home_dir/.claude/settings.json")" = '{"env": {"no_proxy": "*"}}' ] \
|
||||
|| fail "Expected settings with a proxy choice to stay unchanged"
|
||||
|
||||
cp "$fixture/broken.json" "$home_dir/.claude/settings.json"
|
||||
run_install "$repo_root" "$home_dir" env WSL_DISTRO_NAME= INSTALL_INTERACTIVE_MODE=never >"$fixture/install2.out"
|
||||
cmp -s "$fixture/broken.json" "$home_dir/.claude/settings.json" \
|
||||
|| fail "Expected invalid settings.json to stay unchanged"
|
||||
grep -Fq 'не разобран как JSON' "$fixture/install2.out" \
|
||||
|| fail "Expected warning about invalid settings.json"
|
||||
}
|
||||
|
||||
test_migrates_folded_codex_symlink() {
|
||||
local fixture repo_root home_dir legacy_dir
|
||||
fixture="$(setup_fixture)"
|
||||
@@ -651,6 +742,11 @@ main() {
|
||||
test_rerun_does_not_backup_managed_kitty_config
|
||||
test_existing_wezterm_config_is_backed_up
|
||||
test_codex_runtime_dir_is_unmanaged
|
||||
test_codex_env_is_created_when_missing
|
||||
test_codex_env_is_kept_when_present
|
||||
test_claude_proxy_is_added_to_new_settings
|
||||
test_claude_proxy_is_merged_into_existing_settings
|
||||
test_claude_existing_proxy_choice_is_kept
|
||||
test_migrates_folded_codex_symlink
|
||||
test_claude_stale_artifacts_are_removed
|
||||
test_migrates_legacy_zed_config_symlink
|
||||
|
||||
Reference in new issue
Block a user