Hard-disable pm telemetry in every test child so expected refusals never reach production Sentry (pm-vcs-rd82)

Merged
UN
8d ago
+99-19

Fixes #176. Tracker: pm-vcs-rd82

Problem

test/served-defects.test.ts labelled its installed-CLI children PM_TELEMETRY_SOURCE_CONTEXT=test, plus PM_TELEMETRY_INLINE_FLUSH=1, to avoid the detached flusher.

pm-cli's documented policy ("Test environments" in its CONFIGURATION.md) treats a valid explicit source-context label as intentional test delivery, even under NODE_ENV=test. So the suite's expected vcs fetch/push/clone/remote refusals reached the production Sentry project as ExtensionCommandError with environment=test. The CI runs on 2026-11-04 created PM-CLI-3R, 3S, 3T, 3V, 3W and 3X, which blocked pm-cli's 2026.11.4 auto-release Sentry gate (unbraind/pm-cli#1659).

Change

  • test/helpers/test-environment.ts: testEnvironment() adds the hard opt-out PM_TELEMETRY_DISABLED=1.
    • isolate-session.ts applies testEnvironment() to every test process, so the opt-out reaches every child, including runPm and the acceptance helpers.
    • pm-cli documents that neither a source-context label nor PM_TELEMETRY_SEND_TEST_EVENTS overrides it, and that it also disables Sentry and the flush worker.
  • test/served-defects.test.ts: drops the label. With telemetry hard-disabled, no detached flusher writes under HOME after a command returns, which was the original reason for the label.
  • test/test-environment.test.ts: a new behavioural regression.
    • It points the global profile's telemetry.endpoint and SENTRY_DSN at a local HTTP collector, and checks that route is active before running any command that could deliver.
    • It then runs the installed pm with the label and PM_TELEMETRY_SEND_TEST_EVENTS=1, and asserts ops telemetry status reports enabled: false with env_overrides.telemetry_disabled: true.
    • A failing command must then send zero requests.

The test writes the global profile because a project's telemetry.endpoint is ignored; only the global profile is honored. That trap is reported upstream as unbraind/pm-cli#1660.

Verification

  • The regression passes with the fix.
  • With PM_TELEMETRY_DISABLED removed from testEnvironment(), it fails (enabled is true), and everything that run sends goes only to the local collector.
  • Experiment with the old served-defects environment: one failing pm get sent 3 POST /v1/events to the local collector. With PM_TELEMETRY_DISABLED=1 it sent none.
  • All 18 test files that spawn the installed pm CLI pass: 420 of 420.
    • served-defects passes for both Node and Bun.
    • test-environment.test.ts: 6 of 6.
  • typecheck, lint, docstring, duplicates, changelog:check and accept:self-host (at HEAD) pass.

Note

This and #178 both regenerate selfhost.bundle. Whichever merges second rebases and regenerates it.


Summary by cubic

Stops test-spawned pm CLI children from delivering telemetry and Sentry reports to production collectors, and merges main (pack-race fix, closures) with a regenerated selfhost.bundle.

  • testEnvironment() now sets the hard opt-out PM_TELEMETRY_DISABLED=1, which no source-context label or PM_TELEMETRY_SEND_TEST_EVENTS overrides and which also disables Sentry and the flush worker.
  • served-defects.test.ts drops its label; with telemetry hard-disabled, no detached flusher writes under HOME after a command returns.
  • test-environment.test.ts gains a regression that routes the global profile's telemetry endpoint and SENTRY_DSN to a local HTTP collector, proves the route is active, and asserts a labeled failing command sends zero requests.

Fixes #176. Tracker: pm-vcs-rd82.

Summary by Sourcery

Hard-disable pm telemetry for all test child processes and verify that expected command failures cannot reach production Sentry.

Bug Fixes:

  • Prevent test-spawned pm CLI failures from sending telemetry or Sentry reports to production collectors.
  • Remove the served-defects test telemetry label and detached-flush workaround now that telemetry is hard-disabled for all test children.

Enhancements:

  • Apply a hard telemetry opt-out to every test child, including Sentry and background flushing, regardless of test-delivery overrides.

Tests:

  • Add a regression test verifying that labeled test children report telemetry as disabled and send no requests even when a local collector and test-event overrides are configured.

Chores:

  • Regenerate the self-host bundle and record the associated pm issue metadata.