feat(scoring): transition workflow learning and fix history UX (#39)
- 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
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDetect_GitAndGoProject(t *testing.T) {
|
||||
@@ -115,3 +116,38 @@ func TestDetect_MultiEcosystems(t *testing.T) {
|
||||
t.Error("expected HasK8s to be true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectCached_BranchSwitchWithoutDirChange(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
gitDir := filepath.Join(tmp, ".git")
|
||||
_ = os.Mkdir(gitDir, 0755)
|
||||
|
||||
headPath := filepath.Join(gitDir, "HEAD")
|
||||
_ = os.WriteFile(headPath, []byte("ref: refs/heads/main\n"), 0644)
|
||||
|
||||
dirInfoBefore, _ := os.Stat(tmp)
|
||||
|
||||
info1 := DetectCached(tmp)
|
||||
if info1.GitBranch != "main" {
|
||||
t.Fatalf("expected branch 'main', got %q", info1.GitBranch)
|
||||
}
|
||||
|
||||
// Simulate branch switch by updating .git/HEAD only
|
||||
// (this does not update the modtime of tmp on typical filesystems since tmp's direct children didn't change)
|
||||
_ = os.WriteFile(headPath, []byte("ref: refs/heads/feature\n"), 0644)
|
||||
|
||||
// Force the modtime of HEAD to be distinct to avoid flakiness on low-res file systems
|
||||
infoAfter, _ := os.Stat(headPath)
|
||||
newMod := infoAfter.ModTime().Add(2 * time.Second)
|
||||
_ = os.Chtimes(headPath, newMod, newMod)
|
||||
|
||||
dirInfoAfter, _ := os.Stat(tmp)
|
||||
if dirInfoBefore.ModTime() != dirInfoAfter.ModTime() {
|
||||
t.Log("Note: directory modtime changed automatically on this filesystem")
|
||||
}
|
||||
|
||||
info2 := DetectCached(tmp)
|
||||
if info2.GitBranch != "feature" {
|
||||
t.Fatalf("expected branch 'feature', got %q", info2.GitBranch)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user