Skip to content

tests: refine coverage and add cache stats, settings enhancements, and provider fixes#137

Closed
RicherTunes wants to merge 6 commits intomainfrom
chore/coverage-35-push-2
Closed

tests: refine coverage and add cache stats, settings enhancements, and provider fixes#137
RicherTunes wants to merge 6 commits intomainfrom
chore/coverage-35-push-2

Conversation

@RicherTunes
Copy link
Owner

@RicherTunes RicherTunes commented Sep 13, 2025

Add targeted unit tests and code refinements to raise coverage and improve provider resilience:

  • UrlValidator: dangerous schemes, local provider URLs, scheme inference, port bounds, normalization.
  • ConcurrentCache: hits/misses tracking, remove/clear adjust size.
  • BrainarrSettings: API key trimming & length guard; local URL normalization; set/get model per provider.
  • Providers: Add explicit generic type to resilience async calls for HttpResponse to improve type safety.

All tests tagged Category=Unit. No production behavior changes.

Enhancements include:

  • BrainarrSettingsTests: Removed obsolete tests, added tests for API key trimming, excessive length throwing, local URL normalization, and provider-specific model setting.
  • UrlValidatorTests: New tests for URL validation including dangerous schemes, local URLs, scheme inference, port validation, and normalization.
  • ConcurrentCacheTests: Added tests for cache hit/miss tracking and size updates on remove/clear operations.
  • Provider services: Updated resilience async calls to specify generic HttpResponse type.

This update refines and expands test coverage, improves test clarity and relevance, and enhances provider resilience handling.

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/e9bb08d9-44a7-4400-b3e7-2e4495f3e2ac

…/remove/clear; add BrainarrSettings property tests
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines 32 to 36
var s = new BrainarrSettings { Provider = AIProvider.Ollama };
s.ConfigurationUrl = "localhost:11434";
s.ConfigurationUrl.Should().Be("http://localhost:11434");

// Act
var result = settings.Validate();

// Assert
result.IsValid.Should().BeTrue();
s.Provider = AIProvider.LMStudio;

Choose a reason for hiding this comment

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

[P1] ConfigurationUrl tests assume normalization that the property does not perform

The new ConfigurationUrl_Normalizes_For_Local_Providers asserts that assigning "localhost:11434" (or "127.0.0.1:1234") will automatically become http://…. However BrainarrSettings.ConfigurationUrl simply assigns to _ollamaUrl/_lmStudioUrl without passing through NormalizeHttpUrlOrOriginal, so the stored value remains as provided and the getter returns the un-normalized string. Without a matching production change these assertions will fail every run. Either call the normalization helper in the test (or in ConfigurationUrl) or relax the expectation to the raw value.

Useful? React with 👍 / 👎.

Comment on lines 33 to 36
[InlineData("example.com", false)] // no port or dot? Normalize requires dot or port; this has dot so inferred OK but IsValidUrl requires scheme; focus Normalize below
public void Missing_Scheme_Inferred_For_Local(string url, bool expected)
{
UrlValidator.IsValidUrl(url, allowEmpty: false).Should().Be(expected);

Choose a reason for hiding this comment

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

[P1] IsValidUrl test rejects example.com despite the implementation treating it as valid

In Missing_Scheme_Inferred_For_Local the case ("example.com", false) expects UrlValidator.IsValidUrl to return false when no scheme is supplied. The validator explicitly calls EnsureScheme, which prefixes http:// for strings containing a dot or port before validating via Uri.TryCreate, so example.com is accepted. This assertion will consistently fail unless the implementation is changed to forbid non-local hostnames without schemes. Adjust the expected value to true or validate with IsValidLocalProviderUrl if that is the desired constraint.

Useful? React with 👍 / 👎.

@RicherTunes RicherTunes changed the title tests: more coverage (UrlValidator, cache stats, settings) tests: more coverage (UrlValidator, cache stats, settings enhancements) Sep 13, 2025
…HttpResponse> to avoid HttpException/StatusCode ambiguity in analysis build
@RicherTunes RicherTunes changed the title tests: more coverage (UrlValidator, cache stats, settings enhancements) tests: refine coverage and add cache stats, settings enhancements, and provider fixes Sep 13, 2025
@RicherTunes RicherTunes force-pushed the main branch 9 times, most recently from 7aec68d to 024c063 Compare September 16, 2025 21:07
@RicherTunes
Copy link
Owner Author

Closing in favor of PR #146 which contains similar coverage improvements. Consolidating duplicate PRs.

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