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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- **Unit tests no longer demand the test stack.** The live-API guard in
`tests/conftest.py` was session-wide (`autouse`), so even pure unit tests
— including the two files CI runs — errored out when the isolated test
stack wasn't up. The guard now applies only to tests that actually use
the API fixture; unit tests run with no stack, and integration tests
still fail fast with the start-the-stack instructions.

## [0.6.0] — 2026-06-12

### Added
Expand Down
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Integration tests that exercise the real HTTP API against a live PostgreSQL and,

The suite runs against an **isolated test stack** — its own API (port 8002) and its own throwaway Postgres (`braindb_test`, host port 5436). It never touches your personal BrainDB database; tearing the stack down wipes all test data.

Pure unit files (`test_split_chunks.py`, `test_wiki_sections.py`, `test_final_answer_rename.py`, `test_handoff_hooks.py`, `test_runhooks_countdown.py`) need **no stack at all** — only tests that talk to the API or database require the test stack to be up.

## Prerequisites

Start the test stack:
Expand Down
15 changes: 9 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ def _wait_for_health(url: str, timeout: int = 30) -> bool:
return False


@pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope="session")
def _require_live_api() -> None:
"""Fail fast and loud if the test stack isn't up.

Deliberately NOT defaulting to the personal stack on :8000 — the suite
must never run against a database holding real data.
Attached to the `api` fixture (NOT autouse) so pure unit tests — the
validator/handoff/chunking files that never touch HTTP — run with no
stack at all (that's also what CI runs). Deliberately NOT defaulting
to the personal stack on :8000 — the suite must never run against a
database holding real data.
"""
if not _wait_for_health(API_URL):
pytest.fail(
Expand All @@ -72,7 +75,7 @@ def _require_live_api() -> None:


@pytest.fixture
def api() -> str:
def api(_require_live_api: None) -> str:
"""Base URL for the API — tests append paths like f'{api}/api/v1/...'."""
return API_URL

Expand All @@ -86,15 +89,15 @@ def test_tag() -> str:


@pytest.fixture
def created_entities() -> Iterator[list[str]]:
def created_entities(api: str) -> Iterator[list[str]]:
"""Collector the test appends entity IDs to. Everything in it gets deleted
at teardown. Ignore 404s (already cleaned up).
"""
ids: list[str] = []
yield ids
for eid in ids:
try:
requests.delete(f"{API_URL}/api/v1/entities/{eid}", timeout=5)
requests.delete(f"{api}/api/v1/entities/{eid}", timeout=5)
except requests.RequestException:
pass

Expand Down
Loading