Repository navigation
feat(harbor): add the SWITCH tab - #285
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds the SWITCH tab to the harbor, step 5 of the switchboard plan. From a phone, it shows who holds each card and lets a paired device switch the card to an engine or stop the engine that holds it.
What a user sees
berth.tomlwith its state and message, and its models with a dot for a loaded one.berth pair.Keys 1 to 4 now open CARD, SWITCH, ENGINES and ABOUT, in the order the tabs show. Before this, 2 opened ENGINES and 3 opened ABOUT.
How it works
The harbor has no start or stop logic of its own.
GET /v1/boardforwards to the gateway'sGET /v1/berth/board.POST /v1/board/switchand/v1/board/stopforward toPOST /v1/berth/switchand/v1/berth/stop. The harbor sends the node's API key with each. The harbor reads the key with the newapikey.Loadand never creates it.berth harbor --gatewayand--key-fileoverride where the gateway and the key are.Reading the board needs no pairing. Each action and
POST /v1/pair/coderefuses, in this order: a cross-site request (403), a request withoutX-Berth: 1(403), and a device that is not paired (401). A body other than{"engine":"NAME"}gets 400. Only the engine name goes on to the gateway. A missing key gives 503, and the tab says how to fix it. The guard still refuses every other non-GET request.Load for a llama-swap model is step 6 of the plan, and the
/gui/index redirect is step 7. Neither is in this PR.Proof
internal/harbor/switchboard_test.goruns against a real berthd with a pairing file and a fake gateway. It checks that an unpaired read reaches the gateway with the key, and that each gate gives its status and code without calling the gateway. It also checks that a paired switch forwards only{"engine":"strata"}with the bearer key, that a bearer token works as the cookie does, that a 409 from the gateway reaches the page unchanged, that the pair code gives an https link and a QR data URL, and that a missing key gives 503. I removed each gate in turn (cross-site, X-Berth, pairing, empty engine, body reshaping, bearer header, missing key, https link), and each removal failed a test. I deleted one test that passed even without the guard it was meant to cover.?demo, 42 checks passed. They cover the cards, the cordon, the picker and its memory across a reload, which buttons each state gets, the pinned holder, the model list, 44 px buttons, no sideways scroll on the phone, the new key order, the no-key message, and no console errors.go build,gofmt,go vet,go test ./..., the Windows build and vet, and golangci-lint (0 issues) pass locally.Still to do: the plan's last check, a switch from a paired iPhone over the tailnet, after this build runs on aphotic.