mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-18 16:34:18 +01:00
This release has a bunch of minor breaking changes if you are using opencode plugins or sdk 1. storage events have been removed (we might bring this back but had some issues) 2. concept of `app` is gone - there is a new concept called `project` and endpoints to list projects and get the current project 3. plugin receives `directory` which is cwd and `worktree` which is where the root of the project is if it's a git repo 4. the session.chat function has been renamed to session.prompt in sdk. it no longer requires model to be passed in (model is now an object) 5. every endpoint takes an optional `directory` parameter to operate as though opencode is running in that directory
236 lines
6.0 KiB
Go
236 lines
6.0 KiB
Go
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
|
|
package opencode_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/sst/opencode-sdk-go"
|
|
"github.com/sst/opencode-sdk-go/internal/testutil"
|
|
"github.com/sst/opencode-sdk-go/option"
|
|
)
|
|
|
|
func TestTuiAppendPromptWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.AppendPrompt(context.TODO(), opencode.TuiAppendPromptParams{
|
|
Text: opencode.F("text"),
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiClearPromptWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.ClearPrompt(context.TODO(), opencode.TuiClearPromptParams{
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiExecuteCommandWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.ExecuteCommand(context.TODO(), opencode.TuiExecuteCommandParams{
|
|
Command: opencode.F("command"),
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiOpenHelpWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.OpenHelp(context.TODO(), opencode.TuiOpenHelpParams{
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiOpenModelsWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.OpenModels(context.TODO(), opencode.TuiOpenModelsParams{
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiOpenSessionsWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.OpenSessions(context.TODO(), opencode.TuiOpenSessionsParams{
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiOpenThemesWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.OpenThemes(context.TODO(), opencode.TuiOpenThemesParams{
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiShowToastWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.ShowToast(context.TODO(), opencode.TuiShowToastParams{
|
|
Message: opencode.F("message"),
|
|
Variant: opencode.F(opencode.TuiShowToastParamsVariantInfo),
|
|
Directory: opencode.F("directory"),
|
|
Title: opencode.F("title"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestTuiSubmitPromptWithOptionalParams(t *testing.T) {
|
|
t.Skip("Prism tests are disabled")
|
|
baseURL := "http://localhost:4010"
|
|
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
|
|
baseURL = envURL
|
|
}
|
|
if !testutil.CheckTestServer(t, baseURL) {
|
|
return
|
|
}
|
|
client := opencode.NewClient(
|
|
option.WithBaseURL(baseURL),
|
|
)
|
|
_, err := client.Tui.SubmitPrompt(context.TODO(), opencode.TuiSubmitPromptParams{
|
|
Directory: opencode.F("directory"),
|
|
})
|
|
if err != nil {
|
|
var apierr *opencode.Error
|
|
if errors.As(err, &apierr) {
|
|
t.Log(string(apierr.DumpRequest(true)))
|
|
}
|
|
t.Fatalf("err should be nil: %s", err.Error())
|
|
}
|
|
}
|