Skip to content

Conversation

@subtleGradient
Copy link
Contributor

fix: guard PACKAGE_VERSION to avoid ReferenceError in tests

Summary

Fixed a ReferenceError: __PACKAGE_VERSION__ is not defined that was preventing e2e tests from running. Changed the version check in src/version.ts from __PACKAGE_VERSION__ === undefined to typeof __PACKAGE_VERSION__ === 'undefined' to safely handle cases where the global constant doesn't exist (e.g., when running tests directly from TypeScript source without going through the build process).

Technical details:

  • __PACKAGE_VERSION__ is injected by tsup during builds via the define option
  • When vitest runs tests directly from source (especially e2e tests), this global doesn't exist
  • The old code threw a ReferenceError when trying to access the undefined variable
  • The new code uses typeof which safely returns 'undefined' without throwing

Review & Testing Checklist for Human

  • Verify e2e tests run successfully - Run pnpm run test:e2e and confirm tests execute without the ReferenceError (note: there's one flaky test in pdf-blob/index.test.ts that fails due to OCR misreading - this is unrelated to this fix)
  • Confirm build behavior unchanged - Run pnpm build and verify the built output still contains the correct package version (not '0.0.0-test')
  • Review the flaky test - The sending large pdf base64 blob with FileParserPlugin test fails intermittently because the AI model misreads "LARGE-M9N3T" as "LARGE-MNGT" or "LARGE-MN3T". Should this test be made more lenient or is this a real issue to investigate?

Test Plan

  1. Run pnpm typecheck - should pass ✓
  2. Run pnpm test - should pass ✓
  3. Run pnpm run test:e2e - should run without ReferenceError (may have 1 flaky test failure unrelated to this fix)
  4. Run pnpm build and verify dist/index.js contains the real version number

Notes

Co-Authored-By: Tom Aylott <thomas.42@gmail.com>
Copilot AI review requested due to automatic review settings November 12, 2025 01:36
@devin-ai-integration
Copy link
Contributor

Original prompt from Tom
pnpm run test:e2e pdf-blob/index.test.ts
ReferenceError: __PACKAGE_VERSION__ is not defined
unbreak this
ensure that all the tests can run, including the e2e tests

You only need to look in the following repo: OpenRouterTeam/ai-sdk-provider

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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

This PR fixes a ReferenceError that occurred when running e2e tests directly from TypeScript source. The issue was that __PACKAGE_VERSION__, a global constant injected by tsup during builds, doesn't exist in the test environment, causing the code to throw when attempting to access it.

Key changes:

  • Changed the version check from direct comparison (__PACKAGE_VERSION__ === undefined) to type checking (typeof __PACKAGE_VERSION__ === 'undefined')

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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