from fastapi.testclient import TestClient
import pytest

client = TestClient(app)

def test_bundle_requires_start_id_or_query():
    response = client.post("/decision/bundle", json={"role": "engineer"})
    assert response.status_code == 400

def test_bundle_with_fake_start_id():
    req = {
        "start_id": "dr:nonexistent",
        "role": "engineer",
        "max_hops": 1,
        "top_k": 1,
        "include_full_dr": False,
        "redaction": True,
    }
    response = client.post("/decision/bundle", json=req)
    assert response.status_code == 200
    data = response.json()
    assert data["start_id"] == "dr:nonexistent"
    assert "timeline" in data

def test_bundle_cache_hit():
    req = {
        "start_id": "dr:nonexistent",
        "role": "engineer",
        "max_hops": 1,
        "top_k": 1,
        "include_full_dr": False,
        "redaction": True,
    }
    # First call to populate cache
    client.post("/decision/bundle", json=req)
    # Second call to hit cache
    response = client.post("/decision/bundle", json=req)
    data = response.json()
    assert data.get("cache_hit") is True
