Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
feat(phase-10): connector runtime-contract conformance suite + published matrix (#435)
Beenu Arora022d5d5cd06a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bf899e9a9..4b1e889d1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Added+- **Phase 10 — connector runtime-contract conformance suite + published matrix.** The reality audit left the "live Test connection" click-and-connect claim with **NO gate at all**, and the schema/vault claim only partially gated. New `scripts/connector_conformance.py` + `services/connectors/tests/test_conformance.py` gate the runtime contract across **all 69 connectors**: every connector must implement `test_connection` as an async coroutine (the contract behind the "live Test connection" button), implement `fetch_alerts` as an async coroutine, declare only valid `Capability` verbs, and **mark every secret-shaped field `type="secret"`** — a field named `api_key`/`token`/`password` rendered as a plain `string` would be stored outside the vault, the exact leak this check prevents. The published `docs/connectors/conformance-matrix.md` (69/69 conform) is drift-gated by `--check`, so a new connector cannot land without conforming and the matrix can't diverge from the registry. Claim-to-gate matrix: "Connectors: live Test connection" NO GATE → PARTIAL, and the **ratchet ceiling lowered 3 → 2** (14 GATED / 11 PARTIAL / 2 NO GATE). Detection-content lifecycle is already gated by Phase 4a (DAC candidate-rule) + 4b (truth table). Live-vendor sandbox smoke + rate-limit/checkpoint durability are tracked as 10b in `docs/audit/PROGRESS.md`.- **Phase 9a — autonomy-safety policy + honest rollback contract + scorecard.** The reality audit found three holes behind "L0-L4 automation maturity gates every action": dry-run was opt-in (a mis-configured caller executes for real), ~15 executor `rollback()`s silently `return True` with no reverse vendor call (the platform claimed to reverse containment it never did), and there was no post-action verification. New `services/actions/app/services/autonomy_safety.py` closes them at the policy layer: `decide()` makes **dry-run the safe default** — anything not explicitly permitted to auto-execute is previewed (`DRY_RUN`), never silently executed; CRITICAL blast never auto-executes; HIGH only at L4 with a whitelist entry AND the `AISOC_ALLOW_HIGH_BLAST_AUTO` break-glass flag. `rollback_capability()` with a **pinned `REVERSIBLE_ACTIONS={block_ip}`** set makes the rollback claim honest and bounded — a caller learns "this cannot be auto-reversed" instead of a silent `True`, and the set can't grow without a conscious edit + real reverse implementation. Every unattended containment (`AUTO`, blast ≥ MEDIUM) sets `requires_verification`, and `AutonomyScorecard` counts executions that were never verified — and executions of irreversible actions — as **visible gaps** rather than assumed-away. 16 tests (`services/actions/tests/test_autonomy_safety.py`, in the actions coverage matrix). Enforcement-wiring of `decide()` into the live `/dispatch` + `submit_action` router, rewriting the silent-`return True` executor rollbacks, real vendor verifiers, and a durable approval-SLA timer table (replacing the in-memory `approval_timeout.py`) are tracked as 9b in `docs/audit/PROGRESS.md`.- **Phase 8 — LLMOps: prompt registry, model pins, response cache, structured-output validation.** A coherent `services/agents/app/llm/` LLMOps layer, all dependency-light and gated. (1) **Prompt registry** (`prompt_registry.py`) — every production prompt is a named, versioned, sha256-hashed artifact; the committed `prompts.lock.json` pins version→hash, and `scripts/check_prompt_lock.py --check` (wired into the CI lint job) fails when a prompt's text changes without a version bump + lock regeneration. This makes the `AGENTS.md` "prompt change ⇒ re-grade the eval harness" rule *enforceable* — you can no longer edit a prompt silently. (2) **Model pins + provider fallback** (`model_pins.py`) — logical roles pinned to concrete models with ordered fallback chains that ALWAYS terminate in the deterministic tier (env-overridable primaries, but the deterministic floor is gate-enforced), replacing the scattered `os.getenv("...", "gpt-4o-mini")` defaults. (3) **Content-addressed response cache** (`response_cache.py`) — keyed on sha256(model+prompt+input) with field separation and LRU eviction; safe under the determinism contract (a hit is byte-identical). (4) **Fail-closed structured-output validation** (`structured_output.py`) — strips code fences/prose, parses JSON, validates against a caller schema, and on ANY failure returns a deterministic fallback rather than propagating a half-parsed object into an autonomy decision. 15 tests (`services/agents/tests/test_llm_ops.py`, appended to the CI agents gate). Migration of the inline agent prompts to `registry.get()` is tracked as 8b. Doc: `apps/docs/docs/concepts/llmops.md`.- **Phase 7a — unified multi-model router with tier attribution + a determinism contract.** The reality audit confirmed the knowledge graph is already built at ingest (v8 T1.1, `services/ingest/internal/graph/`); the genuine Phase 7 delta was the *model router*. Before it, the deterministic→LLM fallback was reimplemented independently in NL query, playbook drafting, explain, copilot, and each sub-agent — no single audit point for which model answered or why. New `services/agents/app/routing/model_router.py` is that place: a `ModelRouter` that escalates deterministic → ML → LLM only when the cheaper tier is under-confident, and attributes every decision (`tier`, `model_used`, `attribution` trail, `tiers_considered`, `escalation_blocked_reason`). It **never silently uses the LLM** — a skipped or blocked LLM tier (no key, air-gap, deterministic mode, governor circuit open, or a tier error) is always recorded. Introduces the canonical **`AISOC_DETERMINISTIC`** flag and composes with the existing `CostGovernor` circuit breaker: either one forces deterministic-only, in which case the router is reproducible (same input → identical decision). 12 tests (`services/agents/tests/test_model_router.py`, appended to the CI agents gate) prove tier selection, attribution, the no-silent-LLM property, graceful LLM-failure degradation, and the determinism contract. Doc: `apps/docs/docs/concepts/model-router.md`. Remaining Phase 7 enrichments (posture collection, effective-permissions snapshot loader, bi-temporal validity, fusion-time ContextBundle) are tracked as 7b+ in `docs/audit/PROGRESS.md`.diff --git a/ROADMAP.md b/ROADMAP.mdindex cd89354f7..46e500a10 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -32,7 +32,7 @@ A proof-first, security-first program to make every README claim gate-backed, cl- [x] Phase 7 — Ingest-time graph + multi-model router — **graph-at-ingest already shipped** (v8 T1.1, `services/ingest/internal/graph/`); **7a landed**: unified deterministic→ML→LLM router with tier attribution + the `AISOC_DETERMINISTIC` determinism contract (`services/agents/app/routing/model_router.py`, gated). 7b+ (posture collection, effective-permissions snapshot loader, bi-temporal valid_from/valid_to, fusion-time ContextBundle) tracked in `docs/audit/PROGRESS.md`- [x] Phase 8 — LLMOps (version+hash-pinned prompt registry with a CI drift gate; model pins + deterministic-terminated provider-fallback chains; content-addressed response cache; fail-closed structured-output validation)- [x] Phase 9 — Autonomy safety (dry-run-by-default policy, honest bounded rollback-capability contract replacing silent `return True`, mandatory post-action verification for unattended containment, break-glass HIGH-blast flag, autonomy scorecard — all gated at the policy layer; live-router wiring + durable approval-SLA timer table tracked as 9b)-- [ ] Phase 10 — Connector + content quality (conformance suite, published matrix, detection lifecycle)+- [x] Phase 10 — Connector + content quality (runtime-contract conformance suite across all 69 connectors — gates the "live Test connection" capability that had NO gate + secret-field-marking; published `conformance-matrix.md` with a drift gate; detection lifecycle already gated by Phase 4a DAC + Phase 4b truth table. Live-vendor sandbox smoke + rate-limit/checkpoint durability tracked as 10b)- [ ] Phase 11 — API / SDK / release engineering (oasdiff, SDK contract drift, versioning, release discipline)- [ ] Phase 12 — Observability + governance (SLOs, single trace, GOVERNANCE.md, DCO, committers, neutral home, trust docs)diff --git a/docs/audit/CLAIM_TO_GATE_MATRIX.md b/docs/audit/CLAIM_TO_GATE_MATRIX.mdindex 814cae6e0..d713765ca 100644--- a/docs/audit/CLAIM_TO_GATE_MATRIX.md+++ b/docs/audit/CLAIM_TO_GATE_MATRIX.md@@ -11,8 +11,8 @@ Statuses: `GATED` (a CI job fails when the claim stops being true) · `PARTIAL`| Offline sandbox demo runs with no key/network in < 5 s | README L38 | `readme-gates.yml :: sandbox-offline` (ubuntu+macos matrix) | GATED | - || `pnpm aisoc:demo` boots the real stack | README L40, L45 | `compose-smoke.yml`, `compose-smoke-nightly.yml` (cold) | PARTIAL (health-probe only, no time-to-first-investigation assertion) | Phase 3.4 || 69 connectors | README L116, L168 | `ci.yml :: python-lint` (`generate_connector_count.py --check`) | GATED (count) | - |-| Connectors: schema-driven config + vault-encrypted secrets | README L168 | `ci.yml :: python-services-test` (`test_schemas.py`); vault tests | PARTIAL (schema + vault gated; live API conformance, rate-limit, checkpoint durability ungated) | Phase 10 |-| Connectors: live Test connection | README L168 | none | NO GATE | Phase 10 |+| Connectors: schema-driven config + vault-encrypted secrets | README L168 | `ci.yml` connectors matrix (`test_schemas.py` + `test_conformance.py` — secret-shaped fields must be `type=secret`); vault tests | PARTIAL (schema + vault + secret-field-marking + runtime-contract conformance gated; live-vendor API smoke, rate-limit, checkpoint durability deferred) | Phase 10b |+| Connectors: live Test connection | README L168 | `ci.yml` connectors matrix (`test_conformance.py` — every connector implements the async `test_connection` contract) + `connector_conformance.py --check` published matrix | PARTIAL (contract conformance gated; live-vendor sandbox smoke deferred) | Phase 10b || Investigation Ledger stores every step | README L61, L169 | `ci.yml :: api tests` (`audit_hash`, audit immutability) | PARTIAL (write path gated; UI replay only in hermetic e2e) | Phase 3.2 || Public eval harness gates every PR | README L62, L77 | `ci.yml :: p1-eval` | GATED (but suites are self-consistency; see reality report) | Phase 4 || Alert-reduction is a real measurement | README L62 | `ci.yml :: p1-eval` (`alert_reduction`) | PARTIAL (gates an in-test fusion re-impl, not `services/fusion`) | Phase 4 |@@ -39,8 +39,8 @@ Statuses: `GATED` (a CI job fails when the claim stops being true) · `PARTIAL`## Summary- GATED: 14-- PARTIAL: 10-- NO GATE: 3 (Phase 2 moved insecure-defaults-hard-fail to GATED and secret/IaC/container scanning to PARTIAL; the Phase 2 continuation moved signed/attested releases to GATED; Phase 3.4 moved cross-store isolation to GATED via the live-container replay; Phase 4 moved the DAC candidate-rule gate and the imported-count honesty gate to GATED; remaining NO GATE close in Phases 4-continuation/10/11)+- PARTIAL: 11+- NO GATE: 2 (Phase 2 moved insecure-defaults-hard-fail to GATED and secret/IaC/container scanning to PARTIAL; the Phase 2 continuation moved signed/attested releases to GATED; Phase 3.4 moved cross-store isolation to GATED via the live-container replay; Phase 4 moved the DAC candidate-rule gate and the imported-count honesty gate to GATED; Phase 10 moved connector "live Test connection" NO GATE → PARTIAL via the conformance contract; remaining NO GATE — wet-eval live tables (Phase 4c) and OpenAPI breaking-change semantics (Phase 11) — close next)The ratchet is enforced by `scripts/check_claim_gate_matrix.py` (wired into `security.yml`): the NO GATE count may only decrease.diff --git a/docs/connectors/conformance-matrix.md b/docs/connectors/conformance-matrix.mdnew file mode 100644index 000000000..66daf7e29--- /dev/null+++ b/docs/connectors/conformance-matrix.md@@ -0,0 +1,82 @@+# Connector conformance matrix++> Generated by `scripts/connector_conformance.py`; gated by `--check` in the+> connectors test suite. **Do not edit by hand.** Every connector must+> implement the runtime contract (`test_connection` + `fetch_alerts` as+> async coroutines, valid capabilities, secret fields marked `secret`).+> Live-vendor sandbox smoke is a separate wave; this gates the contract.++**69 / 69 connectors conform** to the runtime contract.++| connector | category | fields | secrets | caps | test_connection | fetch_alerts | normalize |+|-----------|----------|-------:|--------:|-----:|:---------------:|:------------:|:---------:|+| abnormal_security | saas | 2 | 1 | 3 | ✅ | ✅ | ✅ |+| auditd | edr | 3 | 0 | 2 | ✅ | ✅ | ✅ |+| auth0 | iam | 3 | 1 | 3 | ✅ | ✅ | ✅ |+| aws_cloudtrail | cloud | 4 | 1 | 1 | ✅ | ✅ | ✅ |+| aws_guardduty | cloud | 3 | 1 | 1 | ✅ | ✅ | ✅ |+| aws_security_hub | cloud | 3 | 1 | 3 | ✅ | ✅ | ✅ |+| aws_vpc_flow | cloud | 6 | 1 | 2 | ✅ | ✅ | ✅ |+| azure_activity | cloud | 4 | 1 | 1 | ✅ | ✅ | ✅ |+| azure_defender | edr | 3 | 1 | 5 | ✅ | ✅ | ✅ |+| azure_entra | iam | 3 | 1 | 2 | ✅ | ✅ | ✅ |+| box | saas | 1 | 1 | 3 | ✅ | ✅ | ✅ |+| carbon_black | edr | 4 | 1 | 6 | ✅ | ✅ | ✅ |+| chronicle | siem | 4 | 1 | 5 | ✅ | ✅ | ✅ |+| cisco_umbrella | network | 3 | 2 | 5 | ✅ | ✅ | ✅ |+| cloudflare | saas | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| cloudflare_zt | network | 4 | 1 | 3 | ✅ | ✅ | ✅ |+| confluence_audit | saas | 3 | 1 | 2 | ✅ | ✅ | ✅ |+| cortex_xdr | edr | 3 | 2 | 1 | ✅ | ✅ | ✅ |+| cortex_xsiam | siem | 3 | 2 | 5 | ✅ | ✅ | ✅ |+| crowdstrike | edr | 3 | 1 | 6 | ✅ | ✅ | ✅ |+| datadog | siem | 5 | 2 | 4 | ✅ | ✅ | ✅ |+| datadog_cloud_siem | siem | 3 | 2 | 5 | ✅ | ✅ | ✅ |+| dropbox | saas | 1 | 1 | 3 | ✅ | ✅ | ✅ |+| duo_security | iam | 3 | 1 | 1 | ✅ | ✅ | ✅ |+| elastic | siem | 6 | 2 | 5 | ✅ | ✅ | ✅ |+| email_inbox | saas | 7 | 1 | 1 | ✅ | ✅ | ✅ |+| falco | siem | 3 | 1 | 2 | ✅ | ✅ | ✅ |+| fleetdm | edr | 4 | 1 | 4 | ✅ | ✅ | ✅ |+| gcp_cloud_audit | cloud | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| gcp_scc | cloud | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| github | vcs | 2 | 1 | 2 | ✅ | ✅ | ✅ |+| gitlab | vcs | 3 | 1 | 2 | ✅ | ✅ | ✅ |+| google_workspace | saas | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| jira | saas | 3 | 1 | 3 | ✅ | ✅ | ✅ |+| kubernetes_audit | cloud | 5 | 1 | 2 | ✅ | ✅ | ✅ |+| lacework | cloud | 4 | 1 | 5 | ✅ | ✅ | ✅ |+| m365_audit | saas | 3 | 1 | 1 | ✅ | ✅ | ✅ |+| microsoft_sentinel | siem | 6 | 1 | 2 | ✅ | ✅ | ✅ |+| mimecast | saas | 3 | 1 | 4 | ✅ | ✅ | ✅ |+| oci | cloud | 6 | 1 | 3 | ✅ | ✅ | ✅ |+| okta | iam | 2 | 1 | 6 | ✅ | ✅ | ✅ |+| onepassword | iam | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| opsgenie | saas | 2 | 1 | 3 | ✅ | ✅ | ✅ |+| orca | cloud | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| osctrl | edr | 4 | 1 | 4 | ✅ | ✅ | ✅ |+| pagerduty | saas | 2 | 1 | 3 | ✅ | ✅ | ✅ |+| prisma_cloud | cloud | 4 | 1 | 1 | ✅ | ✅ | ✅ |+| proofpoint | saas | 2 | 1 | 1 | ✅ | ✅ | ✅ |+| rapid7_insightidr | siem | 2 | 1 | 4 | ✅ | ✅ | ✅ |+| salesforce | saas | 4 | 2 | 4 | ✅ | ✅ | ✅ |+| sentinelone | edr | 3 | 1 | 1 | ✅ | ✅ | ✅ |+| servicenow | saas | 3 | 1 | 3 | ✅ | ✅ | ✅ |+| slack_audit | saas | 1 | 1 | 3 | ✅ | ✅ | ✅ |+| snowflake | saas | 5 | 1 | 4 | ✅ | ✅ | ✅ |+| snyk | vcs | 3 | 1 | 1 | ✅ | ✅ | ✅ |+| splunk | siem | 4 | 1 | 4 | ✅ | ✅ | ✅ |+| sublime_security | saas | 2 | 1 | 3 | ✅ | ✅ | ✅ |+| sumo_logic | siem | 3 | 1 | 4 | ✅ | ✅ | ✅ |+| sysdig | siem | 2 | 1 | 4 | ✅ | ✅ | ✅ |+| tailscale | network | 4 | 2 | 1 | ✅ | ✅ | ✅ |+| tenable_io | cloud | 2 | 1 | 5 | ✅ | ✅ | ✅ |+| tines | saas | 3 | 1 | 3 | ✅ | ✅ | ✅ |+| torq | saas | 3 | 1 | 3 | ✅ | ✅ | ✅ |+| trellix_helix | siem | 3 | 1 | 4 | ✅ | ✅ | ✅ |+| trend_vision_one | edr | 2 | 1 | 5 | ✅ | ✅ | ✅ |+| vault | iam | 4 | 1 | 2 | ✅ | ✅ | ✅ |+| wazuh | siem | 6 | 1 | 4 | ✅ | ✅ | ✅ |+| wiz | cloud | 4 | 1 | 1 | ✅ | ✅ | ✅ |+| zscaler | network | 4 | 2 | 1 | ✅ | ✅ | ✅ |+diff --git a/scripts/check_claim_gate_matrix.py b/scripts/check_claim_gate_matrix.pyindex d7ad5e778..a8fbdbeb9 100644--- a/scripts/check_claim_gate_matrix.py+++ b/scripts/check_claim_gate_matrix.py@@ -26,9 +26,10 @@ MATRIX = ROOT / "docs" / "audit" / "CLAIM_TO_GATE_MATRIX.md"# Ratchet baseline: the number of NO GATE rows allowed. Lower this as phases# close gaps; never raise it. Phase 1 closed injection / non-Postgres isolation-# / no-exfiltration; Phase 2 closed insecure-defaults + secret/IaC scanning.-# Remaining NO GATE rows close in Phases 4 / 10 / 11.-MAX_NO_GATE = 3+# / no-exfiltration; Phase 2 closed insecure-defaults + secret/IaC scanning;+# Phase 10 moved connector "live Test connection" off NO GATE. Remaining NO GATE+# rows (wet-eval live tables, OpenAPI breaking-change) close in Phases 4c / 11.+MAX_NO_GATE = 2def _parse_status_rows(text: str) -> list[str]:diff --git a/scripts/connector_conformance.py b/scripts/connector_conformance.pynew file mode 100644index 000000000..78e302113--- /dev/null+++ b/scripts/connector_conformance.py@@ -0,0 +1,129 @@+#!/usr/bin/env python3+"""Connector conformance matrix (Phase 10 — connector + content quality).++The reality audit left two connector claims under-gated: "live Test connection"+had NO gate at all, and the schema/vault claim was PARTIAL (live API+conformance ungated). This script walks the connector registry and, for every+registered connector, records whether it conforms to the runtime contract:++* implements `test_connection` as an async coroutine (the *contract* behind the+ "live Test connection" click-and-connect claim),+* implements `fetch_alerts` as an async coroutine,+* declares a well-formed schema with every secret field marked `secret`,+* declares only valid `Capability` verbs.++It renders `docs/connectors/conformance-matrix.md` and `--check` gates it, so a+new connector cannot land without conforming and the published matrix cannot+drift from the registry. Live-vendor sandbox smoke (actually hitting each API)+is a separate future wave; this gates the contract every connector must satisfy.++Usage:+ python3 scripts/connector_conformance.py # regenerate the matrix+ python3 scripts/connector_conformance.py --check # fail on drift+ python3 scripts/connector_conformance.py --json # JSON to stdout+"""++from __future__ import annotations++import argparse+import inspect+import json+import sys+from pathlib import Path++ROOT = Path(__file__).resolve().parent.parent+sys.path.insert(0, str(ROOT / "services" / "connectors"))++DOC = ROOT / "docs" / "connectors" / "conformance-matrix.md"+++def _load_registry():+ from app.connectors import CONNECTOR_REGISTRY # noqa: PLC0415+ from app.connectors.base import BaseConnector, Capability # noqa: PLC0415++ return CONNECTOR_REGISTRY, BaseConnector, Capability+++def compute() -> dict:+ registry, base_connector, capability = _load_registry()+ rows: list[dict] = []+ for connector_id, cls in sorted(registry.items()):+ schema = cls.schema()+ secret_fields = [f for f in schema.fields if f.type == "secret"]+ caps = cls.capabilities()+ rows.append(+ {+ "id": connector_id,+ "category": schema.category,+ "fields": len(schema.fields),+ "secrets": len(secret_fields),+ "capabilities": len(caps),+ "async_test_connection": inspect.iscoroutinefunction(cls.test_connection),+ "async_fetch_alerts": inspect.iscoroutinefunction(cls.fetch_alerts),+ "normalize_override": cls.normalize is not base_connector.normalize,+ "capabilities_valid": all(isinstance(c, capability) for c in caps),+ }+ )+ conforming = sum(1 for r in rows if r["async_test_connection"] and r["async_fetch_alerts"] and r["capabilities_valid"])+ return {"total": len(rows), "conforming": conforming, "rows": rows}+++def render_markdown(data: dict) -> str:+ lines: list[str] = []+ lines.append("# Connector conformance matrix")+ lines.append("")+ lines.append("> Generated by `scripts/connector_conformance.py`; gated by `--check` in the")+ lines.append("> connectors test suite. **Do not edit by hand.** Every connector must")+ lines.append("> implement the runtime contract (`test_connection` + `fetch_alerts` as")+ lines.append("> async coroutines, valid capabilities, secret fields marked `secret`).")+ lines.append("> Live-vendor sandbox smoke is a separate wave; this gates the contract.")+ lines.append("")+ lines.append(f"**{data['conforming']} / {data['total']} connectors conform** to the runtime contract.")+ lines.append("")+ lines.append("| connector | category | fields | secrets | caps | test_connection | fetch_alerts | normalize |")+ lines.append("|-----------|----------|-------:|--------:|-----:|:---------------:|:------------:|:---------:|")+ for r in data["rows"]:+ tc = "✅" if r["async_test_connection"] else "❌"+ fa = "✅" if r["async_fetch_alerts"] else "❌"+ nm = "✅" if r["normalize_override"] else "—"+ lines.append(f"| {r['id']} | {r['category']} | {r['fields']} | {r['secrets']} | {r['capabilities']} | {tc} | {fa} | {nm} |")+ lines.append("")+ return "\n".join(lines)+++def main() -> int:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--check", action="store_true")+ parser.add_argument("--json", dest="as_json", action="store_true")+ args = parser.parse_args()++ data = compute()++ if args.as_json:+ print(json.dumps(data, indent=2, sort_keys=True))+ return 0++ rendered = render_markdown(data)++ if args.check:+ if not DOC.exists():+ print(f"ERROR: {DOC.relative_to(ROOT)} missing — run scripts/connector_conformance.py", file=sys.stderr)+ return 1+ if DOC.read_text(encoding="utf-8").strip() != rendered.strip():+ print(+ f"ERROR: {DOC.relative_to(ROOT)} is stale. A connector changed but the conformance "+ "matrix was not regenerated. Run: python3 scripts/connector_conformance.py",+ file=sys.stderr,+ )+ return 1+ print(f"OK: connector conformance matrix current ({data['conforming']}/{data['total']} conform)")+ return 0++ DOC.parent.mkdir(parents=True, exist_ok=True)+ DOC.write_text(rendered + "\n", encoding="utf-8")+ print(f"wrote {DOC.relative_to(ROOT)} — {data['conforming']}/{data['total']} conform")+ return 0+++if __name__ == "__main__":+ raise SystemExit(main())diff --git a/services/connectors/tests/test_conformance.py b/services/connectors/tests/test_conformance.pynew file mode 100644index 000000000..457c9b4fb--- /dev/null+++ b/services/connectors/tests/test_conformance.py@@ -0,0 +1,89 @@+"""Phase 10 — connector runtime-contract conformance suite.++`test_schemas.py` already gates schema well-formedness. This suite gates the+*runtime contract* the reality audit found ungated — most importantly the+"live Test connection" click-and-connect claim, which had NO gate at all.++Every registered connector must:+ * implement `test_connection` as an async coroutine (the contract behind the+ "live Test connection" button),+ * implement `fetch_alerts` as an async coroutine,+ * declare only valid `Capability` verbs,+ * mark every secret field `type="secret"` so it is vault-encrypted.++And the published conformance matrix must be current (drift gate). Live-vendor+sandbox smoke (actually hitting each API) is a separate future wave; this gates+the contract every connector must satisfy to ship.+"""++from __future__ import annotations++import inspect+import sys+from pathlib import Path++from app.connectors import CONNECTOR_REGISTRY+from app.connectors.base import Capability++# Import the conformance generator by path so the drift assertion uses the same+# code the CLI does.+_SCRIPTS = Path(__file__).resolve().parents[3] / "scripts"+sys.path.insert(0, str(_SCRIPTS))+import connector_conformance as cc # noqa: E402++# Secret-shaped field names that MUST be marked type="secret" so the vault+# encrypts them. A field called "api_key" rendered as a plain "string" would+# be stored in the clear — the exact leak this check prevents.+_SECRET_NAME_HINTS = ("secret", "password", "token", "api_key", "apikey", "private_key", "client_secret")+++def test_registry_not_empty():+ assert CONNECTOR_REGISTRY, "connector registry is empty"+++def test_every_connector_implements_async_test_connection():+ """The 'live Test connection' contract — the capability that had NO gate."""+ offenders = [cid for cid, cls in CONNECTOR_REGISTRY.items() if not inspect.iscoroutinefunction(cls.test_connection)]+ assert offenders == [], f"connectors missing an async test_connection: {offenders}"+++def test_every_connector_implements_async_fetch_alerts():+ offenders = [cid for cid, cls in CONNECTOR_REGISTRY.items() if not inspect.iscoroutinefunction(cls.fetch_alerts)]+ assert offenders == [], f"connectors missing an async fetch_alerts: {offenders}"+++def test_every_declared_capability_is_a_valid_verb():+ for cid, cls in CONNECTOR_REGISTRY.items():+ for cap in cls.capabilities():+ assert isinstance(cap, Capability), f"{cid} declares a non-Capability verb: {cap!r}"+++def test_secret_shaped_fields_are_marked_secret():+ """A credential field stored as plain 'string' bypasses the vault. Any+ field whose name looks like a secret must be type='secret'."""+ offenders: list[str] = []+ for cid, cls in CONNECTOR_REGISTRY.items():+ for f in cls.schema().fields:+ name = f.name.lower()+ if any(hint in name for hint in _SECRET_NAME_HINTS) and f.type != "secret":+ offenders.append(f"{cid}.{f.name} (type={f.type})")+ assert offenders == [], f"secret-shaped fields not marked type='secret': {offenders}"+++def test_connector_identity_matches_registry_key():+ for cid, cls in CONNECTOR_REGISTRY.items():+ assert cls.connector_id == cid, f"{cls.__name__}.connector_id {cls.connector_id!r} != registry key {cid!r}"+ assert cls.connector_name, f"{cid}: connector_name is empty"+++def test_published_conformance_matrix_is_current():+ """Drift gate: the committed matrix must match the registry."""+ data = cc.compute()+ rendered = cc.render_markdown(data)+ committed = cc.DOC.read_text(encoding="utf-8")+ assert committed.strip() == rendered.strip(), "docs/connectors/conformance-matrix.md is stale — run scripts/connector_conformance.py"+++def test_all_connectors_conform():+ data = cc.compute()+ assert data["conforming"] == data["total"], f"only {data['conforming']}/{data['total']} connectors conform to the runtime contract"