Skip to content

test: add loop helper parsing tests#26

Merged
AlexanderGardiner merged 1 commit intoCodelab-Davis:mainfrom
brianescutia:brian/test-loop-helpers
Apr 21, 2026
Merged

test: add loop helper parsing tests#26
AlexanderGardiner merged 1 commit intoCodelab-Davis:mainfrom
brianescutia:brian/test-loop-helpers

Conversation

@brianescutia
Copy link
Copy Markdown
Contributor

@brianescutia brianescutia commented Apr 21, 2026

Pull Request

Summary

Adds deterministic unit tests for the helper parsing behavior in src/anchor/loop.py. This PR covers _extract_gap() and _strip_marker() with focused offline tests so regressions in loop protocol parsing are easier to catch and debug.

Linked context

Closes #13

PR Size

  • Small (< 100 LOC delta)
  • Medium (100-499 LOC delta)
  • Large (500-999 LOC delta)
  • XL (1000+ LOC delta — must have been pre-discussed in an issue)

PR Type

  • Bug fix
  • New feature
  • Prompt change (prompt label required; eval results required below)
  • Test
  • Docs
  • Refactor / chore

Context / Motivation

These helpers are small, but they are responsible for parsing GAP: / CONTEXT: content emitted by the loop protocol and for stripping terminal markers from returned text. Adding focused tests helps catch regressions without expanding into full Anchor.run() integration coverage.

Changes

Added tests/unit/test_loop_helpers.py with deterministic unit tests for _extract_gap() and _strip_marker(), covering standard parsing, missing markers, whitespace handling, and terminal marker stripping behavior.

How to test

  1. uv run pytest -m "not eval" tests/unit/test_loop_helpers.py -v
  2. uv run pytest -m "not eval"
  3. uv run pre-commit run --all-files

Checklist

  • I ran the relevant local checks.
  • I updated documentation or confirmed no docs changes were needed.
  • I linked related issues or pull requests and confirmed this is not duplicate work.
  • This change stays within the stated scope of the PR.

Notes for reviewers

This PR stays intentionally narrow and only adds helper-level unit tests. No production code or protocol behavior was changed.

Summary by CodeRabbit

Release Notes

  • Tests
    • Expanded test coverage for internal helper methods to enhance code reliability and maintainability.

@github-actions github-actions bot added the area: tests Automated tests and test infrastructure. label Apr 21, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 21, 2026

📝 Walkthrough

Walkthrough

A new test module tests/unit/test_loop_helpers.py has been added with unit tests for two internal helper methods from the Loop class: _extract_gap and _strip_marker. The tests validate parsing behavior for GAP/CONTEXT extraction and terminal marker stripping across various input scenarios.

Changes

Cohort / File(s) Summary
Loop Helper Tests
tests/unit/test_loop_helpers.py
Added comprehensive unit tests for _extract_gap() covering standard inputs, missing markers, and whitespace edge cases; added tests for _strip_marker() validating removal of trailing markers while preserving non-terminal content.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

area: tests

Suggested reviewers

  • AlexanderGardiner

Poem

🐰 A rabbit hops through test files so neat,
_extract_gap and _strip_marker, what a treat!
Nine times three—one hundred and nine lines,
Robust parsing helpers, marking all the signs.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'test: add loop helper parsing tests' accurately summarizes the main change—adding unit tests for loop helper parsing functions.
Linked Issues check ✅ Passed The PR fully implements all coding objectives from issue #13: tests for _extract_gap() covering standard inputs, missing markers, and whitespace handling; tests for _strip_marker() covering trailing marker removal and edge cases.
Out of Scope Changes check ✅ Passed All changes are in-scope test additions; no out-of-scope modifications to production code, protocol format, or integration tests are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/unit/test_loop_helpers.py (1)

20-109: Optional: use pytest.mark.parametrize to reduce repetition.

This test module is already solid; parametrizing similar cases would make future additions easier to maintain.

♻️ Example refactor pattern
+@pytest.mark.unit
+@pytest.mark.parametrize(
+    ("content", "expected_gap", "expected_context"),
+    [
+        ("GAP: what is X?\nCONTEXT: figuring out X\nREMEMBER", "what is X?", "figuring out X"),
+        ("CONTEXT: still working through it\nREMEMBER", "", "still working through it"),
+        ("GAP: what is Y?\nREMEMBER", "what is Y?", ""),
+        ("Some unrelated reasoning text.\nNo markers here.\nDONE", "", ""),
+        ("\n   GAP:   what is Z?   \n\n   CONTEXT:\treasoning about Z\t\n\nREMEMBER\n", "what is Z?", "reasoning about Z"),
+    ],
+)
+def test_extract_gap_cases(loop: Loop, content: str, expected_gap: str, expected_context: str) -> None:
+    gap, context = loop._extract_gap(content)
+    assert gap == expected_gap
+    assert context == expected_context
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_loop_helpers.py` around lines 20 - 109, Several tests in the
test_extract_gap_* and test_strip_marker_* groups repeat the same structure;
refactor them to parametrize inputs and expected outputs using
pytest.mark.parametrize to reduce duplication. Replace the multiple
test_extract_gap_* functions with a single parametrized test that calls
loop._extract_gap(content) for tuples of (content, expected_gap,
expected_context) and similarly replace the strip_marker tests with a single
parametrized test that calls loop._strip_marker(content, "DONE") for tuples of
(content, expected_result), keeping unique edge-case names as ids; ensure you
reference the existing helper methods _extract_gap and _strip_marker and
preserve all current cases and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/unit/test_loop_helpers.py`:
- Around line 20-109: Several tests in the test_extract_gap_* and
test_strip_marker_* groups repeat the same structure; refactor them to
parametrize inputs and expected outputs using pytest.mark.parametrize to reduce
duplication. Replace the multiple test_extract_gap_* functions with a single
parametrized test that calls loop._extract_gap(content) for tuples of (content,
expected_gap, expected_context) and similarly replace the strip_marker tests
with a single parametrized test that calls loop._strip_marker(content, "DONE")
for tuples of (content, expected_result), keeping unique edge-case names as ids;
ensure you reference the existing helper methods _extract_gap and _strip_marker
and preserve all current cases and assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a1274e2f-0b6c-4607-b2b9-efd11e7b573f

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5011a and ba1b5dd.

📒 Files selected for processing (1)
  • tests/unit/test_loop_helpers.py

Copy link
Copy Markdown
Collaborator

@AlexanderGardiner AlexanderGardiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'll go ahead and merge.

@AlexanderGardiner AlexanderGardiner merged commit 3a28eab into Codelab-Davis:main Apr 21, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Automated tests and test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[task] Add loop helper parsing tests

2 participants