feat(controller-peers-env-fallback): default the harness masters setting from XCE_CONTROLLER_PEERS (task 3.3)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
05a7e6dd0c
commit
65ae25a1e6
3 changed files with 154 additions and 8 deletions
|
|
@ -96,8 +96,6 @@ unset XCE_CONTROLLER_PEERS
|
|||
CONTROLLER_BIN=""
|
||||
SCHEDULER_BIN=""
|
||||
WORKER_BIN=""
|
||||
# Set by preflight; the harness cases (task 3.3) are its only reader.
|
||||
# shellcheck disable=SC2034
|
||||
HARNESS_BIN=""
|
||||
|
||||
# component:relative-path:variable
|
||||
|
|
@ -181,10 +179,13 @@ stop_all() {
|
|||
# left in RUN_RC and <dir>/rc (timed out: 124 with coreutils timeout, 143
|
||||
# with busybox timeout, 137 if it had to be SIGKILLed). `-k` rather than
|
||||
# `--kill-after` because busybox timeout only accepts the short form.
|
||||
# stdin is /dev/null, or the file named by RUN_STDIN when the caller sets it
|
||||
# for this one call (`RUN_STDIN=<file> run_to_completion ...`) -- xce_test
|
||||
# reads its script only from stdin.
|
||||
run_to_completion() {
|
||||
local dir="$1" secs="$2"; shift 2
|
||||
local dir="$1" secs="$2" in="${RUN_STDIN:-/dev/null}"; shift 2
|
||||
RUN_RC=0
|
||||
timeout -k 2 "$secs" env "$@" </dev/null \
|
||||
timeout -k 2 "$secs" env "$@" <"$in" \
|
||||
>"$dir/stdout" 2>"$dir/stderr" || RUN_RC=$?
|
||||
echo "$RUN_RC" >"$dir/rc"
|
||||
}
|
||||
|
|
@ -797,6 +798,92 @@ case_worker_help_names_variable() {
|
|||
add_case case_worker_help_names_variable \
|
||||
"worker: -h documents XCE_CONTROLLER_PEERS, the opt-out and that sudo drops it (1.5, 1.7)"
|
||||
|
||||
# ── Task 3.3 (Req 1.1-1.5, 1.7): the harness (xce_test) takes its `masters`
|
||||
# default from XCE_CONTROLLER_PEERS; an explicit `set masters` wins. Always
|
||||
# run with --norc so the developer's own rc file cannot change the result,
|
||||
# with the script fed on stdin. A bare `set` prints every setting with no
|
||||
# connection attempt. The connecting command (`client`) is only ever given an
|
||||
# INVALID masters value: enter_ctx() rejects it before any connection, so no
|
||||
# case talks to a controller.
|
||||
|
||||
# run_harness <dir> <script-text> <env-args...>
|
||||
# Write <script-text> to <dir>/script and run `xce_test --norc` on it.
|
||||
run_harness() {
|
||||
local dir="$1" script="$2"; shift 2
|
||||
printf '%s' "$script" >"$dir/script"
|
||||
RUN_STDIN="$dir/script" run_to_completion "$dir" 10 "$@" "$HARNESS_BIN" --norc
|
||||
}
|
||||
|
||||
HARNESS_INVALID_RE="enter_ctx: invalid 'masters' setting"
|
||||
|
||||
case_harness_env_default() {
|
||||
local d; d="$(new_scratch harness-env-default)"
|
||||
run_harness "$d" $'set\n' "XCE_CONTROLLER_PEERS=$ENV3"
|
||||
assert_rc 0 || return 1
|
||||
assert_grep "$d/stdout" "^masters +:<not set> default: $ENV3\$" "stdout" || return 1
|
||||
}
|
||||
add_case case_harness_env_default \
|
||||
"harness: bare set shows XCE_CONTROLLER_PEERS as the masters default (1.2)"
|
||||
|
||||
case_harness_builtin_default() {
|
||||
local d; d="$(new_scratch harness-builtin-default)"
|
||||
run_harness "$d" $'set\n' -u XCE_CONTROLLER_PEERS
|
||||
assert_rc 0 || return 1
|
||||
assert_grep "$d/stdout" '^masters +:<not set> default: localhost:9990$' "stdout" || return 1
|
||||
|
||||
d="$(new_scratch harness-empty-default)"
|
||||
run_harness "$d" $'set\n' "XCE_CONTROLLER_PEERS="
|
||||
assert_rc 0 || return 1
|
||||
assert_grep "$d/stdout" '^masters +:<not set> default: localhost:9990$' "stdout (empty variable)" || return 1
|
||||
}
|
||||
add_case case_harness_builtin_default \
|
||||
"harness: unset or empty variable keeps the built-in masters default (1.3, 1.7)"
|
||||
|
||||
case_harness_explicit_wins() {
|
||||
local d; d="$(new_scratch harness-explicit-wins)"
|
||||
run_harness "$d" $'set masters x=localhost:7\nset\n' "XCE_CONTROLLER_PEERS=$ENV3"
|
||||
assert_rc 0 || return 1
|
||||
assert_grep "$d/stdout" "^masters +:x=localhost:7 default: $ENV3\$" "stdout" || return 1
|
||||
}
|
||||
add_case case_harness_explicit_wins \
|
||||
"harness: explicit set masters is the value shown over the env default (1.1)"
|
||||
|
||||
case_harness_invalid_source() {
|
||||
local d
|
||||
# (a) explicit invalid value, variable unset
|
||||
d="$(new_scratch harness-invalid-explicit)"
|
||||
run_harness "$d" $'set masters bad\nclient\n' -u XCE_CONTROLLER_PEERS
|
||||
assert_rc nonzero || return 1
|
||||
assert_grep "$d/stderr" "$HARNESS_INVALID_RE \`bad' \(explicit \`set masters'\)" "stderr (a: explicit)" || return 1
|
||||
|
||||
# (b) no set masters, invalid variable
|
||||
d="$(new_scratch harness-invalid-env)"
|
||||
run_harness "$d" $'client\n' "XCE_CONTROLLER_PEERS=bad"
|
||||
assert_rc nonzero || return 1
|
||||
assert_grep "$d/stderr" "$HARNESS_INVALID_RE \`bad' \(default from XCE_CONTROLLER_PEERS\)" "stderr (b: env)" || return 1
|
||||
|
||||
# (c) explicit invalid value with a valid variable set: explicit is blamed
|
||||
d="$(new_scratch harness-invalid-explicit-env)"
|
||||
run_harness "$d" $'set masters bad\nclient\n' "XCE_CONTROLLER_PEERS=$ENV3"
|
||||
assert_rc nonzero || return 1
|
||||
assert_grep "$d/stderr" "$HARNESS_INVALID_RE \`bad' \(explicit \`set masters'\)" "stderr (c: explicit over env)" || return 1
|
||||
assert_no_grep "$d/stderr" 'XCE_CONTROLLER_PEERS' "stderr (c: explicit over env)" || return 1
|
||||
}
|
||||
add_case case_harness_invalid_source \
|
||||
"harness: invalid masters message names explicit set masters or XCE_CONTROLLER_PEERS (1.1, 1.4)"
|
||||
|
||||
case_harness_help_names_variable() {
|
||||
local d; d="$(new_scratch harness-help)"
|
||||
run_harness "$d" $'help set\n' -u XCE_CONTROLLER_PEERS
|
||||
assert_rc 0 || return 1
|
||||
tr '\n' ' ' <"$d/stdout" | tr -s ' ' >"$d/help.txt"
|
||||
assert_grep "$d/help.txt" 'XCE_CONTROLLER_PEERS' "help set output" || return 1
|
||||
assert_grep "$d/help.txt" 'unset or empty' "help set output" || return 1
|
||||
assert_grep "$d/help.txt" 'localhost:9990' "help set output" || return 1
|
||||
}
|
||||
add_case case_harness_help_names_variable \
|
||||
"harness: help set documents XCE_CONTROLLER_PEERS and the opt-out (1.5, 1.7)"
|
||||
|
||||
|
||||
# ════════════════════════════════════════════════════════════════════════════
|
||||
# main
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue