Invariants¶
invariants — programmatic enforcement of G6's 14 structural invariants.
Cluster: Uncategorised | Type: component | MCP Tools: None
Overview¶
Programmatic enforcement of G6's 14 structural invariant categories. Provides decorator-based compliance marking, automated tier eligibility checking, and a pytest plugin for CI integration. Components are classified into tiers T0-T3 based on which invariant categories they satisfy.
When to use:
- Mark component compliance claims with decorators (@security_checked, @functionally_tested, etc.)
- Run compliance checks in CI via
python -m pytest --invariants-only --min-tier T1 - Generate compliance reports for audit:
python -m pytest --invariants-only --report compliance.json - Check tier eligibility before deployment decisions
Works well with: All components (every component is subject to invariant checking), pytest, CI pipelines
Public API¶
InvariantCategory(str, Enum)¶
The 14 invariant categories that enforce structural integrity across G6.
CategoryMeta(NamedTuple)¶
Metadata for an invariant category.
Tier(str, Enum)¶
InvariantStatus(NamedTuple)¶
Status of a single invariant category for a component.
ComplianceReport(NamedTuple)¶
Full compliance report for a component class.
Methods:
to_dict() -> dict[str, Any]¶
InvariantsInput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | str | required |
parameters | dict[str, Any] | Field(default_factory=dict) |
InvariantsOutput(BaseModel)¶
| Field | Type | Default |
|---|---|---|
op | str | '' |
result | dict[str, Any] | Field(default_factory=dict) |
message | str | '' |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated'] | 'qualified-draft' |
warning_card | dict[str, Any] \| None | None |
evidence | dict[str, Any] | Field(default_factory=dict) |
request_id | str \| None | None |
task_id | str \| None | None |
run_id | str \| None | None |
InvariantsBlock(AIBlock)¶
AIBlock wrapper for the G6 invariants enforcement subsystem.
Methods:
infer(input: InvariantsInput) -> Result[InvariantsOutput]¶
VerificationState(str, Enum)¶
VerificationDetail(NamedTuple)¶
VerificationResult(NamedTuple)¶
Methods:
passed() -> bool¶
CategoryVerifier(Protocol)¶
Methods:
verify(cls: type, evidence: dict[str, Any] | None = None) -> VerificationResult¶
Functions¶
max_tier(satisfied: frozenset[InvariantCategory]) -> Tier¶
Return the highest tier a component qualifies for given its satisfied invariants.
tier_gap(target: Tier, satisfied: frozenset[InvariantCategory]) -> frozenset[InvariantCategory]¶
Return the invariant categories missing to reach the target tier.
check_compliance(cls: type, verify: bool = False) -> ComplianceReport¶
Inspect a class for invariant markers and produce a compliance report.
check_tier_eligible(cls: type, target: Tier) -> tuple[bool, frozenset[InvariantCategory]]¶
Check if a class meets the requirements for a target tier.
blocking_violations(cls: type) -> list[InvariantCategory]¶
Return blocking invariant categories that are NOT satisfied and NOT overridden.
get_invariants(cls: type) -> dict[InvariantCategory, str]¶
Return the invariant compliance claims on a class.
get_satisfied(cls: type) -> frozenset[InvariantCategory]¶
Return the set of satisfied invariant categories for a class.
get_evidence(cls: type) -> dict[InvariantCategory, dict[str, Any]]¶
Return any verification evidence attached to a class.
invariant_override(category: InvariantCategory, justification: str)¶
Suppress a dev-time invariant warning. Logged, does NOT suppress deploy-time checks.
get_overrides(cls: type) -> dict[InvariantCategory, str]¶
Return any invariant overrides declared on a class.
security_checked(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Security invariant.
algorithm_verified(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Algorithmic Correctness invariant.
recoverable(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Backup & Recovery invariant.
financial_audited(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Financial invariant.
functionally_tested(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Functional Correctness invariant.
uat_ready(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the User Acceptance Testing invariant.
infra_safe(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Infrastructure Safety invariant.
safety_gated(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Safety invariant.
ip_clean(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Intellectual Property invariant.
privacy_compliant(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Privacy invariant.
sim_only(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Physical AI invariant.
deployable(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the CI/CD Readiness invariant.
depth_documented(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Depth Documentation invariant.
extensible(reason: str = '', evidence: dict[str, Any] | None = None)¶
Mark a component as satisfying the Extensibility invariant.