feat: resolve memory middleware dir per-call from configurable

This commit is contained in:
m4
2026-08-19 21:50:47 +08:00
parent 5041807a8e
commit 4445379f0a
2 changed files with 62 additions and 28 deletions
+22 -2
View File
@@ -417,9 +417,9 @@ async def test_profile_memory_async_path_inlines_content_under_blockbuster(
call_threads = []
original_read = middleware._read_profile_memory
def tracked_read_profile_memory():
def tracked_read_profile_memory(memory_dir=None):
call_threads.append(threading.get_ident())
return original_read()
return original_read(memory_dir)
monkeypatch.setattr(middleware, "_read_profile_memory", tracked_read_profile_memory)
@@ -625,3 +625,23 @@ def test_profile_memory_skips_legacy_unknown_placeholders(tmp_path, monkeypatch)
assert "(unknown)" not in migrated_profile_text
assert "Imported from legacy MEMORY.md" not in migrated_profile_text
assert not (memories / "MEMORY.md").exists()
def test_read_profile_memory_honors_memory_dir_override(tmp_path, monkeypatch):
from EvoScientist import paths
global_mem = tmp_path / "global"
user_mem = tmp_path / "user"
workspace = tmp_path / "workspace"
workspace.mkdir()
monkeypatch.setattr(paths, "WORKSPACE_ROOT", workspace)
middleware = memory_module.create_memory_middleware(str(global_mem))
middleware.modify_request(_request()) # bootstrap global
(user_mem / "profile").mkdir(parents=True)
(user_mem / "profile" / "USER_PROFILE.md").write_text(
"# User profile\n\nper-user marker", encoding="utf-8"
)
content = middleware._read_profile_memory(memory_dir=user_mem)
assert "per-user marker" in content