- add transition scoring engine to learn sequential workflows per directory using command skeletons - prioritize current active git branch over older branches in suggestions - restore strict chronological order for history navigation and bypass AI re-ranking - add in-memory session history for instant access to just-run commands - fix PTY prompt not syncing when using arrow keys in the history menu - fix history tie-breaker to properly prioritize newer commands by assigning larger IDs - fix potential mutex deadlock between bufferMu and pty write during history navigation - fix workspace git detection to remove depth limits and correctly identify repositories with detached HEADs - fix SQLite connection leaks in frecency queries - fix global state leaks in history tests by snapshotting and restoring registry states - modernize string prefix checks using strings.CutPrefix
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package scoring
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCollectSignals(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
_ = os.WriteFile(filepath.Join(tmpDir, "package.json"), []byte("{}"), 0644)
|
|
|
|
dbPath := filepath.Join(tmpDir, "history.db")
|
|
store, err := NewFrecencyStore(dbPath)
|
|
if err != nil {
|
|
t.Fatalf("NewFrecencyStore failed: %v", err)
|
|
}
|
|
defer store.Close()
|
|
|
|
_ = store.Record(context.Background(), "npm run dev", tmpDir, 0)
|
|
_ = store.Record(context.Background(), "npm test", "/other/dir", 0)
|
|
_ = store.RecordTransition(context.Background(), "git checkout", "npm run dev", tmpDir, 0)
|
|
|
|
signals := CollectSignals(context.Background(), tmpDir, "npm", "npm", store, "git checkout")
|
|
|
|
if !signals.Workspace.HasNodeProject {
|
|
t.Error("expected HasNodeProject to be true in collected signals")
|
|
}
|
|
if len(signals.LocalFrecency) != 1 || signals.LocalFrecency[0].Cmd != "npm run dev" {
|
|
t.Errorf("expected local frecency to contain 'npm run dev', got %v", signals.LocalFrecency)
|
|
}
|
|
if len(signals.GlobalFrecency) != 2 {
|
|
t.Errorf("expected global frecency to contain 2 entries, got %d", len(signals.GlobalFrecency))
|
|
}
|
|
if !signals.TransitionIsLocal || len(signals.TransitionEntries) != 1 || signals.TransitionEntries[0].NextSkeleton != "npm run dev" {
|
|
t.Errorf("expected transition entry 'npm run dev', got %v (isLocal=%v)", signals.TransitionEntries, signals.TransitionIsLocal)
|
|
}
|
|
}
|