closes #57 IRIS now automatically read and suggest internal configuration aliases for Git (`.gitconfig`, `.git/config`) and Cargo (`.cargo/config.toml`) - Added the `Provider` interface and extended registry for CLI tools that define aliases - Git: parse aliases via `git config --show-scope`, supporting raw tab/space separation and scope differentiation - Cargo: traverse the directory tree upwards to root to read the `.cargo/config.toml` configuration - 0ms hot-path caching: key caching is calculated entirely via `os.Stat` mtime (no subprocess spawn) combined with a 2-second TTL window to ensure 0ms latency when typing - Lookup integration: display alias suggestions at the subcommand level and automatically expand aliases as the user enters further arguments (ignore shell pipeline commands starting with `!`)
98 lines
2.4 KiB
Go
98 lines
2.4 KiB
Go
package root
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/versenilvis/iris/spec"
|
|
"github.com/versenilvis/iris/spec/alias"
|
|
)
|
|
|
|
func TestMergeResults(t *testing.T) {
|
|
|
|
t.Run("Dedup exact match", func(t *testing.T) {
|
|
// Mock history items that might conflict with specs
|
|
res := MergeResults("git", "spec")
|
|
seen := make(map[string]bool)
|
|
for _, r := range res {
|
|
if seen[r.Cmd] {
|
|
t.Errorf("Duplicate suggestion found: %q", r.Cmd)
|
|
}
|
|
seen[r.Cmd] = true
|
|
}
|
|
})
|
|
|
|
t.Run("Limit 100", func(t *testing.T) {
|
|
res := MergeResults("a", "history")
|
|
if len(res) > 100 {
|
|
t.Errorf("Expected max 100 suggestions, got %d", len(res))
|
|
}
|
|
})
|
|
|
|
t.Run("AI Suggestion Promotion", func(t *testing.T) {
|
|
aiSugg := &spec.Suggestion{
|
|
Cmd: "git commit -m \"fix(auth): login bug\"",
|
|
Desc: "AI suggestion",
|
|
Source: "ai",
|
|
Confidence: 85,
|
|
}
|
|
SetCurrentAISuggestion(aiSugg)
|
|
defer SetCurrentAISuggestion(nil)
|
|
|
|
res := MergeResults("git c", "history")
|
|
if len(res) == 0 {
|
|
t.Fatalf("Expected suggestions, got 0")
|
|
}
|
|
if res[0].Cmd != aiSugg.Cmd {
|
|
t.Errorf("Expected AI suggestion at index 0, got %q (confidence %d)", res[0].Cmd, res[0].Confidence)
|
|
}
|
|
if res[0].Source != "ai" {
|
|
t.Errorf("Expected promoted source 'ai', got %q", res[0].Source)
|
|
}
|
|
})
|
|
|
|
t.Run("Tool Alias Preserved When Matching Query", func(t *testing.T) {
|
|
alias.Register(&mockGitProvider{})
|
|
defer alias.Reset()
|
|
res := MergeResults("git co", "default")
|
|
foundCo := false
|
|
for _, r := range res {
|
|
if r.Cmd == "git co" {
|
|
foundCo = true
|
|
break
|
|
}
|
|
}
|
|
if !foundCo {
|
|
t.Errorf("expected 'git co' alias suggestion in results for query 'git co', got %v", res)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestPrevRecordedCommandState(t *testing.T) {
|
|
origRegistry := spec.Registry
|
|
t.Cleanup(func() {
|
|
spec.Registry = origRegistry
|
|
})
|
|
|
|
spec.ResetRegistry()
|
|
spec.Register(&spec.Spec{
|
|
Name: "git",
|
|
Subcommands: []spec.Subcommand{
|
|
{Name: "checkout"},
|
|
},
|
|
})
|
|
|
|
setPrevRecordedInfo("git checkout feature-abc", "/repo/dir")
|
|
skel, cwd := getPrevRecordedInfo()
|
|
if skel != "git checkout" || cwd != "/repo/dir" {
|
|
t.Errorf("expected skel='git checkout' and cwd='/repo/dir', got skel=%q, cwd=%q", skel, cwd)
|
|
}
|
|
if gotSkel := getPrevSkeleton(); gotSkel != "git checkout" {
|
|
t.Errorf("expected getPrevSkeleton()='git checkout', got %q", gotSkel)
|
|
}
|
|
|
|
setPrevRecordedInfo("", "")
|
|
if gotSkel := getPrevSkeleton(); gotSkel != "" {
|
|
t.Errorf("expected empty getPrevSkeleton() after reset, got %q", gotSkel)
|
|
}
|
|
}
|