Offer Shell completion for top-level packages without subpackages

`bazel build //` now completes to `bazel build //:` when there are no packages beneath the top-level package. While this is mostly an edge case that doesn't apply to real projects, it will become more relevant when completion support is added for external repositories in a future PR.

Closes #20679.

PiperOrigin-RevId: 597873995
Change-Id: Ida2b26536325acf130a9792b915ed8f3fe425a24
diff --git a/scripts/bash_completion_test.sh b/scripts/bash_completion_test.sh
index 6a2f396..bc243da 100755
--- a/scripts/bash_completion_test.sh
+++ b/scripts/bash_completion_test.sh
@@ -794,4 +794,19 @@
                      'build //sub_repo/'
 }
 
+test_complete_root_package() {
+    # This test only works for Bazel
+    if [[ ! " ${COMMAND_ALIASES[*]} " =~ " bazel " ]]; then return; fi
+
+    mkdir pkgs_repo
+    touch pkgs_repo/WORKSPACE
+    cat > pkgs_repo/BUILD <<'EOF'
+cc_binary(name = "main")
+EOF
+    cd pkgs_repo 2>/dev/null
+
+    assert_expansion 'build //' \
+                     'build //:'
+}
+
 run_suite "Tests of bash completion of 'blaze' command."