Skip to content

Restore the version a trial replaced - #17

Merged
chris-peterson merged 1 commit into
mainfrom
restore-the-version-a-trial-replaced
Sep 17, 2026
Merged

chris-peterson merged 1 commit into
mainfrom
restore-the-version-a-trial-replaced

Conversation

@chris-peterson

@chris-peterson chris-peterson commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Context

npm run trial:on puts a checkout on your PATH as git fi so a change can be run for a few days before shipping. Ending the trial reinstalled @gettyimages/git-fi with no version, which is whatever npm calls latest — so a trial started on 1.2.1 could hand back 1.3.0, and the developer is left on a version they never chose to install. A trial borrows the global install; it should give back the one it borrowed.

trial:on now records the installed version before npm link overwrites it, and trial:off reinstalls that exact version.

Review guide

The one thing to check — what counts as "a version to come back to":

  • scripts/trial.sh — a linked checkout and a registry install both report a version, so the version alone can't tell them apart; the discriminator is resolved, which is a file: URL only for a link. Verified against the real global tree, which currently holds a link: the probe correctly returns empty. An absent resolved (some npm versions omit it for a registry install) reads as not-a-link, which is the right answer.

Supporting:

  • scripts/trial.sh — where nothing was recorded, the latest is installed and the run says so. Silently leaving the developer with no git fi at all would be the worse failure.
  • scripts/trial.sh — only the marked block is the script's to delete, so a reference to .trial/completions copied elsewhere in .zshrc survives it — and .trial/ goes on the next line, leaving that fpath entry pointing at nothing. It names the lines rather than editing one the developer wrote. This is live on at least one machine.
  • SPEC.md — the two new requirements.

Approach & trade-offs

trial:off still needs the network, and that is not fixable here. tack and beacon end a trial with no network at all, because both install a wrapper in ~/.local/bin that points at whichever copy they mean — so reverting is a local file write. git-fi can't take that shape: ~/.local/bin sits behind /opt/homebrew/bin in a normal PATH, where npm links, so the wrapper would be shadowed. For an npm package the registry is the install path. Restoring the exact version is the part that was actually broken; removing the network round trip would mean changing how git-fi installs.

Testing

npm test — 226 pass. The installed_version probe was exercised against the real global tree in its linked state, which is the case the file: check exists for; it returns empty, so trial:off from here reports the no-recorded-version path rather than inventing a version.

@chris-peterson chris-peterson self-assigned this Sep 16, 2026
@chris-peterson chris-peterson added the enhancement New feature or request label Sep 16, 2026
@chris-peterson chris-peterson added this to the 1.3 milestone Sep 17, 2026
`trial:off` reinstalled whatever npm called latest, so ending a trial that
started on 1.2.1 could hand back 1.3.0. A trial borrows the global install;
it should give back the one it borrowed, not a different version chosen by
whatever shipped meanwhile.

`npm link` overwrites that install, so the version is read before the link
and kept under `.trial/`. The probe reports which of three states it found:
a version, a checkout already linked, or nothing installed. The first two
are indistinguishable by version alone and only one has a version to come
back to, and being told no published copy is installed when one is merely
shadowed costs the pin for good.

Ending a trial touches the global install only when there is something to
hand back. A second `trial:off` finds no record, sees a registry install,
and leaves it alone — reinstalling there would replace a version the
developer chose with whatever is newest, which is the outcome this exists
to prevent. A recorded value that is not a bare version is refused rather
than installed, since `npm i -g <pkg>@<spec>` reads URLs, git refs and
aliases from the same position.

The completion cleanup reports what it cannot remove. Only the marked block
is the script's to delete, so a reference to `.trial/completions` copied
elsewhere in `.zshrc` survives it, and `.trial/` goes on the next line,
leaving that `fpath` entry pointing at a directory that no longer exists.
Naming the lines is the right amount of help; editing one the developer
wrote is not the script's call.

This tracks how tack and beacon end a trial: run the install path a user
has rather than a parallel one, and land exactly what they would.
@chris-peterson
chris-peterson force-pushed the restore-the-version-a-trial-replaced branch from 08bdc08 to 117e39c Compare September 17, 2026 21:12
@chris-peterson
chris-peterson marked this pull request as ready for review September 17, 2026 21:12
@chris-peterson
chris-peterson merged commit cf3ded2 into main Sep 17, 2026
9 checks passed
@chris-peterson
chris-peterson deleted the restore-the-version-a-trial-replaced branch September 17, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant