Skip to content

Comments

Add failing tests for issue #392: pdd change KeyError at Step 5#433

Closed
Serhan-Asad wants to merge 3 commits intopromptdriven:mainfrom
Serhan-Asad:fix/issue-392
Closed

Add failing tests for issue #392: pdd change KeyError at Step 5#433
Serhan-Asad wants to merge 3 commits intopromptdriven:mainfrom
Serhan-Asad:fix/issue-392

Conversation

@Serhan-Asad
Copy link
Collaborator

Summary

Adds failing E2E tests that detect the bug reported in #392 where pdd change fails at Step 5 with "Context missing key for step 5: 'url'".

Test Files

  • E2E test: tests/test_e2e_issue_392_change_keyerror.py

What This PR Contains

  • Failing E2E test that reproduces the reported bug
  • 5 comprehensive test cases:
    1. Step 5 execution with JSON in step outputs
    2. Complex nested JSON patterns
    3. Cached outputs with JSON content
    4. Escape function verification
    5. Regression test for normal operation
  • Tests verify that prompt_template.format(**context) doesn't raise KeyError when step outputs contain JSON with curly braces

Root Cause

Python's .format() method interprets curly braces in LLM step outputs (like JSON patterns {"url": ...}) as template placeholders. When step outputs from steps 1-4 contain JSON, these unescaped braces cause KeyError when the placeholder names don't exist in the context dictionary.

Bug Location: pdd/agentic_change_orchestrator.py:489-490 and pdd/agentic_change_orchestrator.py:675

Current Behavior: Step outputs are stored in context WITHOUT escaping curly braces.

Expected Behavior: Step outputs should be escaped using _escape_format_braces() (which already exists at pdd/agentic_change.py:19-24) before being added to the context dictionary.

Next Steps

  1. Implement the fix at lines 490 and 675 of pdd/agentic_change_orchestrator.py
  2. Apply _escape_format_braces() to step outputs before storing in context
  3. Verify the E2E tests pass
  4. Run full test suite to check for regressions
  5. Mark PR as ready for review

Fixes #392


Generated by PDD agentic bug workflow (Step 10)

… at Step 5)

This commit adds comprehensive E2E tests that reproduce the bug where
pdd change fails at Step 5 with "Context missing key for step 5: 'url'".

Root cause: Python's .format() method interprets curly braces in LLM
step outputs (like JSON patterns {"url": ...}) as template placeholders,
causing KeyError when those placeholder names don't exist in the context.

Test file: tests/test_e2e_issue_392_change_keyerror.py
Test cases: 5 tests covering JSON in outputs, nested JSON, cached outputs,
escape function verification, and regression testing.

Related to promptdriven#392

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The original tests from pdd bug did not properly detect the bug because they
mocked run_agentic_task, which is called AFTER the bug occurs.

Changes:
- Updated documentation to clarify the real bug: missing preprocess() call
- Added direct bug reproduction test that triggers KeyError
- Added test verifying the fix with preprocess() + double_curly_brackets
- Improved regression tests to compare with arch orchestrator pattern
- All 9 tests now pass and properly detect/verify the bug

The bug: agentic_change_orchestrator.py doesn't call preprocess() before
.format(), so templates with <include> tags referencing files with JSON
cause KeyError. Fix is to add preprocess() call like arch orchestrator does.
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.

pdd change fails at Step 5 with 'Context missing key for step 5: url'

1 participant