11import json
2- from pathlib import Path
32from unittest .mock import mock_open , patch
43
54import pytest
65import toml
76
8- from codegen .shared .configs .models .feature_flags import CodebaseFeatureFlags , Config , FeatureFlagsConfig , RepositoryConfig
7+ from codegen .shared .configs .models .feature_flags import CodebaseFeatureFlags , FeatureFlagsConfig
8+ from codegen .shared .configs .models .repository import RepositoryConfig
9+ from codegen .shared .configs .models .session import SessionConfig
910
1011
1112@pytest .fixture
12- def sample_config ():
13+ def sample_config (tmpdir ):
1314 codebase_flags = CodebaseFeatureFlags (debug = True , verify_graph = False )
14- return Config ( repository = RepositoryConfig (organization_name = "test-org" , repo_name = "test-repo" ), feature_flags = FeatureFlagsConfig (codebase = codebase_flags ))
15+ return SessionConfig ( file_path = f" { tmpdir } /test_config.toml" , repository = RepositoryConfig (full_name = "test-org" , repo_name = "test-repo" ), feature_flags = FeatureFlagsConfig (codebase = codebase_flags ))
1516
1617
17- def test_config_initialization ():
18- config = Config ( )
18+ def test_config_initialization (tmpdir ):
19+ config = SessionConfig ( file_path = f" { tmpdir } /test_config.toml" )
1920 assert config .repository is not None
2021 assert config .feature_flags is not None
2122 assert config .secrets is not None
2223
2324
24- def test_config_with_values ():
25- config = Config ( repository = {"organization_name " : "test-org" , "repo_name" : "test-repo" })
26- assert config .repository .organization_name == "test-org"
25+ def test_config_with_values (tmpdir ):
26+ config = SessionConfig ( file_path = f" { tmpdir } /test_config.toml" , repository = {"full_name " : "test-org" , "repo_name" : "test-repo" })
27+ assert config .repository .full_name == "test-org"
2728 assert config .repository .repo_name == "test-repo"
2829
2930
3031@patch ("builtins.open" , new_callable = mock_open )
3132@patch ("pathlib.Path.mkdir" )
3233def test_save_config (mock_mkdir , mock_file , sample_config ):
33- sample_config .save (Path ( "test_config.toml" ) )
34+ sample_config .save ()
3435
3536 mock_mkdir .assert_called_once_with (parents = True , exist_ok = True )
36- mock_file .assert_called_once_with (Path ( "test_config.toml" ) , "w" )
37+ mock_file .assert_called_once_with (sample_config . file_path , "w" )
3738
3839 # Verify the content being written
3940 written_data = mock_file ().write .call_args [0 ][0 ]
4041 parsed_data = toml .loads (written_data )
41- assert parsed_data ["repository" ]["organization_name " ] == "test-org"
42+ assert parsed_data ["repository" ]["full_name " ] == "test-org"
4243
4344
4445def test_get_config_value (sample_config ):
4546 # Test getting a simple value
46- assert json .loads (sample_config .get ("repository.organization_name " )) == "test-org"
47+ assert json .loads (sample_config .get ("repository.full_name " )) == "test-org"
4748
4849 # Test getting a nested value
4950 assert json .loads (sample_config .get ("feature_flags.codebase.debug" )) is True
@@ -56,8 +57,8 @@ def test_set_config_value(sample_config):
5657 # Instead of mocking save, we'll mock the open function used within save
5758 with patch ("builtins.open" , new_callable = mock_open ) as mock_file :
5859 # Test setting a simple string value
59- sample_config .set ("repository.organization_name " , "new-org" )
60- assert sample_config .repository .organization_name == "new-org"
60+ sample_config .set ("repository.full_name " , "new-org" )
61+ assert sample_config .repository .full_name == "new-org"
6162
6263 # Test setting a boolean value
6364 sample_config .set ("feature_flags.codebase.debug" , "false" )
@@ -82,7 +83,7 @@ def test_config_str_representation(sample_config):
8283 assert isinstance (config_str , str )
8384 # Verify it's valid JSON
8485 parsed = json .loads (config_str )
85- assert parsed ["repository" ]["organization_name " ] == "test-org"
86+ assert parsed ["repository" ]["full_name " ] == "test-org"
8687
8788
8889def test_set_config_new_override_key (sample_config ):
0 commit comments