feat: read-only RTC + PIS/COFINS assessment (capabilities, validators, applicability, legacy vs expanded coverage) with panel labels and docs

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-24 15:41:51 -03:00
co-authored by Claude Sonnet 5
parent e0ea842168
commit d897cceebb
8 changed files with 528 additions and 6 deletions
+19 -3
View File
@@ -30,7 +30,8 @@ sys.path.insert(0, str(AGENT_ROOT / "src"))
sys.path.insert(0, str(PROJECT_ROOT)) # ships central/app engine modules read-only (central.app.*)
from gti_fiscal_agent.client import HubClient # noqa: E402
from gti_fiscal_agent.firebird_reader import check_connection, read_products # noqa: E402
from gti_fiscal_agent.firebird_reader import _connect as _open_read_only, check_connection, read_products # noqa: E402
from gti_fiscal_agent.rtc_pis_cofins import assess_from_connection # noqa: E402
from gti_fiscal_agent.pipeline import run_pipeline # noqa: E402
from gti_fiscal_agent.runner import REFERENCE_SCHEMA_V1, product_fingerprint, to_hub_product # noqa: E402
from central.app.operational_state import classify_product_state, summarize_operational_states # noqa: E402
@@ -186,6 +187,18 @@ def open_write_connection(env, database_path, firebird_writes=True):
)
def _expanded_scope(env, legacy_states):
"""RTC + PIS/COFINS assessment (read-only, SELECT only). Isolated: a failure here never fails the job or changes legacy coverage."""
try:
connection = _open_read_only(env)
try:
return assess_from_connection(connection, legacy_states)
finally:
connection.close()
except Exception as error: # noqa: BLE001
return {"scope_version": "expanded-v1", "unavailable": type(error).__name__}
def execute_job(job, config, executor, state, env):
"""Run the pipeline for one claimed job. Never raises for job-domain
failures (bad Firebird read, classify error) — returns (result_summary, error)."""
@@ -225,7 +238,7 @@ def execute_job(job, config, executor, state, env):
if write_connection is not None:
write_connection.close()
operational = coverage = None
operational = coverage = expanded_scope = None
if sync_kind:
if cache:
for product, decision in zip(to_process, decisions):
@@ -234,11 +247,14 @@ def execute_job(job, config, executor, state, env):
all_decisions = [state.cached_decision(p["CODIGO"]) or {} for p in products]
else:
all_decisions = decisions
operational = summarize_operational_states([classify_product_state(p, d) for p, d in zip(products, all_decisions)])
product_states = [classify_product_state(p, d) for p, d in zip(products, all_decisions)]
operational = summarize_operational_states(product_states)
coverage = build_job_coverage(env, client, products, all_decisions)
expanded_scope = _expanded_scope(env, {s["product_code"]: s["state"] for s in product_states})
result_summary = {
"coverage": coverage,
"operational": operational,
"expanded_scope": expanded_scope,
"fiscal_mode": getattr(config, "fiscal_mode", None),
"release_version": env.get("AGENT_VERSION") or "1.1.7",
"products_total": len(products),