feat: multi-user/multi-persona support with two-level home directory layout
Restructures persona storage from a flat personas/{name}/ layout to
home/{username}/persona/{name}/, mirroring Linux home directories.
Changes:
- persona.py: two ContextVars (user + persona), Linux-style name validation,
set_context(), get_user(), get_persona(), validate(), list_users(),
list_user_personas(); persona_path() takes (username, name)
- config.py: replaces personas_dir with home_dir + home_root()
- git mv personas/inara → home/scott/persona/inara (history preserved)
- home/holly/persona/tina/: Holly's persona stub added
- cron_runner.py: all storage functions take (username, persona) params
- tools/cron.py: stamps user + persona on jobs; APScheduler IDs are
{user}:{persona}:{job_id} to prevent collisions across users
- memory_distiller.py: distill_short/mid/long take (username, persona);
added missing Path + settings imports
- scheduler.py: _load_user_crons() iterates home/*/persona/* (two-level)
- routers/chat.py, orchestrator.py: user field added; set_context() called
- tests/conftest.py: home_root fixture with two-level structure;
patches home_dir instead of personas_dir
- tests/test_persona.py: fully rewritten for two-level API
- tests/test_api_files.py: updated fixture name and path
- .env.default: documents HOME_DIR setting; scrubs stale API key
- CLAUDE.md, README.md: directory maps updated for new layout
All 80 tests pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,19 @@
|
||||
Shared fixtures for Cortex test suite.
|
||||
|
||||
Key design choices:
|
||||
- All file I/O goes to a tmp_path, never touching personas/inara/ or real sessions.
|
||||
- All file I/O goes to a tmp_path, never touching home/ or real sessions.
|
||||
- LLM calls are mocked by default — tests are fast and deterministic.
|
||||
- The 'app' fixture patches settings before importing main, so all modules
|
||||
- The 'client' fixture patches settings before importing main, so all modules
|
||||
see the temp directory.
|
||||
|
||||
Home layout mirrors the two-level structure:
|
||||
tmp/
|
||||
scott/
|
||||
persona/
|
||||
inara/ ← the default test persona
|
||||
holly/
|
||||
persona/
|
||||
tina/
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -19,19 +28,21 @@ from httpx import ASGITransport
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Temp persona directory
|
||||
# Temp home directory
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def personas_root(tmp_path_factory) -> Path:
|
||||
"""A temp personas/ dir with a minimal 'inara' persona for testing."""
|
||||
root = tmp_path_factory.mktemp("personas")
|
||||
_make_persona(root, "inara", "Inara", "Scott")
|
||||
def home_root(tmp_path_factory) -> Path:
|
||||
"""A temp home/ dir with minimal user/persona stubs for testing."""
|
||||
root = tmp_path_factory.mktemp("home")
|
||||
_make_persona(root, "scott", "inara", "Inara", "Scott")
|
||||
_make_persona(root, "holly", "tina", "Tina", "Holly")
|
||||
return root
|
||||
|
||||
|
||||
def _make_persona(root: Path, name: str, agent: str, user: str) -> Path:
|
||||
p = root / name
|
||||
def _make_persona(root: Path, username: str, persona: str,
|
||||
agent: str, user: str) -> Path:
|
||||
p = root / username / "persona" / persona
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
(p / "IDENTITY.md").write_text(f"# {agent}\nTest identity for {agent}.")
|
||||
(p / "SOUL.md").write_text(f"# Soul\nTest soul for {agent}.")
|
||||
@@ -54,7 +65,7 @@ def _make_persona(root: Path, name: str, agent: str, user: str) -> Path:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def client(personas_root, tmp_path):
|
||||
async def client(home_root, tmp_path):
|
||||
"""HTTPX async test client against the live ASGI app with patched paths."""
|
||||
import config
|
||||
import persona as persona_mod
|
||||
@@ -63,13 +74,12 @@ async def client(personas_root, tmp_path):
|
||||
sessions_dir.mkdir()
|
||||
|
||||
with (
|
||||
patch.object(config.settings, "personas_dir", personas_root),
|
||||
patch.object(config.settings, "home_dir", home_root),
|
||||
patch.object(config.settings, "sessions_dir", sessions_dir),
|
||||
patch("scheduler.start"), # don't run APScheduler in tests
|
||||
patch("scheduler.stop"),
|
||||
):
|
||||
# Force persona module to re-read patched settings
|
||||
persona_mod._current.set("inara")
|
||||
persona_mod.set_context("scott", "inara")
|
||||
|
||||
from main import app
|
||||
async with httpx.AsyncClient(
|
||||
|
||||
Reference in New Issue
Block a user