Skip to content

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

fix: activity source filter discards events whose source spelling differs from its log file name

Luigi Agosti179cfc88aa8c
diff --git a/internal/activity/activity.go b/internal/activity/activity.go
index af969a13..32de95d3 100644
--- a/internal/activity/activity.go
+++ b/internal/activity/activity.go
@@ -459,7 +459,11 @@ func (noopRecorder) Query(Filter) ([]Event, error) {
}
func (f Filter) matches(evt Event) bool {
- if f.Source != "" && evt.Source != f.Source {
+ // Compare normalized names: the source is stored verbatim from the client
+ // header but the per-source file is named with the normalized form, so
+ // matching raw here would discard events from the very file queryFiles
+ // selected for this source.
+ if f.Source != "" && normalizeSourceName(evt.Source) != normalizeSourceName(f.Source) {
return false
}
if f.RequestID != "" && evt.RequestID != f.RequestID {
@@ -674,9 +678,14 @@ func isActivityLogFile(name string) bool {
return name != "events.jsonl" && strings.HasPrefix(name, "events-") && strings.HasSuffix(name, ".jsonl")
}
+// isSourceLogFile anchors on the trailing day so a query for "mcp" does not
+// also scan every "mcp-<something>" source log.
func isSourceLogFile(name, source string) bool {
- prefix := "events-" + source + "-"
- return strings.HasPrefix(name, prefix)
+ day, ok := activityLogDay(name)
+ if !ok {
+ return false
+ }
+ return name == "events-"+source+"-"+day+".jsonl"
}
func activityLogDay(name string) (string, bool) {
diff --git a/internal/activity/source_filter_test.go b/internal/activity/source_filter_test.go
new file mode 100644
index 00000000..9226a346
--- /dev/null
+++ b/internal/activity/source_filter_test.go
@@ -0,0 +1,66 @@
+package activity
+
+import (
+ "testing"
+ "time"
+)
+
+// The source a client sends in X-PinchTab-Source is stored verbatim, but the
+// per-source log file is named with the normalized form. queryFiles compares
+// normalized names while Filter.matches compared raw ones, so a query that
+// named the source the way it appears on disk read the right file and then
+// discarded every event in it.
+func TestQuerySourceFilterIsNormalized(t *testing.T) {
+ recorded := []string{"MCP", "mcp", " Mcp "}
+ for _, source := range recorded {
+ t.Run(source, func(t *testing.T) {
+ s, err := NewStore(t.TempDir(), 7)
+ if err != nil {
+ t.Fatalf("NewStore: %v", err)
+ }
+ if err := s.Record(Event{
+ Source: source,
+ Timestamp: time.Now().UTC(),
+ Method: "GET",
+ Path: "/snapshot",
+ Status: 200,
+ }); err != nil {
+ t.Fatalf("Record: %v", err)
+ }
+
+ got, err := s.Query(Filter{Source: "mcp"})
+ if err != nil {
+ t.Fatalf("Query: %v", err)
+ }
+ if len(got) != 1 {
+ t.Fatalf("Query(source=mcp) returned %d events for a source recorded as %q, want 1", len(got), source)
+ }
+ })
+ }
+}
+
+// A source whose normalized name merely shares a prefix with the queried one
+// must not be returned.
+func TestQuerySourceFilterDoesNotMatchPrefix(t *testing.T) {
+ s, err := NewStore(t.TempDir(), 7)
+ if err != nil {
+ t.Fatalf("NewStore: %v", err)
+ }
+ now := time.Now().UTC()
+ for _, source := range []string{"mcp", "mcp-extra"} {
+ if err := s.Record(Event{Source: source, Timestamp: now, Method: "GET", Path: "/x", Status: 200}); err != nil {
+ t.Fatalf("Record(%s): %v", source, err)
+ }
+ }
+
+ got, err := s.Query(Filter{Source: "mcp"})
+ if err != nil {
+ t.Fatalf("Query: %v", err)
+ }
+ if len(got) != 1 {
+ t.Fatalf("Query(source=mcp) returned %d events, want 1 (mcp-extra must not match)", len(got))
+ }
+ if got[0].Source != "mcp" {
+ t.Errorf("got source %q, want mcp", got[0].Source)
+ }
+}