From b6a473d8080ba511986ce6c980006325c4038273 Mon Sep 17 00:00:00 2001 From: Ezra Date: Sun, 5 Apr 2026 17:32:25 +0000 Subject: [PATCH] test(deepdive): add fleet context unit tests (#830) --- .../deepdive/tests/test_fleet_context.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 intelligence/deepdive/tests/test_fleet_context.py diff --git a/intelligence/deepdive/tests/test_fleet_context.py b/intelligence/deepdive/tests/test_fleet_context.py new file mode 100644 index 0000000..b22eefe --- /dev/null +++ b/intelligence/deepdive/tests/test_fleet_context.py @@ -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