refactor(wsl): унифицирована логика hproxy.local и добавлена миграция legacy boot command

- Зачем:
  - setup-hproxy.sh удалял запись из hosts до проверки gateway — при ошибке hosts ломался.
  - update_hproxy() дублировала логику скрипта с багами и не тестировалась.
  - legacy inline boot command в wsl.conf не мигрировался автоматически.
- Что:
  - setup-hproxy.sh: безопасный порядок (gateway → hosts), set -e, экранированная точка в sed.
  - update_hproxy() заменена на thin wrapper с проверкой wsl.conf и ошибок sudo.
  - install.sh: интерактивная замена legacy boot command, детекция существующих [boot] command,
    принимает русскую «у» наравне с «y».
  - README.md: описаны три сценария (WSL NAT, WSL mirrored — host-side resolution, native Linux).
  - добавлены тесты: existing boot command preserved, legacy command migration hint.
- Проверка:
  - bash tests/test_install.sh
  - ./install.sh (интерактивно, ответить «y» на миграцию legacy command)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ddadminandClaude Opus 4.6 committed 2026-03-22 19:42:50 +03:00
1 parent 1963b6a117
commit 898db1098d
5 files changed
+131 -66

No files matched your search

+53
View File
@@ -236,6 +236,57 @@ test_wsl_noninteractive_skips_file_changes() {
printf '%s' "$output" | grep -Fq 'Добавьте вручную:' || fail "Expected manual WSL hint"
}
test_wsl_noninteractive_existing_boot_command_is_preserved() {
local fixture repo_root home_dir wsl_conf output
fixture="$(setup_fixture)"
repo_root="$fixture/repo"
home_dir="$fixture/home"
wsl_conf="$fixture/wsl.conf"
mkdir -p "$home_dir"
cat > "$wsl_conf" <<'EOF'
[boot]
command = "/usr/local/bin/existing.sh"
EOF
output="$(
run_install "$repo_root" "$home_dir" \
env WSL_DISTRO_NAME=Ubuntu INSTALL_INTERACTIVE_MODE=never WSL_CONF_PATH="$wsl_conf"
)"
assert_file_contains "$wsl_conf" 'command = "/usr/local/bin/existing.sh"'
if grep -Fq 'setup-hproxy.sh' "$wsl_conf"; then
fail "Expected existing boot command to stay untouched"
fi
printf '%s' "$output" | grep -Fq 'уже содержит [boot] command' || fail "Expected warning about existing boot command"
if printf '%s' "$output" | grep -Fq 'Добавьте вручную:'; then
fail "Did not expect manual add hint when [boot] command already exists"
fi
}
test_wsl_legacy_boot_command_suggests_migration() {
local fixture repo_root home_dir wsl_conf output command_line
fixture="$(setup_fixture)"
repo_root="$fixture/repo"
home_dir="$fixture/home"
wsl_conf="$fixture/wsl.conf"
mkdir -p "$home_dir"
cat > "$wsl_conf" <<'EOF'
[boot]
command = "ip route show default | awk '{print $3 \" hproxy.local\"}' >> /etc/hosts"
EOF
command_line="command = \"$repo_root/scripts/setup-hproxy.sh\""
output="$(
run_install "$repo_root" "$home_dir" \
env WSL_DISTRO_NAME=Ubuntu INSTALL_INTERACTIVE_MODE=never WSL_CONF_PATH="$wsl_conf"
)"
assert_file_contains "$wsl_conf" 'command = "ip route show default | awk '\''{print $3 \" hproxy.local\"}'\'' >> /etc/hosts"'
printf '%s' "$output" | grep -Fq 'legacy boot command' || fail "Expected legacy boot command warning"
printf '%s' "$output" | grep -Fq 'Рекомендуется заменить' || fail "Expected migration hint to replace legacy command"
printf '%s' "$output" | grep -Fq "$command_line" || fail "Expected suggested setup-hproxy.sh command"
}
test_wsl_interactive_adds_boot_command() {
local fixture repo_root home_dir wsl_conf command_line
fixture="$(setup_fixture)"
@@ -289,6 +340,8 @@ main() {
test_broken_claude_symlink_does_not_fail
test_absolute_symlinks_in_home_do_not_break_install
test_wsl_noninteractive_skips_file_changes
test_wsl_noninteractive_existing_boot_command_is_preserved
test_wsl_legacy_boot_command_suggests_migration
test_wsl_interactive_adds_boot_command
test_wsl_existing_boot_command_is_preserved