From 768f0ab6b6580a203ed2152fd32e453b07258ebc Mon Sep 17 00:00:00 2001 From: Su Yang Date: Mon, 5 Oct 2026 21:16:55 +0800 Subject: [PATCH] install: preserve options following --setup-repo Remove the extra shift from the valueless --setup-repo option. The loop already advances past the current option; advancing twice discarded the next argument, including --dry-run, --mirror, --channel, or --help. A swallowed --dry-run could run prerequisite installation and repository configuration instead of only printing the execution plan. Add 17 offline parser regression scenarios and a dedicated sh/bash CI workflow. Extract the real parser before installation functions so the regression cannot invoke package managers even against a broken script. Cover option order, values, repeated flags, environment compatibility, help, and error handling without changing other option semantics. Validated on both fork-main and TencentCloud branch baselines: 17 new parser scenarios plus 18 existing mirror scenarios under sh, bash, and BusyBox ash (210 successful scenario executions). Both unpatched baselines fail the new --setup-repo --dry-run regression. Shell syntax and workflow YAML checks passed. No cloud network or package installation was tested. Signed-off-by: Su Yang --- .github/workflows/setup-repo.yml | 21 +++++ install.sh | 1 - scripts/test-setup-repo.sh | 150 +++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/setup-repo.yml create mode 100755 scripts/test-setup-repo.sh diff --git a/.github/workflows/setup-repo.yml b/.github/workflows/setup-repo.yml new file mode 100644 index 00000000..7dc56ff6 --- /dev/null +++ b/.github/workflows/setup-repo.yml @@ -0,0 +1,21 @@ +name: setup-repo option regression + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + test-setup-repo-options: + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3 + - name: Check shell syntax + run: | + sh -n install.sh + sh -n scripts/test-setup-repo.sh + - name: Check setup-repo options (offline only) + run: | + sh scripts/test-setup-repo.sh + TEST_SHELL=bash sh scripts/test-setup-repo.sh diff --git a/install.sh b/install.sh index a9f07402..a759809f 100755 --- a/install.sh +++ b/install.sh @@ -171,7 +171,6 @@ while [ $# -gt 0 ]; do ;; --setup-repo) REPO_ONLY=1 - shift ;; --no-autostart) NO_AUTOSTART=1 diff --git a/scripts/test-setup-repo.sh b/scripts/test-setup-repo.sh new file mode 100755 index 00000000..c999227b --- /dev/null +++ b/scripts/test-setup-repo.sh @@ -0,0 +1,150 @@ +#!/bin/sh +# Exercise the real option parser without entering the installation code. +# In particular, a broken --setup-repo must never turn this test into an install. +set -eu + +cd "$(dirname "$0")/.." +test_shell=${TEST_SHELL:-sh} +tmp_dir=$(mktemp -d) +trap 'rm -rf "$tmp_dir"' 0 +trap 'exit 1' HUP INT TERM + +# Keep the argument parser and mirror/channel validation verbatim. Stop before +# function definitions and do_install, so even a swallowed --dry-run is harmless. +# Fail closed if the boundary changes instead of executing the complete script. +awk ' + /^command_exists\(\) \{$/ { found = 1; exit } + { print } + END { if (!found) exit 1 } +' install.sh > "$tmp_dir/parser.sh" +cat >> "$tmp_dir/parser.sh" <<'PROBE' +printf 'REPO_ONLY=%s\nDRY_RUN=%s\nNO_AUTOSTART=%s\nCHANNEL=%s\nVERSION=%s\nDOWNLOAD_URL=%s\n' \ + "$REPO_ONLY" "$DRY_RUN" "$NO_AUTOSTART" "$CHANNEL" "$VERSION" "$DOWNLOAD_URL" +PROBE + +output="$tmp_dir/output" +dry_run='' +count=0 + +fail() { + printf 'FAIL (offline): %s\n' "$1" >&2 + cat "$output" >&2 + exit 1 +} + +run() { + expected_status=$1 + shift + status=0 + env -i PATH="$PATH" HOME="${HOME:-/tmp}" DRY_RUN="$dry_run" \ + "$test_shell" "$tmp_dir/parser.sh" "$@" > "$output" 2>&1 || status=$? + [ "$status" -eq "$expected_status" ] || fail "expected status $expected_status, got $status" +} + +contains() { + grep -F -- "$1" "$output" > /dev/null || fail "missing: $1" +} + +equals() { + grep -Fx -- "$1" "$output" > /dev/null || fail "missing exact value: $1" +} + +pass() { + count=$((count + 1)) + printf 'PASS (offline): %s\n' "$1" +} + +run 0 +equals 'REPO_ONLY=0' +equals 'DRY_RUN=' +pass 'defaults' + +run 0 --setup-repo +equals 'REPO_ONLY=1' +pass '--setup-repo as the only argument' + +run 0 --setup-repo --dry-run +equals 'REPO_ONLY=1' +equals 'DRY_RUN=1' +pass '--setup-repo preserves following --dry-run' + +run 0 --dry-run --setup-repo +equals 'REPO_ONLY=1' +equals 'DRY_RUN=1' +pass '--setup-repo as the last argument' + +run 0 --setup-repo --mirror Aliyun +equals 'REPO_ONLY=1' +equals 'DOWNLOAD_URL=https://mirrors.aliyun.com/docker-ce' +pass '--setup-repo preserves following --mirror and value' + +run 0 --mirror Aliyun --setup-repo +equals 'REPO_ONLY=1' +equals 'DOWNLOAD_URL=https://mirrors.aliyun.com/docker-ce' +pass 'mirror before --setup-repo' + +run 0 --setup-repo --channel test +equals 'REPO_ONLY=1' +equals 'CHANNEL=test' +pass '--setup-repo preserves following --channel and value' + +run 0 --setup-repo --version v27.5 +equals 'REPO_ONLY=1' +equals 'VERSION=27.5' +pass '--setup-repo preserves following --version and value' + +run 0 --setup-repo --no-autostart +equals 'REPO_ONLY=1' +equals 'NO_AUTOSTART=1' +pass '--setup-repo preserves following --no-autostart' + +run 0 --setup-repo --help +contains 'USAGE:' +if grep -F 'REPO_ONLY=' "$output" > /dev/null; then + fail '--help must exit before the parser probe' +fi +pass '--setup-repo preserves following --help' + +run 1 --setup-repo --unknown-option +contains 'Illegal option --unknown-option' +pass '--setup-repo does not hide an invalid option' + +run 0 --setup-repo --setup-repo --dry-run +equals 'REPO_ONLY=1' +equals 'DRY_RUN=1' +pass 'repeated --setup-repo remains idempotent' + +run 0 --setup-repo --dry-run --mirror Aliyun --channel test --version v27.5 --no-autostart +equals 'REPO_ONLY=1' +equals 'DRY_RUN=1' +equals 'DOWNLOAD_URL=https://mirrors.aliyun.com/docker-ce' +equals 'CHANNEL=test' +equals 'VERSION=27.5' +equals 'NO_AUTOSTART=1' +pass 'all options after --setup-repo' + +run 0 --dry-run --mirror Aliyun --channel test --version v27.5 --no-autostart --setup-repo +equals 'REPO_ONLY=1' +equals 'DRY_RUN=1' +equals 'DOWNLOAD_URL=https://mirrors.aliyun.com/docker-ce' +equals 'CHANNEL=test' +equals 'VERSION=27.5' +equals 'NO_AUTOSTART=1' +pass 'all options before --setup-repo' + +dry_run=1 +run 0 --setup-repo +equals 'REPO_ONLY=1' +equals 'DRY_RUN=1' +pass 'DRY_RUN environment variable remains supported' +dry_run='' + +run 1 --setup-repo --mirror UnknownMirror +contains "unknown mirror 'UnknownMirror'" +pass '--setup-repo does not hide mirror validation' + +run 1 --setup-repo --channel invalid +contains "unknown CHANNEL 'invalid'" +pass '--setup-repo does not hide channel validation' + +printf '%s offline parser scenarios passed; no network or installation was attempted.\n' "$count"