Разделите настройки команд worker и сохраняйте причину сбоя

This commit is contained in:
2026-11-20 10:54:34 +03:00
parent 42a9bf2071
commit 8f90c78b98
8 changed files with 303 additions and 141 deletions
+28 -1
View File
@@ -4,7 +4,9 @@ import (
"context"
"crypto/sha256"
"errors"
"fmt"
"io"
"log/slog"
"strings"
"testing"
@@ -24,7 +26,7 @@ func (s stagedSource) Open(context.Context, string) (io.ReadCloser, error) {
func TestReadOriginalValidatesPersistedSizeAndDigest(t *testing.T) {
h := sha256.Sum256([]byte("accepted"))
c := &pipeline.Claim{SizeBytes: 8, Hash: h[:], SourceKey: "staging/test"}
for _, bad := range []string{"truncated", "altered!", "oversized bytes"} {
for _, bad := range []string{"accept", "altered!", "oversized bytes"} {
_, err := readOriginal(t.Context(), stagedSource{body: bad}, c)
if !errors.Is(err, errSourceMismatch) {
t.Fatalf("body %q: %v", bad, err)
@@ -35,3 +37,28 @@ func TestReadOriginalValidatesPersistedSizeAndDigest(t *testing.T) {
t.Fatalf("valid original: %v", err)
}
}
type failingSource struct{ attachment.Blobs }
func (failingSource) Open(context.Context, string) (io.ReadCloser, error) {
return nil, fmt.Errorf("credentials=private-source-data: %w", context.DeadlineExceeded)
}
func TestFailureLogReportsStageAndReason(t *testing.T) {
var log strings.Builder
w := Worker{Blobs: failingSource{}, Log: slog.New(slog.NewJSONHandler(&log, nil))}
c := &pipeline.Claim{SizeBytes: 5, SourceKey: "sensitive-source-key"}
_, failure := w.writeObjects(t.Context(), c)
if failure == nil {
t.Fatal("expected failure reading source")
}
got := log.String()
for _, want := range []string{`"stage":"read_original"`, `"reason":"deadline_exceeded"`, `"error_code":"processing_failed"`, `"job_id":`, `"attempt":`} {
if !strings.Contains(got, want) {
t.Errorf("log missing %s: %s", want, got)
}
}
if strings.Contains(got, "private-source-data") || strings.Contains(got, "sensitive-source-key") {
t.Errorf("leaked source details: %s", got)
}
}