(t *testing.T)
| 27 | } |
| 28 | |
| 29 | func TestRulesLoader_PathSpecificRule(t *testing.T) { |
| 30 | wsDir := t.TempDir() |
| 31 | rulesDir := filepath.Join(wsDir, ".chatcli", "rules") |
| 32 | _ = os.MkdirAll(rulesDir, 0o755) |
| 33 | |
| 34 | // Rule that only applies to Go files |
| 35 | rule := `--- |
| 36 | paths: ["*.go", "src/**"] |
| 37 | --- |
| 38 | |
| 39 | All Go files must have error handling for every returned error.` |
| 40 | _ = os.WriteFile(filepath.Join(rulesDir, "go-errors.md"), []byte(rule), 0o644) |
| 41 | |
| 42 | rl := NewRulesLoader(wsDir, t.TempDir(), testLogger()) |
| 43 | |
| 44 | // Should match when hint contains a .go file |
| 45 | result := rl.LoadMatchingRules([]string{"main.go"}) |
| 46 | if !strings.Contains(result, "error handling") { |
| 47 | t.Errorf("expected path-specific rule to match main.go, got %q", result) |
| 48 | } |
| 49 | |
| 50 | // Should match for src/** paths |
| 51 | result = rl.LoadMatchingRules([]string{"src/handler.go"}) |
| 52 | if !strings.Contains(result, "error handling") { |
| 53 | t.Errorf("expected path-specific rule to match src/handler.go, got %q", result) |
| 54 | } |
| 55 | |
| 56 | // Should NOT match non-Go files |
| 57 | result = rl.LoadMatchingRules([]string{"readme.txt"}) |
| 58 | if strings.Contains(result, "error handling") { |
| 59 | t.Errorf("did not expect rule to match readme.txt, got %q", result) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func TestRulesLoader_WorkspaceOverridesGlobal(t *testing.T) { |
| 64 | globalDir := t.TempDir() |
nothing calls this directly
no test coverage detected