-
Notifications
You must be signed in to change notification settings - Fork 31
Resolves #97: Include in tests into the context window when generating #119
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
base: main
Are you sure you want to change the base?
Conversation
Bump version
|
close #97 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces automatic unit test file detection and inclusion during code generation to help generate code that passes existing unit tests. The feature is enabled by default and can be disabled using the new --exclude-tests flag.
Key Changes:
- Adds
--exclude-testsCLI flag to disable the auto-include unit test feature - Implements automatic test file detection logic that scans for test files in the project's test directory
- Creates companion
ut_<basename>.promptfiles that include test file references and instructions to generate code passing those tests
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| pdd/code_generator_main.py | Implements core test file detection, prompt augmentation, and companion file creation logic |
| pdd/cli.py | Adds the --exclude-tests flag to the CLI interface |
| README.md | Documents the new --exclude-tests flag in the global options section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| if _pdd_unit_include_line and _pdd_unit_include_line not in prompt_content: | ||
| prompt_content = prompt_content + _pdd_unit_include_line | ||
| #prompt_content = prompt_content + _pdd_unit_include_line |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented-out duplicate code. The active line 396 already performs this operation.
| #prompt_content = prompt_content + _pdd_unit_include_line |
| ) | ||
| # Append include directive if we created one earlier | ||
| if '_pdd_unit_include_line' in locals(): | ||
| #ut_prompt_text = ut_prompt_text + _pdd_unit_include_line |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented-out code. Line 450 provides the correct implementation that prepends the include line instead.
| #ut_prompt_text = ut_prompt_text + _pdd_unit_include_line |
| ##Uncomment below | ||
| #ut_prompt_path = pathlib.Path(prompt_file).with_name(f"{pathlib.Path(prompt_file).stem}_ut.prompt") | ||
| #ut_prompt_path = pathlib.Path(prompt_file).with_name(f"{pathlib.Path(prompt_file).stem}_ut.prompt") |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented-out code and the '##Uncomment below' comment. Line 457 provides the final implementation using the correct 'ut_' prefix pattern.
| ##Uncomment below | |
| #ut_prompt_path = pathlib.Path(prompt_file).with_name(f"{pathlib.Path(prompt_file).stem}_ut.prompt") | |
| #ut_prompt_path = pathlib.Path(prompt_file).with_name(f"{pathlib.Path(prompt_file).stem}_ut.prompt") |
| ) | ||
| prompt_content = input_strings["prompt_file"] | ||
|
|
||
|
|
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra blank lines. One blank line is sufficient for code separation.
| "exclude_tests", | ||
| is_flag=True, | ||
| default=False, | ||
| help="Exclude test scenarios from code coverage generation. (WIP)", |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help text is misleading. Based on the implementation and PR description, this flag excludes test files from being auto-included during code generation, not from 'code coverage generation'. Consider: 'Disable automatic inclusion of unit test files during code generation.'
| help="Exclude test scenarios from code coverage generation. (WIP)", | |
| help="Disable automatic inclusion of unit test files during code generation.", |
| - `--local`: Run commands locally instead of in the cloud. | ||
| - `--context CONTEXT_NAME`: Override automatic context detection and use the specified context from `.pddrc`. | ||
| - `--list-contexts`: List all available contexts defined in `.pddrc` and exit. | ||
| - `--exclude-tests`: Exclude test scenarios from code coverage generation. (WIP) |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation description doesn't match the actual feature. This flag disables automatic inclusion of unit test files during code generation, not code coverage generation. Update to match the actual functionality.
| - `--exclude-tests`: Exclude test scenarios from code coverage generation. (WIP) | |
| - `--exclude-tests`: Disable automatic inclusion of unit test files during code generation. (WIP) |
| # Only create companion UT prompt and test files when tests are not | ||
| # excluded via the --exclude-tests flag. When excluded, we will use the | ||
| # original prompt file as authored by the user. | ||
| if not exclude_tests_flag: |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This creates a deeply nested block (280+ lines inside a conditional). The entire unit test handling logic (lines 246-526) should be extracted into a separate function to improve readability and maintainability.
target 11/5 |
Feat: auto detect and include unit test files during pdd generate
This pull request introduces a new feature to pdd generate, which auto detects and includes unit test files to for code generation. This helps generate code that passes unit tests without the user manually having to include the test files.
Changes Implemented
New --exclude-tests Flag:
A --exclude-tests flag has been added to the pdd generate command in pdd/cli.py.
When this flag is used, the auto-include unit test feature is disabled.
Integrated Repository Logic in pdd/code_generate_main.py:
The core logic is now consolidated within code_generate_main.py:
How to Test
Navigate to any Git repository within your project with unit tests.
Run the command:
pdd generateObserve the output:
The tool will first scan for unit test files and update .prompt file to include the unit test file and add prompt instructions to generate code that passes these tests. The updated .prompt file is saved as "ut_<original_filename>.prompt"
To disable the feature:
pdd --exclude-tests generateThe method now does not auto include test files during generation and runs as usuall