oc_chat
Loading...
Searching...
No Matches
check_registry_invariants Namespace Reference

Classes

class  _ForbiddenSqlVisitor

Functions

int main (list[str]|None argv=None)
list[dict[str, object]] scan_path (Path path)
list[dict[str, object]] _scan_file (Path path)
bool _is_allowlisted (Path path)
str _format_report (list[dict[str, object]] violations)
bool _is_docstring_expr (ast.stmt node)

Variables

tuple FORBIDDEN_SQL_LITERALS
str SQL_OWNER_ALLOWLIST = "oc_chat/registry/backends/sqlite.py"

Detailed Description

AST guard for registry write-invariant SQL ownership.

Purpose
-------
Fail CI when direct operation-log or lock writes appear outside the
SQLite registry backend.

Responsibilities
----------------
- Walk Python files below `oc_chat/` by default.
- Parse files with `ast` and inspect string literals only.
- Ignore comments and module/class/function docstrings.
- Allow the sanctioned SQL owner, `oc_chat/registry/backends/sqlite.py`.

Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
    L2 - lifecycle events
    L3 - semantic details
    L4 - deep tracing

Contracts
---------
- Exit 0 on a clean tree and 1 when violations are found.
- JSON mode returns `{"ok": bool, "violations": [...]}`.

Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)
- ast (Python AST parsing)
- pathlib (filesystem path walking)
- argparse (CLI argument parsing)
- json (JSON report formatting)

Function Documentation

◆ _format_report()

str check_registry_invariants._format_report ( list[dict[str, object]] violations)
protected

Definition at line 121 of file check_registry_invariants.py.

Here is the caller graph for this function:

◆ _is_allowlisted()

bool check_registry_invariants._is_allowlisted ( Path path)
protected

Definition at line 117 of file check_registry_invariants.py.

Here is the caller graph for this function:

◆ _is_docstring_expr()

bool check_registry_invariants._is_docstring_expr ( ast.stmt node)
protected

Definition at line 171 of file check_registry_invariants.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _scan_file()

list[dict[str, object]] check_registry_invariants._scan_file ( Path path)
protected

Definition at line 100 of file check_registry_invariants.py.

Here is the caller graph for this function:

◆ main()

int check_registry_invariants.main ( list[str] | None argv = None)

Definition at line 64 of file check_registry_invariants.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scan_path()

list[dict[str, object]] check_registry_invariants.scan_path ( Path path)
Return all forbidden SQL string-literal violations below `path`.

Definition at line 88 of file check_registry_invariants.py.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ FORBIDDEN_SQL_LITERALS

tuple check_registry_invariants.FORBIDDEN_SQL_LITERALS
Initial value:
1= (
2 "INSERT INTO operation_log",
3 "INSERT INTO locks",
4 "UPDATE locks",
5 "DELETE FROM locks",
6)

Definition at line 55 of file check_registry_invariants.py.

◆ SQL_OWNER_ALLOWLIST

str check_registry_invariants.SQL_OWNER_ALLOWLIST = "oc_chat/registry/backends/sqlite.py"

Definition at line 61 of file check_registry_invariants.py.