Accept "localhost:11434" and trailing slashes as the Ollama endpoint [patch] - #178
Merged
Merged
Conversation
…[patch] The endpoint was used exactly as typed. "localhost:11434", the address Ollama prints, parsed as a URI with the scheme "localhost" and crashed Scan with an unhandled NotSupportedException, and a trailing slash sent every describe request to "//api/generate". OllamaClient.NormalizeEndpoint now adds a missing http:// and drops trailing slashes, and rejects anything that isn't an http or https address. Configure saves the normalized value or keeps the old one, -e/--endpoint is normalized too, Scan prints an "invalid endpoint" error instead of crashing, and request URLs are built with new Uri(base, "api/generate") rather than string concatenation. Fixes #157 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kj95GdQsZpSCcND7LqacT1
SonarCloud failed the quality gate on coverage (69.2%) and on S5332 for the "http://" literal. Build the default scheme from Uri.UriSchemeHttp and Uri.SchemeDelimiter, move Configure's endpoint handling into the testable Configure.ChooseEndpoint, and remove the NotSupportedException and InvalidOperationException catches in IsAvailableAsync: GetBaseUri now rejects every endpoint that could raise them, as ArgumentException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kj95GdQsZpSCcND7LqacT1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kj95GdQsZpSCcND7LqacT1
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #157
What was wrong
The endpoint was used exactly as typed, which broke in two ways:
localhost:11434, the address Ollama prints, parsed as a URI whose scheme islocalhost.IsAvailableAsyncdidn't catch the resultingNotSupportedException, so Scan crashed. Values likehttp://ornot a urlthrew an uncaughtUriFormatExceptionin the same way.$"{endpoint}/api/generate", so a trailing slash sent every describe request to//api/generate.Change
OllamaClient.NormalizeEndpoint:http://when the scheme is missing, and drops trailing slashes.nullunless the result is an absolutehttp/httpsURI with a host and no query or fragment.OllamaClient.GetBaseUri/GetGenerateUri: the base always ends in exactly one/, and request URLs are built withnew Uri(base, "api/generate"). A path prefix such ashttps://host/ollama/is kept.IsAvailableAsync: now also catchesArgumentException(which coversUriFormatException),NotSupportedExceptionandInvalidOperationException, and returnsfalse.Configure: saves the normalized value. An invalid entry prints a message and keeps the current endpoint.BaseVerb.Endpoint(-e/--endpointor the saved setting): normalized when valid. Settings saved before this change are fixed up as they are read.Scan: printsError: Invalid Ollama endpoint "…"and returns before the availability check.Tests
OllamaClientTests:localhost:11434,http://localhost:11434,http://localhost:11434/and a value with surrounding spaces and a double slash all map tohttp://localhost:11434/api/generate.http://,not a url,ftp://and query-string values.IsAvailableAsyncreturnsfalsefor invalid endpoints.ScanTests.ScanReportsAnInvalidEndpointInsteadOfCrashingruns Scan withnot a urland checks for the error message.With the source changes reverted,
ScanReportsAnInvalidEndpointInsteadOfCrashingand bothIsAvailableReturnsFalseForAnInvalidEndpointrows fail withUriFormatException. The URL-building tests don't compile without the new helpers. With the change, the full suite passes: 76 tests, 1 skipped as before because the root user can read every folder.dotnet format --verify-no-changesreports one JSON002 on the fake Ollama response string inScanTests.StartFakeOllama. That line is unchanged onmain.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kj95GdQsZpSCcND7LqacT1
Generated by Claude Code