Skip to content

Add failing tests for #493: update --output subdirectory crash#496

Draft
Serhan-Asad wants to merge 2 commits intopromptdriven:mainfrom
Serhan-Asad:fix/issue-493
Draft

Add failing tests for #493: update --output subdirectory crash#496
Serhan-Asad wants to merge 2 commits intopromptdriven:mainfrom
Serhan-Asad:fix/issue-493

Conversation

@Serhan-Asad
Copy link
Contributor

Summary

Adds failing tests that detect the bug reported in #493.

Test Files

  • Unit test: tests/test_update_main.py
  • E2E test: tests/test_e2e_issue_493_update_output_subdir.py

What This PR Contains

  • Failing unit test that reproduces the reported NameError
  • Failing E2E test that verifies the bug at integration level
  • Tests are verified to fail on current code and will pass once the bug is fixed

Root Cause

context_config is only defined in the else branch (line 75 of update_main.py) but used unconditionally at line 91 when the code file is in a subdirectory. Fix: initialize context_config = {} before the if/else block.

Next Steps

  1. Implement the fix (add context_config = {} before the if/else block)
  2. Verify the unit test passes
  3. Verify the E2E test passes
  4. Run full test suite
  5. Mark PR as ready for review

Fixes #493


Generated by PDD agentic bug workflow

…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>
@Serhan-Asad Serhan-Asad marked this pull request as ready for review February 12, 2026 14:42
@gltanaka gltanaka requested a review from Copilot February 13, 2026 02:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 --output and with root/subdirectory code paths.
  • Add an E2E regression test exercising update_main() with --output + subdirectory code file.
  • Initialize context_config = {} before branching on output_dir to avoid UnboundLocalError.

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.

Comment on lines +17 to +18
import os
import pytest
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
import os
import pytest

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,84 @@
"""
E2E Test for Issue #493: pdd update --output crashes with NameError when
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +14
When --output IS provided and the code file is in a subdirectory (rel_dir != "."),
this causes an UnboundLocalError.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +720 to +724
"""
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.
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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”).

Copilot uses AI. Check for mistakes.
Comment on lines +749 to +750
assert os.path.exists(prompt_path)
assert str(output_dir) in prompt_path
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
@Serhan-Asad Serhan-Asad marked this pull request as draft February 13, 2026 02:58
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 update --output crashes with NameError when code file is in subdirectory

1 participant