Skip to content

test: add public health liveness contract test - #376

Merged
ashrafee-dev merged 1 commit into
ashrafee-dev:mainfrom
ananyamk1:test/34-health-contract
Nov 13, 2026
Merged

ashrafee-dev merged 1 commit into
ashrafee-dev:mainfrom
ananyamk1:test/34-health-contract

Conversation

@ananyamk1

Copy link
Copy Markdown
Contributor

Outcome

Fixes #34

Adds a focused contract test for the public /health liveness endpoint: it's called with no Authorization header, returns 200 with exactly {"status": "ok"}, and never touches Redis or the provider. Before this, the only /health test (tests/test_security.py:52) sent the fixture's Bearer header and checked just the status code.

Changes

  • New file tests/roadmap/text/test_health_contract.py with one test, test_health_is_public_and_cheap:
    • removes the client's Authorization header (as AGENTS.md says to for unauthenticated tests)
    • patches rate_limit.check_rate_limit, rate_limit.r.ping, risk.ask_deepseek and analyze.get_assessment where they're looked up
    • asserts no Authorization header was sent, status 200, body exactly {"status": "ok"}, and none of the four mocks were called
  • No runtime code changed, no changes to conftest.py or existing tests, no new dependencies.

Verification

Run on macOS, Python 3.13.9, uv, base main c05a0ec.

Before (main): the only /health assertion is the status code.

$ grep -rn '"/health"' tests
tests/test_security.py:52:    assert client.get("/health").status_code == 200

After:

$ uv run pytest tests/roadmap/text/test_health_contract.py -q
1 passed, 1 warning in 0.02s

The test catches a broken contract. I temporarily changed health_check() to return {"status": "broken"} (reverted after, not part of this PR):

E       AssertionError: assert {'status': 'broken'} == {'status': 'ok'}
1 failed, 1 warning in 0.07s

Full checks (scripts/check.sh):

$ uv run pytest
56 passed, 1 warning
$ uv run pylint app tests
Your code has been rated at 10.00/10

The warning is the existing StarletteDeprecationWarning from fastapi/testclient.py, also on main.

Not verified: I didn't run the docs build (no docs changed), the container smoke test, or anything on Linux/Windows.

Review notes

  • I patched the provider and assessment functions where risk.py and analyze.py import them, so the "not called" assertions would actually catch a call through those modules.
  • AI use: I used Claude (Claude Code) to set up the environment and find which functions to mock, and it walked me through writing the test step by step. I typed it myself, ran it, and checked it fails when the endpoint's body changes.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 16:06
@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown

@ananyamk1 is attempting to deploy a commit to the ashrafee-dev's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@ashrafee-dev
ashrafee-dev merged commit acdba34 into ashrafee-dev:main Nov 13, 2026
0 of 2 checks passed
@ashrafee-dev

Copy link
Copy Markdown
Owner

Thanks for your contributions! @ananyamk1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test exact public liveness response without authentication

3 participants