|
| 1 | +package hooks |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestScoreRelevance_Errors(t *testing.T) { |
| 6 | + score := ScoreRelevance("Bash", "npm install", "", "exit code 1") |
| 7 | + if score < 0.9 { |
| 8 | + t.Errorf("errors should score 0.9, got %f", score) |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +func TestScoreRelevance_FileModifications(t *testing.T) { |
| 13 | + score := ScoreRelevance("Write", "src/components/auth/main.go", "file written successfully to disk", "") |
| 14 | + if score < 0.7 { |
| 15 | + t.Errorf("Write tool should score >= 0.7, got %f", score) |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +func TestScoreRelevance_ReadLowSignal(t *testing.T) { |
| 20 | + score := ScoreRelevance("Read", "src/main.go", "package main...", "") |
| 21 | + if score > 0.5 { |
| 22 | + t.Errorf("Read tool should be low signal, got %f", score) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestScoreRelevance_BashInstall(t *testing.T) { |
| 27 | + score := ScoreRelevance("Bash", "npm install express morgan helmet", "added 50 packages in 3.2s", "") |
| 28 | + if score < 0.7 { |
| 29 | + t.Errorf("install commands should score >= 0.7, got %f", score) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func TestScoreRelevance_BashNavigation(t *testing.T) { |
| 34 | + score := ScoreRelevance("Bash", "ls src/", "main.go utils.go", "") |
| 35 | + if score > 0.3 { |
| 36 | + t.Errorf("navigation commands should be low signal, got %f", score) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +func TestScoreRelevance_DecisionSignal(t *testing.T) { |
| 41 | + score := ScoreRelevance("Bash", "decided to use jose", "switched to jose library", "") |
| 42 | + if score < 0.5 { |
| 43 | + t.Errorf("decision signals should boost score, got %f", score) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func TestShouldCapture_HighSignal(t *testing.T) { |
| 48 | + if !ShouldCapture("Write", "writing config", "done", "") { |
| 49 | + t.Error("Write tool should pass capture threshold") |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +func TestShouldCapture_LowSignal(t *testing.T) { |
| 54 | + if ShouldCapture("Read", "x", "y", "") { |
| 55 | + t.Error("short Read output should not pass capture threshold") |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestScoreRelevance_CappedAt1(t *testing.T) { |
| 60 | + score := ScoreRelevance("Write", "decided to always enforce convention required", "written pattern", "") |
| 61 | + if score > 1.0 { |
| 62 | + t.Errorf("score should never exceed 1.0, got %f", score) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func TestContainsDecisionSignal(t *testing.T) { |
| 67 | + if !containsDecisionSignal("we decided to use postgres") { |
| 68 | + t.Error("should detect 'decided'") |
| 69 | + } |
| 70 | + if containsDecisionSignal("the weather is nice") { |
| 71 | + t.Error("should not detect false positives") |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +func TestContainsConventionSignal(t *testing.T) { |
| 76 | + if !containsConventionSignal("always use camelCase") { |
| 77 | + t.Error("should detect 'always'") |
| 78 | + } |
| 79 | + if !containsConventionSignal("this is required for deployment") { |
| 80 | + t.Error("should detect 'required'") |
| 81 | + } |
| 82 | +} |
0 commit comments