Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports_files(
[
"example_stub_repo.bzl",
"integration/mock_dd_server.py",
"integration/run_workspace_go_integration.sh",
],
visibility = ["//visibility:public"],
)
Expand Down
8 changes: 8 additions & 0 deletions tools/tests/integration/run_workspace_go_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,14 @@ dd_topt_go_orchestrion_tool_repo(
)

go_rules_dependencies()

# Bazel's collect_coverage helper needs a shell toolchain even for a plain
# go_test. Bzlmod registers it automatically; WORKSPACE consumers must do so.
load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")

rules_shell_dependencies()
rules_shell_toolchains()

go_register_toolchains(version = "${GO_VERSION}")
gazelle_dependencies()

Expand Down
1 change: 1 addition & 0 deletions tools/tests/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ sh_test(
"//tools/test_optimization:create_support_bundle.py",
"//tools/test_optimization:render_report_summary.py",
"//tools/tests:integration/mock_dd_server.py",
"//tools/tests:integration/run_workspace_go_integration.sh",
"//tools/tests/python/fixtures/generated_uploader",
],
)
Expand Down
66 changes: 66 additions & 0 deletions tools/tests/python/test_python_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9068,6 +9068,72 @@ def test_powershell_runtime_supports_multi_context_selection(self) -> None:
self.assertIn("Log-Stderr \"warning: skipping context enrichment", powershell_text)


class GoWorkspaceIntegrationTests(unittest.TestCase):
def test_generated_consumers_register_shell_toolchains(self) -> None:
"""Both fetch paths initialize the shell rules used by collect_coverage."""
bash = _require_functional_bash(self)
source = _runfile("tools/tests/integration/run_workspace_go_integration.sh").read_text(
encoding="utf-8"
)
quote = source[source.index("bzl_quote() {"):source.index("\nsha256_file() {")]
writer = source[
source.index("write_positive_workspace() {"):
source.index("\nwrite_invalid_workspace() {")
]
env = {
**os.environ,
"PYTHON": sys.executable,
"REPO_ROOT": "/fixture/rules with spaces",
"rules_go_fork_abs": "/fixture/rules with spaces/third_party/rgo/v0_60_0/base",
"ARCHIVE_URL": "file:///fixture/rules.tar.gz",
"ARCHIVE_SHA256": "a" * 64,
"ARCHIVE_NAME": "rules-fixture",
"RULES_GO_UPSTREAM": "v0_60_0",
"RULES_GO_VARIANT": "base",
"ORCHESTRION_VERSION": "v1.12.0",
"GO_VERSION": "1.25.0",
"SERVICE_NAME": "fixture-service",
"MODULE_IMPORTPATH": "example.com/fixture",
"OUT_DIR": "custom_topt",
}
for fetch_mode in ("local", "archive"):
with self.subTest(fetch_mode=fetch_mode), tempfile.TemporaryDirectory() as tmp:
subprocess.run(
[
bash, "-eu", "-c",
quote + writer + '\nwrite_positive_workspace "$1" "$2"',
"fixture", tmp, fetch_mode,
],
env=env,
check=True,
capture_output=True,
text=True,
)
workspace = ast.parse(Path(tmp, "WORKSPACE").read_text(encoding="utf-8"))
calls = [
node.value for node in workspace.body
if isinstance(node, ast.Expr) and isinstance(node.value, ast.Call)
]
shell_load = next(
(
index for index, call in enumerate(calls)
if call.func.id == "load"
and call.args[0].value == "@rules_shell//shell:repositories.bzl"
),
None,
)
self.assertIsNotNone(shell_load, "WORKSPACE must load rules_shell initialization")
self.assertEqual(
["rules_shell_dependencies", "rules_shell_toolchains"],
[arg.value for arg in calls[shell_load].args[1:]],
)
names = [call.func.id for call in calls]
self.assertLess(names.index("go_rules_dependencies"), shell_load)
self.assertLess(shell_load, names.index("rules_shell_dependencies"))
self.assertLess(names.index("rules_shell_dependencies"), names.index("rules_shell_toolchains"))
self.assertEqual(1, names.count("rules_shell_toolchains"))


class MockDdServerTests(unittest.TestCase):
"""Test case group covering MockDdServerTests behaviors."""
@classmethod
Expand Down
Loading