Repository navigation
fix: toolchain error handling, binary naming, and platform detection - #2027
Conversation
Add .exe handling to buildHTTPAssetURL() for HTTP type tools (like kubectl from dl.k8s.io) to match existing behavior in buildGitHubReleaseURL(). This fixes HTTP 404 errors on Windows when downloading raw binaries. Added comprehensive test fixture in tests/fixtures/scenarios/windows-test/ with .tool-versions, .atmos.d custom commands, and Terraform components for Windows testing. Related: #2002, #2012 Co-Authored-By: Claude Opus 4.5 <[email protected]>
…ion, add test fixtures and tests
|
Warning This PR exceeds the recommended limit of 1,000 lines.Large PRs are difficult to review and may be rejected due to their size. Please verify that this PR does not address multiple issues. |
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2027 +/- ##
==========================================
+ Coverage 75.39% 75.44% +0.05%
==========================================
Files 792 793 +1
Lines 73513 73666 +153
==========================================
+ Hits 55427 55580 +153
- Misses 14575 14578 +3
+ Partials 3511 3508 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughAdds platform-aware tool installation: pre-flight platform checks, platform-aware error messages/hints, Aqua package binary-name resolution for multi-segment names, enhanced 404/download error construction with OS/arch context, Windows .exe handling for HTTP binaries, and stdout suppression during markdown rendering. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Installer as Installer
participant Registry as Registry
participant Platform as PlatformCheck
participant ErrorBuilder as ErrorBuilder
Client->>Installer: installFromTool(tool)
Installer->>Registry: read tool metadata (SupportedEnvs, Name)
Installer->>Platform: CheckPlatformSupport(tool)
Platform->>Platform: getOS/getArch, isPlatformMatch()
alt platform matches
Platform-->>Installer: nil
Installer->>Installer: BuildAssetURL, BuildAssetPath
Installer->>Client: download/install binary
else platform unsupported
Platform->>ErrorBuilder: buildPlatformHints()
ErrorBuilder-->>Platform: hints
Platform-->>Installer: PlatformError (with hints)
Installer-->>Client: formatted platform-not-supported error (WSL/Rosetta/Docker/qemu hints)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@pkg/ui/markdown/custom_renderer.go`:
- Around line 205-221: The Render method currently mutates process-wide
os.Stdout (oldStdout, devNull) which is racy under concurrent use; protect the
swap by introducing a package-level sync.Mutex (e.g., stdoutMutex) and lock it
around opening /dev/null, replacing os.Stdout, and restoring it in the defer to
serialize swaps, and open /dev/null with os.OpenFile(os.DevNull, os.O_WRONLY, 0)
instead of os.Open so it is write-only; ensure the defer both restores os.Stdout
and closes devNull and preserve existing err handling around the open.
In
`@tests/fixtures/scenarios/complete/components/terraform/infra/vpc-flow-logs-bucket/README.md`:
- Line 94: The markdown list item "*
[cloudposse/terraform-aws-components](https://github.com/cloudposse/terraform-aws-components/tree/master/modules/vpc-flow-logs-bucket)
- Cloud Posse's upstream component" is indented by two spaces causing MD007
failures; remove the two leading spaces so the list marker starts at column zero
(i.e., make the line a top-level list item in README.md) to satisfy
markdownlint.
In `@toolchain/installer/asset_test.go`:
- Around line 701-708: The test hardcodes the Windows architecture
("windows/amd64") when asserting the expected URL, which will fail on non-amd64
machines; update the Windows branch to build the expected URL using
runtime.GOARCH (e.g., construct expected :=
"https://dl.k8s.io/v1.31.4/bin/windows/" + runtime.GOARCH + "/kubectl.exe") and
assert url == expected while keeping the .exe suffix check; modify the assertion
that currently references the literal
"https://dl.k8s.io/v1.31.4/bin/windows/amd64/kubectl.exe" to use the
runtime.GOARCH-based expected value instead.
🧹 Nitpick comments (6)
toolchain/registry/aqua/aqua.go (1)
434-461: Consider extracting binary name resolution helper.The 3-step fallback logic (lines 439-445) duplicates the pattern in
resolveVersionOverrides(lines 269-275). A shared helper would reduce duplication.Suggested helper
// resolveBinaryName determines the binary name using Aqua's resolution order. func resolveBinaryName(binaryName, packageName, repoName string) string { if binaryName != "" { return binaryName } if name := extractBinaryNameFromPackageName(packageName); name != "" { return name } return repoName }toolchain/installer/download.go (1)
202-214: Potential duplication withbuildPlatformHintsin platform.go.This function and
buildPlatformHintsinplatform.goboth generate platform-specific hints but with slightly different coverage. Consider consolidating to a single source of truth to avoid drift. For now, this is acceptable since the contexts differ (post-404 vs pre-flight check).toolchain/installer/platform_test.go (2)
137-148: Preferstrings.Containsover custom substring search.This custom implementation is overly complex and reimplements stdlib functionality.
♻️ Suggested simplification
-func contains(s, substr string) bool { - return len(s) > 0 && len(substr) > 0 && (s == substr || len(s) > len(substr) && (s[:len(substr)] == substr || s[len(s)-len(substr):] == substr || findSubstring(s, substr))) -} - -func findSubstring(s, substr string) bool { - for i := 0; i <= len(s)-len(substr); i++ { - if s[i:i+len(substr)] == substr { - return true - } - } - return false -} +func contains(s, substr string) bool { + return strings.Contains(s, substr) +}You'll need to add
"strings"to imports.
102-110: Redundant condition in hint search loop.The check
assert.NotEmpty(t, hint) && len(hint) > 0is redundant—len(hint) > 0already covers non-empty.♻️ Simplified loop
- for _, hint := range hints { - if assert.NotEmpty(t, hint) && len(hint) > 0 { - if contains(hint, "WSL") { - foundWSL = true - } - } - } + for _, hint := range hints { + if contains(hint, "WSL") { + foundWSL = true + } + }tests/toolchain_aqua_tools_test.go (1)
149-163: Consider extracting version constants for maintainability.Tool versions like
"1.31.4"and"0.17.0"appear multiple times. Extracting to constants at the top of the file would make updates easier and reduce risk of inconsistency.toolchain/installer/platform.go (1)
20-25: Consider removing perf.Track from Error() method.The
Error()method may be called multiple times (e.g., during logging, error wrapping, display). Performance tracking here adds overhead with limited diagnostic value. Reserveperf.Trackfor heavier operations.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@docs/fixes/toolchain-error-handling-and-binary-naming.md`:
- Line 682: The markdown contains a bare URL in the table cell
("https://github.com/replicatedhq/replicated"); update that cell so the URL is
wrapped in angle brackets (<https://github.com/replicatedhq/replicated>) to
satisfy static analysis and proper Markdown linking—edit the table row where the
GitHub repo URL appears and replace the plain URL with the angle-bracketed form.
🧹 Nitpick comments (1)
toolchain/installer/platform.go (1)
87-103: Consider hoisting the known architectures map to package level.The map is allocated on each call. For the typical small
supported_envslists, this isn't a performance concern, but a package-level var would be cleaner.♻️ Optional refactor
+// knownArchs contains Go's architecture identifiers. +var knownArchs = map[string]bool{ + "amd64": true, "arm64": true, "386": true, "arm": true, + "ppc64": true, "ppc64le": true, "mips": true, "mipsle": true, + "mips64": true, "s390x": true, "riscv64": true, +} + // isKnownArch returns true if the string is a known Go architecture name. func isKnownArch(s string) bool { - knownArchs := map[string]bool{ - "amd64": true, - "arm64": true, - "386": true, - "arm": true, - "ppc64": true, - "ppc64le": true, - "mips": true, - "mipsle": true, - "mips64": true, - "s390x": true, - "riscv64": true, - } return knownArchs[s] }
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@docs/fixes/toolchain-error-handling-and-binary-naming.md`:
- Around line 46-47: Update the documentation text to refer to the portable
os.DevNull constant instead of the platform-specific path "/dev/null": in the
discussion of glamour rendering (see pkg/ui/markdown/custom_renderer.go and the
glamor/glamour rendering section), change the wording from “redirect stdout to
`/dev/null`” to “redirect stdout to os.DevNull” so the doc matches the
implementation and is correct on Windows.
|
These changes were released in v1.204.1-rc.6. |
what
kubectlinstead ofkubernetes(extracts binary name from last segment of Aqua package name likekubernetes/kubernetes/kubectl) viaresolveBinaryNamehelpersupported_envsfrom Aqua registry before attempting download, providing immediate feedback instead of waiting for HTTP 404supported_envsentries likeamd64which mean "any OS with this architecture" (fixes helm/helm on Windows which uses["darwin", "linux", "amd64"])replicatedhq/replicatedwhich exists on GitHub but is not in Aqua registry)why
kubectlbinary nameamd64insupported_envswas treated as an OS name instead of architecturereferences
supported_envsfield for platform detectiontests/fixtures/scenarios/toolchain-aqua-tools/docs/fixes/toolchain-error-handling-and-binary-naming.mdFiles Changed
errors/errors.go,toolchain/installer/download.gotoolchain/installer/platform.go,toolchain/installer/platform_test.gotoolchain/registry/registry.go,toolchain/registry/aqua/aqua.gopkg/ui/markdown/custom_renderer.gotests/toolchain_aqua_tools_test.go,toolchain/installer/download_test.gotests/fixtures/scenarios/toolchain-aqua-tools/Platform Matching Logic
The
isPlatformMatchfunction handles three Aqua registrysupported_envsformats:darwindarwin/amd64amd64This correctly handles entries like helm's
["darwin", "linux", "amd64"]whereamd64means "Windows amd64 is supported".Test Coverage
TestToolchainAquaTools_KubectlBinaryNamingkubectlNOTkubernetesTestToolchainAquaTools_InstallAllToolsTestToolchainAquaTools_WindowsKotsPlatformErrorTestToolchainAquaTools_NonExistentToolErrorTestIsPlatformMatchTestIsKnownArchTestBuildPlatformNotSupportedErrorTestFormatPlatformErrorSummary by CodeRabbit
New Features
Bug Fixes
Tests
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.