-
Notifications
You must be signed in to change notification settings - Fork 0
feat(discovery): canonicalize same-origin checkouts in workspace scan #32
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """Tests for workspace discovery canonicalization in portfolio_truth_sources. | ||
|
|
||
| Multiple on-disk checkouts of the same repo (linked git worktrees and stray | ||
| duplicate full-clones left by multi-repo sweeps) share one origin | ||
| (`repo_full_name`). Discovery must collapse them to a single canonical project | ||
| so they don't inflate the project count and pollute catalog-completeness. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from src.portfolio_truth_sources import _dedupe_checkouts_by_origin | ||
|
|
||
|
|
||
| def _p(name: str, repo_full_name: str = "", path: str | None = None) -> dict: | ||
| return {"name": name, "repo_full_name": repo_full_name, "path": path or name} | ||
|
|
||
|
|
||
| def test_collapses_same_origin_checkouts_to_one() -> None: | ||
| discovered = [ | ||
| _p("AssistSupport-openssl-fix", "saagpatel/AssistSupport"), | ||
| _p("AssistSupport", "saagpatel/AssistSupport"), | ||
| _p("AssistSupport-security-followup", "saagpatel/AssistSupport"), | ||
| ] | ||
| result = _dedupe_checkouts_by_origin(discovered) | ||
| assert len(result) == 1 | ||
| # the canonical checkout is the one whose dir name matches the repo basename | ||
| assert result[0]["name"] == "AssistSupport" | ||
|
|
||
|
|
||
| def test_prefers_basename_match_then_shortest_name() -> None: | ||
| # no exact-basename checkout present -> shortest name wins | ||
| discovered = [ | ||
| _p("IncidentWorkbench-statuspage-finish", "saagpatel/IncidentWorkbench"), | ||
| _p("IncidentWorkbench-zendesk", "saagpatel/IncidentWorkbench"), | ||
| ] | ||
| result = _dedupe_checkouts_by_origin(discovered) | ||
| assert len(result) == 1 | ||
| assert result[0]["name"] == "IncidentWorkbench-zendesk" # shortest | ||
|
|
||
|
|
||
| def test_distinct_origins_are_kept() -> None: | ||
| discovered = [ | ||
| _p("Alpha", "saagpatel/Alpha"), | ||
| _p("Beta", "saagpatel/Beta"), | ||
| ] | ||
| result = _dedupe_checkouts_by_origin(discovered) | ||
| assert {p["name"] for p in result} == {"Alpha", "Beta"} | ||
|
|
||
|
|
||
| def test_origin_basename_match_is_case_insensitive() -> None: | ||
| discovered = [ | ||
| _p("notion-operating-system", "saagpatel/notion-operating-system"), | ||
| _p("Notion", "saagpatel/notion-operating-system"), | ||
| ] | ||
| result = _dedupe_checkouts_by_origin(discovered) | ||
| assert len(result) == 1 | ||
| assert result[0]["name"] == "notion-operating-system" | ||
|
|
||
|
|
||
| def test_local_only_projects_without_origin_are_never_collapsed() -> None: | ||
| # empty repo_full_name => genuinely distinct local projects, keep all | ||
| discovered = [ | ||
| _p("scratch-a", ""), | ||
| _p("scratch-b", ""), | ||
| _p("scratch-c", ""), | ||
| ] | ||
| result = _dedupe_checkouts_by_origin(discovered) | ||
| assert len(result) == 3 | ||
|
|
||
|
|
||
| def test_result_is_sorted_by_name_case_insensitively() -> None: | ||
| discovered = [ | ||
| _p("zeta", "saagpatel/zeta"), | ||
| _p("Alpha", "saagpatel/Alpha"), | ||
| _p("mike", ""), | ||
| ] | ||
| result = _dedupe_checkouts_by_origin(discovered) | ||
| assert [p["name"] for p in result] == ["Alpha", "mike", "zeta"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When same-origin checkouts include a path-cataloged project plus a stray basename clone, this tie-breaker always keeps the basename directory even if the catalog only has a contract for the nested path.
_build_truth_projectlater resolves catalog entries fromraw_project["path"]first, so a workspace withITPRJsViaClaude/IncidentWorkbenchand a rootIncidentWorkbenchsharing the same origin would drop the explicitITPRJsViaClaude/IncidentWorkbenchcontract and report the wrong group/completeness metadata. Consider preferring checkouts whose path has an explicit catalog entry before falling back to basename/length.Useful? React with 👍 / 👎.