High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test(testbrowser): fail a profile removal the way Windows actually fails one
Darshan Jainbcefc4d6fd6b
diff --git a/internal/testbrowser/profile_test.go b/internal/testbrowser/profile_test.goindex 00aa11d8..a53fd23c 100644--- a/internal/testbrowser/profile_test.go+++ b/internal/testbrowser/profile_test.go@@ -13,10 +13,11 @@ import (// The property the fix delivers, proven deterministically rather than sampled by// re-running a suite: a browser profile whose removal FAILS must not fail the test.-// The subtest's own recorder stands in for a real Chrome still flushing its cache —-// on this platform a directory is unremovable while it is a mount point or read-only-// parent, so the honest simulation is to fail the removal by making the PARENT-// unwritable, which is exactly the class of error RemoveAll reports mid-flush.+// The subtest's own recorder stands in for a real Chrome still flushing its cache.+//+// How a removal is made to fail is per-platform, so makeRemovalFail owns it: unix+// clears the parent's write bit, Windows holds a handle open inside the profile.+// Both produce the class of error RemoveAll reports mid-flush.func TestProfileDirCleanupToleratesAFailedRemoval(t *testing.T) {parent := t.TempDir()dir := filepath.Join(parent, "profile")@@ -26,10 +27,7 @@ func TestProfileDirCleanupToleratesAFailedRemoval(t *testing.T) {if err := os.WriteFile(filepath.Join(dir, "Default", "Cache", "Cache_Data", "index"), []byte("x"), 0o644); err != nil {t.Fatal(err)}- if err := os.Chmod(parent, 0o500); err != nil {- t.Fatal(err)- }- t.Cleanup(func() { _ = os.Chmod(parent, 0o700) })+ makeRemovalFail(t, parent, dir)recorder := &cleanupRecorder{TB: t}removeProfileDir(recorder, dir)diff --git a/internal/testbrowser/removal_fail_other_test.go b/internal/testbrowser/removal_fail_other_test.gonew file mode 100644index 00000000..2b57c5ee--- /dev/null+++ b/internal/testbrowser/removal_fail_other_test.go@@ -0,0 +1,21 @@+//go:build !windows++package testbrowser++import (+ "os"+ "testing"+)++// makeRemovalFail arranges for os.RemoveAll(dir) to fail, standing in for a+// browser still writing into its profile.+//+// On unix it is the parent's write bit that governs whether an entry can be+// unlinked, so clearing it is enough and the directory below is untouched.+func makeRemovalFail(t *testing.T, parent, _ string) {+ t.Helper()+ if err := os.Chmod(parent, 0o500); err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = os.Chmod(parent, 0o700) })+}diff --git a/internal/testbrowser/removal_fail_windows_test.go b/internal/testbrowser/removal_fail_windows_test.gonew file mode 100644index 00000000..a33f7e48--- /dev/null+++ b/internal/testbrowser/removal_fail_windows_test.go@@ -0,0 +1,32 @@+//go:build windows++package testbrowser++import (+ "os"+ "path/filepath"+ "testing"+)++// makeRemovalFail arranges for os.RemoveAll(dir) to fail, standing in for a+// browser still writing into its profile.+//+// The unix approach — clearing the parent's write bit — arranges nothing here.+// os.Chmod on Windows only toggles the read-only attribute, and RemoveAll+// clears that on its way through, so the directory came away cleanly and the+// test found itself asserting against a successful removal: it reported that+// "the unremovable dir vanished", which was exactly right.+//+// What Windows does enforce is sharing. A file held open cannot be unlinked,+// and its directory cannot be removed while it is there, which surfaces as+// "The process cannot access the file because it is being used by another+// process." That is also the closer analogue of the case this guards — a real+// Chrome still flushing its cache is holding handles, not permissions.+func makeRemovalFail(t *testing.T, _, dir string) {+ t.Helper()+ held, err := os.Open(filepath.Join(dir, "Default", "Cache", "Cache_Data", "index"))+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { _ = held.Close() })+}