-
Notifications
You must be signed in to change notification settings - Fork 48
Add failing tests for #493: update --output subdirectory crash #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Serhan-Asad
wants to merge
3
commits into
promptdriven:main
Choose a base branch
from
Serhan-Asad:fix/issue-493
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """ | ||
| E2E Test for Issue #493: pdd update --output crashes with NameError when | ||
| code file is in a subdirectory. | ||
|
|
||
| This test exercises the full update_main() → resolve_prompt_code_pair() path | ||
| that a user triggers via `pdd update <code_file> --output <path>`. It mocks | ||
| only the LLM call (update_prompt) and agent availability at the system boundary, | ||
| but exercises all real path resolution logic including .pddrc context detection, | ||
| git repo discovery, and subdirectory structure preservation. | ||
|
|
||
| Bug: resolve_prompt_code_pair() defines context_config only in the else branch | ||
| (when --output is NOT provided) but references it unconditionally when computing | ||
| code_root. When --output IS provided and the code file is in a subdirectory | ||
| (rel_dir != "."), this causes an UnboundLocalError. | ||
| """ | ||
|
|
||
| import git | ||
| import click | ||
| from pathlib import Path | ||
| from unittest.mock import patch | ||
|
|
||
| from pdd.update_main import update_main | ||
|
|
||
|
|
||
| def test_e2e_update_output_flag_with_subdirectory_code_file(tmp_path, monkeypatch): | ||
| """ | ||
| E2E regression test: `pdd update backend/src/module.py --output /tmp/output/` | ||
| should NOT crash with NameError when the code file is in a subdirectory. | ||
|
|
||
| Exercises: update_main → resolve_prompt_code_pair → path resolution with --output. | ||
| Mocks: LLM call (update_prompt), agent availability (get_available_agents). | ||
| """ | ||
| # Setup: realistic repo structure matching the issue reproduction | ||
| repo_path = tmp_path / "pdd-test" | ||
| repo_path.mkdir() | ||
| sub_dir = repo_path / "backend" / "src" | ||
| sub_dir.mkdir(parents=True) | ||
| code_file = sub_dir / "module.py" | ||
| code_file.write_text("def hello(): return 'world'") | ||
|
|
||
| output_dir = tmp_path / "output" | ||
| output_dir.mkdir() | ||
|
|
||
| # Initialize git repo (required for repo root detection) | ||
| repo = git.Repo.init(repo_path) | ||
| repo.index.add([str(code_file)]) | ||
| repo.index.commit("init") | ||
|
|
||
| monkeypatch.chdir(repo_path) | ||
|
|
||
| # Build a real Click context like the CLI would | ||
| ctx = click.Context(click.Command("update")) | ||
| ctx.obj = { | ||
| "strength": 0.5, | ||
| "temperature": 0.0, | ||
| "verbose": False, | ||
| "quiet": True, | ||
| } | ||
|
|
||
| with patch("pdd.update_main.update_prompt") as mock_up, \ | ||
| patch("pdd.update_main.get_available_agents", return_value=[]), \ | ||
| patch("pdd.update_main.get_language", return_value="python"): | ||
|
|
||
| mock_up.return_value = ("generated prompt content", 0.01, "mock-model") | ||
|
|
||
| # Act: This is what `pdd update backend/src/module.py --output /tmp/output/` does | ||
| result = update_main( | ||
| ctx=ctx, | ||
| input_prompt_file=None, | ||
| modified_code_file=str(code_file), | ||
| input_code_file=None, | ||
| output=str(output_dir), | ||
| use_git=False, | ||
| ) | ||
|
|
||
| # Assert: should succeed, not crash with NameError | ||
| assert result is not None, "update_main returned None, indicating a crash or error" | ||
| assert result[0] == "generated prompt content" | ||
|
|
||
| # The prompt file should exist somewhere under the output directory | ||
| prompt_files = list(output_dir.rglob("*_python.prompt")) | ||
| assert len(prompt_files) >= 1, f"No prompt file created in {output_dir}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.