Skip to content

Add failing tests for #774: detect_structural_test_patterns previous_content API#775

Draft
prompt-driven-github[bot] wants to merge 1 commit intomainfrom
fix/issue-774
Draft

Add failing tests for #774: detect_structural_test_patterns previous_content API#775
prompt-driven-github[bot] wants to merge 1 commit intomainfrom
fix/issue-774

Conversation

@prompt-driven-github
Copy link
Copy Markdown
Contributor

Summary

Adds 8 failing tests that detect the bug reported in #774.

Test Files

  • Unit test: tests/test_structural_test_guard.py

What This PR Contains

Failing unit tests that reproduce the reported bug. Tests are verified to fail on current code and will pass once the bug is fixed.

Tests 1–7 call detect_structural_test_patterns(path, previous_content=...) directly → fail with TypeError because the previous_content parameter doesn't exist yet (current param is start_line).

Test 8 mocks the orchestrator through step 9 and verifies the caller passes previous_content=<str> not start_line=<int> → fails because the caller currently passes {'start_line': 3}.

Root Cause

pdd/agentic_bug_orchestrator.py:980 — the clamp:

effective_start = 1 if start_line > len(lines) else start_line

fires when start_line = N+1 (the normal "nothing appended" case, since callers pass len(splitlines()) + 1). Because N+1 > N is always True, it clamps effective_start = 1 and rescans the entire file — flagging pre-existing structural test patterns as violations and triggering destructive retries.

File-on-disk scanning with line-count offsets cannot distinguish "nothing new" from "file truncated."

Fix Location

  • pdd/agentic_bug_orchestrator.py:931 — replace start_line: Optional[int] with previous_content: Optional[str], remove clamp at line 980, add _compute_changed_lines helper using difflib.SequenceMatcher
  • pdd/agentic_bug_orchestrator.py:1528 — rename pre_step9_line_counts: Dict[str, int] to pre_step9_content: Dict[str, str]
  • pdd/agentic_bug_orchestrator.py:1537 — snapshot full read_text() instead of len(splitlines())
  • pdd/agentic_bug_orchestrator.py:1868-1871 — pass previous_content=pre_step9_content.get(...) to callers

Next Steps

  1. Implement the fix at the identified locations above
  2. Verify all 8 new unit tests pass
  3. Run full test suite to check for regressions
  4. Mark PR as ready for review

Fixes #774


Generated by PDD agentic bug workflow

…vious_content API

Add 8 failing tests to tests/test_structural_test_guard.py that verify the
fix for the off-by-one bug in detect_structural_test_patterns(). Tests cover:

- Off-by-one regression: unchanged file with previous_content returns []
- Appended violations: only newly appended patterns are flagged
- Pre-existing violations: patterns in snapshot are not reported
- Truncation safety: rewritten-shorter file scanned correctly
- Cross-boundary variable tracking: var defined in snapshot, used in new lines
- New file: previous_content=None scans everything
- Multiple pattern types: various structural test patterns detected
- Caller API: orchestrator passes previous_content= not start_line=

Tests fail with TypeError on current code (start_line param, not previous_content).
Fix: replace start_line with previous_content + difflib.SequenceMatcher in
pdd/agentic_bug_orchestrator.py:931 and update callers.

Fixes #774

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: structural test validator should scan generated output, not file on disk

1 participant