Skip to content

Conversation

@tculig
Copy link
Contributor

@tculig tculig commented Oct 29, 2025

Description

https://jira.mongodb.org/browse/VSCODE-517

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@tculig tculig requested a review from a team as a code owner October 29, 2025 12:55
@tculig tculig force-pushed the VSCODE-517-update-telemetry-test branch from f920a50 to b8e0dac Compare October 29, 2025 13:03
@tculig tculig marked this pull request as draft October 29, 2025 13:54
@tculig tculig force-pushed the VSCODE-517-update-telemetry-test branch from 6c9c3d7 to 949e13b Compare October 31, 2025 11:53
@tculig tculig force-pushed the VSCODE-517-update-telemetry-test branch from 949e13b to f512f0c Compare October 31, 2025 14:31
@tculig tculig marked this pull request as ready for review October 31, 2025 15:10
Copy link
Contributor

@himanshusinghs himanshusinghs left a comment

Choose a reason for hiding this comment

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

Was wondering if we could simply get away with providing the test-segment-key through the npm test script?

Additionally we might still want to have a test to confirm that the final build contains the segment key.

Comment on lines 62 to 73
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Module = require('module');
const originalRequire = Module.prototype.require;
Module.prototype.require = function (id: string, ...args: any[]): any {
if (id === '../../../../constants') {
return { segmentKey: process.env.SEGMENT_KEY };
}
return originalRequire.apply(this, [id, ...args]);
};

// Store the original require for restoration
originalRequireFunction = originalRequire;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems super heavy-handed - the require(segmentKeyFileLocation) call is used as a shorthand to reading a json file. Rather than mocking it, we could do something like:

const readSegmentKeyFromDisk = (): string => {
  if (process.env.CI) {
    return require('../../../../constants').segmentKey;
  }

  // "mock" the on-disk segment key
  return process.env.SEGMENT_KEY;
}

);

// Mock readSegmentKey to return a fake key for local testing
sandbox.replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

This should only be done for non-CI runs, right?

package.json Outdated
"watch:extension": "npm run compile:extension -- -watch",
"watch:extension-bundles": "webpack --mode development --watch",
"pretest": "npm run compile",
"pretest": "cross-env SEGMENT_KEY=test-segment-key npm run compile",
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to set this in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the env variable gets baked into the config file at compile time, and there is a unit tests which checks the env values against the config file value, so the answer is yes, we do need it in both places. Alternatively, we can just skip the test that makes that check.

@tculig tculig merged commit 1625fa7 into main Nov 7, 2025
13 checks passed
@tculig tculig deleted the VSCODE-517-update-telemetry-test branch November 7, 2025 13:22
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.

5 participants