Files
iris-context/tests/root/suggestions_test.go
T
VERSE 94c8af7b1d feat: AI suggestion (#34)
## Feat
* feat(ai): add AI suggestion engine, context gathering, and ghost text
overlay (`v0.3.0`)

## Security & Perf
* fix(ai): restrict background `--help` execution to a hardcoded command
allowlist to prevent RCE
* fix(root): defer context cancellation in goroutine to prevent resource
leaks
* perf(ai): implement LRU eviction and maximum size limit for
`ProviderCache`
* perf(ai): truncate command context output
(`CommandContextProvider.Gather`) to 1000 characters to save tokens

## Bug Fixes
* fix(ai): add mutex synchronization and thread-safe snapshotting to
`AIEngine.RegisterProvider` and `GatherDynamicContext`
* fix(ai): return a copy of fresh `Suggestion` in `AIEngine.Suggest` to
prevent cache mutation
* fix(ai): use length-prefixed encoding in `EnvSnapshot.Hash` to prevent
delimiter collisions
* fix(ai): skip variable assignment lines containing `=` when extracting
Makefile targets
* fix(runner): check `scanner.Err()` and return `nil` on scan errors in
justfile generator
* test(ci): rename `git commit` to `git checkout` in overlay test to
resolve CI `typos` false positive
2026-07-11 15:17:14 +07:00

51 lines
1.2 KiB
Go

package tests
import (
"testing"
"github.com/versenilvis/iris/root"
"github.com/versenilvis/iris/spec"
)
func TestMergeResults(t *testing.T) {
t.Run("Dedup exact match", func(t *testing.T) {
// Mock history items that might conflict with specs
res := root.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 := root.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,
}
root.SetCurrentAISuggestion(aiSugg)
defer root.SetCurrentAISuggestion(nil)
res := root.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)
}
})
}