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:
@@ -0,0 +1,38 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
_ "github.com/versenilvis/iris/commands/runner"
|
||||
"github.com/versenilvis/iris/spec"
|
||||
)
|
||||
|
||||
// Verify that the just command generator parses recipes and returns nil on read errors
|
||||
func TestJustGenerator(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
content := []byte("# build project\nbuild:\n\techo build\n")
|
||||
_ = os.WriteFile(filepath.Join(tmp, "justfile"), content, 0644)
|
||||
|
||||
oldWd, _ := os.Getwd()
|
||||
_ = os.Chdir(tmp)
|
||||
defer func() { _ = os.Chdir(oldWd) }()
|
||||
|
||||
s := spec.Registry["just"]
|
||||
if s == nil || s.Generator == nil {
|
||||
t.Fatalf("expected just spec with generator to be registered in Registry")
|
||||
}
|
||||
|
||||
res := s.Generator([]string{"just", ""}, "just ", "")
|
||||
if len(res) != 1 || res[0].Cmd != "build" || res[0].Desc != "build project" {
|
||||
t.Fatalf("expected recipe build with comment, got %v", res)
|
||||
}
|
||||
|
||||
// Verify missing file returns nil
|
||||
_ = os.Remove(filepath.Join(tmp, "justfile"))
|
||||
resMissing := s.Generator([]string{"just", ""}, "just ", "")
|
||||
if resMissing != nil {
|
||||
t.Fatalf("expected nil when justfile cannot be read, got %v", resMissing)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user