From cc35af0caa48531590aa664f9113a770e16bba82 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 3 Dec 2025 12:13:25 -0500 Subject: [PATCH 1/2] feat(devtools-connect): make lookup configurable --- packages/devtools-connect/package.json | 2 +- packages/devtools-connect/src/connect.spec.ts | 24 +++++++++++++++++++ packages/devtools-connect/src/connect.ts | 7 +++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/devtools-connect/package.json b/packages/devtools-connect/package.json index 495a33b0..14fd1e63 100644 --- a/packages/devtools-connect/package.json +++ b/packages/devtools-connect/package.json @@ -36,7 +36,7 @@ "depcheck": "depcheck", "check": "npm run typecheck && npm run lint && npm run depcheck", "check-ci": "npm run check", - "testonly": "nyc mocha --colors -r ts-node/register src/**/*.spec.ts", + "testonly": "nyc mocha --colors --register ts-node/register src/**/*.spec.ts", "test": "npm run lint && npm run compile && npm run testonly", "test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test", "test-watch": "npm run test -- --watch", diff --git a/packages/devtools-connect/src/connect.spec.ts b/packages/devtools-connect/src/connect.spec.ts index 38e85ba5..d4e47aab 100644 --- a/packages/devtools-connect/src/connect.spec.ts +++ b/packages/devtools-connect/src/connect.spec.ts @@ -412,6 +412,30 @@ describe('devtools connect', function () { expect(result.client).to.equal(mClient); }); + it('allows lookup to be configured', async function () { + const uri = 'localhost:27017'; + const mClient = stubConstructor(FakeMongoClient); + const mClientType = sinon.stub().returns(mClient); + mClient.connect.onFirstCall().resolves(mClient); + const lookupSpy = sinon.spy(); + await connectMongoClient( + uri, + { ...defaultOpts, useSystemCA: false, lookup: lookupSpy }, + bus, + mClientType as any, + ); + + // get options passed to mongo client + const finalClientOptions = mClientType.getCalls()[0].args[1]; + expect(finalClientOptions.lookup).to.not.equal(lookupSpy); // lookup is always wrapped + finalClientOptions.lookup('localhost', 27017, () => {}); // invoke it the way it would be by net/tls + expect(lookupSpy.getCalls()).to.have.lengthOf(1); // verify our input lookup was called instead of the dns package + expect(lookupSpy.getCalls()[0].args[1]).to.have.property( + 'verbatim', + false, + ); // but we still always set verbatim to false + }); + describe('retryable TLS errors', function () { it('retries TLS errors without system CA integration enabled -- MongoClient error', async function () { const uri = 'localhost:27017'; diff --git a/packages/devtools-connect/src/connect.ts b/packages/devtools-connect/src/connect.ts index bb6a3f3a..ea685c11 100644 --- a/packages/devtools-connect/src/connect.ts +++ b/packages/devtools-connect/src/connect.ts @@ -588,10 +588,15 @@ async function connectMongoClientImpl({ ca ? { ca } : {}, ); + const customLookup = mongoClientOptions.lookup; // Adopt dns result order changes with Node v18 that affected the VSCode extension VSCODE-458. // Refs https://github.com/microsoft/vscode/issues/189805 mongoClientOptions.lookup = (hostname, options, callback) => { - return dns.lookup(hostname, { verbatim: false, ...options }, callback); + return (customLookup ?? dns.lookup)( + hostname, + { verbatim: false, ...options }, + callback, + ); }; delete (mongoClientOptions as any).useSystemCA; // can be removed once no product uses this anymore From 37c69c9d38175390623eadd53f207badbfcdf79d Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 3 Dec 2025 12:47:37 -0500 Subject: [PATCH 2/2] chore: ignore depcheck on ts-node --- packages/devtools-connect/.depcheckrc | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/devtools-connect/.depcheckrc b/packages/devtools-connect/.depcheckrc index 5097ea53..0b5b6c0f 100644 --- a/packages/devtools-connect/.depcheckrc +++ b/packages/devtools-connect/.depcheckrc @@ -8,5 +8,6 @@ ignores: # this is explicitly called as a dependency to make sure that is bootstrapped # before mongodb-runner, since it is required via mongodb - '@mongodb-js/saslprep' + - 'ts-node' # used by mocha ignore-patterns: - 'dist'