test(deploy): recover worker panic into failed operation
CI / validate (pull_request) Canceled after 0s

This commit is contained in:
2026-08-15 20:02:40 +02:00
parent 384c616d58
commit 96b3306448
+13 -9
View File
@@ -112,9 +112,6 @@ func TestInstanceUnbanCapabilityFallback(t *testing.T) {
}
defer db.Close()
repository := sqlite.NewRepository(db)
if err := repository.SetSecretKey(bytes.Repeat([]byte{1}, 32)); err != nil {
t.Fatal(err)
}
snapshots, err := catalog.LoadFS(catalogdata.Files, ".")
if err != nil {
t.Fatal(err)
@@ -253,9 +250,6 @@ func TestCatalogPreviewAndDraftAPIAuthorization(t *testing.T) {
}
defer db.Close()
repository := sqlite.NewRepository(db)
if err := repository.SetSecretKey(bytes.Repeat([]byte{1}, 32)); err != nil {
t.Fatal(err)
}
snapshots, err := catalog.LoadFS(catalogdata.Files, ".")
if err != nil {
t.Fatal(err)
@@ -1148,7 +1142,11 @@ func TestDeploymentFormRequiresAdminAndRendersTemplateFields(t *testing.T) {
assertStatus(t, missing, http.StatusNotFound)
}
func TestDeploymentHTTPAsyncProgressAndRBAC(t *testing.T) {
func TestDeploymentHTTPAsyncProgressAndRBAC(t *testing.T) { testDeploymentHTTPAsync(t, false) }
func TestDeploymentWorkerPanicFailsOperation(t *testing.T) { testDeploymentHTTPAsync(t, true) }
func testDeploymentHTTPAsync(t *testing.T, panicWorker bool) {
ctx := context.Background()
db, err := sqlite.Open(ctx, filepath.Join(t.TempDir(), "dogama.db"))
if err != nil {
@@ -1181,7 +1179,7 @@ func TestDeploymentHTTPAsyncProgressAndRBAC(t *testing.T) {
if err != nil {
t.Fatal(err)
}
agent := &blockingLifecycleAgent{entered: make(chan struct{}), release: make(chan struct{})}
agent := &blockingLifecycleAgent{entered: make(chan struct{}), release: make(chan struct{}), panicOnCreate: panicWorker}
handler, err := NewHandlerCompleteWithCatalogAndDeployment(authService, repository, instance.NewLifecycleService(repository, agent), nil, nil, nil, nil, nil, filepath.Join(t.TempDir(), "servers"), slog.New(slog.NewTextHandler(io.Discard, nil)))
if err != nil {
t.Fatal(err)
@@ -1249,7 +1247,10 @@ func TestDeploymentHTTPAsyncProgressAndRBAC(t *testing.T) {
deadline := time.Now().Add(2 * time.Second)
for {
value, err := repository.GetOperationProgress(ctx, accepted["operation_id"])
if err == nil && value.GlobalStatus == "success" {
if err == nil && ((!panicWorker && value.GlobalStatus == "success") || (panicWorker && value.GlobalStatus == "failed")) {
if panicWorker && (value.ErrorCode == "" || value.OperationID != accepted["operation_id"]) {
t.Fatalf("panic result is not actionable: %#v", value)
}
break
}
if time.Now().After(deadline) {
@@ -1262,4 +1263,7 @@ func TestDeploymentHTTPAsyncProgressAndRBAC(t *testing.T) {
adminDiagnosticResponse := httptest.NewRecorder()
handler.ServeHTTP(adminDiagnosticResponse, adminDiagnostic)
assertStatus(t, adminDiagnosticResponse, http.StatusOK)
if panicWorker && (strings.Contains(adminDiagnosticResponse.Body.String(), "top-secret-value") || !strings.Contains(adminDiagnosticResponse.Body.String(), accepted["operation_id"])) {
t.Fatalf("panic diagnostic leaked secret or lost operation id: %s", adminDiagnosticResponse.Body.String())
}
}