session_test.go 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. Agent: opencode.F("agent"),
  125. MessageID: opencode.F("msg"),
  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 TestSessionMessage(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.Message(
  182. context.TODO(),
  183. "id",
  184. "messageID",
  185. )
  186. if err != nil {
  187. var apierr *opencode.Error
  188. if errors.As(err, &apierr) {
  189. t.Log(string(apierr.DumpRequest(true)))
  190. }
  191. t.Fatalf("err should be nil: %s", err.Error())
  192. }
  193. }
  194. func TestSessionMessages(t *testing.T) {
  195. t.Skip("skipped: tests are disabled for the time being")
  196. baseURL := "http://localhost:4010"
  197. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  198. baseURL = envURL
  199. }
  200. if !testutil.CheckTestServer(t, baseURL) {
  201. return
  202. }
  203. client := opencode.NewClient(
  204. option.WithBaseURL(baseURL),
  205. )
  206. _, err := client.Session.Messages(context.TODO(), "id")
  207. if err != nil {
  208. var apierr *opencode.Error
  209. if errors.As(err, &apierr) {
  210. t.Log(string(apierr.DumpRequest(true)))
  211. }
  212. t.Fatalf("err should be nil: %s", err.Error())
  213. }
  214. }
  215. func TestSessionRevertWithOptionalParams(t *testing.T) {
  216. t.Skip("skipped: tests are disabled for the time being")
  217. baseURL := "http://localhost:4010"
  218. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  219. baseURL = envURL
  220. }
  221. if !testutil.CheckTestServer(t, baseURL) {
  222. return
  223. }
  224. client := opencode.NewClient(
  225. option.WithBaseURL(baseURL),
  226. )
  227. _, err := client.Session.Revert(
  228. context.TODO(),
  229. "id",
  230. opencode.SessionRevertParams{
  231. MessageID: opencode.F("msg"),
  232. PartID: opencode.F("prt"),
  233. },
  234. )
  235. if err != nil {
  236. var apierr *opencode.Error
  237. if errors.As(err, &apierr) {
  238. t.Log(string(apierr.DumpRequest(true)))
  239. }
  240. t.Fatalf("err should be nil: %s", err.Error())
  241. }
  242. }
  243. func TestSessionShare(t *testing.T) {
  244. t.Skip("skipped: tests are disabled for the time being")
  245. baseURL := "http://localhost:4010"
  246. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  247. baseURL = envURL
  248. }
  249. if !testutil.CheckTestServer(t, baseURL) {
  250. return
  251. }
  252. client := opencode.NewClient(
  253. option.WithBaseURL(baseURL),
  254. )
  255. _, err := client.Session.Share(context.TODO(), "id")
  256. if err != nil {
  257. var apierr *opencode.Error
  258. if errors.As(err, &apierr) {
  259. t.Log(string(apierr.DumpRequest(true)))
  260. }
  261. t.Fatalf("err should be nil: %s", err.Error())
  262. }
  263. }
  264. func TestSessionSummarize(t *testing.T) {
  265. t.Skip("skipped: tests are disabled for the time being")
  266. baseURL := "http://localhost:4010"
  267. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  268. baseURL = envURL
  269. }
  270. if !testutil.CheckTestServer(t, baseURL) {
  271. return
  272. }
  273. client := opencode.NewClient(
  274. option.WithBaseURL(baseURL),
  275. )
  276. _, err := client.Session.Summarize(
  277. context.TODO(),
  278. "id",
  279. opencode.SessionSummarizeParams{
  280. ModelID: opencode.F("modelID"),
  281. ProviderID: opencode.F("providerID"),
  282. },
  283. )
  284. if err != nil {
  285. var apierr *opencode.Error
  286. if errors.As(err, &apierr) {
  287. t.Log(string(apierr.DumpRequest(true)))
  288. }
  289. t.Fatalf("err should be nil: %s", err.Error())
  290. }
  291. }
  292. func TestSessionUnrevert(t *testing.T) {
  293. t.Skip("skipped: tests are disabled for the time being")
  294. baseURL := "http://localhost:4010"
  295. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  296. baseURL = envURL
  297. }
  298. if !testutil.CheckTestServer(t, baseURL) {
  299. return
  300. }
  301. client := opencode.NewClient(
  302. option.WithBaseURL(baseURL),
  303. )
  304. _, err := client.Session.Unrevert(context.TODO(), "id")
  305. if err != nil {
  306. var apierr *opencode.Error
  307. if errors.As(err, &apierr) {
  308. t.Log(string(apierr.DumpRequest(true)))
  309. }
  310. t.Fatalf("err should be nil: %s", err.Error())
  311. }
  312. }
  313. func TestSessionUnshare(t *testing.T) {
  314. t.Skip("skipped: tests are disabled for the time being")
  315. baseURL := "http://localhost:4010"
  316. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  317. baseURL = envURL
  318. }
  319. if !testutil.CheckTestServer(t, baseURL) {
  320. return
  321. }
  322. client := opencode.NewClient(
  323. option.WithBaseURL(baseURL),
  324. )
  325. _, err := client.Session.Unshare(context.TODO(), "id")
  326. if err != nil {
  327. var apierr *opencode.Error
  328. if errors.As(err, &apierr) {
  329. t.Log(string(apierr.DumpRequest(true)))
  330. }
  331. t.Fatalf("err should be nil: %s", err.Error())
  332. }
  333. }