fix(telemetry): respect CI kill switch in python daemon identity

This commit is contained in:
Andrey Avtomonov 2026-05-22 17:51:08 +02:00
parent db7757df32
commit 5e6b235979
2 changed files with 15 additions and 10 deletions

View file

@ -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:

View file

@ -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: