Skip to content

Commit 35bf516

Browse files
chore: remove dead functions — 7 functions removed (#24727)
1 parent 9023ef4 commit 35bf516

17 files changed

Lines changed: 23 additions & 2759 deletions

pkg/agentdrain/miner.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,6 @@ func (m *Miner) Train(line string) (*MatchResult, error) {
7373
}, nil
7474
}
7575

76-
// Match performs inference only: it finds the best matching cluster but does
77-
// not mutate any state. Returns (result, true) when a match is found.
78-
// It is safe to call from multiple goroutines.
79-
func (m *Miner) Match(line string) (*MatchResult, bool, error) {
80-
masked := m.masker.Mask(line)
81-
tokens := Tokenize(masked)
82-
if len(tokens) == 0 {
83-
return nil, false, errors.New("agentdrain: Match: empty line after masking")
84-
}
85-
86-
m.mu.RLock()
87-
defer m.mu.RUnlock()
88-
89-
result, _ := m.match(tokens)
90-
if result == nil {
91-
return nil, false, nil
92-
}
93-
return result, true, nil
94-
}
95-
9676
// match is the internal (non-locking) lookup. Must be called with mu held.
9777
func (m *Miner) match(tokens []string) (*MatchResult, bool) {
9878
candidates := m.tree.search(tokens, m.cfg.Depth, m.cfg.ParamToken)

pkg/agentdrain/miner_test.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,6 @@ func TestTrain_ClusterMerge(t *testing.T) {
6767
}
6868
}
6969

