session_test.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 TestSessionChatWithOptionalParams(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.SessionChatParamsPartUnion{opencode.TextPartInputParam{
  114. Text: opencode.F("text"),
  115. Type: opencode.F(opencode.TextPartInputTypeText),
  116. ID: opencode.F("id"),
  117. Synthetic: opencode.F(true),
  118. Time: opencode.F(opencode.TextPartInputTimeParam{
  119. Start: opencode.F(0.000000),
  120. End: opencode.F(0.000000),
  121. }),
  122. }}),
  123. ProviderID: opencode.F("providerID"),
  124. MessageID: opencode.F("msg"),
  125. Mode: opencode.F("mode"),
  126. Tools: opencode.F(map[string]bool{
  127. "foo": true,
  128. }),
  129. },
  130. )
  131. if err != nil {
  132. var apierr *opencode.Error
  133. if errors.As(err, &apierr) {
  134. t.Log(string(apierr.DumpRequest(true)))
  135. }
  136. t.Fatalf("err should be nil: %s", err.Error())
  137. }
  138. }
  139. func TestSessionInit(t *testing.T) {
  140. t.Skip("skipped: tests are disabled for the time being")
  141. baseURL := "http://localhost:4010"
  142. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  143. baseURL = envURL
  144. }
  145. if !testutil.CheckTestServer(t, baseURL) {
  146. return
  147. }
  148. client := opencode.NewClient(
  149. option.WithBaseURL(baseURL),
  150. )
  151. _, err := client.Session.Init(
  152. context.TODO(),
  153. "id",
  154. opencode.SessionInitParams{
  155. MessageID: opencode.F("messageID"),
  156. ModelID: opencode.F("modelID"),
  157. ProviderID: opencode.F("providerID"),
  158. },
  159. )
  160. if err != nil {
  161. var apierr *opencode.Error
  162. if errors.As(err, &apierr) {
  163. t.Log(string(apierr.DumpRequest(true)))
  164. }
  165. t.Fatalf("err should be nil: %s", err.Error())
  166. }
  167. }
  168. func TestSessionMessages(t *testing.T) {
  169. t.Skip("skipped: tests are disabled for the time being")
  170. baseURL := "http://localhost:4010"
  171. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  172. baseURL = envURL
  173. }
  174. if !testutil.CheckTestServer(t, baseURL) {
  175. return
  176. }
  177. client := opencode.NewClient(
  178. option.WithBaseURL(baseURL),
  179. )
  180. _, err := client.Session.Messages(context.TODO(), "id")
  181. if err != nil {
  182. var apierr *opencode.Error
  183. if errors.As(err, &apierr) {
  184. t.Log(string(apierr.DumpRequest(true)))
  185. }
  186. t.Fatalf("err should be nil: %s", err.Error())
  187. }
  188. }
  189. func TestSessionRevertWithOptionalParams(t *testing.T) {
  190. t.Skip("skipped: tests are disabled for the time being")
  191. baseURL := "http://localhost:4010"
  192. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  193. baseURL = envURL
  194. }
  195. if !testutil.CheckTestServer(t, baseURL) {
  196. return
  197. }
  198. client := opencode.NewClient(
  199. option.WithBaseURL(baseURL),
  200. )
  201. _, err := client.Session.Revert(
  202. context.TODO(),
  203. "id",
  204. opencode.SessionRevertParams{
  205. MessageID: opencode.F("msg"),
  206. PartID: opencode.F("prt"),
  207. },
  208. )
  209. if err != nil {
  210. var apierr *opencode.Error
  211. if errors.As(err, &apierr) {
  212. t.Log(string(apierr.DumpRequest(true)))
  213. }
  214. t.Fatalf("err should be nil: %s", err.Error())
  215. }
  216. }
  217. func TestSessionShare(t *testing.T) {
  218. t.Skip("skipped: tests are disabled for the time being")
  219. baseURL := "http://localhost:4010"
  220. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  221. baseURL = envURL
  222. }
  223. if !testutil.CheckTestServer(t, baseURL) {
  224. return
  225. }
  226. client := opencode.NewClient(
  227. option.WithBaseURL(baseURL),
  228. )
  229. _, err := client.Session.Share(context.TODO(), "id")
  230. if err != nil {
  231. var apierr *opencode.Error
  232. if errors.As(err, &apierr) {
  233. t.Log(string(apierr.DumpRequest(true)))
  234. }
  235. t.Fatalf("err should be nil: %s", err.Error())
  236. }
  237. }
  238. func TestSessionSummarize(t *testing.T) {
  239. t.Skip("skipped: tests are disabled for the time being")
  240. baseURL := "http://localhost:4010"
  241. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  242. baseURL = envURL
  243. }
  244. if !testutil.CheckTestServer(t, baseURL) {
  245. return
  246. }
  247. client := opencode.NewClient(
  248. option.WithBaseURL(baseURL),
  249. )
  250. _, err := client.Session.Summarize(
  251. context.TODO(),
  252. "id",
  253. opencode.SessionSummarizeParams{
  254. ModelID: opencode.F("modelID"),
  255. ProviderID: opencode.F("providerID"),
  256. },
  257. )
  258. if err != nil {
  259. var apierr *opencode.Error
  260. if errors.As(err, &apierr) {
  261. t.Log(string(apierr.DumpRequest(true)))
  262. }
  263. t.Fatalf("err should be nil: %s", err.Error())
  264. }
  265. }
  266. func TestSessionUnrevert(t *testing.T) {
  267. t.Skip("skipped: tests are disabled for the time being")
  268. baseURL := "http://localhost:4010"
  269. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  270. baseURL = envURL
  271. }
  272. if !testutil.CheckTestServer(t, baseURL) {
  273. return
  274. }
  275. client := opencode.NewClient(
  276. option.WithBaseURL(baseURL),
  277. )
  278. _, err := client.Session.Unrevert(context.TODO(), "id")
  279. if err != nil {
  280. var apierr *opencode.Error
  281. if errors.As(err, &apierr) {
  282. t.Log(string(apierr.DumpRequest(true)))
  283. }
  284. t.Fatalf("err should be nil: %s", err.Error())
  285. }
  286. }
  287. func TestSessionUnshare(t *testing.T) {
  288. t.Skip("skipped: tests are disabled for the time being")
  289. baseURL := "http://localhost:4010"
  290. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  291. baseURL = envURL
  292. }
  293. if !testutil.CheckTestServer(t, baseURL) {
  294. return
  295. }
  296. client := opencode.NewClient(
  297. option.WithBaseURL(baseURL),
  298. )
  299. _, err := client.Session.Unshare(context.TODO(), "id")
  300. if err != nil {
  301. var apierr *opencode.Error
  302. if errors.As(err, &apierr) {
  303. t.Log(string(apierr.DumpRequest(true)))
  304. }
  305. t.Fatalf("err should be nil: %s", err.Error())
  306. }
  307. }