…he fleet preview (#3955)
## Change
Changes what `ovis add` (also `ovis link` and `ovis login`) does under
the fleet preview, `OVIS_PREVIEW=fleet`
(`server/preview.ts`, from #3938, which this pull request builds on). No
release sets that variable. The plugin
reads it from its environment or its
settings file (`env`, `.env`), the merged settings the server it starts
gets. With it unset, `ovis add` does what
`main` does.
Under `OVIS_PREVIEW=fleet`, `ovis add` without `--approve`, in the order
a person meets it:
- If its output or its input is not a terminal, with or without
`--print`, it does not start the sign-in. It
prints one line saying that adding this PC needs a terminal and exits 1.
It lists nothing and shows no code.
With the preview unset, `--print` behaves as before.
- The sign-in itself is unchanged.
- After the sign-in, it names the account that signed in and the
provider it used: `Signed in as Ovis account
<id> (signed in with GitHub). Press Enter to show the QR code for this
account's phone, or press Ctrl+C if that is
not your account:`. Until Enter is pressed, this PC is not listed in
that account and no code is made.
- A line that is empty, or holds only spaces, lists this PC in the
account (`This PC is listed in that account as
<name>.`). It then shows the QR code as before, on a screen of its own,
or with `--print` as lines that stay.
- Any other line, or the end of the input (Ctrl+D), prints `The QR code
was not shown, and this PC was not listed
in that account.` with what to run again, and exits 1.
- Some lines answer nothing, and the question is asked again:
- a line that comes less than 1.5 s after the question shows;
- the first line, where the terminal's input could not be emptied as the
question showed.
This is the same rule the existing questions of `ovis add` use.
- Under the preview, two variables change what the command names:
- The app the server pairs with (`OVIS_RELAY_APP_URL`; its offers carry
it) replaces `app.ovis.sh` in the code
lines of `ovis add` and `ovis link --code` and in the `--approve` line.
- `OVIS_CLI_NAME`, for a wrapper that runs the plugin under another
name, replaces `ovis` in the commands
`ovis add` says to run.
`ovis add --approve` gets neither the terminal check nor the Enter step.
Under the preview, only the app it names
changes.
With `OVIS_PREVIEW` unset (or set to a list without the word `fleet`),
nothing changes, whatever
`OVIS_RELAY_APP_URL` and `OVIS_CLI_NAME` say. The one change in
`scripts/plugin.ts` passes `OVIS_RELAY_APP_URL` on
to `link`, which reads it only under the preview.
A changelog fragment is included
(`changelog.d/add-confirm-under-fleet-preview.md`).
Five follow-ups rated low in review are in #3957.
## Validation
On this head, which holds `main` 9d17bcd: `main` was merged in after
#3953 changed the same files (two conflicts,
both in import lines: `linkSettings` now comes with `link`'s deferred
import of `scripts/plugin-link.ts`):
- `bun run typecheck`: passed.
- One run of `bun test scripts/plugin-link.test.ts
scripts/plugin.test.ts`: 213 pass, 0 fail (with `main`'s new tests
of a checkout whose packages are not installed).
- `bun run check fast`: passed (workflow syntax, generated types and
themes, typecheck, build; unit tests 17,705
pass, 0 fail, 54 skip).
- macOS arm64 (27.0.1), Bun 1.4.2, in a fresh clone of this pull
request's head (535de9e): the same two test
files, 211 pass, 2 skip, 0 fail.
- `main` e5c6a8e and this branch two revisions before this head (before
the settings-file change and before
`main` 9d17bcd was merged in), side by side
with `OVIS_PREVIEW` unset, by a reviewer that did not write it, through
the real `scripts/plugin.ts`: `add`,
`add --print`, `add --approve`, `link --code`, `status`, `help` and an
unknown command; piped and at a pty; the two
variables unset and set; `OVIS_PREVIEW` unset, empty, `fleets` and
`no-fleet`: 112 runs a side under `strace`,
against a local stand-in for the PC and an account service that refuses
connections. Output (the pty's bytes
too), exit codes, the calls to the PC and the `connect` and `execve`
calls were the same. These runs reach the
refusal, the sign-in failing, `link --code` and usage; the QR, Enter and
approve paths are compared in the
in-process runs below.
- New tests in `scripts/plugin-link.test.ts`:
- under the preview: the refusal without a terminal (output, input,
`--print`, and a list that names `fleet`
beside another word); the account named before anything is listed, with
Enter, other lines (`no`, `y`, ` x `)
and Ctrl+D; the line that comes too soon and the first line where the
input could not be emptied; both
variables taking effect; the preview set only in the plugin's settings
file (the refusal through the real
command, the Enter step in-process through the plugin's own merge of its
settings);
- a control with the preview unset (also `""`, `fleets`, `no-fleet`),
run once with nothing set and once with
both variables set. It expects `main`'s lines: `--print` to a pipe
writes the code, no Enter step, `app.ovis.sh`
and `ovis` in what is printed;
- one run of the real `scripts/plugin.ts add` with its output piped: the
refusal under the preview, `main`'s
sentence without it.
- These tests fail when the preview condition is removed:
- The preview-unset controls failed with the condition removed from the
terminal check and the Enter step (on
the first version of this branch).
- The control also failed with the condition removed from the app name
and from the command name (on this
code).
- `main` 9d17bcd and this head, with `OVIS_PREVIEW` unset, compared
side by side by the author (the real
`scripts/plugin.ts` also for `status`, `stop` and `help`):
- `link` was driven in-process, with the test file's fake PC, fake
account service and a fixed clock, through 14
runs: plain add, `--print` at a terminal, `--print` with the output and
with both output and input not a
terminal, output only or input only not a terminal, the account service
off (with and without `--print`),
already in an account, nobody scanning for 30 minutes, Ctrl+C while the
code shows, a device kept out by
Enter, `link --code`, and `--approve`.
- The real `scripts/plugin.ts add` and `add --print` were run with
stdout a pipe, with the account service
unreachable and off.
- Each was run three ways: nothing set, `OVIS_RELAY_APP_URL` set,
`OVIS_CLI_NAME` set; the real command also
with the two names set only in the settings file. The output, exit
codes, calls to the PC and calls to the
account service were the same.
Not run: the Enter step with a person at a real terminal, or through the
real command with the preview only in
the settings file; under the preview, the QR and approve paths through
the
real command (in-process only); a real account service, relay or phone;
Windows.
The small signal and load faults the reviews of #3940 and #3944 left in the plugin scripts. Nothing in
install.ps1orinstall.sh.What changes
scripts/plugin-tui.ts,scripts/plugin.ts). Since fix(install): the launcher listens for SIGTERM and SIGHUP before it starts its command, so one in between no longer leaves the command running #3944 the SIGTERM/SIGHUP listeners are added before the spawn. They calledchild.killwithout a guard, so when the spawn threw, a later signal hit an unsetchild: aTypeErrorinrunTui, or aReferenceError(theconstbefore its declaration) inplugin.ts. Both now callchild?.kill(signal)and take their listeners off on every way out, the throwing one included. Inplugin.tsthe three places that hand a command on to the release Settings → Updates installed (link,phone-setup, an unknown command) now share onehandOn().runTui's injectedonreturns the function that takes the handler off again.scripts/plugin-launch.ts). The build records the signal with??=, so a SIGTERM followed by a SIGHUP during a step that then ends with 0 gives 143, not 129.scripts/plugin-launch.ts). I chose to pass the record explicitly rather than reset it in eachmain(). The record now belongs to thefromSourcecall that runs the build steps, andrun()fills it through a parameter. No module-level state is left, so a signal an earlierrun()ormain()in the same process was sent cannot stop a later build. A laterstartnever read the record anyway: its one child gets the signal itself. Resetting inmain()would still leave a strayrun()call writing module state that the next caller sees. The CLI cannot reach this (one command per process), so it is covered by a unit test.scripts/plugin-launch.ts).run()'s table knew only HUP, INT and TERM, so a child killed by SIGKILL gave 128. It now usesos.constants.signalsand gives 137 for SIGKILL and 131 for SIGQUIT.stopandstatusload without application packages (scripts/plugin.ts). Loadingplugin.tspulled inqrcode-generatordirectly, and throughshared/relay-offer.tsandscripts/plugin-link.tsit also loaded@noble/*,tweetnacl,base64-jsandjsonc-parser. Anode_modulesfolder that exists but lacks them turns Bun's auto-install off, sostopfailed withCannot find package 'qrcode-generator'and a server running from that checkout could not be stopped through herdr. The QR code,decodeOfferandplugin-link.tsare now imported in the commands that use them.COMMAND_ALIASESmoves toscripts/plugin-runtime.ts, which loads no packages;plugin.tsstill names it, so install.sh'sgrep COMMAND_ALIASESstill matches.plugin-link.tskeeps its static import ofqrcode-generator: that file needs the relay's and the account's packages at load anyway, andplugin.tsnow loads it only forlinkandpair --approve.scripts/plugin.ts stopandstatusload with no packages at all (the test below runs them with an emptynode_modules), so no case is left where the fallback cannot load the sources.phoneSetuphanded on to the release with no signal handling at all. A run on main with a stand-in release showed the result: a SIGTERM or SIGHUP sent to the plugin process ended it (143 / 129), and the release's phone-setup kept running in the pane with nobody waiting for it. It holds the pane's terminal and is the one process that must be told, so it now follows the same rule aslink, throughhandOn().Second push (69249e2), on the merge pass's review of 69ebe4b
A. Packages load before a command changes anything. At 69ebe4b the deferred imports came after the first change. With the QR package missing,
pairandphone-setupasked the app for a pairing code, which replaces the one another device may be using, andphonerantailscale serve; each then failed at the import. Every command that needs a package now loads it first:pairPOST /api/devices/pair/start(a new pairing code)pairingParts()(QR code + relay offer), at the top ofpair, beforehealth()phone-setup(the checkout's own)pairpairingParts()right after the hand-on check, before its first line, passed topair(so it is not reported as "Could not read phone setup")phonetailscale serve --yes …(publishes the app)qrDrawer(), the first line ofphonelink/add/loginplugin-link.tslink()import("./plugin-link.ts")right after the hand-on check, beforehealth()pair --approvePOST /api/relay/pairing(a decision)import("./plugin-link.ts"), the first line ofapprovePairingsA run in a copy with an empty
node_modulesand a stand-in app andtailscale. At 69ebe4b,pairsentPOST /api/devices/pair/startand failed at the import;phone-setupsent the same and said "Could not read phone setup";phoneranserve --yes --bg --https=443 ….linkandpair --approvealready changed nothing. Here, all five fail withCannot find package 'qrcode-generator': no request that changes anything, and noserve. The test isplugin.test.ts"the commands that need a package fail before they change anything…", POSIX only (its stand-intailscaleis a shell script).B. SIGINT is passed on to the release (
handOn). At 69ebe4b a SIGINT sent to the checkout alone hit an empty handler: the release got nothing, and the checkout waited. NowhandOnpasses it on like TERM and HUP, except on Windows: there Bun ends a child outright for any signal it is sent, without the release's own Ctrl+C cleanup, and a Ctrl+C reaches every process of the console anyway. I settled the double delivery by a run, with a stand-in release that counts its SIGINTs and ends 0.5 s after the first:So a Ctrl+C now reaches the release twice. That is harmless for every release this hands on to:
link'shaltreturns at once on a second signal (if (stop.signal.aborted) return, written for exactly that), andphone-setuphas no SIGINT handler, so it ends at the first. Tests:<command>: … passes it a SIGINT and exits as it did" forlink,phone-setupand an unknown command. They fail at 69ebe4b (10 s timeout, the checkout waiting).<command>: ends with the release on a Ctrl+C, which reaches both through their process group".C. Wording. I chose the smaller truthful one: the launcher still passes on only TERM and HUP (a QUIT sent to it alone ends it and leaves its child, as on main). The title and the changelog fragment now say only what changed: how the launcher reports a child's death by any signal (128 + n, 137 for SIGKILL). The fragment also names the SIGINT of B and the "nothing changed" of A.
Not changed (outside the three points): Codex's LOW at plugin-launch.ts:73. A build step that ends non-zero by the second of two signals returns its own code (129) rather than the first signal's (143).
Validation
All runs were on Linux (Bun 1.4.2) with
TMPDIR=$HOME/.cache/ovis-tmp/.... Each case that touches the plugin used a scratch state, config and app-state directory and a quiet port above 20000 (quietPort). Nothing ran the real pluginstartorstopagainst the default state directory.Second push, on 69249e2 (its base is still 869ec34: main's two newer commits touch no file of this PR, and in what plugin.ts imports only
server/owner-guard.ts, with no new import. GitHub's run tests the merge with main.)bun run check fastthrough the heavy-slot wrapper passed: workflow syntax, generated types and themes, typecheck, build, and 17665 unit tests passed, 0 failed, 54 skipped.plugin-launch20/20,plugin-tui20/20,plugin20/20,plugin-link19/20. The one failure (run 17) was the existing test "never takes a line typed for a request that went away as the answer to the next one shown in the same look", which timed out at 5.8 s against its 5 s limit while the host's load average was 88. That test exerciseslink()in-process; this PR's only change toplugin-link.tsis the removedCOMMAND_ALIASESconstant, and the test file's only change is that import.plugin-launch39 pass / 8 skip,plugin-link131 / 3 skip,plugin-runtime2,phone-setup3.plugin-tuiandpluginfail the same 9 and 27 tests by name as main. The new SIGINT and missing-package cases are POSIX only and skipped there.First push, on 69ebe4b
bun run check fastthrough the heavy-slot wrapper on the head 69ebe4b (rebased on 869ec34). It passed: workflow syntax, generated types and themes, typecheck, build, and 17658 unit tests passed, 0 failed, 54 skipped.HERDR_TEST_MODE=unit bun test ./scripts/<file>:plugin-launch.test.ts: 20/20plugin-tui.test.ts: 20/20plugin.test.ts: 20/20plugin-link.test.ts: 20/20plugin-runtime.test.tsandphone-setup.test.ts, on 7f7a4f43 (the same change before the rebase onto 869ec34), from a bundle clone. The POSIX-signal cases are skipped on Windows (it.skipIf(win32)).plugin-launch39 pass / 8 skip,plugin-link131 pass / 3 skip,plugin-runtime2 pass,phone-setup3 pass.plugin-tui(7 pass, 1 skip, 9 fail) andplugin(25 pass, 13 skip, 27 fail) fail on Windows on main too. I ran them on main's commit fccc9c4 in the same VM, and the failing tests are the same 9 and 27 by name. Neither file is in CI's Windows set. The newrunTuispawn-throws case and the empty-node_modulescase pass on Windows.Before and after. Each new regression case was run against main's sources (main's scripts with the new test files) and fails there:
plugin-tui.test.ts"stops listening when the program cannot be started…"plugin.test.ts"link / a-later-command: stops listening when the release cannot be started…"signal: null)plugin-launch.test.ts"names the first of two signals…"plugin-launch.test.ts"does not stop a build at a signal an earlier run in the same process was sent"{first: 143, code: 143, steps: 1}{first: 143, code: 0, steps: 3}plugin-launch.test.ts"exits with 128 + the platform's number…"plugin.test.ts"load and answer with an empty node_modules…"Cannot find package 'qrcode-generator'status→down http://127.0.0.1:<port>,stop→Ovis is not running, both 0plugin.test.ts"phone-setup: listens before the release starts, passes it a SIGTERM / SIGHUP…"spawn 0 0(no listener), exit 143 / 129, release left runningspawn 1 1, exit 3 / 4 (the release's own), none leftThe tests showing that link, an unknown command and
runTuilisten before the spawn (spawn 1 1, and the order SIGINT, SIGTERM, SIGHUP, then spawn) pass on main too: since #3944 that order is right there. They add the coverage the #3944 review asked for.After the runs,
pgrep -afon my scratch path found onlysleep 7200restore leases thatserver/pc-install.tsleaves on purpose for its two-hour cleanup, started bycheck fast's unit tests. I ended them, andpgrepthen found nothing. Neither VM run left one: each Windows run's leftover shell came from the existingstop > returns only once the server's process group is gonecase, which fails on Windows on main too. I ended it, and both clones were removed.Not run:
bun run check full, the integration suite, the browser jobs and macOS. GitHub's run on this head covers them.