mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
* feat(release): add release-manager feature flag (default off) * feat(release): change classification + semver-bump derivation * feat(release): readiness audit (changelog/version-ref/docs/migration/gate) * feat(release): release-manager engine proposes a gated release * feat(release): fail-closed release executor (bump, gate, publish) * feat(release): CEO approve/reject release-proposal surface * docs(release): document the gated release manager * feat(memory): add org-memory feature flags (default off) * feat(memory): add playbooks table + status enum + migration * feat(memory): playbook service with auditor curation transitions * feat(memory): playbooks RAG index plugin * feat(memory): index a playbook into RAG on approval * feat(memory): distill a high-signal lesson at task completion * feat(memory): keep private journal reflections out of the shared RAG corpus * feat(memory): draft_playbook verb + auditor curation verbs * fix(ci): resolve mypy tests/ errors blocking the gate (UUID casts, annotations) * feat(memory): auto-inject similar lessons/playbooks into the briefing * feat(memory): auditor playbook review queue (api + panel) * docs(memory): document the org-memory loop + playbook verbs * fix(provisioning): idempotent pitch provisioning (reuse product/project by slug on re-approval) * fix(memory): add chunks_playbooks to the chunk schema + isolate release route tests - Migration 030's CHUNK_TABLES was missing chunks_playbooks, breaking the IndexType<->migration parity guard once the PLAYBOOKS index landed. The upgrade is ALTER ... IF EXISTS so adding it is safe on any DB shape. - The release-route fixture's approve/reject paths call db.commit() (real behavior), so a held proposal outlived the per-test rollback and leaked into engine tests that read the global list_open_release_proposals(). Tear down source=release_manager rows after each test. - Make the gather_snapshot real-repo smoke version-agnostic (semver match) so it stops pinning the literal repo version. * chore(release): 0.13.0 * ++ --------- Co-authored-by: Renn F <rennf93@users.noreply.github.com>
92 lines
3.0 KiB
Python
92 lines
3.0 KiB
Python
"""Org-memory keystone — role-shaped query + relevance-floored injection.
|
|
|
|
``shape_memory_query`` shapes the KB query per role; ``EvidenceRepo.similar_memory``
|
|
applies the cosine floor + top-K and returns the shaped items that
|
|
``_briefing_for`` injects as ``context_briefing["institutional_memory"]`` (only
|
|
when ``org_memory_enabled``).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
from roboco.models.optimal import IndexType, SearchResult
|
|
from roboco.services.gateway.evidence_builder import shape_memory_query
|
|
from roboco.services.gateway.evidence_repo import EvidenceRepo
|
|
|
|
_FLOOR = 0.6
|
|
_HIGH = 0.9
|
|
_LOW = 0.4
|
|
|
|
|
|
def _result(score: float, index_type: IndexType = IndexType.LEARNINGS) -> SearchResult:
|
|
return SearchResult(
|
|
content="a distilled lesson body",
|
|
source="roboco://learnings/lrn-1",
|
|
score=score,
|
|
index_type=index_type,
|
|
)
|
|
|
|
|
|
def test_shape_memory_query_is_role_specific() -> None:
|
|
dev = shape_memory_query("developer", "Add retry", "code")
|
|
pm = shape_memory_query("cell_pm", "Add retry", "code")
|
|
qa = shape_memory_query("qa", "Add retry", "code")
|
|
doc = shape_memory_query("documenter", "Add retry", "documentation")
|
|
assert dev != pm # role shaping actually differs
|
|
assert "Add retry" in dev and "implementation" in dev
|
|
assert "decomposition" in pm
|
|
assert "defect" in qa
|
|
assert "documentation pattern" in doc
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_applies_floor_and_shapes(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(
|
|
return_value=[_result(_HIGH, IndexType.PLAYBOOKS), _result(_LOW)]
|
|
)
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
items = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
assert len(items) == 1 # the 0.4 result is below the floor, excluded
|
|
assert items[0]["kind"] == "playbook"
|
|
assert items[0]["score"] == _HIGH
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_caps_at_top_k(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
optimal = MagicMock()
|
|
optimal.search = AsyncMock(return_value=[_result(_HIGH) for _ in range(5)])
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(return_value=optimal),
|
|
)
|
|
items = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=2, min_score=_FLOOR
|
|
)
|
|
assert len(items) == 2 # noqa: PLR2004 - top_k cap
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_similar_memory_empty_on_rag_error(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
"roboco.services.optimal.get_optimal_service",
|
|
AsyncMock(side_effect=RuntimeError("rag down")),
|
|
)
|
|
items = await EvidenceRepo(MagicMock()).similar_memory(
|
|
query="q", top_k=3, min_score=_FLOOR
|
|
)
|
|
assert items == []
|