personal memory agent
1# SPDX-License-Identifier: AGPL-3.0-only
2# Copyright (c) 2026 sol pbc
3
4"""Verify API baselines match checked-in fixture responses."""
5
6from __future__ import annotations
7
8import json
9from pathlib import Path
10
11import pytest
12
13from convey import create_app
14from tests.verify_api import ENDPOINTS, baseline_path, fetch_endpoint, normalize
15
16
17@pytest.fixture(scope="module")
18def client():
19 journal = str(Path(__file__).resolve().parent / "fixtures" / "journal")
20 app = create_app(journal)
21 app.config["TESTING"] = True
22 return app.test_client()
23
24
25@pytest.fixture(scope="module")
26def journal_path():
27 return str(Path(__file__).resolve().parent / "fixtures" / "journal")
28
29
30@pytest.mark.parametrize(
31 "endpoint", ENDPOINTS, ids=[endpoint["name"] for endpoint in ENDPOINTS]
32)
33def test_api_baseline(client, journal_path, endpoint):
34 """Verify endpoint response matches stored baseline."""
35 if endpoint.get("sandbox_only"):
36 pytest.skip("sandbox-only baseline (differs in Flask test client)")
37 path = baseline_path(endpoint)
38 if not path.exists():
39 pytest.skip(f"No baseline file: {path}")
40
41 status, payload = fetch_endpoint(client, endpoint)
42 assert status == endpoint["status"], (
43 f"Expected status {endpoint['status']}, got {status}"
44 )
45
46 actual = normalize(payload, journal_path)
47 expected = json.loads(path.read_text())
48
49 assert actual == expected, (
50 f"Baseline mismatch for {endpoint['app']}/{endpoint['name']}. "
51 "Run 'make update-api-baselines' to update."
52 )