feat: enhance profile path resolution and add example profiles for better project adaptability
This commit is contained in:
47
scripts/aiw/test_profile.py
Normal file
47
scripts/aiw/test_profile.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/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")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user