Skip to content

🧪 test: Add unit tests for initObservability#62

Open
groupthinking wants to merge 4 commits intomainfrom
add-observability-tests-6699426491412081943
Open

🧪 test: Add unit tests for initObservability#62
groupthinking wants to merge 4 commits intomainfrom
add-observability-tests-6699426491412081943

Conversation

@groupthinking
Copy link
Owner

🎯 What: The initObservability and getObservability functions in packages/observability/src/observability.ts were lacking test coverage, meaning initialization behavior wasn't being validated.
📊 Coverage: The new tests now fully cover:

  • Successful instantiation of the Observability singleton.
  • Proper behavior when initObservability is called multiple times.
  • Proper error throwing when getObservability is called before initialization.
  • Successful return of the existing singleton instance when initialized.
    Result: Test coverage for these initialization functions went from 0% to fully covered. Vitest and TypeScript configuration dependencies were also added to the workspace appropriately, allowing for simple testing via npm run test --workspaces.

PR created automatically by Jules for task 6699426491412081943 started by @groupthinking

Adds a new test file for the `initObservability` and `getObservability`
singleton functions in the `packages/observability` module.

The tests ensure proper initialization of the singleton, handle multiple
instantiation attempts, and ensure the getter function behaves correctly
if called prior to initialization.

Properly utilizes `vi.resetModules()` with dynamic imports to avoid test
flakiness between tests since the singleton is stateful. Mocked OTel
dependencies to prevent network calls.

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
v0-uvai Skipped Skipped Mar 8, 2026 10:24pm

Copilot AI review requested due to automatic review settings March 8, 2026 22:12
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the reliability of the observability package by introducing robust unit tests for its core initialization and retrieval functions. The new tests ensure that the Observability singleton behaves correctly under various scenarios, including initial setup, repeated calls, and pre-initialization access, thereby improving the overall stability and maintainability of the module.

Highlights

  • New Unit Tests: Comprehensive unit tests were added for the initObservability and getObservability functions in packages/observability/src/observability.ts.
  • Test Coverage Improvement: Test coverage for these critical initialization functions increased from 0% to full coverage, validating their behavior.
  • Initialization Logic Validation: Tests confirm successful instantiation of the Observability singleton, proper handling of multiple initObservability calls, and correct error throwing when getObservability is called before initialization.
  • Development Dependency Updates: Vitest and updated TypeScript configuration dependencies were added to the workspace to support the new testing framework.
Changelog
  • package-lock.json
    • Updated @opentelemetry/api from version 1.7.0 to 1.9.0.
    • Added @swc/helpers dependency.
    • Updated @types/node from version 20.19.30 to 20.19.37.
    • Removed duplicate nested node_modules entries for @opentelemetry/api and @swc/helpers.
    • Removed dev: true flag from the fsevents entry.
  • packages/observability/package.json
    • Added a test script using vitest run.
    • Reordered OpenTelemetry dependencies for better organization.
    • Added @repo/typescript-config and vitest to devDependencies.
    • Updated @types/node to ^20.19.37 and typescript to ^5.9.3.
  • packages/observability/src/observability.test.ts
    • Added a new file containing unit tests for initObservability and getObservability.
    • Included mocks for @opentelemetry/sdk-node and @opentelemetry/api to isolate testing.
    • Implemented tests to cover successful initialization, singleton instance retrieval, and error handling for uninitialized access.
Activity
  • The pull request was automatically created by Jules for a task initiated by @groupthinking.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-62 March 8, 2026 22:13 Destroyed
@railway-app
Copy link

railway-app bot commented Mar 8, 2026

🚅 Deployed to the EventRelay-pr-62 environment in EventRelay

Service Status Web Updated (UTC)
EventRelay ✅ Success (View Logs) Web Mar 8, 2026 at 10:26 pm
web ✅ Success (View Logs) Web Mar 8, 2026 at 10:26 pm
eslint-config ✅ Success (View Logs) Web Mar 8, 2026 at 10:26 pm
supabase ✅ Success (View Logs) Mar 8, 2026 at 10:26 pm
guides ✅ Success (View Logs) Web Mar 8, 2026 at 10:26 pm

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds valuable unit tests for the observability initialization logic, significantly improving test coverage. The tests are well-structured, particularly with the use of vi.resetModules() to handle the singleton pattern. My review includes a couple of suggestions to enhance the tests by avoiding @ts-ignore and direct access to private properties. This will make the tests more robust and better aligned with the repository's strict typing standards.

