Add failing tests for #493: update --output subdirectory crash#496
Add failing tests for #493: update --output subdirectory crash#496Serhan-Asad wants to merge 2 commits intopromptdriven:mainfrom
Conversation
…n#493) Unit test and E2E test that reproduce the NameError when using pdd update with --output flag on a code file in a subdirectory. context_config is only defined in the else branch but used unconditionally at line 91. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds regression coverage for issue #493 where pdd update --output crashes when the target code file lives in a subdirectory, and includes the minimal fix to prevent the context_config scoping error.
Changes:
- Add unit tests covering
resolve_prompt_code_pair()with/without--outputand with root/subdirectory code paths. - Add an E2E regression test exercising
update_main()with--output+ subdirectory code file. - Initialize
context_config = {}before branching onoutput_dirto avoidUnboundLocalError.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/test_update_main.py | Adds unit regression tests for resolve_prompt_code_pair() covering the reported crash scenario. |
| tests/test_e2e_issue_493_update_output_subdir.py | Adds an integration-level test to reproduce issue #493 via update_main() with --output. |
| pdd/update_main.py | Fixes scoping by initializing context_config before it’s used in subdirectory path logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import os | ||
| import pytest |
There was a problem hiding this comment.
os and pytest are imported but not used anywhere in this new test file. Please remove the unused imports to keep linting clean (and avoid failing CI if unused-import checks are enabled).
| import os | |
| import pytest |
| @@ -0,0 +1,84 @@ | |||
| """ | |||
| E2E Test for Issue #493: pdd update --output crashes with NameError when | |||
There was a problem hiding this comment.
The module docstring mixes NameError and UnboundLocalError. In Python, this specific case is UnboundLocalError (a subclass of NameError), but the wording should be consistent (prefer the precise exception name) to avoid confusion when someone is debugging failures.
| When --output IS provided and the code file is in a subdirectory (rel_dir != "."), | ||
| this causes an UnboundLocalError. |
There was a problem hiding this comment.
The module docstring mixes NameError and UnboundLocalError. In Python, this specific case is UnboundLocalError (a subclass of NameError), but the wording should be consistent (prefer the precise exception name) to avoid confusion when someone is debugging failures.
| """ | ||
| Regression test for GitHub issue #493. | ||
| resolve_prompt_code_pair() crashes with NameError when --output is provided | ||
| and the code file is in a subdirectory (rel_dir != "."), because context_config | ||
| is only defined in the else branch but used unconditionally at line 91. |
There was a problem hiding this comment.
This docstring is a bit too specific/brittle: (1) the exception is more precisely UnboundLocalError, and (2) referencing a hard-coded line number (“line 91”) will drift as the file changes. Consider describing the failure mode without line numbers (e.g., “used before assignment when output_dir is set”).
| assert os.path.exists(prompt_path) | ||
| assert str(output_dir) in prompt_path |
There was a problem hiding this comment.
The assertion str(output_dir) in prompt_path is a substring check and can be fragile across platforms/path normalization (e.g., case differences on Windows, differing separators). Prefer path-structure assertions using Path(prompt_path) (e.g., verify the prompt path is under output_dir via output_dir in Path(prompt_path).parents, or Path(prompt_path).resolve().is_relative_to(output_dir.resolve()) if available).
Summary
Adds failing tests that detect the bug reported in #493.
Test Files
tests/test_update_main.pytests/test_e2e_issue_493_update_output_subdir.pyWhat This PR Contains
Root Cause
context_configis only defined in theelsebranch (line 75 ofupdate_main.py) but used unconditionally at line 91 when the code file is in a subdirectory. Fix: initializecontext_config = {}before the if/else block.Next Steps
context_config = {}before the if/else block)Fixes #493
Generated by PDD agentic bug workflow