54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
PROFILE_PATH = Path(__file__).with_name("profile.py")
|
|
SPEC = importlib.util.spec_from_file_location("aiw_profile", PROFILE_PATH)
|
|
profile = importlib.util.module_from_spec(SPEC)
|
|
assert SPEC.loader is not None
|
|
sys.modules[SPEC.name] = profile
|
|
SPEC.loader.exec_module(profile)
|
|
|
|
|
|
class ProfileTests(unittest.TestCase):
|
|
def test_workspace_config_resolves_profile_paths(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
config = root / "profiles" / "demo" / "workspace.json"
|
|
config.parent.mkdir(parents=True)
|
|
config.write_text(json.dumps({
|
|
"knowledge_dir": "workspaces/demo/project-knowledge",
|
|
"inbox_dir": "workspaces/demo/inbox",
|
|
"index_dir": ".aiw/indexes/demo",
|
|
}), encoding="utf-8")
|
|
|
|
self.assertEqual(profile.knowledge_dir("demo", root=root), root / "workspaces" / "demo" / "project-knowledge")
|
|
self.assertEqual(profile.inbox_dir("demo", root=root), root / "workspaces" / "demo" / "inbox")
|
|
self.assertEqual(profile.index_dir("demo", root=root), root / ".aiw" / "indexes" / "demo")
|
|
|
|
def test_defaults_preserve_current_root_paths(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
|
|
self.assertEqual(profile.knowledge_dir("missing", root=root), root / "project-knowledge")
|
|
self.assertEqual(profile.inbox_dir("missing", root=root), root / "ai" / "inbox")
|
|
self.assertEqual(profile.index_dir("missing", root=root), root / ".aiw" / "indexes" / "missing")
|
|
|
|
def test_relative_to_root_handles_external_paths(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
self.assertEqual(profile.relative_to_root(root / "a" / "b", root=root), "a/b")
|
|
self.assertEqual(profile.relative_to_root(Path("/external/path"), root=root), "/external/path")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|