teleo-infrastructure/tests/test_approve_proposal.py
twentyOne2x 699a9e7917
Some checks are pending
CI / lint-and-test (push) Waiting to run
Add Working Leo operator skill pack
- Add reusable Teleo/Leo skills for VPS, GCP, Telegram, KB changes, provenance, and handoff onboarding.
- Add guarded KB proposal tooling for approved rich proposals, apply packets, and rollback proof.
- Add Cory-style open-ended benchmark prompts and tests alongside the precise regression canaries.

`.agents/skills/leo-telegram-canary-ops/SKILL.md`
`.agents/skills/teleo-gcp-parity-ops/SKILL.md`
`.agents/skills/teleo-infra-provenance/SKILL.md`
`.agents/skills/teleo-kb-db-change-workflow/SKILL.md`
`.agents/skills/teleo-leo-onboarding/SKILL.md`
`.agents/skills/teleo-proof-handoff/SKILL.md`
`.agents/skills/teleo-vps-runtime-ops/SKILL.md`
`.agents/skills/working-leo-cory-outcomes/SKILL.md`
`docs/reports/leo-working-state-20260709/claim-source-contract-preview-current.md`
`docs/reports/leo-working-state-20260709/cory-expected-working-leo-outcomes-20260709.md`
`docs/reports/leo-working-state-20260709/current-truth-index.md`
`docs/reports/leo-working-state-20260709/fable-leo-teleo-onboarding.md`
`docs/reports/leo-working-state-20260709/gcp-db-parity-current-blocker-20260709.json`
`docs/reports/leo-working-state-20260709/helmer-7powers-creation-plan.json`
`docs/reports/leo-working-state-20260709/kb-apply-canary-execute-current.md`
`docs/reports/leo-working-state-20260709/kb-apply-canary-plan-current.md`
`docs/reports/leo-working-state-20260709/leo-db-state-13-skill-pack.svg`
`docs/reports/leo-working-state-20260709/operator-surface-map.md`
`docs/reports/leo-working-state-20260709/production-apply-packet-current.md`
`docs/reports/leo-working-state-20260709/rich-proposal-creation-plan-mapped-current.md`
`docs/reports/leo-working-state-20260709/skill-pack-manifest.json`
`docs/reports/leo-working-state-20260709/skill-pack-readme.md`
`docs/reports/leo-working-state-20260709/telegram-gateway-handler-canary-current.json`
`docs/reports/leo-working-state-20260709/telegram-gateway-handler-canary-current.md`
`docs/reports/leo-working-state-20260709/telegram-live-canary-current.json`
`docs/reports/leo-working-state-20260709/telegram-live-canary-current.md`
`docs/reports/leo-working-state-20260709/telegram-live-db-write-canary-20260709.json`
`docs/reports/leo-working-state-20260709/telegram-live-db-write-canary-20260709.md`
`docs/reports/leo-working-state-20260709/working-leo-current-state-20260709.md`
`docs/reports/leo-working-state-20260709/working-leo-definition-20260709.md`
`docs/reports/leo-working-state-20260709/working-leo-execution-plan-current.md`
`docs/reports/leo-working-state-20260709/working-leo-open-ended-benchmark-spec.json`
`scripts/approve_proposal.py`
`scripts/kb_claim_source_contract_preview.py`
`scripts/kb_rich_proposal_apply_packet.py`
`scripts/kb_rich_proposal_creation_plan.py`
`scripts/working_leo_open_ended_benchmark.py`
`tests/test_approve_proposal.py`
`tests/test_kb_claim_source_contract_preview.py`
`tests/test_kb_rich_proposal_apply_packet.py`
`tests/test_kb_rich_proposal_creation_plan.py`
`tests/test_working_leo_open_ended_benchmark.py`
2026-07-09 22:56:48 +02:00

119 lines
3.7 KiB
Python

"""Unit tests for scripts/approve_proposal.py."""
from __future__ import annotations
import sys
from pathlib import Path
try:
import pytest
except ImportError: # standalone fallback so the file runs without pytest installed
import contextlib
import types
pytest = types.SimpleNamespace()
@contextlib.contextmanager
def _raises(exc, match=None):
try:
yield
except exc as err:
if match is not None and match not in str(err):
raise AssertionError(f"expected {match!r} in {err!r}") from err
return
raise AssertionError(f"expected {exc.__name__} to be raised")
pytest.raises = _raises
REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "scripts"))
import approve_proposal as approve # noqa: E402
def _strict_pending():
return {
"id": "00957f6c-9883-4015-95a4-6b09367efb0e",
"proposal_type": "add_edge",
"status": "pending_review",
"payload": {
"apply_payload": {
"from_claim": "11111111-1111-1111-1111-111111111111",
"to_claim": "22222222-2222-2222-2222-222222222222",
"edge_type": "supports",
}
},
}
def test_assert_approvable_allows_strict_pending_payload():
approve.assert_approvable(_strict_pending(), "m3ta", "approved from Telegram")
def test_assert_approvable_rejects_missing_review_note():
with pytest.raises(SystemExit):
approve.assert_approvable(_strict_pending(), "m3ta", "")
def test_assert_approvable_rejects_empty_reviewer():
with pytest.raises(SystemExit):
approve.assert_approvable(_strict_pending(), " ", "approved")
def test_assert_approvable_rejects_already_approved():
proposal = _strict_pending()
proposal["status"] = "approved"
with pytest.raises(SystemExit):
approve.assert_approvable(proposal, "m3ta", "approved")
def test_assert_approvable_rejects_non_applyable_type():
proposal = _strict_pending()
proposal["proposal_type"] = "rewrite_claim"
with pytest.raises(SystemExit):
approve.assert_approvable(proposal, "m3ta", "approved")
def test_assert_approvable_rejects_freeform_without_apply_payload():
proposal = _strict_pending()
proposal["payload"] = {"rationale": "looks approved in chat"}
with pytest.raises(SystemExit):
approve.assert_approvable(proposal, "m3ta", "approved")
def test_build_approve_sql_has_required_guards():
sql = approve.build_approve_sql("00957f6c-9883-4015-95a4-6b09367efb0e", "m3ta", "O'Brien approves")
assert "status = 'approved'" in sql
assert "where id = '00957f6c-9883-4015-95a4-6b09367efb0e'::uuid" in sql
assert "and status = 'pending_review'" in sql
assert "and payload ? 'apply_payload'" in sql
assert "'O''Brien approves'" in sql
assert "'add_edge'" in sql
assert "'attach_evidence'" in sql
assert "'revise_strategy'" in sql
def test_parse_reviewed_rows_requires_exactly_one_row():
rows = approve.parse_reviewed_rows(
'[{"id":"00957f6c-9883-4015-95a4-6b09367efb0e","status":"approved"}]',
"00957f6c-9883-4015-95a4-6b09367efb0e",
)
assert rows[0]["status"] == "approved"
with pytest.raises(SystemExit):
approve.parse_reviewed_rows("[]", "00957f6c-9883-4015-95a4-6b09367efb0e")
if __name__ == "__main__":
import traceback
failures = 0
for name, fn in sorted(globals().items()):
if name.startswith("test_") and callable(fn):
try:
fn()
print(f"PASS {name}")
except Exception:
failures += 1
print(f"FAIL {name}")
traceback.print_exc()
sys.exit(1 if failures else 0)