fix(codeql): batch-5 cyclic-import, multiple-definition, unreachable#114
Conversation
|
marcusds
left a comment
There was a problem hiding this comment.
Inline notes on the rationale behind each change (CodeQL batch-5). Self-authored context, not blocking.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPR refactors auditor SDK resources to use parent protocol abstraction, modernizes E2E test patterns with explicit type casting and smoke testing, and applies targeted cleanups across metric computation, pagination, validation assertions, error handling, and dataset retrieval. ChangesAuditor SDK Parent Protocol Abstraction
E2E Testing Refactoring & Type Safety
Scattered Metric, Validation & Utility Cleanups
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
plugins/nemo-auditor/src/nemo_auditor/sdk_resources/_parent.py (1)
18-35: 💤 Low valueConsider adding
__all__for consistency.Both
configs.pyandtargets.pydefine__all__. Adding it here clarifies the public interface.Suggested addition
class AsyncAuditorResourceParent(Protocol): """Async parent surface used by sub-resources.""" _http_client: httpx.AsyncClient def _url(self, path: str) -> str: """Build the absolute request URL for ``path``.""" raise NotImplementedError + + +__all__ = ["AuditorResourceParent", "AsyncAuditorResourceParent"]🤖 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 `@plugins/nemo-auditor/src/nemo_auditor/sdk_resources/_parent.py` around lines 18 - 35, Add a module-level __all__ to explicitly declare the public API for this file; include the protocol names "AuditorResourceParent" and "AsyncAuditorResourceParent" in the list so imports and tooling are consistent with configs.py and targets.py. Update the top-level exports by adding __all__ = ["AuditorResourceParent", "AsyncAuditorResourceParent"] near the class definitions to make the public interface explicit.
🤖 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 `@packages/nmp_testing/src/nmp/testing/e2e/evaluator.py`:
- Around line 166-167: The code uses a string literal type in the cast call -
replace cast("int", ...) with cast(int, ...) for the samples_processed
assignment and the similar occurrence around line 179; update the two calls that
cast outputs.job_status.status_details.get("samples_processed", 0) to use
cast(int, ...) so the concrete int type is used (refer to the samples_processed
variable and the cast(...) calls on outputs.job_status.status_details).
---
Nitpick comments:
In `@plugins/nemo-auditor/src/nemo_auditor/sdk_resources/_parent.py`:
- Around line 18-35: Add a module-level __all__ to explicitly declare the public
API for this file; include the protocol names "AuditorResourceParent" and
"AsyncAuditorResourceParent" in the list so imports and tooling are consistent
with configs.py and targets.py. Update the top-level exports by adding __all__ =
["AuditorResourceParent", "AsyncAuditorResourceParent"] near the class
definitions to make the public interface explicit.
🪄 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: CHILL
Plan: Enterprise
Run ID: 17af8ec3-6114-4a4e-ab4f-bbb96de49251
⛔ Files ignored due to path filters (2)
sdk/python/nemo-platform/src/nemo_platform/beta/evaluator/metrics/tool_calling.pyis excluded by!sdk/**sdk/python/nemo-platform/src/nemo_platform/cli/core/pagination.pyis excluded by!sdk/**
📒 Files selected for processing (14)
packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/metrics/tool_calling.pypackages/nemo_platform_ext/src/nemo_platform_ext/cli/core/pagination.pypackages/nmp_common/tests/secrets/test_secret_key.pypackages/nmp_testing/src/nmp/testing/e2e/evaluator.pyplugins/nemo-auditor/src/nemo_auditor/sdk_resources/_parent.pyplugins/nemo-auditor/src/nemo_auditor/sdk_resources/configs.pyplugins/nemo-auditor/src/nemo_auditor/sdk_resources/targets.pyscript/openapi_helper/openapi_tools.pyservices/core/jobs/tests/test_jobs_api.pyservices/core/models/src/nmp/core/models/parallelism/models.pyservices/core/models/tests/unit/parallelism/test_parallelism_models.pyservices/customizer/src/nmp/customizer/tasks/training/backends/nemo_rl/ray_bootstrap.pyservices/evaluator/src/nmp/evaluator/app/datasets/nmp_datasets/utils.pyservices/intake/tests/test_entries.py
💤 Files with no reviewable changes (4)
- services/customizer/src/nmp/customizer/tasks/training/backends/nemo_rl/ray_bootstrap.py
- packages/nemo_platform_ext/src/nemo_platform_ext/cli/core/pagination.py
- packages/nemo_evaluator_sdk/src/nemo_evaluator_sdk/metrics/tool_calling.py
- services/evaluator/src/nmp/evaluator/app/datasets/nmp_datasets/utils.py
py/unsafe-cyclic-import (8 fixed, 4 vendored dismissed): - nemo-auditor sdk: break the sdk <-> sdk_resources cycle by typing sub-resource parents against new Protocols (AuditorResourceParent / AsyncAuditorResourceParent in sdk_resources/_parent.py) instead of importing the concrete AuditorPluginResource under TYPE_CHECKING. py/multiple-definition (9 fixed): - Drop dead pre-assignments later reassigned before use (tool_calling fn_name_and_args_accuracy_score, pagination page_num, ray_bootstrap exit_code init). - Tests: drop pointless bindings in pytest.raises blocks (test_secret_key, test_parallelism_models -> pytest.raises), bare create POST in test_entries; in test_jobs_api the dead 'response' rebinds were latent missing assertions -> added the absent status_code == 201 / == 200 checks. py/unreachable-statement (3 fixed): - openapi_tools: 'raise typer.Exit(1)' after 'raise e' -> 'raise ... from e'. - parallelism/models: Priority-4 guard always true; drop redundant if + dead 'return None'. - evaluator datasets/utils: drop dead trailing 'return dataset'. Vendored switchyard cyclic-imports and unreachable false-positives (pytest.raises suppression CodeQL doesn't model), defensive guards, and a WIP stub dismissed via the Security tab. Signed-off-by: mschwab <mschwab@nvidia.com>
- get_job_outputs: drop dead loop bindings (aggregate_scores/row_scores
reassigned via typed accessors before use); keep the generic
results.download calls for endpoint coverage.
- Clear pre-existing ty errors in the same file so the commit hook (which
type-checks changed non-excluded files) passes: build the fileset.create
call with explicit kwargs instead of **dict spread, and cast
status_details.get('samples_processed') to int before numeric compare.
Signed-off-by: mschwab <mschwab@nvidia.com>
Signed-off-by: mschwab <mschwab@nvidia.com>
Drops the # noqa: B017 by narrowing the missing-precision test to the pydantic ValidationError ModelSpec actually raises. Signed-off-by: mschwab <mschwab@nvidia.com>
Note that the typed aggregate_scores/row_scores accessors below are what validate content; the generic results.download loop only asserts the endpoint responds and the body reads. Addresses review feedback. Signed-off-by: mschwab <mschwab@nvidia.com>
CodeQL py/ineffectual-statement flagged the inline '...' stub bodies in the parent Protocols. Replace with a docstring + raise NotImplementedError so the statement is effectful and the declared str return type holds. Signed-off-by: mschwab <mschwab@nvidia.com>
Signed-off-by: mschwab <mschwab@nvidia.com>
bbbd4d6 to
f2737c8
Compare
CodeRabbit: AGENTS.md prefers concrete type hints over string-based ones.
cast("int", ...) -> cast(int, ...).
Signed-off-by: mschwab <mschwab@nvidia.com>
Summary
Batch 5 of the CodeQL cleanup. Targets the error/warning-severity rules deferred from prior batches:
py/unsafe-cyclic-import,py/multiple-definition,py/unreachable-statement. 22 alerts fixed in-tree, 14 dismissed (vendored, false-positives, defensive guards).Branches off
mainafter #91/#98/#100 merged; no overlap with the still-open #102 (batch-4) — files in flight there were intentionally excluded.Alerts addressed
py/unsafe-cyclic-importsdk ⇄ sdk_resourcesimport cycle by introducingAuditorResourceParent/AsyncAuditorResourceParentProtocols insdk_resources/_parent.pyand typing the sub-resourceparentagainst them, instead of importing the concreteAuditorPluginResourceunderTYPE_CHECKING. The 4 vendored switchyard cycles were dismissed (snapshot, overwritten on re-vendor).py/multiple-definitiontool_callingscore init,paginationpage_num,ray_bootstrapexit_code,e2e/evaluatorloop bindings). In tests, dropped pointless bindings insidepytest.raisesblocks and—where the deadresponserebind intest_jobs_apimasked a latent missing assertion—added the absentstatus_code == 201/200checks.py/unreachable-statementopenapi_toolsdouble-raise→raise … from e;parallelism/modelsalways-true Priority-4 guard + deadreturn None;evaluator/datasets/utilsdead trailingreturn. Dismissed: post-pytest.raises-block assertions CodeQL marks unreachable because it doesn't model__exit__suppression (6), a defensivedelin afinally(1), a type-checker-load-bearing terminalraise(1), a WIP stub (1), illustrative test scaffolding (1).Notable
test_jobs_apicreated jobs 2 and 3 but never asserted the POST succeeded (theresponsewas clobbered by the next GET). Added the missingassert response.status_code == 201.# noqaleft behind: the missing-precision test now assertspydantic.ValidationErrorrather than a broadException(noB017suppression).Test plan
uv run pytest plugins/nemo-auditor/tests/test_sdk_resources.py— 15 passuv run pytest packages/nmp_common/tests/secrets packages/nemo_evaluator_sdk/tests services/core/jobs/tests/test_jobs_api.py services/intake/tests/test_entries.py— green (894 in the broad run)ruff check+ty checkclean on all touched, non-excluded filesimport nemo_auditor.sdk+ both sub-resource modules load)Dismissals
14 alerts dismissed via the Security tab with rationale (vendored switchyard,
pytest.raises-suppression false positives, defensivefinally/terminal-raiseguards, one WIP stub). See per-alert comments.Summary by CodeRabbit
Refactor
Behavior
Tests