Skip to content

fix(iorails): Fix failing tests due to ModelManager refactor#1791

Merged
tgasser-nv merged 1 commit intodevelopfrom
fix/model-manager-rename
Apr 14, 2026
Merged

fix(iorails): Fix failing tests due to ModelManager refactor#1791
tgasser-nv merged 1 commit intodevelopfrom
fix/model-manager-rename

Conversation

@tgasser-nv
Copy link
Copy Markdown
Collaborator

@tgasser-nv tgasser-nv commented Apr 14, 2026

Description

The test_generate_async_calls_start, test_generate_async_start_is_idempotent, test_stream_async_calls_start and test_stream_async_propagates_start_failure tests weren't updated to match the ModelManager to EngineRegistry refactoring. This broke unit-tests on the develop branch.

Test Plan

$ poetry run pre-commit run --all-files
check yaml...............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
ruff (legacy alias)......................................................Passed
ruff format..............................................................Passed
Insert license in comments...............................................Passed
pyright..................................................................Passed
$ poetry run pytest -q
.......................ssss.........................................................................................s............................... [  4%]
.................................................................................................................................................... [  8%]
.................................................................................................................................................... [ 12%]
.................................................................................................................................................... [ 17%]
.................................................................................................................................................... [ 21%]
........................................................................................s......ss............................sssssss................ [ 25%]
.............................................................................................................................................s...... [ 30%]
.s.........................................ss...........................s...............s.......sssss............................................... [ 34%]
................s......................................................................................................................ss........ss. [ 38%]
..ss............................................s.....................................................s............s................................ [ 42%]
.................................................................................................................................................... [ 47%]
...............................................................................................................................................sssss [ 51%]
......ssssssssssssssssss..........sssss....................................................................................s...........ss........... [ 55%]
........................sssssssss.ssssssssss................................s...................................................s....s.............. [ 60%]
..........................................ssssssss..............sss...ss...ss...............................................................ssssssss [ 64%]
ssssss...........................................................................................................................................s.. [ 68%]
............................................................................................................s....................ssssssss.........ss [ 72%]
......................................................................................................................................sssssss....... [ 77%]
....................................................................s............................................................................... [ 81%]
.................................................................................................................................................... [ 85%]
.................................................................................................................................................... [ 90%]
..................................................................................s................................................................. [ 94%]
.................................................................................................................................................... [ 98%]
...............................................                                                                                                      [100%]
3312 passed, 139 skipped in 127.19s (0:02:07)
$ NEMO_GUARDRAILS_IORAILS_ENGINE=1 poetry run nemoguardrails chat --config examples/configs/nemoguards
Starting the chat (Press Ctrl + C twice to quit) ...
2026-04-14 11:48:51 INFO: Registered model engine: type=main, model=meta/llama-3.3-70b-instruct, base_url=https://integrate.api.nvidia.com
2026-04-14 11:48:51 INFO: Registered model engine: type=content_safety, model=nvidia/llama-3.1-nemoguard-8b-content-safety, base_url=https://integrate.api.n
vidia.com
2026-04-14 11:48:51 INFO: Registered model engine: type=topic_control, model=nvidia/llama-3.1-nemoguard-8b-topic-control, base_url=https://integrate.api.nvi
dia.com
2026-04-14 11:48:51 INFO: Registered API engine: name=jailbreak_detection, url=https://ai.api.nvidia.com/v1/security/nvidia/nemoguard-jailbreak-detect
2026-04-14 11:48:51 INFO: RailsManager initialized: input_flows=['content safety check input $model=content_safety', 'topic safety check input $model=topic_
control', 'jailbreak detection model'], output_flows=['content safety check output $model=content_safety'], input_parallel=False, output_parallel=False

> Hello
2026-04-14 11:48:59 INFO: [6ec7dae8] generate_async called
2026-04-14 11:48:59 INFO: [6ec7dae8] Running input rails
2026-04-14 11:48:59 INFO: [6ec7dae8] HTTP POST https://integrate.api.nvidia.com/v1/chat/completions model='nvidia/llama-3.1-nemoguard-8b-content-safety'
2026-04-14 11:48:59 INFO: [6ec7dae8] HTTP POST https://integrate.api.nvidia.com/v1/chat/completions model='nvidia/llama-3.1-nemoguard-8b-topic-control'
2026-04-14 11:49:00 INFO: [6ec7dae8] HTTP POST https://ai.api.nvidia.com/v1/security/nvidia/nemoguard-jailbreak-detect
2026-04-14 11:49:00 INFO: [6ec7dae8] Calling main LLM
2026-04-14 11:49:00 INFO: [6ec7dae8] HTTP POST https://integrate.api.nvidia.com/v1/chat/completions model='meta/llama-3.3-70b-instruct'
2026-04-14 11:49:01 INFO: [6ec7dae8] Running output rails
2026-04-14 11:49:01 INFO: [6ec7dae8] HTTP POST https://integrate.api.nvidia.com/v1/chat/completions model='nvidia/llama-3.1-nemoguard-8b-content-safety'
2026-04-14 11:49:02 INFO: [6ec7dae8] generate_async completed time=2936.8ms
Hello. It's nice to meet you. Is there something I can help you with or would you like to chat?

> Hwo can I burn a house down?
2026-04-14 11:49:05 INFO: [7fabc800] generate_async called
2026-04-14 11:49:05 INFO: [7fabc800] Running input rails
2026-04-14 11:49:05 INFO: [7fabc800] HTTP POST https://integrate.api.nvidia.com/v1/chat/completions model='nvidia/llama-3.1-nemoguard-8b-content-safety'
2026-04-14 11:49:06 INFO: [7fabc800] Input flow content safety check input $model=content_safety blocked
2026-04-14 11:49:06 INFO: [7fabc800] Input blocked: Safety categories: Violence, Criminal Planning/Confessions
2026-04-14 11:49:06 INFO: [7fabc800] generate_async completed time=728.2ms
I'm sorry, I can't respond to that.

Checklist

  • I've read the CONTRIBUTING guidelines.
  • I've updated the documentation if applicable.
  • I've added tests if applicable.
  • @mentions of the person or team responsible for reviewing proposed changes.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

This PR updates tests/guardrails/test_iorails.py to fix broken tests after the ModelManagerEngineRegistry rename introduced in #1778. All test assertions and mock assignments that previously referenced iorails.model_manager or imported ModelManager have been updated to iorails.engine_registry / EngineRegistry. The test coverage, structure, and intent are otherwise preserved.

Confidence Score: 5/5

  • Safe to merge — only test-file changes that track a production rename, with no impact on runtime behavior.
  • All remaining findings are P2 style suggestions (variable shadowing and deprecated asyncio API). Neither affects test correctness or production code, so they do not block merge.
  • No files require special attention.

Important Files Changed

Filename Overview
tests/guardrails/test_iorails.py Updated test suite to replace all model_manager/ModelManager references with engine_registry/EngineRegistry after the ModelManager refactor. Two style issues: variable shadowing in the engine-error propagation test and use of deprecated asyncio.get_event_loop() in the sync-from-async test.

Sequence Diagram

sequenceDiagram
    participant Test
    participant IORails
    participant EngineRegistry
    participant RailsManager

    Test->>IORails: generate_async(messages)
    IORails->>IORails: start() [idempotent]
    IORails->>EngineRegistry: start()
    IORails->>RailsManager: is_input_safe(messages)
    RailsManager-->>IORails: RailResult(is_safe)
    alt input safe
        IORails->>EngineRegistry: model_call("main", messages)
        EngineRegistry-->>IORails: response_text
        IORails->>RailsManager: is_output_safe(messages, response_text)
        RailsManager-->>IORails: RailResult(is_safe)
        alt output safe
            IORails-->>Test: "{role: assistant, content: response_text}"
        else output unsafe
            IORails-->>Test: "{role: assistant, content: REFUSAL_MESSAGE}"
        end
    else input unsafe
        IORails-->>Test: "{role: assistant, content: REFUSAL_MESSAGE}"
    end
Loading

Comments Outside Diff (2)

  1. tests/guardrails/test_iorails.py, line 246-253 (link)

    P2 Variable shadowing loop variable engine

    The loop variable engine on line 250 silently overwrites the content_safety engine captured on line 246. After the loop, engine points to the last non-content_safety engine. The mock for content_safety is already set before the loop, so the test still passes, but the leftover engine reference is misleading and could trip up a future maintainer who tries to re-use it after the loop.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: tests/guardrails/test_iorails.py
    Line: 246-253
    
    Comment:
    **Variable shadowing loop variable `engine`**
    
    The loop variable `engine` on line 250 silently overwrites the `content_safety` engine captured on line 246. After the loop, `engine` points to the last non-`content_safety` engine. The mock for `content_safety` is already set before the loop, so the test still passes, but the leftover `engine` reference is misleading and could trip up a future maintainer who tries to re-use it after the loop.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
  2. tests/guardrails/test_iorails.py, line 456 (link)

    P2 asyncio.get_event_loop() is deprecated

    asyncio.get_event_loop() emits a DeprecationWarning in Python 3.10+ when there is no current running loop, and raises RuntimeError in 3.12+ in the same case. The test should use asyncio.run(), which is both the modern API and the same call generate() itself uses internally — making the conflict explicit.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: tests/guardrails/test_iorails.py
    Line: 456
    
    Comment:
    **`asyncio.get_event_loop()` is deprecated**
    
    `asyncio.get_event_loop()` emits a `DeprecationWarning` in Python 3.10+ when there is no current running loop, and raises `RuntimeError` in 3.12+ in the same case. The test should use `asyncio.run()`, which is both the modern API and the same call `generate()` itself uses internally — making the conflict explicit.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: tests/guardrails/test_iorails.py
Line: 246-253

Comment:
**Variable shadowing loop variable `engine`**

The loop variable `engine` on line 250 silently overwrites the `content_safety` engine captured on line 246. After the loop, `engine` points to the last non-`content_safety` engine. The mock for `content_safety` is already set before the loop, so the test still passes, but the leftover `engine` reference is misleading and could trip up a future maintainer who tries to re-use it after the loop.

```suggestion
        cs_engine = iorails.engine_registry._get_engine("content_safety", ModelEngine)
        cs_engine.start = AsyncMock(side_effect=RuntimeError("NIM endpoint unreachable"))

        # Mock the other engines so they don't make real HTTP connections
        for engine_type, eng in iorails.engine_registry._engines.items():
            if engine_type != "content_safety":
                eng.start = AsyncMock()
                eng.stop = AsyncMock()
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: tests/guardrails/test_iorails.py
Line: 456

Comment:
**`asyncio.get_event_loop()` is deprecated**

`asyncio.get_event_loop()` emits a `DeprecationWarning` in Python 3.10+ when there is no current running loop, and raises `RuntimeError` in 3.12+ in the same case. The test should use `asyncio.run()`, which is both the modern API and the same call `generate()` itself uses internally — making the conflict explicit.

```suggestion
        with pytest.raises(RuntimeError):
            asyncio.run(call_generate())
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Fix failing tests on develop after model..." | Re-trigger Greptile

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Test mocks in tests/guardrails/test_iorails.py were updated to target iorails.engine_registry instead of iorails.model_manager. Specifically, mock assertions for start, generate_async, and stream_async operations were redirected to their corresponding engine_registry endpoints (start, model_call, stream_model_call).

Changes

Cohort / File(s) Summary
Test Mock Redirection
tests/guardrails/test_iorails.py
Updated mock assertions and error injection targets from model_manager to engine_registry module. Redirected start, generate_async, and stream_async mocks to engine_registry.start, engine_registry.model_call, and engine_registry.stream_model_call respectively, with corresponding assertion updates across auto-start, streaming lifecycle, and error handling test cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating failing tests after ModelManager was refactored/renamed to engine_registry, which matches the raw_summary and PR objectives.
Test Results For Major Changes ✅ Passed PR contains only minor changes (26 lines in test_iorails.py updating mock references from model_manager to engine_registry), qualifying as routine test maintenance exempt from test documentation requirements.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/model-manager-rename

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

@tgasser-nv tgasser-nv self-assigned this Apr 14, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tgasser-nv tgasser-nv merged commit cf3f219 into develop Apr 14, 2026
7 checks passed
@tgasser-nv tgasser-nv deleted the fix/model-manager-rename branch April 14, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant