Repository navigation
test(machines): the bridge tunnel's own checks run again, and an unknown token fails its case - #3663
Conversation
…own token fails its case ## Change Follow-up to #3655, which fixed two races in the SSH tunnel stand-ins of `server/machine-core-choice.test.ts`, `server/machine-herdr-choice.test.ts` and `server/machine-herdr-switch-retry.test.ts` by replacing `MachineManager.tunnel` itself. Review found that this lost coverage: - the real `tunnel` (it refuses a descriptor whose port or token is not one of this app's with "Invalid bridge credentials", frees a local port, forwards it and builds the address and token) ran in none of these files, and no test anywhere reached "Invalid bridge credentials"; - the core-choice relay answered 401 to any token none of the case's bridges holds, so a wrong token the app sent was refused like a bridge would refuse it instead of failing the case. ### Fix - A shared stand-in (`server/machine-tunnel.fixture.ts`) mocks `SshConnection.forward` again, so `MachineManager.tunnel` runs whole. `forward`'s stand-in still serves the relay on port 0, never on the number `freePort` freed (the race #3655 fixed); `tunnel` is wrapped only to point the address it returned at the relay `forward` was asked to open at that number, with the token it returned. - The core-choice relay answers 401 only to the tokens of cases already ended (a late move-badge read of theirs, the other race #3655 fixed). Any other token must again be the token of the bridge it reaches. - A focused test drives the real `tunnel` with a descriptor whose port or token is invalid: it rejects with "Invalid bridge credentials" and forwards nothing, while the same valid descriptor opens a tunnel. ### Seen in production code, not changed here `MachineManager.tunnel` takes a port number from `freePort` (bind port 0, close it) and only then has `ssh -L` bind it, so another local process can take the number between the two. In multiplexed mode the forward then fails. In direct mode (`forward` polls until something listens on the port), the app could take another process's listener for the tunnel and send it the bridge's token. Letting ssh choose the port (`-L 0:...`) or binding before handing it over would remove that window. ## Validation Each file 400 times, 16 copies at a time on this host (load 20-32), as CI's unit lane runs them (`bun test --timeout 60000`, `HERDR_TEST_MODE=unit`): - `machine-core-choice.test.ts`: 400 of 400 passed - `machine-herdr-choice.test.ts`: 400 of 400 passed - `machine-herdr-switch-retry.test.ts`: 400 of 400 passed The restored checks bite (in a scratch copy, discarded): - `tunnel` returning a well-formed wrong token: 44 of 52 core-choice tests fail on the relay's token assertion; with main's tests all 44 pass. - `tunnel`'s credential check disabled: all 8 new cases fail. `bun run check fast` passes.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Merge passMerged head
Test-only PR (three server unit test files and one new fixture). Two reviewers at this head: Claude (Opus) CLEAR, Codex Terra CLEAR with no findings. It restores the coverage #3655 gave up, which the merge pass merged before reading its author's request to hold it: Left, LOW (Claude, not run): the fixture matches a tunnel to its relay by the freed local port alone, in call order; that holds while the stand-in |
…e 0.5.3 release (#3693) ## Change The low-priority review findings left for after the 0.5.3 release, from the reviews of #3653, #3654, #3656, #3663, #3666, #3668 and #3682. One commit each: **Product (changelog fragment `post-release-lows.md`)** - `fix(opencode)`: a verified pane keeps the right OpenCode pid. A pid herdr did not report is unknown, not `-1`; an older verification ending after a newer one does not put its older pid back, nor a pid over the newer one's empty reading; a read with nothing in front clears the pid, as before. (#3653; the #3653 suggestion to keep the pid on an empty read was dropped in review: a still-running pid is no proof it is the pane's job.) - `fix(opencode)`: a known OpenCode pid is followed up its parents to the shell, so a shell with more than 256 processes still finds its stopped OpenCode. Checked on a real `/proc` with 301 children. (#3653) - `fix(ssh)`: a failed forward's error leaves out the lines `ssh -v` writes without the debug prefix (`Authenticated to`, transfer totals, some builds' banner). (#3666) - `fix(ci)`: the runner route asks the Actions API again only after a server error or no answer (a 4xx ends it), each attempt bounded to a minute. (#3682) **Tests and docs** - `test(ssh)`: which ssh's word a forward waits for is its own function, with a test for Git for Windows', Windows' own and other OpenSSH. (#3666) - `test(chat-fallback)`: the two waits on the chat's callbacks fail with a reason after 10 s instead of hanging. (#3668) - `test(copilot-chat)`: New messages is looked up and clicked in one page step. (#3654) - `test(machines)`: the tunnel fixture matches a relay by both of its ports. (#3663) - `test(pages)`: the stale-deploy gate is checked on the parsed `pages.yml`. (#3656) - `docs(pages)`: `docs/development.md` describes the `current` / `deploy` split. (#3656) Left out on purpose: a test seam for `MachineManager.verify` (60 tests already reach its privates the same way), cancelling the move-badge read in `MachineManager.stop()` (its answer is already dropped and the read is bounded at 30 s), and `quietPort` across processes (a 1-in-~12k pick collision; it needs cross-process claims). Workflow changes from those reviews wait for the owner. ## Validation - Each commit's own tests (ssh 35, opencode/status 443, route 25, pages 57, machine tunnel 70) and `bun run typecheck`: pass. - `scripts/chat-fallback-browser-qa.ts`: pass locally. `scripts/copilot-chat-browser-qa.ts`: **not run locally** (this host's node names the fixture process `MainThread`, so the script stops before the changed line); CI runs it. - `bun run check fast` on the branch rebased onto 1f4368e: pass (16152 pass, 0 fail).
Follow-up to #3655, which the owner kept merged (2026-11-11). #3655 fixed two races in three machine tests by mocking
MachineManager.tunnelitself, and so lost two things: these flows no longer ran the real tunnel and its "Invalid bridge credentials" check (server/machines.ts, near line 1961), which no other test reached, and the core-choice relay answered 401 to any unknown token, so a wrong token the app sent no longer failed the case. This PR brings both back and keeps both races fixed.Change
Follow-up to #3655, which fixed two races in the SSH tunnel stand-ins of
server/machine-core-choice.test.ts,server/machine-herdr-choice.test.tsand
server/machine-herdr-switch-retry.test.tsby replacingMachineManager.tunnelitself. Review found that this lost coverage:tunnel(it refuses a descriptor whose port or token is notone of this app's with "Invalid bridge credentials", frees a local port,
forwards it and builds the address and token) ran in none of these
files, and no test anywhere reached "Invalid bridge credentials";
bridges holds, so a wrong token the app sent was refused like a bridge
would refuse it instead of failing the case.
Fix
server/machine-tunnel.fixture.ts) mocksSshConnection.forwardagain, soMachineManager.tunnelruns whole.forward's stand-in still serves the relay on port 0, never on thenumber
freePortfreed (the race test(machine-core-choice): the tunnel's relay listens on a port of its own, and refuses another case's late reads #3655 fixed);tunnelis wrapped onlyto point the address it returned at the relay
forwardwas asked toopen at that number, with the token it returned.
ended (a late move-badge read of theirs, the other race test(machine-core-choice): the tunnel's relay listens on a port of its own, and refuses another case's late reads #3655 fixed).
Any other token must again be the token of the bridge it reaches.
tunnelwith a descriptor whose port ortoken is invalid: it rejects with "Invalid bridge credentials" and
forwards nothing, while the same valid descriptor opens a tunnel.
Seen in production code, not changed here
MachineManager.tunneltakes a port number fromfreePort(bind port 0,close it) and only then has
ssh -Lbind it, so another local process cantake the number between the two. In multiplexed mode the forward then
fails. In direct mode (
forwardpolls until something listens on theport), the app could take another process's listener for the tunnel and
send it the bridge's token. Letting ssh choose the port (
-L 0:...) orbinding before handing it over would remove that window.
Validation
Each file 400 times, 16 copies at a time on this host (load 20-32), as CI's
unit lane runs them (
bun test --timeout 60000,HERDR_TEST_MODE=unit):machine-core-choice.test.ts: 400 of 400 passedmachine-herdr-choice.test.ts: 400 of 400 passedmachine-herdr-switch-retry.test.ts: 400 of 400 passedThe restored checks bite (in a scratch copy, discarded):
tunnelreturning a well-formed wrong token: 44 of 52 core-choice testsfail on the relay's token assertion; with main's tests all 44 pass.
tunnel's credential check disabled: all 8 new cases fail.bun run check faston this branch, rebased on main 9c07ec1: pass (16117 pass, 0 fail).The production race in
MachineManager.tunnelnoted above is handled in its own PR.