teleo-infrastructure/tests
Fawaz 7bb6fc417b
Some checks are pending
CI / lint-and-test (push) Waiting to run
feat(kb): apply_proposal engine (stage 2 of KB apply pipeline) (#35)
* feat(kb): apply_proposal engine to land approved proposals into canonical

Stage 2 of the KB apply pipeline (approve -> APPLY -> render -> surface).
Turns an approved kb_stage.kb_proposals row into canonical public.* rows and
flips the ledger to 'applied' in one verified transaction.

- Connects as the narrow kb_apply role (never superuser): writes only
  strategies, strategy_nodes, claim_evidence, claim_edges + kb_proposals ledger.
  Enforces "agents propose, do not self-apply" at the DB boundary.
- Per-type handlers: revise_strategy (versioned strategy + node replace),
  add_edge, attach_evidence (requires existing source_id; source minting is
  intentionally out of scope for kb_apply's grants).
- Strict apply_payload contract (v1); freeform eval packets are normalized
  upstream, not applied directly.
- --dry-run prints exact SQL; idempotent (refuses non-approved / already-applied);
  transactional with an in-txn DO-block invariant check that rolls back on failure.
- Unit tests cover SQL builders, validation, dispatch, and status guards.

* fix(kb): rowcount=1 apply guard + real applied_by FK stamp

Closes the three draft-exit review items on the apply engine:

- Ledger flip now runs in a DO block asserting exactly one 'approved'
  row moved to 'applied' (GET DIAGNOSTICS row_count). Closes the
  concurrent double-apply race — load_proposal (read) and the flip
  (write) are separate statements, so a row lock cannot span them; only
  one concurrent apply can match status='approved', so rowcount=1 is the
  authoritative guard. A loser RAISEs and the whole txn rolls back.
- applied_by_agent_id is stamped as a real FK resolved from public.agents
  by handle, defaulting to the kb-apply service agent — no more NULL FK,
  no backfill needed.
- scripts/kb_apply_prereqs.sql: one-time superuser bootstrap — inserts the
  kb-apply service-agent row (kb_apply never gets INSERT on agents), grants
  kb_apply SELECT on public.agents, and ensures the one-active-strategy
  unique index (idempotent; already present on prod).

18/18 unit tests pass.

* fix(kb): hard-resolve applied_by handle, RAISE on NULL FK

Resolve applied_by into a variable and assert NOT NULL before the ledger
flip, instead of an inline subselect that silently stamps a NULL
applied_by_agent_id on an unresolved handle. Since the FK is ON DELETE SET
NULL, a bad handle (typo/unseeded agent) was a legal silent NULL -- the
perpetually-NULL FK we eliminated. Unresolved handle now hard-fails ->
rollback. Non-default --applied-by (operator, future drafters) is the path
that goes through the lookup and could strand NULL.
2026-07-04 19:57:49 -04:00
..
__init__.py ganymede: add dev infrastructure — pyproject.toml, CI, deploy script 2026-03-13 14:24:27 +00:00
conftest.py ganymede: add dev infrastructure — pyproject.toml, CI, deploy script 2026-03-13 14:24:27 +00:00
test_activity_classify.py test(diagnostics): activity_endpoint classify_pr_operation suite 2026-04-27 13:39:44 +01:00
test_agent_graph_schema_sql.py Add Teleo research eval schema 2026-06-24 14:21:03 +02:00
test_agent_routing.py Implement phase 1b agent routing 2026-05-29 14:00:13 +02:00
test_apply_proposal.py feat(kb): apply_proposal engine (stage 2 of KB apply pipeline) (#35) 2026-07-04 19:57:49 -04:00
test_attribution.py fix(attribution): --diff-filter=A + handle sanity filter + remove legacy fallback 2026-04-24 12:58:55 +01:00
test_contributor.py Prove phase 1b local e2e 2026-05-29 15:08:09 +02:00
test_decision_engine_replay.py Add decision engine replay harness 2026-06-01 17:37:38 +02:00
test_enrichment_dedup.py fix: enrichment idempotency — three-layer dedup prevents duplicate evidence blocks 2026-03-31 13:18:23 +01:00
test_entity_queue.py epimetheus: sync VPS-deployed code to repo — Mar 18-20 reliability + features 2026-03-20 20:17:27 +00:00
test_eval_actions.py refactor: Phase 4 — extract eval_actions.py, drop underscore prefixes in eval_parse 2026-04-16 12:57:51 +01:00
test_eval_parse.py Prove phase 1b local e2e 2026-05-29 15:08:09 +02:00
test_eval_pipeline.py fix: add telegram/ and tests/ to deploy pipeline, remove hardcoded API key 2026-04-20 17:15:55 +01:00
test_evaluate_agent_routing.py Harden local phase 1b review path 2026-05-29 14:16:12 +02:00
test_extraction_prompt.py epimetheus: sync VPS-deployed code to repo — Mar 18-20 reliability + features 2026-03-20 20:17:27 +00:00
test_feedback.py epimetheus: sync VPS-deployed code to repo — Mar 18-20 reliability + features 2026-03-20 20:17:27 +00:00
test_install_telegram_agent_token.py Add safe Telegram agent token installer 2026-06-22 20:47:44 +02:00
test_install_telegram_smart_research_gates.py Allow Leo paid research gate by chat title (#32) 2026-07-02 01:19:17 +02:00
test_leaderboard.py fix(tests): apply Ganymede review nits + add m3taversal reset script 2026-04-27 17:35:18 +01:00
test_merge.py Replace rebase-retry with cherry-pick merge mechanism 2026-03-31 13:18:26 +01:00
test_phase1b_end_to_end.py Prove phase 1b local e2e 2026-05-29 15:08:09 +02:00
test_post_extract.py feat: atomic extract-and-connect + stale PR monitor + response audit 2026-03-28 22:34:20 +00:00
test_pr_state.py refactor: Phase 3 — fix close_pr ghost bug, wire stale_pr, extract eval_parse 2026-04-16 12:40:23 +01:00
test_research_backfill_idempotent.py test(attribution): prove research-backfill replay is idempotent 2026-04-27 12:50:17 +01:00
test_research_eval_schema_sql.py Add Teleo research eval schema 2026-06-24 14:21:03 +02:00
test_reweave.py feat: consolidate eval pipeline, reweave fixes, enrichment dedup, cherry-pick merge, TG batching 2026-03-31 13:21:59 +01:00
test_reweave_merge.py Phase 6a: extract frontmatter.py from merge.py — pure YAML helpers 2026-04-16 13:16:38 +01:00
test_search.py Prove phase 1b local e2e 2026-05-29 15:08:09 +02:00
test_telegram_leo_wallet_test_runtime.py Use existing Leo wallet-test Telegram bot 2026-06-22 21:53:37 +02:00
test_telegram_leo_x402_bridge.py Allow Leo paid research gate by chat title (#32) 2026-07-02 01:19:17 +02:00
test_teleo_agent_healthcheck.py add teleo agent autorecovery timer 2026-07-02 23:37:22 +02:00
test_teleo_agent_systemd.py add teleo agent autorecovery timer 2026-07-02 23:37:22 +02:00
test_tg_batching.py fix: TG message batching — group by chat_id + time proximity 2026-03-31 13:19:35 +01:00
test_x_content_pipeline.py Add X content pipeline: output gates + tweet queue + pluggable approval 2026-04-15 17:02:08 +01:00