Make sure all other shell/integration tests work with --enable_workspace=false

A part of https://github.com/bazelbuild/bazel/pull/23087

Working towards: https://github.com/bazelbuild/bazel/issues/23023

PiperOrigin-RevId: 661158600
Change-Id: Ib16db0042ff40baaf15937f3320e3a32f5211b36
diff --git a/src/test/shell/integration/aquery_test.sh b/src/test/shell/integration/aquery_test.sh
index f810750..fb68f28 100755
--- a/src/test/shell/integration/aquery_test.sh
+++ b/src/test/shell/integration/aquery_test.sh
@@ -1219,14 +1219,14 @@
 
   bazel clean
 
-  bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \
+  bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
   assert_not_contains "actions" output
 
-  bazel build --noenable_bzlmod --nobuild "//$pkg:foo"
+  bazel build --nobuild "//$pkg:foo"
 
-  bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \
+  bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
 
@@ -1255,9 +1255,9 @@
   QUERY="inputs('.*matching_in.java', outputs('.*matching_out', mnemonic('Genrule')))"
 
   bazel clean
-  bazel build --noenable_bzlmod --nobuild "//$pkg:foo"
+  bazel build --nobuild "//$pkg:foo"
 
-  bazel aquery --noenable_bzlmod --output=textproto --skyframe_state ${QUERY} > output 2> "$TEST_log" \
+  bazel aquery --output=textproto --skyframe_state ${QUERY} > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
 
@@ -1277,14 +1277,14 @@
 
   bazel clean
 
-  bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \
+  bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
   assert_not_contains "actions" output
 
-  bazel build --noenable_bzlmod --nobuild "//$pkg:foo"
+  bazel build --nobuild "//$pkg:foo"
 
-  bazel aquery --noenable_bzlmod --output=textproto --skyframe_state > output 2> "$TEST_log" \
+  bazel aquery --output=textproto --skyframe_state > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
 
@@ -1308,14 +1308,14 @@
 
   bazel clean
 
-  bazel aquery --noenable_bzlmod --output=jsonproto --skyframe_state > output 2> "$TEST_log" \
+  bazel aquery --output=jsonproto --skyframe_state > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
   assert_not_contains "actions" output
 
-  bazel build --noenable_bzlmod --nobuild "//$pkg:foo"
+  bazel build --nobuild "//$pkg:foo"
 
-  bazel aquery --noenable_bzlmod --output=jsonproto --skyframe_state > output 2> "$TEST_log" \
+  bazel aquery --output=jsonproto --skyframe_state > output 2> "$TEST_log" \
     || fail "Expected success"
   cat output >> "$TEST_log"
 
@@ -1336,7 +1336,7 @@
 
   bazel clean
 
-  bazel aquery --noenable_bzlmod --output=text --skyframe_state &> "$TEST_log" \
+  bazel aquery --output=text --skyframe_state &> "$TEST_log" \
     && fail "Expected failure"
   expect_log "--skyframe_state must be used with --output=proto\|textproto\|jsonproto. Invalid aquery output format: text"
 }
