Skip to content

fix(install): a named install uses b.yaml; b.lock describes the file on disk - #195

Merged
fentas merged 18 commits into
mainfrom
fix/named-install-uses-config
Nov 17, 2026
Merged

fentas merged 18 commits into
mainfrom
fix/named-install-uses-config

Conversation

@fentas

@fentas fentas commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

What

Four fixes to how b install picks a binary and records it in b.lock.

  1. A named install applies its b.yaml entry. b install <name> took the built-in preset first and ignored the b.yaml entry of that name. GetBinary (pkg/cli/shared.go) now looks up the b.yaml entry first and merges it with resolveBinary, the same merge the no-argument b install uses. An explicit <name>@<version> still wins.
  2. Another version replaces a present binary. Before, a present file was kept whatever version was asked for, and b.lock then recorded the asked version with the old file's hash. planInstall (pkg/cli/install.go) now decides per binary, before any download:
    • it downloads when --force is set or the file is missing;
    • it keeps the file when no version is asked (or latest), or when the b.lock entry's sha256 matches the file and its version is the one asked;
    • otherwise it downloads and replaces the file.
  3. A kept binary keeps its known version. It records the version from b.lock when the entry describes the file, else "". It no longer records the command line's version or overwrites a known one with "". A failed download leaves the entry as it was.
  4. b.lock changes only when an entry changes. WriteLock leaves the file as it is when the binary and env entries are the same, so timestamp and tool.b stay and git diff b.lock stays clean after a no-op run.

Behaviour changes (for the release notes)

  • b install <name>, b update <name> and b version <name> now see the b.yaml entry of that name (version, enforced, file, onPost), like their no-argument forms.
  • b install <name>@<v> over a present binary of another version downloads and replaces it.
  • With a version asked (on the command line or in b.yaml), a present binary that b.lock does not confirm (no entry, or another sha256) is downloaded once. The no-argument b install (the CI path) is included. After that download, b.lock matches and the binary is kept.
  • With no version asked, a present binary is kept, as before.
  • A no-op run no longer rewrites b.lock, including tool.b from a newer b.

Tests

  • New tests:
    • pkg/lock: TestWriteLock_UnchangedEntriesKeepTheFile.
    • pkg/cli: TestGetBinary_ConfigEntryOverPreset.
    • TestPlanInstall (10 cases) and TestUpdateLock_FollowsThePlan. These run in the -race CI job.
    • install_pins_norace_test.go: Run-level tests against an httptest release server (replace, keep, failed download, config version).
  • Each new test fails on the code without its fix.
  • Nine mutants were killed (the anchored ones, run by the author). The reviewer added one more: the lock compare ignoring env entries, killed by six env tests.
  • Results: go test ./... and go test -race ./pkg/cli/ ./pkg/lock/ pass, go vet passes, gofmt is clean, and golangci-lint v2.9.0 reports 0 issues.

Note: the !race test files (including the existing install_norace_test.go) never run in CI, because the test jobs use -race. The plan tests cover the decision there. A non-race test step would also run the Run-level tests.

Review rounds 1-5 (alias and --add)

  • A named install keeps the b.yaml alias, unless --alias is given.
  • --add updates an aliased entry in place, and keeps its enforced version and file.
  • A provider ref has one entry, under the ref, with the binary's name as its alias. --add finds it by the ref, and --alias renames the binary in it. A new ref entry is written as <ref>: {alias: x}.
  • GetBinary resolves a provider-ref entry as a ref. A preset with the same name as the alias does not replace it.
  • A preset installed under a new alias gets its own entry and its own file. The entry of the preset's name stays as it was.

Left open

  • The provider-ref config merge is still duplicated in GetBinary and GetBinariesFromConfig (pre-existing).
  • b update's own keep/replace logic is unchanged.
  • b.lock rows are keyed by the preset name, not by the installed file. A plain entry and an alias of the same preset at different versions therefore share one row: each install downloads one of them again and runs its onPost. Each file still ends at its own version. Main shares the row too, but never applies a version change. The fix keys the row by the file in install and update. That renames the lock rows of aliased entries, so it gets its own PR.
  • --on-post and --asset are not written into an entry that already exists.
  • b verify looks for PATH_BIN/<lock row name>, so it reports an aliased binary as missing (also on main).

🤖 Generated with Claude Code

fentas and others added 18 commits November 16, 2026 21:57
WriteLock set a new timestamp and tool version on every write, so every
`b install` and `b update` changed b.lock even when no binary or env
changed, and `git diff --exit-code b.lock` failed after any run.

