beads/tools/bazel/classify_tier_results_test.py
Julian Knutsen 873162dafa
ci(bazel): dolt-int gates server-storage + cmd-dolt in mode remote (item 5 A2) (#7535)
* ci(bazel): dolt-int gates the server-storage and cmd-dolt tiers in mode remote (item 5 A2)

In mode remote, folds bazel-server-storage (--config=doltserver-integration)
and bazel-cmd-dolt (--config=doltserver-cmd) into one bazel-dolt-int job
(--config=dolt-int), following the dolt-race pattern from #7514. The
members have different gating categories (server-storage plain-gated,
cmd-dolt flag-gated/advisory), so the union carries continue-on-error: true
and a bespoke --label-scoped Shard balance step. All other modes keep the
two lanes running unchanged. Action keys are byte-identical between the
member configs and the union (17 + 46 = 63 TestRunner actions), so cached
results carry over either direction and a revert is a safe rollback.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(bazel): dolt-int per-tier results, integration gating, key-parity wording (review)

Coordinator review of #7535 found three must-fixes: integration:"off" was
ignored in remote mode (the union's members already honor it); job-level
continue-on-error made a server-storage-only failure read success on
push/nightly/dispatch, where main stays red; and the PR's key-parity claim
overstated byte-identical actionKeys when only the remote action digest
(not the local actionKey) is unaffected by moving --test_env/--test_arg
onto the targets' own env/args.

Fixes:
- bazel-dolt-int's if now adds `&& inputs.integration != 'off'`, matching
  the members (#7491's review); bazelLaneRunModes and
  TestBazelDoltIntArmsExactlyOnePerMode cover the "off" case.
- Job-level continue-on-error removed; only the `bazel test` step carries
  it, and a new always() "Classify tier results" step
  (tools/bazel/classify_tier_results.py, with its own unit tests and a Go
  wrapper) computes server_storage_result/cmd_dolt_result from the BEP and
  decides job.status per-tier. Confirmed with bazel-gate.sh/ci-gate.sh on
  synthetic empty-output inputs that a dead job still fails the gate.
- Corrected the local-actionKey-vs-remote-digest wording in .bazelrc,
  bazel.yml's job comment and CI_REQUIRED_CHECK_TOPOLOGY.md.
- Should-fix: test step 23->25 / job 58 minutes with reasoning; --label
  coverage added to shard_budget_test.py; stale lane comment fixed in
  tests/regression/BUILD.bazel:46; TestBazelDoltIntSoleRunIsInTheUnion's
  docstring corrected (members bake sole-run's line in directly, never via
  --config=sole-run).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(bazel): fail-closed classify, per-tier check_testcases, pinned argv (review)

Final review round for PR #7535 (maintainer-city-c3, bee-ghosttrack,
julianknutsen):

- classify_tier_results.py now fails every tier shut (exit 1) on a
  non-PASSED label outside every --tier list, so a newly tagged target
  added without updating the step's --tier args cannot silently read as
  success (must-fix 1). Its --tier/--check label sets are policy-tied to
  the BUILD files' own tag sets by a new
  TestBazelDoltIntTierLabelsMatchTheTags.
- A missing or non-integer --rc (a timed-out or cancelled test step)
  takes the same fail-everything-shut branch instead of crashing argparse
  with no outputs written (bee-ghosttrack's should-fix 2).
- check_testcases.py gained a repeatable --label flag, and bazel.yml's
  shared "Every target and shard ran tests" step is split into check-ss
  and check-cd, each continue-on-error and folded into its own tier via
  classify's new --check NAME=OUTCOME, so a zero-testcase cmd-dolt shard
  no longer reddens the job on push/nightly (must-fix 2).
- classify's run: argv is now pinned by exact equality
  (bazelDoltIntClassifyRun), and every flag except --tier/--check is
  --StoreOnce; a repeated --tier/--check name or an unrecognized flag is
  now a hard parser error (must-fix 3).
- "Upload test logs" now also fires on steps.test.outcome == 'failure',
  not just failure() (must-fix 4).
- shard_budget.py --label now fails closed (::error, exit 1) on a label
  with no executed shard in the BEP at all, instead of silently reporting
  "no sharded test target executed two or more shards" (should-fix 3,
  carried across both review rounds).
- Updated engdocs/TESTING.md, CI_REQUIRED_CHECK_TOPOLOGY.md, .bazelrc and
  scripts/bazel_dolt_int_test.go/ci_workflow_test.go comments for the
  nits: stale "Advisory (continue-on-error: true)" wording, the
  bazelUnionHasFlagGatedMember comment's stale claim about bazel-dolt-int,
  "byte-identical" without specifying remote action digest vs. local
  actionKey, and "is unset" vs. ci-gate.sh's actual "was skipped" branch
  for an empty union output.

Verified: python3 -I on all four tools/bazel/*_test.py (classify 29,
check_testcases 7, shard_budget 19) green; GOTOOLCHAIN=go1.26.7 go test
./scripts/... green; bazel --nohome_rc test //scripts:scripts_test
--config=ci green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(bazel): shard_budget --label fail-closed only on a truly unknown label

The previous commit's fail-closed --label check compared against
read_shard_durations, which only records executed (non-cached) shards, so
a target whose every shard was a cache hit this run had zero entries and
was wrongly treated the same as a --label typo. This was not caught by
the new tests (none exercised an all-cached target) and broke this PR's
own dolt-int CI run: bazel-dolt-int's Shard balance step went red on
//internal/storage/dolt:dolt_server_full_test with "no executed shard for
it", even though that target was correctly, fully cache-hit.

Fix: a new read_tested_labels() reads every label with any testResult
event (cached or executed), and --label's fail-closed check now tests
against that set instead of read_shard_durations. A fully-cached target
still legitimately reports "nothing to judge" through evaluate(); only a
label absent from the BEP altogether is now an error. Added the missing
test row (every shard cached) that would have caught this before push.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* test(bazel): pin bazel-dolt-int's Upload test logs if-condition

A full 42-mutation re-run for PR #7535's second review round found that
nothing pinned this job's own "Upload test logs" if-condition (must-fix 4):
the other lanes' upload-logs steps are each pinned, but bazel-dolt-int's
(unlike dolt-race, a brand-new job) had no equivalent assertion, so a future
accidental revert to the old failure()-only condition would go uncaught.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-13 09:17:54 +00:00

434 lines
16 KiB
Python

#!/usr/bin/env python3
"""Unit tests for classify_tier_results.py.
Run directly: python3 tools/bazel/classify_tier_results_test.py
(or: python3 -m unittest tools.bazel.classify_tier_results_test, from the repo root)
"""
import json
import os
import sys
import tempfile
import unittest
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import classify_tier_results as ctr # noqa: E402
SS = "//internal/storage/dolt:dolt_server_full_test"
SS2 = "//internal/storage/dolt:dolt_server_conformance_test"
CD = "//cmd/bd:bd_dolt_server_test"
CD2 = "//tests/regression:regression_test"
UNKNOWN = "//internal/storage/dolt:dolt_server_new_test"
TIERS = {"server-storage": [SS, SS2], "cmd-dolt": [CD, CD2]}
def write_bep(events):
f = tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False, encoding="utf-8")
for ev in events:
f.write(json.dumps(ev) + "\n")
f.close()
return f.name
def result_event(label, status):
return {"id": {"testResult": {"label": label}}, "testResult": {"status": status}}
def all_passed_bep(extra=()):
return write_bep([result_event(l, "PASSED") for l in (SS, SS2, CD, CD2)] + list(extra))
class TierResultTest(unittest.TestCase):
def test_all_passed_is_success(self):
statuses = {SS: {"PASSED"}, SS2: {"PASSED"}}
self.assertEqual(ctr.tier_result(statuses, [SS, SS2]), "success")
def test_any_failed_label_is_failure(self):
statuses = {SS: {"PASSED"}, SS2: {"FAILED"}}
self.assertEqual(ctr.tier_result(statuses, [SS, SS2]), "failure")
def test_missing_label_is_failure(self):
statuses = {SS: {"PASSED"}}
self.assertEqual(ctr.tier_result(statuses, [SS, SS2]), "failure")
def test_flaky_status_is_failure(self):
# These lanes run flaky=False: a FLAKY-looking status is still a
# failure, never silently treated as a pass.
statuses = {SS: {"PASSED", "FLAKY"}}
self.assertEqual(ctr.tier_result(statuses, [SS]), "failure")
def test_omitted_status_is_failure(self):
# proto3 JSON omits a NO_STATUS (0) field entirely; read_test_statuses
# falls back to the literal string "NO_STATUS", which is not PASSED.
statuses = {SS: {"NO_STATUS"}}
self.assertEqual(ctr.tier_result(statuses, [SS]), "failure")
class ClassifyTest(unittest.TestCase):
def test_rc_0_both_tiers_succeed(self):
path = all_passed_bep()
try:
results, status, reason = ctr.classify(path, 0, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "success", "cmd-dolt": "success"})
self.assertEqual(status, 0)
self.assertIsNone(reason)
def test_server_storage_fail_only_fails_the_job(self):
path = write_bep([
result_event(SS, "FAILED"),
result_event(SS2, "PASSED"),
result_event(CD, "PASSED"),
result_event(CD2, "PASSED"),
])
try:
results, status, reason = ctr.classify(path, 3, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "success"})
self.assertEqual(status, 1)
self.assertIsNotNone(reason)
def test_cmd_dolt_fail_only_leaves_the_job_green(self):
path = write_bep([
result_event(SS, "PASSED"),
result_event(SS2, "PASSED"),
result_event(CD, "FAILED"),
result_event(CD2, "PASSED"),
])
try:
results, status, reason = ctr.classify(path, 3, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "success", "cmd-dolt": "failure"})
# A cmd-dolt-only test failure must not fail the job: it stays
# advisory, exactly as bazel-cmd-dolt's own continue-on-error outside
# mode remote.
self.assertEqual(status, 0)
self.assertIsNone(reason)
def test_both_tiers_fail(self):
path = write_bep([
result_event(SS, "FAILED"),
result_event(SS2, "PASSED"),
result_event(CD, "TIMEOUT"),
result_event(CD2, "PASSED"),
])
try:
results, status, reason = ctr.classify(path, 3, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "failure"})
self.assertEqual(status, 1)
def test_build_failure_fails_both_tiers_and_the_job(self):
# rc=1 (BUILD_FAILURE): not attributable to one tier, even though the
# BEP happens to show every known label passing (e.g. an unrelated
# target failed to build under --keep_going).
path = all_passed_bep()
try:
results, status, reason = ctr.classify(path, 1, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "failure"})
self.assertEqual(status, 1)
def test_missing_rc_fails_both_tiers_and_the_job(self):
# should-fix 2 (bee-ghosttrack's review): a timed-out or cancelled
# `bazel test` step never writes $TEST_RC, so bazel.yml passes
# --rc "" rather than omitting the flag; this must take the "not 0
# or 3" branch, not crash.
path = all_passed_bep()
try:
results, status, reason = ctr.classify(path, "", TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "failure"})
self.assertEqual(status, 1)
self.assertIn("missing or not an integer", reason)
def test_non_integer_rc_fails_both_tiers_and_the_job(self):
path = all_passed_bep()
try:
results, status, reason = ctr.classify(path, "abc", TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "failure"})
self.assertEqual(status, 1)
self.assertIn("missing or not an integer", reason)
def test_gate_tier_selects_which_tier_fails_the_job(self):
# Flip which tier gates: a cmd-dolt failure now fails the job, a
# server-storage failure does not. (Not bazel-dolt-int's own wiring,
# which always gates on server-storage; this just proves the script
# is not hardcoded to one tier name.)
path = write_bep([
result_event(SS, "FAILED"),
result_event(SS2, "PASSED"),
result_event(CD, "PASSED"),
result_event(CD2, "PASSED"),
])
try:
results, status, reason = ctr.classify(path, 3, TIERS, "cmd-dolt")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "success"})
self.assertEqual(status, 0)
def test_unknown_failing_label_fails_every_tier_and_the_job(self):
# must-fix 1: a target tagged dolt-server-integration/dolt-server-cmd
# added without updating the --tier lists (bazel.yml's classify step
# args, or the --tier arg dict built here) must not read as success
# just because no --tier list claims its label.
path = all_passed_bep(extra=[result_event(UNKNOWN, "FAILED")])
try:
results, status, reason = ctr.classify(path, 3, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "failure"})
self.assertEqual(status, 1)
self.assertIn(UNKNOWN, reason)
def test_unknown_passing_label_does_not_affect_classification(self):
# A target outside every --tier that passed is not this script's
# business (it is not one of the two tiers bazel-dolt-int reports);
# only a non-PASSED result outside the tiers triggers the fail-closed
# path.
path = all_passed_bep(extra=[result_event(UNKNOWN, "PASSED")])
try:
results, status, reason = ctr.classify(path, 0, TIERS, "server-storage")
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "success", "cmd-dolt": "success"})
self.assertEqual(status, 0)
def test_check_failure_forces_that_tier_failed_and_gates_the_job(self):
# should-fix 2: a per-tier check_testcases.py step's own outcome
# (bazel.yml's split "Every target and shard ran tests (<tier>)"
# steps) folds into that tier's result even though the BEP alone
# would call it a success (e.g. a zero-testcase shard).
path = all_passed_bep()
try:
results, status, reason = ctr.classify(
path, 0, TIERS, "server-storage", checks={"server-storage": "failure"}
)
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "failure", "cmd-dolt": "success"})
self.assertEqual(status, 1)
def test_check_failure_on_non_gate_tier_leaves_the_job_green(self):
path = all_passed_bep()
try:
results, status, reason = ctr.classify(
path, 0, TIERS, "server-storage", checks={"cmd-dolt": "failure"}
)
finally:
os.unlink(path)
self.assertEqual(results, {"server-storage": "success", "cmd-dolt": "failure"})
self.assertEqual(status, 0)
def test_check_cancelled_also_forces_failure(self):
path = all_passed_bep()
try:
results, _, _ = ctr.classify(
path, 0, TIERS, "server-storage", checks={"cmd-dolt": "cancelled"}
)
finally:
os.unlink(path)
self.assertEqual(results["cmd-dolt"], "failure")
def test_check_success_leaves_bep_result_alone(self):
path = write_bep([
result_event(SS, "FAILED"),
result_event(SS2, "PASSED"),
result_event(CD, "PASSED"),
result_event(CD2, "PASSED"),
])
try:
results, status, _ = ctr.classify(
path, 3, TIERS, "server-storage", checks={"server-storage": "success"}
)
finally:
os.unlink(path)
self.assertEqual(results["server-storage"], "failure")
self.assertEqual(status, 1)
class MainTest(unittest.TestCase):
def run_main(self, bep, rc, gate_tier="server-storage", extra_args=()):
out = tempfile.NamedTemporaryFile(mode="w", delete=False)
out.close()
try:
status = ctr.main([
"--bep", bep,
"--rc", str(rc),
"--tier", f"server-storage={SS},{SS2}",
"--tier", f"cmd-dolt={CD},{CD2}",
"--gate-tier", gate_tier,
"--github-output", out.name,
*extra_args,
])
with open(out.name, encoding="utf-8") as f:
lines = set(f.read().splitlines())
finally:
os.unlink(out.name)
return status, lines
def test_writes_github_output_and_exits_1_on_gate_tier_failure(self):
bep = write_bep([
result_event(SS, "FAILED"),
result_event(SS2, "PASSED"),
result_event(CD, "PASSED"),
result_event(CD2, "PASSED"),
])
try:
status, lines = self.run_main(bep, 3)
finally:
os.unlink(bep)
self.assertEqual(status, 1)
self.assertEqual(lines, {"server_storage_result=failure", "cmd_dolt_result=success"})
def test_empty_rc_exits_1_with_outputs_written_not_an_argparse_crash(self):
# should-fix 2: bazel.yml always passes --rc "$TEST_RC", so a timed
# out or cancelled test step reaches main() with --rc "" rather than
# omitting the flag; this must write both failure outputs and exit
# 1, not crash argparse with nothing written at all.
bep = all_passed_bep()
try:
status, lines = self.run_main(bep, "")
finally:
os.unlink(bep)
self.assertEqual(status, 1)
self.assertEqual(lines, {"server_storage_result=failure", "cmd_dolt_result=failure"})
def test_exits_0_when_only_the_non_gate_tier_fails(self):
bep = write_bep([
result_event(SS, "PASSED"),
result_event(SS2, "PASSED"),
result_event(CD, "FAILED"),
result_event(CD2, "PASSED"),
])
try:
status, _ = self.run_main(bep, 3)
finally:
os.unlink(bep)
self.assertEqual(status, 0)
def test_unknown_failing_label_exits_1_through_main(self):
bep = all_passed_bep(extra=[result_event(UNKNOWN, "FAILED")])
try:
status, lines = self.run_main(bep, 3)
finally:
os.unlink(bep)
self.assertEqual(status, 1)
self.assertEqual(lines, {"server_storage_result=failure", "cmd_dolt_result=failure"})
def test_check_flag_folds_into_tier_output(self):
bep = all_passed_bep()
try:
status, lines = self.run_main(bep, 0, extra_args=["--check", "cmd-dolt=failure"])
finally:
os.unlink(bep)
self.assertEqual(status, 0)
self.assertEqual(lines, {"server_storage_result=success", "cmd_dolt_result=failure"})
def test_repeated_tier_name_is_rejected(self):
bep = all_passed_bep()
out = tempfile.NamedTemporaryFile(mode="w", delete=False)
out.close()
try:
with self.assertRaises(SystemExit):
ctr.main([
"--bep", bep,
"--rc", "0",
"--tier", f"server-storage={SS},{SS2}",
"--tier", f"cmd-dolt={CD},{CD2}",
"--tier", "cmd-dolt=//other:t",
"--gate-tier", "server-storage",
"--github-output", out.name,
])
finally:
os.unlink(bep)
os.unlink(out.name)
def test_repeated_gate_tier_is_rejected(self):
bep = all_passed_bep()
out = tempfile.NamedTemporaryFile(mode="w", delete=False)
out.close()
try:
with self.assertRaises(SystemExit):
ctr.main([
"--bep", bep,
"--rc", "0",
"--tier", f"server-storage={SS},{SS2}",
"--tier", f"cmd-dolt={CD},{CD2}",
"--gate-tier", "server-storage",
"--gate-tier", "cmd-dolt",
"--github-output", out.name,
])
finally:
os.unlink(bep)
os.unlink(out.name)
def test_repeated_check_name_is_rejected(self):
bep = all_passed_bep()
out = tempfile.NamedTemporaryFile(mode="w", delete=False)
out.close()
try:
with self.assertRaises(SystemExit):
ctr.main([
"--bep", bep,
"--rc", "0",
"--tier", f"server-storage={SS},{SS2}",
"--tier", f"cmd-dolt={CD},{CD2}",
"--gate-tier", "server-storage",
"--github-output", out.name,
"--check", "cmd-dolt=failure",
"--check", "cmd-dolt=success",
])
finally:
os.unlink(bep)
os.unlink(out.name)
def test_unknown_flag_is_rejected(self):
bep = all_passed_bep()
out = tempfile.NamedTemporaryFile(mode="w", delete=False)
out.close()
try:
with self.assertRaises(SystemExit):
ctr.main([
"--bep", bep,
"--rc", "0",
"--tier", f"server-storage={SS},{SS2}",
"--gate-tier", "server-storage",
"--github-output", out.name,
"--gate-tier-extra", "server-storage",
])
finally:
os.unlink(bep)
os.unlink(out.name)
def test_check_for_unknown_tier_name_is_rejected(self):
bep = all_passed_bep()
out = tempfile.NamedTemporaryFile(mode="w", delete=False)
out.close()
try:
with self.assertRaises(SystemExit):
ctr.main([
"--bep", bep,
"--rc", "0",
"--tier", f"server-storage={SS},{SS2}",
"--gate-tier", "server-storage",
"--github-output", out.name,
"--check", "not-a-tier=failure",
])
finally:
os.unlink(bep)
os.unlink(out.name)
if __name__ == "__main__":
unittest.main()