70-
func TestMatch_InferenceOnly(t *testing.T) {
71-
m, err := NewMiner(DefaultConfig())
72-
if err != nil {
73-
t.Fatalf("NewMiner: %v", err)
74-
}
75-
// Train once.
76-
_, err = m.Train("stage=plan action=start")
77-
if err != nil {
78-
t.Fatalf("Train: %v", err)
79-
}
80-
before := m.ClusterCount()
81-
82-
// Match should not create new clusters.
83-
_, _, err = m.Match("stage=plan action=unknown_value")
84-
if err != nil {
85-
t.Fatalf("Match: unexpected error: %v", err)
86-
}
87-
if m.ClusterCount() != before {
88-
t.Errorf("Match: cluster count changed from %d to %d", before, m.ClusterCount())
89-
}
90-
}
91-
9270
func TestMasking(t *testing.T) {
9371
masker, err := NewMasker(DefaultConfig().MaskRules)
9472
if err != nil {
@@ -154,38 +132,6 @@ func TestFlattenEvent(t *testing.T) {
154132
}
155133
}
156134

157-
func TestSaveLoadJSON(t *testing.T) {
158-
cfg := DefaultConfig()
159-
m, err := NewMiner(cfg)
160-
if err != nil {
161-
t.Fatalf("NewMiner: %v", err)
162-
}
163-
lines := []string{
164-
"stage=plan action=start",
165-
"stage=plan action=start",
166-
"stage=tool_call tool=search",
167-
}
168-
for _, l := range lines {
169-
if _, err := m.Train(l); err != nil {
170-
t.Fatalf("Train(%q): %v", l, err)
171-
}
172-
}
173-
originalCount := m.ClusterCount()
174-
175-
data, err := m.SaveJSON()
176-
if err != nil {
177-
t.Fatalf("SaveJSON: %v", err)
178-
}
179-
180-
m2, err := LoadMinerJSON(data)
181-
if err != nil {
182-
t.Fatalf("LoadMinerJSON: %v", err)
183-
}
184-
if m2.ClusterCount() != originalCount {
185-
t.Errorf("round-trip: expected %d clusters, got %d", originalCount, m2.ClusterCount())
186-
}
187-
}
188-
189135
func TestConcurrency(t *testing.T) {
190136
m, err := NewMiner(DefaultConfig())
191137
if err != nil {

pkg/agentdrain/persist.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,3 @@ func (m *Miner) LoadJSON(data []byte) error {
8585
persistLog.Printf("Loaded miner state: clusters=%d", len(snap.Clusters))
8686
return nil
8787
}
88-
89-
// LoadMinerJSON creates a new Miner by restoring state from JSON bytes.
90-
func LoadMinerJSON(data []byte) (*Miner, error) {
91-
var snap Snapshot
92-
if err := json.Unmarshal(data, &snap); err != nil {
93-
return nil, fmt.Errorf("agentdrain: LoadMinerJSON: %w", err)
94-
}
95-
m, err := NewMiner(snap.Config)
96-
if err != nil {
97-
return nil, err
98-
}
99-
if err := m.LoadJSON(data); err != nil {
100-
return nil, err
101-
}
102-
return m, nil
103-
}

pkg/workflow/compiler_draft_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ This is a test workflow for draft filtering.
184184

185185
if tt.shouldHaveIf {
186186
// Check that the expected if condition is present (normalize for multiline comparison)
187-
normalizedLockContent := NormalizeExpressionForComparison(lockContent)
188-
normalizedExpectedIf := NormalizeExpressionForComparison(tt.expectedIf)
187+
normalizedLockContent := strings.Join(strings.Fields(lockContent), " ")
188+
normalizedExpectedIf := strings.Join(strings.Fields(tt.expectedIf), " ")
189189
if !strings.Contains(normalizedLockContent, normalizedExpectedIf) {
190190
t.Errorf("Expected lock file to contain '%s' but it didn't.\nExpected (normalized): %s\nActual (normalized): %s\nOriginal Content:\n%s",
191191
tt.expectedIf, normalizedExpectedIf, normalizedLockContent, lockContent)

pkg/workflow/compiler_events_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ This is a test workflow for command triggering.
236236
}
237237

238238
// Check that the expected if condition is present (normalize for multiline comparison)
239-
normalizedLockContent := NormalizeExpressionForComparison(lockContent)
240-
normalizedExpectedIf := NormalizeExpressionForComparison(tt.expectedIf)
239+
normalizedLockContent := strings.Join(strings.Fields(lockContent), " ")
240+
normalizedExpectedIf := strings.Join(strings.Fields(tt.expectedIf), " ")
241241
if !strings.Contains(normalizedLockContent, normalizedExpectedIf) {
242242
t.Errorf("Expected lock file to contain '%s' but it didn't.\nExpected (normalized): %s\nActual (normalized): %s\nOriginal Content:\n%s",
243243
tt.expectedIf, normalizedExpectedIf, normalizedLockContent, lockContent)
@@ -464,8 +464,8 @@ This is a test workflow for command merging with other events.
464464
}
465465

466466
// Check that the expected if condition is present (normalize for multiline comparison)
467-
normalizedLockContent := NormalizeExpressionForComparison(lockContent)
468-
normalizedExpectedIf := NormalizeExpressionForComparison(tt.expectedIf)
467+
normalizedLockContent := strings.Join(strings.Fields(lockContent), " ")
468+
normalizedExpectedIf := strings.Join(strings.Fields(tt.expectedIf), " ")
469469
if !strings.Contains(normalizedLockContent, normalizedExpectedIf) {
470470
t.Errorf("Expected lock file to contain '%s' but it didn't.\nExpected (normalized): %s\nActual (normalized): %s\nOriginal Content:\n%s",
471471
tt.expectedIf, normalizedExpectedIf, normalizedLockContent, lockContent)

pkg/workflow/expression_parser.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,3 @@ func escapeForYAMLDoubleQuoted(s string) string {
508508
}
509509
return b.String()
510510
}
511-
512-
// NormalizeExpressionForComparison normalizes an expression by removing extra spaces and newlines
513-
// This is used for comparing multiline expressions with their single-line equivalents
514-
func NormalizeExpressionForComparison(expression string) string {
515-
// Replace newlines and tabs with spaces
516-
normalized := strings.ReplaceAll(expression, "\n", " ")
517-
normalized = strings.ReplaceAll(normalized, "\t", " ")
518-
519-
// Replace multiple spaces with single spaces
520-
for strings.Contains(normalized, " ") {
521-
normalized = strings.ReplaceAll(normalized, " ", " ")
522-
}
523-
524-
// Trim leading and trailing spaces
525-
return strings.TrimSpace(normalized)
526-
}

pkg/workflow/expressions_test.go

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,8 @@ func TestBreakLongExpression(t *testing.T) {
946946

947947
// Verify that joined lines equal normalized original (whitespace differences allowed)
948948
joined := strings.Join(lines, " ")
949-
originalNorm := NormalizeExpressionForComparison(tt.expression)
950-
joinedNorm := NormalizeExpressionForComparison(joined)
949+
originalNorm := strings.Join(strings.Fields(tt.expression), " ")
950+
joinedNorm := strings.Join(strings.Fields(joined), " ")
951951

952952
if joinedNorm != originalNorm {
953953
t.Errorf("Joined lines don't match original expression\nOriginal: %s\nJoined: %s", originalNorm, joinedNorm)
@@ -985,8 +985,8 @@ func TestBreakAtParentheses(t *testing.T) {
985985

986986
// Verify that joined lines equal normalized original
987987
joined := strings.Join(lines, " ")
988-
originalNorm := NormalizeExpressionForComparison(tt.expression)
989-
joinedNorm := NormalizeExpressionForComparison(joined)
988+
originalNorm := strings.Join(strings.Fields(tt.expression), " ")
989+
joinedNorm := strings.Join(strings.Fields(joined), " ")
990990

991991
if joinedNorm != originalNorm {
992992
t.Errorf("Joined lines don't match original expression\nOriginal: %s\nJoined: %s", originalNorm, joinedNorm)
@@ -995,48 +995,6 @@ func TestBreakAtParentheses(t *testing.T) {
995995
}
996996
}
997997

998-
// TestNormalizeExpressionForComparison tests the expression normalization function
999-
func TestNormalizeExpressionForComparison(t *testing.T) {
1000-
tests := []struct {
1001-
name string
1002-
input string
1003-
expected string
1004-
}{
1005-
{
1006-
name: "single line with extra spaces",
1007-
input: "github.event_name == 'issues' || github.event.action == 'opened'",
1008-
expected: "github.event_name == 'issues' || github.event.action == 'opened'",
1009-
},
1010-
{
1011-
name: "multiline expression",
1012-
input: `github.event_name == 'issues' ||
1013-
github.event_name == 'pull_request' ||
1014-
github.event.action == 'opened'`,
1015-
expected: "github.event_name == 'issues' || github.event_name == 'pull_request' || github.event.action == 'opened'",
1016-
},
1017-
{
1018-
name: "expression with mixed whitespace",
1019-
input: `github.event_name == 'issues' ||
1020-
github.event_name == 'pull_request'`,
1021-
expected: "github.event_name == 'issues' || github.event_name == 'pull_request'",
1022-
},
1023-
{
1024-
name: "expression with leading/trailing whitespace",
1025-
input: " github.event_name == 'issues' ",
1026-
expected: "github.event_name == 'issues'",
1027-
},
1028-
}
1029-
1030-
for _, tt := range tests {
1031-
t.Run(tt.name, func(t *testing.T) {
1032-
result := NormalizeExpressionForComparison(tt.input)
1033-
if result != tt.expected {
1034-
t.Errorf("NormalizeExpressionForComparison() = '%s', expected '%s'", result, tt.expected)
1035-
}
1036-
})
1037-
}
1038-
}
1039-
1040998
// TestMultilineExpressionEquivalence tests that multiline expressions are equivalent to single-line expressions
1041999
func TestMultilineExpressionEquivalence(t *testing.T) {
10421000
tests := []struct {
@@ -1079,8 +1037,8 @@ github.event_name == 'issue_comment' ||
10791037

10801038
for _, tt := range tests {
10811039
t.Run(tt.name, func(t *testing.T) {
1082-
singleNorm := NormalizeExpressionForComparison(tt.singleLine)
1083-
multiNorm := NormalizeExpressionForComparison(tt.multiLine)
1040+
singleNorm := strings.Join(strings.Fields(tt.singleLine), " ")
1041+
multiNorm := strings.Join(strings.Fields(tt.multiLine), " ")
10841042

10851043
isEqual := singleNorm == multiNorm
10861044
if isEqual != tt.shouldBeEqual {
@@ -1134,8 +1092,8 @@ func TestLongExpressionBreakingDetailed(t *testing.T) {
11341092

11351093
// Most importantly: verify equivalence
11361094
joined := strings.Join(lines, " ")
1137-
originalNorm := NormalizeExpressionForComparison(tt.expression)
1138-
joinedNorm := NormalizeExpressionForComparison(joined)
1095+
originalNorm := strings.Join(strings.Fields(tt.expression), " ")
1096+
joinedNorm := strings.Join(strings.Fields(joined), " ")
11391097

11401098
if joinedNorm != originalNorm {
11411099
t.Errorf("Broken expression is not equivalent to original\nOriginal: %s\nBroken: %s\nJoined: %s\nOriginal normalized: %s\nJoined normalized: %s",
@@ -1175,8 +1133,8 @@ func TestExpressionBreakingWithQuotes(t *testing.T) {
11751133

11761134
// Verify that quotes are preserved and no breaking happens inside quoted strings
11771135
joined := strings.Join(lines, " ")
1178-
originalNorm := NormalizeExpressionForComparison(tt.expression)
1179-
joinedNorm := NormalizeExpressionForComparison(joined)
1136+
originalNorm := strings.Join(strings.Fields(tt.expression), " ")
1137+
joinedNorm := strings.Join(strings.Fields(joined), " ")
11801138

11811139
if joinedNorm != originalNorm {
11821140
t.Errorf("Expression with quotes not preserved correctly\nOriginal: %s\nJoined: %s", originalNorm, joinedNorm)

0 commit comments

Comments
 (0)