Skip to content

refactor: replaced ModelMatcher interface with ModelCatalog struct to avoid having to do to nil checks using reflect#1589

Merged
Pratham-Mishra04 merged 1 commit intomainfrom
feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect
Feb 10, 2026
Merged

refactor: replaced ModelMatcher interface with ModelCatalog struct to avoid having to do to nil checks using reflect#1589
Pratham-Mishra04 merged 1 commit intomainfrom
feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect

Conversation

@danpiths
Copy link
Collaborator

@danpiths danpiths commented Feb 9, 2026

Summary

replaced ModelMatcher interface with ModelCatalog struct to avoid having to
do to nil checks using reflect

Changes

  • Added NewTestCatalog function to create a minimal ModelCatalog for testing
    purposes
  • Replaced the custom mockModelMatcher with the new NewTestCatalog function
    in governance tests
  • Updated the governance store to use ModelCatalog directly instead of a
    ModelMatcher interface
  • Renamed references from modelMatcher to modelCatalog throughout the
    codebase

Type of change

  • Refactor
  • Feature

Affected areas

  • Core (Go)
  • Plugins

How to test

# Run the governance tests
go test ./plugins/governance/...

# Run the modelcatalog tests
go test ./framework/modelcatalog/...

Breaking changes

  • No

Related issues

N/A

Security considerations

No security implications as this is a testing utility.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go)

Copy link
Collaborator Author

danpiths commented Feb 9, 2026

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Improved internal model catalog implementation by replacing an abstraction layer with a direct dependency to enhance code clarity and simplify model handling logic.
    • Updated test infrastructure to use new testing utilities for more robust model matching verification across governance tests.

Walkthrough

Replaces the governance plugin's ModelMatcher dependency with a ModelCatalog field, updates related code and tests to use ModelCatalog, and adds an exported NewTestCatalog helper to construct minimal ModelCatalog instances for testing. No background sync or production initialization behavior changed.

Changes

Cohort / File(s) Summary
Model catalog test helper
framework/modelcatalog/main.go
Adds exported NewTestCatalog(baseModelIndex map[string]string) *ModelCatalog to create minimal ModelCatalog instances for tests (does not start sync workers or external connections).
Governance core implementation
plugins/governance/store.go
Removes ModelMatcher interface; LocalGovernanceStore now holds modelCatalog *modelcatalog.ModelCatalog. Updates NewLocalGovernanceStore signature and replaces matcher calls with modelCatalog.GetBaseModelName(...) for model-name normalization and key derivation.
Governance test infrastructure & tests
plugins/governance/test_utils.go, plugins/governance/model_provider_governance_test.go
Removes mockModelMatcher type and constructor; adds newTestModelCatalog(t *testing.T) that returns *modelcatalog.ModelCatalog (uses NewTestCatalog). Tests updated to use the new test catalog factory.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • akshaydeo

Poem

🐰 I swapped a matcher for a tidy book,
A quiet catalog took its nook,
Tests now sip tea, no workers to hum,
Pages closed gently — the changes are done,
I thump my foot and nibble a plum.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main refactoring change: replacing ModelMatcher interface with ModelCatalog struct and the specific reason (avoiding nil checks with reflect).
Description check ✅ Passed The description covers all essential required sections: Summary, Changes, Type of change, Affected areas, How to test, Breaking changes, and Checklist items are mostly complete.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@framework/modelcatalog/main.go`:
- Around line 638-648: NewTestCatalog returns a minimal ModelCatalog but doesn't
initialize the done channel, so calling Cleanup (which closes mc.done) can
panic; update NewTestCatalog to initialize the ModelCatalog.done channel (e.g.,
make(chan struct{})) when constructing the return value so Cleanup can safely
close it; refer to NewTestCatalog, ModelCatalog, and Cleanup to locate and fix
the initialization.

@danpiths danpiths force-pushed the feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect branch from 35ce660 to 26647b0 Compare February 9, 2026 15:26
Copy link
Collaborator

Pratham-Mishra04 commented Feb 9, 2026

Merge activity

@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from 02-06-feat_added_retries_for_mcp_connection to graphite-base/1589 February 9, 2026 17:45
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect branch from 26647b0 to 1913341 Compare February 9, 2026 19:31
@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from graphite-base/1589 to 02-06-feat_added_retries_for_mcp_connection February 9, 2026 19:33
@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from 02-06-feat_added_retries_for_mcp_connection to graphite-base/1589 February 10, 2026 09:14
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect branch from 1913341 to 6328738 Compare February 10, 2026 09:22
@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from graphite-base/1589 to 02-06-feat_added_retries_for_mcp_connection February 10, 2026 09:22
@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from 02-06-feat_added_retries_for_mcp_connection to graphite-base/1589 February 10, 2026 09:23
@Pratham-Mishra04 Pratham-Mishra04 changed the base branch from graphite-base/1589 to main February 10, 2026 09:23
… avoid having to do to nil checks using reflect
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect branch from 6328738 to d3cb70e Compare February 10, 2026 09:24
@Pratham-Mishra04 Pratham-Mishra04 merged commit 18cbd59 into main Feb 10, 2026
8 checks passed
@Pratham-Mishra04 Pratham-Mishra04 deleted the feature/02-09-refactor_replaced_modelmatcher_interface_with_modelcatalog_struct_to_avoid_having_to_do_to_nil_checks_using_reflect branch February 10, 2026 09:26
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.

2 participants