Comment on lines +58 to +61
// @ts-ignore - accessing private member for verification
expect(instance.serviceName).toBe('test-service');
// @ts-ignore - accessing private member for verification
expect(instance.enabled).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using @ts-ignore to access private members for verification makes tests brittle and bypasses type safety. This goes against the 'strict type hinting' principle from the repository style guide.

A better approach is to test the observable behavior. For example, to test the enabled: false case, you could assert that NodeSDK is not instantiated. To test the serviceName, you could assert that trace.getTracer is called with the correct name in a separate test where observability is enabled.

References
  1. The use of @ts-ignore bypasses TypeScript's type checking, which is contrary to the principle of strict type hinting mentioned in the repository style guide (line 7). (link)

Comment on lines +70 to +71
// @ts-ignore
expect(instance2.serviceName).toBe('test-service');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As with the previous comment, it's best to avoid @ts-ignore to maintain strict type safety.

To verify that the singleton instance is not reconfigured on subsequent calls, you could check that the initialization logic (e.g., calls to trace.getTracer()) is only executed once, even when initObservability is called multiple times. This tests the behavior without accessing private implementation details.

References
  1. The use of @ts-ignore bypasses TypeScript's type checking, which is contrary to the principle of strict type hinting mentioned in the repository style guide (line 7). (link)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit test coverage for the packages/observability singleton initialization surface (initObservability / getObservability) and wires up the package to run tests with Vitest in the workspace.

Changes:

  • Added Vitest unit tests covering initialization, idempotent init behavior, and pre-init access errors.
  • Added a test script and Vitest dev dependency for @repo/observability (plus TypeScript config dependency alignment).
  • Updated root package-lock.json to reflect the new dev tooling/dependency resolution.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/observability/src/observability.test.ts Adds unit tests for initObservability / getObservability behavior using Vitest + module mocking.
packages/observability/package.json Adds vitest run test script and required devDependencies (Vitest, TS config, etc.).
package-lock.json Lockfile updates resulting from adding Vitest/tooling and updated dependency resolution.

Comment on lines +1 to +5
import { describe, it, expect, beforeEach, vi } from 'vitest';

