diff --git a/python/ktx-daemon/src/ktx_daemon/telemetry/identity.py b/python/ktx-daemon/src/ktx_daemon/telemetry/identity.py index cfdcee30..f4b31b37 100644 --- a/python/ktx-daemon/src/ktx_daemon/telemetry/identity.py +++ b/python/ktx-daemon/src/ktx_daemon/telemetry/identity.py @@ -27,7 +27,11 @@ def _telemetry_path(home_dir: Path | None = None) -> Path: def _env_disables(env: Mapping[str, str] | None = None) -> bool: source = env or os.environ - return bool(source.get("KTX_TELEMETRY_DISABLED") or source.get("DO_NOT_TRACK")) + return bool( + source.get("KTX_TELEMETRY_DISABLED") + or source.get("DO_NOT_TRACK") + or source.get("CI") + ) def _read_identity(path: Path) -> TelemetryIdentity: diff --git a/python/ktx-daemon/tests/test_telemetry.py b/python/ktx-daemon/tests/test_telemetry.py index f04a9037..a69b7016 100644 --- a/python/ktx-daemon/tests/test_telemetry.py +++ b/python/ktx-daemon/tests/test_telemetry.py @@ -44,17 +44,18 @@ def test_identity_reads_file_with_ttl_cache(tmp_path: Path) -> None: def test_identity_honors_python_env_kill_switches(tmp_path: Path) -> None: - reset_identity_cache() - write_identity(tmp_path) + for kill_switch in ("KTX_TELEMETRY_DISABLED", "DO_NOT_TRACK", "CI"): + reset_identity_cache() + write_identity(tmp_path) - disabled = load_telemetry_identity( - home_dir=tmp_path, - env={"KTX_TELEMETRY_DISABLED": "1"}, - now=lambda: time.monotonic(), - ) + disabled = load_telemetry_identity( + home_dir=tmp_path, + env={kill_switch: "1"}, + now=lambda: time.monotonic(), + ) - assert disabled.enabled is False - assert disabled.install_id == "00000000-0000-4000-8000-000000000000" + assert disabled.enabled is False, f"{kill_switch} should disable telemetry" + assert disabled.install_id == "00000000-0000-4000-8000-000000000000" def test_event_builder_rejects_unknown_fields() -> None: