Closes #146, #147, #148. Parallel plan isolation (#148, @shawnli1874): init-session.sh slug mode creates .planning/YYYY-MM-DD-<slug>/ for each task. set-active-plan.sh/.ps1 switch the active plan pointer. resolve-plan-dir.sh/.ps1 provide the resolution chain ($PLAN_ID env, .active_plan file, newest plan dir, legacy fallback). All four Codex hooks route through the resolver. resolve_latest_dir now requires task_plan.md to be present, preventing system dirs like sessions/ from being selected as plan dirs. short_uuid() probes each Python candidate before trusting command -v, fixing silent failure on Windows Store aliases. Codex session isolation (#146, @githubYiheng): sessions attach to a plan by creating .planning/sessions/<session_id>.attached. user-prompt-submit.sh, pre_tool_use.py, stop.py, and post_tool_use.py all gate on session attachment before injecting context or blocking. Legacy mode preserved when .planning/sessions/ does not exist. Hermes integration notes (#147, @09ashishkapoor): docs/hermes.md gains an Integration Notes section covering current support level, what is not full parity with hook-native platforms, recommended integration pattern, and a tradeoffs table. 34 new tests across five files. Version bumped to 2.36.0 across 14 SKILL.md variants, plugin.json, marketplace.json, and CITATION.cff.
99 lines
4.2 KiB
Python
99 lines
4.2 KiB
Python
"""Tests for slug-aware init-session.sh — addresses #148.
|
|
|
|
Backward-compat behavior:
|
|
- Zero args → legacy root mode: writes task_plan.md/findings.md/progress.md in cwd
|
|
- One+ string args → slug mode: writes under .planning/YYYY-MM-DD-<slug>/
|
|
- --plan-dir flag forces slug mode without naming
|
|
- Slug collisions append -2, -3, ...
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from datetime import date
|
|
from pathlib import Path
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
INIT_SH = REPO_ROOT / "scripts" / "init-session.sh"
|
|
|
|
|
|
class InitSessionSlugTests(unittest.TestCase):
|
|
def run_init(self, cwd: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
|
return subprocess.run(
|
|
["sh", str(INIT_SH), *args],
|
|
cwd=str(cwd),
|
|
text=True,
|
|
capture_output=True,
|
|
check=False,
|
|
)
|
|
|
|
def test_legacy_zero_args_keeps_root_files(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
result = self.run_init(root)
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertTrue((root / "task_plan.md").exists())
|
|
self.assertTrue((root / "findings.md").exists())
|
|
self.assertTrue((root / "progress.md").exists())
|
|
self.assertFalse((root / ".planning").exists(), "legacy mode must not create .planning/")
|
|
|
|
def test_slug_arg_creates_dated_dir(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
result = self.run_init(root, "Backend Refactor")
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
today = date.today().isoformat()
|
|
expected = root / ".planning" / f"{today}-backend-refactor"
|
|
self.assertTrue(expected.is_dir(), f"missing {expected}")
|
|
self.assertTrue((expected / "task_plan.md").exists())
|
|
self.assertTrue((expected / "findings.md").exists())
|
|
self.assertTrue((expected / "progress.md").exists())
|
|
active = (root / ".planning" / ".active_plan").read_text(encoding="utf-8").strip()
|
|
self.assertEqual(active, f"{today}-backend-refactor")
|
|
|
|
def test_slug_sanitizes_unsafe_chars(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
result = self.run_init(root, "Foo / Bar! Baz??")
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
today = date.today().isoformat()
|
|
expected = root / ".planning" / f"{today}-foo-bar-baz"
|
|
self.assertTrue(expected.is_dir(), f"got {[p.name for p in (root / '.planning').iterdir()]}")
|
|
|
|
def test_slug_collision_appends_suffix(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
self.run_init(root, "same name")
|
|
result = self.run_init(root, "same name")
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
today = date.today().isoformat()
|
|
self.assertTrue((root / ".planning" / f"{today}-same-name").is_dir())
|
|
self.assertTrue((root / ".planning" / f"{today}-same-name-2").is_dir())
|
|
|
|
def test_plan_dir_flag_default_slug(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
result = self.run_init(root, "--plan-dir")
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
today = date.today().isoformat()
|
|
dirs = list((root / ".planning").iterdir())
|
|
dirs = [d for d in dirs if d.is_dir()]
|
|
self.assertEqual(1, len(dirs))
|
|
self.assertTrue(re.match(rf"^{today}-untitled-[a-z0-9]+$", dirs[0].name))
|
|
|
|
def test_template_flag_still_works_in_legacy_mode(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
result = self.run_init(root, "--template", "default")
|
|
self.assertEqual(0, result.returncode, result.stderr)
|
|
self.assertTrue((root / "task_plan.md").exists())
|
|
self.assertFalse((root / ".planning").exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|