Skip to content

Commit 1e1e51d

Browse files
authored
fix: update missed CodebaseGraph rename (#428)
1 parent a815763 commit 1e1e51d

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

tests/unit/codegen/sdk/core/test_directory.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212

1313

1414
@pytest.fixture
15-
def mock_codebase_context(tmp_path):
15+
def mock_codebase_graph(tmp_path):
1616
mock = MagicMock(spec=CodebaseContext)
1717
mock.transaction_manager = MagicMock()
1818
mock.config = CodebaseConfig()
1919
mock.repo_path = tmp_path
2020
mock.to_absolute = types.MethodType(CodebaseContext.to_absolute, mock)
2121
mock.to_relative = types.MethodType(CodebaseContext.to_relative, mock)
22+
mock.io = MagicMock()
2223
return mock
2324

2425

@@ -34,17 +35,17 @@ def dir_path(tmp_path):
3435

3536
@pytest.fixture
3637
def sub_dir(subdir_path, tmp_path):
37-
return Directory(path=subdir_path.absolute(), dirpath=subdir_path.relative_to(tmp_path), parent=None)
38+
return Directory(path=subdir_path.absolute(), dirpath=str(subdir_path.relative_to(tmp_path)), parent=None)
3839

3940

4041
@pytest.fixture
4142
def mock_file(dir_path, mock_codebase_graph):
42-
return File(filepath=dir_path / "example.py", G=mock_codebase_graph)
43+
return File(filepath=dir_path / "example.py", ctx=mock_codebase_graph)
4344

4445

4546
@pytest.fixture
4647
def mock_directory(tmp_path, dir_path, sub_dir, mock_file):
47-
directory = Directory(path=dir_path.absolute(), dirpath=dir_path.relative_to(tmp_path), parent=None)
48+
directory = Directory(path=dir_path.absolute(), dirpath=str(dir_path.relative_to(tmp_path)), parent=None)
4849
directory.add_file(mock_file)
4950
directory.add_subdirectory(sub_dir)
5051
return directory
@@ -53,7 +54,7 @@ def mock_directory(tmp_path, dir_path, sub_dir, mock_file):
5354
def test_directory_init(tmp_path, mock_directory):
5455
"""Test initialization of Directory object."""
5556
assert mock_directory.path == tmp_path / "mock_dir"
56-
assert mock_directory.dirpath == Path("mock_dir")
57+
assert mock_directory.dirpath == "mock_dir"
5758
assert mock_directory.parent is None
5859
assert len(mock_directory.items) == 2
5960
assert mock_directory.items["subdir"] is not None
@@ -67,7 +68,7 @@ def test_name_property(mock_directory):
6768

6869
def test_add_and_file(mock_directory, mock_codebase_graph):
6970
"""Test adding a file to the directory."""
70-
mock_file = File(filepath=Path("mock_dir/example_2.py"), G=mock_codebase_graph)
71+
mock_file = File(filepath=Path("mock_dir/example_2.py"), ctx=mock_codebase_graph)
7172
mock_directory.add_file(mock_file)
7273
rel_path = os.path.relpath(mock_file.file_path, mock_directory.dirpath)
7374
assert rel_path in mock_directory.items
@@ -84,7 +85,7 @@ def test_remove_file(mock_directory, mock_file):
8485

8586
def test_remove_file_by_path(mock_directory, mock_file):
8687
"""Test removing a file by path."""
87-
mock_directory.remove_file_by_path(mock_file.file_path)
88+
mock_directory.remove_file_by_path(Path(mock_file.file_path))
8889

8990
rel_path = os.path.relpath(mock_file.file_path, mock_directory.dirpath)
9091
assert rel_path not in mock_directory.items
@@ -108,7 +109,7 @@ def test_get_file_not_found(mock_directory):
108109
def test_add_subdirectory(mock_directory, dir_path):
109110
"""Test adding a subdirectory."""
110111
new_subdir_path = dir_path / "new_subdir"
111-
subdir = Directory(path=new_subdir_path.absolute(), dirpath=new_subdir_path.relative_to(dir_path), parent=mock_directory)
112+
subdir = Directory(path=new_subdir_path.absolute(), dirpath=str(new_subdir_path.relative_to(dir_path)), parent=mock_directory)
112113
mock_directory.add_subdirectory(subdir)
113114
rel_path = os.path.relpath(subdir.dirpath, mock_directory.dirpath)
114115
assert rel_path in mock_directory.items
@@ -143,7 +144,7 @@ def test_files_property(mock_directory, sub_dir, mock_codebase_graph):
143144
all_files = mock_directory.files
144145
assert len(all_files) == 1
145146

146-
new_file = File(filepath=Path("mock_dir/example_2.py"), G=mock_codebase_graph)
147+
new_file = File(filepath=Path("mock_dir/example_2.py"), ctx=mock_codebase_graph)
147148
sub_dir.add_file(new_file)
148149

149150
all_files = mock_directory.files
@@ -162,7 +163,7 @@ def test_subdirectories_property(mock_directory, sub_dir):
162163
assert len(all_subdirs) == 1
163164
assert sub_dir in all_subdirs
164165

165-
new_sub_dir = Directory(path=sub_dir.path / "new_subdir", dirpath=sub_dir.dirpath / "new_subdir", parent=sub_dir)
166+
new_sub_dir = Directory(path=sub_dir.path / "new_subdir", dirpath=str(Path(sub_dir.dirpath) / "new_subdir"), parent=sub_dir)
166167
sub_dir.add_subdirectory(new_sub_dir)
167168

168169
all_subdirs = mock_directory.subdirectories

tests/unit/codegen/shared/configs/test_config.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,31 @@ def test_merge_configs_none_values():
3434

3535

3636
def test_merge_configs_empty_string():
37-
base = {"repository": {"organization_name": "org1"}}
38-
override = {"repository": {"organization_name": ""}}
37+
base = {"repository": {"full_name": "org1/test-repo"}}
38+
override = {"repository": {"full_name": ""}}
3939
result = _merge_configs(base, override)
40-
assert result == {"repository": {"organization_name": "org1"}}
40+
assert result == {"repository": {"full_name": "org1/test-repo"}}
4141

4242

4343
# Test _load_from_toml
4444
def test_load_from_toml_existing_file(temp_config_file):
4545
config = _load_from_toml(temp_config_file)
4646
assert isinstance(config, SessionConfig)
4747
assert config.secrets.github_token == "gh_token123"
48-
assert config.repository.organization_name == "test-org"
48+
assert config.repository.repo_name == "test-repo"
4949
assert config.feature_flags.codebase.debug is True
5050
assert config.feature_flags.codebase.typescript.ts_dependency_manager is True
5151
assert config.feature_flags.codebase.import_resolution_overrides == {"@org/pkg": "./local/path"}
5252

5353

54-
@patch("codegen.shared.configs.models.SecretsConfig.model_config", {"env_file": "nonexistent.env"})
54+
@patch.dict("os.environ", {})
55+
@patch("codegen.shared.configs.models.secrets.SecretsConfig.model_config", {"env_file": "nonexistent.env"})
5556
def test_load_from_toml_nonexistent_file():
5657
config = _load_from_toml(Path("nonexistent.toml"))
5758
assert isinstance(config, SessionConfig)
5859
assert config.secrets.github_token is None
59-
assert config.repository.organization_name is None
60-
assert config.feature_flags.codebase.debug is None
60+
assert config.repository.full_name is None
61+
assert config.feature_flags.codebase.debug is False
6162

6263

6364
# Test _load_from_env
@@ -71,31 +72,21 @@ def test_load_from_env():
7172

7273
# Test load function
7374
@patch.dict("os.environ", {}, clear=True) # Clear all env vars for this test
74-
@patch("codegen.shared.configs.config._load_from_env")
75-
@patch("codegen.shared.configs.config._load_from_toml")
76-
@patch("codegen.shared.configs.models.SecretsConfig.model_config", {"env_file": None, "env_prefix": "CODEGEN_SECRETS__"})
75+
@patch("codegen.shared.configs.session_configs._load_from_env")
76+
@patch("codegen.shared.configs.session_configs._load_from_toml")
77+
@patch("codegen.shared.configs.models.secrets.SecretsConfig.model_config", {"env_file": None, "env_prefix": "CODEGEN_SECRETS__"})
7778
def test_load_with_both_configs(mock_toml, mock_env):
7879
# Setup mock returns
79-
mock_env.return_value = SessionConfig(secrets=SecretsConfig(github_token="env_token"), feature_flags=FeatureFlagsConfig(codebase=CodebaseFeatureFlags(debug=True)))
80-
mock_toml.return_value = SessionConfig(secrets={"openai_api_key": "openai_key"}, repository={"organization_name": "codegen-org"})
80+
mock_env.return_value = SessionConfig(file_path=str(CONFIG_PATH), secrets=SecretsConfig(github_token="env_token"), feature_flags=FeatureFlagsConfig(codebase=CodebaseFeatureFlags(debug=True)))
81+
mock_toml.return_value = SessionConfig(file_path=str(CONFIG_PATH), secrets={"openai_api_key": "openai_key"}, repository={"full_name": "codegen-org/test-repo"})
8182

8283
config = load_session_config(CONFIG_PATH)
8384

8485
assert isinstance(config, SessionConfig)
8586
assert config.secrets.github_token == "env_token"
8687
assert config.secrets.openai_api_key == "openai_key"
87-
assert config.repository.organization_name == "codegen-org"
88-
assert config.feature_flags.codebase.debug is True
89-
90-
91-
@patch("codegen.shared.configs.config._load_from_env")
92-
@patch("codegen.shared.configs.config._load_from_toml")
93-
def test_load_with_custom_path(mock_toml, mock_env):
94-
custom_path = Path("custom/config.toml")
95-
load_session_config(config_path=custom_path)
96-
97-
mock_toml.assert_called_once_with(custom_path)
98-
mock_env.assert_called_once()
88+
assert config.repository.full_name == "codegen-org/test-repo"
89+
assert config.feature_flags.codebase.debug is False
9990

10091

10192
# Error cases

tests/unit/codegen/shared/configs/test_models.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
import toml
66

7+
from codegen.shared.configs.constants import CONFIG_PATH
78
from codegen.shared.configs.models.feature_flags import CodebaseFeatureFlags, FeatureFlagsConfig
89
from codegen.shared.configs.models.repository import RepositoryConfig
910
from codegen.shared.configs.models.session import SessionConfig
@@ -12,7 +13,7 @@
1213
@pytest.fixture
1314
def sample_config(tmpdir):
1415
codebase_flags = CodebaseFeatureFlags(debug=True, verify_graph=False)
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))
16+
return SessionConfig(file_path=str(CONFIG_PATH), repository=RepositoryConfig(full_name="test-org/test-repo", repo_name="test-repo"), feature_flags=FeatureFlagsConfig(codebase=codebase_flags))
1617

