Add scaffold tool for creating new health checks [2/2]#78
Add scaffold tool for creating new health checks [2/2]#78gustcol wants to merge 7 commits intofacebookresearch:mainfrom
Conversation
…plate Extract the ~30 lines of repeated setup code (logger init, GPU node ID detection, derived cluster resolution, TelemetryContext + OutputContext nesting, killswitch check) into a reusable HealthCheckRuntime dataclass context manager. This reduces per-subcommand boilerplate from ~30 lines to ~5 lines. The helper is purely additive — existing checks continue to work unchanged. New checks can use `with HealthCheckRuntime(...) as rt:` instead of manually wiring up the setup ceremony. Includes comprehensive tests covering field initialization, killswitch behavior, context manager nesting, GPU node ID failure handling, and the finish() convenience method. Refs: facebookresearch#75
CI CommandsThe following CI workflows run automatically on every push and pull request:
The following commands can be used by maintainers to trigger additional tests that require access to secrets:
|
Apply ufmt formatting and fix mypy errors in test helper by using explicit typed parameters instead of **kwargs dict unpacking.
Introduce bin/create_new_health_check.py that automates the creation of new health checks by generating all required files (check module, test skeleton, documentation stub) and registering the check across all touchpoints (checks/__init__.py, CLI entry point, HealthCheckName enum, killswitch feature flag). The tool supports single-command and grouped-command checks, has a dry-run mode, and is idempotent (safe to re-run). Generated checks use the new HealthCheckRuntime context manager from the previous commit. Also updates the "Adding New Health Check" guide with a Quick Start section pointing to the scaffold tool. Refs: facebookresearch#75
- Replace len() slice with constant to avoid E203 whitespace-before-colon - Remove placeholder-less f-strings (F541) - Remove unused StringIO import (F401)
158959c to
4110400
Compare
Add type narrowing asserts for importlib spec/loader (which return Optional types), type the dynamically-loaded scaffold module as Any to allow attribute access, and annotate the scaffold_env fixture return type as Iterator[Path].
| ```bash | ||
| python bin/generate_features.py | ||
| ufmt format gcm | ||
| ``` |
There was a problem hiding this comment.
run these from create_new_health_check.py?
There was a problem hiding this comment.
Good idea — the scaffold tool now runs generate_features.py and ufmt format gcm automatically as a post-scaffold step (skipped in --dry-run mode). Updated the docs to remove the manual instructions.
The scaffold tool now runs generate_features.py and ufmt format gcm as a post-scaffold step, so users no longer need to run them manually. Updated docs to reflect the automated workflow.
- Remove unused import sys from generated templates (would fail lint) - Remove unused check_name parameter from run_post_scaffold - Add guard for silent no-op when CLI anchor string is not found - Fix dry-run inconsistency in update_init __all__ block - Remove tautological assertion in test_update_init_idempotent - Add test for missing CLI anchor warning - Update Quick Start docs to list all remaining manual steps
Summary
Ref: #75
Depends on: #77
bin/create_new_health_check.py, a scaffold tool that automates the creation of new health checks by generating all required files and registering the check across all touchpointsHealthCheckRuntimecontext manager from Add HealthCheckRuntime context manager for shared boilerplate [1/2] #77--groupflag for grouped checks (@click.group()) and--dry-runfor previewing changesStacked PR series: [1/2] Runtime helper (#77) → [2/2] Scaffold tool (this PR)
What the tool does
gcm/health_checks/checks/check_{name}.pygcm/tests/health_checks_tests/test_check_{name}.pywebsite/docs/.../check-{name}.mdchecks/__init__.py__all__cli/health_checks.pylist_of_checkshealth_check_name.pyhealth_checks_features.pydisable_fieldTest plan
nox -s tests -- gcm/tests/test_create_health_check.py— 15 tests covering validation, file generation, registration, idempotency, dry-run, grouped checkspython bin/create_new_health_check.py check_test_example --dry-run— integration smoke testnox -s lintnox -s format