MCPcopy Create free account
hub / github.com/diillson/chatcli / TestRulesLoader_PathSpecificRule

Function TestRulesLoader_PathSpecificRule

cli/workspace/rules_test.go:29–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27}
28
29func 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 := `---
36paths: ["*.go", "src/**"]
37---
38
39All 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
63func TestRulesLoader_WorkspaceOverridesGlobal(t *testing.T) {
64 globalDir := t.TempDir()

Callers

nothing calls this directly

Calls 4

LoadMatchingRulesMethod · 0.95
NewRulesLoaderFunction · 0.85
ErrorfMethod · 0.80
testLoggerFunction · 0.70

Tested by

no test coverage detected