Skip to content

Conversation

@dagardner-nv
Copy link
Contributor

@dagardner-nv dagardner-nv commented Oct 6, 2025

Description

  • When using AyncMock all attributes return another AyncMock, there were a few cases where a method was being called on an AsyncMock that was expected to be blocking (yielding an ... was never awaited warning). In these situations I explicitly set a blocking mock object.
  • Use the model_fields attribute on the class not the instance, avoids Pydantic deprecation warning

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • Refactor

    • Improved component reference discovery by using class-level metadata for more consistent behavior. No API changes or user-facing differences expected.
  • Tests

    • Updated tests to align with metadata handling changes.
    • Enhanced HTTP response mocks (including headers and status behavior) for more realistic scenarios.
    • Expanded authentication tests to cover callback setup in token flows.
  • Chores

    • General reliability and consistency improvements, with no impact on existing workflows.

…Pydantic deprecation warning

Signed-off-by: David Gardner <[email protected]>
…Pydantic deprecation warning

Signed-off-by: David Gardner <[email protected]>
…ver an attribute from an AsyncMock object ii called as if it were a blocking method

Signed-off-by: David Gardner <[email protected]>
@dagardner-nv dagardner-nv self-assigned this Oct 6, 2025
@dagardner-nv dagardner-nv requested a review from a team as a code owner October 6, 2025 22:42
@dagardner-nv dagardner-nv added improvement Improvement to existing functionality non-breaking Non-breaking change labels Oct 6, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

Switches Pydantic field access from instance-level to class-level in recursive component reference discovery; updates tests to use class-level model_fields. Adjusts MCP tests to use MagicMock for raise_for_status, add JSON Content-Type headers in mocked responses, and adds a mocked private callback in token storage tests.

Changes

Cohort / File(s) Summary of changes
Builder: class-level model_fields access
src/nat/builder/component_utils.py
In recursive_componentref_discovery, iterate over type(value).model_fields instead of value.model_fields when value is a BaseModel instance.
Builder tests alignment
tests/nat/builder/test_component_utils.py
Update tests to iterate TestConfig.model_fields (class-level) instead of instance_config.model_fields.
Data models tests alignment
tests/nat/data_models/test_optimizable.py
Replace dict(m.model_fields)["x"].json_schema_extra usages with dict(M.model_fields)["x"].json_schema_extra (class-level access).
MCP auth provider test mocks
tests/nat/mcp/test_mcp_auth_provider.py
Use MagicMock for mock_resp.raise_for_status, and set mock_resp.headers = {"content-type": "application/json"} on relevant mocked HTTP responses.
MCP token storage test mocks
tests/nat/mcp/test_mcp_token_storage.py
Add mock_instance._set_custom_auth_callback = MagicMock(...) in the lazy OAuth2 token test setup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title uses an imperative verb and succinctly describes the primary change of silencing test warnings, aligns with the PR’s objectives, and stays well under the 72-character limit.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5170f2 and 6fddb56.

📒 Files selected for processing (1)
  • tests/nat/data_models/test_optimizable.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{py,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.{py,yaml,yml}: Configure response_seq as a list of strings; values cycle per call, and [] yields an empty string.
Configure delay_ms to inject per-call artificial latency in milliseconds for nat_test_llm.

Files:

  • tests/nat/data_models/test_optimizable.py
**/*.py

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.py: Programmatic use: create TestLLMConfig(response_seq=[...], delay_ms=...), add with builder.add_llm("", cfg).
When retrieving the test LLM wrapper, use builder.get_llm(name, wrapper_type=LLMFrameworkEnum.) and call the framework’s method (e.g., ainvoke, achat, call).

**/*.py: In code comments/identifiers use NAT abbreviations as specified: nat for API namespace/CLI, nvidia-nat for package name, NAT for env var prefixes; do not use these abbreviations in documentation
Follow PEP 20 and PEP 8; run yapf with column_limit=120; use 4-space indentation; end files with a single trailing newline
Run ruff check --fix as linter (not formatter) using pyproject.toml config; fix warnings unless explicitly ignored
Respect naming: snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants
Treat pyright warnings as errors during development
Exception handling: use bare raise to re-raise; log with logger.error() when re-raising to avoid duplicate stack traces; use logger.exception() when catching without re-raising
Provide Google-style docstrings for every public module, class, function, and CLI command; first line concise and ending with a period; surround code entities with backticks
Validate and sanitize all user input, especially in web or CLI interfaces
Prefer httpx with SSL verification enabled by default and follow OWASP Top-10 recommendations
Use async/await for I/O-bound work; profile CPU-heavy paths with cProfile or mprof before optimizing; cache expensive computations with functools.lru_cache or external cache; leverage NumPy vectorized operations when beneficial

Files:

  • tests/nat/data_models/test_optimizable.py
tests/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Unit tests reside under tests/ and should use markers defined in pyproject.toml (e.g., integration)

Files:

  • tests/nat/data_models/test_optimizable.py

⚙️ CodeRabbit configuration file

tests/**/*.py: - Ensure that tests are comprehensive, cover edge cases, and validate the functionality of the code. - Test functions should be named using the test_ prefix, using snake_case. - Any frequently repeated code should be extracted into pytest fixtures. - Pytest fixtures should define the name argument when applying the pytest.fixture decorator. The fixture
function being decorated should be named using the fixture_ prefix, using snake_case. Example:
@pytest.fixture(name="my_fixture")
def fixture_my_fixture():
pass

Files:

  • tests/nat/data_models/test_optimizable.py
{tests/**/*.py,examples/*/tests/**/*.py}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

{tests/**/*.py,examples/*/tests/**/*.py}: Use pytest (with pytest-asyncio for async); name test files test_*.py; test functions start with test_; extract repeated code into fixtures; fixtures must set name in decorator and be named with fixture_ prefix
Mock external services with pytest_httpserver or unittest.mock; do not hit live endpoints
Mark expensive tests with @pytest.mark.slow or @pytest.mark.integration

Files:

  • tests/nat/data_models/test_optimizable.py
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • tests/nat/data_models/test_optimizable.py
🔇 Additional comments (1)
tests/nat/data_models/test_optimizable.py (1)

74-74: LGTM! Correctly addresses Pydantic deprecation warning.

The switch from instance-level to class-level access of model_fields (e.g., M.model_fields instead of m.model_fields) correctly follows Pydantic v2 best practices and silences the deprecation warning as intended by the PR objectives.

Also applies to: 83-83, 99-99, 119-119, 137-137


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: David Gardner <[email protected]>
@dagardner-nv
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 62c05b5 into NVIDIA:release/1.3 Oct 6, 2025
17 checks passed
@dagardner-nv dagardner-nv deleted the david-model_fields-warning branch October 6, 2025 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement to existing functionality non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants