Official Codebase of 3DCodeVerse
Python
config: a config file that is not a mapping is a bad configuration, not a traceback
gaoypeng7ae2caba6680
diff --git a/harness/codeverse3d/config.py b/harness/codeverse3d/config.pyindex baa36b61..e3ff7e3f 100644--- a/harness/codeverse3d/config.py+++ b/harness/codeverse3d/config.py@@ -387,10 +387,19 @@ class Settings(BaseSettings):def _load_yaml(path: Path) -> dict:+ """A config file's mapping; a file that is not one is a ``ValueError`` naming it (the CLI+ reports that as a bad configuration — a YAML syntax error or a top-level list used to+ escape every command as a raw traceback)."""if not path.is_file():return {}- with path.open() as fh:- return yaml.safe_load(fh) or {}+ try:+ with path.open() as fh:+ data = yaml.safe_load(fh) or {}+ except yaml.YAMLError as e:+ raise ValueError(f"{path}: not valid YAML: {e}") from e+ if not isinstance(data, dict):+ raise ValueError(f"{path}: expected a mapping of settings, got a {type(data).__name__}")+ return datadef _legacy_gemini_keys() -> list[str]:diff --git a/harness/tests/flywheel_cli/test_cli.py b/harness/tests/flywheel_cli/test_cli.pyindex e94d37ce..63bd4826 100644--- a/harness/tests/flywheel_cli/test_cli.py+++ b/harness/tests/flywheel_cli/test_cli.py@@ -493,3 +493,17 @@ def test_make_refuses_a_blank_prompt(tmp_path: Path):assert not (tmp_path / "runs").exists() or not any((tmp_path / "runs").iterdir())[email protected]("text", ["judge: [unclosed\n", "- a\n- list\n"], ids=["syntax", "list"])+def test_a_config_file_that_is_not_a_mapping_is_a_bad_configuration(tmp_path: Path, monkeypatch, text: str):+ from codeverse3d import config++ (tmp_path / "3dcodeverse.yaml").write_text(text)+ monkeypatch.chdir(tmp_path)+ config.get_settings.cache_clear()+ try:+ r = runner.invoke(app, ["cost", "profiles"])+ finally:+ config.get_settings.cache_clear()+ assert r.exit_code == 2 and "bad configuration" in r.output and "3dcodeverse.yaml" in r.output++