Coverage for node / src / stigmem_node / routes / cid_integrity.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-25 01:49 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-25 01:49 +0000
1"""HTTP read-path enforcement for content-addressed fact integrity."""
3from __future__ import annotations
5import logging
6from typing import Any
8from fastapi import HTTPException, status
10from ..cid import CidMismatchError, verify_cid_from_row
12logger = logging.getLogger("stigmem.cid")
15def enforce_read_path_cid(row: Any) -> None:
16 """Raise ``409 cid_mismatch`` when a stored CID no longer matches a fact row."""
17 try:
18 verify_cid_from_row(row)
19 except CidMismatchError as exc:
20 logger.warning(
21 "CID mismatch on read path for fact %s: computed=%s stored=%s",
22 exc.fact_id,
23 exc.computed_cid,
24 exc.stored_cid,
25 )
26 raise HTTPException(
27 status_code=status.HTTP_409_CONFLICT,
28 detail={
29 "code": "cid_mismatch",
30 "message": "stored CID does not match the fact canonical body",
31 "fact_id": exc.fact_id,
32 "computed_cid": exc.computed_cid,
33 "stored_cid": exc.stored_cid,
34 },
35 ) from exc