feat(config): add devbox_version to require a devbox version - #2990
Conversation
|
@claude ptal |
|
@claude review |
|
Claude finished @mikeland73's task in 5m 25s —— View job Code review:
|
|
Claude finished @mikeland73's task in 4m 12s —— View job Claude's reviewTodo list
Overall this is a clean, well-tested implementation — the shorthand/object JSON handling, the root-config-only scoping, the per-process warning dedupe, and the config validation are all solid. A few things worth a look before merging: 1. The mismatch message's suggested fix can be wrong for range constraints (
|
|
@claude review |
|
Claude finished @mikeland73's task in 17s —— View job Review of
|
Add a top-level `devbox_version` field to devbox.json that declares which devbox versions a project supports (#1371). It accepts a semver constraint string, or an object with an explicit mismatch policy: "devbox_version": "^0.18.0" "devbox_version": {"version": "0.18.4", "on_mismatch": "error"} When the running devbox doesn't satisfy the constraint, "warn" (the default) prints a warning once per project per process tree and "error" fails the command. DEVBOX_VERSION_POLICY=off|warn|error overrides the policy. The check runs in devbox.Open right after the config loads, before the lockfile is read, so it covers every command that opens a project (including `devbox global`). Development builds skip it. Constraints use npm-style syntax via Masterminds/semver, which moves from an indirect to a direct dependency. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
For range constraints, the mismatch message always suggested `devbox version update`, but that only moves to the latest release. If the running version is already past the constraint's upper bound, or the latest release doesn't satisfy it, updating can't fix the mismatch. Now we only suggest it when the latest version (DEVBOX_LATEST_VERSION) satisfies the constraint, and otherwise point at DEVBOX_USE_VERSION alone. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ntally Two places opened the current directory's project on every devbox invocation, so the devbox_version check fired for commands that don't use the project (e.g. `devbox version` printed the mismatch warning), and a swallowed error let `devbox run --list` ignore the "error" policy: - `devbox run` computed ValidArgs eagerly while building the command tree. It's now a lazy ValidArgsFunction that only runs during shell completion, which also lets cobra parse --config for us. listScripts now returns its error, so `run --list` and bare `run` report it. - The telemetry middleware opens the project after every command to record package names. Add devopt.Opts.SkipVersionCheck for these incidental opens (telemetry and completion), and cover `devbox version` and `run --list` in the testscript. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
50c2729 to
4331a49
Compare
…lepp/lapp stacks The lepp-stack run_test flaked in CI with "the database system is starting up" because it assumed postgres was ready after a fixed 2s sleep. Poll with pg_isready (up to 30s) instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…sion-auto main has the squash-merged devbox_version change (#2990). Conflicts in the devbox_version files are add/add conflicts where this branch's version is main's plus the "auto" policy, so this branch's side is kept. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
) ## Summary Stacked on #2990, which adds `devbox_version`. Merge that first. Adds an `auto` policy that switches to the pinned devbox version: ```json "devbox_version": {"version": "0.18.4", "on_mismatch": "auto"} ``` - **How switching works:** when the running devbox doesn't match, it re-runs the same command through the devbox launcher (`$LAUNCHER_PATH`) with `DEVBOX_USE_VERSION` set to the pinned version. - The existing launcher already downloads, checksum-verifies and runs any release named by `DEVBOX_USE_VERSION`, so the launcher needs no changes. - Download progress goes to stderr, so `shellenv` and direnv output stays clean. - **Exact versions only:** `auto` requires an exact version; a range with `auto` is a config error. `DEVBOX_VERSION_POLICY=auto` with a range fails like `error`. - **A `DEVBOX_USE_VERSION` set by the user wins:** devbox warns instead of switching. - **Loop guard:** `__DEVBOX_AUTO_VERSION` marks a version that `auto` chose. That lets a nested shell switch again for a different project, and makes devbox fail instead of looping if the launcher doesn't switch. - **Without a launcher** (for example Nix or Homebrew installs), `auto` fails with install instructions. - **Inheritance:** `DEVBOX_USE_VERSION` carries into `devbox shell`, so nested devbox commands stay on the pinned version. ## How was it tested? - Unit tests with a mocked `exec` cover: switching, replacing existing env values, switching again for a different project, no launcher, the loop guard, a user-set version winning, and the env override with a range. - `testscripts/version/devbox_version_auto.test.txt` uses a fake launcher script to check that the same command is re-run with `DEVBOX_USE_VERSION` set. It also covers the no-launcher error, a user-set version winning, and rejecting ranges. - Manual end-to-end run with the real launcher (v0.2.2): a binary built as 0.17.1, run in a project pinned to `0.18.4` with `auto`, ran `devbox run` under 0.18.4. Inside the script, `devbox version` printed 0.18.4 and `DEVBOX_USE_VERSION=0.18.4`. - `go test ./internal/...` and `devbox run lint` pass. ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request, I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Summary
Adds a top-level
devbox_versionfield to devbox.json that declares which devbox versions a project supports. Addresses #1371.Masterminds/semver/v3:0.18.4,^0.18.0,~0.18.1,>=0.17.0 <0.19.0,0.18.x,||. The library was already an indirect dependency and is now direct;vendor-hashis unchanged. An invalid constraint or policy is a config load error.warn(default) prints the warning once per project per process tree, so nested devbox commands don't repeat it, then continues.errorfails before the command does any work.DEVBOX_USE_VERSION=<version>for exact pins ordevbox version updatefor ranges.DEVBOX_VERSION_POLICY=off|warn|erroroverrides the policy in devbox.json, as an escape hatch for CI and emergencies.devbox.Open, right after the config loads and before the lockfile is read. That covers every command that opens a project, includingdevbox global.init,search,version, …) and dev builds skip it. Only the root config's field is used; it is ignored in plugins and includes.devbox initdoesn't add the field.additionalProperties: false.Devbox releases from before this change ignore the field, so enforcement starts with the release that ships it. The follow-up PR adds an
autopolicy that switches to the pinned version.How was it tested?
internal/devconfig/configfile/devbox_version_test.gocovers parsing, round-trips and validation.internal/vercheck/project_test.gocovers the policies, warning dedupe, the env override, and dev builds.testscripts/version/devbox_version.test.txtcovers warn, error, theoffoverride, a satisfied constraint, and an invalid constraint. It setsDEVBOX_PROD=1so the check isn't skipped for dev builds.go test ./internal/... ./pkg/...anddevbox run lintpass.Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.
🤖 Generated with Claude Code