@@ -100,6 +100,81 @@ else
100100 fail " S5: empty output -> expected rc 1, got $rc "
101101fi
102102
103+ # ---------------------------------------------------------------------------
104+ # R-2b: agent_auth_failed (the dev-review.sh execute/verify auth gate, distinct
105+ # from lib's validate_agent_artifact). Regression for the false positive where a
106+ # large working log echoes auth strings (plan text, or the auth-detection source
107+ # itself) and trips a naive substring scan. Extract the real functions from the
108+ # runner via sed (dev-review.sh has no main guard, so it is not safe to source
109+ # whole — same discipline as tests/revise-loop-simulation.sh).
110+ # ---------------------------------------------------------------------------
111+ AUTH_FN_SRC=" $TEST_DIR /agent_auth_failed.sh"
112+ sed -n ' /^agent_cli_name() {/,/^}$/p' " $REPO_ROOT /dev-review/codex/dev-review.sh" > " $AUTH_FN_SRC "
113+ sed -n ' /^agent_auth_failed() {/,/^}$/p' " $REPO_ROOT /dev-review/codex/dev-review.sh" >> " $AUTH_FN_SRC "
114+ # shellcheck disable=SC1090
115+ source " $AUTH_FN_SRC "
116+
117+ if ! declare -F agent_auth_failed > /dev/null; then
118+ TOTAL=$(( TOTAL + 1 ))
119+ fail " R-2b: agent_auth_failed not sourced — cannot test"
120+ else
121+ # Scenario 5a: empty output + auth banner in stderr -> detected (rc 0).
122+ TOTAL=$(( TOTAL + 1 ))
123+ out=" $TEST_DIR /s5a-out.md" ; err=" $TEST_DIR /s5a-err.log"
124+ : > " $out " ; printf ' Not logged in. Please run /login\n' > " $err "
125+ rc=0; agent_auth_failed codex " $out " " $err " > /dev/null 2>&1 || rc=$?
126+ if [[ " $rc " -eq 0 ]]; then
127+ pass " S5a: agent_auth_failed: empty output + stderr banner -> detected"
128+ else
129+ fail " S5a: expected detection (rc 0), got $rc "
130+ fi
131+
132+ # Scenario 5b: short auth banner in the OUTPUT -> detected (rc 0).
133+ TOTAL=$(( TOTAL + 1 ))
134+ out=" $TEST_DIR /s5b-out.md" ; err=" $TEST_DIR /s5b-err.log"
135+ printf ' Failed to authenticate. Please run `claude login`.\n' > " $out " ; : > " $err "
136+ rc=0; agent_auth_failed claude " $out " " $err " > /dev/null 2>&1 || rc=$?
137+ if [[ " $rc " -eq 0 ]]; then
138+ pass " S5b: agent_auth_failed: short banner in output -> detected"
139+ else
140+ fail " S5b: expected detection (rc 0), got $rc "
141+ fi
142+
143+ # Scenario 5c (REGRESSION): substantial output + a huge stderr working log that
144+ # echoes auth strings deep inside (plan text / the auth-detection source) ->
145+ # NOT an auth failure (rc 1). This is the codex-build self-build false positive.
146+ TOTAL=$(( TOTAL + 1 ))
147+ out=" $TEST_DIR /s5c-out.md" ; err=" $TEST_DIR /s5c-err.log"
148+ {
149+ printf ' Implemented the feature as planned. Files changed and tests pass.\n'
150+ for i in $( seq 1 80) ; do printf ' word%d ' " $i " ; done ; printf ' \n'
151+ } > " $out "
152+ {
153+ for i in $( seq 1 3000) ; do printf ' log line %d: working...\n' " $i " ; done
154+ printf ' 66: - If the output contains `Not logged in` (or `/login`): degrade\n'
155+ printf " 576: grep -qiE 'Not logged in|Please run /login|Unauthorized' file\n"
156+ for i in $( seq 1 3000) ; do printf ' log line %d: more work...\n' " $i " ; done
157+ } > " $err "
158+ rc=0; agent_auth_failed codex " $out " " $err " > /dev/null 2>&1 || rc=$?
159+ if [[ " $rc " -eq 1 ]]; then
160+ pass " S5c: agent_auth_failed: big working log echoing auth strings -> NOT flagged (regression)"
161+ else
162+ fail " S5c: expected no detection (rc 1), got $rc — false positive regressed"
163+ fi
164+
165+ # Scenario 5d: empty output + genuine stderr banner -> still detected (rc 0).
166+ # The regression guard must not mask a real failure whose only signal is stderr.
167+ TOTAL=$(( TOTAL + 1 ))
168+ out=" $TEST_DIR /s5d-out.md" ; err=" $TEST_DIR /s5d-err.log"
169+ : > " $out " ; printf ' authentication_error: OAuth token expired\n' > " $err "
170+ rc=0; agent_auth_failed codex " $out " " $err " > /dev/null 2>&1 || rc=$?
171+ if [[ " $rc " -eq 0 ]]; then
172+ pass " S5d: agent_auth_failed: empty output + genuine stderr banner -> detected"
173+ else
174+ fail " S5d: expected detection (rc 0), got $rc "
175+ fi
176+ fi
177+
103178# ---------------------------------------------------------------------------
104179# C-2/S-2: fill_template metacharacter pinning (false-positive verification)
105180# ---------------------------------------------------------------------------
0 commit comments