go-update/CLAUDE.md
Snider 0efc1ebc80 fix(dx): audit error handling, file I/O, and test coverage
- Create CLAUDE.md with package-specific conventions and commands
- Replace fmt.Errorf with coreerr.E() in test mock (updater_test.go)
- Replace os.ReadFile/os.WriteFile with go-io in build/main.go
- Add unit tests for filterReleases, determineChannel, GetDownloadURL,
  formatVersionForDisplay, formatVersionForComparison, and default
  cases in startGitHubCheck/startHTTPCheck
- All targeted functions now at 100% coverage

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 08:53:58 +00:00

2.1 KiB

CLAUDE.md — go-update

This file provides guidance to Claude Code when working with the go-update package.

Package Overview

go-update (forge.lthn.ai/core/go-update) is a self-updater library for Go applications. It supports updates from GitHub releases and generic HTTP endpoints, with configurable startup behaviour and version channel filtering.

Build & Test Commands

# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run a single test
go test -run TestName ./...

# Generate version.go from package.json
go generate ./...

# Vet and lint
go vet ./...

Architecture

Update Sources

Source Description
GitHub Releases Fetches releases via GitHub API, filters by channel (stable/beta/alpha)
Generic HTTP Fetches latest.json from a base URL with version + download URL

Key Types

  • UpdateService — Configured service that checks for updates on startup
  • GithubClient — Interface for GitHub API interactions (mockable for tests)
  • Release / ReleaseAsset — GitHub release model
  • GenericUpdateInfo — HTTP update endpoint model

Testable Function Variables

Core update logic is exposed as var function values so tests can replace them:

  • NewGithubClient — Factory for GitHub client (replace with mock)
  • DoUpdate — Performs the actual binary update
  • CheckForNewerVersion, CheckForUpdates, CheckOnly — GitHub update flow
  • CheckForUpdatesHTTP, CheckOnlyHTTP — HTTP update flow
  • NewAuthenticatedClient — HTTP client factory (supports GITHUB_TOKEN)

Error Handling

All errors must use coreerr.E() from forge.lthn.ai/core/go-log:

import coreerr "forge.lthn.ai/core/go-log"

return coreerr.E("FunctionName", "what failed", underlyingErr)

Never use fmt.Errorf or errors.New.

File I/O

Use forge.lthn.ai/core/go-io for file operations, not os.ReadFile/os.WriteFile.

Coding Standards

  • UK English in comments and strings
  • Strict types: All parameters and return types
  • Test naming: _Good, _Bad, _Ugly suffix pattern
  • License: EUPL-1.2