@@ -90,3 +90,45 @@ async def test_pre_existing_input_used_by_actor(input_file_name: str) -> None:
9090 path_to_input / input_file_name ,
9191 path_to_input / f'{ input_file_name } .__metadata__.json' ,
9292 }
93+
94+
95+ async def test_set_value_with_input_key_targets_existing_input_file () -> None :
96+ """`set_value` with the input key overwrites the existing `INPUT.json` instead of creating a duplicate."""
97+ configuration = Configuration .get_global_configuration ()
98+
99+ # Pre-create a custom-named input file (with extension) before opening the client.
100+ kvs_path = Path (configuration .storage_dir ) / 'key_value_stores' / 'default'
101+ kvs_path .mkdir (parents = True )
102+ (kvs_path / 'INPUT.json' ).write_text (json .dumps ({'foo' : 'bar' }))
103+
104+ client = await ApifyFileSystemKeyValueStoreClient .open (id = None , name = None , alias = None , configuration = configuration )
105+ await client .set_value (key = configuration .input_key , value = {'foo' : 'baz' })
106+
107+ # The existing input file is overwritten in place. No second input file (e.g. `INPUT`) is created.
108+ assert set (kvs_path .glob ('*' )) == {
109+ kvs_path / '__metadata__.json' ,
110+ kvs_path / 'INPUT.json' ,
111+ kvs_path / f'INPUT.json.{ METADATA_FILENAME } ' ,
112+ }
113+
114+ # Reopening must not raise "Only one input file is allowed", i.e. no duplicate input file was created.
115+ client = await ApifyFileSystemKeyValueStoreClient .open (id = None , name = None , alias = None , configuration = configuration )
116+ record = await client .get_value (key = configuration .input_key )
117+ assert record is not None
118+ assert record .value == {'foo' : 'baz' }
119+
120+
121+ async def test_record_exists_and_delete_value_target_existing_input_file () -> None :
122+ """`record_exists` and `delete_value` with the input key operate on the existing `INPUT.json`."""
123+ configuration = Configuration .get_global_configuration ()
124+
125+ kvs_path = Path (configuration .storage_dir ) / 'key_value_stores' / 'default'
126+ kvs_path .mkdir (parents = True )
127+ (kvs_path / 'INPUT.json' ).write_text (json .dumps ({'foo' : 'bar' }))
128+
129+ client = await ApifyFileSystemKeyValueStoreClient .open (id = None , name = None , alias = None , configuration = configuration )
130+ assert await client .record_exists (key = configuration .input_key ) is True
131+
132+ await client .delete_value (key = configuration .input_key )
133+ assert await client .record_exists (key = configuration .input_key ) is False
134+ assert not (kvs_path / 'INPUT.json' ).exists ()
0 commit comments