Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: capture output filenames collide within the same second, silently overwriting earlier images (PIN-050)

Luigi Agostib3536e818719
diff --git a/internal/handlers/binary_export_test.go b/internal/handlers/binary_export_test.go
index 49bb9d00..8e26e2a8 100644
--- a/internal/handlers/binary_export_test.go
+++ b/internal/handlers/binary_export_test.go
@@ -283,3 +283,30 @@ func TestSnapshotFileBranchRoutesTheGeneratedNameThroughTheUniqueHelper(t *testi
t.Error("the plain write is no longer inside the caller-supplied-path branch")
}
}
+
+// A reserved name must be given back when the stop it was reserved for is refused.
+// Reserving creates a real file, so without this every rejected /record/stop leaves a
+// 0-byte recording behind — which is how this showed up: a test with an empty StateDir
+// started writing into the package directory.
+func TestARefusedRecordStopLeavesNoReservedFile(t *testing.T) {
+ stateDir := t.TempDir()
+ h := New(&mockBridge{}, &config.RuntimeConfig{StateDir: stateDir}, nil, nil, nil)
+
+ req := httptest.NewRequest("POST", "/record/stop", nil)
+ w := httptest.NewRecorder()
+ h.HandleRecordStop(w, req)
+
+ if w.Code != 400 {
+ t.Fatalf("precondition: stopping with no active recording must be a 400, got %d", w.Code)
+ }
+ entries, err := os.ReadDir(filepath.Join(stateDir, "recordings"))
+ if err != nil {
+ if os.IsNotExist(err) {
+ return
+ }
+ t.Fatal(err)
+ }
+ for _, e := range entries {
+ t.Errorf("a refused stop left %s behind", e.Name())
+ }
+}
diff --git a/internal/handlers/record_handlers.go b/internal/handlers/record_handlers.go
index 228d3d32..10f8cc90 100644
--- a/internal/handlers/record_handlers.go
+++ b/internal/handlers/record_handlers.go
@@ -126,6 +126,13 @@ func (h *Handlers) HandleRecordStop(w http.ResponseWriter, r *http.Request) {
owner := authenticatedOwner(r)
result, err := h.recorder.stop(owner, outputPath)
if err != nil {
+ // The path is RESERVED before stop, because stop needs it. Reserving now
+ // creates a real file, so a refused stop — no active recording, a foreign
+ // owner — has to give the name back or every rejected request leaves a
+ // 0-byte recording behind.
+ if outputPath != "" {
+ _ = os.Remove(outputPath)
+ }
httpx.ErrorCode(w, 400, "recording_error", err.Error(), false, nil)
return
}
diff --git a/internal/handlers/record_test.go b/internal/handlers/record_test.go
index a21671b0..a1af2436 100644
--- a/internal/handlers/record_test.go
+++ b/internal/handlers/record_test.go
@@ -110,7 +110,9 @@ func TestRecorderStart_AlreadyRecording(t *testing.T) {
}
func TestHandleRecordStop_NoRecording(t *testing.T) {
- cfg := &config.RuntimeConfig{}
+ // A real StateDir: the stop path reserves its output name on disk, so an empty
+ // StateDir would write into the package directory.
+ cfg := &config.RuntimeConfig{StateDir: t.TempDir()}
h := New(&mockBridge{}, cfg, nil, nil, nil)
req := httptest.NewRequest("POST", "/record/stop", nil)