Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def main():
_log("skip", reason="empty", scope=scope)
sys.exit(0)

_log("injected", scope=scope, claims=len(claims), candidates=len(candidates), articles=len(articles))
_log("injected", scope=scope, claims=len(claims), candidates=candidates, articles=len(articles))

context = _format_context(scope, claims, cycle, candidates, articles, profile)
output = {
Expand Down
33 changes: 33 additions & 0 deletions tests/test_compiled_profile_surfaces.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations

import importlib.util
import io
import json
import subprocess
import sys
from pathlib import Path

import pytest


ROOT = Path(__file__).resolve().parents[1]
HOOK = ROOT / "memorymaster" / "config_templates" / "hooks" / "memorymaster-session-start.py"
Expand Down Expand Up @@ -38,6 +41,36 @@ def test_session_start_loads_only_generated_bounded_profile(tmp_path: Path) -> N
assert module._load_compiled_profile() == ""


def test_session_start_logs_integer_candidate_count_and_injects_profile(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
module = _hook_module()
db = tmp_path / "memory.db"
db.touch()
profile = tmp_path / "user.md"
profile.write_text(
"<!-- generated by MemoryMaster; rebuild instead of editing -->\nprofile fact\n",
encoding="utf-8",
)
logged: list[dict[str, object]] = []
monkeypatch.setattr(module, "DB_PATH", db)
monkeypatch.setattr(module, "PROFILE_PATH", profile)
monkeypatch.setattr(module, "_query_recent_claims", lambda *_: [])
monkeypatch.setattr(module, "_query_last_cycle_summary", lambda *_: {})
monkeypatch.setattr(module, "_query_candidate_claims", lambda *_: 2)
monkeypatch.setattr(module, "_load_recent_wiki_articles", lambda *_: [])
monkeypatch.setattr(module, "_log", lambda _event, **values: logged.append(values))
monkeypatch.setattr(sys, "stdin", io.StringIO("{}"))

with pytest.raises(SystemExit) as stopped:
module.main()

payload = json.loads(capsys.readouterr().out)
assert stopped.value.code == 0
assert logged[-1]["candidates"] == 2
assert "MemoryMaster compiled user profile" in payload["hookSpecificOutput"]["additionalContext"]


def test_profile_module_cli_status_and_help(tmp_path: Path) -> None:
db = tmp_path / "profile.db"
help_run = subprocess.run(
Expand Down
Loading