WriteLock now compares the binary and env entries with the file on disk.
When they are the same, it leaves the file as it is. A changed entry
writes the file with a new timestamp and tool version, as before. A
missing b.lock is still written.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b install <name>` took the built-in preset and ignored the b.yaml entry
of that name, so its version and file never applied; only the no-argument
`b install` and `b install <name>@<version>` honoured a pinned version.

GetBinary now looks up the b.yaml entry first and merges it over the
preset with resolveBinary, the same merge as the no-argument install. An
explicit @Version still wins. `b update <name>` and `b version <name>`
use GetBinary too, so they now see the pinned version as well, like
their no-argument forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b install <name>@<version>` over a present binary of another version
kept the old file and recorded its sha256 under the new version, so
b.lock named one version and hashed another. Only --force replaced it.

The install now decides per binary before any download (planInstall). A
present file is kept when no version is asked for, or when b.lock says
that file (by its sha256) is the version asked for. When another version
is asked for, or b.lock does not describe the file, the binary is
downloaded and replaced. A download that fails leaves the b.lock entry
as it was, since the old file is still the one on disk. The onPost hook
still runs only after a download.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bare `b install <name>` over a present binary rewrote its b.lock entry
with the version "" (the binary stayed). The entry took the version of
the command line, which is empty when no version is asked for.

When the install keeps the present file, the entry now records the
version b.lock gives that file: the previous entry's version when its
sha256 is the file's, else "" (b cannot tell which version the file
is). An install that changes nothing now leaves b.lock as it was. With
a version pinned in b.yaml, `b install <name>` asks for that version: a
present file of it is kept, a file of another version is replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The end-to-end install tests are !race, like the other tests that run an
install through the progress writer, and the CI test jobs run with -race.
planInstall and updateLock are now also tested without the progress
writer, so the race job checks the keep-or-replace decision and the lock
entry of a kept, a downloaded and a failed binary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b install <name>` for a b.yaml entry that is an alias of a preset
cleared the entry's alias, so the binary went to the preset's file name
and not to the name of the entry. Only --alias replaces it now.

Also correct the comment on a failed download: the download writes the
file in place, so a partial file can stay behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eps its alias

With the alias of a b.yaml entry kept, `b install <alias>@<version> --add`
looked for the entry under the preset name, did not find it, and added a
second entry of the same name. That entry replaced the first one, so its
enforced version and its file were lost. addToConfig now looks for an
aliased binary under its alias, the name a new entry gets.

The named install of a provider-ref entry now also takes the entry's
alias, as the no-argument install does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is no preset

- A provider-ref entry is stored under the ref, with the binary's name as
  its alias. `b install <ref>@<version> --add` and `b install --add` now
  update that entry; before, they added a second entry under the alias,
  which did not resolve.
- GetBinary resolves a provider-ref entry as a provider ref, as the
  no-argument install does. A preset with the same name as the entry's
  alias no longer replaces the ref.
- Tests: the provider-ref entry with and without an argument, the preset
  named like the alias, and the version update of an aliased entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- `--add` finds a provider-ref entry by the ref alone. With --alias, it
  renames the binary in that entry; before, it added an entry under the
  alias that did not resolve.
- A new provider-ref entry is written under the ref, with the alias as
  the binary's name (`<ref>: {alias: t}`), the shape that the no-argument
  install reads. An alias of a preset still gets its own entry, and the
  entry of the preset's name stays as it was.
- Tests: --alias on a provider-ref entry (the entry keeps its other
  fields), new entries of both kinds resolve to the files they installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b install jq@v2 --alias x --add` with an entry `jq: {file: /opt/jq}`
