test(whl_library): test a recent fix for pipstar (#3469)

Test for fix for #3352 implemented in #3468.

---------

Co-authored-by: Richard Levasseur <rlevasseur@google.com>
diff --git a/MODULE.bazel b/MODULE.bazel
index 80c7ab1..6486634 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -242,6 +242,7 @@
     "pkgutil_nspkg2",
     "rules_python_runtime_env_tc_info",
     "somepkg_with_build_files",
+    "whl_library_extras_direct_dep",
     "whl_with_build_files",
 )
 
diff --git a/python/private/internal_dev_deps.bzl b/python/private/internal_dev_deps.bzl
index 0e21d8b..fbdd571 100644
--- a/python/private/internal_dev_deps.bzl
+++ b/python/private/internal_dev_deps.bzl
@@ -91,6 +91,36 @@
         enable_implicit_namespace_pkgs = False,
     )
 
+    _whl_library_from_dir(
+        name = "whl_library_extras_direct_dep",
+        root = "//tests/pypi/whl_library/testdata/pkg:BUILD.bazel",
+        output = "pkg-1.0-any-none-any.whl",
+        requirement = "pkg[optional]",
+        # The following is necessary to enable pipstar and make tests faster
+        config_load = "@rules_python//tests/pypi/whl_library/testdata:packages.bzl",
+        dep_template = "@whl_library_extras_{name}//:{target}",
+    )
+    _whl_library_from_dir(
+        name = "whl_library_extras_optional_dep",
+        root = "//tests/pypi/whl_library/testdata/optional_dep:BUILD.bazel",
+        output = "optional_dep-1.0-any-none-any.whl",
+        requirement = "optional_dep",
+        # The following is necessary to enable pipstar and make tests faster
+        config_load = "@rules_python//tests/pypi/whl_library/testdata:packages.bzl",
+    )
+
+def _whl_library_from_dir(*, name, output, root, **kwargs):
+    whl_from_dir_repo(
+        name = "{}_whl".format(name),
+        root = root,
+        output = output,
+    )
+    whl_library(
+        name = name,
+        whl_file = "@{}_whl//:{}".format(name, output),
+        **kwargs
+    )
+
 internal_dev_deps = module_extension(
     implementation = _internal_dev_deps_impl,
     doc = "This extension creates internal rules_python dev dependencies.",
diff --git a/python/private/pypi/whl_library.bzl b/python/private/pypi/whl_library.bzl
index 3c4b6be..db2b6bc 100644
--- a/python/private/pypi/whl_library.bzl
+++ b/python/private/pypi/whl_library.bzl
@@ -359,7 +359,7 @@
 
     # also enable pipstar for any whls that are downloaded without `pip`
     enable_pipstar = (rp_config.enable_pipstar or whl_path) and rctx.attr.config_load
-    enable_pipstar_extract = (rp_config.enable_pipstar and rp_config.bazel_8_or_later) and rctx.attr.config_load
+    enable_pipstar_extract = enable_pipstar and rp_config.bazel_8_or_later
 
     if not whl_path:
         if rctx.attr.urls:
diff --git a/tests/pypi/whl_library/BUILD.bazel b/tests/pypi/whl_library/BUILD.bazel
new file mode 100644
index 0000000..599bb12
--- /dev/null
+++ b/tests/pypi/whl_library/BUILD.bazel
@@ -0,0 +1,11 @@
+load("//python:py_test.bzl", "py_test")
+load("//tests/support:support.bzl", "SUPPORTS_BZLMOD_UNIXY")
+
+py_test(
+    name = "whl_library_extras_test",
+    srcs = ["whl_library_extras_test.py"],
+    target_compatible_with = SUPPORTS_BZLMOD_UNIXY,
+    deps = [
+        "@whl_library_extras_direct_dep//:pkg",
+    ],
+)
diff --git a/tests/pypi/whl_library/testdata/BUILD.bazel b/tests/pypi/whl_library/testdata/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/BUILD.bazel
diff --git a/tests/pypi/whl_library/testdata/optional_dep/BUILD.bazel b/tests/pypi/whl_library/testdata/optional_dep/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/optional_dep/BUILD.bazel
diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA
new file mode 100644
index 0000000..6495d1b
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/METADATA
@@ -0,0 +1,2 @@
+Name: optional-dep
+Version: 1.0
diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/RECORD b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/RECORD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/RECORD
diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL
new file mode 100644
index 0000000..a64521a
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/optional_dep/optional-dep-1.0.dist-info/WHEEL
@@ -0,0 +1 @@
+Wheel-Version: 1.0
diff --git a/tests/pypi/whl_library/testdata/optional_dep/optional_dep.py b/tests/pypi/whl_library/testdata/optional_dep/optional_dep.py
new file mode 100644
index 0000000..4af2718
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/optional_dep/optional_dep.py
@@ -0,0 +1 @@
+I_AM_OPTIONAL = True
diff --git a/tests/pypi/whl_library/testdata/packages.bzl b/tests/pypi/whl_library/testdata/packages.bzl
new file mode 100644
index 0000000..e4a9b0a
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/packages.bzl
@@ -0,0 +1,6 @@
+"""A list of packages that this logical testdata hub repo contains."""
+
+packages = [
+    "optional_dep",
+    "pkg",
+]
diff --git a/tests/pypi/whl_library/testdata/pkg/BUILD.bazel b/tests/pypi/whl_library/testdata/pkg/BUILD.bazel
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/pkg/BUILD.bazel
diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA
new file mode 100644
index 0000000..712b44e
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/METADATA
@@ -0,0 +1,4 @@
+Name: pkg
+Version: 1.0
+Requires-Dist: optional_dep; extra == "optional"
+Provides-Extra: optional
diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/RECORD b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/RECORD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/RECORD
diff --git a/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL
new file mode 100644
index 0000000..a64521a
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/pkg/pkg-1.0.dist-info/WHEEL
@@ -0,0 +1 @@
+Wheel-Version: 1.0
diff --git a/tests/pypi/whl_library/testdata/pkg/pkg.py b/tests/pypi/whl_library/testdata/pkg/pkg.py
new file mode 100644
index 0000000..c5aca09
--- /dev/null
+++ b/tests/pypi/whl_library/testdata/pkg/pkg.py
@@ -0,0 +1,6 @@
+try:
+    import optional_dep
+
+    WITH_EXTRAS = True
+except ImportError:
+    WITH_EXTRAS = False
diff --git a/tests/pypi/whl_library/whl_library_extras_test.py b/tests/pypi/whl_library/whl_library_extras_test.py
new file mode 100644
index 0000000..4fe3444
--- /dev/null
+++ b/tests/pypi/whl_library/whl_library_extras_test.py
@@ -0,0 +1,13 @@
+import unittest
+
+
+class NamespacePackagesTest(unittest.TestCase):
+
+    def test_extras_propagated(self):
+        import pkg
+
+        self.assertEqual(pkg.WITH_EXTRAS, True)
+
+
+if __name__ == "__main__":
+    unittest.main()