Skip to content

Consolidate __setTelemetryClientForTesting wiring into shared makeTrackEventSpy() fixture #408

Description

@geevensingh

Discovered while addressing #71 (Telemetry coverage expansion: backend Functions). After #71 shipped, the __setTelemetryClientForTesting / __resetTelemetryInitForTesting wiring per-spec is the dominant pattern in api/src/functions/blobs.test.ts (4 describe blocks) and is also installed at the file-scope beforeEach in api/src/shared/blobs.test.ts. A shared helper would consolidate the boilerplate without semantic change.

PR #403's rubber-duck panel (architect finding 1 + skeptic finding 2) explicitly recommended NOT extracting helpers ad-hoc inside #403 and folding the consolidation into this issue instead, so the next contributor designs the shape once rather than discovering it in pieces.

Acceptance criteria

  • New module under api/src/shared/__testing__/ (new directory; mirrors the frontend src/testing/ carve-out from production builds via api/tsconfig.json excludes) exporting a makeTrackEventSpy() helper that returns {spy, install, uninstall}:
    • install() calls __setTelemetryClientForTesting({ trackEvent: spy } as unknown as TelemetryClient) and __resetTelemetryInitForTesting().
    • uninstall() reverses both.
  • Migrate the four existing backend test files that wire the seam by hand to use the helper:
  • Optional but recommended: also consolidate the two manyBlobsForQuota test-data builders currently duplicated between the quota.exceeded and blob.autoDeleted describe blocks in blobs.test.ts (Add backend telemetry: blob.autoDeleted, blob.versionConflict, slug.collisions.exhausted (#71) #403 left them duplicated intentionally, deferring to this issue).
  • Verify api/tsconfig.json excludes __testing__/ from production build inclusion (mirrors how api/integration/ is excluded).
  • Cross-link from PR back to Telemetry coverage expansion: backend Functions #71.

References

  • api/src/shared/auth.test.ts:387,504 -- canonical existing pattern for the seam.
  • api/src/functions/blobs.test.ts:749-760, 802-813, 877-886, 935-944 -- four describe blocks now each wire the seam by hand.
  • AGENTS.md §4 Telemetry (Test requirement section): "The repo pattern uses __setTelemetryClientForTesting / __resetTelemetryInitForTesting (backend)..."
  • docs/telemetry.md Backend events Deferral notes (records this issue as the consolidation target).

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:lowLow priority - nice to have, no urgencytech-debtCleanup, refactoring, or paying down shortcuts

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions