From 3caf53cfb6635ace1d886184207094190a69b19d Mon Sep 17 00:00:00 2001
From: PJ
Date: Sat, 22 Aug 2026 21:31:13 +0530
Subject: [PATCH] test(chrome): one launch preamble, and parity now pins ground
truth
48 of 51 call sites shared one eight-line block that opened a fixture server,
launched chrome and checked the error. The three left are the launch tests
themselves, where what the helper hardcodes is the subject.
The audit called four tests superseded by fact_parity_test.go. They were not:
parity asserts the two producers agree and that each fact appears both ways,
never that either reading is right, so deleting them would have removed the only
thing anchoring the pair to reality. The values they pinned are now asserted
inside parity against both producers, and the shadow fixture has ground truth
where it had none.
---
internal/driver/chrome/driver_test.go | 636 +++---------------
internal/driver/chrome/element_state_test.go | 106 +--
internal/driver/chrome/fact_parity_test.go | 204 +++++-
internal/driver/chrome/picker_stream_test.go | 27 +-
.../driver/chrome/selector_parity_test.go | 91 +--
5 files changed, 273 insertions(+), 791 deletions(-)
diff --git a/internal/driver/chrome/driver_test.go b/internal/driver/chrome/driver_test.go
index 103a8b8..f54d5a4 100644
--- a/internal/driver/chrome/driver_test.go
+++ b/internal/driver/chrome/driver_test.go
@@ -23,6 +23,47 @@ import (
"github.com/priyanshujain/sanderling/internal/verifier"
)
+// launchChrome starts a browser on target and returns it with the context every
+// later driver call must use. The browser, and the deadline that bounds a call
+// against a wedged one, are torn down when the test ends.
+//
+// A test whose subject is the launch itself (a clearState wipe, a caller
+// deadline, a browser outliving its caller's context) builds this by hand: the
+// flag, the timeout and the cancel are what it is measuring.
+func launchChrome(t *testing.T, target string) (*Driver, context.Context) {
+ t.Helper()
+ d := New()
+ t.Cleanup(func() { _ = d.Terminate(context.Background()) })
+ ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
+ t.Cleanup(cancel)
+ if err := d.Launch(ctx, target, false, nil); err != nil {
+ t.Fatalf("Launch: %v", err)
+ }
+ return d, ctx
+}
+
+// servePage serves html at a real http origin for the duration of the test. A
+// data: URL carries the same markup but has an opaque origin, where storage,
+// routing and everything else keyed by origin behaves as it never would in an
+// app.
+func servePage(t *testing.T, html string) *httptest.Server {
+ t.Helper()
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.Header().Set("Content-Type", "text/html")
+ _, _ = w.Write([]byte(html))
+ }))
+ t.Cleanup(server.Close)
+ return server
+}
+
+// testdataServer serves the fixture pages in testdata, each at its own path.
+func testdataServer(t *testing.T) *httptest.Server {
+ t.Helper()
+ server := httptest.NewServer(http.FileServer(http.Dir("testdata")))
+ t.Cleanup(server.Close)
+ return server
+}
+
// TestLaunch_ClearStateWipesStorageForTheTargetOrigin covers the CLI's default
// path (--clear-data). The tab sits on about:blank when Launch runs, an opaque
// origin that denies storage access, so clearing by script there throws
@@ -33,11 +74,7 @@ func TestLaunch_ClearStateWipesStorageForTheTargetOrigin(t *testing.T) {
localStorage.setItem("visits", String(visits));
sessionStorage.setItem("tab", "dirty");