-
Notifications
You must be signed in to change notification settings - Fork 70
fix(ui): persist group create/rename/move even during a reload window (fixes #1539) #1573
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
Open
drmzperx
wants to merge
3
commits into
asheshgoplani:main
Choose a base branch
from
drmzperx:fix/1539-group-persist-during-reload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package ui | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| tea "github.com/charmbracelet/bubbletea" | ||
|
|
||
| "github.com/asheshgoplani/agent-deck/internal/session" | ||
| ) | ||
|
|
||
| // These tests are the regression guard for the "new main group only works | ||
| // every second try" / "rename group only works every second try" bug. | ||
| // | ||
| // Root cause: GroupDialogCreate/Rename persisted via saveInstances(), which is | ||
| // SKIPPED while isReloading (and aborts on the mtime external-change check). A | ||
| // group mutation that landed during a storage-watcher reload window was written | ||
| // to memory but never to disk, so when the reload rebuilt groupTree from disk | ||
| // the mutation vanished — hence the alternating "every second try". The fix | ||
| // switches these paths to forceSaveInstances(), which persists regardless of | ||
| // the reload flag (mirroring session creation's "was losing groups!" forceSave). | ||
|
|
||
| // testHomeWithStorage builds a minimally-wired Home backed by real SQLite | ||
| // storage under an isolated temp HOME, with one seed instance so the | ||
| // empty-overwrite guard in saveInstancesWithForce does not refuse the write. | ||
| func testHomeWithStorage(t *testing.T, profile string) (*Home, *session.Storage) { | ||
| t.Helper() | ||
| origHome := os.Getenv("HOME") | ||
| os.Setenv("HOME", t.TempDir()) | ||
| session.ClearUserConfigCache() | ||
| t.Cleanup(func() { | ||
| os.Setenv("HOME", origHome) | ||
| session.ClearUserConfigCache() | ||
| }) | ||
|
|
||
| storage, err := session.NewStorageWithProfile(profile) | ||
| if err != nil { | ||
| t.Fatalf("NewStorageWithProfile: %v", err) | ||
| } | ||
| t.Cleanup(func() { storage.Close() }) | ||
|
|
||
| seed := session.NewInstance("seed", "/tmp/seed") | ||
| h := &Home{ | ||
| storage: storage, | ||
| profile: profile, | ||
| instances: []*session.Instance{seed}, | ||
| groupTree: session.NewGroupTree([]*session.Instance{seed}), | ||
| groupDialog: NewGroupDialog(), | ||
| } | ||
| return h, storage | ||
| } | ||
|
|
||
| func groupPersisted(t *testing.T, storage *session.Storage, name string) bool { | ||
| t.Helper() | ||
| _, groups, err := storage.LoadWithGroups() | ||
| if err != nil { | ||
| t.Fatalf("LoadWithGroups: %v", err) | ||
| } | ||
| for _, g := range groups { | ||
| if g.Name == name { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func TestGroupCreatePersistsDuringReload(t *testing.T) { | ||
| h, storage := testHomeWithStorage(t, "_group_persist_create") | ||
|
|
||
| // Simulate a storage-watcher reload in flight — the window in which the old | ||
| // saveInstances() silently dropped the write. | ||
| h.isReloading = true | ||
|
|
||
| // Drive the real create flow: create-mode dialog + Enter. | ||
| h.groupDialog.Show() | ||
| h.groupDialog.nameInput.SetValue("alpha") | ||
| h.handleGroupDialogKey(tea.KeyMsg{Type: tea.KeyEnter}) | ||
|
|
||
| if !groupPersisted(t, storage, "alpha") { | ||
| t.Error(`group "alpha" created during a reload window was not persisted; ` + | ||
| `create must use forceSaveInstances (saveInstances is skipped while isReloading)`) | ||
| } | ||
| } | ||
|
|
||
| func TestGroupRenamePersistsDuringReload(t *testing.T) { | ||
| h, storage := testHomeWithStorage(t, "_group_persist_rename") | ||
|
|
||
| // Seed and persist a group while NOT reloading. | ||
| h.groupTree.CreateGroup("old") | ||
| h.forceSaveInstances() | ||
| if !groupPersisted(t, storage, "old") { | ||
| t.Fatal("precondition: seed group 'old' should be persisted") | ||
| } | ||
|
|
||
| // Now rename it during a reload window. | ||
| h.isReloading = true | ||
| h.groupDialog.ShowRename("old", "old") | ||
| h.groupDialog.nameInput.SetValue("new") | ||
| h.handleGroupDialogKey(tea.KeyMsg{Type: tea.KeyEnter}) | ||
|
|
||
| if groupPersisted(t, storage, "old") { | ||
| t.Error(`old group name still present after rename during reload window`) | ||
| } | ||
| if !groupPersisted(t, storage, "new") { | ||
| t.Error(`renamed group "new" was not persisted during reload window; ` + | ||
| `rename must use forceSaveInstances`) | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Missing explicit RemoteSession note/
t.Skipper path guideline.These tests exercise group create/rename during a reload window but don't mention RemoteSession or include a
t.Skipexplaining why it's out of scope. Groups here operate purely on localsession.Instancedata (groupTree), so RemoteSession is likely structurally inapplicable — similar to the fork-dispatch precedent — but the guideline calls for that to be stated explicitly.As per path instructions,
internal/ui/**/*_test.gofiles touching TUI behavior must "verify it also handles RemoteSession or include an explicit t.Skip documenting why."📝 Suggested doc note
func TestGroupCreatePersistsDuringReload(t *testing.T) { + // RemoteSession items are read-only views with no local Instance/groupTree + // membership, so they are not applicable to group create/rename flows. h, storage := testHomeWithStorage(t, "_group_persist_create")📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Path instructions