Skip to content

Commit 661a0b7

Browse files
committed
aver: regex-match effects opener under arbitrary whitespace (CR review)
The opener check used startswith("effects [", "effects["), which misses LLM output with non-canonical whitespace (multiple spaces, tab) between the keyword and the bracket — variants the Aver parser still accepts. Replace the prefix tuple with _AVER_EFFECTS_OPEN_RE = re.compile( r"^effects\\s*\\[") and cover the variants in TestStripModuleEffects.
1 parent b0545a7 commit 661a0b7

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

tests/test_runner.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,27 @@ def test_no_op_when_no_module_declaration(self):
947947
result = _strip_module_effects(code)
948948
assert result == code
949949

950+
def test_strips_arbitrary_whitespace_between_keyword_and_bracket(self):
951+
# LLM-formatted output may emit any whitespace between
952+
# `effects` and `[`; the strip must catch every variant the
953+
# Aver parser accepts, not just the canonical single space.
954+
for opener in ("effects[", "effects [", "effects [", "effects\t["):
955+
code = (
956+
"module M\n"
957+
' intent = "t"\n'
958+
f" {opener}Console.print]\n"
959+
"\n"
960+
"fn f() -> Unit\n"
961+
" ! [Console.print]\n"
962+
' Console.print("hi")\n'
963+
)
964+
result = _strip_module_effects(code)
965+
header_part = result.split("fn f")[0]
966+
assert "Console.print]" not in header_part, (
967+
f"failed to strip header with opener: {opener!r}"
968+
)
969+
assert "fn f" in result
970+
950971
def test_only_strips_inside_module_header(self):
951972
# An `effects [...]`-shaped line that appears below a
952973
# function body must not be removed; only the module-header

vera_bench/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ def _strip_aver_main(code: str) -> str:
566566
return "\n".join(result_lines)
567567

568568

569+
_AVER_EFFECTS_OPEN_RE = re.compile(r"^effects\s*\[")
570+
571+
569572
def _strip_module_effects(code: str) -> str:
570573
"""Remove the module header's `effects [...]` declaration if present.
571574
@@ -617,7 +620,7 @@ def _strip_module_effects(code: str) -> str:
617620
if (
618621
in_module_header
619622
and indent_len > 0
620-
and (stripped.startswith("effects [") or stripped.startswith("effects["))
623+
and _AVER_EFFECTS_OPEN_RE.match(stripped)
621624
):
622625
if stripped.endswith("]"):
623626
continue

0 commit comments

Comments
 (0)