1- """Functional tests for mounted file edit persistence against a live API."""
1+ """Functional tests for mounted file edit persistence against a live API.
2+
3+ Modified mounted files surface as new generated outputs with fresh file_ids
4+ (not in-place overwrites of the original S3 object). The exec response
5+ includes a `modified_from` reference back to the original upload. LibreChat
6+ downloads the new file_id to capture the edited content.
7+ """
28
39import pytest
410
511
12+ def _find_modified_file (exec_result , original_file_id ):
13+ """Find the generated file entry that was modified from the original."""
14+ for f in exec_result .get ("files" , []):
15+ modified_from = f .get ("modified_from" )
16+ if modified_from and modified_from .get ("id" ) == original_file_id :
17+ return f
18+ return None
19+
20+
621class TestMountedFileEdits :
7- """Verify in-place edits to mounted files persist after execution ."""
22+ """Verify in-place edits to mounted files surface as new generated outputs ."""
823
924 @pytest .mark .asyncio
1025 async def test_overwrite_mounted_file_persists (self , async_client , auth_headers ):
11- """Overwriting a mounted user file should persist the new content."""
26+ """Overwriting a mounted file should produce a new output with modified content."""
1227 upload = await async_client .post (
1328 "/upload" ,
1429 headers = {"x-api-key" : auth_headers ["x-api-key" ]},
@@ -36,18 +51,26 @@ async def test_overwrite_mounted_file_persists(self, async_client, auth_headers)
3651 },
3752 )
3853 assert execute .status_code == 200 , execute .text
39- assert "File modified" in execute .json ()["stdout" ]
54+ exec_result = execute .json ()
55+ assert "File modified" in exec_result ["stdout" ]
56+
57+ modified = _find_modified_file (exec_result , file_id )
58+ assert modified is not None , (
59+ f"No modified_from entry for { file_id } in files: { exec_result ['files' ]} "
60+ )
61+ assert modified .get ("inherited" ) is not True
62+ assert modified ["name" ] == "test.txt"
4063
4164 download = await async_client .get (
42- f"/download/{ session_id } /{ file_id } " ,
65+ f"/download/{ session_id } /{ modified [ 'id' ] } " ,
4366 headers = auth_headers ,
4467 )
4568 assert download .status_code == 200
4669 assert download .text == "modified content"
4770
4871 @pytest .mark .asyncio
4972 async def test_append_to_mounted_file_persists (self , async_client , auth_headers ):
50- """Appending to a mounted file should persist all new lines."""
73+ """Appending to a mounted file should produce a new output with all lines."""
5174 upload = await async_client .post (
5275 "/upload" ,
5376 headers = {"x-api-key" : auth_headers ["x-api-key" ]},
@@ -74,9 +97,16 @@ async def test_append_to_mounted_file_persists(self, async_client, auth_headers)
7497 },
7598 )
7699 assert execute .status_code == 200 , execute .text
100+ exec_result = execute .json ()
101+
102+ modified = _find_modified_file (exec_result , file_id )
103+ assert modified is not None , (
104+ f"No modified_from entry for { file_id } in files: { exec_result ['files' ]} "
105+ )
106+ assert modified .get ("inherited" ) is not True
77107
78108 download = await async_client .get (
79- f"/download/{ session_id } /{ file_id } " ,
109+ f"/download/{ session_id } /{ modified [ 'id' ] } " ,
80110 headers = auth_headers ,
81111 )
82112 assert download .status_code == 200
@@ -123,7 +153,7 @@ async def test_delete_mounted_file_does_not_error(
123153
124154 @pytest .mark .asyncio
125155 async def test_edit_csv_file_persists (self , async_client , auth_headers ):
126- """Editing a mounted CSV file should persist the transformed data."""
156+ """Editing a mounted CSV file should produce a new output with transformed data."""
127157 upload = await async_client .post (
128158 "/upload" ,
129159 headers = {"x-api-key" : auth_headers ["x-api-key" ]},
@@ -153,10 +183,17 @@ async def test_edit_csv_file_persists(self, async_client, auth_headers):
153183 },
154184 )
155185 assert execute .status_code == 200 , execute .text
156- assert "csv updated" in execute .json ()["stdout" ]
186+ exec_result = execute .json ()
187+ assert "csv updated" in exec_result ["stdout" ]
188+
189+ modified = _find_modified_file (exec_result , file_id )
190+ assert modified is not None , (
191+ f"No modified_from entry for { file_id } in files: { exec_result ['files' ]} "
192+ )
193+ assert modified .get ("inherited" ) is not True
157194
158195 download = await async_client .get (
159- f"/download/{ session_id } /{ file_id } " ,
196+ f"/download/{ session_id } /{ modified [ 'id' ] } " ,
160197 headers = auth_headers ,
161198 )
162199 assert download .status_code == 200
0 commit comments