session_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode_test
  3. import (
  4. "context"
  5. "errors"
  6. "os"
  7. "testing"
  8. "github.com/sst/opencode-sdk-go"
  9. "github.com/sst/opencode-sdk-go/internal/testutil"
  10. "github.com/sst/opencode-sdk-go/option"
  11. )
  12. func TestSessionNew(t *testing.T) {
  13. t.Skip("skipped: tests are disabled for the time being")
  14. baseURL := "http://localhost:4010"
  15. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  16. baseURL = envURL
  17. }
  18. if !testutil.CheckTestServer(t, baseURL) {
  19. return
  20. }
  21. client := opencode.NewClient(
  22. option.WithBaseURL(baseURL),
  23. )
  24. _, err := client.Session.New(context.TODO())
  25. if err != nil {
  26. var apierr *opencode.Error
  27. if errors.As(err, &apierr) {
  28. t.Log(string(apierr.DumpRequest(true)))
  29. }
  30. t.Fatalf("err should be nil: %s", err.Error())
  31. }
  32. }
  33. func TestSessionList(t *testing.T) {
  34. t.Skip("skipped: tests are disabled for the time being")
  35. baseURL := "http://localhost:4010"
  36. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  37. baseURL = envURL
  38. }
  39. if !testutil.CheckTestServer(t, baseURL) {
  40. return
  41. }
  42. client := opencode.NewClient(
  43. option.WithBaseURL(baseURL),
  44. )
  45. _, err := client.Session.List(context.TODO())
  46. if err != nil {
  47. var apierr *opencode.Error
  48. if errors.As(err, &apierr) {
  49. t.Log(string(apierr.DumpRequest(true)))
  50. }
  51. t.Fatalf("err should be nil: %s", err.Error())
  52. }
  53. }
  54. func TestSessionDelete(t *testing.T) {
  55. t.Skip("skipped: tests are disabled for the time being")
  56. baseURL := "http://localhost:4010"
  57. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  58. baseURL = envURL
  59. }
  60. if !testutil.CheckTestServer(t, baseURL) {
  61. return
  62. }
  63. client := opencode.NewClient(
  64. option.WithBaseURL(baseURL),
  65. )
  66. _, err := client.Session.Delete(context.TODO(), "id")
  67. if err != nil {
  68. var apierr *opencode.Error
  69. if errors.As(err, &apierr) {
  70. t.Log(string(apierr.DumpRequest(true)))
  71. }
  72. t.Fatalf("err should be nil: %s", err.Error())
  73. }
  74. }
  75. func TestSessionAbort(t *testing.T) {
  76. t.Skip("skipped: tests are disabled for the time being")
  77. baseURL := "http://localhost:4010"
  78. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  79. baseURL = envURL
  80. }
  81. if !testutil.CheckTestServer(t, baseURL) {
  82. return
  83. }
  84. client := opencode.NewClient(
  85. option.WithBaseURL(baseURL),
  86. )
  87. _, err := client.Session.Abort(context.TODO(), "id")
  88. if err != nil {
  89. var apierr *opencode.Error
  90. if errors.As(err, &apierr) {
  91. t.Log(string(apierr.DumpRequest(true)))
  92. }
  93. t.Fatalf("err should be nil: %s", err.Error())
  94. }
  95. }
  96. func TestSessionChat(t *testing.T) {
  97. t.Skip("skipped: tests are disabled for the time being")
  98. baseURL := "http://localhost:4010"
  99. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  100. baseURL = envURL
  101. }
  102. if !testutil.CheckTestServer(t, baseURL) {
  103. return
  104. }
  105. client := opencode.NewClient(
  106. option.WithBaseURL(baseURL),
  107. )
  108. _, err := client.Session.Chat(
  109. context.TODO(),
  110. "id",
  111. opencode.SessionChatParams{
  112. ModelID: opencode.F("modelID"),
  113. Parts: opencode.F([]opencode.UserMessagePartUnionParam{opencode.TextPartParam{
  114. Text: opencode.F("text"),
  115. Type: opencode.F(opencode.TextPartTypeText),
  116. }}),
  117. ProviderID: opencode.F("providerID"),
  118. },
  119. )
  120. if err != nil {
  121. var apierr *opencode.Error
  122. if errors.As(err, &apierr) {
  123. t.Log(string(apierr.DumpRequest(true)))
  124. }
  125. t.Fatalf("err should be nil: %s", err.Error())
  126. }
  127. }
  128. func TestSessionInit(t *testing.T) {
  129. t.Skip("skipped: tests are disabled for the time being")
  130. baseURL := "http://localhost:4010"
  131. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  132. baseURL = envURL
  133. }
  134. if !testutil.CheckTestServer(t, baseURL) {
  135. return
  136. }
  137. client := opencode.NewClient(
  138. option.WithBaseURL(baseURL),
  139. )
  140. _, err := client.Session.Init(
  141. context.TODO(),
  142. "id",
  143. opencode.SessionInitParams{
  144. ModelID: opencode.F("modelID"),
  145. ProviderID: opencode.F("providerID"),
  146. },
  147. )
  148. if err != nil {
  149. var apierr *opencode.Error
  150. if errors.As(err, &apierr) {
  151. t.Log(string(apierr.DumpRequest(true)))
  152. }
  153. t.Fatalf("err should be nil: %s", err.Error())
  154. }
  155. }
  156. func TestSessionMessages(t *testing.T) {
  157. t.Skip("skipped: tests are disabled for the time being")
  158. baseURL := "http://localhost:4010"
  159. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  160. baseURL = envURL
  161. }
  162. if !testutil.CheckTestServer(t, baseURL) {
  163. return
  164. }
  165. client := opencode.NewClient(
  166. option.WithBaseURL(baseURL),
  167. )
  168. _, err := client.Session.Messages(context.TODO(), "id")
  169. if err != nil {
  170. var apierr *opencode.Error
  171. if errors.As(err, &apierr) {
  172. t.Log(string(apierr.DumpRequest(true)))
  173. }
  174. t.Fatalf("err should be nil: %s", err.Error())
  175. }
  176. }
  177. func TestSessionShare(t *testing.T) {
  178. t.Skip("skipped: tests are disabled for the time being")
  179. baseURL := "http://localhost:4010"
  180. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  181. baseURL = envURL
  182. }
  183. if !testutil.CheckTestServer(t, baseURL) {
  184. return
  185. }
  186. client := opencode.NewClient(
  187. option.WithBaseURL(baseURL),
  188. )
  189. _, err := client.Session.Share(context.TODO(), "id")
  190. if err != nil {
  191. var apierr *opencode.Error
  192. if errors.As(err, &apierr) {
  193. t.Log(string(apierr.DumpRequest(true)))
  194. }
  195. t.Fatalf("err should be nil: %s", err.Error())
  196. }
  197. }
  198. func TestSessionSummarize(t *testing.T) {
  199. t.Skip("skipped: tests are disabled for the time being")
  200. baseURL := "http://localhost:4010"
  201. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  202. baseURL = envURL
  203. }
  204. if !testutil.CheckTestServer(t, baseURL) {
  205. return
  206. }
  207. client := opencode.NewClient(
  208. option.WithBaseURL(baseURL),
  209. )
  210. _, err := client.Session.Summarize(
  211. context.TODO(),
  212. "id",
  213. opencode.SessionSummarizeParams{
  214. ModelID: opencode.F("modelID"),
  215. ProviderID: opencode.F("providerID"),
  216. },
  217. )
  218. if err != nil {
  219. var apierr *opencode.Error
  220. if errors.As(err, &apierr) {
  221. t.Log(string(apierr.DumpRequest(true)))
  222. }
  223. t.Fatalf("err should be nil: %s", err.Error())
  224. }
  225. }
  226. func TestSessionUnshare(t *testing.T) {
  227. t.Skip("skipped: tests are disabled for the time being")
  228. baseURL := "http://localhost:4010"
  229. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  230. baseURL = envURL
  231. }
  232. if !testutil.CheckTestServer(t, baseURL) {
  233. return
  234. }
  235. client := opencode.NewClient(
  236. option.WithBaseURL(baseURL),
  237. )
  238. _, err := client.Session.Unshare(context.TODO(), "id")
  239. if err != nil {
  240. var apierr *opencode.Error
  241. if errors.As(err, &apierr) {
  242. t.Log(string(apierr.DumpRequest(true)))
  243. }
  244. t.Fatalf("err should be nil: %s", err.Error())
  245. }
  246. }