mirror of
https://github.com/ollama/ollama.git
synced 2026-04-20 00:54:27 +02:00
launch/opencode: detect curl installed opencode at ~/.opencode/bin (#15197)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -771,6 +772,40 @@ func TestLookupCloudModelLimit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOpenCode(t *testing.T) {
|
||||
t.Run("fallback to ~/.opencode/bin", func(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
setTestHome(t, tmpDir)
|
||||
|
||||
// Ensure opencode is not on PATH
|
||||
t.Setenv("PATH", tmpDir)
|
||||
|
||||
// Without the fallback binary, findOpenCode should fail
|
||||
if _, ok := findOpenCode(); ok {
|
||||
t.Fatal("findOpenCode should fail when binary is not on PATH or in fallback location")
|
||||
}
|
||||
|
||||
// Create a fake binary at the curl install fallback location
|
||||
binDir := filepath.Join(tmpDir, ".opencode", "bin")
|
||||
os.MkdirAll(binDir, 0o755)
|
||||
name := "opencode"
|
||||
if runtime.GOOS == "windows" {
|
||||
name = "opencode.exe"
|
||||
}
|
||||
fakeBin := filepath.Join(binDir, name)
|
||||
os.WriteFile(fakeBin, []byte("#!/bin/sh\n"), 0o755)
|
||||
|
||||
// Now findOpenCode should succeed via fallback
|
||||
path, ok := findOpenCode()
|
||||
if !ok {
|
||||
t.Fatal("findOpenCode should succeed with fallback binary")
|
||||
}
|
||||
if path != fakeBin {
|
||||
t.Errorf("findOpenCode = %q, want %q", path, fakeBin)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestOpenCodeModels_NoConfig(t *testing.T) {
|
||||
o := &OpenCode{}
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user