[v8.0] Disallow committing imports of ShardingTest and ReplSetTest on 8.0 and lower branches

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.0.12
    • Affects Version/s: 6.0.0, 7.0.0, 8.0.0
    • Component/s: None
    • Catalog and Routing
    • v7.0, v6.0, v5.0
    • CAR Team 2025-02-03, CAR Team 2025-02-17, CAR Team 2025-03-03
    • 200
    • 1
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      For MongoDB 8.1, both ReplSetTest and ShardingTest were converted to ES6 modules (SERVER-81339, SERVER-81341), and thus they need to be imported in jstests as follows:

      import {ShardingTest} from "jstests/libs/shardingtest.js";
      

      For older versions, they should not be imported, and it is an error to do so. However, multiple BACKPORT tickets have been merged with that problem (BACKPORT-23229, BACKPORT-23849, BACKPORT-21361), causing redness in the test suite.

      We should make such mistakes fail the commit queue checks so PRs with them can not be merged. This can be done by adding a ESLint rule in .eslintrc as follows:

        no-restricted-syntax: [
          'error',
          {
            message: "Invalid import. Please do not import replsettest.js in MongoDB v8.0 and below.",
            selector: "ImportDeclaration[source.value=/^jstests\\u002Flibs\\u002Freplsettest.js$/]"
          },
          {
            message: "Invalid import. Please do not import shardingtest.js in MongoDB v8.0 and below.",
            selector: "ImportDeclaration[source.value=/^jstests\\u002Flibs\\u002Fshardingtest.js$/]"
          },
        ]
      

              Assignee:
              Aitor Esteve Alvarado
              Reporter:
              Joan Bruguera Micó
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: