-
Notifications
You must be signed in to change notification settings - Fork 16
fix(project-slug): resolve relative root before deriving slug #38
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,9 @@ def get_project_root() -> str: | |
|
|
||
|
|
||
| def get_project_slug(project_root: str | None = None) -> str: | ||
| root = Path(project_root or get_project_root()) | ||
| # Resolve before .name so a relative root like "." (whose Path(".").name is "") | ||
| # doesn't collapse to the generic "project" fallback. Mirrors get_project_hash(). | ||
| root = Path(project_root or get_project_root()).resolve() | ||
| value = re.sub(r"[^a-z0-9]", "", root.name.lower())[:8] | ||
| return value or "project" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: low 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentional, and consistent with the sibling |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import tempfile | ||
| import unittest | ||
| from contextlib import contextmanager | ||
| from pathlib import Path | ||
|
|
||
| from story_automator.core.utils import get_project_slug | ||
|
|
||
|
|
||
| @contextmanager | ||
| def chdir(path: str): | ||
| prev = os.getcwd() | ||
| os.chdir(path) | ||
| try: | ||
| yield | ||
| finally: | ||
| os.chdir(prev) | ||
|
|
||
|
|
||
| class GetProjectSlugTests(unittest.TestCase): | ||
| def test_absolute_root_uses_dir_name(self) -> None: | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| target = Path(tmp) / "upmon-automator" | ||
| target.mkdir() | ||
| self.assertEqual(get_project_slug(str(target)), "upmonaut") | ||
|
|
||
| def test_relative_dot_resolves_instead_of_collapsing_to_generic(self) -> None: | ||
| # Regression: `Path(".").name == ""` previously collapsed to "project". | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| target = Path(tmp) / "myproject" | ||
| target.mkdir() | ||
| with chdir(str(target)): | ||
| self.assertEqual(get_project_slug("."), "myprojec") | ||
|
|
||
| def test_empty_name_still_falls_back_to_project(self) -> None: | ||
| # A root that resolves to a non-alphanumeric name keeps the safe default. | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| target = Path(tmp) / "___" | ||
| target.mkdir() | ||
| self.assertEqual(get_project_slug(str(target)), "project") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
This currently resolves the project root before deriving the slug. That fixes
.but also makes an absolute symlinked root use the target directory basename, soPROJECT_ROOT=/workspace/linked-rootpointing at/workspace/actual-rootproducesactualroinstead oflinkedro. Existing sessions named under the symlink prefix are then hidden by project-only filtering, which matchessa-{project_slug}-.Suggested fix: handle
.without changing absolute symlink identity, or document and test that project identity is based on the resolved real path.