Files
roboco/tests/unit/services/optimal_brain/test_playbooks_index.py
T
Renn F 3441e37120 [sweep] strip Fxxx audit-ID tokens + trim bloated comments/docstrings + add behavior-change docs
Post-audit sweep over the 135 audit-fix commits since 19a474d3:

1. Stripped every # Fxxx: audit-ID token from comments AND every Fxxx token
   from docstring openings across 211 blocks / ~626 lines. The CEO flagged
   these twice: audit-issue IDs in code confuse future devs/agents. The
   descriptive text is preserved; only the Fxxx token is removed (and bloated
   narrative blocks trimmed to 1-3 lines keeping the one non-obvious invariant).
2. Trimmed bloated comments/docstrings to the concise standard (1-3 lines).
3. Added missing behavior-change docs for the audit-fix batch: prompts/roles
   (documenter, pr_reviewer, qa), user-facing docs (api auth, websockets,
   agent-gateway, megatask, merge-model, task-lifecycle, grok, resilience,
   conventions, panel, security, troubleshooting), and the RAG corpus (cell-pm,
   main-pm, pr-reviewer, qa roles; conventions; messaging-tools; escalation;
   megatask; task-claiming workflows).

Comment/docstring/prose ONLY — zero code-line edits (verified: the diff
contains no def/class/return/if/for/await/assignment/call lines). Gates green:
ruff format + ruff check clean, mypy clean on roboco/. The only pytest failures
are the pre-existing sync_branch tracing-decision gap (B1, 250be5c2) — not
sweep-caused and tracked separately.
2026-06-29 01:25:40 +02:00

61 lines
2.2 KiB
Python

"""PlaybooksIndexPlugin — index_type + pure metadata/URI methods.
Mirrors the other index-plugin unit tests (instantiate via __new__, exercise the
pure methods). The embed + pgvector ingest/search path is inherited from
BaseIndexPlugin (shared, proven by the other 8 plugins) and runs live.
"""
from __future__ import annotations
import asyncio
from unittest.mock import AsyncMock, MagicMock
from roboco.models.optimal import IndexType
from roboco.services.optimal_brain.indexes.playbooks import PlaybooksIndexPlugin
def _plugin() -> PlaybooksIndexPlugin:
return PlaybooksIndexPlugin.__new__(PlaybooksIndexPlugin)
def test_index_type_is_playbooks() -> None:
assert _plugin().index_type == IndexType.PLAYBOOKS
def test_prepare_metadata_marks_approved_with_routing_fields() -> None:
md = _plugin().prepare_metadata(
"content", playbook_id="pb-1", team="backend", scope="org", tags=["retry"]
)
assert md["type"] == "playbook"
assert md["playbook_id"] == "pb-1"
assert md["team"] == "backend"
assert md["scope"] == "org"
assert md["tags"] == ["retry"]
# Only approved playbooks are ever indexed — the metadata says so.
assert md["status"] == "approved"
def test_build_source_uri_with_id() -> None:
assert _plugin().build_source_uri(doc_id="pb-1") == "roboco://playbooks/pb-1"
def test_build_source_uri_none_when_missing() -> None:
assert _plugin().build_source_uri(doc_id=None) is None
def test_delete_playbook_removes_its_chunks_by_source() -> None:
"""Deleting a playbook removes its embedded chunks from the vector store
by the playbook's source URI (idempotent — no-op if absent). A
rejected/archived playbook must not stay retrievable in the PLAYBOOKS index."""
plugin = PlaybooksIndexPlugin.__new__(PlaybooksIndexPlugin)
store = MagicMock()
store.delete_by_source = AsyncMock(return_value=None)
# Bypass the initialized-guard property so the unit test doesn't need a
# live pgvector store.
object.__setattr__(plugin, "_initialized", True)
object.__setattr__(plugin, "_store", store)
asyncio.run(plugin.delete_playbook("pb-42"))
store.delete_by_source.assert_awaited_once_with("roboco://playbooks/pb-42")