Feature: Implement Self-Update Feature with Comprehensive Testing and Documentation - #10
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements a comprehensive self-update feature for the flac-converter CLI tool, allowing automatic updates from GitHub releases with cross-platform support. The implementation includes robust error handling, comprehensive testing with HTTP mocking, and enhanced documentation.
- Adds
--self-updateflag with platform-specific binary downloads and safe replacement - Implements comprehensive testing with HTTP client mocking for offline, deterministic tests
- Replaces shell script prototype with Go implementation and adds detailed development documentation
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| main.go | Implements self-update functionality with GitHub API integration, version comparison, and binary replacement logic |
| main_test.go | Adds extensive test coverage with HTTP mocking, including edge cases and error scenarios |
| flac-converter.sh | Removes shell script prototype in favor of Go implementation |
| README.md | Updates documentation with self-update usage and references development guide |
| Development.md | Adds comprehensive development guide covering versioning, testing, and build processes |
Comments suppressed due to low confidence (1)
main_test.go:1
- The magic number
4(length of '.zip') should be replaced with a named constant or usestrings.TrimSuffix(filename, '.zip')for better readability and maintainability.
package main
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ardakilic
added a commit
that referenced
this pull request
Sep 8, 2025
… Documentation (#10) * wip: self-update feature * chore: mock http client * chore: fix unit tests * Update main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> add more ignore patterns for flac-converter binary
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.
🎯 Overview
This PR implements a robust self-update feature for the
flac-converterCLI tool, allowing users to automatically check for and apply updates from GitHub releases. The feature includes cross-platform binary downloads (tar.gz for Unix, zip for Windows), safe replacement with backups, comprehensive error handling (including GitHub API rate limiting), and transparent URL display in error messages.Key improvements include:
*http.Clientfor full testabilityThe self-update is triggered via
--self-updateflag and handles dev versions gracefully (skips updates).📝 Changes Summary
New Features
--self-updateflag to check GitHub releases, download platform-specific binaries, extract, and replace the running binary with backup/rollback on failure.-ldflags="-X main.version=vX.Y.Z"orgit describe.runtime.GOOS/GOARCHfor correct asset downloads (e.g.,flac-converter-linux-amd64.tar.gz).install.sh..old, restores on failure, sets executable permissions.Testing Improvements
selfUpdate(*http.Client)for dependency injection; tests usemockTransportto simulate responses (200 OK with JSON, 403 Forbidden, 500, invalid JSON, network errors).stdoutto verify printed messages (e.g., "Checking for updates from: [URL]", "HTTP 403 (Forbidden)", rate limiting guidance).Documentation Enhancements
Development.md: Comprehensive guide covering:README.md:--self-updateflag and usage example.Development.md.Other Changes
flac-converter.sh: Replaced by the Go binary implementation (shell script was a prototype).flac-converter.oldcreated during self-update testing (can be ignored/deleted).🔍 Git Diff Highlights (from
mainbranch)Full diff: See the commit history or run
git diff main -- .for details.🧪 Testing
All tests pass with 100% offline mocking:
Key test outputs verified:
Manual testing:
go build -ldflags="-X main.version=v1.2.3" -o flac-converter ../flac-converter --self-updatehandles 403 gracefully (as shown in conversation history).📱 Screenshots/Examples
Self-Update Output (Simulated 403 Rate Limiting)
Up-to-Date Message
🚀 How to Review/Test
git checkout [branch]go mod tidygo test -v ./...golangci-lint runandgo fmt ./...Development.mdand updatedREADME.md🔗 Related Issues
📝 Checklist
Ready for merge! 🚀
GitHub PR Title Suggestion:
feat: Implement self-update with HTTP client mocking, enhanced testing & documentationGitHub PR Description: (Paste the content of this PR.md file)