-
-
Notifications
You must be signed in to change notification settings - Fork 159
Wire the prompt and auto update modes, behind three refusals #7784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| ### Added | ||
|
|
||
| **`prompt` and `auto` update modes now do something, and refuse to do the wrong | ||
| thing.** The previous slice made the modes configurable; this wires them to the | ||
| existing signed self-updater, behind three refusals. | ||
|
|
||
| **A package-managed install is never replaced in place.** `perry update` | ||
| overwrites the running executable, which is right for a tarball or `install.sh` | ||
| install and wrong for every managed one: Homebrew, npm, apt and winget each keep | ||
| their own record of what is installed and at what version, and overwriting the | ||
| file underneath leaves that record lying. `prompt` and `auto` now detect the | ||
| owner and name that owner's command instead: | ||
|
|
||
| | owner | what Perry says to run | | ||
| |---|---| | ||
| | Homebrew | `brew upgrade perryts/perry/perry` | | ||
| | npm | `npm install -g @perryts/perry@latest` | | ||
| | apt | `sudo apt update && sudo apt install --only-upgrade perry` | | ||
| | winget | `winget upgrade PerryTS.Perry` | | ||
|
|
||
| npm gets an extra sentence, because it is the worst case: Perry ships as a | ||
| wrapper package plus a per-platform binary package, so replacing the binary also | ||
| desyncs it from the wrapper that launched it. | ||
|
|
||
| **Nothing is offered after a command that failed.** The user is looking at an | ||
| error; a question about upgrading is noise at the worst possible moment, and an | ||
| unattended install would bury the error under progress output. Both active modes | ||
| fall back to a plain notice. | ||
|
|
||
| **An unwritable install directory is reported, not attempted.** `install.sh` | ||
| targets `/usr/local/bin`, which is root-owned on a default macOS and most Linux | ||
| boxes. That is now checked *before* anything is downloaded, so the outcome is | ||
| one sentence naming `sudo perry update` rather than a half-finished install. Perry | ||
| never escalates on its own. | ||
|
|
||
| **`perry update --mode <off|notify|prompt|auto>`** saves the setting and exits, | ||
| so the one thing people are most likely to change does not require hand-editing | ||
| TOML. It is a read-modify-write through the shared loader, so the rest of the | ||
| file comes back out the way it went in. | ||
|
|
||
| **`perry doctor`** now reports the effective mode and, when there is one, the | ||
| package manager that owns the binary — the two questions behind "why did it not | ||
| update". | ||
|
|
||
| <details> | ||
| <summary><b>Why the channel detection fails open</b></summary> | ||
|
|
||
| Every rule answers "is this definitely managed?", never "is this definitely | ||
| unmanaged?", and an unrecognised layout resolves to self-managed. | ||
|
|
||
| That asymmetry is deliberate. Guessing "managed" wrongly would refuse to | ||
| self-update a plain tarball install — the majority case, and the one with no | ||
| other upgrade path. Guessing "self-managed" wrongly costs an in-place update on | ||
| a machine that had a package manager available, which is recoverable by running | ||
| that manager. | ||
|
|
||
| The paths are canonicalized before classification, because Homebrew's `perry` in | ||
| `/usr/local/bin` is a symlink into the Cellar; classifying the link rather than | ||
| its target would miss every Homebrew install there is. | ||
|
|
||
| apt requires **both** a dpkg file list and a dpkg-owned path, because dpkg does | ||
| not own `/usr/local` — that is `install.sh`'s directory. The path alone would | ||
| misclassify a hand-placed binary; the dpkg list alone would claim a tarball | ||
| install on a machine that also has the `.deb` installed somewhere else. The check | ||
| is a file-existence test rather than a `dpkg -S` subprocess, since this runs on | ||
| the update path of every command. | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary><b>Prompting needs stdin, not just stderr</b></summary> | ||
|
|
||
| The mode gate already requires stderr to be a terminal. That is not enough to | ||
| ask a question: stdin can be a pipe while stderr is a tty, and reading from it | ||
| would either block the command or take whatever the pipe happened to contain as | ||
| consent. `prompt` degrades to a plain notice when stdin is not a terminal. | ||
|
|
||
| `auto` asks nothing, so it does not need stdin — but it does still require the | ||
| command to have succeeded, an unmanaged install, and a writable directory. | ||
| </details> | ||
|
|
||
| <details> | ||
| <summary><b>Tests</b></summary> | ||
|
|
||
| 24 new, all in the required per-pull-request job. The decision is a pure | ||
| function of the mode plus four facts about the machine, so every refusal is | ||
| asserted directly rather than left inside an `if` in the middle of a teardown | ||
| path: | ||
|
|
||
| - both active modes downgrade to a notice after a failed command; | ||
| - both refuse on all four managed channels, and name a command for each; | ||
| - both report elevation rather than attempting an unwritable install; | ||
| - `prompt` degrades without stdin while `auto` does not need it. | ||
|
|
||
| The channel table covers Homebrew under all three prefixes, npm for global, nvm | ||
| and project-local layouts, apt with and without each half of its rule, both | ||
| winget delivery shapes, and four unrecognised layouts that must fail open. | ||
| Classification splits on both path separators rather than using | ||
| `Path::components`, so the winget cases run on every host instead of only on | ||
| Windows. | ||
|
|
||
| Verified end to end: writing `mode` into a real config file that already had a | ||
| `license_key` and an unknown `[update] future_key` left both intact. | ||
|
|
||
| `cargo test -p perry`: 914 passed, 0 failed. | ||
| </details> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| ### Fixed | ||
|
|
||
| Five defects in the update surface, all found in review of | ||
| [#7749](https://github.com/PerryTS/perry/pull/7749) after it had merged. | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| **The config warning escaped the rules that were meant to silence it.** The | ||
| "unrecognized `[update] mode`" line was printed inside `UpdatePolicy::resolve`, | ||
| before the precedence rules it sits behind had been applied — so it reached | ||
| stderr during `--format json`, in CI, with a piped stderr, and under `--quiet`. | ||
| Those rules exist to keep exactly those runs silent, and the one line whose job | ||
| was to report a config problem was the one line ignoring them. It is now held on | ||
| the policy and emitted at the single point where the run is known to be speaking | ||
| at all. | ||
|
|
||
| **The notify interval throttled on time alone, so it swallowed the next | ||
| release.** The documented contract is that the interval throttles repeats of | ||
| *the same* update. Keyed only on a timestamp, it also suppressed a **different** | ||
| version that arrived inside the window — so somebody setting a week-long | ||
| interval to stop being nagged about one release would also have been denied the | ||
| release that fixed it. The cache now records which version it announced, and a | ||
| different version is announced regardless of the interval. | ||
|
|
||
| **The interval comparison was signed.** `Duration::as_secs() as i64` goes | ||
| negative for a large enough configured value, and a negative interval reads as | ||
| already-elapsed — so an absurd value would have notified on *every* run instead | ||
| of suppressing. The comparison is unsigned. | ||
|
|
||
| **Two `perry` processes could corrupt the cache.** Every write used one shared | ||
| `*.json.tmp`, so two writers each wrote it and each renamed it: the loser's | ||
| rename landed a file the winner was still writing into. Each write now builds | ||
| its own temporary name. | ||
|
|
||
| **A refresh could erase a notice recorded while its request was in flight.** | ||
| `fetch_latest_version` read the notice state *before* issuing its request and | ||
| wrote it back afterwards, overwriting anything recorded in between — telling the | ||
| user about the same release twice. The read-modify-write pairs are now | ||
| serialized by a lock file, and the refresh re-reads inside that lock immediately | ||
| before replacing. | ||
|
|
||
| <details> | ||
| <summary><b>Tests</b></summary> | ||
|
|
||
| Two new contract tests, both sabotage-verified — reverting either fix turns its | ||
| test red: | ||
|
|
||
| - a different version is announced regardless of the interval, and never having | ||
| announced anything counts as "not this version"; | ||
| - an enormous interval still suppresses rather than wrapping into notifying. | ||
|
|
||
| The existing interval tests are unchanged in intent: they now go through a | ||
| helper that holds the announced version constant, so they still exercise only | ||
| the interval arithmetic. | ||
|
|
||
| `cargo test -p perry`: 904 passed, 0 failed. | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </details> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.