Skip to content

Commit 9cd7188

Browse files
committed
fix(review): reject near-miss cycle markers instead of ignoring them
1 parent 55ba278 commit 9cd7188

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎scripts/render-prompt.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ BEGIN { depth = 0; keep = 1; err = "" }
6363
next
6464
}
6565
66+
# Anything that mentions a cycle marker but did not match the two strict forms above is
67+
# malformed, not prose. This must be an error rather than a passthrough: an unrecognised
68+
# marker keeps its whole block, so a stray indent, a trailing space, or CRLF line endings
69+
# would silently restore the full nit-bearing prompt at late cycles -- the exact regression
70+
# this script exists to prevent, arriving with a zero exit status and no warning.
71+
/<!--[[:space:]]*\/?[[:space:]]*cycle/ {
72+
err = "malformed cycle marker at line " NR ": " $0
73+
exit 2
74+
}
75+
6676
{ if (!depth || keep) print }
6777
6878
END {

‎tests/render-prompt-test.sh‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,40 @@ for bad in '<!-- cycle>=2 -->\nx\n<!-- cycle>=3 -->\ny\n<!-- /cycle -->' \
108108
fi
109109
done
110110

111+
# A marker that is ALMOST right is the dangerous case, not an obviously broken one. An
112+
# unrecognised marker keeps its whole block and exits 0, so before this was an error a stray
113+
# indent or CRLF silently shipped the full nit-bearing prompt at cycle 6 -- indistinguishable
114+
# from the behaviour this script exists to remove. Each of these must exit non-zero.
115+
#
116+
# near_miss <description> <printf format producing the file>
117+
near_miss() {
118+
local desc=$1 body=$2 out
119+
# The assignment lives in the `if` condition on purpose: under `set -e` a bare
120+
# `out=$(failing command)` aborts this script instead of running the assertion.
121+
if out=$(printf '%b' "$body" | bash "$RENDER" 1 2>&1); then
122+
fail "silently ignored a near-miss marker ($desc); its block would leak at every cycle"
123+
elif printf '%s' "$out" | grep -q 'malformed cycle marker'; then
124+
pass "rejects near-miss marker: $desc"
125+
else
126+
fail "rejected $desc but without a malformed-marker message"
127+
fi
128+
}
129+
near_miss "CRLF line endings" 'keep\r\n<!-- cycle>=3 -->\r\nLATE\r\n<!-- /cycle -->\r\n'
130+
near_miss "trailing space on marker" 'keep\n<!-- cycle>=3 --> \nLATE\n<!-- /cycle -->\n'
131+
near_miss "indented marker" 'keep\n <!-- cycle>=3 -->\nLATE\n <!-- /cycle -->\n'
132+
near_miss "indented closing marker" 'keep\n<!-- cycle>=3 -->\nLATE\n <!-- /cycle -->\n'
133+
near_miss "missing space in marker" 'keep\n<!--cycle>=3-->\nLATE\n<!-- /cycle -->\n'
134+
near_miss "unknown operator" 'keep\n<!-- cycle!=3 -->\nLATE\n<!-- /cycle -->\n'
135+
near_miss "non-numeric bound" 'keep\n<!-- cycle>=x -->\nLATE\n<!-- /cycle -->\n'
136+
137+
# The real prompt must contain only strict markers, or CI is asserting against a file that
138+
# silently stopped being gated.
139+
if bash "$RENDER" 1 < "$PROMPT" >/dev/null 2>&1; then
140+
pass "the shipped prompt has no malformed markers"
141+
else
142+
fail "the shipped prompt contains a malformed marker"
143+
fi
144+
111145
echo "-- shipped prompt, cycle 1 (full review) --"
112146
has 1 "### Documentation" "the Documentation criterion"
113147
has 1 "### Code Quality" "the Code Quality criterion"

0 commit comments

Comments
 (0)