Repository navigation
Forget a peer's manual entry when the TUI removes it from the cluster #172
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
Noah-Tervalon-Nvidia
merged 7 commits into
develop
from
fix/tui-remove-member-manual-entry
Oct 30, 2026
+214
−21
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
29098ac
Forget a peer's manual entry when the TUI removes it from the cluster
Noah-Tervalon-Nvidia 512ef3d
Merge remote-tracking branch 'public/develop' into review/pr172
Noah-Tervalon-Nvidia 41e9b94
test(tui): use assert.Contains after the develop merge
Noah-Tervalon-Nvidia 3c32c34
refactor(tui): forget the manual entry inside removeMember
Noah-Tervalon-Nvidia 8cb7eb3
test(tui): move the member-removal tests into nodes_test.go
Noah-Tervalon-Nvidia 1f4bc21
fix(tui): forget every manual entry of a removed peer
Noah-Tervalon-Nvidia 1913a87
test(tui): follow the PAIR test style in the removal tests
Noah-Tervalon-Nvidia 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package ui | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "net" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "nvpair-tui/rpc" | ||
|
|
||
| tea "github.com/charmbracelet/bubbletea" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // removalCall is one request removalBroker received. | ||
| type removalCall struct { | ||
| method string | ||
| params json.RawMessage | ||
| } | ||
|
|
||
| // removalBroker is a broker that records every call and answers it, failing | ||
| // each call to the method named by fail. | ||
| func removalBroker(t *testing.T, fail string) (*rpc.Client, <-chan removalCall) { | ||
| t.Helper() | ||
| c1, c2 := net.Pipe() | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| t.Cleanup(func() { | ||
| cancel() | ||
| c1.Close() | ||
| c2.Close() | ||
| }) | ||
| client := rpc.NewClient(c1, c1) | ||
| go client.Run(ctx) | ||
|
|
||
| calls := make(chan removalCall, 8) | ||
| broker := rpc.NewCodec(c2, c2) | ||
| go func() { | ||
| for { | ||
| req, err := broker.Read() | ||
| if err != nil { | ||
| return | ||
| } | ||
| calls <- removalCall{method: req.Method, params: req.Params} | ||
| reply := &rpc.Message{JSONRPC: "2.0", ID: req.ID, Result: json.RawMessage(`{}`)} | ||
| if req.Method == fail { | ||
| reply = &rpc.Message{JSONRPC: "2.0", ID: req.ID, | ||
| Error: &rpc.RPCError{Code: -32000, Message: "refused"}} | ||
| } | ||
| _ = broker.Write(reply) | ||
| } | ||
| }() | ||
| return client, calls | ||
| } | ||
|
|
||
| // confirmRemoval arms and confirms removing the selected node, then feeds each | ||
| // reply back into the view until it reports an outcome. | ||
| func confirmRemoval(t *testing.T, v *nodesView) { | ||
| t.Helper() | ||
| require.Nil(t, v.removeSelected(), "removal was dispatched without confirmation") | ||
| cmd := v.handleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("y")}) | ||
| for cmd != nil { | ||
| msg := cmd() | ||
| if _, done := msg.(nodeActionMsg); done { | ||
| v.Update(msg) | ||
| return | ||
| } | ||
| cmd = v.Update(msg) | ||
| } | ||
| require.FailNow(t, "the removal ended without reporting an outcome") | ||
| } | ||
|
|
||
| // wantCall checks the next request the broker received carries field = value. | ||
| func wantCall(t *testing.T, calls <-chan removalCall, method, field, value string) { | ||
| t.Helper() | ||
| select { | ||
| case c := <-calls: | ||
| require.Equal(t, method, c.method) | ||
| var params map[string]string | ||
| require.NoError(t, json.Unmarshal(c.params, ¶ms), "decode %s params", method) | ||
| assert.Equal(t, value, params[field], "%s %s", method, field) | ||
| case <-time.After(2 * time.Second): | ||
| require.FailNow(t, "broker never received "+method) | ||
| } | ||
| } | ||
|
|
||
| // peerAddedByAddress is a nodes view with one member that was first added by | ||
| // address, selected. | ||
| func peerAddedByAddress(client *rpc.Client) *nodesView { | ||
| v := newNodesView(client) | ||
| v.feeds.discovered = []availableNode{{ | ||
| HostUUID: "peer", Name: "peer", IPAddress: "10.0.0.2", Trusted: true, | ||
| }} | ||
| v.feeds.manual = []manualNode{{ID: "manual:10.0.0.2", Address: "10.0.0.2", HostUUID: "peer"}} | ||
| v.rebuild() | ||
| v.selectedKey = "peer" | ||
| return v | ||
| } | ||
|
|
||
| // TestRemoveMember_ForgetsItsManualEntry checks un-pairing a peer that was added | ||
| // by address forgets that address too. The broker keeps manual entries on disk | ||
| // and re-adds them when it starts, so one left behind brought the peer back. | ||
| func TestRemoveMember_ForgetsItsManualEntry(t *testing.T) { | ||
| client, calls := removalBroker(t, "") | ||
| v := peerAddedByAddress(client) | ||
|
|
||
| confirmRemoval(t, v) | ||
|
|
||
| wantCall(t, calls, "nodes:remove", "nodeUuid", "peer") | ||
| wantCall(t, calls, "node/remove", "id", "manual:10.0.0.2") | ||
| assert.Contains(t, v.status.render(), "remove peer ok", "the removal is reported") | ||
| } | ||
|
|
||
| // TestRemoveMember_ForgetsEveryManualEntry checks a peer added twice, by | ||
| // hostname and by IP, has both entries forgotten when it is un-paired. | ||
| func TestRemoveMember_ForgetsEveryManualEntry(t *testing.T) { | ||
| client, calls := removalBroker(t, "") | ||
| v := peerAddedByAddress(client) | ||
| v.feeds.manual = append(v.feeds.manual, | ||
| manualNode{ID: "manual:peer.lan", Address: "peer.lan", HostUUID: "peer"}) | ||
| v.rebuild() | ||
|
|
||
| confirmRemoval(t, v) | ||
|
|
||
| wantCall(t, calls, "nodes:remove", "nodeUuid", "peer") | ||
| wantCall(t, calls, "node/remove", "id", "manual:10.0.0.2") | ||
| wantCall(t, calls, "node/remove", "id", "manual:peer.lan") | ||
| assert.Contains(t, v.status.render(), "remove peer ok", "the removal is reported") | ||
| } | ||
|
|
||
| // TestRemoveMember_KeepsTheManualEntryWhenUnpairingFails checks a peer the cluster manager | ||
| // would not un-pair keeps the address it was added by: it is still a member, | ||
| // and that address is how it is reached. | ||
| func TestRemoveMember_KeepsTheManualEntryWhenUnpairingFails(t *testing.T) { | ||
| client, calls := removalBroker(t, "nodes:remove") | ||
| v := peerAddedByAddress(client) | ||
|
|
||
| confirmRemoval(t, v) | ||
|
|
||
| wantCall(t, calls, "nodes:remove", "nodeUuid", "peer") | ||
| assert.Empty(t, calls, "a failed un-pairing must not go on to forget the manual entry") | ||
| assert.Contains(t, v.status.render(), "remove peer failed", "the failure is reported") | ||
| } |
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.
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.