mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
fix(telemetry): make python identity env={} bypass os.environ and unset CI in tests
This commit is contained in:
parent
cdcadca1e1
commit
14431c01ee
4 changed files with 10 additions and 4 deletions
|
|
@ -26,7 +26,7 @@ def _telemetry_path(home_dir: Path | None = None) -> Path:
|
|||
|
||||
|
||||
def _env_disables(env: Mapping[str, str] | None = None) -> bool:
|
||||
source = env or os.environ
|
||||
source = os.environ if env is None else env
|
||||
return bool(
|
||||
source.get("KTX_TELEMETRY_DISABLED")
|
||||
or source.get("DO_NOT_TRACK")
|
||||
|
|
|
|||
|
|
@ -106,6 +106,9 @@ def test_app_lifespan_emits_daemon_lifecycle_debug_events(
|
|||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.setenv("KTX_TELEMETRY_DEBUG", "1")
|
||||
monkeypatch.setenv("KTX_DAEMON_VERSION", "0.4.1")
|
||||
monkeypatch.delenv("CI", raising=False)
|
||||
monkeypatch.delenv("KTX_TELEMETRY_DISABLED", raising=False)
|
||||
monkeypatch.delenv("DO_NOT_TRACK", raising=False)
|
||||
|
||||
with TestClient(
|
||||
create_app(telemetry_started_at=100.0, clock=lambda: 100.125)
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ def test_query_semantic_layer_emits_plan_and_sql_debug_events(
|
|||
)
|
||||
monkeypatch.setenv("HOME", str(tmp_path))
|
||||
monkeypatch.setenv("KTX_TELEMETRY_DEBUG", "1")
|
||||
monkeypatch.delenv("CI", raising=False)
|
||||
monkeypatch.delenv("KTX_TELEMETRY_DISABLED", raising=False)
|
||||
monkeypatch.delenv("DO_NOT_TRACK", raising=False)
|
||||
|
||||
query_semantic_layer(
|
||||
SemanticLayerQueryRequest(
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@ def test_identity_reads_file_with_ttl_cache(tmp_path: Path) -> None:
|
|||
reset_identity_cache()
|
||||
write_identity(tmp_path)
|
||||
|
||||
first = load_telemetry_identity(home_dir=tmp_path, now=lambda: 100.0)
|
||||
first = load_telemetry_identity(home_dir=tmp_path, env={}, now=lambda: 100.0)
|
||||
assert first.enabled is True
|
||||
assert first.install_id == "00000000-0000-4000-8000-000000000000"
|
||||
|
||||
write_identity(tmp_path, enabled=False)
|
||||
cached = load_telemetry_identity(home_dir=tmp_path, now=lambda: 120.0)
|
||||
cached = load_telemetry_identity(home_dir=tmp_path, env={}, now=lambda: 120.0)
|
||||
assert cached.enabled is True
|
||||
|
||||
refreshed = load_telemetry_identity(home_dir=tmp_path, now=lambda: 161.0)
|
||||
refreshed = load_telemetry_identity(home_dir=tmp_path, env={}, now=lambda: 161.0)
|
||||
assert refreshed.enabled is False
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue