Skip to content

Commit 53f04bc

Browse files
aclark4lifeCopilot
andcommitted
spec status: show spec dirs touched in last resync commit
Adds _commit_spec_dirs() which runs 'git diff-tree' on the resync commit and extracts the unique top-level test/ subdirectory names, giving a clear summary of what was actually synced. Example output: 🕐 Last resync commit: 36dffed resyncing specs 05-18-2026 (3 days ago) Specs touched: discovery_and_monitoring, load_balancer, server_selection_logging In verbose mode, prior resync commits also show their touched dirs. 3 new tests added. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e35c559 commit 53f04bc

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

src/dbx_python_cli/commands/spec.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,27 @@ def _commit_relative_date(repo_path: Path, commit_sha: str) -> str:
384384
return result.stdout.strip() or "unknown"
385385

386386

387+
def _commit_spec_dirs(repo_path: Path, commit_sha: str) -> list[str]:
388+
"""Return sorted unique top-level test subdirectory names changed in a commit.
389+
390+
Runs ``git diff-tree`` on the commit and extracts the first path component
391+
under ``test/``, giving the spec directory names that were actually modified.
392+
"""
393+
result = subprocess.run(
394+
["git", "diff-tree", "--no-commit-id", "-r", "--name-only", commit_sha],
395+
cwd=repo_path,
396+
capture_output=True,
397+
text=True,
398+
check=False,
399+
)
400+
dirs: set[str] = set()
401+
for line in result.stdout.splitlines():
402+
parts = line.strip().split("/")
403+
if len(parts) >= 2 and parts[0] == "test":
404+
dirs.add(parts[1])
405+
return sorted(dirs)
406+
407+
387408
def _spec_is_stale(
388409
specs_source: Path,
389410
driver_test: Path,
@@ -505,9 +526,16 @@ def spec_status(
505526
sha = recent[0].split()[0]
506527
age = _commit_relative_date(driver_path, sha)
507528
typer.echo(f" 🕐 Last resync commit: {recent[0]} ({age})")
529+
spec_dirs = _commit_spec_dirs(driver_path, sha)
530+
if spec_dirs:
531+
typer.echo(f" Specs touched: {', '.join(spec_dirs)}")
508532
if verbose and len(recent) > 1:
509533
for c in recent[1:]:
510-
typer.echo(f" also: {c}")
534+
c_sha = c.split()[0]
535+
c_age = _commit_relative_date(driver_path, c_sha)
536+
c_dirs = _commit_spec_dirs(driver_path, c_sha)
537+
dirs_str = f" — {', '.join(c_dirs)}" if c_dirs else ""
538+
typer.echo(f" also: {c} ({c_age}){dirs_str}")
511539
else:
512540
typer.echo(" ⚠ No resync commit found on this branch.", err=True)
513541

tests/test_spec_command.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,62 @@ def test_spec_status_suggests_combined_command(tmp_path):
751751
assert result.exit_code == 0
752752
assert "dbx spec sync" in result.output
753753
assert "To sync all stale specs at once" in result.output
754+
755+
756+
def test_commit_spec_dirs(tmp_path):
757+
"""_commit_spec_dirs extracts unique test subdirs from a real git commit."""
758+
from dbx_python_cli.commands.spec import _commit_spec_dirs
759+
from unittest.mock import patch, MagicMock
760+
761+
mock_result = MagicMock()
762+
mock_result.stdout = (
763+
"test/crud/foo.json\n"
764+
"test/crud/bar.json\n"
765+
"test/sessions/baz.json\n"
766+
".evergreen/resync-specs.sh\n" # non-test file should be ignored
767+
"test/auth/qux.json\n"
768+
)
769+
770+
with patch("subprocess.run", return_value=mock_result):
771+
dirs = _commit_spec_dirs(tmp_path, "abc1234")
772+
773+
assert dirs == ["auth", "crud", "sessions"]
774+
775+
776+
def test_commit_spec_dirs_no_test_files(tmp_path):
777+
from dbx_python_cli.commands.spec import _commit_spec_dirs
778+
from unittest.mock import patch, MagicMock
779+
780+
mock_result = MagicMock()
781+
mock_result.stdout = ".evergreen/resync-specs.sh\n"
782+
783+
with patch("subprocess.run", return_value=mock_result):
784+
dirs = _commit_spec_dirs(tmp_path, "abc1234")
785+
786+
assert dirs == []
787+
788+
789+
def test_spec_status_shows_specs_touched(tmp_path):
790+
_, cfg = _make_status_repos(tmp_path, content_same=True)
791+
with (
792+
patch("dbx_python_cli.utils.repo.get_config_path", return_value=cfg),
793+
patch(
794+
"dbx_python_cli.commands.spec._get_current_branch",
795+
return_value="spec-resync-test",
796+
),
797+
patch(
798+
"dbx_python_cli.commands.spec._find_recent_resync_commits",
799+
return_value=["abc1234 resyncing specs 05-18-2026"],
800+
),
801+
patch(
802+
"dbx_python_cli.commands.spec._commit_relative_date",
803+
return_value="3 days ago",
804+
),
805+
patch(
806+
"dbx_python_cli.commands.spec._commit_spec_dirs",
807+
return_value=["auth", "crud", "sessions"],
808+
),
809+
):
810+
result = runner.invoke(app, ["spec", "status"])
811+
assert result.exit_code == 0
812+
assert "Specs touched: auth, crud, sessions" in result.output

0 commit comments

Comments
 (0)