diff --git a/CHANGELOG.md b/CHANGELOG.md index f7599c0..cf0f192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Fixed + +- A `[budgets]` section in `tracepanel.toml` (or `[tool.tracepanel.budgets]`) + is the agent's `check`, not an unknown setting. + ## 0.17.0 (2026-11-20) Needs `tracepanel-agent` 0.17.0 (installed with it). diff --git a/src/tracepanel/core/conf.py b/src/tracepanel/core/conf.py index 38eb486..37c1a68 100644 --- a/src/tracepanel/core/conf.py +++ b/src/tracepanel/core/conf.py @@ -310,6 +310,8 @@ class ConfigError(ValueError): FILES = ("tracepanel.toml", "pyproject.toml") +# Sections of the file that are not the SDK's settings: the agent's `check` reads the budgets. +NOT_SETTINGS = frozenset({"budgets"}) def find_file(start: Path) -> tuple[Path, dict[str, object]] | None: @@ -320,15 +322,20 @@ def find_file(start: Path) -> tuple[Path, dict[str, object]] | None: for directory in (start, *start.parents): tracepanel_toml = directory / "tracepanel.toml" if tracepanel_toml.is_file(): - return tracepanel_toml, _read_toml(tracepanel_toml) + return tracepanel_toml, _settings(_read_toml(tracepanel_toml)) pyproject = directory / "pyproject.toml" if pyproject.is_file(): section = _read_toml(pyproject).get("tool", {}) settings = section.get("tracepanel") if isinstance(section, dict) else None - return (pyproject, dict(settings)) if isinstance(settings, dict) else None + return (pyproject, _settings(settings)) if isinstance(settings, dict) else None return None +def _settings(values: dict[str, object]) -> dict[str, object]: + """The file's settings, without the sections other tools read there (NOT_SETTINGS).""" + return {name: value for name, value in values.items() if name not in NOT_SETTINGS} + + def _read_toml(path: Path) -> dict[str, object]: try: return tomllib.loads(path.read_text()) diff --git a/tests/core/test_conf.py b/tests/core/test_conf.py index ad5ba5e..d75b7e7 100644 --- a/tests/core/test_conf.py +++ b/tests/core/test_conf.py @@ -187,6 +187,18 @@ def test_bad_file_values_name_the_file(project: Path) -> None: loaded() +def test_the_agents_budgets_in_the_file_are_not_settings(project: Path) -> None: + (project / "tracepanel.toml").write_text('slow_sql_ms = 50\n\n[budgets."GET /api/*"]\nsql_max = 10\n') + (project / "pyproject.toml").write_text("[tool.tracepanel]\n\n[tool.tracepanel.budgets]\nsql_max = 10\n") + + assert loaded().slow_sql_ms == 50 + + (project / "tracepanel.toml").unlink() + conf.reset() + + assert loaded().slow_sql_ms == 100 # the default + + def test_integrations_can_be_turned_off(project: Path, monkeypatch: pytest.MonkeyPatch) -> None: (project / "tracepanel.toml").write_text("celery_enabled = false\n")