fix: validate project path key, avoid shared mutable default
This commit is contained in:
+3
-1
@@ -13,7 +13,9 @@ def load_config(path=CONFIG_PATH):
|
|||||||
if not cfg or 'projects' not in cfg or not cfg['projects']:
|
if not cfg or 'projects' not in cfg or not cfg['projects']:
|
||||||
raise ConfigError(f"'projects' list is required in {path}")
|
raise ConfigError(f"'projects' list is required in {path}")
|
||||||
for p in cfg['projects']:
|
for p in cfg['projects']:
|
||||||
p.setdefault('benchmarks', DEFAULTS['benchmarks'])
|
if not isinstance(p, dict) or 'path' not in p:
|
||||||
|
raise ConfigError(f"Each project must have a 'path' key, got: {p!r}")
|
||||||
|
p.setdefault('benchmarks', list(DEFAULTS['benchmarks']))
|
||||||
p.setdefault('time_limit_minutes', DEFAULTS['time_limit_minutes'])
|
p.setdefault('time_limit_minutes', DEFAULTS['time_limit_minutes'])
|
||||||
p['path'] = os.path.expanduser(p['path'])
|
p['path'] = os.path.expanduser(p['path'])
|
||||||
cfg.setdefault('token_threshold', {'context_remaining_pct': 60, 'api_budget_usd': 5.0})
|
cfg.setdefault('token_threshold', {'context_remaining_pct': 60, 'api_budget_usd': 5.0})
|
||||||
|
|||||||
@@ -23,6 +23,18 @@ def test_missing_projects_raises():
|
|||||||
load_config(name)
|
load_config(name)
|
||||||
os.unlink(name)
|
os.unlink(name)
|
||||||
|
|
||||||
|
def test_project_missing_path_raises():
|
||||||
|
data = {
|
||||||
|
'projects': [{'benchmarks': ['echo ok']}], # no 'path' key
|
||||||
|
'token_threshold': {'context_remaining_pct': 60, 'api_budget_usd': 5.0}
|
||||||
|
}
|
||||||
|
with tempfile.NamedTemporaryFile('w', suffix='.yaml', delete=False) as f:
|
||||||
|
yaml.dump(data, f)
|
||||||
|
name = f.name
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
load_config(name)
|
||||||
|
os.unlink(name)
|
||||||
|
|
||||||
def test_expands_tilde_in_path():
|
def test_expands_tilde_in_path():
|
||||||
data = {
|
data = {
|
||||||
'projects': [{'path': '~/.claude', 'benchmarks': [], 'time_limit_minutes': 5}],
|
'projects': [{'path': '~/.claude', 'benchmarks': [], 'time_limit_minutes': 5}],
|
||||||
|
|||||||
Reference in New Issue
Block a user