Allow external callers to configure the hook directory#951
Allow external callers to configure the hook directory#951shreyaskommuri wants to merge 1 commit into
Conversation
Expose an optional --hook-dir across scenario commands and pass the resolved directory into Parser so tools such as CloudAI Autotune can invoke hook-bearing scenarios outside the CloudAI repository. Constraint: Preserve conf/hook as the parser default and keep hook-free external invocations backward compatible. Rejected: Require callers to change into the CloudAI checkout | output paths and orchestration should not depend on process working directory. Confidence: high Scope-risk: narrow Directive: Keep scenario config roots explicit at the CLI boundary when external orchestration depends on them. Tested: uv run pytest -q (1636 passed, 4 skipped); uv run pytest -q -m ci_only (490 passed); uv run pytest --dead-fixtures; uv run pre-commit run --all-files; external NCCL dry-run from CloudAI-Autotune cwd exits 0 with --hook-dir Not-tested: Live NCCL execution on a Slurm cluster. Signed-off-by: shreyaskommuri <shreyaskommuri@gmail.com>
📝 WalkthroughWalkthroughAdds a Hook directory configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/test_cli.py`:
- Around line 49-55: The hook-dir help check only covers the dry-run command, so
it can miss regressions in other commands that should also include the shared
option. Update the test in test_hook_dir_is_available_on_run_commands to be
parameterized over the full command set covered by the common_options decorator,
including install, uninstall, run, dry-run, and generate-report, and invoke main
for each command to assert the help output still contains --hook-dir DIRECTORY.
In `@tests/test_parser.py`:
- Around line 42-47: The current test only checks Parser constructor state, so
it won’t catch regressions in path resolution inside parse(). Update
test_custom_hook_root_is_used to exercise Parser.parse() with the injected
hook_root and assert the parsed hook file resolution comes from that custom
directory, using Parser.parse and the parser.hook_root/hook_test_root setup to
verify the runtime behavior instead of just object fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 43241b99-55f5-4ceb-8a26-047f57f413e5
📒 Files selected for processing (5)
src/cloudai/cli/cli.pysrc/cloudai/cli/handlers.pysrc/cloudai/parser.pytests/test_cli.pytests/test_parser.py
| def test_hook_dir_is_available_on_run_commands(): | ||
| runner = CliRunner() | ||
|
|
||
| result = runner.invoke(main, ["dry-run", "--help"]) | ||
|
|
||
| assert result.exit_code == 0 | ||
| assert "--hook-dir DIRECTORY" in result.output |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
Cover all commands that now accept --hook-dir.
This only locks the help text for dry-run, but the PR contract is broader (install, uninstall, run, dry-run, generate-report). If one command later drops @common_options, this regression test still passes. Please parametrize this check over the full command set.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/test_cli.py` around lines 49 - 55, The hook-dir help check only covers
the dry-run command, so it can miss regressions in other commands that should
also include the shared option. Update the test in
test_hook_dir_is_available_on_run_commands to be parameterized over the full
command set covered by the common_options decorator, including install,
uninstall, run, dry-run, and generate-report, and invoke main for each command
to assert the help output still contains --hook-dir DIRECTORY.
| def test_custom_hook_root_is_used(self, parser: Parser, tmp_path: Path): | ||
| hook_root = tmp_path / "hooks" | ||
| parser = Parser(parser.system_config_path, hook_root) | ||
|
|
||
| assert parser.hook_root == hook_root | ||
| assert parser.hook_test_root == hook_root / "test" |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Exercise parse() with the custom hook root, not just constructor state.
These assertions still pass if Parser.parse() regresses to consulting HOOK_ROOT directly. The behavior change in this PR is path resolution during parsing, so the regression test should drive parse() and verify the injected hook directory is the one actually used.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/test_parser.py` around lines 42 - 47, The current test only checks
Parser constructor state, so it won’t catch regressions in path resolution
inside parse(). Update test_custom_hook_root_is_used to exercise Parser.parse()
with the injected hook_root and assert the parsed hook file resolution comes
from that custom directory, using Parser.parse and the
parser.hook_root/hook_test_root setup to verify the runtime behavior instead of
just object fields.
|
we're quite busy with release + I'll be on vacations for couple weeks. I'll respond as soon as I get some spare time 🙏 |
|
@podkidyshev No worries! Take your time, happy to wait but I will update branch and merge conflicts once this is active again to avoid redundant work. |
Summary
Closes #952.
--hook-dirargument to the shared scenario command options used byrun,dry-run,install,uninstall, andgenerate-report.Parserinstead of always resolving hooks fromconf/hookrelative to the process working directory.conf/hookas the default for existing in-repository workflows.CloudAI Autotune exposed this while validating CloudAI's supplied NCCL scenario from outside the CloudAI checkout. Autotune already passed absolute paths for the scenario, system config, tests, and output directory:
CloudAI still resolved hooks from
conf/hookunder Autotune's working directory and exited with:Changing the caller's working directory would make output and orchestration behavior depend on where CloudAI was launched. This change instead makes the remaining configuration root explicit, consistent with
--system-config,--tests-dir, and--test-scenario.Test Plan
Testing environment:
uvenvironmentCloudAI-Autotunerepository, not the CloudAI working directoryRegression and repository checks:
The original NCCL dry-run was then repeated from the Autotune working directory with the new option:
Result:
The dry run emitted expected local warnings for unavailable Slurm commands, but hook discovery succeeded and the complete NCCL scenario was generated.
Additional Notes