From a7e183a9a799ef8d3bbba9b52337b42920afc130 Mon Sep 17 00:00:00 2001 From: wolverinaton Date: Thu, 13 Aug 2026 14:24:53 -0300 Subject: [PATCH] fix: inject compiled profile at session start --- .../hooks/memorymaster-session-start.py | 2 +- tests/test_compiled_profile_surfaces.py | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/memorymaster/config_templates/hooks/memorymaster-session-start.py b/memorymaster/config_templates/hooks/memorymaster-session-start.py index f4b0b66d..f699d555 100644 --- a/memorymaster/config_templates/hooks/memorymaster-session-start.py +++ b/memorymaster/config_templates/hooks/memorymaster-session-start.py @@ -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 = { diff --git a/tests/test_compiled_profile_surfaces.py b/tests/test_compiled_profile_surfaces.py index c1bf2c7a..fe7bcc16 100644 --- a/tests/test_compiled_profile_surfaces.py +++ b/tests/test_compiled_profile_surfaces.py @@ -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" @@ -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( + "\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(