Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ShellApiAutocompleter implements Autocompleter {

let completions: CompletionResults;

if (process.env.USE_NEW_AUTOCOMPLETE) {
if (process.env.USE_NEW_AUTOCOMPLETE !== '0') {
if (!this.newMongoshCompleter) {
this.newMongoshCompleter = await initNewAutocompleter(
this.shellInstanceState
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-repl/src/async-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function expectInStream(
expect(found).to.be.true;
}

describe('AsyncRepl', function () {
describe.skip('AsyncRepl', function () {
before(function () {
// nyc adds its own SIGINT listener that annoys use here.
process.removeAllListeners('SIGINT');
Expand Down
16 changes: 7 additions & 9 deletions packages/cli-repl/src/cli-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ describe('CliRepl', function () {
hasDatabaseNames: false,
});

context('pressing CTRL-C', function () {
context.skip('pressing CTRL-C', function () {
before(function () {
if (process.platform === 'win32') {
// cannot trigger SIGINT on Windows
Expand Down Expand Up @@ -2446,7 +2446,7 @@ describe('CliRepl', function () {
let wantVersion = true;
let wantQueryOperators = true;

if (process.env.USE_NEW_AUTOCOMPLETE && !testServer) {
if (process.env.USE_NEW_AUTOCOMPLETE !== '0' && !testServer) {
// mongodb-ts-autocomplete does not support noDb mode. It wouldn't be able
// to list collections anyway, and since the collections don't exist it
// wouldn't autocomplete methods on those collections.
Expand All @@ -2458,7 +2458,7 @@ describe('CliRepl', function () {
hasDatabaseNames = false;
}

if (process.env.USE_NEW_AUTOCOMPLETE && testServer) {
if (process.env.USE_NEW_AUTOCOMPLETE !== '0' && testServer) {
if ((testServer as any)?._opts.args?.includes('--auth')) {
// mongodb-ts-autocomplete does not take into account the server version
// or capabilities, so it always completes db.watch
Expand Down Expand Up @@ -2530,12 +2530,10 @@ describe('CliRepl', function () {
input.write('db.movies.find({year: {$g');
await tabCompletion();

if (wantQueryOperators) {
if (process.env.USE_NEW_AUTOCOMPLETE) {
// wait for the documents to finish loading to be sure that the next
// tabCompletion() call will work
await docsLoadedPromise;
}
if (wantQueryOperators && process.env.USE_NEW_AUTOCOMPLETE !== '0') {
// wait for the documents to finish loading to be sure that the next
// tabCompletion() call will work
await docsLoadedPromise;
}

await tabCompletion();
Expand Down
12 changes: 7 additions & 5 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('MongoshNodeRepl', function () {
});
sp.runCommandWithCheck.resolves({ ok: 1 });

if (process.env.USE_NEW_AUTOCOMPLETE) {
if (process.env.USE_NEW_AUTOCOMPLETE !== '0') {
sp.listCollections.resolves([{ name: 'coll' }]);
const aggCursor = stubInterface<AggregationCursor>();
aggCursor.toArray.resolves([{ foo: 1, bar: 2 }]);
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('MongoshNodeRepl', function () {

context(
`autocompleting during .editor [${
process.env.USE_NEW_AUTOCOMPLETE ? 'new' : 'old'
process.env.USE_NEW_AUTOCOMPLETE !== '0' ? 'new' : 'old'
}]`,
function () {
it('does not stop input when autocompleting during .editor', async function () {
Expand Down Expand Up @@ -481,7 +481,9 @@ describe('MongoshNodeRepl', function () {
});

context(
`autocompletion [${process.env.USE_NEW_AUTOCOMPLETE ? 'new' : 'old'}]`,
`autocompletion [${
process.env.USE_NEW_AUTOCOMPLETE !== '0' ? 'new' : 'old'
}]`,
function () {
it('autocompletes collection methods', async function () {
input.write('db.coll.');
Expand All @@ -491,7 +493,7 @@ describe('MongoshNodeRepl', function () {
expect(output, output).to.include('db.coll.updateOne');
});
it('autocompletes collection schema fields', async function () {
if (!process.env.USE_NEW_AUTOCOMPLETE) {
if (process.env.USE_NEW_AUTOCOMPLETE === '0') {
// auto-completing collection field names only supported by new autocomplete
return this.skip();
}
Expand All @@ -505,7 +507,7 @@ describe('MongoshNodeRepl', function () {
});

it('does not autocomplete collection schema fields if disableSchemaSampling=true', async function () {
if (!process.env.USE_NEW_AUTOCOMPLETE) {
if (process.env.USE_NEW_AUTOCOMPLETE === '0') {
// auto-completing collection field names only supported by new autocomplete
return this.skip();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class MongoshNodeRepl implements EvaluationListener {
let newMongoshCompleter: (line: string) => Promise<CompletionResults>;
let oldMongoshCompleter: (line: string) => Promise<CompletionResults>;

if (process.env.USE_NEW_AUTOCOMPLETE) {
if (process.env.USE_NEW_AUTOCOMPLETE !== '0') {
Copy link
Preview

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic string comparison !== '0' is repeated across multiple files; consider introducing a helper (e.g., function isNewAutocompleteEnabled(env = process.env) { return env.USE_NEW_AUTOCOMPLETE !== '0'; }) to centralize the flag semantics and avoid divergence.

Copilot uses AI. Check for mistakes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a horrible idea. If we had it centralized like that, it'd have made it easier to flip the flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we can still do this if you prefer? I think this is something that would primarily have made sense when we first introduced the flag

// we will lazily instantiate the new autocompleter on first use
} else {
const autocompleteParams = instanceState.getAutocompleteParameters();
Expand All @@ -461,7 +461,7 @@ class MongoshNodeRepl implements EvaluationListener {
return nodeResults;
})(),
(async () => {
if (process.env.USE_NEW_AUTOCOMPLETE) {
if (process.env.USE_NEW_AUTOCOMPLETE !== '0') {
if (!newMongoshCompleter) {
newMongoshCompleter = await initNewAutocompleter(instanceState);
}
Expand Down