Skip to content

Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411

Merged
berendt merged 2 commits into
mainfrom
implement/issue-2406-api-facts-integration-test
Jun 22, 2026
Merged

Integration test: API facts endpoints (FastAPI TestClient + Redis)#2411
berendt merged 2 commits into
mainfrom
implement/issue-2406-api-facts-integration-test

Conversation

@berendt

@berendt berendt commented Jun 19, 2026

Copy link
Copy Markdown
Member

What

Integration coverage for the read-only inventory-facts HTTP endpoints, which
read straight from Redis:

  • GET /v1/inventory/hosts/{host}/facts (osism/api.py:927)
  • GET /v1/inventory/hosts/{host}/facts/{fact} (osism/api.py:966)

Both call utils.redis.get("ansible_facts{host}"). Driving them through
fastapi.testclient.TestClient against the live Redis exercises the API↔Redis
read path end-to-end. The suite is skipped automatically when Redis is not
reachable, like the other modules under tests/integration/.

Part of #2400. Follow-up to #2368.

Changes (in commit order)

  1. Add httpx to dev dependencies for FastAPI TestClientfastapi.testclient.TestClient
    needs httpx as its transport. Adds httpx = "==0.28.1" to [dev-packages]
    and regenerates Pipfile.lock so pipenv install --dev --deploy keeps
    verifying the lock in CI. The lock diff adds only httpx and its transitives
    (httpcore, h11, anyio, sniffio, idna, certifi, typing-extensions)
    to develop; no runtime pins move.

  2. Add integration tests for inventory facts API endpoints — new module
    tests/integration/test_api_facts.py. Each test seeds the exact
    ansible_facts<host> key (UUID-based host) and deletes it in teardown.
    Covers every Scope item from the issue:

    • parsed facts returned with the correct count and from_cache flag;
    • a single fact value;
    • unknown fact → 404;
    • unknown host → 404 (both endpoints);
    • malformed JSON in Redis → 500.

Notes

  • Importing osism.api wires the event bridge to Redis at import time, so the
    import is deferred into the client fixture — fine in the integration env
    where Redis is up (and the suite is skipped without it).
  • The README "Running integration tests" overview sentence is shared by all
    Meta: Extend Celery/Redis integration tests (Tier 1 + Tier 2) #2400 siblings; it is intentionally left untouched here to avoid per-issue
    merge churn. The existing warning block already covers the per-run UUID keys.

Test plan

  • CI runs tests/integration with a live Redis (playbooks/test-integration.yml,
    OSISM_REQUIRE_REDIS=1). Per repo convention the tests run in CI, not locally.
  • Verified locally: pipenv verify (lock in sync) and flake8 on the new file.

Closes #2406


Implemented by planwerk-review f1c04d7 with Claude:claude-opus-4-8

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@berendt berendt requested a review from ideaship June 19, 2026 18:15
@ideaship ideaship self-requested a review June 22, 2026 15:05

@ideaship ideaship left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs a rebase.

@github-project-automation github-project-automation Bot moved this from Ready to In review in Human Board Jun 22, 2026
berendt added 2 commits June 22, 2026 17:11
The integration tests drive the FastAPI app through
fastapi.testclient.TestClient, which requires httpx as its transport.
Add it to [dev-packages] and re-lock so that pipenv install --dev
--deploy keeps verifying the lock in CI.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Christian Berendt <berendt@osism.tech>
Drive the read-only GET /v1/inventory/hosts/{host}/facts and
.../facts/{fact} endpoints through fastapi.testclient.TestClient
against the live Redis. The endpoints read the ansible_facts<host>
cache key directly, so each test seeds that exact key and removes it
in teardown.

Coverage: parsed facts with the correct count, a single fact value,
404 for an unknown fact, 404 for an unknown host on both endpoints,
and 500 for malformed JSON in the cache.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Christian Berendt <berendt@osism.tech>
@berendt

berendt commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

Rebase analysis: #2411

Rebased onto main
Analyzed by planwerk-review c7d1c16 with Claude

e5e890c Add httpx to dev dependencies for FastAPI TestClient

No adjustments needed — the upstream range does not invalidate this commit.

1845401 Add integration tests for inventory facts API endpoints

No adjustments needed — the upstream range does not invalidate this commit.

Summary

The rebase landed cleanly. The httpx commit (e5e890c) shares Pipfile/Pipfile.lock with the upstream paramiko v5 bump (4ff2168), but its pre-image Pipfile blob (b1dbd4e) is byte-identical to the post-paramiko Pipfile, so the lock _meta hash (feebbac3) is consistent with paramiko==5.0.0 + httpx==0.28.1 and pipenv --deploy verification still passes. The integration-tests commit (1845401) depends only on osism.utils.redis, osism.api.app, the unchanged facts endpoints (api.py:932/971), and the integration conftest — none of which the upstream localhost-exclusion change (5b34431, scoped to check_ansible_facts()) or the paramiko bump touches.

Important

Recommendation: Safe to push as-is. Neither upstream commit invalidates any assumption in the two rebased commits; no adjustments are required.


Rebase analysis generated by planwerk-review c7d1c16 rebase with Claude

@berendt berendt force-pushed the implement/issue-2406-api-facts-integration-test branch from cc41349 to 1845401 Compare June 22, 2026 15:13
@berendt berendt requested a review from ideaship June 22, 2026 15:14
@berendt berendt merged commit 480bb1b into main Jun 22, 2026
3 checks passed
@berendt berendt deleted the implement/issue-2406-api-facts-integration-test branch June 22, 2026 19:20
@github-project-automation github-project-automation Bot moved this from In review to Done in Human Board Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Integration test: API facts endpoints (FastAPI TestClient + Redis)

3 participants