91 conn: sqlite3.Connection,
94 logical_state_hash: str,
95 store_scope: str = _AUTHORED_PROJECTION,
96 derive_rule_set_hash: Optional[str] =
None,
97 constraint_inventory_hash: Optional[str] =
None,
98 status: str = _PASSED,
100 """Write the single-row verification stamp into the temp DB (pre-swap)."""
101 conn.execute(_CREATE_STAMP)
102 conn.execute(f
"DELETE FROM {STAMP_TABLE}")
104 f
"INSERT INTO {STAMP_TABLE}(id, store_scope, source_hash, logical_state_hash, "
105 "derive_rule_set_hash, constraint_inventory_hash, verified_at_step, "
106 "verification_schema_version, verification_status) VALUES(1,?,?,?,?,?,?,?,?)",
107 (store_scope, source_hash, logical_state_hash, derive_rule_set_hash,
108 constraint_inventory_hash,
"step-7", VERIFICATION_SCHEMA_VERSION, status),
139def stamp_hashes(conn: sqlite3.Connection) -> Optional[tuple[str, str]]:
140 """Return the stamped ``(source_hash, logical_state_hash)``, fail-closed for
141 an authored projection (Plan 142i R2(a), §5.4 [R9] closure).
143 - An ``authored_projection`` store MUST carry a
144 ``verification_status='passed'`` stamp: a missing stamp OR a non-``passed``
145 status (N-c) raises ``REGEN_UNVERIFIED_PROJECTION`` — the header's hashes
146 are never emitted from an unverified authored projection.
147 - Any other store (a legacy ``live_store`` / pre-v0.3.2 DB — the deliberate
148 F7 pass-through) returns the stamp values if a stamp exists, else ``None``
149 so the caller applies its deterministic fallback (never gated).
151 This is defence-in-depth for direct / future callers: the render open path
152 already raises at open time via ``assert_verified_projection`` for a
153 stampless authored projection (G5), so through ``open_verified`` the raise
154 never fires — the fail-closed unit test calls this on a raw connection.
159 f
"SELECT source_hash, logical_state_hash, verification_status "
160 f
"FROM {STAMP_TABLE} WHERE id = 1"
162 except sqlite3.OperationalError:
164 if scope == _AUTHORED_PROJECTION:
165 if row
is None or str(row[2]) != _PASSED:
167 "authored projection stamp is missing or not 'passed' — "
168 "refusing to emit unverified header hashes",
169 code=REGEN_UNVERIFIED_PROJECTION,
170 hint=
"run 'regenerate' to build + verify before reading",
172 return str(row[0]), str(row[1])
174 return str(row[0]), str(row[1])
None write_verification_stamp(sqlite3.Connection conn, *, str source_hash, str logical_state_hash, str store_scope=_AUTHORED_PROJECTION, Optional[str] derive_rule_set_hash=None, Optional[str] constraint_inventory_hash=None, str status=_PASSED)