Skip to content

Commit de552a0

Browse files
HumanBean17claude
andcommitted
fix detect_microservice_from_path for cwd at microservice root
microservice_for_path walks _bounded_parents which excludes the path itself. When cwd is exactly the microservice root directory (the most common case), it was never checked for a build marker and auto-scope returned None. Pass a synthetic child path so cwd appears in the parent walk. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 55da9ca commit de552a0

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

graph_enrich.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,11 @@ def detect_microservice_from_path(cwd: Path, source_root: Path) -> str | None:
15891589
if overrides and cwd_resolved.name in overrides:
15901590
return cwd_resolved.name
15911591

1592-
# Call existing microservice_for_path to detect microservice from build markers
1593-
ms = microservice_for_path(str(cwd_resolved), source_resolved)
1592+
# microservice_for_path walks _bounded_parents which excludes the path itself.
1593+
# For query-time detection we need cwd included in the walk, so pass a synthetic
1594+
# child path so that cwd appears as a parent in the build-marker scan.
1595+
synthetic = cwd_resolved / "__scope_probe__"
1596+
ms = microservice_for_path(str(synthetic), source_resolved)
15941597
return ms if ms else None
15951598

15961599

tests/test_microservice_scope.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,30 @@ def test_detect_microservice_deep_inside(self, tmp_path):
2121
assert result == "microservice-a"
2222

2323
def test_detect_microservice_at_microservice_root(self, tmp_path):
24-
"""At microservice root detects that microservice."""
24+
"""At microservice root (cwd = the dir with pom.xml) detects that microservice."""
2525
ms_dir = tmp_path / "microservice-b"
2626
ms_dir.mkdir()
2727

2828
# Add a build marker
2929
(ms_dir / "build.gradle").write_text("plugins { id 'java' }")
3030

31-
# Use a subdirectory inside the microservice (not the root itself)
32-
sub_dir = ms_dir / "src"
33-
sub_dir.mkdir()
34-
35-
result = detect_microservice_from_path(sub_dir, tmp_path)
31+
# cwd IS the microservice root — the most common user scenario
32+
result = detect_microservice_from_path(ms_dir, tmp_path)
3633
assert result == "microservice-b"
3734

35+
def test_detect_microservice_nested_modules(self, tmp_path):
36+
"""Nested build markers scope to outermost microservice, not inner module."""
37+
ms_dir = tmp_path / "my-service"
38+
ms_dir.mkdir()
39+
(ms_dir / "pom.xml").write_text("<project></project>")
40+
module_dir = ms_dir / "my-module"
41+
module_dir.mkdir()
42+
(module_dir / "pom.xml").write_text("<project></project>")
43+
44+
# From inside the module, should scope to the service, not the module
45+
result = detect_microservice_from_path(module_dir, tmp_path)
46+
assert result == "my-service"
47+
3848
def test_detect_microservice_at_system_root(self, tmp_path):
3949
"""At system root returns None (no specific scope)."""
4050
result = detect_microservice_from_path(tmp_path, tmp_path)

0 commit comments

Comments
 (0)