test(deepdive): add fleet context unit tests (#830)
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
This commit is contained in:
62
intelligence/deepdive/tests/test_fleet_context.py
Normal file
62
intelligence/deepdive/tests/test_fleet_context.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests for Phase 0: Fleet Context Grounding"""
|
||||
|
||||
import pytest
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
import sys
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from fleet_context import FleetContext, GiteaFleetClient, build_fleet_context
|
||||
|
||||
|
||||
class TestFleetContext:
|
||||
"""Test suite for fleet context dataclass."""
|
||||
|
||||
def test_to_markdown_format(self):
|
||||
ctx = FleetContext(
|
||||
generated_at=datetime.now(timezone.utc).isoformat(),
|
||||
repos=[{"name": "the-nexus", "open_issues_count": 3, "open_prs_count": 1}],
|
||||
open_issues=[{"repo": "the-nexus", "number": 830, "title": "Deep Dive", "state": "open"}],
|
||||
recent_commits=[{"repo": "timmy-config", "message": "docs: update", "author": "ezra", "when": "2026-04-05T12:00:00Z"}],
|
||||
open_prs=[{"repo": "hermes-agent", "number": 42, "title": "feat: tools", "state": "open"}],
|
||||
)
|
||||
md = ctx.to_markdown()
|
||||
assert "Fleet Context Snapshot" in md
|
||||
assert "the-nexus" in md
|
||||
assert "#830" in md
|
||||
assert "docs: update" in md
|
||||
|
||||
def test_to_prompt_text(self):
|
||||
ctx = FleetContext(
|
||||
generated_at="2026-04-05T17:00:00Z",
|
||||
repos=[],
|
||||
open_issues=[],
|
||||
recent_commits=[],
|
||||
open_prs=[],
|
||||
)
|
||||
assert ctx.to_prompt_text() == ctx.to_markdown()
|
||||
|
||||
|
||||
class TestGiteaFleetClient:
|
||||
"""Test suite for Gitea API client (mocked)."""
|
||||
|
||||
def test_client_headers_with_token(self):
|
||||
client = GiteaFleetClient("http://example.com", token="testtoken")
|
||||
assert client.headers["Authorization"] == "token testtoken"
|
||||
|
||||
def test_client_headers_without_token(self):
|
||||
client = GiteaFleetClient("http://example.com")
|
||||
assert "Authorization" not in client.headers
|
||||
|
||||
|
||||
class TestBuildFleetContext:
|
||||
"""Test configuration-driven builder."""
|
||||
|
||||
def test_disabled_returns_none(self):
|
||||
config = {"fleet_context": {"enabled": False}}
|
||||
assert build_fleet_context(config) is None
|
||||
|
||||
def test_no_repos_returns_none(self):
|
||||
config = {"fleet_context": {"enabled": True, "repos": []}}
|
||||
assert build_fleet_context(config) is None
|
||||
Reference in New Issue
Block a user