Dpx 693 pr 2 teach lstk update to handle the bundled extensions - #482
Dpx 693 pr 2 teach lstk update to handle the bundled extensions#482carillan81 wants to merge 4 commits into
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
peter-smith-phd
left a comment
There was a problem hiding this comment.
Thanks for implementing this, but I'm not sure we need a 2000-line solution to handle the "binary" case where we're moving from just lstk to lstk/bundled-extensions/lstk-extensions.toml. I appreciate the need to carefully replace the three files, rather than just one, but this solution feels over complicated. I was expecting closer to 100 lines of code.
In particular, do we really need the "repair" functionality? If it breaks for some reason, we already have error messages that inform the user of the problem. They should instead just uninstall/reinstall lstk and the problem will go away. My concern is that the code has become so complicated that we'll have trouble maintaining it in future.
What can we do to make this significantly less complicated, and focus on just replacing three files instead of one?
…ser. Co-Authored-By: Claude <noreply@anthropic.com>
After some discussion with humans and AI I agree that the repair functionality is an overkill. We are facing a temporal issue while the users update and the repair adds some code that will be stale in a month. I think we must address user UX so I just implemented a better error message that gives a hint for reinstall (and command) in case the command is not found. It adds some code but barely adds a few tenths of lines.
This looks a much better solution to me. Does this works for you? |
Motivation
Once releases ship the bundled extensions (
bundled-extensionsandlstk-extensions.tomlnext tolstk),lstk updateon the binary channel has to replace all three files together, not just the binary. Today it replaces one file,lstk, and ignores everything else in the archive.That has a second-order problem. The first bundling release is installed by the updater users already have, which only replaces
lstk. They land on a current binary with no extensions, and because they are already on the newest version,lstk updatesays "already up to date" until the next release ships. Nobody can fix that retroactively, so the new updater has to detect and repair it.Solution
Set-wise replacement (stage-then-commit). Every member of the archive is copied into the install directory under a
.lstk-newname; only when all copies succeed is each renamed over its final name,lstklast. A file visible under its real name is never half-written, a failure before the last rename leaves a workinglstkto re-run with, and the updater never deletes anlstk-*file it cannot prove it owns (additive-only). An archive containing onlylstkbehaves exactly as before, so pre-bundling releases and rollbacks are unaffected.Repair when current but incomplete. The release stamps the expected set into the binary (version.bundledSet, via ldflags). When versions match but a stamped member is missing or unusable,lstk updatereinstalls the same release, then re-checks; if the archive still did not deliver the members it fails loudly ("did not restore the bundled extensions") instead of looping. Empty stamp keeps today's pure version comparison. Homebrew and npm never repair; the package manager owns the whole set there. The passive update notice also nudges an incomplete install towardlstk update.The same-version repair from the first revision was dropped in review. The transition release (old updater, new archive) leaves the bundle uninstalled until the next
lstk update. Instead of repairing, lstk tells the user: a release build that finds no bundle beside itself adds a reinstall hint to the unknown-command error and warns on an up-to-datelstk update(also in the--jsonwarnings array). One goreleaser ldflag, one detector, two call sites.Hardening. Windows moves every existing member aside before renaming (a running extension no longer breaks the commit); a squatting symlink or directory at a staging path is refused rather than written through; the install directory is listed literally instead of globbed (a
[in the path used to fail every update); setuid/setgid bits survive the update; a concurrent update cannot truncate another's staging file.Structured output.
UpdateCheckedEventgainsRepairBundled; the--jsoncheck shape gains"repairBundled": truefor a same-version repair (absent otherwise, and scrubbed from the applied shape).Dependencies and follow-ups
dpx-692(PR 1) must merge first or together: it carries the resolver that dispatches bundled commands from the toml. Without it a repaired install has the files but nothing resolves them.bundledSetldflags stamp (tasks.md 5.2) is not yet in.goreleaser.yaml; until it lands on the packaging side the repair path stays dormant and this PR changes nothing user-visible.bundledBinaryBaseNamefromextension.BundledBinaryName(TODO left on the constant).Testing
internal/updatecovers every behaviour above, including the Windows path from any host via agoosparameter. All new behaviour was written test-first.goreleaser, npm publisher): the full transition (published 0.23.0 to bundling release, repair, no-op, bundled-to-bundled upgrade, rollback, forward) passes on the binary channel and npm. Caveat: the currently published bundle predates thebundled-extensions listcontract, so the release gate was run as a warning for that exercise; Homebrew was not executed.Docs
No documentation work needed outside this PR.docs/structured-output.mdis updated for the newrepairBundledkey, and the update guarantees are documented in theinternal/updatepackage comment. User-facing bundling docs (docs/extensions-bundling.md) live on dpx-692.The reinstall hint is new user-facing output; the spec has a scenario for it. Release notes for the first bundling release should carry one line: if a bundled command reports "unknown command" after updating, reinstall lstk once.
Review
Human review advisable. This is the update path, the one thing a broken release cannot ship a fix for, and it adds new user-visible behaviour (the repair). Not a self-merge candidate.
Closes DPX-693