Files
roboco/tests/unit/test_vault_cli.py
15a3e87a2f feat(vault): Obsidian vault V1 — projection core, Auditor narrative, input loop (#458)
* fix(gateway): gate review diffs against the task's real parent branch (#444)

The in-path PR-review gate's evidence diff (claim_gate_review) and the
pr_pass conventions guard derived their diff base via parent_branch_for
string surgery, which reuses the child branch's own team segment — wrong
for every cross-team hop (a frontend child of a main_pm root derives a
ref that never existed) and silently falls back to the repo default
branch, so the reviewer judged the entire inherited base-branch content
as the task's own work and failed acceptance criteria the task never
touched. Bounced a live goals-tab fix three times, unfixable by branch
surgery.

The gate now resolves the base via resolve_parent_branch (the parent
task's recorded branch_name, cross-team correct) and threads it as a new
preferred_parent override through git.diff / list_changed_files /
conventions_check_for_task — consulted only when no explicit base is
given, so the pinned literal-base contract (base="HEAD~1") and every
other diff caller (QA, doc, content) are byte-identical. Parent lookup
fails open (derived-base fallback) like the other resolve_parent_branch
call sites, and is skipped entirely while the conventions flag is off.

Also excludes .uv-cache/ and .claude/ (agent worktrees, private uv
cache) from the markdown prose scanner — both are repo-local tool dirs
whose vendored/generated files tripped make reflow-check.

Co-authored-by: Renn F <rennf93@users.noreply.github.com>

* feat(vault): Obsidian vault V1 — projection core + input loop

The vault is a rebuildable projection of the DB (never a source of
truth), default-off behind ROBOCO_OBSIDIAN_VAULT_ENABLED + ROBOCO_VAULT_PATH.

Projection core: VaultWriter materializes tasks/journals/A2A/agents as
wikilinked markdown (id-suffixed stable filenames, alias-based links so
renames never break, is_private journals excluded like the RAG corpus);
event seams materialize on journal write and A2A send and touch task-note
frontmatter at the status-transition chokepoint — all best-effort, a
vault failure never blocks a verb. Shipped .obsidian config (Dataview,
Kanban, team/status graph groups) + _meta dashboards; python -m
roboco.vault rebuild/relocate (rebuild preserves the narrative section).

Auditor narrative duty: curate_vault content verb (auditor-only,
playbook-curation pattern) spawned by a dedicated root-completion hook
with its own cooldown — fully separate from _dispatch_audit_work, whose
scheduled-sweep/alert-producer revival belongs to the queued fleet task.

Input loop: VaultIntakeEngine (ROBOCO_VAULT_INTAKE_*) watches the
intake folder for #roboco-tagged notes and materializes each as ONE held
draft (confirmed_by_human=False, Secretary-owned, source=vault_note,
excluded by the dispatchers via _is_held_ceo_source) with local-model
extraction and a deterministic fallback; vault_seen_notes ledger
(migration 070) keyed on path+content-hash (the CEO-feedback callout is
stripped before hashing so the engine's own append never self-triggers);
per-cycle and open-draft caps. Nothing auto-starts.

* fix(vault): integrate with master — re-chain migration 070 onto 069, mypy-clean tests

The vault branch was cut from slave before the sequence-gate promotion,
so migration 070 chained from 068 while master already carried 069 —
two heads on merge. Master is now merged in and 070 revises 069.
Vault test files also get mypy-clean mock idioms (monkeypatch.setattr
over method assignment; await_args narrowed before access).

* fix(scripts): dedupe SKIP_DIRS again after the master merge

Master still carries the twin-merge duplicate (its dedupe hotfix is an
unmerged PR); the merge re-imported it here.

* fix(vault): reflow hard-wrapped prose in the vault asset templates

* chore(config): exclude .uv-cache and .claude from deptry's scan scope

Same repo-local tool dirs the prose scanner skips; the standalone deptry
target walks the repo root and drowned in the cache's unpacked wheels.

* fix(vault): board-review activation path for vault drafts + relocate graft

The input loop's held-artifact posture was a dead end: vault_note drafts
were unconditionally held by _is_held_ceo_source, owned by the verbless
Secretary, hidden from the panel's approval surfaces by team, and the
open-drafts cap counted them forever — the engine self-bricked after ten
notes. Vault drafts now ride the intake board-review path instead: a
tagged note becomes a PENDING Product-Owner-assigned Board draft (the
exact confirm_live_draft board shape), the board reviews it, and only
the CEO's approve_and_start makes it deliverable — never-auto-starts now
rests on the board gate, proven by tests against the real dispatchers.
The cap counts only drafts still awaiting the CEO (team==BOARD,
non-terminal), so approval and cancellation both free it.

relocate into an existing personal vault now grafts old_root/RoboCo as a
direct child (refusing loudly if RoboCo/ already exists there) and adds
only absent .obsidian/_meta files — a personal vault's config is never
clobbered. An absent destination keeps the whole-tree move.

---------

Co-authored-by: Renn F <rennf93@users.noreply.github.com>
2026-07-11 03:17:59 +02:00

203 lines
7.3 KiB
Python

"""``python -m roboco.vault`` — rebuild / relocate, on a tmp vault.
Flag-gated: both subcommands refuse when ROBOCO_OBSIDIAN_VAULT_ENABLED is off.
"""
from __future__ import annotations
from contextlib import asynccontextmanager
from datetime import UTC, datetime
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any
from unittest.mock import AsyncMock, MagicMock, patch
from uuid import uuid4
from roboco.config import settings
from roboco.services.vault_writer import TaskNoteData
from roboco.vault import ensure_vault_assets, main
if TYPE_CHECKING:
from pathlib import Path
import pytest
def test_main_refuses_rebuild_when_flag_off(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(settings, "obsidian_vault_enabled", False)
assert main(["rebuild"]) == 1
def test_main_refuses_relocate_when_flag_off(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(settings, "obsidian_vault_enabled", False)
assert main(["relocate", "/tmp/somewhere"]) == 1
def test_relocate_moves_existing_tree(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
old_root = tmp_path / "old-vault"
old_root.mkdir()
(old_root / "RoboCo").mkdir()
(old_root / "RoboCo" / "marker.md").write_text("hi", encoding="utf-8")
new_root = tmp_path / "new-vault"
monkeypatch.setattr(settings, "obsidian_vault_enabled", True)
monkeypatch.setattr(settings, "vault_path", str(old_root))
assert main(["relocate", str(new_root)]) == 0
assert not old_root.exists()
assert (new_root / "RoboCo" / "marker.md").read_text(encoding="utf-8") == "hi"
def test_relocate_into_existing_vault_grafts_roboco_subtree(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""An existing destination is a personal vault: only RoboCo/ moves into it
(never nesting the old dirname), the personal .obsidian is never
clobbered, and absent shipped assets are added."""
old_root = tmp_path / "old-vault"
(old_root / "RoboCo").mkdir(parents=True)
(old_root / "RoboCo" / "marker.md").write_text("hi", encoding="utf-8")
personal = tmp_path / "personal-vault"
(personal / ".obsidian").mkdir(parents=True)
(personal / ".obsidian" / "app.json").write_text("personal", encoding="utf-8")
(personal / "My Notes").mkdir()
monkeypatch.setattr(settings, "obsidian_vault_enabled", True)
monkeypatch.setattr(settings, "vault_path", str(old_root))
assert main(["relocate", str(personal)]) == 0
assert (personal / "RoboCo" / "marker.md").read_text(encoding="utf-8") == "hi"
assert not (personal / "old-vault").exists() # no nested old dirname
assert not (old_root / "RoboCo").exists() # subtree moved, not copied
# Personal config untouched; absent shipped assets materialized.
assert (personal / ".obsidian" / "app.json").read_text(
encoding="utf-8"
) == "personal"
assert (personal / ".obsidian" / "community-plugins.json").exists()
assert (personal / "My Notes").exists()
def test_relocate_refuses_when_destination_roboco_exists(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
old_root = tmp_path / "old-vault"
(old_root / "RoboCo").mkdir(parents=True)
(old_root / "RoboCo" / "marker.md").write_text("hi", encoding="utf-8")
personal = tmp_path / "personal-vault"
(personal / "RoboCo").mkdir(parents=True)
monkeypatch.setattr(settings, "obsidian_vault_enabled", True)
monkeypatch.setattr(settings, "vault_path", str(old_root))
assert main(["relocate", str(personal)]) == 1
# Nothing moved on refusal.
assert (old_root / "RoboCo" / "marker.md").exists()
def test_ensure_vault_assets_materializes_templates_idempotently(
tmp_path: Path,
) -> None:
ensure_vault_assets(tmp_path)
plugins = tmp_path / ".obsidian" / "community-plugins.json"
dashboard = tmp_path / "RoboCo" / "_meta" / "dashboard.md"
kanban = tmp_path / "RoboCo" / "_meta" / "kanban-board.md"
assert plugins.exists()
assert dashboard.exists()
assert kanban.exists()
assert "dataview" in plugins.read_text(encoding="utf-8")
# An operator's own edit survives a second call (never overwritten).
dashboard.write_text("operator edit", encoding="utf-8")
ensure_vault_assets(tmp_path)
assert dashboard.read_text(encoding="utf-8") == "operator edit"
def _db_ctx(db: Any) -> Any:
@asynccontextmanager
async def _ctx() -> Any:
yield db
return _ctx
def test_rebuild_writes_agent_task_journal_and_a2a(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""``main()`` drives ``_rebuild`` via ``asyncio.run`` — this test must
stay a plain (non-async) function, or pytest-asyncio's own running loop
collides with it."""
monkeypatch.setattr(settings, "obsidian_vault_enabled", True)
monkeypatch.setattr(settings, "vault_path", str(tmp_path))
agent = MagicMock(
id=uuid4(),
slug="be-dev-1",
name="BE Dev 1",
role="developer",
team=SimpleNamespace(value="backend"),
)
agent_service = MagicMock()
agent_service.list_agents = AsyncMock(return_value=[agent])
task = MagicMock(id=uuid4(), project_id=None)
task_service = MagicMock()
task_service.list_all = AsyncMock(side_effect=[[task], []])
journal = MagicMock(id=uuid4())
entry = MagicMock(
id=uuid4(),
task_id=None,
title="Learned something",
content="body",
timestamp=datetime.now(UTC),
type="learning",
)
journal_service = MagicMock()
journal_service.get_or_create_journal = AsyncMock(return_value=journal)
journal_service.list_entries = AsyncMock(side_effect=[[entry], []])
conv = MagicMock(id=uuid4(), agent_a="be-dev-1", agent_b="be-pm", task_id=None)
conv_result = MagicMock()
conv_result.scalars.return_value.all.return_value = [conv]
db = MagicMock()
db.execute = AsyncMock(return_value=conv_result)
a2a_msg = MagicMock(
id=uuid4(), from_agent="be-dev-1", content="hi", created_at=datetime.now(UTC)
)
a2a_service = MagicMock()
a2a_service.get_messages = AsyncMock(return_value=[a2a_msg])
task_note_data = TaskNoteData(
id=str(task.id),
title="A task",
project_slug="unassigned",
description="desc",
status="completed",
team="backend",
priority=2,
task_type="code",
)
with (
patch("roboco.db.base.get_db_context", _db_ctx(db)),
patch("roboco.services.agent.AgentService", return_value=agent_service),
patch("roboco.services.task.TaskService", return_value=task_service),
patch("roboco.services.journal.JournalService", return_value=journal_service),
patch("roboco.services.project.get_project_service", return_value=MagicMock()),
patch("roboco.services.a2a.A2AService", return_value=a2a_service),
patch(
"roboco.services.vault_assembly.assemble_task_note_data",
AsyncMock(return_value=task_note_data),
),
):
assert main(["rebuild"]) == 0
assert (tmp_path / "RoboCo" / "Agents" / "be-dev-1.md").exists()
assert any((tmp_path / "RoboCo" / "Tasks" / "unassigned").glob("*.md"))
assert any((tmp_path / "RoboCo" / "Journals" / "be-dev-1").glob("*.md"))
assert any((tmp_path / "RoboCo" / "A2A").glob("*.md"))
# asset bootstrap ran too
assert (tmp_path / ".obsidian" / "community-plugins.json").exists()