99 RepomixConfigOutput ,
1010 RepomixOutputStyle ,
1111)
12+ from src .repomix .config .config_load import migrate_config_format
1213
1314
1415class TestRepomixConfigOutput :
@@ -281,7 +282,7 @@ def test_advanced_output_options_configuration(self):
281282 "truncate_base64" : True ,
282283 "include_empty_directories" : True ,
283284 "include_diffs" : True ,
284- "style" : "xml"
285+ "style" : "xml" ,
285286 }
286287 }
287288
@@ -309,12 +310,13 @@ def test_advanced_output_options_json_serialization(self):
309310 "truncate_base64" : True ,
310311 "include_empty_directories" : False ,
311312 "include_diffs" : True ,
312- "copy_to_clipboard" : True
313+ "copy_to_clipboard" : True ,
313314 }
314315 }
315316
316317 # Convert to JSON and back to simulate config file loading
317318 import json
319+
318320 json_str = json .dumps (original_config )
319321 loaded_dict = json .loads (json_str )
320322 config = RepomixConfig (** loaded_dict )
@@ -332,5 +334,79 @@ def test_advanced_output_options_json_serialization(self):
332334 assert config .output .copy_to_clipboard is True
333335
334336
337+ class TestConfigMigration :
338+ """Test cases for configuration migration functionality"""
339+
340+ def test_style_migration_from_underscore_style (self ):
341+ """Test that _style is properly migrated to style"""
342+ old_config = {
343+ "output" : {"file_path" : "repomix-output.md" , "_style" : "markdown" , "header_text" : "" , "remove_comments" : False },
344+ "security" : {"enable_security_check" : True },
345+ }
346+
347+ migrated = migrate_config_format (old_config )
348+
349+ # Check that _style was converted to style
350+ assert "_style" not in migrated ["output" ]
351+ assert migrated ["output" ]["style" ] == "markdown"
352+
353+ # Verify we can create RepomixConfig with migrated data
354+ config_obj = RepomixConfig (** migrated )
355+ assert config_obj .output .style == "markdown"
356+ assert config_obj .output .style_enum == RepomixOutputStyle .MARKDOWN
357+
358+ def test_style_migration_with_both_style_and_underscore_style (self ):
359+ """Test that _style is removed when both _style and style are present"""
360+ config_with_both = {"output" : {"_style" : "xml" , "style" : "markdown" }}
361+
362+ migrated = migrate_config_format (config_with_both )
363+ assert "_style" not in migrated ["output" ]
364+ assert migrated ["output" ]["style" ] == "markdown"
365+
366+ def test_migration_preserves_new_format (self ):
367+ """Test that new config format without _style is unchanged"""
368+ new_config = {"output" : {"style" : "xml" , "file_path" : "output.xml" }}
369+
370+ migrated = migrate_config_format (new_config )
371+ assert migrated ["output" ]["style" ] == "xml"
372+ assert "_style" not in migrated ["output" ]
373+
374+ def test_migration_with_real_user_config (self ):
375+ """Test with the actual problematic config from user"""
376+ user_config = {
377+ "output" : {
378+ "file_path" : "repomix-output.md" ,
379+ "_style" : "markdown" ,
380+ "header_text" : "" ,
381+ "instruction_file_path" : "" ,
382+ "remove_comments" : False ,
383+ "remove_empty_lines" : False ,
384+ "top_files_length" : 5 ,
385+ "show_line_numbers" : False ,
386+ "copy_to_clipboard" : False ,
387+ "include_empty_directories" : False ,
388+ "calculate_tokens" : False ,
389+ "show_file_stats" : False ,
390+ "show_directory_structure" : True ,
391+ },
392+ "security" : {"enable_security_check" : True , "exclude_suspicious_files" : True },
393+ "ignore" : {"custom_patterns" : [], "use_gitignore" : True , "use_default_ignore" : True },
394+ "include" : [],
395+ }
396+
397+ migrated = migrate_config_format (user_config )
398+
399+ # Verify migration
400+ assert "_style" not in migrated ["output" ]
401+ assert migrated ["output" ]["style" ] == "markdown"
402+
403+ # Test that we can create RepomixConfig with migrated data
404+ config_obj = RepomixConfig (** migrated )
405+ assert config_obj .output .style == "markdown"
406+ assert config_obj .output .style_enum == RepomixOutputStyle .MARKDOWN
407+ assert config_obj .output .top_files_length == 5
408+ assert config_obj .security .enable_security_check is True
409+
410+
335411if __name__ == "__main__" :
336412 pytest .main ([__file__ ])
0 commit comments