Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/ci/opencode_review_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ def _language(value: str) -> str:

def extract_model_prose(raw_output: str) -> str:
"""Return the human review body, stripping sentinel and control JSON."""
if "<!-- opencode-review-" not in raw_output:
# Neither SENTINEL_PREFIX nor CONTROL_START's shared literal prefix
# occurs anywhere, so the loop below is guaranteed to append every
# line unchanged -- skip the per-line prefix checks for the common
# case of a plain-prose response, without changing line-ending
# normalization behavior.
return "\n".join(raw_output.splitlines()).strip()

lines: list[str] = []
skipping_control = False
for line in raw_output.splitlines():
Expand Down
25 changes: 25 additions & 0 deletions tests/test_opencode_review_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,31 @@ def test_extract_model_prose_strips_sentinel_and_control() -> None:
assert "opencode-review-control-v1" not in prose


def test_extract_model_prose_fast_path_matches_slow_path_on_plain_text() -> None:
"""The no-marker fast path is byte-identical to the full line-scan result."""
raw = "line one\r\nline two\r\n\r\nline three\n"

fast_result = surfaces.extract_model_prose(raw)

lines: list[str] = []
skipping_control = False
for line in raw.splitlines():
stripped = line.strip()
if stripped.startswith(surfaces.SENTINEL_PREFIX):
continue
if stripped.startswith(surfaces.CONTROL_START):
skipping_control = True
continue
if skipping_control:
if stripped.endswith("-->"):
skipping_control = False
continue
lines.append(line)
slow_result = "\n".join(lines).strip()

assert fast_result == slow_result == "line one\nline two\n\nline three"


def test_format_request_changes_keeps_model_prose_and_strips_fake_anchor() -> None:
"""REQUEST_CHANGES keeps the model walkthrough and never cites workflow:1."""
body = surfaces.format_request_changes_review(
Expand Down
Loading