Skip to content

Commit a472f6a

Browse files
authored
fix(autocomplete): fix a semver check in old autocomplete (#2499)
* fix a semver check in old autocomplete * add a test * don't check the results * print the whole error * wait longer * too much
1 parent 43f93c3 commit a472f6a

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/autocomplete/src/index.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ describe('completer.completer', function () {
497497
});
498498

499499
context('when context is aggregation query', function () {
500+
it('returns all suggestions', async function () {
501+
const i = 'db.shipwrecks.aggregate([{';
502+
expect((await completer(standalone440, i))[0]).to.be.an('array');
503+
});
504+
500505
it('has several matches', async function () {
501506
const i = 'db.shipwrecks.aggregate([ { $so';
502507
expect(await completer(standalone440, i)).to.deep.equal([

packages/autocomplete/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ export async function completer(
290290
return [[], line];
291291
}
292292

293+
// from https://github.com/mongodb-js/devtools-shared/commit/e4a5b00a83b19a76bdf380799a421511230168db
294+
function satisfiesVersion(v1: string, v2: string): boolean {
295+
const isGTECheck = /^\d+?\.\d+?\.\d+?$/.test(v2);
296+
return semver.satisfies(v1, isGTECheck ? `>=${v2}` : v2);
297+
}
298+
293299
function isAcceptable(
294300
params: AutocompleteParameters,
295301
entry: {
@@ -310,7 +316,10 @@ function isAcceptable(
310316
!entry[versionKey] ||
311317
// TODO: when https://jira.mongodb.org/browse/SPM-2327 is done we can rely on server_version being present
312318
!connectionInfo?.server_version ||
313-
semver.gte(connectionInfo.server_version, entry[versionKey] as string);
319+
satisfiesVersion(
320+
connectionInfo.server_version,
321+
entry[versionKey] as string
322+
);
314323
}
315324
const isAcceptableEnvironment =
316325
!entry.env ||

packages/cli-repl/test/repl-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function waitEval(bus: MongoshBus) {
7373
async function waitCompletion(bus: MongoshBus) {
7474
await Promise.race([
7575
waitBus(bus, 'mongosh:autocompletion-complete'),
76-
new Promise((resolve) => setTimeout(resolve, 5000)?.unref?.()),
76+
new Promise((resolve) => setTimeout(resolve, 10_000)?.unref?.()),
7777
]);
7878
await tick();
7979
}

0 commit comments

Comments
 (0)