Some checks failed
Contributor Attribution Check / check-attribution (pull_request) Failing after 15s
Supply Chain Audit / Scan PR for supply chain risks (pull_request) Successful in 15s
Docker Build and Publish / build-and-push (pull_request) Has been skipped
Tests / test (pull_request) Failing after 18m33s
Tests / e2e (pull_request) Successful in 1m17s
Part of #891
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
"""Tests for profile session isolation (#891)."""
|
|
|
|
import sys
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
# Override paths for testing
|
|
import agent.profile_isolation as iso_mod
|
|
_test_dir = Path(tempfile.mkdtemp())
|
|
iso_mod.PROFILE_TAGS_FILE = _test_dir / "tags.json"
|
|
|
|
|
|
def test_tag_session():
|
|
"""Session gets tagged with profile."""
|
|
profile = iso_mod.tag_session("sess-1", "sprint")
|
|
assert profile == "sprint"
|
|
assert iso_mod.get_session_profile("sess-1") == "sprint"
|
|
|
|
|
|
def test_default_profile():
|
|
"""Sessions tagged with default when no profile specified."""
|
|
profile = iso_mod.tag_session("sess-2")
|
|
assert profile is not None
|
|
|
|
|
|
def test_get_session_profile():
|
|
"""Can retrieve profile for tagged session."""
|
|
iso_mod.tag_session("sess-3", "fenrir")
|
|
assert iso_mod.get_session_profile("sess-3") == "fenrir"
|
|
|
|
|
|
def test_untagged_returns_none():
|
|
"""Untagged session returns None."""
|
|
assert iso_mod.get_session_profile("nonexistent") is None
|
|
|
|
|
|
def test_profile_stats():
|
|
"""Stats reflect tagged sessions."""
|
|
iso_mod.tag_session("s1", "default")
|
|
iso_mod.tag_session("s2", "sprint")
|
|
iso_mod.tag_session("s3", "sprint")
|
|
stats = iso_mod.get_profile_stats()
|
|
assert stats["total_tagged_sessions"] >= 3
|
|
assert "sprint" in stats["profile_counts"]
|
|
|
|
|
|
def test_filter_sessions():
|
|
"""Filter returns only matching profile sessions."""
|
|
iso_mod.tag_session("filter-1", "alpha")
|
|
iso_mod.tag_session("filter-2", "beta")
|
|
iso_mod.tag_session("filter-3", "alpha")
|
|
|
|
sessions = [
|
|
{"session_id": "filter-1"},
|
|
{"session_id": "filter-2"},
|
|
{"session_id": "filter-3"},
|
|
]
|
|
|
|
filtered = iso_mod.filter_sessions_by_profile(sessions, "alpha")
|
|
ids = [s["session_id"] for s in filtered]
|
|
assert "filter-1" in ids
|
|
assert "filter-3" in ids
|
|
assert "filter-2" not in ids
|
|
|
|
|
|
if __name__ == "__main__":
|
|
tests = [test_tag_session, test_default_profile, test_get_session_profile,
|
|
test_untagged_returns_none, test_profile_stats, test_filter_sessions]
|
|
for t in tests:
|
|
print(f"Running {t.__name__}...")
|
|
t()
|
|
print(" PASS")
|
|
print("\nAll tests passed.")
|