@@ -1363,6 +1363,7 @@
 }
 
 function test_aquery_include_template_substitution_for_template_expand_of_py_binary() {
+  add_rules_python "MODULE.bazel"
   local pkg="${FUNCNAME[0]}"
   mkdir -p "$pkg" || fail "mkdir -p $pkg"
   cat > "$pkg/BUILD" <<'EOF'
diff --git a/src/test/shell/integration/bazel_aquery_test.sh b/src/test/shell/integration/bazel_aquery_test.sh
index 44fd9dc..cb21812 100755
--- a/src/test/shell/integration/bazel_aquery_test.sh
+++ b/src/test/shell/integration/bazel_aquery_test.sh
@@ -55,13 +55,14 @@
   local pkg="${FUNCNAME[0]}"
   local pkg2="${FUNCNAME[0]}_pkg2"
   mkdir -p "$pkg" || fail "mkdir -p $pkg"
-  cat > "$pkg/WORKSPACE" <<EOF
+  cat > $(setup_module_dot_bazel "$pkg/MODULE.bazel") <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(
     name = "pkg2",
     path = "../$pkg2",
 )
 EOF
-  write_default_lockfile "$pkg/MODULE.bazel.lock"
+
   touch "$pkg/foo.cpp"
   cat > "$pkg/BUILD" <<EOF
 cc_binary(name = "foo",
@@ -70,7 +71,7 @@
 )
 EOF
   mkdir -p "$pkg2" || fail "mkdir -p $pkg2"
-  touch "$pkg2/WORKSPACE"
+  touch "$pkg2/REPO.bazel"
   touch "$pkg2/bar.cpp"
   cat > "$pkg2/BUILD" <<EOF
 cc_binary(name = "bar",
@@ -82,7 +83,7 @@
   bazel aquery --output=textproto --include_file_write_contents \
      "//:foo" >output 2> "$TEST_log" || fail "Expected success"
   cat output >> "$TEST_log"
-  assert_contains "^file_contents:.*pkg2,__main__,_main" output
+  assert_contains "^file_contents:.*pkg2,+_repo_rules+pkg2" output
 
   bazel aquery --output=text --include_file_write_contents "//:foo" | \
     sed -nr '/Mnemonic: RepoMappingManifest/,/^ *$/p' >output \
@@ -92,7 +93,7 @@
   # Verify file contents if we can decode base64-encoded data.
   if which base64 >/dev/null; then
     sed -nr 's/^ *FileWriteContents: \[(.*)\]/echo \1 | base64 -d/p' output | \
-       sh | tee -a "$TEST_log"  | assert_contains "pkg2,__main__,_main" -
+       sh | tee -a "$TEST_log"  | assert_contains "pkg2,+_repo_rules+pkg2" -
   fi
 }
 
diff --git a/src/test/shell/integration/bazel_java_test.sh b/src/test/shell/integration/bazel_java_test.sh
index c5b82bf..47da103 100755
--- a/src/test/shell/integration/bazel_java_test.sh
+++ b/src/test/shell/integration/bazel_java_test.sh
@@ -51,13 +51,18 @@
 # Javabuilder shall be executed using JDK defined in java_toolchain's java_runtime attribute.
 # Java targets shall be executed using JDK matching --java_runtime_version version.
 function test_java_runtime() {
-  cat << EOF >> WORKSPACE
-load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
-local_java_repository(
+  add_rules_java "MODULE.bazel"
+  add_platforms "MODULE.bazel"
+  cat << EOF >> MODULE.bazel
+_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule")
+_local_java_repository_rule(
     name = "host_javabase",
+    runtime_name = "host_javabase",
     java_home = "$PWD/foobar",
     version = "11",
 )
+register_toolchains("@host_javabase//:runtime_toolchain_definition")
+register_toolchains("@host_javabase//:bootstrap_runtime_toolchain_definition")
 EOF
 
   mkdir java
@@ -118,13 +123,18 @@
 # Javabuilder shall be executed using JDK defined in java_toolchain's java_runtime attribute, not tool_java_runtime.
 # Testing: Javabuilder in exec configuration.
 function test_exec_toolchain_java_runtime_not_set_from_tool_java_runtime_version() {
-  cat << EOF >> WORKSPACE
-load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
-local_java_repository(
+  add_rules_java "MODULE.bazel"
+  add_platforms "MODULE.bazel"
+  cat << EOF >> MODULE.bazel
+_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule")
+_local_java_repository_rule(
     name = "host_javabase",
+    runtime_name = "host_javabase",
     java_home = "$PWD/foobar",
     version = "11",
 )
+register_toolchains("@host_javabase//:runtime_toolchain_definition")
+register_toolchains("@host_javabase//:bootstrap_runtime_toolchain_definition")
 EOF
   mkdir -p java
   cat >> java/rule.bzl <<EOF
@@ -180,13 +190,21 @@
 
 
 function test_javabase() {
-   cat << EOF >> WORKSPACE
-load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
-local_java_repository(
+  add_rules_java "MODULE.bazel"
+  add_platforms "MODULE.bazel"
+  cat << EOF >> MODULE.bazel
+_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule")
+_local_java_repository_rule(
     name = "javabase",
+    runtime_name = "javabase",
     java_home = "$PWD/zoo",
     version = "11",
 )
+register_toolchains("@javabase//:runtime_toolchain_definition")
+register_toolchains("@javabase//:bootstrap_runtime_toolchain_definition")
+
+java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
+use_repo(java_toolchains, "local_jdk")
 EOF
 
   mkdir -p zoo/bin
@@ -273,28 +291,38 @@
 
 # Tests non-existent java_home path.
 function test_no_java_home_path() {
-  cat << EOF >> WORKSPACE
-load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
-local_java_repository(
-    name = "javabase",
-    java_home = "$PWD/i-dont-exist",
+  add_rules_java "MODULE.bazel"
+  add_platforms "MODULE.bazel"
+  cat << EOF >> MODULE.bazel
+_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule")
+_local_java_repository_rule(
+    name = "host_javabase",
+    runtime_name = "host_javabase",
+    java_home = "$PWD/idontexist",
     version = "11",
 )
+register_toolchains("@host_javabase//:runtime_toolchain_definition")
+register_toolchains("@host_javabase//:bootstrap_runtime_toolchain_definition")
 EOF
 
-  bazel build @javabase//... >& $TEST_log && fail "Build with missing java_home should fail."
+  bazel build @host_javabase//... >& $TEST_log && fail "Build with missing java_home should fail."
   expect_log "The path indicated by the \"java_home\" attribute .* does not exist."
 }
 
 
 function test_genrule() {
-  cat << EOF >> WORKSPACE
-load("@bazel_tools//tools/jdk:local_java_repository.bzl", "local_java_repository")
-local_java_repository(
+  add_rules_java "MODULE.bazel"
+  add_platforms "MODULE.bazel"
+  cat << EOF >> MODULE.bazel
+_local_java_repository_rule = use_repo_rule("@rules_java//toolchains:local_java_repository.bzl", "_local_java_repository_rule")
+_local_java_repository_rule(
     name = "foo_javabase",
+    runtime_name = "foo_javabase",
     java_home = "$PWD/foo",
     version = "11",
 )
+register_toolchains("@foo_javabase//:runtime_toolchain_definition")
+register_toolchains("@foo_javabase//:bootstrap_runtime_toolchain_definition")
 EOF
 
   mkdir -p foo/bin bar/bin
diff --git a/src/test/shell/integration/bazel_query_test.sh b/src/test/shell/integration/bazel_query_test.sh
index 86aa3c6..2d6b3e2 100755
--- a/src/test/shell/integration/bazel_query_test.sh
+++ b/src/test/shell/integration/bazel_query_test.sh
@@ -66,7 +66,7 @@
 
 function set_up() {
   add_to_bazelrc "build --package_path=%workspace%"
-  setup_skylib_support
+  add_bazel_skylib "MODULE.bazel"
 }
 
 function tear_down() {
@@ -498,6 +498,7 @@
 }
 
 function test_location_output_source_files() {
+  add_rules_python "MODULE.bazel"
   rm -rf foo
   mkdir -p foo
   cat > foo/BUILD <<EOF
@@ -530,6 +531,7 @@
 }
 
 function test_proto_output_source_files() {
+  add_rules_python "MODULE.bazel"
   rm -rf foo
   mkdir -p foo
   cat > foo/BUILD <<EOF
@@ -550,6 +552,7 @@
 }
 
 function test_xml_output_source_files() {
+  add_rules_python "MODULE.bazel"
   rm -rf foo
   mkdir -p foo
   cat > foo/BUILD <<EOF
@@ -978,7 +981,8 @@
 }
 
 function test_unnecessary_external_workspaces_not_loaded() {
-  cat > WORKSPACE <<'EOF'
+  cat > MODULE.bazel <<'EOF'
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(
     name = "notthere",
     path = "/nope",
diff --git a/src/test/shell/integration/build_event_stream_test.sh b/src/test/shell/integration/build_event_stream_test.sh
index 1d3532d..00495a5 100755
--- a/src/test/shell/integration/build_event_stream_test.sh
+++ b/src/test/shell/integration/build_event_stream_test.sh
@@ -26,7 +26,7 @@
 set -e
 
 function set_up() {
-  setup_skylib_support
+  add_bazel_skylib "MODULE.bazel"
 
   mkdir -p pkg
   touch pkg/somesourcefile
@@ -1249,7 +1249,7 @@
   srcs = ["doesnotexist"],
 )
 EOF
-  (bazel build --noenable_bzlmod --build_event_text_file="${TEST_log}" :badfilegroup \
+  (bazel build --build_event_text_file="${TEST_log}" :badfilegroup \
     && fail "Expected failure") || :
   # There should be precisely one event with target_completed as event id type
   (echo 'g/^id/+1p'; echo 'q') | ed "${TEST_log}" 2>&1 | tail -n +2 > event_id_types
@@ -1259,7 +1259,7 @@
   [ `grep unconfigured_label event_id_types | wc -l` -eq 1 ] \
       || fail "not precisely one unconfigured_label event id"
 
-  (bazel build -k --noenable_bzlmod --build_event_text_file="${TEST_log}" :badfilegroup :doesnotexist \
+  (bazel build -k --build_event_text_file="${TEST_log}" :badfilegroup :doesnotexist \
     && fail "Expected failure") || :
   # There should be precisely two events with target_completed as event id type
   (echo 'g/^id/+1p'; echo 'q') | ed "${TEST_log}" 2>&1 | tail -n +2 > event_id_types
@@ -1493,7 +1493,7 @@
   # toolchain resolution and also the //external package. This way we don't need
   # to bother making careful assertions about these packages in our actual test
   # logic below.
-  bazel build --noenable_bzlmod --nobuild \
+  bazel build --nobuild \
     //just-to-get-packages-needed-for-toolchain-resolution:whatever \
     >& "$TEST_log" || fail "Expected success"
 
@@ -1535,7 +1535,6 @@
 EOF
 
   bazel build \
-    --noenable_bzlmod \
     --nobuild \
     --keep_going \
     --build_event_text_file=bep.txt \
diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh
index 5e84246..c8d0fde 100755
--- a/src/test/shell/integration/configured_query_test.sh
+++ b/src/test/shell/integration/configured_query_test.sh
@@ -286,6 +286,7 @@
 function test_show_transitive_config_fragments() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -359,6 +360,7 @@
 function test_show_transitive_config_fragments_alias() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -420,6 +422,7 @@
 function test_show_transitive_config_fragments_host_deps() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -451,6 +454,7 @@
 function test_show_transitive_config_fragments_through_output_file() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -482,6 +486,7 @@
 function test_show_direct_config_fragments() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -907,6 +912,7 @@
 function test_starlark_output_mode() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -1041,6 +1047,7 @@
 )
 EOF
 
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load(":rules.bzl", "bool_flag", "list_flag", "root_rule")
 load("@rules_python//python:py_library.bzl", "py_library")
@@ -1111,7 +1118,7 @@
 function test_starlark_build_options_invalid_arg() {
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
-
+  add_rules_python "MODULE.bazel"
   cat > $pkg/BUILD <<'EOF'
 load("@rules_python//python:py_library.bzl", "py_library")
 
@@ -1389,13 +1396,14 @@
   local -r pkg=$FUNCNAME
 
   mkdir -p $pkg/repo
-  touch $pkg/repo/WORKSPACE
+  touch $pkg/repo/REPO.bazel
   cat > $pkg/repo/BUILD <<EOF
   toolchain_type(name = "toolchain_type")
 EOF
 
-  cat > $pkg/WORKSPACE <<EOF
-  local_repository(name = "repo", path = "./repo")
+  cat > $pkg/MODULE.bazel <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
+local_repository(name = "repo", path = "./repo")
 EOF
   bazel cquery --output=starlark --starlark:expr 'target' @repo//:toolchain_type >output \
     2>"$TEST_log" && fail "Expected failure"
@@ -1421,8 +1429,9 @@
 EOF
 
   mkdir -p $dir/main
-  write_default_lockfile $dir/main/MODULE.bazel.lock
-  cat > $dir/main/WORKSPACE <<EOF
+  setup_module_dot_bazel $dir/main/MODULE.bazel
+  cat > $dir/main/MODULE.bazel <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(name = "repo", path = "../repo")
 EOF
   touch $dir/main/BUILD
@@ -1450,8 +1459,9 @@
 EOF
 
   mkdir -p $dir/main
-  write_default_lockfile $dir/main/MODULE.bazel.lock
-  cat > $dir/main/WORKSPACE <<EOF
+  setup_module_dot_bazel $dir/main/MODULE.bazel
+  cat > $dir/main/MODULE.bazel <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(name = "repo", path = "../repo")
 EOF
   touch $dir/main/BUILD
diff --git a/src/test/shell/integration/exec_group_test.sh b/src/test/shell/integration/exec_group_test.sh
index 029787c..f453c0d 100755
--- a/src/test/shell/integration/exec_group_test.sh
+++ b/src/test/shell/integration/exec_group_test.sh
@@ -680,7 +680,7 @@
 )
 EOF
 
-  cat >> WORKSPACE <<EOF
+  cat >> ${TOOLCHAIN_REGISTRAION_FILE} <<EOF
 register_toolchains('//${pkg}/platform:all')
 register_execution_platforms('//${pkg}/platform:all')
 EOF
@@ -774,7 +774,7 @@
 )
 EOF
 
-  cat >> WORKSPACE <<EOF
+  cat >> ${TOOLCHAIN_REGISTRAION_FILE} <<EOF
 register_toolchains('//${pkg}/other:all')
 EOF
 
diff --git a/src/test/shell/integration/implicit_dependency_reporting_test.sh b/src/test/shell/integration/implicit_dependency_reporting_test.sh
index b84cc20..0bf759d 100755
--- a/src/test/shell/integration/implicit_dependency_reporting_test.sh
+++ b/src/test/shell/integration/implicit_dependency_reporting_test.sh
@@ -62,7 +62,7 @@
   mkdir custommessage
   cd custommessage
 
-  create_workspace_with_default_repos WORKSPACE
+  setup_module_dot_bazel "MODULE.bazel"
   cat > rule.bzl <<'EOF'
 def _rule_impl(ctx):
   out = ctx.actions.declare_file(ctx.label.name + ".txt")
diff --git a/src/test/shell/integration/loading_phase_test.sh b/src/test/shell/integration/loading_phase_test.sh
index 15313ed..8576f3b 100755
--- a/src/test/shell/integration/loading_phase_test.sh
+++ b/src/test/shell/integration/loading_phase_test.sh
@@ -324,26 +324,26 @@
 
   echo 'workspace(name="wsname1")' > WORKSPACE
   echo 'sh_library(name="shname1")' > $pkg/foo/BUILD
-  bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
+  bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
       || fail "Expected success"
   expect_log "Loading package: $pkg/foo"
   expect_log "//$pkg/foo:shname1"
 
   echo 'sh_library(name="shname2")' > $pkg/foo/BUILD
-  bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
+  bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
       || fail "Expected success"
   expect_log "Loading package: $pkg/foo"
   expect_log "//$pkg/foo:shname2"
 
   # Test that comment changes do not cause package reloading
   echo '#benign comment' >> WORKSPACE
-  bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
+  bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
       || fail "Expected success"
   expect_not_log "Loading package: $pkg/foo"
   expect_log "//$pkg/foo:shname2"
 
   echo 'workspace(name="wsname2")' > WORKSPACE
-  bazel query --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
+  bazel query --enable_workspace --experimental_ui_debug_all_events //$pkg/foo:all >& "$TEST_log" \
       || fail "Expected success"
   expect_log "Loading package: $pkg/foo"
   expect_log "//$pkg/foo:shname2"
@@ -467,7 +467,7 @@
   local -r pkg="${FUNCNAME[0]}"
   mkdir "$pkg" || fail "Could not mkdir $pkg"
   echo "filegroup(name = '$pkg')" > "$pkg/BUILD"
-  setup_skylib_support
+  add_bazel_skylib "MODULE.bazel"
   # Ensure bazel-<pkg> is created.
   bazel build --symlink_prefix="foo_prefix-" "//$pkg" || fail "build failed"
   [[ -d "foo_prefix-bin" ]] || fail "bazel-bin was not created"
diff --git a/src/test/shell/integration/modify_execution_info_test.sh b/src/test/shell/integration/modify_execution_info_test.sh
index d627c99..5038e42 100755
--- a/src/test/shell/integration/modify_execution_info_test.sh
+++ b/src/test/shell/integration/modify_execution_info_test.sh
@@ -151,20 +151,7 @@
 
 function test_modify_execution_info_various_types() {
   if [[ "$PRODUCT_NAME" = "bazel" ]]; then
-    cat "$(rlocation "io_bazel/src/test/shell/integration/rules_proto_stanza.txt")" >>WORKSPACE
-    cat >> WORKSPACE << EOF
-load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
-rules_proto_dependencies()
-rules_proto_toolchains()
-
-# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib.
-new_local_repository(
-    name = "io_bazel",
-    path = "$(dirname $(dirname $(dirname $(rlocation io_bazel/third_party/zlib/BUILD))))",
-    build_file_content = "# Intentionally left empty.",
-    workspace_file_content = "workspace(name = 'io_bazel')",
-)
-EOF
+    add_rules_python "MODULE.bazel"
   fi
   local pkg="${FUNCNAME[0]}"
   mkdir -p "$pkg" || fail "mkdir -p $pkg"
diff --git a/src/test/shell/integration/prelude_test.sh b/src/test/shell/integration/prelude_test.sh
index 30aae9b..7893adb6 100755
--- a/src/test/shell/integration/prelude_test.sh
+++ b/src/test/shell/integration/prelude_test.sh
@@ -28,7 +28,6 @@
 #### TESTS #############################################################
 
 function test_prelude() {
-  create_workspace_with_default_repos WORKSPACE
 
   mkdir -p tools/build_rules
   touch tools/build_rules/BUILD
@@ -53,7 +52,8 @@
 }
 
 function test_prelude_external_repository() {
-  cat > WORKSPACE << EOF
+  cat > MODULE.bazel << EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(
   name = "imported_workspace",
   path = "$PWD/imported_workspace",
@@ -77,7 +77,7 @@
 EOF
 
   mkdir -p imported_workspace
-  touch imported_workspace/WORKSPACE
+  touch imported_workspace/REPO.bazel
 
   mkdir -p imported_workspace/tools/build_rules
   touch imported_workspace/tools/build_rules/BUILD
@@ -100,7 +100,7 @@
   output=$(cat bazel-genfiles/gr.out)
   check_eq "outer from test_prelude_external_repository, outer workspace" "$output" "unexpected output in gr.out"
 
-  output=$(cat bazel-genfiles/external/imported_workspace/gr_inner.out)
+  output=$(cat bazel-genfiles/external/+_repo_rules+imported_workspace/gr_inner.out)
   check_eq "inner from test_prelude_external_repository, inner workspace" "$output" "unexpected output in gr_inner.out"
 }
 
diff --git a/src/test/shell/integration/py_args_escaping_test.sh b/src/test/shell/integration/py_args_escaping_test.sh
index 4c5c537..9d6e588 100755
--- a/src/test/shell/integration/py_args_escaping_test.sh
+++ b/src/test/shell/integration/py_args_escaping_test.sh
@@ -226,7 +226,7 @@
 function test_args_escaping() {
   local -r ws="$TEST_TMPDIR/${FUNCNAME[0]}"  # unique workspace for this test
   mkdir -p "$ws"
-  create_workspace_with_default_repos "$ws/WORKSPACE"
+  setup_module_dot_bazel "$ws/MODULE.bazel"
 
   create_py_file_that_prints_args "$ws"
   create_build_file_with_many_args "$ws"
@@ -248,7 +248,7 @@
 function test_untokenizable_args() {
   local -r ws="$TEST_TMPDIR/${FUNCNAME[0]}"  # unique workspace for this test
   mkdir -p "$ws"
-  create_workspace_with_default_repos "$ws/WORKSPACE"
+  setup_module_dot_bazel "$ws/MODULE.bazel"
 
   create_py_file_that_prints_args "$ws"
   create_build_file_for_untokenizable_args "$ws"
@@ -263,7 +263,7 @@
 function test_host_config() {
   local -r ws="$TEST_TMPDIR/${FUNCNAME[0]}"  # unique workspace for this test
   mkdir -p "$ws"
-  create_workspace_with_default_repos "$ws/WORKSPACE"
+  setup_module_dot_bazel "$ws/MODULE.bazel"
 
   cat >"$ws/BUILD" <<'eof'
 load("//:rule.bzl", "run_host_configured")
diff --git a/src/test/shell/integration/python_stub_test.sh b/src/test/shell/integration/python_stub_test.sh
index de3f1e3..f089307 100755
--- a/src/test/shell/integration/python_stub_test.sh
+++ b/src/test/shell/integration/python_stub_test.sh
@@ -70,6 +70,7 @@
 
 # Tests that Python 2 or Python 3 is actually invoked.
 function test_python_version() {
+  add_rules_python "MODULE.bazel"
   mkdir -p test
   touch test/main3.py
   cat > test/BUILD << EOF
@@ -91,6 +92,7 @@
 }
 
 function test_can_build_py_library_at_top_level_regardless_of_version() {
+  add_rules_python "MODULE.bazel"
   mkdir -p test
   cat > test/BUILD << EOF
 load("@rules_python//python:py_library.bzl", "py_library")
@@ -113,6 +115,7 @@
 # capable of finding its runfiles directory by considering RUNFILES_DIR
 # and RUNFILES_MANIFEST_FILE set by the caller.
 function test_python_through_bash_without_runfile_links() {
+  add_rules_python "MODULE.bazel"
   mkdir -p python_through_bash
 
   cat > python_through_bash/BUILD << EOF
diff --git a/src/test/shell/integration/python_test.sh b/src/test/shell/integration/python_test.sh
index d2d5e28..c3afe22 100755
--- a/src/test/shell/integration/python_test.sh
+++ b/src/test/shell/integration/python_test.sh
@@ -82,6 +82,7 @@
 # * https://github.com/bazelbuild/bazel/issues/2394
 # * https://bugs.python.org/issue28425
 function test_python_binary_empty_files_in_runfiles_are_regular_files() {
+  add_rules_python "MODULE.bazel"
   mkdir -p test/mypackage
   cat > test/BUILD <<'EOF'
 load("@rules_python//python:py_test.bzl", "py_test")
diff --git a/src/test/shell/integration/runfiles_test.sh b/src/test/shell/integration/runfiles_test.sh
index 73e87d9..5526f13 100755
--- a/src/test/shell/integration/runfiles_test.sh
+++ b/src/test/shell/integration/runfiles_test.sh
@@ -71,8 +71,6 @@
 
 set -e
 
-disable_bzlmod
-
 function create_pkg() {
   local -r pkg=$1
   mkdir -p $pkg
@@ -149,6 +147,8 @@
 }
 
 function test_foo_runfiles() {
+  add_rules_python "MODULE.bazel"
+  local WORKSPACE_NAME=$TEST_WORKSPACE
   local -r pkg=$FUNCNAME
   create_pkg $pkg
 cat > BUILD << EOF
@@ -379,8 +379,7 @@
   # TODO(b/174761497): Re-enable the test outside of Bazel.
   [[ "${PRODUCT_NAME}" != bazel ]] && return 0
 
-  # Rewrite the workspace name but leave the rest of WORKSPACE alone.
-  sed -ie 's,workspace(.*,workspace(name = "foo"),' WORKSPACE
+  echo 'workspace(name = "foo")' > WORKSPACE
 
   cat > BUILD <<EOF
 cc_binary(
@@ -392,12 +391,12 @@
   cat > thing.cc <<EOF
 int main() { return 0; }
 EOF
-  bazel build //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed"
+  bazel build --noenable_bzlmod --enable_workspace //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed"
   [[ -d ${PRODUCT_NAME}-bin/thing${EXT}.runfiles/foo ]] || fail "foo not found"
 
   # Change workspace name to bar.
   sed -ie 's,workspace(.*,workspace(name = "bar"),' WORKSPACE
-  bazel build //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed"
+  bazel build --noenable_bzlmod --enable_workspace //:thing $EXTRA_BUILD_FLAGS &> $TEST_log || fail "Build failed"
   [[ -d ${PRODUCT_NAME}-bin/thing${EXT}.runfiles/bar ]] || fail "bar not found"
   [[ ! -d ${PRODUCT_NAME}-bin/thing${EXT}.runfiles/foo ]] \
     || fail "Old foo still found"
diff --git a/src/test/shell/integration/sandboxing_test.sh b/src/test/shell/integration/sandboxing_test.sh
index 12e8fc4..18622b1 100755
--- a/src/test/shell/integration/sandboxing_test.sh
+++ b/src/test/shell/integration/sandboxing_test.sh
@@ -24,8 +24,6 @@
 source "${CURRENT_DIR}/../integration_test_setup.sh" \
   || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
 
-disable_bzlmod
-
 function set_up() {
   add_to_bazelrc "build --spawn_strategy=sandboxed"
   add_to_bazelrc "build --genrule_strategy=sandboxed"
@@ -352,6 +350,7 @@
   cat << 'EOF' >> examples/genrule/datafile
 this is a datafile
 EOF
+  local WORKSPACE_NAME=$TEST_WORKSPACE
   # The workspace name is initialized in testenv.sh; use that var rather than
   # hardcoding it here. The extra sed pass is so we can selectively expand that
   # one var while keeping the rest of the heredoc literal.
@@ -1061,6 +1060,7 @@
   file_inode_a=$(awk '/The file inode is/ {print $5}' ${test_output})
 
   local output_base="$(bazel info output_base)"
+  local WORKSPACE_NAME=$TEST_WORKSPACE
   local stashed_test_dir="${output_base}/sandbox/sandbox_stash/TestRunner/6/execroot/$WORKSPACE_NAME"
   touch $(find "$stashed_test_dir/$out_directory/" -name a.sh.runfiles -type d)"/$WORKSPACE_NAME/pkg/file4.txt"
 
diff --git a/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh b/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh
index a8723bb..11e7ce4 100755
--- a/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh
+++ b/src/test/shell/integration/starlark_configurations_external_workspaces_test.sh
@@ -127,12 +127,13 @@
 
 
 function test_set_flag_with_workspace_name() {
+  echo "workspace(name = '${WORKSPACE_NAME}')" > WORKSPACE
   local -r pkg=$FUNCNAME
   mkdir -p $pkg
 
   write_build_setting_bzl "@${WORKSPACE_NAME}"
 
-  bazel build //$pkg:my_drink --@//$pkg:type="coffee" \
+  bazel build --enable_workspace //$pkg:my_drink --@//$pkg:type="coffee" \
     > output 2>"$TEST_log" || fail "Expected success"
 
   expect_log "type=coffee"
@@ -144,12 +145,12 @@
   mkdir -p $subpkg
 
   ## set up outer repo
-  cat > $pkg/WORKSPACE <<EOF
+  cat > $(setup_module_dot_bazel "$pkg/MODULE.bazel") <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(
   name = "sub",
   path = "./sub")
 EOF
-  write_default_lockfile "$pkg/MODULE.bazel.lock"
 
   ## set up inner repo
   cat > $subpkg/BUILD <<EOF
@@ -199,10 +200,9 @@
 )
 EOF
 
-  cat > $subpkg/WORKSPACE <<EOF
-workspace(name = "sub")
+  cat > $(setup_module_dot_bazel "$subpkg/MODULE.bazel") <<EOF
+module(name = "sub")
 EOF
-  write_default_lockfile "$subpkg/MODULE.bazel.lock"
 
   # from the outer repo
   cd $pkg
diff --git a/src/test/shell/integration/starlark_configurations_test.sh b/src/test/shell/integration/starlark_configurations_test.sh
index c91612e..6017335 100755
--- a/src/test/shell/integration/starlark_configurations_test.sh
+++ b/src/test/shell/integration/starlark_configurations_test.sh
@@ -815,7 +815,7 @@
 
   bazel build //$pkg:demo >& "$TEST_log" && fail "Expected failure"
   expect_not_log "crashed due to an internal error"
-  expect_log "`cfg` must be set to a transition object initialized by the transition() function"
+  expect_log '`cfg` must be set to a transition object initialized by the transition() function'
 }
 
 function write_attr_list_transition() {
diff --git a/src/test/shell/integration/stub_finds_runfiles_test.sh b/src/test/shell/integration/stub_finds_runfiles_test.sh
index de7948c..98e7a17 100755
--- a/src/test/shell/integration/stub_finds_runfiles_test.sh
+++ b/src/test/shell/integration/stub_finds_runfiles_test.sh
@@ -35,6 +35,7 @@
 #### HELPER FUNCTIONS ##################################################
 
 function set_up() {
+  add_rules_python "MODULE.bazel"
   mkdir -p pkg pkg/java
   cat > pkg/BUILD << 'EOF'
 load("@rules_python//python:py_binary.bzl", "py_binary")
diff --git a/src/test/shell/integration/target_compatible_with_test.sh b/src/test/shell/integration/target_compatible_with_test.sh
index 8e5b162..c3dc96e 100755
--- a/src/test/shell/integration/target_compatible_with_test.sh
+++ b/src/test/shell/integration/target_compatible_with_test.sh
@@ -64,6 +64,7 @@
 fi
 
 function set_up() {
+  add_platforms "MODULE.bazel"
   mkdir -p target_skipping || fail "couldn't create directory"
   cat > target_skipping/pass.sh <<'EOF'
 #!/bin/bash
@@ -890,7 +891,7 @@
 # Validates that we can express targets being compatible with everything _but_
 # A and B.
 function test_inverse_logic() {
-  setup_skylib_support
+  add_bazel_skylib "MODULE.bazel"
 
   # Not using 'EOF' because injecting skylib_package
   cat >> target_skipping/BUILD <<EOF
@@ -1076,11 +1077,12 @@
 # for https://github.com/bazelbuild/bazel/issues/12897.
 function test_incompatible_with_missing_toolchain() {
   set_up_custom_toolchain
-  cat >> WORKSPACE <<'EOF'
+  cat >> MODULE.bazel <<'EOF'
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(name = 'build_bazel_apple_support', path = 'build_bazel_apple_support')
 EOF
   mkdir -p build_bazel_apple_support/platforms
-  touch build_bazel_apple_support/WORKSPACE
+  touch build_bazel_apple_support/REPO.bazel
   cat > build_bazel_apple_support/platforms/BUILD <<'EOF'
 package(default_visibility=["//visibility:public"])
 platform(
@@ -1237,7 +1239,7 @@
 # Validates that we successfully skip analysistest rule targets when they
 # depend on incompatible targets.
 function test_analysistest() {
-  setup_skylib_support
+  add_bazel_skylib "MODULE.bazel"
 
   # Not using 'EOF' because injecting skylib_package
   cat > target_skipping/analysistest.bzl <<EOF
diff --git a/src/test/shell/integration/target_compatible_with_test_external_repo.sh b/src/test/shell/integration/target_compatible_with_test_external_repo.sh
index 1010f2f..ab2b5f5 100755
--- a/src/test/shell/integration/target_compatible_with_test_external_repo.sh
+++ b/src/test/shell/integration/target_compatible_with_test_external_repo.sh
@@ -52,13 +52,14 @@
 
 function set_up() {
   mkdir -p target_skipping || fail "couldn't create directory"
+  touch target_skipping/MODULE.bazel
   cat > target_skipping/pass.sh <<EOF || fail "couldn't create pass.sh"
 #!/bin/bash
 exit 0
 EOF
   chmod +x target_skipping/pass.sh
 
-  cat > target_skipping/fail.sh <<EOF|| fail "couldn't create fail.sh"
+  cat > target_skipping/fail.sh <<EOF || fail "couldn't create fail.sh"
 #!/bin/bash
 exit 1
 EOF
@@ -161,9 +162,6 @@
     ],
 )
 EOF
-
-  cat > target_skipping/WORKSPACE <<EOF || fail "couldn't create WORKSPACE"
-EOF
 }
 
 add_to_bazelrc "test --nocache_test_results"
@@ -174,14 +172,15 @@
 }
 
 function test_failure_on_incompatible_top_level_target_in_external_repo() {
-  cat >> target_skipping/WORKSPACE <<EOF
+  cat > $(setup_module_dot_bazel "target_skipping/MODULE.bazel") <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(
     name = "test_repo",
     path = "third_party/test_repo",
 )
 EOF
   mkdir -p target_skipping/third_party/test_repo/
-  touch target_skipping/third_party/test_repo/WORKSPACE
+  touch target_skipping/third_party/test_repo/REPO.bazel
   cat > target_skipping/third_party/test_repo/BUILD <<EOF
 cc_binary(
     name = "bin",
@@ -196,7 +195,6 @@
     return 0;
 }
 EOF
-  write_default_lockfile "target_skipping/MODULE.bazel.lock"
   cd target_skipping || fail "couldn't cd into workspace"
   bazel test \
     --show_result=10 \
@@ -204,12 +202,12 @@
     --platforms=@//:foo3_platform \
     --build_event_text_file="${TEST_log}".build.json \
     @test_repo//:bin &> "${TEST_log}" && fail "Bazel passed unexpectedly."
-  expect_log 'ERROR:.*Target @@test_repo//:bin is incompatible and cannot be built'
+  expect_log 'ERROR:.*Target @@+_repo_rules+test_repo//:bin is incompatible and cannot be built'
   expect_log '^ERROR: Build did NOT complete successfully'
   # Now look at the build event log.
   mv "${TEST_log}".build.json "${TEST_log}"
   expect_log '^    name: "PARSING_FAILURE"$'
-  expect_log 'Target @@test_repo//:bin is incompatible and cannot be built.'
+  expect_log 'Target @@+_repo_rules+test_repo//:bin is incompatible and cannot be built.'
 }
 
 # Regression test for https://github.com/bazelbuild/bazel/issues/12374
@@ -226,8 +224,8 @@
 )
 EOF
 
-  cat >> WORKSPACE <<EOF
-load(':repo.bzl', 'repo_rule')
+  cat >> MODULE.bazel <<EOF
+repo_rule = use_repo_rule(':repo.bzl', 'repo_rule')
 repo_rule(name = 'defines_tcw')
 EOF
 
diff --git a/src/test/shell/integration/toolchain_test.sh b/src/test/shell/integration/toolchain_test.sh
index 98149b6..95c0925 100755
--- a/src/test/shell/integration/toolchain_test.sh
+++ b/src/test/shell/integration/toolchain_test.sh
@@ -44,9 +44,9 @@
 
 function set_up() {
   create_new_workspace
-  # Clean out the WORKSPACE file.
-  rm WORKSPACE
-  touch WORKSPACE
+  # Clean out the MODULE.bazel file.
+  rm -f $TOOLCHAIN_REGISTRAION_FILE
+  setup_module_dot_bazel "MODULE.bazel"
 
   # Create shared report rule for printing toolchain info.
   mkdir -p report
@@ -159,7 +159,7 @@
   local exec_compatible_with="${3:-"[]"}"
   local target_compatible_with="${4:-"[]"}"
 
-  cat >> WORKSPACE <<EOF
+  cat >> $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//register/${pkg}:${toolchain_name}_1')
 EOF
 
@@ -877,7 +877,7 @@
   write_test_toolchain "${pkg}"
   write_test_rule "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:toolchain_1')
 register_toolchains('//${pkg}:toolchain_2')
 EOF
@@ -971,7 +971,7 @@
   write_test_rule "${pkg}"
   write_register_toolchain "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('/:invalid:label:syntax')
 EOF
 
@@ -988,7 +988,12 @@
 EOF
 
   bazel build "//${pkg}/demo:use" &> $TEST_log && fail "Build failure expected"
-  expect_log "error parsing target pattern \"/:invalid:label:syntax\": invalid package name '/': package names may not start with '/'"
+
+  if [[ $PRODUCT_NAME == "bazel" ]]; then
+    expect_log "Expected absolute target patterns (must begin with '//' or '@') for 'register_toolchains' argument, but got '/:invalid:label:syntax'"
+  else
+    expect_log "error parsing target pattern \"/:invalid:label:syntax\": invalid package name '/': package names may not start with '/'"
+  fi
 }
 
 function test_register_toolchain_error_invalid_target() {
@@ -996,7 +1001,7 @@
   write_test_toolchain "${pkg}"
   write_test_rule "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}/demo:not_a_target')
 EOF
 
@@ -1021,7 +1026,7 @@
   write_test_toolchain "${pkg}"
   write_test_rule "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}/demo:invalid')
 EOF
 
@@ -1051,7 +1056,7 @@
 
 function test_register_toolchain_error_invalid_pattern() {
   local -r pkg="${FUNCNAME[0]}"
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:bad1')
 register_toolchains('//${pkg}:bad2')
 EOF
@@ -1102,7 +1107,7 @@
 )
 EOF
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}/invalid:invalid_toolchain')
 EOF
 
@@ -1410,7 +1415,7 @@
   write_test_toolchain "${pkg}"
   write_test_rule "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:toolchain_1')
 register_toolchains('//${pkg}:toolchain_2')
 EOF
@@ -1486,7 +1491,7 @@
   write_test_toolchain "${pkg}"
   write_test_rule "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:toolchain_1')
 register_toolchains('//${pkg}:toolchain_2')
 EOF
@@ -1645,7 +1650,7 @@
 EOF
 
   # Register the toolchains
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:test_toolchain_foo', '//${pkg}:test_toolchain_bar')
 EOF
 
@@ -1716,7 +1721,7 @@
 EOF
 
   # Create and register a toolchain
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:toolchain_var_1')
 EOF
 
@@ -1866,8 +1871,8 @@
 )
 EOF
 
-  # Finally, set up the misconfigured WORKSPACE file.
-  cat >WORKSPACE <<EOF
+  # Finally, set up the misconfigured MODULE.bazel file.
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains(
     '//${pkg}:upper_toolchain', # Not a toolchain() target!
     '//${pkg}:lower_toolchain_impl',
@@ -2210,7 +2215,7 @@
 )
 EOF
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}/project:toolchain')
 EOF
 
@@ -2338,7 +2343,7 @@
   local -r pkg="${FUNCNAME[0]}"
   write_test_toolchain "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:toolchain_1')
 register_toolchains('//${pkg}:toolchain_2')
 EOF
@@ -2507,7 +2512,7 @@
 EOF
 
   # Register all the toolchains.
-  cat >WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains("//${pkg}/inner:all")
 register_toolchains("//${pkg}/outer:all")
 EOF
@@ -2557,7 +2562,7 @@
   # Create a repository that defines a toolchain type and simple rule.
   # The toolchain type used in the repository is relative to the repository.
   mkdir -p "${pkg}/external/rules_foo"
-  touch "${pkg}/external/rules_foo/WORKSPACE"
+  touch "${pkg}/external/rules_foo/REPO.bazel"
   mkdir -p "${pkg}/external/rules_foo/rule"
   touch "${pkg}/external/rules_foo/rule/BUILD"
   cat > "${pkg}/external/rules_foo/rule/rule.bzl" <<EOF
@@ -2633,8 +2638,9 @@
 foo_rule(name = "demo")
 EOF
 
-  # Set up the WORKSPACE.
-  cat > WORKSPACE <<EOF
+  # Set up the MODULE.bazel.
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
+local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
 local_repository(
   name = "rules_foo",
   path = "${pkg}/external/rules_foo",
@@ -2648,7 +2654,7 @@
   # Test the build.
   bazel build \
     "//${pkg}/demo:demo" &> $TEST_log || fail "Build failed"
-  expect_log "foo_tool = <target @@rules_foo//foo_tools:foo_tool>"
+  expect_log "foo_tool = <target @@+_repo_rules+rules_foo//foo_tools:foo_tool>"
 }
 
 function test_exec_platform_order_with_mandatory_toolchains {
@@ -2673,7 +2679,7 @@
 )
 EOF
   # Register them in order.
-  cat >> WORKSPACE <<EOF
+  cat >> $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_execution_platforms("//${pkg}/platforms:platform1", "//${pkg}/platforms:platform2")
 EOF
 
@@ -2747,7 +2753,7 @@
 )
 EOF
   # Register them in order.
-  cat >> WORKSPACE <<EOF
+  cat >> $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_execution_platforms("//${pkg}/platforms:platform1", "//${pkg}/platforms:platform2")
 EOF
 
@@ -2805,7 +2811,7 @@
   write_test_toolchain "${pkg}"
   write_test_rule "${pkg}"
 
-  cat > WORKSPACE <<EOF
+  cat > $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains('//${pkg}:toolchain_1')
 EOF
 
diff --git a/src/test/shell/integration/toolchain_transition_test.sh b/src/test/shell/integration/toolchain_transition_test.sh
index 0f8ad64..de08903 100755
--- a/src/test/shell/integration/toolchain_transition_test.sh
+++ b/src/test/shell/integration/toolchain_transition_test.sh
@@ -176,8 +176,8 @@
 )
 EOF
 
-  # Append to WORKSPACE
-  cat >>WORKSPACE <<EOF
+  # Append to $TOOLCHAIN_REGISTRAION_FILE
+  cat >> $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_execution_platforms(
     "//${pkg}/platform:exec_alpha",
     "//${pkg}/platform:exec_beta",
@@ -309,8 +309,8 @@
 )
 EOF
 
-  # Append to WORKSPACE
-  cat >>WORKSPACE <<EOF
+  # Append to $TOOLCHAIN_REGISTRAION_FILE
+  cat >> $TOOLCHAIN_REGISTRAION_FILE <<EOF
 register_toolchains(
     "//${pkg}/toolchain:sample_toolchain_alpha",
     "//${pkg}/toolchain:sample_toolchain_beta",
diff --git a/src/test/shell/testenv.sh.tmpl b/src/test/shell/testenv.sh.tmpl
index a92b519..f18d74c 100755
--- a/src/test/shell/testenv.sh.tmpl
+++ b/src/test/shell/testenv.sh.tmpl
@@ -92,6 +92,9 @@
 workspace_file="${BAZEL_RUNFILES}/WORKSPACE"
 distdir_bzl_file="${BAZEL_RUNFILES}/distdir.bzl"
 
+# Where to register toolchains
+TOOLCHAIN_REGISTRAION_FILE="MODULE.bazel"
+
 # Tools directory location
 tools_dir="$(dirname $(rlocation io_bazel/tools/BUILD))"