feat: add repository mesh reconciliation round
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Iterable
|
||||
|
||||
from .governance_models import EcosystemGovernancePortfolio, PlatformGovernanceCard, GovernanceCheckResult
|
||||
from .human_readiness_registry import ReadinessRegistry, ReadinessRegistryEntry
|
||||
from .mcp_contract import McpContractCoverage, McpContractReport
|
||||
from .models import as_plain_data, utc_now
|
||||
from .round_assurance import AssuranceSuite, AssuranceCase
|
||||
from .runtime_budget import RoundLineBudget, RepositoryLineBudget
|
||||
@@ -116,6 +117,25 @@ CREATE TABLE IF NOT EXISTS line_budgets (
|
||||
payload_json TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS mcp_contracts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
contract_id TEXT UNIQUE NOT NULL,
|
||||
kind TEXT NOT NULL,
|
||||
platform_id TEXT NOT NULL,
|
||||
profile_id TEXT NOT NULL,
|
||||
tool_id TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
truth_state TEXT NOT NULL,
|
||||
score INTEGER NOT NULL,
|
||||
same_source INTEGER NOT NULL,
|
||||
source_payload_hash TEXT NOT NULL,
|
||||
source_records_hash TEXT NOT NULL,
|
||||
blocker_count INTEGER NOT NULL,
|
||||
next_action TEXT NOT NULL,
|
||||
payload_json TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
"""
|
||||
|
||||
|
||||
@@ -335,6 +355,50 @@ def upsert_line_budget(conn: sqlite3.Connection, repo: RepositoryLineBudget, now
|
||||
)
|
||||
|
||||
|
||||
def upsert_mcp_contract(conn: sqlite3.Connection, coverage: McpContractCoverage, now: str) -> None:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO mcp_contracts (
|
||||
contract_id, kind, platform_id, profile_id, tool_id, status, truth_state,
|
||||
score, same_source, source_payload_hash, source_records_hash, blocker_count,
|
||||
next_action, payload_json, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(contract_id) DO UPDATE SET
|
||||
kind=excluded.kind,
|
||||
platform_id=excluded.platform_id,
|
||||
profile_id=excluded.profile_id,
|
||||
tool_id=excluded.tool_id,
|
||||
status=excluded.status,
|
||||
truth_state=excluded.truth_state,
|
||||
score=excluded.score,
|
||||
same_source=excluded.same_source,
|
||||
source_payload_hash=excluded.source_payload_hash,
|
||||
source_records_hash=excluded.source_records_hash,
|
||||
blocker_count=excluded.blocker_count,
|
||||
next_action=excluded.next_action,
|
||||
payload_json=excluded.payload_json,
|
||||
updated_at=excluded.updated_at
|
||||
""",
|
||||
(
|
||||
coverage.contract_id,
|
||||
coverage.kind.value,
|
||||
coverage.platform_id,
|
||||
coverage.profile_id,
|
||||
coverage.tool_id,
|
||||
coverage.status.value,
|
||||
coverage.truth_state.value,
|
||||
coverage.score,
|
||||
1 if coverage.same_source else 0,
|
||||
coverage.source_payload_hash,
|
||||
coverage.source_records_hash,
|
||||
len(coverage.blockers),
|
||||
coverage.next_action,
|
||||
payload(coverage),
|
||||
now,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def write_governance_semantic_state(
|
||||
sqlite_path: Path,
|
||||
portfolio: EcosystemGovernancePortfolio,
|
||||
@@ -344,6 +408,7 @@ def write_governance_semantic_state(
|
||||
assurance: AssuranceSuite | None = None,
|
||||
lifecycle: RoundExecutionPackage | None = None,
|
||||
budget: RoundLineBudget | None = None,
|
||||
mcp_contract_report: McpContractReport | None = None,
|
||||
) -> None:
|
||||
sqlite_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
now = utc_now()
|
||||
@@ -368,6 +433,9 @@ def write_governance_semantic_state(
|
||||
if budget is not None:
|
||||
for repo in budget.repositories:
|
||||
upsert_line_budget(conn, repo, now)
|
||||
if mcp_contract_report is not None:
|
||||
for coverage in mcp_contract_report.coverage:
|
||||
upsert_mcp_contract(conn, coverage, now)
|
||||
conn.commit()
|
||||
|
||||
|
||||
@@ -381,6 +449,7 @@ def governance_table_counts(sqlite_path: Path) -> dict[str, int]:
|
||||
"assurance_cases",
|
||||
"lifecycle_decisions",
|
||||
"line_budgets",
|
||||
"mcp_contracts",
|
||||
)
|
||||
if not sqlite_path.exists():
|
||||
return {table: 0 for table in tables}
|
||||
|
||||
Reference in New Issue
Block a user