Simplify recent vault open flow and Android local sync
ci / lint-test (push) Successful in 1m46s
ci / build (push) Successful in 3m44s

This commit is contained in:
Joe Julian
2026-04-05 16:37:43 -07:00
parent 37f1a0ef8f
commit eb6624cba5
10 changed files with 326 additions and 10 deletions
+103 -1
View File
@@ -135,7 +135,7 @@ func TestUISearchBehaviorIsConsistentAcrossDesktopAndPhoneLayouts(t *testing.T)
{ID: "tpl-2", Title: "SSH Login", URL: "ssh://infra.internal", Path: []string{"Templates", "Infra"}},
},
RecycleBin: []vault.Entry{
{ID: "deleted-1", Title: "Deleted Bellagio", URL: "https://bellagio.example.com", Path: []string{"Root", "Internet"}},
{ID: "deleted-1", Title: "Deleted Bellagio", URL: "https://bellagio.example.invalid", Path: []string{"Root", "Internet"}},
{ID: "deleted-2", Title: "Deleted HVAC", URL: "https://climate.example.com", Path: []string{"Root", "Home"}},
},
})
@@ -1754,6 +1754,67 @@ func TestUIAdvancedSynchronizeFromLocalMergesIntoCurrentVault(t *testing.T) {
}
}
func TestUIAdvancedSynchronizeFromImportedLocalVaultMergesIntoCurrentVault(t *testing.T) {
t.Parallel()
key := vault.MasterKey{Password: "correct horse battery staple"}
currentPath := filepath.Join(t.TempDir(), "current.kdbx")
writeKDBXMainTestFile(t, currentPath, vault.Model{
Entries: []vault.Entry{{
ID: "entry-current",
Title: "Vault Console",
Username: "dannyocean",
Password: "token-current",
URL: "https://vault.crew.example.invalid",
Path: []string{"Root", "Internet"},
}},
}, key)
var other bytes.Buffer
if err := vault.SaveKDBX(&other, vault.Model{
Entries: []vault.Entry{{
ID: "entry-other",
Title: "Bellagio",
Username: "rustyryan",
Password: "token-other",
URL: "https://bellagio.example.invalid",
Path: []string{"Root", "Internet"},
}},
}, key.Password); err != nil {
t.Fatalf("SaveKDBX(other) error = %v", err)
}
u := newUIWithSession("desktop", &session.Manager{})
u.masterPassword.SetText(key.Password)
u.vaultPath.SetText(currentPath)
if err := u.openVaultAction(); err != nil {
t.Fatalf("openVaultAction() error = %v", err)
}
u.openAdvancedSyncDialog()
u.syncDirection = syncDirectionPull
u.syncSourceMode = syncSourceLocal
u.syncLocalImportName = "Selected Android vault"
u.syncLocalImportContent = other.Bytes()
u.syncLocalPath.SetText("Selected Android vault")
if err := u.advancedSyncAction(); err != nil {
t.Fatalf("advancedSyncAction() error = %v", err)
}
var reopened session.Manager
if err := reopened.Open(currentPath, key); err != nil {
t.Fatalf("reopen Open(current) error = %v", err)
}
model, err := reopened.Current()
if err != nil {
t.Fatalf("reopened Current() error = %v", err)
}
if got := len(model.EntriesInPath([]string{"Root", "Internet"})); got != 2 {
t.Fatalf("len(EntriesInPath(Root/Internet)) = %d, want 2", got)
}
}
func TestUIStartOpenVaultActionAppliesResultOnMainThread(t *testing.T) {
t.Parallel()
@@ -4275,6 +4336,47 @@ func TestSelectingRecentVaultSwitchesToLocalMode(t *testing.T) {
}
}
func TestRestoreStartupLifecycleTargetSelectsMostRecentLocalVault(t *testing.T) {
t.Parallel()
u := newUIWithSession("desktop", &session.Manager{})
u.lifecycleMode = "remote"
u.vaultPath.SetText("")
u.recentVaults = []string{"/tmp/example.kdbx"}
u.recentVaultUsedAt["/tmp/example.kdbx"] = time.Date(2026, time.April, 5, 1, 2, 3, 0, time.UTC)
u.recentRemotes = nil
u.restoreStartupLifecycleTarget()
if got := u.lifecycleMode; got != "local" {
t.Fatalf("lifecycleMode after restore = %q, want local", got)
}
if got := u.vaultPath.Text(); got != "/tmp/example.kdbx" {
t.Fatalf("vaultPath after restore = %q, want /tmp/example.kdbx", got)
}
}
func TestShowLocalVaultChooser(t *testing.T) {
t.Parallel()
u := newUIWithSession("desktop", &session.Manager{})
u.lifecycleMode = "local"
u.vaultPath.SetText("")
if got := u.showLocalVaultChooser(); !got {
t.Fatal("showLocalVaultChooser() = false, want true when no local vault is selected")
}
u.vaultPath.SetText("/tmp/example.kdbx")
if got := u.showLocalVaultChooser(); got {
t.Fatal("showLocalVaultChooser() = true, want false when a local vault is selected")
}
u.lifecycleMode = "remote"
if got := u.showLocalVaultChooser(); !got {
t.Fatal("showLocalVaultChooser() = false, want true outside local lifecycle mode")
}
}
func TestSelectingRecentRemoteSwitchesToRemoteMode(t *testing.T) {
t.Parallel()