Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ requires-python = ">=3.11"
dependencies = [
"pydantic>=2.7,<3",
"PyYAML>=6.0,<7",
"fastapi>=0.110,<1"
"fastapi>=0.110,<1",
"httpx>=0.27,<1"
]

[project.scripts]
Expand Down
45 changes: 45 additions & 0 deletions tests/test_api_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from fastapi.testclient import TestClient

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Declare httpx before importing TestClient

In a clean CI environment, this import fails during test collection because Starlette's TestClient requires the optional httpx package. The workflow in .github/workflows/ci.yml installs only the package and pytest, while pyproject.toml does not declare httpx, so this commit makes the test job consistently fail with ModuleNotFoundError: No module named 'httpx'; add it to the project's test dependencies and install those dependencies in CI.

Useful? React with 👍 / 👎.


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