Skip to content

let your agent control your phone

Send telemetry from other CI runs again. (#128)

shawn pana8ad9a8b764c5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1a2ee00..27c90b2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,6 +6,9 @@ on:
push:
branches: [main]
+env:
+ PHONE_HARNESS_TELEMETRY: "0"
+
jobs:
install:
strategy:
diff --git a/install.md b/install.md
index 640b437..db8a39b 100644
--- a/install.md
+++ b/install.md
@@ -138,7 +138,6 @@ the iPhone is driven through the mirroring window, the Android over adb. A
cloud iPhone is a third path: HTTPS ops, covered in the skill.
`phone-harness config set telemetry false` turns off anonymous usage telemetry.
-Runs in CI do not send telemetry.
## If It Fails
diff --git a/integrations/hermes/README.md b/integrations/hermes/README.md
index 2f0f1e0..e7c12dc 100644
--- a/integrations/hermes/README.md
+++ b/integrations/hermes/README.md
@@ -50,7 +50,7 @@ covers each.
- Plugin setting `classifier_auto_run` (boolean, default false).
- Or export `PHONE_HARNESS_CLASSIFIER_AUTO_RUN=1` in the environment Hermes
runs in. When that variable is set, it wins over the plugin setting.
-- Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`. Runs in CI do not send telemetry.
+- Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`.
- `PHONE_HARNESS_PLATFORM`, when you have exported it, is passed through.
- The agent workspace is one folder, `agent-workspace`, in Hermes's plugin
data directory. If `PH_AGENT_WORKSPACE` is already set, that path is used
@@ -69,7 +69,7 @@ covers each.
After 120 s the tool reports the phone as busy.
4. The plugin pipes the script on stdin to the phone-harness Hermes installed,
with `PH_AGENT_WORKSPACE` and `PH_CLIENT=hermes`. It does not set a platform.
- Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`. Runs in CI do not send telemetry.
+ Telemetry is off for Hermes runs unless you opt in with `phone-harness config set telemetry true`.
5. The result is what the script printed, plus the exit code and the tail of
stderr. `screenshot()` prints the path it saved. The last absolute PNG,
JPEG, or WebP path in that output that exists and was written during the
diff --git a/src/phone_harness/telemetry.py b/src/phone_harness/telemetry.py
index d8be858..876146f 100644
--- a/src/phone_harness/telemetry.py
+++ b/src/phone_harness/telemetry.py
@@ -4,8 +4,7 @@ One `cli_event` per CLI invocation, sent to PostHog from a detached helper
process so the CLI never blocks on the network.
Off: `phone-harness config set telemetry false`, or PHONE_HARNESS_TELEMETRY=0
-for one call. A run in CI does not send telemetry. The install id lives in
-the state dir; see config.py.
+for one call. The install id lives in the state dir; see config.py.
"""
from __future__ import annotations
@@ -31,21 +30,7 @@ def _version() -> str:
return ""
-def _in_ci() -> bool:
- """GitHub Actions, GitLab, CircleCI, and others set CI=true.
-
- Empty, 0, and false are not CI. Anything else set on CI is.
- """
- value = os.environ.get("CI")
- if value is None:
- return False
- return value.strip().lower() not in ("", "0", "false")
-
-
def is_enabled() -> bool:
- # CI never sends. An explicit opt-in does not turn it back on.
- if _in_ci():
- return False
return bool(_config.get("telemetry"))
diff --git a/tests/support/sitecustomize.py b/tests/support/sitecustomize.py
index 63dd2ca..6d7fe30 100644
--- a/tests/support/sitecustomize.py
+++ b/tests/support/sitecustomize.py
@@ -3,10 +3,12 @@
Installed before phone_harness so `cloud start`, `cloud watch`, and `cloud open`
record the URL instead of calling a real browser. The update check stays off:
a test must not call PyPI, and a failure there must not fail the suite.
+Telemetry stays off so a test subprocess does not post a usage event.
"""
import os
import browser_recorder
os.environ.setdefault("PHONE_HARNESS_NO_UPDATE_CHECK", "1")
+os.environ.setdefault("PHONE_HARNESS_TELEMETRY", "0")
browser_recorder.install()
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 8df3fcb..583d98b 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -472,7 +472,8 @@ class TelemetryDefault(unittest.TestCase):
with mock.patch.dict(os.environ, {"PHONE_HARNESS_HOME": home.name}, clear=False):
os.environ.pop("PHONE_HARNESS_TELEMETRY", None)
- # GitHub Actions sets CI=true. This test is the non-CI default.
+ # GitHub Actions sets CI=true, and this repo's workflow sets
+ # PHONE_HARNESS_TELEMETRY=0. This test is the ordinary default.
os.environ.pop("CI", None)
self.assertEqual(lookup("telemetry"), (True, "default"))
self.assertTrue(get("telemetry"))
diff --git a/tests/test_hermes_plugin.py b/tests/test_hermes_plugin.py
index 95fc72c..952e3df 100644
--- a/tests/test_hermes_plugin.py
+++ b/tests/test_hermes_plugin.py
@@ -463,8 +463,9 @@ class TelemetryOptIn(Base):
self.saved = dict(os.environ)
os.environ["PHONE_HARNESS_HOME"] = str(self.data)
os.environ.pop("PHONE_HARNESS_TELEMETRY", None)
- # GitHub Actions sets CI=true. These checks are the non-CI opt-in rules,
- # including the child process that would otherwise inherit CI and not send.
+ # GitHub Actions sets CI=true, and this repo's workflow sets
+ # PHONE_HARNESS_TELEMETRY=0. These checks are the ordinary opt-in rules,
+ # including the child process.
os.environ.pop("CI", None)
self.addCleanup(self.restore_env)
diff --git a/tests/test_skill.py b/tests/test_skill.py
index a4b853f..df5b47e 100644
--- a/tests/test_skill.py
+++ b/tests/test_skill.py
@@ -25,6 +25,7 @@ class SkillOutput(unittest.TestCase):
env = os.environ.copy()
env["PYTHONIOENCODING"] = "cp1252:strict"
env["PYTHONPATH"] = str(SRC) + os.pathsep + env.get("PYTHONPATH", "")
+ env["PHONE_HARNESS_TELEMETRY"] = "0"
env.pop("BROWSER", None)
r = subprocess.run(
[sys.executable, "-m", "phone_harness.run", "skill"],
diff --git a/tests/test_telemetry.py b/tests/test_telemetry.py
deleted file mode 100644
index 6915fee..0000000
--- a/tests/test_telemetry.py
+++ /dev/null
@@ -1,66 +0,0 @@
-"""CI runs send no telemetry. An ordinary run still does.
-
- python -m unittest tests.test_telemetry
-"""
-import os
-import sys
-import tempfile
-import unittest
-from pathlib import Path
-from unittest import mock
-
-SRC = str(Path(__file__).resolve().parents[1] / "src")
-if SRC not in sys.path:
- sys.path.insert(0, SRC)
-
-
-class CiTelemetry(unittest.TestCase):
- def setUp(self):
- home = tempfile.TemporaryDirectory()
- self.addCleanup(home.cleanup)
- self._env = mock.patch.dict(
- os.environ, {"PHONE_HARNESS_HOME": home.name}, clear=False,
- )
- self._env.start()
- self.addCleanup(self._env.stop)
- os.environ.pop("PHONE_HARNESS_TELEMETRY", None)
- # The suite itself runs with CI=true. Clear it here so a case that
- # expects a send is not turned into a no-op by the runner.
- os.environ.pop("CI", None)
-
- def test_ci_true_does_not_send_or_write_an_install_id(self):
- from phone_harness.config import paths
- from phone_harness.telemetry import capture_cli_event, is_enabled
-
- os.environ["CI"] = "true"
- os.environ["PHONE_HARNESS_TELEMETRY"] = "1"
- self.assertFalse(is_enabled())
- with mock.patch("phone_harness.telemetry._send_detached") as send:
- capture_cli_event(action="completed", command="version")
- send.assert_not_called()
- self.assertFalse(paths()["telemetry"].exists())
-
- def test_ci_unset_still_sends(self):
- from phone_harness.config import paths
- from phone_harness.telemetry import capture_cli_event, is_enabled
-
- self.assertNotIn("CI", os.environ)
- self.assertTrue(is_enabled())
- with mock.patch("phone_harness.telemetry._send_detached") as send:
- capture_cli_event(action="completed", command="version")
- send.assert_called_once()
- payload = send.call_args.args[0]
- self.assertEqual(payload["event"], "cli_event")
- self.assertTrue(payload["distinct_id"])
- self.assertTrue(paths()["telemetry"].is_file())
-
- def test_empty_zero_and_false_are_not_ci(self):
- from phone_harness.telemetry import capture_cli_event, is_enabled
-
- for value in ("", "0", "false", "False"):
- os.environ["CI"] = value
- self.assertTrue(is_enabled(), value)
- with mock.patch("phone_harness.telemetry._send_detached") as send:
- capture_cli_event(action="completed", command="version")
- send.assert_called_once()
- self.assertEqual(send.call_args.args[0]["event"], "cli_event")