Fix FATAL crash in bazel mod on dependency cycles (#31084)

Fixes #29437

### Description
When `bazel mod` encounters a dependency cycle (such as when an `archive_override` specifies a file overlay referencing the main repo, or module extensions form a cyclic dependency), Bazel previously crashed with an internal error:
```text
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.UnsupportedOperationException: unexpected access of cycle details
        at com.google.devtools.build.skyframe.CycleInfo$CycleInfoNoDetails.getTopKey(CycleInfo.java:124)
        at com.google.devtools.build.lib.bazel.commands.ModCommand.execInternal(ModCommand.java:301)
```

#### Root Cause
1. `ModCommand` evaluated the Skyframe keys using `skyframeExecutor.prepareAndGet(keys.build(), evaluationContext)`, which unconditionally forces `setStoreExactCycles(false)` (originally added for `SkyQueryEnvironment`).
2. When `storeExactCycles` is `false`, `SimpleCycleDetector` produces `CycleInfoNoDetails`. Calling `getTopKey()` or `getCycle()` on `CycleInfoNoDetails` unconditionally throws `UnsupportedOperationException: unexpected access of cycle details`.
3. `ModCommand` called `cycleInfo.getFirst().getTopKey()` without checking `hasCycleDetails()`, turning what should have been a clean error report into a fatal crash of the Bazel daemon.
4. Additionally, `CyclesReporter.reportCycles` called `cycleInfo.getTopKey()` and `cycleInfo.getCycle()` on each cycle without verifying `cycleInfo.hasCycleDetails()`.

#### Solution
1. In `ModCommand.java`, switch from `skyframeExecutor.prepareAndGet` to `skyframeExecutor.evaluate` with `keepGoing = true`. This preserves `storeExactCycles = true`, enabling `CyclesReporter` (with `BzlmodRepoCycleReporter` and `BzlLoadCycleReporter`) to cleanly display the exact circular dependency chain.
2. Defensively guard `new CyclesReporter(...).reportCycles(...)` in `ModCommand.java` with `cycleInfo.getFirst().hasCycleDetails()` so that even if cycle details are absent, `getTopKey()` is never called on a `CycleInfoNoDetails`.
3. In `CyclesReporter.java`, skip any `cycleInfo` where `!cycleInfo.hasCycleDetails()` to prevent crashes across all callers.
4. Added a unit test in `CyclesReporterTest` and an integration test in `mod_command_test.py`.

### Checklist
- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

Closes #31084

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/bazel/pull/31084 from jdymitarai:fix-mod-command-cycle-crash-29437 d0485fafb8d2cc740c3c5a8488342989ab3b7d61
PiperOrigin-RevId: 981241744
Change-Id: I120b90752c2c5f874ad4f7cbff54dee09783d6be
2 files changed
tree: 3fef2fa9e26cbe99405d31a730bf6374db60ec21
  1. .bazelci/
  2. .devcontainer/
  3. .gemini/
  4. .github/
  5. docs/
  6. examples/
  7. scripts/
  8. src/
  9. third_party/
  10. tools/
  11. .bazelrc
  12. .bazelversion
  13. .gitattributes
  14. .gitignore
  15. AGENTS.md
  16. AUTHORS
  17. bazel_downloader.cfg
  18. BUILD
  19. CHANGELOG.md
  20. CODE_OF_CONDUCT.md
  21. CODEOWNERS
  22. combine_distfiles.py
  23. combine_distfiles_to_tar.sh
  24. compile.sh
  25. CONTRIBUTING.md
  26. CONTRIBUTORS
  27. distdir.bzl
  28. extensions.bzl
  29. LICENSE
  30. maven_install.json
  31. MODULE.bazel
  32. MODULE.bazel.lock
  33. oneversion_allowlist.csv
  34. oneversion_allowlist_for_tests.csv
  35. pyproject.toml
  36. README.md
  37. repositories.bzl
  38. requirements.txt
  39. SECURITY.md
  40. verify_module_bazel_lock.sh
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Reporting a Vulnerability

To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.

Contributing to Bazel

See CONTRIBUTING.md

Build status