1718

1819
def test_config_initialization(tmpdir):
@@ -22,9 +23,9 @@ def test_config_initialization(tmpdir):
2223
assert config.secrets is not None
2324

2425

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"
26+
def test_config_with_values():
27+
config = SessionConfig(file_path=str(CONFIG_PATH), repository={"full_name": "test-org/test-repo", "repo_name": "test-repo"})
28+
assert config.repository.full_name == "test-org/test-repo"
2829
assert config.repository.repo_name == "test-repo"
2930

3031

@@ -39,12 +40,12 @@ def test_save_config(mock_mkdir, mock_file, sample_config):
3940
# Verify the content being written
4041
written_data = mock_file().write.call_args[0][0]
4142
parsed_data = toml.loads(written_data)
42-
assert parsed_data["repository"]["full_name"] == "test-org"
43+
assert parsed_data["repository"]["full_name"] == "test-org/test-repo"
4344

4445

4546
def test_get_config_value(sample_config):
4647
# Test getting a simple value
47-
assert json.loads(sample_config.get("repository.full_name")) == "test-org"
48+
assert json.loads(sample_config.get("repository.full_name")) == "test-org/test-repo"
4849

4950
# Test getting a nested value
5051
assert json.loads(sample_config.get("feature_flags.codebase.debug")) is True
@@ -57,8 +58,8 @@ def test_set_config_value(sample_config):
5758
# Instead of mocking save, we'll mock the open function used within save
5859
with patch("builtins.open", new_callable=mock_open) as mock_file:
5960
# Test setting a simple string value
60-
sample_config.set("repository.full_name", "new-org")
61-
assert sample_config.repository.full_name == "new-org"
61+
sample_config.set("repository.full_name", "new-org/test-repo")
62+
assert sample_config.repository.full_name == "new-org/test-repo"
6263

6364
# Test setting a boolean value
6465
sample_config.set("feature_flags.codebase.debug", "false")
@@ -83,7 +84,7 @@ def test_config_str_representation(sample_config):
8384
assert isinstance(config_str, str)
8485
# Verify it's valid JSON
8586
parsed = json.loads(config_str)
86-
assert parsed["repository"]["full_name"] == "test-org"
87+
assert parsed["repository"]["full_name"] == "test-org/test-repo"
8788

8889

8990
def test_set_config_new_override_key(sample_config):

0 commit comments

Comments
 (0)