ouroboros/tests/test_skill_peer_inventory.py
Ouroboros 506bccc7d6 fix(#1195): keep the server responsive while skills and history run
- F1: the historical model-send seal audit leaves the readiness path and runs
  as one session-custodied child per generation (ouroboros.startup_historical_audit),
  in its own process group; readiness, gateway requests, Panic and the forced
  emergency cleanup never wait on it.
- F3: the in-process extension execution barrier becomes a non-reentrant
  shared-reader/exclusive-writer lease: no-deps handlers overlap, a deps
  injection scope still excludes every reader across its await and cleanup.
- F4: execution hashes only the selected payload; peers are an immutable
  non-executable projection (skill_peer_inventory.py) sharing one conflict
  verdict (skill_conflicts.py); freshness on the next request is unchanged.
- F5: the Widgets list/preferences reads share the existing widget request
  timeout under one AbortController; a timeout keeps the last good cards and
  offers the existing Retry (widget_list.js owns the request seam); a cancelled
  body read stays a rejection and a malformed list is refused, so navigating
  away can never stop a kept-running frame.
- Regression: a custody-record failure inside spawn_supervised kills only the
  child's dedicated group, never the spawner's.

Version-neutral contributor candidate over official 3bdbfef5; release metadata
is allocated at integration. Investigation evidence and the separate
token-usage skill candidate stay on fix/issue-1195-responsiveness.

Co-authored-by: Ouroboros <311266734+ouroboros-agent@users.noreply.github.com>
2026-09-22 18:10:17 +03:00

68 lines
2.7 KiB
Python

from __future__ import annotations
import json
from ouroboros import skill_loader
from ouroboros.skill_loader import save_enabled
from ouroboros.skill_peer_inventory import discover_skill_peers
def _manifest(name: str, *, conflicts=()) -> str:
conflict_text = "[" + ", ".join(json.dumps(item) for item in conflicts) + "]"
return (
"---\n"
f"name: {name}\n"
"description: peer fixture\n"
"version: 1.0.0\n"
"type: instruction\n"
f"conflicts: {conflict_text}\n"
"---\n"
"body\n"
)
def test_peer_projection_preserves_conflicts_without_payload_hashing(tmp_path, monkeypatch):
drive = tmp_path / "drive"
skills = drive / "skills"
first = skills / "alpha"
second = skills / "beta"
first.mkdir(parents=True)
second.mkdir(parents=True)
(first / "SKILL.md").write_text(_manifest("display-alpha", conflicts=("beta",)), encoding="utf-8")
(first / "payload.bin").write_bytes(b"large payload")
(second / "SKILL.md").write_text(_manifest("display-beta"), encoding="utf-8")
save_enabled(drive, "alpha", True)
save_enabled(drive, "beta", True)
def fail_hash(*_args, **_kwargs):
raise AssertionError("peer inventory must not hash payloads")
monkeypatch.setattr(skill_loader, "compute_content_hash", fail_hash)
peers = discover_skill_peers(drive, repo_path="")
by_name = {peer.name: peer for peer in peers}
assert by_name["alpha"].enabled is True
assert by_name["alpha"].conflicts == ("beta",)
assert by_name["beta"].enabled is True
assert all(not peer.identity_collision for peer in peers)
def test_peer_projection_keeps_collision_and_malformed_as_disabled_placeholders(tmp_path):
drive = tmp_path / "drive"
skills = drive / "skills"
(skills / "same").mkdir(parents=True)
(skills / "same").joinpath("SKILL.md").write_text(_manifest("one"), encoding="utf-8")
# A second canonical location is supplied by the user checkout.
checkout = tmp_path / "checkout"
(checkout / "same").mkdir(parents=True)
(checkout / "same").joinpath("SKILL.md").write_text(_manifest("two"), encoding="utf-8")
(skills / "broken").mkdir(parents=True)
(skills / "broken" / "SKILL.md").write_text("---\nname: [\n---\n", encoding="utf-8")
peers = discover_skill_peers(drive, repo_path=str(checkout))
same = [peer for peer in peers if peer.name == "same"]
assert len(same) == 2
assert all(peer.identity_collision and not peer.enabled and not peer.conflicts for peer in same)
broken = next(peer for peer in peers if peer.name == "broken")
assert broken.manifest_error
assert broken.enabled is False
assert broken.conflicts == ()