From 0d0e1f55a7df92b791a33fd8d4300da1c5fceb08 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Mon, 6 Apr 2026 12:24:19 +0300 Subject: [PATCH] Avoid misleading SAT summaries after task cancellation --- audit/internal/platform/sat.go | 3 +++ audit/internal/platform/sat_test.go | 34 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/audit/internal/platform/sat.go b/audit/internal/platform/sat.go index 29c4037..0b7e2ea 100644 --- a/audit/internal/platform/sat.go +++ b/audit/internal/platform/sat.go @@ -674,6 +674,9 @@ func runAcceptancePackCtx(ctx context.Context, baseDir, prefix string, jobs []sa if writeErr := os.WriteFile(filepath.Join(runDir, job.name), out, 0644); writeErr != nil { return "", writeErr } + if ctx.Err() != nil { + return "", ctx.Err() + } status, rc := classifySATResult(job.name, out, err) stats.Add(status) key := strings.TrimSuffix(strings.TrimPrefix(job.name, "0"), ".log") diff --git a/audit/internal/platform/sat_test.go b/audit/internal/platform/sat_test.go index 7f0475a..423c16b 100644 --- a/audit/internal/platform/sat_test.go +++ b/audit/internal/platform/sat_test.go @@ -1,12 +1,14 @@ package platform import ( + "context" "errors" "os" "os/exec" "path/filepath" "strings" "testing" + "time" ) func TestStorageSATCommands(t *testing.T) { @@ -353,6 +355,38 @@ func TestClassifySATResult(t *testing.T) { } } +func TestRunAcceptancePackCtxReturnsContextErrorWithoutArchive(t *testing.T) { + dir := t.TempDir() + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + + done := make(chan struct{}) + go func() { + time.Sleep(100 * time.Millisecond) + cancel() + close(done) + }() + + archive, err := runAcceptancePackCtx(ctx, dir, "cancelled-pack", []satJob{ + {name: "01-sleep.log", cmd: []string{"sh", "-c", "sleep 5"}}, + }, nil) + <-done + + if !errors.Is(err, context.Canceled) { + t.Fatalf("err=%v want context.Canceled", err) + } + if archive != "" { + t.Fatalf("archive=%q want empty", archive) + } + matches, globErr := filepath.Glob(filepath.Join(dir, "cancelled-pack-*.tar.gz")) + if globErr != nil { + t.Fatalf("Glob error: %v", globErr) + } + if len(matches) != 0 { + t.Fatalf("archives=%v want none", matches) + } +} + func TestParseStorageDevicesSkipsUSBDisks(t *testing.T) { t.Parallel()