[PR #7579] [MERGED] test(telemetry): add coverage for undefined BETTER_AUTH_TELEMETRY_ENDPOINT #24316

Closed
opened 2026-04-15 22:18:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7579
Author: @Copilot
Created: 1/23/2026
Status: Merged
Merged: 1/23/2026
Merged by: @himself65

Base: himself65/2026/01/23/move-telemetryHead: copilot/sub-pr-7578


📝 Commits (4)

  • e0707d6 Initial plan
  • e5e4ff0 test(telemetry): add test for undefined BETTER_AUTH_TELEMETRY_ENDPOINT
  • da50774 fix(telemetry): add guard for undefined endpoint in track function
  • 393824d test(telemetry): use vi.stubEnv instead of delete for env var mocking

📊 Changes

2 files changed (+32 additions, -2 deletions)

View changed files

📝 packages/telemetry/src/index.ts (+3 -2)
📝 packages/telemetry/src/telemetry.test.ts (+29 -0)

📄 Description

Addresses review feedback on #7578 requesting test coverage for the early return behavior when BETTER_AUTH_TELEMETRY_ENDPOINT is undefined.

Changes:

  • Added test verifying noop publisher is returned when endpoint is undefined, without making HTTP requests
  • Fixed early return condition to allow customTrack (test utility) to bypass the endpoint check: !telemetryEndpoint && !context?.customTrack
  • Added defensive guard in track() to prevent calling betterFetch with undefined endpoint: changed else to else if (telemetryEndpoint)

The original early return logic broke existing tests that use customTrack to intercept telemetry events. The fix ensures tests work while still short-circuiting in production when no endpoint is configured.


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Summary by cubic

Adds test coverage and safeguards for telemetry when BETTER_AUTH_TELEMETRY_ENDPOINT is undefined, per feedback on #7578. Ensures customTrack works in tests and prevents HTTP calls without an endpoint.

  • Bug Fixes
    • Return noop publisher when no endpoint unless customTrack is provided.
    • Guard track() to only call betterFetch if telemetryEndpoint exists.
    • Add test verifying betterFetch is not called when the endpoint is missing.

Written for commit 393824d932. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7579 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 1/23/2026 **Status:** ✅ Merged **Merged:** 1/23/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `himself65/2026/01/23/move-telemetry` ← **Head:** `copilot/sub-pr-7578` --- ### 📝 Commits (4) - [`e0707d6`](https://github.com/better-auth/better-auth/commit/e0707d6c1bb3a55eaf1ed761648f9a1117340203) Initial plan - [`e5e4ff0`](https://github.com/better-auth/better-auth/commit/e5e4ff0da401d9e02512af16a1b1e72074f69745) test(telemetry): add test for undefined BETTER_AUTH_TELEMETRY_ENDPOINT - [`da50774`](https://github.com/better-auth/better-auth/commit/da507749199458f5d48a624f53bebaefd275eea5) fix(telemetry): add guard for undefined endpoint in track function - [`393824d`](https://github.com/better-auth/better-auth/commit/393824d932cf096a6184fcf7c1e5c0737267340a) test(telemetry): use vi.stubEnv instead of delete for env var mocking ### 📊 Changes **2 files changed** (+32 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/telemetry/src/index.ts` (+3 -2) 📝 `packages/telemetry/src/telemetry.test.ts` (+29 -0) </details> ### 📄 Description Addresses review feedback on #7578 requesting test coverage for the early return behavior when `BETTER_AUTH_TELEMETRY_ENDPOINT` is undefined. **Changes:** - Added test verifying noop publisher is returned when endpoint is undefined, without making HTTP requests - Fixed early return condition to allow `customTrack` (test utility) to bypass the endpoint check: `!telemetryEndpoint && !context?.customTrack` - Added defensive guard in `track()` to prevent calling `betterFetch` with undefined endpoint: changed `else` to `else if (telemetryEndpoint)` The original early return logic broke existing tests that use `customTrack` to intercept telemetry events. The fix ensures tests work while still short-circuiting in production when no endpoint is configured. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/better-auth/better-auth/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds test coverage and safeguards for telemetry when BETTER_AUTH_TELEMETRY_ENDPOINT is undefined, per feedback on #7578. Ensures customTrack works in tests and prevents HTTP calls without an endpoint. - **Bug Fixes** - Return noop publisher when no endpoint unless customTrack is provided. - Guard track() to only call betterFetch if telemetryEndpoint exists. - Add test verifying betterFetch is not called when the endpoint is missing. <sup>Written for commit 393824d932cf096a6184fcf7c1e5c0737267340a. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:18:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#24316