Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Copy link
Copy Markdown
Collaborator

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, so PROJECT_ROOT=/workspace/linked-root pointing at /workspace/actual-root produces actualro instead of linkedro. Existing sessions named under the symlink prefix are then hidden by project-only filtering, which matches sa-{project_slug}-.

Suggested fix: handle . without changing absolute symlink identity, or document and test that project identity is based on the resolved real path.

value = re.sub(r"[^a-z0-9]", "", root.name.lower())[:8]
return value or "project"

@augmentcode augmentcode Bot Jun 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path.resolve() will also collapse symlinks, so callers passing a symlinked project_root may see get_project_slug() change compared to the prior Path(...).name behavior. Is that acceptable given this slug is used in tmux session naming/filtering?

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional, and consistent with the sibling get_project_hash, which already calls .resolve(). This makes a project's slug and hash agree on identity instead of diverging (the previous slug used the unresolved name while the hash resolved). For tmux session naming/filtering it's preferable: the same real project reached via different symlinked paths now maps to one consistent slug+hash, rather than fragmenting sessions per symlink. Net effect is removing a pre-existing slug/hash inconsistency, not introducing new behavior.


Expand Down
46 changes: 46 additions & 0 deletions tests/test_project_slug.py
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()