Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(domain): use slices.Contains in AnalyticsFilter.MatchesProject (#353)

fx-kurumib3a92d1085fd
diff --git a/internal/domain/analytics.go b/internal/domain/analytics.go
index a0974d64..be6d2887 100644
--- a/internal/domain/analytics.go
+++ b/internal/domain/analytics.go
@@ -1,6 +1,9 @@
package domain
-import "time"
+import (
+ "slices"
+ "time"
+)
// AnalyticsFilter scopes platform analytics without coupling the store to HTTP.
type AnalyticsFilter struct {
@@ -537,10 +540,5 @@ func (f AnalyticsFilter) MatchesProject(id string) bool {
if f.ProjectIDs == nil {
return true
}
- for _, allowed := range f.ProjectIDs {
- if id == allowed {
- return true
- }
- }
- return false
+ return slices.Contains(f.ProjectIDs, id)
}
diff --git a/internal/domain/analytics_filter_test.go b/internal/domain/analytics_filter_test.go
new file mode 100644
index 00000000..eb85c831
--- /dev/null
+++ b/internal/domain/analytics_filter_test.go
@@ -0,0 +1,27 @@
+package domain
+
+import "testing"
+
+func TestAnalyticsFilterMatchesProject(t *testing.T) {
+ cases := []struct {
+ name string
+ filter AnalyticsFilter
+ id string
+ want bool
+ }{
+ {name: "unrestricted", filter: AnalyticsFilter{}, id: "p1", want: true},
+ {name: "empty scope means no projects", filter: AnalyticsFilter{ProjectIDs: []string{}}, id: "p1", want: false},
+ {name: "in scope", filter: AnalyticsFilter{ProjectIDs: []string{"p0", "p1"}}, id: "p1", want: true},
+ {name: "out of scope", filter: AnalyticsFilter{ProjectIDs: []string{"p0"}}, id: "p1", want: false},
+ {name: "exact match only", filter: AnalyticsFilter{ProjectIDs: []string{"P1"}}, id: "p1", want: false},
+ {name: "project id narrows", filter: AnalyticsFilter{ProjectID: "p0"}, id: "p1", want: false},
+ {name: "project id matches", filter: AnalyticsFilter{ProjectID: "p1"}, id: "p1", want: true},
+ {name: "project id still needs scope", filter: AnalyticsFilter{ProjectID: "p1", ProjectIDs: []string{"p0"}}, id: "p1", want: false},
+ {name: "project id and scope", filter: AnalyticsFilter{ProjectID: "p1", ProjectIDs: []string{"p1"}}, id: "p1", want: true},
+ }
+ for _, tc := range cases {
+ if got := tc.filter.MatchesProject(tc.id); got != tc.want {
+ t.Errorf("%s: MatchesProject(%q) = %v, want %v", tc.name, tc.id, got, tc.want)
+ }
+ }
+}