Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tests/test_api_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import httpx
from fastapi.testclient import TestClient

from sovereign_cortex.api import create_app


def _write_workspace(tmp_path):
vault = tmp_path / "vault" / "demo-project" / "tasks"
vault.mkdir(parents=True)
(tmp_path / "workspaces.yaml").write_text(
"workspaces:\n demo-project:\n vault_root: vault/demo-project\n",
encoding="utf-8",
)
(vault / "launch.md").write_text(
"---\nid: launch\ntitle: Launch\nstatus: planned\ndue: 2026-06-05\ndependencies: []\n---\n# Launch\n",
encoding="utf-8",
)


def test_health_contract_uses_http_client():
client = TestClient(create_app())

response = client.get("/health")

assert response.status_code == 200
assert response.json() == {"status": "ok"}


def test_commands_contract_serializes_report_response(tmp_path):
_write_workspace(tmp_path)
client = TestClient(create_app(tmp_path))

response = client.post(
"/commands",
json={"text": "Project summary", "date": "2026-06-06"},
)

assert response.status_code == 200
payload = response.json()
assert set(payload) == {"status", "message", "approval_id", "commit_hash", "events"}
assert payload["status"] == "no_action"
assert payload["approval_id"] is None
assert payload["commit_hash"] is None
assert "Project summary for demo-project:" in payload["message"]
assert payload["events"][0]["event_type"] == "CommandReceived"
assert payload["events"][0]["payload"]["channel"] == "api"
Loading