mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
feat(cli): say at a launch in a terminal when a newer devvm release is out
A launch in a terminal checks at most once a day for devvm's newest release, with upgrade's Source.Check in the background (5 s at most, the launch waiting at most 1 s more once it's done), and records what it found in the data folder's cache/release.json (latest, checked, tried; an offline try keeps what was known, silently). The next launch says upgrade_available in one line when that release is newer. Nothing without a terminal, with --no-input, for a source build or for a copy neither install.sh nor Homebrew installed. Off with config.toml's release-check = false or DEVVM_NO_RELEASE_CHECK=1. devvm doctor shows the newest release known (doctor_latest_release, --json's release). - upgrade: Known, ReadKnown, Due, Newer, Source.Refresh - settings: ReleaseCheck, KeyReleaseCheck (strict bool) - paths: Dirs.ReleaseCheck (Dirs' limit 58) - cli: releaseNotice in up; doctor's Release - tests: release_notice.txtar, TestKnown, TestRefresh, TestReleaseCheck; the CLI tests set DEVVM_NO_RELEASE_CHECK=1 by default - docs: settings (the release check), install, troubleshooting Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
19 files changed
+477
-11
No files matched your search
@@ -138,7 +138,7 @@ An owner gets a check only when a second copy would be a bug or a security hole,
|
||||
| the structure test's `owners`, `paths.Dirs.AgentSettings` and `paths.Dirs.AgentLogins` | devvm's agent store: `agentStore` in `internal/vm/agents.go` for the agents' settings, which the mounts, the setup's copies, a remake's home and `devvm agent import` take, and `secrets.LoginFile` in `internal/secrets/secrets.go` for their logins, which the setup's copies and the proxy read, so nothing reads an agent's files from the home folder but `vm.AgentImport` | `internal/paths`, and tests |
|
||||
| the structure test's `owners`, paths in devvm's folders | `internal/paths`, whose `Dirs` and `VM` name every file and folder devvm keeps, so the layout, its golden listing in `testdata/script/layout.txtar` and a VM's teardown miss none. A `filepath.Join` onto a `Data` or `Config` field fails, and so does an `os.MkdirTemp` or `os.CreateTemp` there whose name is a literal; a name from `paths`, such as `paths.ToolsBuildPrefix`, passes | tests |
|
||||
|
||||
forbidigo matches only the function a call names, so the checks that look at a call's arguments are in the [structure test](#the-structure-test). It finds a host command in an `exec.Command` or `exec.CommandContext` call that names it, as a literal or as a constant, whatever name the file imports `os/exec` under. It finds a `DEVVM_` variable in a call to any function or field named `Getenv` or `LookupEnv`, in any case, so `t.Getenv` and a `getenv` parameter count as well as `os.Getenv`, and it finds `HOME` the same way. The settings `envSettings` lists are the ones users set, `DEVVM_NO_TOOL_CHECK`, `DEVVM_LIMA_HOME`, `DEVVM_SECRET_SERVICE` and `DEVVM_FROM`; names mode, `DEVVM_MESSAGES`, which any build has; and the variables devvm sets for its own processes, `DEVVM_GUESTFWD` for `devvm _qemu` and `DEVVM_DAEMON_STATUS` for each background process `internal/daemon` starts.
|
||||
forbidigo matches only the function a call names, so the checks that look at a call's arguments are in the [structure test](#the-structure-test). It finds a host command in an `exec.Command` or `exec.CommandContext` call that names it, as a literal or as a constant, whatever name the file imports `os/exec` under. It finds a `DEVVM_` variable in a call to any function or field named `Getenv` or `LookupEnv`, in any case, so `t.Getenv` and a `getenv` parameter count as well as `os.Getenv`, and it finds `HOME` the same way. The settings `envSettings` lists are the ones users set, `DEVVM_NO_TOOL_CHECK`, `DEVVM_NO_RELEASE_CHECK`, `DEVVM_LIMA_HOME`, `DEVVM_SECRET_SERVICE` and `DEVVM_FROM`; names mode, `DEVVM_MESSAGES`, which any build has; and the variables devvm sets for its own processes, `DEVVM_GUESTFWD` for `devvm _qemu` and `DEVVM_DAEMON_STATUS` for each background process `internal/daemon` starts.
|
||||
|
||||
The structure test also finds a copy of an owner's code by its text, in `literals`. A string literal outside tests that holds `'\''`, the escaped quote a shell quoter writes, belongs in `internal/shell`, and one that holds `[0-9a-f]{14}`, the hash at the end of a project VM's name, belongs in `internal/vmname`. A quote written as a rune, such as `'\''` in Go, isn't a string literal, so it doesn't count. In the same way, `separators` finds a copy of a parser by what it splits on: a call to any function of package `strings` with `+` as an argument, as a literal or as a constant, splits or joins an image's layers, so it belongs in `internal/image`. A call with another argument that holds a `+`, such as `strings.ContainsAny(arg, "+,")`, doesn't count.
|
||||
|
||||
|
||||
@@ -88,6 +88,8 @@ devvm upgrade
|
||||
|
||||
It says which release it will install in place of the devvm you have, and asks first. `devvm upgrade --force` installs it without asking, which devvm needs without a terminal or with `--no-input`, and `devvm upgrade --check` says whether a newer release is out and installs nothing.
|
||||
|
||||
You don't have to remember to check. When you run devvm in a terminal, it checks at most once a day for a newer release without making you wait, and when one is out it says so in one line that names devvm upgrade. It never upgrades on its own, and `release-check = false` in `config.toml` or `DEVVM_NO_RELEASE_CHECK=1` turns the check off ([the release check](../using/settings.md#the-release-check)).
|
||||
|
||||
You can also upgrade devvm without devvm upgrade, with the command for the way you installed it:
|
||||
|
||||
{{< os-tabs >}}
|
||||
|
||||
@@ -24,7 +24,7 @@ Upgrading devvm keeps this folder as it is. Back it up, such as in a dotfiles re
|
||||
|
||||
## config.toml
|
||||
|
||||
`~/.config/devvm/config.toml` sets the defaults that new VMs get, the retention settings, the company proxy and an Ubuntu mirror, in a file you write by hand. devvm reads it and never writes it. Every key is optional, and devvm has no `config.toml` until you write one. This example sets every key:
|
||||
`~/.config/devvm/config.toml` sets the defaults that new VMs get, the retention settings, the company proxy, an Ubuntu mirror and the release check, in a file you write by hand. devvm reads it and never writes it. Every key is optional, and devvm has no `config.toml` until you write one. This example sets every key:
|
||||
|
||||
```toml
|
||||
# The network tier new VMs get: open, internet, allowlist or none.
|
||||
@@ -45,6 +45,9 @@ layers = ["docker"]
|
||||
# A mirror of Ubuntu's archive that base's first build tries first.
|
||||
ubuntu-mirror = "http://mirror.example.com/ubuntu-ports"
|
||||
|
||||
# Whether a launch checks once a day for a newer devvm release.
|
||||
release-check = true
|
||||
|
||||
# New VMs' CPUs, and their memory and disk in GiB.
|
||||
[size]
|
||||
cpus = 4
|
||||
@@ -77,6 +80,12 @@ The `[proxy]` table is the [company proxy](../safety/network.md#behind-a-company
|
||||
|
||||
A mirror can't give base a package that Ubuntu didn't publish. apt checks every list and package against Ubuntu's archive key whichever server sends it, and refuses one that doesn't match, and devvm checks them against that key again on this machine before it keeps any package. A mirror that's behind, or one that's lying, can still serve lists older than Ubuntu's, because Ubuntu's signed lists don't expire. devvm refuses lists more than a day older than the Ubuntu cloud image base starts from, and it names the mirror and keeps none of the build's packages ([old package lists](troubleshooting.md#base-gets-old-package-lists)). devvm compares the lists with the cloud image's date, not with today's, so a mirror that fell behind after that date can still give base packages older than Ubuntu's, and you should only set a mirror you trust to keep up. Only the first build of each base uses the mirror, because a later build of the same base installs the packages devvm kept from that first build ([base](images.md#base)). VMs don't use it, and neither do layers or a `--from` base. No command saves it, so it's only ever in `config.toml`.
|
||||
|
||||
### The release check
|
||||
|
||||
When you run devvm in a terminal, it checks at most once a day for a newer devvm release, and when one is out it says so in one line before it opens the VM, naming the release, the version you have and devvm upgrade. devvm never installs anything on its own, so you upgrade with [devvm upgrade](../getting-started/install.md#upgrading) when you choose to. `release-check = false` turns the check off, and so does setting `DEVVM_NO_RELEASE_CHECK=1` in the environment, as CI can. `release-check` must be `true` or `false`, and devvm refuses anything else (`config.toml` names the line). No command saves it, so it's only ever in `config.toml`.
|
||||
|
||||
The check reads only where GitHub's latest devvm release is, over HTTPS, and sends nothing about you or your machine. It runs beside the launch, so it never makes devvm wait, and when you're offline it says nothing and tries again the next day. The line comes from what the last check found, so a release that came out since then shows up at the launch after the next check. devvm keeps what the check found in `~/.local/share/devvm/cache/release.json`, and `devvm doctor` shows it. devvm says nothing without a terminal, with `--no-input`, for a devvm built from its source, or for a copy that neither the install script nor Homebrew installed, which devvm upgrade can't upgrade.
|
||||
|
||||
### Where a default comes from
|
||||
|
||||
For each default, devvm uses the first of these that sets it:
|
||||
@@ -256,5 +265,6 @@ devvm decides for standard output and standard error apart, and colors one only
|
||||
| `DEVVM_LIMA_HOME` | move devvm's own Lima home ([details](../internals/lima.md#a-lima-home-of-its-own)) |
|
||||
| `DEVVM_FROM` | the container image that the base of new VMs and builds starts from when there's no `--from` ([details](from.md)) |
|
||||
| `DEVVM_NO_TOOL_CHECK=1` | don't check for newer shared tools once a day ([details](images.md#shared-tools)) |
|
||||
| `DEVVM_NO_RELEASE_CHECK=1` | don't check for a newer devvm release once a day ([details](#the-release-check)) |
|
||||
| `DEVVM_SECRET_SERVICE` | the Keychain service devvm saves and reads secrets in, instead of `devvm` ([details](../safety/network.md#saving-and-binding-secrets)) |
|
||||
| `CLAUDE_CODE_OAUTH_TOKEN` | the Claude Code token that VMs get, over the saved Claude Code login, whichever it is ([details](coding-agents.md#claude-code-login)) |
|
||||
@@ -95,6 +95,12 @@ When devvm can't read one of its settings or state files, it names the file, and
|
||||
|
||||
A VM's own state file, `vm.json` in its folder in `vms/`, is the one to fix rather than delete, because it's what devvm knows of that VM. While devvm can't read it, every command on that VM fails, and the commands that read every VM leave that VM out and carry on with the rest. `devvm ls` warns and lists the VM with its name and status alone, when its backend has it, and `devvm gc --orphans` never forgets it. devvm doesn't know which shared tools such a VM uses or which folders it mounts, so `devvm space`, `devvm images` and `devvm gc` fail and name the file. devvm also refuses to add a key to its own SSH agent, or to load one into it as a VM starts, because it can't tell whether that VM mounts the key's folder.
|
||||
|
||||
## devvm says a newer release is out
|
||||
|
||||
When you run devvm in a terminal and a newer release is out, devvm says so in one line before it opens the VM, and it opens the VM as usual. Run `devvm upgrade` to install the release, or carry on with the devvm you have, because devvm never upgrades on its own. The line comes from devvm's daily check, and `devvm doctor` shows the newest release that check found and the day it found it. When you'd rather not see the line, set `release-check = false` in `config.toml`, or `DEVVM_NO_RELEASE_CHECK=1` in the environment ([the release check](settings.md#the-release-check)).
|
||||
|
||||
When devvm never says it, even though a newer release is out, the check may not have run yet, because it runs once a day and the line comes from what it found the time before. It also doesn't run while you're offline, without a terminal, with `--no-input`, for a devvm built from its source, or for a copy that neither the install script nor Homebrew installed. `devvm upgrade --check` asks GitHub at once.
|
||||
|
||||
## A newer devvm changed devvm's folders
|
||||
|
||||
devvm's data folder, `~/.local/share/devvm`, and its settings folder, `~/.config/devvm`, each record their layout version in a file named `version`, which says how devvm keeps its files there, and devvm checks both before each command. When either one has a newer version than this devvm's, a newer devvm has changed the folders, so this one refuses to run rather than misread them, and it names the file and both versions. Run the newer devvm, or upgrade this one to it, for example after going back to an older version by mistake. `devvm --version`, help and completion still run. An older version is never refused, because devvm changes the folders to its own layout before the command runs, and a folder without a `version` file gets this devvm's ([the layout version](../internals/overview.md#the-layout-version)).
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
"github.com/w3cj/devvm/internal/state"
|
||||
"github.com/w3cj/devvm/internal/trust"
|
||||
"github.com/w3cj/devvm/internal/ui"
|
||||
"github.com/w3cj/devvm/internal/upgrade"
|
||||
"github.com/w3cj/devvm/internal/vm"
|
||||
)
|
||||
|
||||
@@ -60,6 +62,13 @@ func newDoctorCmd(a *app) *cobra.Command {
|
||||
}
|
||||
return state.VMFolderProblems(dirs)
|
||||
},
|
||||
Release: func() upgrade.Known {
|
||||
dirs, err := a.dirs()
|
||||
if err != nil {
|
||||
return upgrade.Known{}
|
||||
}
|
||||
return upgrade.ReadKnown(dirs.ReleaseCheck())
|
||||
},
|
||||
}
|
||||
if asJSON {
|
||||
return printJSON(u, d.report(cmd.Context(), u.Text, reg.All(), b))
|
||||
@@ -82,6 +91,16 @@ type doctorOutput struct {
|
||||
// Features is, for each backend, how it has each feature: native,
|
||||
// emulated, unreviewed or none.
|
||||
Features map[string]map[string]string `json:"features"`
|
||||
// Release is the newest release the daily check found, and when;
|
||||
// null before it found one.
|
||||
Release *releaseJSON `json:"release"`
|
||||
}
|
||||
|
||||
// releaseJSON is the newest devvm release a launch's daily check found,
|
||||
// and when, in RFC 3339.
|
||||
type releaseJSON struct {
|
||||
Latest string `json:"latest"`
|
||||
Checked string `json:"checked"`
|
||||
}
|
||||
|
||||
// problemJSON is something the backend is missing: its key, the command
|
||||
@@ -118,6 +137,9 @@ func (d doctor) report(ctx context.Context, text func(msg.M) string, all []backe
|
||||
}
|
||||
out.Features[be.Name()] = fs
|
||||
}
|
||||
if k := d.known(); k.Latest != "" {
|
||||
out.Release = &releaseJSON{Latest: k.Latest, Checked: k.Checked.UTC().Format(time.RFC3339)}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -162,6 +184,17 @@ type doctor struct {
|
||||
// Folders are the warnings for what in the VMs' folder isn't a VM's
|
||||
// (state.VMFolderProblems); nil for none.
|
||||
Folders func() []msg.M
|
||||
// Release is what the daily release check last found
|
||||
// (upgrade.ReadKnown); nil for nothing.
|
||||
Release func() upgrade.Known
|
||||
}
|
||||
|
||||
// known is what the daily release check last found, if anything.
|
||||
func (d doctor) known() upgrade.Known {
|
||||
if d.Release == nil {
|
||||
return upgrade.Known{}
|
||||
}
|
||||
return d.Release()
|
||||
}
|
||||
|
||||
// run checks b, the backend new VMs get, and lists its features. It
|
||||
@@ -182,6 +215,9 @@ func (d doctor) run(ctx context.Context, u *ui.UI, b backend.Backend) error {
|
||||
for _, m := range d.warnings(b) {
|
||||
u.Warn(m)
|
||||
}
|
||||
if k := d.known(); k.Latest != "" {
|
||||
u.Say(msg.DoctorLatestRelease(k.Checked.Local().Format(time.DateOnly), k.Latest))
|
||||
}
|
||||
if len(problems) == 0 {
|
||||
u.Say(msg.DoctorOK(b.Name(), devvmVersion()))
|
||||
return nil
|
||||
|
||||
@@ -72,10 +72,11 @@ func machineShapes() []shapeCase {
|
||||
doctorOutput{
|
||||
Backend: "lima", Problems: []problemJSON{{Key: "lima", Fix: &fix, Message: "m"}, {Key: "kvm", Message: "m"}},
|
||||
Warnings: []string{"w"}, Docker: yes, Features: map[string]map[string]string{"lima": {"ssh": "native"}},
|
||||
Release: &releaseJSON{Latest: "0.2.0", Checked: "2026-11-05T00:00:00Z"},
|
||||
},
|
||||
[]string{
|
||||
"backend: string", "docker: bool", "features.lima.ssh: string", "problems[].fix: string", "problems[].key: string",
|
||||
"problems[].message: string", "warnings[]: string",
|
||||
"problems[].message: string", "release.checked: string", "release.latest: string", "warnings[]: string",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/w3cj/devvm/internal/msg"
|
||||
"github.com/w3cj/devvm/internal/settings"
|
||||
"github.com/w3cj/devvm/internal/upgrade"
|
||||
)
|
||||
|
||||
// releaseWait is how long a launch waits, once it's done, for the daily
|
||||
// check it started to finish, so the next launch knows what it found.
|
||||
const releaseWait = time.Second
|
||||
|
||||
// releaseNotice says, at a launch in a terminal, that a newer release is
|
||||
// out, from the daily check's record, and starts the check beside the
|
||||
// launch when it's due. It never asks and never blocks the launch: the
|
||||
// check runs in the background, and the function it returns, which the
|
||||
// launch calls once it's done, waits at most releaseWait for it. Nothing
|
||||
// without a terminal or with --no-input (the UI's CanPick), with the
|
||||
// check off (settings.ReleaseCheck), for a build from the source, or for
|
||||
// a devvm neither install.sh nor Homebrew installed, which devvm upgrade
|
||||
// can't upgrade.
|
||||
func releaseNotice(ctx context.Context, a *app) (wait func()) {
|
||||
none := func() {}
|
||||
if !a.u.CanPick() {
|
||||
return none
|
||||
}
|
||||
d, err := a.dirs()
|
||||
if err != nil {
|
||||
return none
|
||||
}
|
||||
if on, err := settings.ReleaseCheck(d, os.Getenv); err != nil || !on {
|
||||
return none
|
||||
}
|
||||
up, err := a.upgrader()
|
||||
if err != nil || up.Install.Kind == upgrade.Other || !upgrade.Valid(up.Current) {
|
||||
return none
|
||||
}
|
||||
path := d.ReleaseCheck()
|
||||
known := upgrade.ReadKnown(path)
|
||||
if known.Newer(up.Current) {
|
||||
a.u.Info(msg.UpgradeAvailable(up.Current, known.Latest))
|
||||
}
|
||||
now := time.Now()
|
||||
if !known.Due(now) {
|
||||
return none
|
||||
}
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
_ = up.Source.Refresh(ctx, path, now) // offline is silent: the next day tries again
|
||||
}()
|
||||
return func() {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(releaseWait):
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,6 +215,9 @@ func sandbox(env *testscript.Env, bin, stubs string) error {
|
||||
}
|
||||
env.Setenv("DEVVM_KVM", kvm)
|
||||
env.Setenv("DEVVM_SECRET_SERVICE", "devvm-test")
|
||||
// No launch asks GitHub for devvm's newest release: a script that
|
||||
// tests the check unsets it and serves its own (release_server).
|
||||
env.Setenv("DEVVM_NO_RELEASE_CHECK", "1")
|
||||
// A large host, whatever runs the tests: a script that tests a small
|
||||
// one sets its own.
|
||||
for name, v := range fakeHost() {
|
||||
|
||||
@@ -70,6 +70,7 @@ func (uf *upFlags) options() vm.Options {
|
||||
// up opens a shell in this folder's VM, making it first.
|
||||
func up(ctx context.Context, a *app, uf *upFlags) error {
|
||||
o := uf.options()
|
||||
defer releaseNotice(ctx, a)()
|
||||
return a.env(func(env *vm.Env) error {
|
||||
env.AddInclude = uf.sshConfig
|
||||
return vm.Launch{Env: env}.Up(ctx, o)
|
||||
|
||||
@@ -1079,6 +1079,11 @@ func DoctorFailed(reason string) M {
|
||||
return M{id: "doctor_failed", vals: []val{{"reason", reason}}}
|
||||
}
|
||||
|
||||
// DoctorLatestRelease is [doctor_latest_release]: "The newest devvm release is {{.latest}}, as of {{.date}}."
|
||||
func DoctorLatestRelease(date string, latest string) M {
|
||||
return M{id: "doctor_latest_release", vals: []val{{"date", date}, {"latest", latest}}}
|
||||
}
|
||||
|
||||
// DoctorOK is [doctor_ok]: "This is devvm {{.version}}, and the {{.backend}} backend has everything it needs."
|
||||
func DoctorOK(backend string, version string) M {
|
||||
return M{id: "doctor_ok", vals: []val{{"backend", backend}, {"version", version}}}
|
||||
@@ -4086,6 +4091,7 @@ var specs = map[string]spec{
|
||||
"docker_missing": {},
|
||||
"docker_only": {fields: []string{"from"}},
|
||||
"doctor_failed": {fields: []string{"reason"}},
|
||||
"doctor_latest_release": {fields: []string{"date", "latest"}},
|
||||
"doctor_ok": {fields: []string{"backend", "version"}},
|
||||
"doctor_proxy_ca": {fields: []string{"dir"}},
|
||||
"downloading_mise": {fields: []string{"version"}},
|
||||
|
||||
@@ -163,6 +163,10 @@ func (d Dirs) Cache() string { return filepath.Join(d.Data, "cache") }
|
||||
// reference.
|
||||
func (d Dirs) FromDigests() string { return filepath.Join(d.Cache(), "from-digests.json") }
|
||||
|
||||
// ReleaseCheck is the daily release check's record: the newest devvm
|
||||
// release it found, and when it last checked.
|
||||
func (d Dirs) ReleaseCheck() string { return filepath.Join(d.Cache(), "release.json") }
|
||||
|
||||
// Run holds what running VMs need that isn't one VM's, or whose path
|
||||
// must be short: the QEMU wrapper, the claims lock, the port forwarders'
|
||||
// and link sessions' sockets, named by hashes (a socket's path is at most
|
||||
|
||||
@@ -50,6 +50,9 @@ type configFile struct {
|
||||
// UbuntuMirror is base's first mirror (UbuntuMirror), which no command
|
||||
// saves.
|
||||
UbuntuMirror opt[ubuntuMirrorKind] `toml:"ubuntu-mirror"`
|
||||
// ReleaseCheck is the daily check for a newer release (ReleaseCheck),
|
||||
// which no command saves.
|
||||
ReleaseCheck opt[switchKind] `toml:"release-check"`
|
||||
// Proxy is the company proxy (HostProxy), which no command saves.
|
||||
Proxy struct {
|
||||
HTTPS opt[proxyHTTPSKind] `toml:"https"`
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"github.com/w3cj/devvm/internal/paths"
|
||||
)
|
||||
|
||||
// KeyReleaseCheck is config.toml's switch for the daily check for a newer
|
||||
// devvm release.
|
||||
const KeyReleaseCheck = "release-check"
|
||||
|
||||
// ReleaseCheck reports whether a launch checks for a newer devvm release
|
||||
// once a day: unless config.toml's release-check is false, or
|
||||
// DEVVM_NO_RELEASE_CHECK is set in getenv's environment, as CI sets it.
|
||||
func ReleaseCheck(d paths.Dirs, getenv func(string) string) (bool, error) {
|
||||
if getenv("DEVVM_NO_RELEASE_CHECK") != "" {
|
||||
return false, nil
|
||||
}
|
||||
cf, err := decodeConfig(d.ConfigFile())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cf.ReleaseCheck.v != "false", nil
|
||||
}
|
||||
|
||||
type switchKind struct{}
|
||||
|
||||
func (switchKind) parse(v any) (string, error) {
|
||||
b, ok := v.(bool)
|
||||
if !ok {
|
||||
return "", errText("not true or false")
|
||||
}
|
||||
if b {
|
||||
return "true", nil
|
||||
}
|
||||
return "false", nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/w3cj/devvm/internal/state"
|
||||
)
|
||||
|
||||
// The daily release check: on unless config.toml's release-check is false
|
||||
// or DEVVM_NO_RELEASE_CHECK is set; release-check must be true or false.
|
||||
func TestReleaseCheck(t *testing.T) {
|
||||
d := testDirs(t)
|
||||
none := func(string) string { return "" }
|
||||
ci := func(k string) string {
|
||||
if k == "DEVVM_NO_RELEASE_CHECK" {
|
||||
return "1"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
for _, c := range []struct {
|
||||
config string
|
||||
getenv func(string) string
|
||||
want bool
|
||||
}{
|
||||
{"", none, true},
|
||||
{"release-check = true\n", none, true},
|
||||
{"release-check = false\n", none, false},
|
||||
{"", ci, false},
|
||||
{"release-check = true\n", ci, false},
|
||||
} {
|
||||
write(t, d.ConfigFile(), c.config)
|
||||
if on, err := ReleaseCheck(d, c.getenv); err != nil || on != c.want {
|
||||
t.Errorf("%q: %v, %v; want %v", c.config, on, err, c.want)
|
||||
}
|
||||
}
|
||||
write(t, d.ConfigFile(), "# off\nrelease-check = \"no\"\n")
|
||||
_, err := ReleaseCheck(d, none)
|
||||
if c, ok := errors.AsType[*state.CorruptError](err); !ok || c.Line != 2 {
|
||||
t.Errorf("a string: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func devvm() rules {
|
||||
// fake's own types each implement.
|
||||
maxMethods: 24,
|
||||
largeTypes: map[string]large{
|
||||
"internal/paths.Dirs": {57, "one method per folder or file devvm uses: a list (a VM's own files are paths.VM's)"},
|
||||
"internal/paths.Dirs": {58, "one method per folder or file devvm uses: a list (a VM's own files are paths.VM's)"},
|
||||
"internal/ui.UI": {45, "the one terminal: messages and where they go, as text or names, errors with the caller's exit code, prompts and their refusals, whether the picker shows, status line, tables, run log and how many are kept, cleanups, signals"},
|
||||
},
|
||||
allowedVars: devvmVars(),
|
||||
@@ -236,13 +236,14 @@ func devvmVars() map[string]string {
|
||||
// each with the files that read it and why.
|
||||
func devvmEnvSettings() map[string]envSetting {
|
||||
return map[string]envSetting{
|
||||
"DEVVM_NO_TOOL_CHECK": {[]string{"internal/tools/tools.go"}, "a user setting: no daily check for newer shared tools"},
|
||||
"DEVVM_LIMA_HOME": {[]string{"internal/paths/dirs.go"}, "a user setting: devvm's Lima home"},
|
||||
"DEVVM_SECRET_SERVICE": {[]string{"internal/secrets/secrets.go"}, "a user setting: the Keychain service secrets are saved under"},
|
||||
"DEVVM_FROM": {[]string{"internal/cli/flags.go"}, "a user setting: --from's default"},
|
||||
"DEVVM_MESSAGES": {[]string{"internal/ui/style.go"}, "names mode, which tests and e2e read messages in: any build has it"},
|
||||
"DEVVM_GUESTFWD": {[]string{"internal/backend/lima/qemu.go"}, "what devvm gives its own QEMU wrapper, devvm _qemu"},
|
||||
"DEVVM_DAEMON_STATUS": {[]string{"internal/daemon/status.go"}, "what devvm gives its own background processes: where each says it's ready"},
|
||||
"DEVVM_NO_TOOL_CHECK": {[]string{"internal/tools/tools.go"}, "a user setting: no daily check for newer shared tools"},
|
||||
"DEVVM_NO_RELEASE_CHECK": {[]string{"internal/settings/release.go"}, "a user setting: no daily check for a newer devvm release"},
|
||||
"DEVVM_LIMA_HOME": {[]string{"internal/paths/dirs.go"}, "a user setting: devvm's Lima home"},
|
||||
"DEVVM_SECRET_SERVICE": {[]string{"internal/secrets/secrets.go"}, "a user setting: the Keychain service secrets are saved under"},
|
||||
"DEVVM_FROM": {[]string{"internal/cli/flags.go"}, "a user setting: --from's default"},
|
||||
"DEVVM_MESSAGES": {[]string{"internal/ui/style.go"}, "names mode, which tests and e2e read messages in: any build has it"},
|
||||
"DEVVM_GUESTFWD": {[]string{"internal/backend/lima/qemu.go"}, "what devvm gives its own QEMU wrapper, devvm _qemu"},
|
||||
"DEVVM_DAEMON_STATUS": {[]string{"internal/daemon/status.go"}, "what devvm gives its own background processes: where each says it's ready"},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/w3cj/devvm/internal/state"
|
||||
)
|
||||
|
||||
// CheckEvery is how often a launch checks for a newer release.
|
||||
const CheckEvery = 24 * time.Hour
|
||||
|
||||
// noticeTimeout bounds a launch's check, which runs beside the launch and
|
||||
// is dropped when it takes longer.
|
||||
const noticeTimeout = 5 * time.Second
|
||||
|
||||
// Known is the daily check's record: the newest release it found and
|
||||
// when, and when it last tried, found or not, so an offline machine tries
|
||||
// once a day too.
|
||||
type Known struct {
|
||||
Latest string `json:"latest,omitempty"`
|
||||
Checked time.Time `json:"checked,omitzero"`
|
||||
Tried time.Time `json:"tried,omitzero"`
|
||||
}
|
||||
|
||||
// ReadKnown reads the record at path. A missing or unreadable one is
|
||||
// none: the next check writes it again.
|
||||
func ReadKnown(path string) Known {
|
||||
var k Known
|
||||
data, err := os.ReadFile(path) //nolint:gosec // paths come from paths.Dirs
|
||||
if err != nil || json.Unmarshal(data, &k) != nil || (k.Latest != "" && !Valid(k.Latest)) {
|
||||
return Known{}
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
// Due reports whether k's last try is a day old at now, or not yet made,
|
||||
// or in the future (a clock set back).
|
||||
func (k Known) Due(now time.Time) bool {
|
||||
return k.Tried.IsZero() || now.Sub(k.Tried) >= CheckEvery || k.Tried.After(now)
|
||||
}
|
||||
|
||||
// Newer reports whether k's release is newer than current.
|
||||
func (k Known) Newer(current string) bool {
|
||||
return k.Latest != "" && Valid(current) && Compare(k.Latest, current) > 0
|
||||
}
|
||||
|
||||
// Refresh checks s for the newest release, within noticeTimeout, and
|
||||
// records what it found at path, with now as the try's time. A failed
|
||||
// check, such as offline, keeps what was known and returns its error.
|
||||
func (s Source) Refresh(ctx context.Context, path string, now time.Time) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, noticeTimeout)
|
||||
defer cancel()
|
||||
k := ReadKnown(path)
|
||||
k.Tried = now
|
||||
av, err := s.Check(ctx, "")
|
||||
if err == nil {
|
||||
k.Latest, k.Checked = av.Latest, now
|
||||
}
|
||||
data, merr := json.Marshal(k)
|
||||
if merr != nil {
|
||||
return merr
|
||||
}
|
||||
if werr := state.WriteFile(path, data); werr != nil {
|
||||
return werr
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package upgrade_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/w3cj/devvm/internal/upgrade"
|
||||
"github.com/w3cj/devvm/internal/upgrade/upgradetest"
|
||||
)
|
||||
|
||||
// The daily check's record: due once a day (or never tried, or tried in
|
||||
// the future), newer only for a newer release than a release's version.
|
||||
func TestKnown(t *testing.T) {
|
||||
now := time.Date(2026, 11, 5, 12, 0, 0, 0, time.UTC)
|
||||
for _, c := range []struct {
|
||||
tried time.Time
|
||||
due bool
|
||||
}{
|
||||
{time.Time{}, true},
|
||||
{now.Add(-time.Hour), false},
|
||||
{now.Add(-upgrade.CheckEvery), true},
|
||||
{now.Add(time.Hour), true},
|
||||
} {
|
||||
if got := (upgrade.Known{Tried: c.tried}).Due(now); got != c.due {
|
||||
t.Errorf("tried %v: due %v", c.tried, got)
|
||||
}
|
||||
}
|
||||
for _, c := range []struct {
|
||||
latest, current string
|
||||
newer bool
|
||||
}{
|
||||
{"0.2.0", "0.1.0", true},
|
||||
{"0.2.0", "0.2.0", false},
|
||||
{"0.2.0", "0.3.0", false},
|
||||
{"", "0.1.0", false},
|
||||
{"0.2.0", "", false},
|
||||
} {
|
||||
if got := (upgrade.Known{Latest: c.latest}).Newer(c.current); got != c.newer {
|
||||
t.Errorf("%q over %q: %v", c.latest, c.current, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh records the newest release and the try; offline it keeps what
|
||||
// was known, records the try, and returns the error. A record devvm can't
|
||||
// read is none.
|
||||
func TestRefresh(t *testing.T) {
|
||||
srv := upgradetest.NewServer(t)
|
||||
srv.Add("0.2.0", upgradetest.NewRelease(upgradetest.NewKey(), "0.2.0", nil), true)
|
||||
src := upgrade.NewSource(srv.URL, "")
|
||||
src.Client.Trust(srv.Roots())
|
||||
path := filepath.Join(t.TempDir(), "cache", "release.json")
|
||||
if k := upgrade.ReadKnown(path); k != (upgrade.Known{}) {
|
||||
t.Fatalf("no record: %+v", k)
|
||||
}
|
||||
first := time.Date(2026, 11, 5, 12, 0, 0, 0, time.UTC)
|
||||
if err := src.Refresh(t.Context(), path, first); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if k := upgrade.ReadKnown(path); k.Latest != "0.2.0" || !k.Checked.Equal(first) || !k.Tried.Equal(first) {
|
||||
t.Fatalf("recorded %+v", k)
|
||||
}
|
||||
offline := upgrade.NewSource("https://127.0.0.1:1", "")
|
||||
next := first.Add(upgrade.CheckEvery)
|
||||
if err := offline.Refresh(t.Context(), path, next); err == nil {
|
||||
t.Fatal("offline: no error")
|
||||
}
|
||||
if k := upgrade.ReadKnown(path); k.Latest != "0.2.0" || !k.Checked.Equal(first) || !k.Tried.Equal(next) {
|
||||
t.Fatalf("offline: %+v", k)
|
||||
}
|
||||
for _, bad := range []string{"{", `{"latest":"v1; rm"}`} {
|
||||
if err := os.WriteFile(path, []byte(bad), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if k := upgrade.ReadKnown(path); k != (upgrade.Known{}) {
|
||||
t.Errorf("%s: %+v", bad, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,6 +195,10 @@ other = "This machine has {{.have}} CPUs, fewer than the {{.want}} devvm recomme
|
||||
[doctor_ok]
|
||||
other = "This is devvm {{.version}}, and the {{.backend}} backend has everything it needs."
|
||||
|
||||
[doctor_latest_release]
|
||||
description = "devvm doctor: the newest release a launch's daily check found, and the day it found it."
|
||||
other = "The newest devvm release is {{.latest}}, as of {{.date}}."
|
||||
|
||||
[doctor_failed]
|
||||
description = "reason is an error from the system, in English"
|
||||
other = "Checking what devvm needs failed: {{.reason}}."
|
||||
|
||||
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
# A launch in a terminal says, in one line, that a newer devvm release is
|
||||
# out, from what the daily check last found, and starts that check beside
|
||||
# the launch once a day. The release server is a fake one
|
||||
# (release_server), this devvm says it's 0.1.0, installed as install.sh
|
||||
# installs it, and every launch here is refused, in the home folder, after
|
||||
# the check.
|
||||
env DEVVM_TEST_VERSION=0.1.0
|
||||
env DEVVM_NO_RELEASE_CHECK=
|
||||
env DEVVM_PICK_ON_PIPE=1
|
||||
mkdir pfx/lib/devvm/0.1.0 pfx/bin
|
||||
cp $DEVVM_BIN/devvm pfx/lib/devvm/0.1.0/devvm
|
||||
chmod 0755 pfx/lib/devvm/0.1.0/devvm
|
||||
symlink pfx/bin/devvm -> $WORK/pfx/lib/devvm/0.1.0/devvm
|
||||
env DEVVM=$WORK/pfx/bin/devvm
|
||||
release_server 0.2.0 0.1.0
|
||||
env REPO=$DEVVM_REPO_URL
|
||||
cd $HOME
|
||||
|
||||
# Without a terminal, nothing is checked or said.
|
||||
! exec $DEVVM
|
||||
! stdout upgrade_available
|
||||
! exists $DATA/cache/release.json
|
||||
|
||||
# With --no-input, neither.
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM --no-input
|
||||
! stdout upgrade_available
|
||||
! exists $DATA/cache/release.json
|
||||
|
||||
# The first launch in a terminal knows of nothing yet, so it says nothing,
|
||||
# and its check records the newest release.
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
! stdout upgrade_available
|
||||
grep '"latest":"0.2.0"' $DATA/cache/release.json
|
||||
|
||||
# The next says it, and checks no more that day: a release server that
|
||||
# has gone changes nothing.
|
||||
env DEVVM_REPO_URL=$REPO/nope
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
stdout '^==> upgrade_available current=0.1.0 latest=0.2.0$'
|
||||
grep '"latest":"0.2.0"' $DATA/cache/release.json
|
||||
|
||||
# devvm doctor shows what the check last found.
|
||||
exec devvm doctor
|
||||
stdout '^doctor_latest_release date=\S+ latest=0.2.0$'
|
||||
exec devvm doctor --json
|
||||
stdout '"latest": "0.2.0"'
|
||||
|
||||
# A day later it checks again. Offline, it says what it knew, silently
|
||||
# keeps it, and tries again only the next day.
|
||||
json_set $DATA/cache/release.json tried=2026-01-01T00:00:00Z
|
||||
env DEVVM_REPO_URL=https://127.0.0.1:1
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
stdout '^==> upgrade_available current=0.1.0 latest=0.2.0$'
|
||||
! stderr 'upgrade_no_latest'
|
||||
grep '"latest":"0.2.0"' $DATA/cache/release.json
|
||||
! grep '"tried":"2026-01-01' $DATA/cache/release.json
|
||||
|
||||
# Online again, a day later, the newest being this devvm's own version:
|
||||
# nothing to say from the next launch on.
|
||||
json_set $DATA/cache/release.json tried=2026-01-01T00:00:00Z
|
||||
env DEVVM_REPO_URL=$REPO
|
||||
env DEVVM_TEST_VERSION=0.2.0
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
! stdout upgrade_available
|
||||
|
||||
# An older release than this devvm is nothing to say either.
|
||||
env DEVVM_TEST_VERSION=0.3.0
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
! stdout upgrade_available
|
||||
env DEVVM_TEST_VERSION=0.1.0
|
||||
|
||||
# Off: with DEVVM_NO_RELEASE_CHECK, or config.toml's release-check.
|
||||
env DEVVM_NO_RELEASE_CHECK=1
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
! stdout upgrade_available
|
||||
env DEVVM_NO_RELEASE_CHECK=
|
||||
cp $WORK/off.toml $CFG/config.toml
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
! stdout upgrade_available
|
||||
|
||||
# On again, it says it.
|
||||
rm $CFG/config.toml
|
||||
ttyin -stdin $WORK/no.txt
|
||||
! exec $DEVVM
|
||||
stdout '^==> upgrade_available current=0.1.0 latest=0.2.0$'
|
||||
|
||||
-- no.txt --
|
||||
n
|
||||
-- off.toml --
|
||||
release-check = false
|
||||
Reference in new issue
Block a user