// Mock the open telemetry modules
vi.mock('@opentelemetry/sdk-node', () => {
return {
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file is located under src/, and packages/observability/tsconfig.json currently includes all of src without excluding *.test.ts. That means tsc will emit this test into dist/ during npm run build, which is usually undesirable for a library package. Consider moving tests outside src (e.g., tests/), or updating the tsconfig exclude/include patterns to omit test files.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +61
// @ts-ignore - accessing private member for verification
expect(instance.serviceName).toBe('test-service');
// @ts-ignore - accessing private member for verification
expect(instance.enabled).toBe(false);
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions rely on @ts-ignore to access private members (serviceName, enabled). That makes the tests brittle against refactors (e.g., switching to #private fields) and tests implementation details rather than behavior. Prefer asserting observable behavior instead (e.g., verify OpenTelemetry SDK setup methods are/aren’t invoked based on config), or add a minimal read-only getter if you really need to validate config.

Copilot uses AI. Check for mistakes.
The `actions/github-script@v7` runs were failing with `HttpError: Resource not accessible by integration`
when attempting to add labels or create comments on Pull Requests.

This adds the missing `pull-requests: write` and `issues: write` permissions
to the `.github/workflows/auto-label.yml` and `.github/workflows/pr-checks.yml` workflows.

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-62 March 8, 2026 22:17 Destroyed
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

🔍 PR Validation

⚠️ PR title should follow conventional commits format

The `actions/github-script@v7` runs were failing with `HttpError: Resource not accessible by integration`
when attempting to add labels or create comments on Pull Requests.

This adds the missing `pull-requests: write` and `issues: write` permissions
to the `.github/workflows/auto-label.yml` and `.github/workflows/pr-checks.yml` workflows.

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@railway-app railway-app bot temporarily deployed to EventRelay / EventRelay-pr-62 March 8, 2026 22:21 Destroyed
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

🔍 PR Validation

⚠️ PR title should follow conventional commits format

The `actions/github-script@v7` runs were failing with `HttpError: Resource not accessible by integration`
when attempting to add labels or create comments on Pull Requests.

This adds the missing `pull-requests: write` and `issues: write` permissions
to the `.github/workflows/auto-label.yml` and `.github/workflows/pr-checks.yml` workflows.

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Mar 8, 2026

🔍 PR Validation

⚠️ PR title should follow conventional commits format

@@ -0,0 +1,91 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import afterEach.

Copilot Autofix

AI 2 days ago

In general, unused imports should be removed from the import list to avoid confusion and keep the codebase clean. Here, we only need to adjust the vitest import on line 1 to no longer include afterEach.

The best fix without changing functionality is to edit packages/observability/src/observability.test.ts and remove afterEach from the destructuring import from 'vitest'. No other lines or imports need to change, and no new methods or definitions are required. This keeps all currently used testing helpers (describe, it, expect, beforeEach, vi) while eliminating the unused one.

Suggested changeset 1
packages/observability/src/observability.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/observability/src/observability.test.ts b/packages/observability/src/observability.test.ts
--- a/packages/observability/src/observability.test.ts
+++ b/packages/observability/src/observability.test.ts
@@ -1,4 +1,4 @@
-import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
+import { describe, it, expect, beforeEach, vi } from 'vitest';
 import * as observabilityModule from './observability';
 import { Observability } from './observability';
 
EOF
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import * as observabilityModule from './observability';
import { Observability } from './observability';

Copilot is powered by AI and may make mistakes. Always verify output.
@@ -0,0 +1,91 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import * as observabilityModule from './observability';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import observabilityModule.

Copilot Autofix

AI 2 days ago

In general, unused imports should be removed to improve readability and avoid confusion. If the module is only needed for side effects, it should instead be imported without binding it to a name (e.g., import './module';). Here, the module is already imported dynamically inside each test, so the top-level namespace import is redundant.

The best fix without changing existing functionality is to delete the unused import line import * as observabilityModule from './observability'; in packages/observability/src/observability.test.ts. No additional imports or code changes are required because all references to the observability module use await import('./observability') within tests. Removing this line will not alter runtime behavior or test logic.

Concretely: in packages/observability/src/observability.test.ts, remove line 2 containing the unused import. No new methods, imports, or definitions are needed.

Suggested changeset 1
packages/observability/src/observability.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/observability/src/observability.test.ts b/packages/observability/src/observability.test.ts
--- a/packages/observability/src/observability.test.ts
+++ b/packages/observability/src/observability.test.ts
@@ -1,5 +1,4 @@
 import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
-import * as observabilityModule from './observability';
 import { Observability } from './observability';
 
 // Mock the open telemetry modules
EOF
@@ -1,5 +1,4 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import * as observabilityModule from './observability';
import { Observability } from './observability';

// Mock the open telemetry modules
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -0,0 +1,91 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import * as observabilityModule from './observability';
import { Observability } from './observability';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import Observability.

Copilot Autofix

AI 2 days ago

In general, unused imports should be removed to improve readability and avoid confusion. Since all uses of the Observability class go through the dynamically imported mod object (e.g., mod.Observability), the direct named import is unnecessary.

The best fix here is to delete line 3 (import { Observability } from './observability';) from packages/observability/src/observability.test.ts. No other code changes are required, because tests already work with mod.Observability and observabilityModule and do not rely on the directly imported Observability symbol. No additional methods, imports, or definitions are needed.

Suggested changeset 1
packages/observability/src/observability.test.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/observability/src/observability.test.ts b/packages/observability/src/observability.test.ts
--- a/packages/observability/src/observability.test.ts
+++ b/packages/observability/src/observability.test.ts
@@ -1,6 +1,5 @@
 import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
 import * as observabilityModule from './observability';
-import { Observability } from './observability';
 
 // Mock the open telemetry modules
 vi.mock('@opentelemetry/sdk-node', () => {
EOF
@@ -1,6 +1,5 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import * as observabilityModule from './observability';
import { Observability } from './observability';

// Mock the open telemetry modules
vi.mock('@opentelemetry/sdk-node', () => {
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Test files are compiled into the npm package distribution because tsconfig.json doesn't exclude *.test.ts and *.spec.ts files

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants