Skip to content

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

refactor: two more hand-rolled censuses landed after srccensus shipped, and the one guarding reservations covers one of the two routed sites (PIN-176)

Luigi Agostia66fc3eacd6e
diff --git a/internal/fileout/autonaming_census_test.go b/internal/fileout/autonaming_census_test.go
index ca4024dd..881dda89 100644
--- a/internal/fileout/autonaming_census_test.go
+++ b/internal/fileout/autonaming_census_test.go
@@ -40,8 +40,12 @@ var timestampLayouts = []string{"150405", "15-04-05", "15_04_05", "15.04.05"}
// earlier output. Package-qualified, so one map serves the whole module and a reader can
// see which package each decision belongs to. Every entry is a boundary decision, which
// is why each carries its reason rather than just a path.
+//
+// The KEYS are checked in both directions; a reason's TEXT is only printed. It is
+// documentation for the next reader, not a check, so it rots silently unless someone
+// updating a site updates it here too — this entry credited a helper deleted a card ago.
var autoNamingSites = map[string]string{
- "internal/handlers/binary_export.go": "exportTimestamp only builds the base name; fileout reserves the path",
+ "internal/handlers/binary_export.go": "exportTimestamp only builds the base name; fileout.WriteUnique reserves the path and writes it",
"internal/handlers/record_handlers.go": "the recording base name is reserved by " +
"fileout.ReserveUnique before it is returned",
"internal/cli/actions/actions_capture.go": "writeOutputFile with autoNamed",
diff --git a/internal/fileout/fileout_test.go b/internal/fileout/fileout_test.go
index 24d7d86d..cd15403e 100644
--- a/internal/fileout/fileout_test.go
+++ b/internal/fileout/fileout_test.go
@@ -1,6 +1,7 @@
package fileout
import (
+ "github.com/pinchtab/pinchtab/internal/srccensus"
"os"
"path/filepath"
"strconv"
@@ -196,31 +197,47 @@ func TestReservePathDelegatesToTheThreePartForm(t *testing.T) {
// two copies of the close-and-remove pair is how the rule drifted out of one of them
// before. Behavioural tests cannot see the difference — a copy passes them — so this is
// a structural check on the delegation itself.
+//
+// The declaration is located anywhere in the package and each banned call is judged by
+// whether it lies INSIDE that declaration, so moving ReservePath to a sibling file keeps
+// the rule rather than reporting the function missing. Non-vacuity rests on the delegation
+// assertion, not on a match count: a ReservePath that stops calling ReserveUnique reds by
+// name here rather than fataling as an empty scan.
+//
+// There is deliberately no ban on Close: a method call resolves as "<receiver>.Close", so a
+// ban naming Close alone is blind to every real spelling of it, and the only handle
+// ReservePath could close is one CreateUnique gave it — which is banned below.
func TestReservePathHoldsNoSecondImplementation(t *testing.T) {
- raw, err := os.ReadFile("fileout.go")
- if err != nil {
- t.Fatal(err)
+ pkg := srccensus.Load(t, ".", fileoutSourceFileFloor)
+
+ fn, ok := pkg.Func("ReservePath")
+ if !ok {
+ t.Fatalf("ReservePath is not declared anywhere in %s; this guard is pinned to a function that no longer exists — re-point it at whatever replaced it rather than deleting it", pkg.Dir())
}
- const declaration = "func ReservePath("
- start := strings.Index(string(raw), declaration)
- if start < 0 {
- t.Fatalf("%s not found; this guard is pinned to a function that no longer exists", declaration)
+
+ delegates := false
+ for _, site := range pkg.CallsAllowingNone("ReserveUnique") {
+ if pkg.Contains(fn, site) {
+ delegates = true
+ }
}
- body := string(raw)[start:]
- if end := strings.Index(body, "\n}\n"); end >= 0 {
- body = body[:end]
+ if !delegates {
+ t.Errorf("%s (%s:%d) no longer calls ReserveUnique; the reserve-and-close sequence has one implementation and this is meant to be a shape over it", fn.Name, fn.File, fn.Line)
}
- if !strings.Contains(body, "ReserveUnique(dir, base, ext)") {
- t.Error("ReservePath no longer delegates to ReserveUnique")
- }
- for _, reimplemented := range []string{"CreateUnique(", "os.Remove(", ".Close()"} {
- if strings.Contains(body, reimplemented) {
- t.Errorf("ReservePath contains %q; the reserve-and-close sequence has one implementation and this is meant to be a shape over it", reimplemented)
+ for _, banned := range []string{"CreateUnique", "os.Remove"} {
+ for _, site := range pkg.CallsAllowingNone(banned) {
+ if pkg.Contains(fn, site) {
+ t.Errorf("%s lies inside ReservePath; that is a second copy of the reserve-and-close sequence, which is how its removal went missing before — delegate to ReserveUnique instead", site)
+ }
}
}
}
+// The package holds one production file today; the floor exists so a scan that stopped
+// reading it fails instead of passing over nothing.
+const fileoutSourceFileFloor = 1
+
// TestWriteUniqueRemovesTheFileItCreatedWhenTheWriteFails pins the removal through
// the creator seam: the stub creates a REAL file and hands back a closed handle, so
// the write fails for a reason the caller cannot control and the file it left is the
diff --git a/internal/handlers/binary_export_test.go b/internal/handlers/binary_export_test.go
index 3604a1e8..5620b33d 100644
--- a/internal/handlers/binary_export_test.go
+++ b/internal/handlers/binary_export_test.go
@@ -13,6 +13,7 @@ import (
"github.com/pinchtab/pinchtab/internal/bridge/observe"
"github.com/pinchtab/pinchtab/internal/config"
+ "github.com/pinchtab/pinchtab/internal/srccensus"
)
// Two saves in immediate succession must land on different paths with both files intact.
@@ -139,35 +140,45 @@ func TestRecordingsOutputPathReservesEachPath(t *testing.T) {
}
}
-// The reservation rule — create exclusively, close, remove the placeholder if the close
-// fails — belongs to internal/fileout, which pins the removal itself through an injected
-// creator. This site owes only proof that it ROUTES there and keeps no second copy of
-// the sequence: a local create-then-close is how the removal came to be missing here.
-func TestRecordingsOutputPathReservesThroughFileout(t *testing.T) {
- raw, err := os.ReadFile("record_handlers.go")
- if err != nil {
- t.Fatal(err)
- }
- const declaration = "func (h *Handlers) recordingsOutputPath("
- start := strings.Index(string(raw), declaration)
- if start < 0 {
- t.Fatalf("%s not found in record_handlers.go; this guard is pinned to a function that no longer exists", declaration)
- }
- body := string(raw)[start:]
- if end := strings.Index(body, "\n}\n"); end >= 0 {
- body = body[:end]
- }
+// Reservation is fileout's rule — create exclusively, close, remove the placeholder when
+// the close fails — and this package owes only proof that it ROUTES there.
+//
+// The scope is the PACKAGE, not one file. The guard this replaces opened record_handlers.go
+// by name, so network_export.go reserved with no guard at all: the exact sequence the
+// reservation fix removed could be reinstated there today with a green suite. Deriving the
+// scope covers both sites and every future one for free.
+//
+// The ban is on the CALL, not on tokens. fileout.CreateUnique hands back an OPEN handle, and
+// closing it to reserve a name is the hand-rolled sequence whose removal-on-failed-close went
+// missing here; everything in this package reserves through ReserveUnique or writes through
+// WriteUnique instead. Banning ".Close()" over a whole package would red on eleven correct
+// calls across five files — network_export.go closes the export file it wrote, twice — and a
+// census that reds on correct code gets loosened or deleted, which is how the gap came back
+// the first time.
+func TestEveryReservationInThisPackageRoutesThroughFileout(t *testing.T) {
+ pkg := srccensus.Load(t, ".", handlersSourceFileFloor)
- if !strings.Contains(body, "fileout.ReserveUnique(") {
- t.Error("recordingsOutputPath no longer reserves through fileout.ReserveUnique, so the removal on a failed close is not inherited")
+ for _, site := range pkg.CallsAllowingNone("fileout.CreateUnique") {
+ t.Errorf("%s hands back an OPEN handle, and closing it to reserve a name is the copy whose removal-on-failed-close went missing — call fileout.ReserveUnique, or fileout.WriteUnique to write in one step", site)
}
- for _, reimplemented := range []string{"createUniqueFile(", ".Close()", "os.Remove("} {
- if strings.Contains(body, reimplemented) {
- t.Errorf("recordingsOutputPath contains %q; the reserve-and-close sequence has one owner in internal/fileout, and a local copy is how its removal went missing", reimplemented)
- }
+
+ routed := append(
+ pkg.CallsAllowingNone("fileout.ReserveUnique"),
+ pkg.CallsAllowingNone("fileout.WriteUnique")...,
+ )
+ if len(routed) < reservationRouteFloor {
+ t.Fatalf("found %d fileout reservation calls in %s, want at least %d; the routing this guard defends is gone, so the ban above now guards air — re-point it at whatever replaced it rather than deleting it", len(routed), pkg.Dir(), reservationRouteFloor)
}
}
+const (
+ // Well under the real count, so ordinary growth or deletion does not trip it while a
+ // scan that stopped seeing most of the package still fails.
+ handlersSourceFileFloor = 90
+ // One per production reserver: record_handlers, network_export and binary_export.
+ reservationRouteFloor = 3
+)
+
// stubExportEncoder is the smallest ExportEncoder writeExportFile will accept, so the
// naming and overwrite policy can be driven without a browser.
type stubExportEncoder struct {