From a6019977127a72b2dabe9a832a8501a90e5f8915 Mon Sep 17 00:00:00 2001 From: Greg Tanaka Date: Mon, 30 Mar 2026 19:21:33 -0700 Subject: [PATCH] test: add regression tests for multi-context basename resolution Adds tests verifying _detect_modules_from_branch_diff preserves directory context for prompts in context-specific directories like prompts/frontend/ and prompts/backend/. Also covers extension prompts under extensions/github_pdd_app/prompts/. These basenames (e.g. "frontend/app/dashboard/page") must retain their directory prefix so pdd sync resolves the correct .pddrc context. Related: promptdriven/pdd_cloud#826 Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/test_agentic_sync.py | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_agentic_sync.py b/tests/test_agentic_sync.py index 3202024c1..9d6935d27 100644 --- a/tests/test_agentic_sync.py +++ b/tests/test_agentic_sync.py @@ -1040,6 +1040,55 @@ def test_handles_nested_prompt_paths(self): result = _detect_modules_from_branch_diff(Path("/fake/project")) assert result == ["commands/fix", "commands/sync"] + def test_preserves_context_prefix_for_multi_context_prompts(self): + """Prompts under context-specific dirs like prompts/frontend/ preserve the full path. + + When pdd_cloud has multiple contexts (frontend, backend, etc.), the diff + output contains paths like 'prompts/frontend/app/dashboard/page_TypescriptReact.prompt'. + The basename must include the context prefix ('frontend/app/dashboard/page') so that + pdd sync can resolve the correct .pddrc context. Stripping to just 'page' causes + sync to pick the wrong context or fail with 'No prompt files found'. + + Regression test for GitHub issue promptdriven/pdd_cloud#826. + """ + diff_output = ( + "prompts/frontend/app/dashboard/page_TypescriptReact.prompt\n" + "prompts/frontend/components/layout/Sidebar_TypescriptReact.prompt\n" + "prompts/frontend/components/dashboard/GitHubAppCTA_TypescriptReact.prompt\n" + "prompts/backend/utils/credit_helpers_python.prompt\n" + ) + with patch("pdd.agentic_sync.subprocess.run") as mock_run: + mock_run.side_effect = [ + MagicMock(returncode=0, stdout="change/issue-836\n", stderr=""), + MagicMock(returncode=0, stdout=diff_output, stderr=""), + ] + result = _detect_modules_from_branch_diff(Path("/fake/project")) + assert result == [ + "frontend/app/dashboard/page", + "frontend/components/layout/Sidebar", + "frontend/components/dashboard/GitHubAppCTA", + "backend/utils/credit_helpers", + ] + + def test_handles_extension_prompts_with_nested_prompts_dir(self): + """Prompts under extension dirs like extensions/github_pdd_app/prompts/ are handled. + + Extension prompts have a different structure: the 'prompts/' directory is nested + inside the extension, not at the repo root. The function should still extract + correct basenames relative to the prompts/ directory. + """ + diff_output = ( + "extensions/github_pdd_app/prompts/pdd_executor_Python.prompt\n" + "extensions/github_pdd_app/prompts/solving_orchestrator_Python.prompt\n" + ) + with patch("pdd.agentic_sync.subprocess.run") as mock_run: + mock_run.side_effect = [ + MagicMock(returncode=0, stdout="change/issue-838\n", stderr=""), + MagicMock(returncode=0, stdout=diff_output, stderr=""), + ] + result = _detect_modules_from_branch_diff(Path("/fake/project")) + assert result == ["pdd_executor", "solving_orchestrator"] + class TestBranchDiffSkipsLlm: """Verify run_agentic_sync uses branch diff and skips LLM when modules found."""