-
Notifications
You must be signed in to change notification settings - Fork 48
feat: Implement user story prompt validation [Fixes #346] #484
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |||||
| from .change import change as change_func | ||||||
| from .process_csv_change import process_csv_change | ||||||
| from .get_extension import get_extension | ||||||
| from .user_story_tests import run_user_story_tests, discover_prompt_files | ||||||
|
|
||||||
| # Set up logging | ||||||
| logger = logging.getLogger(__name__) | ||||||
|
|
@@ -487,7 +488,71 @@ def change_main( | |||||
| logger.error(msg, exc_info=True) | ||||||
| return msg, total_cost, model_name or "" | ||||||
|
|
||||||
| # --- 5. Final User Feedback --- | ||||||
| # --- 5. User Story Validation (Optional) --- | ||||||
| if (use_csv or success) and not ctx.obj.get("skip_user_stories", False): | ||||||
| prompts_dir = resolved_config.get("prompts_dir") or os.environ.get("PDD_PROMPTS_DIR") or "prompts" | ||||||
| stories_dir = os.environ.get("PDD_USER_STORIES_DIR") or "user_stories" | ||||||
| validation_prompt_files = None | ||||||
| validation_prompts_dir = Path(prompts_dir) | ||||||
| output_is_csv = False | ||||||
|
|
||||||
| if use_csv and output_path_obj: | ||||||
| output_is_csv = output_path_obj.suffix.lower() == ".csv" | ||||||
|
|
||||||
| if output_is_csv: | ||||||
| if not quiet: | ||||||
| rprint("[yellow]Skipping user story validation: output is CSV, no prompt files written.[/yellow]") | ||||||
| passed = True | ||||||
| story_cost = 0.0 | ||||||
| story_model = "" | ||||||
| else: | ||||||
| override_dir = None | ||||||
| if use_csv: | ||||||
| if "output_dir" in locals(): | ||||||
| override_dir = output_dir | ||||||
| elif output_path_obj: | ||||||
| if output_path_obj.is_dir() or (not output_path_obj.exists() and not output_path_obj.suffix): | ||||||
| override_dir = output_path_obj | ||||||
| else: | ||||||
| override_dir = output_path_obj.parent | ||||||
| else: | ||||||
| if output_path_obj: | ||||||
| override_dir = output_path_obj.parent | ||||||
|
|
||||||
| if override_dir: | ||||||
| override_prompts = discover_prompt_files(str(override_dir)) | ||||||
| base_prompts = discover_prompt_files(str(validation_prompts_dir)) | ||||||
| merged: List[Path] = [] | ||||||
| seen = set() | ||||||
| for pf in override_prompts + base_prompts: | ||||||
| key = pf.name.lower() | ||||||
| if key in seen: | ||||||
| continue | ||||||
| merged.append(pf) | ||||||
| seen.add(key) | ||||||
| validation_prompt_files = merged | ||||||
|
|
||||||
| passed, _, story_cost, story_model = run_user_story_tests( | ||||||
| prompts_dir=str(validation_prompts_dir) if validation_prompt_files is None else None, | ||||||
| prompt_files=validation_prompt_files, | ||||||
| stories_dir=stories_dir, | ||||||
| strength=strength, | ||||||
| temperature=temperature, | ||||||
| time=time_budget, | ||||||
| verbose=not quiet, | ||||||
|
||||||
| verbose=not quiet, | |
| verbose=ctx.obj.get("verbose", False), |
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.
De-duplicating by
pf.name.lower()can drop distinct prompt files that share the same basename in different subdirectories. That can cause user story validation to miss prompts (false passes) depending on repository layout. Use a uniqueness key based on full normalized path (e.g.,str(pf.resolve()).lower()) or avoid de-duplication entirely and letdetect_changesee all prompt files.