@@ -510,6 +510,62 @@ async def _fake_wait_for_queues(*, timeout):
510510 assert write_calls == [(file_uri , "new content" )]
511511
512512
513+ @pytest .mark .asyncio
514+ async def test_create_mode_canonicalizes_user_shorthand_memory_uri (monkeypatch ):
515+ input_uri = "viking://user/memories/new_file.md"
516+ canonical_uri = "viking://user/default/memories/new_file.md"
517+ root_uri = "viking://user/default/memories"
518+ ctx = RequestContext (user = UserIdentifier .the_default_user (), role = Role .USER )
519+ viking_fs = _FakeVikingFSForCreate (
520+ file_uri = canonical_uri ,
521+ root_uri = root_uri ,
522+ file_exists = False ,
523+ )
524+ coordinator = ContentWriteCoordinator (viking_fs = viking_fs )
525+ lock_manager = _FakeLockManager ()
526+
527+ monkeypatch .setattr ("openviking.storage.content_write.get_lock_manager" , lambda : lock_manager )
528+
529+ write_calls = []
530+ vectorize_calls = []
531+ refresh_calls = []
532+
533+ async def _fake_write_in_place (uri , content , * , mode , ctx ):
534+ del mode , ctx
535+ write_calls .append ((uri , content ))
536+ return content
537+
538+ async def _fake_vectorize_single_file (uri , * , context_type , ctx ):
539+ del ctx
540+ vectorize_calls .append ((uri , context_type ))
541+ return None
542+
543+ async def _fake_enqueue_memory_refresh (** kwargs ):
544+ refresh_calls .append (kwargs )
545+ return None
546+
547+ async def _fake_wait_for_queues (* , timeout ):
548+ del timeout
549+ return None
550+
551+ monkeypatch .setattr (coordinator , "_write_in_place" , _fake_write_in_place )
552+ monkeypatch .setattr (coordinator , "_vectorize_single_file" , _fake_vectorize_single_file )
553+ monkeypatch .setattr (coordinator , "_enqueue_memory_refresh" , _fake_enqueue_memory_refresh )
554+ monkeypatch .setattr (coordinator , "_wait_for_queues" , _fake_wait_for_queues )
555+
556+ result = await coordinator .write (
557+ uri = input_uri , content = "new content" , mode = "create" , ctx = ctx , wait = True
558+ )
559+
560+ assert result ["uri" ] == canonical_uri
561+ assert result ["root_uri" ] == root_uri
562+ assert result ["context_type" ] == "memory"
563+ assert write_calls == [(canonical_uri , "new content" )]
564+ assert vectorize_calls == [(canonical_uri , "memory" )]
565+ assert refresh_calls [0 ]["root_uri" ] == root_uri
566+ assert refresh_calls [0 ]["modified_uri" ] == canonical_uri
567+
568+
513569@pytest .mark .asyncio
514570async def test_create_mode_existing_file_raises_409 (monkeypatch ):
515571 file_uri = "viking://user/default/memories/existing.md"
0 commit comments