From eb9357a5de6e19ea4f0501783afdf50cd54b2af0 Mon Sep 17 00:00:00 2001 From: Mathias Date: Thu, 1 Oct 2026 16:56:11 +0200 Subject: [PATCH] test(cmd): start-up removes spooled audio left by a crash (red) Co-Authored-By: Claude Sonnet 5.5 --- cmd/tapir/uploads_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/tapir/uploads_test.go b/cmd/tapir/uploads_test.go index 6d33f92..a18c02e 100644 --- a/cmd/tapir/uploads_test.go +++ b/cmd/tapir/uploads_test.go @@ -104,3 +104,24 @@ func TestBuildUploads_EnabledWithoutAGatewayIsAnError(t *testing.T) { assert.Error(t, err, "uploads on with nowhere to transcribe must fail loudly at start-up, not at the first upload") } + +func TestBuildUploads_RemovesAudioLeftBehindByACrash(t *testing.T) { + cfg := uploadCfg(t, true) + require.NoError(t, os.MkdirAll(cfg.UploadTmpDir, 0o700)) + leftovers := []string{"upload-123", "wav-456"} + for _, n := range leftovers { + require.NoError(t, os.WriteFile(filepath.Join(cfg.UploadTmpDir, n), []byte("audio"), 0o600)) + } + unrelated := filepath.Join(cfg.UploadTmpDir, "someone-elses-file") + require.NoError(t, os.WriteFile(unrelated, []byte("keep"), 0o600)) + + _, _, err := buildUploads(context.Background(), cfg, &fakeUploadsStore{}, quietLog()) + + require.NoError(t, err) + for _, n := range leftovers { + _, err := os.Stat(filepath.Join(cfg.UploadTmpDir, n)) + assert.True(t, os.IsNotExist(err), "%s: audio is never retained, so a spooled file from a crashed run must not survive start-up", n) + } + _, err = os.Stat(unrelated) + assert.NoError(t, err, "only our own spool files are removed") +}