Files
Alexey MilovidovandClaude Opus 4.8 295ced78d1 Enable more Ruff checks (F401/F403/F405/F541/F841) and clean up tests
Follow-up to #105171, which added `ruff` with a deliberately narrow,
bug-class-only rule set and left the unused-name and star-import rules
off pending a dedicated cleanup pass. This enables that second batch in
`pyproject.toml` and fixes every violation across the tree (the bulk in
integration tests):

- `F401` unused-import and `F841` unused-variable: removed, preserving
  any side-effecting right-hand side (e.g. `result = node.query(...)`
  becomes `node.query(...)`). Two `try: import ...` feature probes are
  kept with `# noqa: F401`.
- `F541` f-string-missing-placeholders: dropped the redundant `f` prefix.
- `F403`/`F405` star imports: every `from module import *` is expanded
  into explicit imports of the names actually used, taken from each
  name's real origin, so stdlib/third-party names import from their real
  source rather than through a test "convenience bundle". The now-empty
  `tests/integration/helpers/kafka/common_direct.py` bundle is removed and
  its three remaining consumers import `_VarintBytes`/`KafkaAdminClient`
  directly.

Eliminating the star imports surfaced a real bug the wildcard had masked
from `F821`: `generate_presets.py` in `test_prometheus_protocols` called
an undefined `execute_instant_query_with_http_api`; fixed to the existing
`execute_query_via_http_api`.

No `black`/`isort` reformatting was applied (neither is enforced in the
style check), so the diff is limited to the lint fixes themselves.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-18 23:22:25 +00:00

127 lines
5.4 KiB
Python

import json
import traceback
from pathlib import Path
from ci.jobs.scripts.cidb_cluster import CIDBCluster
from ci.praktika.gh import GH
from ci.praktika.info import Info
def check():
info = Info()
comment_file = Path("./ci/tmp/coverage_comment.json")
if not comment_file.exists():
print(f"Coverage comment data not found at {comment_file}, skipping")
return
try:
with open(comment_file) as f:
d = json.load(f)
b_line_cov = d["b_line_cov"]
c_line_cov = d["c_line_cov"]
b_function_cov = d["b_function_cov"]
c_function_cov = d["c_function_cov"]
b_branch_cov = d["b_branch_cov"]
c_branch_cov = d["c_branch_cov"]
d.get("b_line_hit", 0)
d.get("b_line_total", 0)
d.get("c_line_hit", 0)
d.get("c_line_total", 0)
d.get("b_func_hit", 0)
d.get("b_func_total", 0)
d.get("c_func_hit", 0)
d.get("c_func_total", 0)
d.get("b_branch_hit", 0)
d.get("b_branch_total", 0)
d.get("c_branch_hit", 0)
d.get("c_branch_total", 0)
pr_changed_lines_info = d.get("pr_changed_lines_info", "")
diff_url = d.get("diff_url", "")
uncovered_code_url = d.get("uncovered_code_url", "")
newly_covered_info = d.get("newly_covered_info", "")
newly_covered_url = d.get("newly_covered_url", "")
newly_covered_top_files = d.get("newly_covered_top_files", []) or []
if info.pr_number > 0:
body = (
f"### LLVM Coverage Report\n\n"
f"| Metric | Baseline | Current | Δ |\n"
f"|--------|----------|---------|---|\n"
f"| Lines | {b_line_cov:.2f}% | {c_line_cov:.2f}% | {c_line_cov - b_line_cov:+.2f}% |\n"
f"| Functions | {b_function_cov:.2f}% | {c_function_cov:.2f}% | {c_function_cov - b_function_cov:+.2f}% |\n"
f"| Branches | {b_branch_cov:.2f}% | {c_branch_cov:.2f}% | {c_branch_cov - b_branch_cov:+.2f}% |\n"
)
if pr_changed_lines_info:
changed_line = f"\n**Changed lines:** {pr_changed_lines_info}"
if uncovered_code_url:
changed_line += f" · [Uncovered code]({uncovered_code_url})"
body += changed_line + "\n"
if newly_covered_info:
# For a tests-only PR: surface what previously-uncovered code the new
# test(s) now exercise. The table delta above is typically too small
# to be meaningful on its own; this section is the actionable signal.
nc_line = f"\n**Newly covered by added/modified tests:** {newly_covered_info}"
if newly_covered_url:
nc_line += f" · [Details]({newly_covered_url})"
body += nc_line + "\n"
if newly_covered_top_files:
body += "\n<details><summary>Top files</summary>\n\n"
for f in newly_covered_top_files:
rel = f.get("rel", "")
lc = int(f.get("lines", 0))
fc = int(f.get("fns", 0))
parts = []
if lc > 0:
parts.append(f"{lc} line(s)")
if fc > 0:
parts.append(f"{fc} function(s)")
body += f"- `{rel}`: {', '.join(parts)}\n"
body += "\n</details>\n"
links = []
if coverage_report_url := d.get("coverage_report_url", ""):
links.append(f"[Full report]({coverage_report_url})")
if diff_url:
links.append(f"[Diff report]({diff_url})")
if not pr_changed_lines_info and uncovered_code_url:
links.append(f"[Uncovered code]({uncovered_code_url})")
if links:
body += "\n" + " · ".join(links)
GH.post_fresh_comment(tag="llvm-coverage", body=body)
else:
print("Not a PR run, skipping GitHub coverage comment")
CIDBCluster().insert_json(
table="coverage_ci.coverage_data",
json_str={
"check_start_time": d["check_start_time"],
"pull_request_number": d["pull_request_number"],
"commit_sha": d["commit_sha"],
"base_commit_sha": d["base_commit_sha"],
"branch": d["branch"],
"base_branch": d["base_branch"],
"status": d["status"],
"baseline_line_cov": b_line_cov,
"baseline_func_cov": b_function_cov,
"baseline_branch_cov": b_branch_cov,
"current_line_cov": c_line_cov,
"current_func_cov": c_function_cov,
"current_branch_cov": c_branch_cov,
"delta_line_cov": d["delta_line_cov"],
"changed_lines_total": d.get("changed_lines_total", 0),
"changed_lines_covered": d.get("changed_lines_covered", 0),
"changed_lines_cov": d.get("changed_lines_cov", 0.0),
"coverage_report_url": d["coverage_report_url"],
"diff_coverage_report_url": d.get("diff_coverage_report_url", ""),
"uncovered_code_url": uncovered_code_url,
},
)
except Exception:
print("ERROR: Failed to post coverage comment or insert into CIDB")
traceback.print_exc()
if __name__ == "__main__":
check()