bazel-test-hygiene

Các quy tắc bắt buộc khi chạy kiểm thử bazel trong quá trình phát triển. Tải kỹ năng này trước khi chạy bất kỳ lệnh kiểm thử bazel nào, đặc biệt là khi xác thực các bản sửa lỗi hoặc…

npx skills add https://github.com/cloudflare/workerd --skill bazel-test-hygiene

Bazel Test Hygiene

The Three Rules

1. Always disable caching

bazel test //... --nocache_test_results

Why: Bazel's action cache can serve stale test binaries even after you edit source files. Without --nocache_test_results, you may be running the OLD binary and seeing OLD results. This is not hypothetical — it has caused real false-positive/false-negative confusion in this repo.

Always include --nocache_test_results. No exceptions.

2. Keep it simple — no filter flags

Do NOT use --test_arg='-f' or similar filter flags to run individual test cases.

Why: KJ test's -f flag silently passes when zero tests match. If you typo the filter or the test name changes, bazel reports "PASSED" with zero tests actually run. This gives completely false confidence.

Run the full test target. If you need to check a specific test, look for its name in the full output. If the full suite is too slow, run the specific test target (e.g., //src/workerd/api:streams/standard-test@), not a filtered subset within a target.

3. Run the full suite before claiming done

A single test target passing does not mean you haven't broken something else. Fixes to shared code (queue.c++, standard.c++, common.h) can break tests in completely different directories.

Before claiming any fix is complete:

bazel test //... --nocache_test_results

Check the final summary line: Executed N out of N tests: N tests pass. All N must match. If any test fails, the fix is not done.

Red-Green Verification for Regression Tests

When writing a regression test for a bug fix, you MUST verify the test actually catches the bug:

  1. Green: Run bazel test //... --nocache_test_results — all tests pass (fix in place)
  2. Red: Remove the fix, run bazel test //... --nocache_test_results — the new test(s) MUST fail
  3. Green: Restore the fix, run bazel test //... --nocache_test_results — all tests pass again

If step 2 passes (test doesn't fail without the fix), the test is not testing what you think. Go back and fix the test.

Do the red-green on the full suite, not just the one target. This catches two problems at once: (a) the regression test actually detects the bug, and (b) the fix doesn't break anything else.

Anti-Patterns

Don'tDo instead
bazel test //target (no cache flag)bazel test //target --nocache_test_results
--test_arg='-f' --test_arg='test name'Run the full target, grep output for test name
Run one target, claim fix is doneRun //..., check all-pass summary
Claim "tests pass" from a previous runRun fresh, read fresh output
Trust filter-based "PASSED" at face valueCheck that the expected test names appear in output

Thêm skills từ cloudflare

workerd-api-review
cloudflare
Tối ưu hóa hiệu suất, thiết kế & tương thích API, lỗ hổng bảo mật và tuân thủ đặc tả tiêu chuẩn cho việc xem xét mã workerd. Bao gồm nhận biết tcmalloc…
official
workerd-safety-review
cloudflare
Các mẫu phát hiện về an toàn bộ nhớ, an toàn luồng, đồng thời và quan trọng cho việc xem xét mã workerd. Bao gồm các rủi ro ranh giới V8/KJ, quản lý vòng đời,…
official
module-registry
cloudflare
Tải khi làm việc với module registry trong workerd — đọc, sửa đổi, gỡ lỗi hoặc xem xét việc phân giải, biên dịch, đánh giá hoặc đăng ký module…
official
reproduce
cloudflare
Tái tạo một vấn đề GitHub của cloudflare/agents bằng cách tạo khung một dự án Agents/Worker tối thiểu và triển khai nó lên một tài khoản Cloudflare tạm thời, sau đó báo cáo…
official
local-explorer
cloudflare
Cách thêm sản phẩm/tài nguyên vào local explorer hoặc local API. Sử dụng khi triển khai các local API mới hoặc các route UI trong…
official
commit-categories
cloudflare
Quy tắc phân loại commit cho changelog và tóm tắt "có gì mới". PHẢI được tải trước khi phân loại commit trong changelog hoặc lệnh whats-new. Cung cấp…
official
architecture
cloudflare
Sử dụng khi lần đầu điều hướng cơ sở mã, thêm một phương thức client mới, thêm một trình xử lý/dịch vụ container mới, hoặc hiểu cách một yêu cầu luân chuyển…
official
changesets
cloudflare
Sử dụng khi tạo changeset, chuẩn bị phát hành hoặc nâng phiên bản. Bao gồm các gói cần tham chiếu, cách viết mô tả changeset hướng đến người dùng,…
official