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
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/versenilvis/iris/root"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
func TestMergeResults(t *testing.T) {
|
||||
@@ -27,4 +28,23 @@ func TestMergeResults(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user