The worktree pill's hover card listed each worktree's short name only, so a conversation that spun up worktrees in several repos (e.g. `ae-paint` in both creature-forge and spore-study) gave no way to tell them apart. - Backend: each worktree record now carries `project` — read off `new-worktree.sh -p <project>` by the transcript parse (`homelab` in super mode), else inferred from the `<project>-<name>` dir by the longest matching ~/projects slug (projects.worktree_project), so summaries parsed before the field existed and live sidecar events get one too. - Frontend: the card groups the rows under a sticky heading per project — the project's registry pill (colour + icon) linking to its page, and its count; a worktree whose project is unknown shows its full dir under "unknown project". Clicks inside the card no longer bubble to the conversation card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.6 KiB
Python
85 lines
3.6 KiB
Python
"""Each worktree a conversation created says which repo it is a worktree of —
|
|
the worktree pill's hover card groups by it. The parse reads it off
|
|
`new-worktree.sh -p <project>` (homelab otherwise); a summary parsed before the
|
|
field existed, or a live sidecar event, gets it from the directory name.
|
|
``python3 -m unittest test_worktree_project``"""
|
|
|
|
import pathlib
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
import projects
|
|
from conversations import cards
|
|
from conversations.parse import _worktree_events
|
|
from projects import catalog
|
|
|
|
|
|
class WorktreeEvents(unittest.TestCase):
|
|
def test_project_mode_records_the_project(self):
|
|
self.assertEqual(
|
|
_worktree_events("scripts/new-worktree.sh -p creature-forge ae-paint"),
|
|
[{"kind": "create", "name": "ae-paint", "dir": "creature-forge-ae-paint",
|
|
"project": "creature-forge"}])
|
|
|
|
def test_super_mode_is_homelab(self):
|
|
self.assertEqual(
|
|
_worktree_events("cd ~/homelab && scripts/new-worktree.sh fix-x"),
|
|
[{"kind": "create", "name": "fix-x", "dir": "homelab-fix-x",
|
|
"project": "homelab"}])
|
|
|
|
def test_remove_has_no_project(self):
|
|
self.assertEqual(
|
|
_worktree_events("scripts/new-worktree.sh -r ~/worktrees/bffr-groups"),
|
|
[{"kind": "remove", "name": "", "dir": "bffr-groups"}])
|
|
|
|
|
|
class WorktreeProject(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
root = pathlib.Path(self.tmp.name)
|
|
for d in ("creature-forge", "creature", "spore-study", "ai-agent", "node_modules"):
|
|
(root / d).mkdir()
|
|
self.patches = [mock.patch.object(catalog, "PROJECTS_DIR", root),
|
|
mock.patch.object(catalog, "_wt_slugs", None)]
|
|
for p in self.patches:
|
|
p.start()
|
|
|
|
def tearDown(self):
|
|
for p in reversed(self.patches):
|
|
p.stop()
|
|
self.tmp.cleanup()
|
|
|
|
def test_longest_slug_wins(self):
|
|
self.assertEqual(projects.worktree_project("creature-forge-ae-paint"), "creature-forge")
|
|
self.assertEqual(projects.worktree_project("creature-x"), "creature")
|
|
self.assertEqual(projects.worktree_project("ai-agent-hold-fix"), "ai-agent")
|
|
|
|
def test_homelab_and_unknown(self):
|
|
self.assertEqual(projects.worktree_project("homelab-relay-mirror"), "homelab")
|
|
self.assertIsNone(projects.worktree_project("gone-project-x"))
|
|
self.assertIsNone(projects.worktree_project("node_modules-x"))
|
|
self.assertIsNone(projects.worktree_project(""))
|
|
|
|
def test_merge_prefers_parsed_project_then_infers(self):
|
|
merged = cards._merge_worktrees(
|
|
# parsed: explicit project, even one the dir would not infer
|
|
[{"name": "ae-paint", "dir": "spore-study-ae-paint", "project": "spore-study",
|
|
"createdAt": "2026-10-20T19:07:08Z", "removedAt": None},
|
|
{"name": "x", "dir": "creature-x", "project": "creature-forge",
|
|
"createdAt": "2026-10-20T19:08:00Z", "removedAt": None}],
|
|
# live sidecar: no project field — inferred from the dir
|
|
[{"name": "groups", "dir": "homelab-groups", "createdAt": "2026-10-20T20:00:00Z"},
|
|
{"name": "ae-paint", "dir": "spore-study-ae-paint",
|
|
"removedAt": "2026-10-20T22:24:11Z"}])
|
|
self.assertEqual([(w["dir"], w["project"]) for w in merged], [
|
|
("spore-study-ae-paint", "spore-study"),
|
|
("creature-x", "creature-forge"),
|
|
("homelab-groups", "homelab"),
|
|
])
|
|
self.assertEqual(merged[0]["removedAt"], "2026-10-20T22:24:11Z")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|