session_test.go 8.0 KB

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