Skip to content

Conversation

@Serhan-Asad
Copy link

Problem

When running pdd update in regeneration mode, the subdirectory structure from the code file path was not being preserved in the prompts directory. The function was using os.path.basename() which stripped all directory information, causing prompts to be created in a flat structure.

Example of the bug:

  • Code file: pdd/commands/generate.py
  • Expected: prompts/commands/generate_python.prompt
  • Actual: prompts/generate_python.prompt

This caused:

  1. Loss of organizational structure in the prompts directory
  2. Potential naming collisions for files with the same name in different directories
  3. Inconsistency between code organization and prompt organization

Solution

Modified the resolve_prompt_code_pair() function in pdd/update_main.py by writing tests and using pdd fix --loop that:

  1. Calculate relative path from repository root - Uses os.path.relpath() to determine the subdirectory structure
  2. Strip package root prefix - Respects generate_output_path from .pddrc context configuration to avoid duplicating the package directory
  3. Preserve subdirectory structure - Maintains the directory hierarchy in the prompts directory

Example of the fix:

  • Code file: pdd/commands/generate.py
  • Context config: generate_output_path: "pdd"
  • Result: prompts/commands/generate_python.prompt

The fix correctly handles:

  • Files in nested subdirectories (e.g., pdd/commands/subdir/file.pyprompts/commands/subdir/file_python.prompt)
  • Context-specific code roots (strips the prefix defined by generate_output_path)
  • Files at the root level (no unnecessary nesting)

Testing

  • Added regression test: test_update_preserves_subdirectory_structure_issue_254
  • Fixed previously broken test: test_update_regeneration_mode_respects_pddrc_prompts_dir
  • Updated other affected tests to expect nested structure
  • All 9 tests in test_update_main.py passing ✅

Workflow

This fix was developed using PDD's own workflow:

  • Used pdd fix --loop to automatically fix the bug
  • Cost: $0.65 (Gemini 3 Pro)
  • Converged in 2 attempts

@gltanaka gltanaka requested a review from Copilot January 8, 2026 07:03
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

This PR fixes a bug where pdd update in regeneration mode did not preserve the subdirectory structure from code file paths when creating prompt files. The fix ensures that the directory hierarchy is maintained in the prompts directory by calculating relative paths and respecting the generate_output_path configuration.

Key Changes:

  • Modified resolve_prompt_code_pair() to preserve subdirectory structure using os.path.relpath()
  • Added logic to strip the package root prefix defined by generate_output_path from .pddrc context configuration
  • Added regression test test_update_preserves_subdirectory_structure_issue_254 and fixed existing tests to expect nested structure

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pdd/update_main.py Modified resolve_prompt_code_pair() to calculate relative paths from repository root and preserve subdirectory structure while respecting context-specific code roots
tests/test_update_main.py Added regression test for issue #254, updated existing tests to expect nested prompt structure, and fixed previously broken test with additional mocks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Assert: Prompt should be saved to prompts/backend/, not prompts/
expected_prompt_path = repo_path / "prompts" / "backend" / "some_module_python.prompt"
expected_prompt_path = repo_path / "prompts" / "backend" / "backend" / "some_module_python.prompt"
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The expected path contains 'backend' twice (prompts/backend/backend/), which appears incorrect. Based on the test setup where generate_output_path: 'backend' and the code file is at backend/some_module.py, the expected path should likely be prompts/backend/some_module_python.prompt (single 'backend'), not nested twice. This suggests the path stripping logic may not be working as intended for this test case.

Suggested change
expected_prompt_path = repo_path / "prompts" / "backend" / "backend" / "some_module_python.prompt"
expected_prompt_path = repo_path / "prompts" / "backend" / "some_module_python.prompt"

Copilot uses AI. Check for mistakes.
@gltanaka
Copy link
Contributor

gltanaka commented Jan 9, 2026

Can you address the copilot comments?

Did this pass all tests?

Copy link
Contributor

@gltanaka gltanaka left a comment

Choose a reason for hiding this comment

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

are any prompt changes needed or is this purely a bug?

@gltanaka
Copy link
Contributor

gltanaka commented Jan 9, 2026

what kind of test coverage is there?

@Serhan-Asad
Copy link
Author

Regression Test for Issue #254:

  • test_update_preserves_subdirectory_structure_issue_254 - validates that subdirectory structure is preserved when running pdd update

Related Tests:

  • test_update_regeneration_mode_respects_pddrc_prompts_dir - ensures context-specific prompts_dir from .pddrc is respected
  • test_update_main_regeneration_mode - validates regeneration mode workflow
  • test_update_main_repo_mode_orchestration - tests full repository mode
  • test_create_and_find_prompt_code_pairs - validates prompt/code pair resolution

All 9 tests in test_update_main.py pass. The fix has 65% code coverage of update_main.py (184 out of 285 lines covered).

Bug

  • This is purely a bug where pdd update was not taking into account the full subdirectory path

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.

2 participants