Skip to content

[CI] Bazel: Phase 0.5 — tag codegen tool (demo, stage 1 of 3) - #2

Draft
Kangyan-Zhou wants to merge 2 commits into
feat/bazel-test-wrapperfrom
feat/bazel-tag-codegen
Draft

[CI] Bazel: Phase 0.5 — tag codegen tool (demo, stage 1 of 3)#2
Kangyan-Zhou wants to merge 2 commits into
feat/bazel-test-wrapperfrom
feat/bazel-tag-codegen

Conversation

@Kangyan-Zhou

Copy link
Copy Markdown
Owner

Demo stack — stage 1 of 3 validating the Bazel test-runner migration plan.

This layer bridges register_cuda_ci/cpu_ci/amd_ci decorators to Bazel test tags via an AST-parsing codegen tool. Generates a 642-entry Starlark registry; pytest_test macro injects sgl-suite-* and est_time:* tags onto each py_test.

Components:

  • scripts/ci/generate_bazel_tags.py — AST-parser
  • tools/sglang_test_registry.bzl — generated registry
  • tools/pytest.bzl — tag injection from registry
  • .pre-commit-config.yaml — check-bazel-test-registry hook

Validated on H100 (lmsysorg/sglang:dev container kangyan_bazel_test):

  • 3 prototype 1-GPU tests pass
  • bazel query "attr(tags, sgl-suite-stage-b-test-1-gpu-small, //test/...)" returns 9 tagged tests

Reviewed by code-reviewer + silent-failure-hunter agents (findings in chat). Five fixes landed in df4b52f: positional arg support, hard-fail on every silent-skip path, ast.walk for non-top-level registrations, json.dumps for Starlark output, --check wired into pre-commit.

Stack:

  • this PR — feat/bazel-tag-codegen — Phase 0.5
  • next: feat/bazel-pr-test-yml — Phase 1
  • next: feat/bazel-manifest-job — Phase 3

🤖 Generated with Claude Code

Kangyan-Zhou and others added 2 commits May 4, 2026 21:53
Phase-0.5 of the bazel migration. Builds the bridge between sglang's
existing run_suite.py CI registry (register_cuda_ci(suite=..., est_time=...)
decorations on test_*.py files) and Bazel's tag-based test selection.

Components:
- scripts/ci/generate_bazel_tags.py: AST-parses test_*.py files for
  register_*_ci(...) calls at module scope. Emits a Starlark dict mapping
  repo-relative test path to {suite, est_time, nightly}. Supports a
  --check mode for pre-commit / CI gating against staleness.
- tools/sglang_test_registry.bzl: generated registry, 629 entries
  spanning test/registered/ + test/srt/ + test/manual/.
- tools/pytest.bzl: pytest_test now injects "sgl-suite-<suite>" and
  "est_time:<n>" tags onto each generated py_test from the registry.
  User-supplied tags compose additively (no overwriting). Tests without
  a register_*_ci decoration get no extra tags.

Validated on H100:
- 629 entries generated from existing decorations.
- bazel query "attr(tags, sgl-suite-stage-b-test-1-gpu-small, //test/...)"
  returns the 9 currently-wired tests across 3 packages.
- bazel query --output=build //test/registered/quant:test_int8_kernel shows
  tags = ["1-gpu", "est_time:15", "gpu", "sgl-suite-stage-b-test-1-gpu-small"]
  (user tags + registry-injected tags coexist).
- 3 prototype 1-GPU tests still pass.
- --check correctly detects staleness (tampered file -> exit 1).

Limitations (documented in script):
- Cuda > cpu > amd > npu priority when multiple registrations exist;
  AMD-specific suites lost in the demo registry.
- Non-literal kwargs are skipped with a stderr warning.
- disabled=True registrations are excluded.

Next layer (feat/bazel-pr-test-yml) wires --test_tag_filters into
pr-test.yml for stage-a-test-cpu.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses critical findings from the silent-failure-hunter and code-reviewer
agents on commit 36fe6e7. Five fixes, all gated against the same failure
mode (a test that disappears from the Bazel registry without anyone seeing it):

- Positional argument support (was the root cause of 13 false positives in
  the first pass). _PARAM_ORDER mirrors python/sglang/test/ci/ci_register.py
  so positional calls like `register_cpu_ci(1.0, "stage-a-test-cpu")` bind
  correctly. Registry now has 642 entries (up from 629).

- Hard-fail (exit 1) on every silent-skip path: parse errors,
  UnicodeDecodeError, non-literal kwargs, **kwargs splats, duplicate args,
  wrong-type suite/est_time. Each error logged with file:line.

- Non-top-level register_*_ci calls (inside if/try/def blocks) are now
  fatal errors with a clear message, surfaced via ast.walk pre-pass.

- json.dumps() for every string value in the generated Starlark output.
  Defense in depth against quote/backslash/newline characters.

- est_time accepts both int and float (sglang's CPU tests use 1.0).
  Rejects bool. Rounds float to int for the registry.

Pre-commit hook wiring (.pre-commit-config.yaml):
- New `check-bazel-test-registry` hook runs `--check` on test/.../*.py,
  the script itself, or the registry file. Without it, --check was
  load-bearing UI with no enforcement.

Validated on H100: all 3 prototype 1-GPU tests still pass; --check is
byte-stable on a fresh regen.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant