Skip to content

Add registry regression test for duplicate tool names across modules#1141

Merged
VaibhavUpreti merged 3 commits intoTracer-Cloud:mainfrom
Aaryan-549:feat/add-duplicate-tool-registry-test
Apr 30, 2026
Merged

Add registry regression test for duplicate tool names across modules#1141
VaibhavUpreti merged 3 commits intoTracer-Cloud:mainfrom
Aaryan-549:feat/add-duplicate-tool-registry-test

Conversation

@Aaryan-549
Copy link
Copy Markdown
Contributor

Fixes #1116

Add registry regression test for duplicate tool names across modules

Describe the changes you have made in this PR

Added a comprehensive regression test test_registry_regression_duplicate_tool_names_across_modules to ensure the tool registry correctly
handles duplicate tool names when they appear across different modules.

What was added:

  • New test that creates two fake modules with identically-named tools
  • Verifies registry keeps only the first tool definition and skips subsequent duplicates
  • Confirms warning is logged when duplicates are detected
  • Validates the first module's tool implementation is preserved

Test validates:

  1. Two modules can export tools with the same name
  2. Registry deduplication logic keeps first definition (FIFO)
  3. Warning message "[tools] Duplicate tool name 'X' across modules; keeping first definition" is logged
  4. Subsequent modules' conflicting tools are skipped silently

Demo/Screenshot for feature changes and bug fixes

Test execution with broken duplicate handling (simulating bug):
FAILED tests/tools/test_registry.py::test_registry_regression_duplicate_tool_names_across_modules
AssertionError: assert {'module': 'second'} == {'module': 'first'}

Test execution with fix in place:
tests/tools/test_registry.py::test_registry_regression_duplicate_tool_names_across_modules PASSED

All 13 registry tests passing after change.


Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:

The test follows the existing pattern in test_registry.py:

  1. Create fake ModuleType instances to simulate tool modules
  2. Decorate functions with @tool decorator to register them
  3. Use monkeypatch to mock the module discovery mechanism
  4. Assert registry behavior: deduplication, warning logging, first-definition preservation

The test proves the fix works by deliberately breaking the continue statement in registry.py line 146 and verifying the test fails
(second module's tool overwrites first). With the fix restored, the test passes.

Why this approach:

  • Mimics real-world scenario where modules might have naming collisions
  • Uses registry's own monkeypatch fixtures for consistency with other tests
  • Validates both the deduplication logic AND the warning mechanism
  • Non-destructive: test doesn't modify actual tool discovery

Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR adds a regression test (test_registry_regression_duplicate_tool_names_across_modules) that verifies the tool registry's cross-module deduplication logic: when two modules export identically-named tools, the registry keeps the first definition and emits a WARNING. The test follows existing patterns in test_registry.py and correctly exercises the _load_registry_snapshot path in registry.py.

Confidence Score: 5/5

Safe to merge; the one finding is a minor robustness suggestion on the caplog assertion that does not affect correctness.

All findings are P2. The test logic is sound, integrates correctly with the autouse cache-reset fixture, and the monkeypatching approach mirrors the established pattern in the file. No production code is changed.

No files require special attention.

Important Files Changed

Filename Overview
tests/tools/test_registry.py Adds regression test for cross-module duplicate tool name deduplication; test logic is sound but the caplog warning assertion is fragile without an explicit log-level override.

Sequence Diagram

sequenceDiagram
    participant Test as test_registry_regression…
    participant Registry as registry._load_registry_snapshot
    participant M1 as module1 (first_module)
    participant M2 as module2 (second_module)
    participant Log as logger (WARNING)

    Test->>Registry: get_registered_tools()
    Registry->>M1: _import_tool_module("first_module")
    M1-->>Registry: [shared_tool_name → {module: first}]
    Registry->>Registry: tools_by_name["shared_tool_name"] = first
    Registry->>M2: _import_tool_module("second_module")
    M2-->>Registry: [shared_tool_name → {module: second}]
    Registry->>Log: WARNING "Duplicate tool name 'shared_tool_name' across modules"
    Registry->>Registry: continue (skip second tool)
    Registry-->>Test: [RegisteredTool(shared_tool_name, first)]
    Test->>Registry: get_registered_tool_map()["shared_tool_name"].run()
    Registry-->>Test: {"module": "first"} ✓
    Test->>Log: assert WARNING record captured ✓
Loading

Reviews (1): Last reviewed commit: "Add registry regression test for duplica..." | Re-trigger Greptile

Comment thread tests/tools/test_registry.py
Aaryan-549 and others added 2 commits April 30, 2026 18:08
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Member

@VaibhavUpreti VaibhavUpreti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, awesome @Aaryan-549 !

@VaibhavUpreti VaibhavUpreti merged commit e40f3fa into Tracer-Cloud:main Apr 30, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🏄 Some PRs rot in review for six weeks. @Aaryan-549's said "not today" and merged like it owned the place. 🌊


👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome.

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.

Add registry regression test for duplicate tool names

2 participants