fix: preserve sync error status

This commit is contained in:
mirivlad 2026-06-29 03:23:45 +08:00
parent 57677d1b1b
commit 04ce8c5bf3
2 changed files with 52 additions and 0 deletions

View File

@ -1944,6 +1944,8 @@ func (a *App) syncStatus() (*SyncStatusDTO, error) {
switch { switch {
case dto.Revoked: case dto.Revoked:
dto.StatusLabel = "revoked" dto.StatusLabel = "revoked"
case dto.LastError != "":
dto.StatusLabel = "error"
case dto.Connected: case dto.Connected:
dto.StatusLabel = "connected" dto.StatusLabel = "connected"
case dto.Configured: case dto.Configured:
@ -2002,6 +2004,7 @@ func (a *App) syncConfigure(serverURL, username, password string) error {
cfg.Sync.DeviceID = deviceID cfg.Sync.DeviceID = deviceID
cfg.Sync.DeviceName = hostname cfg.Sync.DeviceName = hostname
cfg.Sync.LastStatus = "connected" cfg.Sync.LastStatus = "connected"
cfg.Sync.LastError = ""
_ = a.appSettings.UpdateSync(cfg.Sync) _ = a.appSettings.UpdateSync(cfg.Sync)
return nil return nil

View File

@ -1645,6 +1645,55 @@ func TestPluginSyncBridgeRequiresDeclaredPermissions(t *testing.T) {
} }
} }
func TestPluginSyncStatusReportsPersistedError(t *testing.T) {
app := newBridgeTestApp(t)
app.plugins = append(app.plugins,
plugin.Plugin{
Manifest: plugin.Manifest{
ID: "sync.local",
Name: "Sync Local",
Version: "1.0.0",
Provides: []string{"sync/local/v1"},
Permissions: []string{"sync.participate"},
},
Status: plugin.StatusLoaded,
Enabled: true,
},
)
app.syncSvc = syncsvc.NewService(app.vaultPath(), "local-device")
app.appSettings = appsettings.NewManager(filepath.Join(t.TempDir(), "config.json"))
if err := app.appSettings.Load(); err != nil {
t.Fatalf("settings Load: %v", err)
}
if err := app.syncSvc.SetState("https://sync.example.test", ""); err != nil {
t.Fatalf("SetState: %v", err)
}
cfg := app.appSettings.Get()
cfg.Sync.Enabled = true
cfg.Sync.ServerURL = "https://sync.example.test"
cfg.Sync.DeviceID = "device-1"
cfg.Sync.LastStatus = "error"
cfg.Sync.LastError = "push: server unavailable"
if err := app.appSettings.UpdateSync(cfg.Sync); err != nil {
t.Fatalf("settings UpdateSync: %v", err)
}
if err := syncsvc.SaveDeviceToken(app.vaultPath(), "secret-token"); err != nil {
t.Fatalf("SaveDeviceToken: %v", err)
}
status, errStr := app.PluginSyncStatus("sync.local")
if errStr != "" {
t.Fatalf("PluginSyncStatus: %s", errStr)
}
if status.StatusLabel != "error" || status.LastError != "push: server unavailable" {
t.Fatalf("status = %#v, want persisted sync error", status)
}
cfg = app.appSettings.Get()
if cfg.Sync.LastStatus != "error" || cfg.Sync.LastError != "push: server unavailable" {
t.Fatalf("persisted sync settings = %#v, want error preserved", cfg.Sync)
}
}
func TestPluginBridgeCapabilitiesCommandsAndEventsAreChecked(t *testing.T) { func TestPluginBridgeCapabilitiesCommandsAndEventsAreChecked(t *testing.T) {
app := newBridgeTestApp(t) app := newBridgeTestApp(t)