biliPath looked for bili.cmd on PATH and in %APPDATA%\npm only. bun add -g puts bili.exe (with a bili.bunx) in the bin of BUN_INSTALL or ~\.bun\bin, so a bun install was never found. It now asks proc.FindTool, which tries .exe and .cmd in every folder a user's tools are installed in. proc's UserBinDirs also takes BUN_INSTALL's bin (Windows and elsewhere), and Kiro Crew's adapter search gets ~/.bun/bin, BUN_INSTALL's bin and, on Windows, %APPDATA%\npm, its siblings that had the same hole. Run: on xiaomi-gpu (Windows 11) really `bun add -g billion-context` into a sandbox BUN_INSTALL with PATH holding no bun bin. Before the fix biliPath was "" ; after, it was bili.exe and `bili --version` answered 0.1.213. go vet and go test -run Bili|KiroCrew|ToolIn|UserPath for library, agent and proc passed on Windows and in WSL (magpie-desktop). The three new tests fail on the old code in WSL (broken by hand with the sources stashed). Not run: the full suite, a darwin vet and a mote run (mote's disk was full, 226Mi free), the GUI suites (no GUI file touched).
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package library
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func bunBiliSandbox(t *testing.T, bun string) (home, name string) {
|
|
home = t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
|
t.Setenv("BUN_INSTALL", bun)
|
|
t.Setenv("PATH", t.TempDir())
|
|
name = "bili"
|
|
if runtime.GOOS == "windows" {
|
|
name = "bili.exe"
|
|
}
|
|
return home, name
|
|
}
|
|
|
|
// Zerenjie on X: on Windows magpie 0.1.3693 didn't find billion-context
|
|
// installed with bun. `bun add -g` puts bili.exe (a shim, bili.bunx beside
|
|
// it) in the bin of BUN_INSTALL, and biliPath looked for bili.cmd on PATH
|
|
// and in npm's folder only. bun's folder, and an exe, count too.
|
|
func TestBiliPathFindsBunsInstall(t *testing.T) {
|
|
bun := filepath.Join(t.TempDir(), "bun-home")
|
|
_, name := bunBiliSandbox(t, bun)
|
|
if got := biliPath(); got != "" {
|
|
t.Fatalf("nothing installed, found %q", got)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(bun, "bin"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := filepath.Join(bun, "bin", name)
|
|
if err := os.WriteFile(want, []byte("MZ"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := biliPath(); got != want {
|
|
t.Errorf("bun's bili: %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
// bun's default folder, ~/.bun/bin, with no BUN_INSTALL set.
|
|
func TestBiliPathFindsDefaultBun(t *testing.T) {
|
|
home, name := bunBiliSandbox(t, "")
|
|
dir := filepath.Join(home, ".bun", "bin")
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := filepath.Join(dir, name)
|
|
if err := os.WriteFile(want, []byte("MZ"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := biliPath(); got != want {
|
|
t.Errorf("~/.bun/bin's bili: %q, want %q", got, want)
|
|
}
|
|
}
|