Documentation
¶
Overview ¶
Package update checks whether a newer Caprock release exists and works out the command that would install it.
This is the ONE place in Caprock that talks to the network, and it is off until the user turns it on. Engineering rule 4 ("no outbound calls") is not bent quietly: the check is opt-in, asked for once, visible in the UI with the time of the last check, and revocable. The request carries no body, no identifiers, and no usage data — GitHub learns an IP asked for a release tag, which is what any `brew update` already tells it.
Caprock deliberately does NOT install the update itself. Upgrading means replacing the running binary, so the daemon would be killing the process executing the command — a race whose failure mode is a user left with no working Caprock. Running a package manager on the user's behalf from a web page is also exactly the surface a local tool should not open. Instead we name the exact command for how this copy was installed, and the user runs it.
The desktop app is the one exception, and it is the app, not this package: its own signed updater replaces the app bundle, which carries the daemon with it (ADR-042), on a click or — when the user chose Update automatically — once no agent is busy (GET /v1/update/busy). The daemon still never overwrites its own binary.
Index ¶
Constants ¶
const AppCask = "caprock-app"
AppCask is the Homebrew cask that installs the desktop app.
const FailRetry = 15 * time.Minute
FailRetry spaces the checks after a failed one.
const Interval = time.Hour
Interval is how often a release check is due: hourly, since releases ship several times a day. The daemon asks on a shorter tick (its updateTick) so a check due during sleep runs within minutes of waking.
const ReleasesPage = "https://github.com/dspv/caprock/releases/latest"
ReleasesPage is where a user without a package manager goes.
Variables ¶
var LatestURL = "https://api.github.com/repos/dspv/caprock/releases/latest"
LatestURL is the release endpoint. Overridable in tests.
Functions ¶
func InstallCommand ¶
func InstallCommand() string
InstallCommand returns the upgrade command for how this copy was installed, inferred from the executable's path. When we cannot tell, we say nothing rather than suggest a command that might do the wrong thing — an empty result means the UI offers the release page instead.
Types ¶
type Checker ¶
type Checker struct {
// Now is injectable for tests.
Now func() time.Time
// HTTPClient is injectable for tests.
HTTPClient *http.Client
// MinInterval throttles checks (default Interval, an hour). Releases
// ship several times a day, and the request is a conditional one
// (ETag): an unchanged answer is a 304 with no body, which GitHub does
// not count against the rate limit.
MinInterval time.Duration
// RetryAfter is how long a failed check waits before the next one that
// was not asked for (default FailRetry): a laptop offline for a day
// tries every quarter hour, not on every tick.
RetryAfter time.Duration
// CaskRoots are where Homebrew keeps installed casks; the app was
// installed by the cask when one of them holds caprock-app.
CaskRoots []string
// IsDir is os.Stat's view of a directory; injectable for tests.
IsDir func(string) bool
// contains filtered or unexported fields
}
Checker holds the cached result. It never checks on its own: the caller decides when, so "opt-in" is enforced at the call site as well as here.
type Status ¶
type Status struct {
// Enabled reports whether the user turned checking on.
Enabled bool `json:"enabled"`
// Current is the running version.
Current string `json:"current"`
// Latest is the newest published version, "" if never checked.
Latest string `json:"latest,omitempty"`
// UpdateAvailable is true only when Latest is genuinely newer than Current.
UpdateAvailable bool `json:"update_available"`
// Command is how to install it, given how this copy was installed.
Command string `json:"command,omitempty"`
// AppCommand is how to upgrade the desktop app, when Homebrew's cask
// installed it on this machine (F12). Set beside Command, not instead of
// it: the cask and the caprock formula are upgraded separately.
AppCommand string `json:"app_command,omitempty"`
// URL is the release page, always safe to offer.
URL string `json:"url,omitempty"`
// CheckedAt is the last successful check (unix ms), 0 if never.
CheckedAt int64 `json:"checked_at,omitempty"`
// Error is the last failure, if any. A failed check is never fatal.
Error string `json:"error,omitempty"`
// Notes is the published release's own description of what changed, as
// written on GitHub. It arrives in the same response as the tag — asking
// for the version and then asking again for the notes would be a second
// request for something we already had.
Notes string `json:"notes,omitempty"`
// NotesFor is the version Notes describes. Without it a stale note could
// be shown beside a different version after a failed check.
NotesFor string `json:"notes_for,omitempty"`
}
Status is what the UI renders.