Files
DeepTutor/tests/core/test_config_manager.py
Scarlet Moore cddc5160e8 work/llm-error-framework (#35)
* feat: enhance error handling and logging in DocumentAdder

* feat: implement robust error handling utilities for API exceptions

* style: fix formatting issues

* feat: implement retry logic for LLM API calls to handle rate limits and timeouts

* feat: enhance document validation and error handling in file uploads

* feat: enhance valid tools configuration and error handling in project structure

* feat: refactor error handling and validation functions for improved robustness

* fix: pre-commit format

* feat: implement configuration validation for tool consistency and enhance error handling in file uploads

* feat: add exception hierarchy for LLM service errors to improve error handling

* chore: update repo roster images [skip ci]

* chore: update repo roster images [skip ci]

* Integrate documentation updates and rebase onto upstream dev

* Implement error handling utilities and validation functions

* feat: implement multi-provider support with enhanced capability handling and model extraction

* fix: enhance error handling and validation across multiple modules

* chore: remove unused local environment configuration file

* commit

* fix: improve error handling and logging in utilities and error handler

* fix: enhance error handling and logging across multiple modules

* fix: enhance async initialization and validation in multiple modules

* feat: implement LLM error framework

- Add LLM-specific exception classes in exceptions.py
- Create error mapping utilities for standardized error handling
- Implement base provider interface with error handling
- Add OpenAI provider implementation with error mapping
- Define LLM types and response structures

* feat: add missing registry and telemetry modules

- Add registry.py for provider registration system
- Add telemetry.py for basic LLM call tracking
- Complete the LLM error framework implementation

* fix(llm): safer sync wrapper + smarter retries + optional openai mapping

* Fix LLM error framework and code quality improvements

* feat: update environment configuration and improve logging in LLM services

* Update README.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Refactor code structure for improved readability and maintainability

* chore: update documentation, improve error handling, and enhance file upload validation

* feat: enhance error handling and configuration validation across multiple modules

* feat: add configuration for pytest, improve error handling, and enhance byte formatting utilities

---------

Co-authored-by: scrrlt <smo0051@student.monash.edu>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-01-13 16:58:13 +11:00

63 lines
1.9 KiB
Python

from pathlib import Path
import yaml
from src.utils.config_manager import ConfigManager
def write_yaml(path: Path, data: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8")
def test_atomic_save_and_deep_merge(tmp_path: Path):
project = tmp_path
cfg_path = project / "config" / "main.yaml"
base_cfg = {
"llm": {"model": "Pro/Flash", "provider": "openai"},
"paths": {
"user_data_dir": "./data/user",
"knowledge_bases_dir": "./data/knowledge_bases",
"user_log_dir": "./data/user/logs",
},
}
write_yaml(cfg_path, base_cfg)
cm = ConfigManager(project_root=project)
loaded = cm.load_config(force_reload=True)
assert loaded["llm"]["model"] == "Pro/Flash"
# Deep merge update
assert cm.save_config({"llm": {"model": "Other"}, "features": {"enable_solve": True}})
# Backup exists
assert (project / "config" / "main.yaml.bak").exists()
updated = cm.load_config(force_reload=True)
assert updated["llm"]["model"] == "Other"
assert updated["llm"]["provider"] == "openai"
assert updated["features"]["enable_solve"] is True
def test_env_layering(tmp_path: Path):
project = tmp_path
(project / ".env").write_text("LLM_MODEL=Base\n", encoding="utf-8")
(project / ".env.local").write_text("LLM_MODEL=Override\n", encoding="utf-8")
# Minimal valid config for schema
cfg_path = project / "config" / "main.yaml"
base_cfg = {
"llm": {"model": "Pro/Flash", "provider": "openai"},
"paths": {
"user_data_dir": "./data/user",
"knowledge_bases_dir": "./data/knowledge_bases",
"user_log_dir": "./data/user/logs",
},
}
write_yaml(cfg_path, base_cfg)
cm = ConfigManager(project_root=project)
env = cm.get_env_info()
assert env["model"] == "Override"