mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-19 08:44:22 +01:00
553 lines
13 KiB
Go
553 lines
13 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 TestSessionNewWithOptionalParams(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.Session.New(context.TODO(), opencode.SessionNewParams{
|
|
Directory: opencode.F("directory"),
|
|
ParentID: opencode.F("sesJ!"),
|
|
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 TestSessionUpdateWithOptionalParams(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.Session.Update(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionUpdateParams{
|
|
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 TestSessionListWithOptionalParams(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.Session.List(context.TODO(), opencode.SessionListParams{
|
|
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 TestSessionDeleteWithOptionalParams(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.Session.Delete(
|
|
context.TODO(),
|
|
"sesJ!",
|
|
opencode.SessionDeleteParams{
|
|
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 TestSessionAbortWithOptionalParams(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.Session.Abort(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionAbortParams{
|
|
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 TestSessionChildrenWithOptionalParams(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.Session.Children(
|
|
context.TODO(),
|
|
"sesJ!",
|
|
opencode.SessionChildrenParams{
|
|
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 TestSessionCommandWithOptionalParams(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.Session.Command(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionCommandParams{
|
|
Arguments: opencode.F("arguments"),
|
|
Command: opencode.F("command"),
|
|
Directory: opencode.F("directory"),
|
|
Agent: opencode.F("agent"),
|
|
MessageID: opencode.F("msgJ!"),
|
|
Model: opencode.F("model"),
|
|
},
|
|
)
|
|
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 TestSessionGetWithOptionalParams(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.Session.Get(
|
|
context.TODO(),
|
|
"sesJ!",
|
|
opencode.SessionGetParams{
|
|
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 TestSessionInitWithOptionalParams(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.Session.Init(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionInitParams{
|
|
MessageID: opencode.F("msgJ!"),
|
|
ModelID: opencode.F("modelID"),
|
|
ProviderID: opencode.F("providerID"),
|
|
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 TestSessionMessageWithOptionalParams(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.Session.Message(
|
|
context.TODO(),
|
|
"id",
|
|
"messageID",
|
|
opencode.SessionMessageParams{
|
|
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 TestSessionMessagesWithOptionalParams(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.Session.Messages(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionMessagesParams{
|
|
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 TestSessionPromptWithOptionalParams(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.Session.Prompt(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionPromptParams{
|
|
Parts: opencode.F([]opencode.SessionPromptParamsPartUnion{opencode.TextPartInputParam{
|
|
Text: opencode.F("text"),
|
|
Type: opencode.F(opencode.TextPartInputTypeText),
|
|
ID: opencode.F("id"),
|
|
Metadata: opencode.F(map[string]interface{}{
|
|
"foo": "bar",
|
|
}),
|
|
Synthetic: opencode.F(true),
|
|
Time: opencode.F(opencode.TextPartInputTimeParam{
|
|
Start: opencode.F(0.000000),
|
|
End: opencode.F(0.000000),
|
|
}),
|
|
}}),
|
|
Directory: opencode.F("directory"),
|
|
Agent: opencode.F("agent"),
|
|
MessageID: opencode.F("msgJ!"),
|
|
Model: opencode.F(opencode.SessionPromptParamsModel{
|
|
ModelID: opencode.F("modelID"),
|
|
ProviderID: opencode.F("providerID"),
|
|
}),
|
|
NoReply: opencode.F(true),
|
|
System: opencode.F("system"),
|
|
Tools: opencode.F(map[string]bool{
|
|
"foo": true,
|
|
}),
|
|
},
|
|
)
|
|
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 TestSessionRevertWithOptionalParams(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.Session.Revert(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionRevertParams{
|
|
MessageID: opencode.F("msgJ!"),
|
|
Directory: opencode.F("directory"),
|
|
PartID: opencode.F("prtJ!"),
|
|
},
|
|
)
|
|
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 TestSessionShareWithOptionalParams(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.Session.Share(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionShareParams{
|
|
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 TestSessionShellWithOptionalParams(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.Session.Shell(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionShellParams{
|
|
Agent: opencode.F("agent"),
|
|
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 TestSessionSummarizeWithOptionalParams(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.Session.Summarize(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionSummarizeParams{
|
|
ModelID: opencode.F("modelID"),
|
|
ProviderID: opencode.F("providerID"),
|
|
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 TestSessionUnrevertWithOptionalParams(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.Session.Unrevert(
|
|
context.TODO(),
|
|
"id",
|
|
opencode.SessionUnrevertParams{
|
|
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 TestSessionUnshareWithOptionalParams(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.Session.Unshare(
|
|
context.TODO(),
|
|
"sesJ!",
|
|
opencode.SessionUnshareParams{
|
|
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())
|
|
}
|
|
}
|