downloaded v2 into /opt/jq (the entry's file), then wrote an entry `x`
that names .bin/x. The file of a b.yaml entry belongs to that entry's
binary: --alias with another name now drops it for a preset. A provider
ref keeps its one entry, so it keeps the file too.

Tests: the installed file of both cases, the version of the new alias
entry, and the file of the entry that stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A preset installed under --alias is the binary of the b.yaml entry of
that name, the entry that --add writes. It now takes that entry's file,
or its own file when there is no such entry. Before, `--alias plain` on
an entry `plain: {file: /opt/plain}` installed .bin/plain while the
entry still named /opt/plain, and `--alias x` on an alias entry
`x: {file: /opt/x}` installed .bin/x.

Test: for its own name, an alias entry with a file and a new name, the
binary installs at the expected file and the written b.yaml resolves to
the same file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An --alias that names the b.yaml entry of another binary (another
preset's entry, an alias entry of another preset, or a provider ref's
entry) made the install write over that binary's file and rewrite its
entry. Complete now refuses it with a hint, and installs nothing.

A new entry under --alias equal to the binary's own name no longer
aliases itself. The condition in Complete is written without the
negated conjunction (staticcheck QF1001).

Tests: the alias table gets the refusals, an alias entry of the preset
under the preset's own name, an alias entry under a new name, and a
check that no written entry aliases itself. Mutants killed: the entry
lookup also matching by alias, the provider-ref guard removed, the file
reset removed, the check removed, a plain entry of any name accepted,
the self alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b.yaml `tool: {version: v1.0.0}` and `t2: {alias: tool, version:
v3.0.0}` install two files of one preset, but both wrote and read the
b.lock row of the preset's name. Each run then found the row of the
other file, and downloaded one binary again.

The row of a binary is now named by lockName: the alias for an alias
entry of a preset, the binary's name for the preset's own entry and
for a provider ref, as before. A b.lock written before still matches
the preset's own entry and every provider ref; an alias entry finds no
row once, and downloads its pinned version once. The digest checks of
b update read the row by the same name. b verify, which looks for the
file named by the row, now finds the default file of an alias entry.

Tests: three runs of `b install` over the two entries download 2, 0
and 0 binaries, each row describes its own file, and b verify passes;
a table of lockName. Mutants killed: the row read by the binary's
name, the row written by the binary's name, lockName without the alias,
lockName without the provider-ref guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With `x: {alias: plain, enforced: v3.0.0, file: /opt/x}`, `b install
plain --alias x --add` took the version and onPost of the entry plain:
it put plain's v1.0.0 into /opt/x and set the version of x to v1.0.0,
while the enforced pin of x stayed v3.0.0.

A preset installed under an --alias that names an entry of the same
preset is the binary of that entry. Complete now builds it from that
entry with resolveBinary, as the no-argument install does: version,
enforced pin, file and onPost. A version on the command line still
wins, and is now applied after the entry.

--add no longer sets the version of an entry to a value its enforced
pin contradicts (the pin wins at every later install, so the entry
would name a version b never installs). Such an install is refused
before any download, with a hint to add --fix, which moves the pin.
This also holds for an entry named directly, `b install x@v2.0.0 --add`.
The entry that --add writes is named by configKey, which addToConfig
and the check share.

Tests: the settings of the entry for six argument and alias pairs,
also when the preset's file is already set; the pin kept, refused or
moved with --fix; a table of checkPin. The alias-entry test of --add
no longer expects a version beside a contradicting pin. Mutants
killed: the entry not resolved, its file not applied, the command-line
version applied before the entry, the check removed, --fix ignored, the
pinned version refused, latest or an empty version refused, the check
by the binary's name, configKey without the alias or the ref.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b install plain --alias tool` beside `github.com/org/tool: {alias:
tool}` was accepted and wrote over that ref's file, as the check looked
only for an entry named tool. A provider ref installed with --alias had
no check at all.

aliasOwner now finds the entry of another binary that --alias already
names: an entry of that name which is not an entry of the preset (for a
provider ref: any entry of that name), or a provider-ref entry, other
than the ref being installed, whose binary has that name (its alias, or
the name from the ref). Both a preset and a provider ref are refused
with the hint as before, and nothing is installed. entryOfPreset no
longer checks for a provider ref; aliasOwner does.

Tests: the alias of a ref, the name from a ref without an alias, a ref
under the alias of another ref, under a preset entry and under alias
entries; a ref under its own alias and under a new name is accepted.
The ref entries of the fixture now set IsProviderRef from the name, as
the loader does. Mutants killed: the check removed, the own-ref skip
removed, the ref entry's name or its binary name not compared, the name
from the ref dropped, any entry of that name not refused for a ref, a
plain entry of any name taken as the preset's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s name

The alias table had no case where the argument is an alias entry and
--alias names an entry of the same preset, so a check of the argument's
name in place of the preset's passed it. Two cases: `b install x
--alias x` and `b install x --alias plain` (x an alias entry of plain)
install at the file of the entry --alias names.

Mutant killed (with this test alone): the alias check given the
argument's name in place of the preset's. The fixture sets
IsProviderRef as the loader does since the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`b install a b --alias x` gave both binaries the alias x, so both were
installed into the one file of x, the last download winning. --alias
names the file of one binary: Complete now refuses a second binary
argument when --alias is set, with a hint, and installs nothing. An env
install beside the one binary is still accepted, and several binaries
without --alias too. The flag help says so.

Test: two presets, a preset and a provider ref, a preset and an env
install, one preset, and two presets without --alias. Mutants killed:
the check removed, the check without the --alias condition, the check
from the third binary on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fentas
fentas merged commit 1fb43e5 into main Nov 17, 2026
10 checks passed
@fentas
fentas deleted the fix/named-install-uses-config branch November 17, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant