feat: backend native executor implement

This commit is contained in:
2026-08-16 01:27:30 +08:00
parent fbce91d797
commit 390e0565d3
44 changed files with 6430 additions and 31 deletions
+40
View File
@@ -0,0 +1,40 @@
package backendupdate
import (
"context"
"encoding/json"
"errors"
"path/filepath"
"testing"
"yms-daemon/internal/daemonapi"
"yms-daemon/internal/transaction"
)
func TestRestartRejectsUnfinishedBackendUpdate(t *testing.T) {
ctx := context.Background()
store, err := transaction.OpenStore(ctx, filepath.Join(t.TempDir(), "transactions.db"))
if err != nil {
t.Fatalf("open transaction store: %v", err)
}
defer store.Close()
request, err := json.Marshal(persistedRequest{InputType: daemonapi.InputTypeNativeJAR})
if err != nil {
t.Fatalf("encode unfinished update request: %v", err)
}
active, _, err := store.CreateTransaction(ctx, transaction.CreateRequest{
ID: "unfinished-backend-update",
IdempotencyKey: "backend:update:unfinished",
Source: sourceLocalCLI,
Service: serviceBackend,
Request: request,
})
if err != nil {
t.Fatalf("create unfinished update transaction: %v", err)
}
updater := &Updater{store: store}
record, err := updater.Restart(ctx, nil)
if !errors.Is(err, transaction.ErrActiveExists) || record.ID != active.ID {
t.Fatalf("unexpected restart result with unfinished update: record=%+v err=%v", record, err)
}
}