@@ -167,6 +167,57 @@ def test_memory_type_registry_loads_schemas_from_prompt_manager_resolved_templat
167167 assert registry .get ("custom_memory" ) is not None
168168
169169
170+ def test_memory_type_registry_prefers_custom_memory_dir_over_prompt_manager_templates_root (
171+ tmp_path , monkeypatch
172+ ):
173+ resolved_templates_dir = tmp_path / "resolved-prompts"
174+ resolved_memory_dir = resolved_templates_dir / "memory"
175+ custom_memory_dir = tmp_path / "custom-memory"
176+ resolved_memory_dir .mkdir (parents = True )
177+ custom_memory_dir .mkdir (parents = True )
178+ (resolved_memory_dir / "prompt_root.yaml" ).write_text (
179+ json .dumps (
180+ {
181+ "memory_type" : "prompt_root_memory" ,
182+ "description" : "schema from prompt manager root" ,
183+ "directory" : "viking://user/{{ user_space }}/memories/prompt-root" ,
184+ "filename_template" : "prompt-root.md" ,
185+ "fields" : [],
186+ }
187+ ),
188+ encoding = "utf-8" ,
189+ )
190+ (custom_memory_dir / "custom.yaml" ).write_text (
191+ json .dumps (
192+ {
193+ "memory_type" : "custom_memory" ,
194+ "description" : "schema from custom memory dir" ,
195+ "directory" : "viking://user/{{ user_space }}/memories/custom" ,
196+ "filename_template" : "custom.md" ,
197+ "fields" : [],
198+ }
199+ ),
200+ encoding = "utf-8" ,
201+ )
202+
203+ monkeypatch .setattr (
204+ PromptManager ,
205+ "_resolve_templates_dir" ,
206+ classmethod (lambda cls , templates_dir = None : resolved_templates_dir ),
207+ )
208+ monkeypatch .setattr (
209+ "openviking_cli.utils.config.get_openviking_config" ,
210+ lambda : SimpleNamespace (
211+ memory = SimpleNamespace (custom_templates_dir = str (custom_memory_dir ))
212+ ),
213+ )
214+
215+ registry = MemoryTypeRegistry (load_schemas = True )
216+
217+ assert registry .get ("custom_memory" ) is not None
218+ assert registry .get ("prompt_root_memory" ) is None
219+
220+
170221def test_context_provider_schema_directories_use_prompt_manager_resolved_templates_root (
171222 tmp_path , monkeypatch
172223):
@@ -188,3 +239,37 @@ def test_context_provider_schema_directories_use_prompt_manager_resolved_templat
188239 provider = SessionExtractContextProvider (messages = [])
189240
190241 assert provider .get_schema_directories () == [str (expected_memory_dir )]
242+
243+
244+ def test_context_provider_schema_directories_prefer_custom_memory_dir_over_prompt_manager_root (
245+ tmp_path , monkeypatch
246+ ):
247+ resolved_templates_dir = tmp_path / "resolved-prompts"
248+ custom_memory_dir = tmp_path / "custom-memory"
249+
250+ monkeypatch .setattr (
251+ PromptManager ,
252+ "_resolve_templates_dir" ,
253+ classmethod (lambda cls , templates_dir = None : resolved_templates_dir ),
254+ )
255+ monkeypatch .setattr (
256+ "openviking.session.memory.session_extract_context_provider.get_openviking_config" ,
257+ lambda : SimpleNamespace (
258+ memory = SimpleNamespace (
259+ custom_templates_dir = str (custom_memory_dir ),
260+ eager_prefetch = False ,
261+ )
262+ ),
263+ )
264+ monkeypatch .setattr (
265+ "os.path.exists" ,
266+ lambda path : path == str (custom_memory_dir )
267+ or path == str (PromptManager ._get_bundled_templates_dir () / "memory" ),
268+ )
269+
270+ provider = SessionExtractContextProvider (messages = [])
271+
272+ assert provider .get_schema_directories () == [
273+ str (PromptManager ._get_bundled_templates_dir () / "memory" ),
274+ str (custom_memory_dir ),
275+ ]
0 commit comments