Stop a trailing comment in an allow file killing every run

cfg_read_allowlist() ended on `[[ -n "$line" ]] && CFG_allow+=(...)`, so a file whose
last line is a comment or blank returned 1 from the loop. load_config() calls it twice
in a non-final position, so under `set -e` every run died with exit 1 and no output at
all -- --dry-run and --print-policy included, with nothing to explain it.

Reading a file now always succeeds. An allowlist with nothing in it stays
validate_opts()'s call to refuse, with the message that says why.

LLM-Generated: true
This commit is contained in:
2026-10-30 22:50:04 -04:00
parent 9347bca78f
commit 8b70967907
2 changed files with 29 additions and 0 deletions
+22
View File
@@ -76,3 +76,25 @@ echo 'bogus_key = 1' >> "$CFG/config"
sb --print-policy --net none
assert_contains "unknown key: bogus_key" "unknown key warns"
assert_rc 0 "unknown key is not fatal"
t_name "an allow file may end on a comment or a blank line"
# Regression: cfg_read_allowlist() ended on its `[[ -n "$line" ]]`, so a file whose last
# line yields no target returned 1. load_config() calls it in a non-final position, so under
# `set -e` every run died with exit 1 and *zero* bytes of output -- --dry-run and
# --print-policy included. The test above ends its file on "host # trailing comment", which
# yields a target and so never exercised this.
for last in '# a trailing comment' '' ' '; do
printf '# user-wide allowlist\napi.openai.com\n%s\n' "$last" > "$CFG/allow"
printf 'pypi.org\n%s\n' "$last" > "$REPO/.ai-sandbox/allow"
sb --print-policy --net allow
assert_rc 0 "user allow file ending on [$last] is not fatal"
assert_contains "api.openai.com" "user target survives a file ending on [$last]"
assert_contains "pypi.org" "repo target survives a file ending on [$last]"
done
# The fix must not trade one silence for another: with no target anywhere, the run still
# refuses, and says why.
printf '# nothing but a header here\n' > "$CFG/allow"
printf '# nothing but a header here\n' > "$REPO/.ai-sandbox/allow"
sb_timeout 20 --print-policy --net allow
assert_rc 1 "a header-only allow file still refuses to start"
assert_contains "no egress allowlist configured" "and refuses out loud"