session_test.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 TestSessionUpdateWithOptionalParams(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.Update(
  46. context.TODO(),
  47. "id",
  48. opencode.SessionUpdateParams{
  49. Title: opencode.F("title"),
  50. },
  51. )
  52. if err != nil {
  53. var apierr *opencode.Error
  54. if errors.As(err, &apierr) {
  55. t.Log(string(apierr.DumpRequest(true)))
  56. }
  57. t.Fatalf("err should be nil: %s", err.Error())
  58. }
  59. }
  60. func TestSessionList(t *testing.T) {
  61. t.Skip("skipped: tests are disabled for the time being")
  62. baseURL := "http://localhost:4010"
  63. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  64. baseURL = envURL
  65. }
  66. if !testutil.CheckTestServer(t, baseURL) {
  67. return
  68. }
  69. client := opencode.NewClient(
  70. option.WithBaseURL(baseURL),
  71. )
  72. _, err := client.Session.List(context.TODO())
  73. if err != nil {
  74. var apierr *opencode.Error
  75. if errors.As(err, &apierr) {
  76. t.Log(string(apierr.DumpRequest(true)))
  77. }
  78. t.Fatalf("err should be nil: %s", err.Error())
  79. }
  80. }
  81. func TestSessionDelete(t *testing.T) {
  82. t.Skip("skipped: tests are disabled for the time being")
  83. baseURL := "http://localhost:4010"
  84. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  85. baseURL = envURL
  86. }
  87. if !testutil.CheckTestServer(t, baseURL) {
  88. return
  89. }
  90. client := opencode.NewClient(
  91. option.WithBaseURL(baseURL),
  92. )
  93. _, err := client.Session.Delete(context.TODO(), "id")
  94. if err != nil {
  95. var apierr *opencode.Error
  96. if errors.As(err, &apierr) {
  97. t.Log(string(apierr.DumpRequest(true)))
  98. }
  99. t.Fatalf("err should be nil: %s", err.Error())
  100. }
  101. }
  102. func TestSessionAbort(t *testing.T) {
  103. t.Skip("skipped: tests are disabled for the time being")
  104. baseURL := "http://localhost:4010"
  105. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  106. baseURL = envURL
  107. }
  108. if !testutil.CheckTestServer(t, baseURL) {
  109. return
  110. }
  111. client := opencode.NewClient(
  112. option.WithBaseURL(baseURL),
  113. )
  114. _, err := client.Session.Abort(context.TODO(), "id")
  115. if err != nil {
  116. var apierr *opencode.Error
  117. if errors.As(err, &apierr) {
  118. t.Log(string(apierr.DumpRequest(true)))
  119. }
  120. t.Fatalf("err should be nil: %s", err.Error())
  121. }
  122. }
  123. func TestSessionChatWithOptionalParams(t *testing.T) {
  124. t.Skip("skipped: tests are disabled for the time being")
  125. baseURL := "http://localhost:4010"
  126. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  127. baseURL = envURL
  128. }
  129. if !testutil.CheckTestServer(t, baseURL) {
  130. return
  131. }
  132. client := opencode.NewClient(
  133. option.WithBaseURL(baseURL),
  134. )
  135. _, err := client.Session.Chat(
  136. context.TODO(),
  137. "id",
  138. opencode.SessionChatParams{
  139. ModelID: opencode.F("modelID"),
  140. Parts: opencode.F([]opencode.SessionChatParamsPartUnion{opencode.TextPartInputParam{
  141. Text: opencode.F("text"),
  142. Type: opencode.F(opencode.TextPartInputTypeText),
  143. ID: opencode.F("id"),
  144. Synthetic: opencode.F(true),
  145. Time: opencode.F(opencode.TextPartInputTimeParam{
  146. Start: opencode.F(0.000000),
  147. End: opencode.F(0.000000),
  148. }),
  149. }}),
  150. ProviderID: opencode.F("providerID"),
  151. Agent: opencode.F("agent"),
  152. MessageID: opencode.F("msg"),
  153. System: opencode.F("system"),
  154. Tools: opencode.F(map[string]bool{
  155. "foo": true,
  156. }),
  157. },
  158. )
  159. if err != nil {
  160. var apierr *opencode.Error
  161. if errors.As(err, &apierr) {
  162. t.Log(string(apierr.DumpRequest(true)))
  163. }
  164. t.Fatalf("err should be nil: %s", err.Error())
  165. }
  166. }
  167. func TestSessionInit(t *testing.T) {
  168. t.Skip("skipped: tests are disabled for the time being")
  169. baseURL := "http://localhost:4010"
  170. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  171. baseURL = envURL
  172. }
  173. if !testutil.CheckTestServer(t, baseURL) {
  174. return
  175. }
  176. client := opencode.NewClient(
  177. option.WithBaseURL(baseURL),
  178. )
  179. _, err := client.Session.Init(
  180. context.TODO(),
  181. "id",
  182. opencode.SessionInitParams{
  183. MessageID: opencode.F("messageID"),
  184. ModelID: opencode.F("modelID"),
  185. ProviderID: opencode.F("providerID"),
  186. },
  187. )
  188. if err != nil {
  189. var apierr *opencode.Error
  190. if errors.As(err, &apierr) {
  191. t.Log(string(apierr.DumpRequest(true)))
  192. }
  193. t.Fatalf("err should be nil: %s", err.Error())
  194. }
  195. }
  196. func TestSessionMessage(t *testing.T) {
  197. t.Skip("skipped: tests are disabled for the time being")
  198. baseURL := "http://localhost:4010"
  199. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  200. baseURL = envURL
  201. }
  202. if !testutil.CheckTestServer(t, baseURL) {
  203. return
  204. }
  205. client := opencode.NewClient(
  206. option.WithBaseURL(baseURL),
  207. )
  208. _, err := client.Session.Message(
  209. context.TODO(),
  210. "id",
  211. "messageID",
  212. )
  213. if err != nil {
  214. var apierr *opencode.Error
  215. if errors.As(err, &apierr) {
  216. t.Log(string(apierr.DumpRequest(true)))
  217. }
  218. t.Fatalf("err should be nil: %s", err.Error())
  219. }
  220. }
  221. func TestSessionMessages(t *testing.T) {
  222. t.Skip("skipped: tests are disabled for the time being")
  223. baseURL := "http://localhost:4010"
  224. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  225. baseURL = envURL
  226. }
  227. if !testutil.CheckTestServer(t, baseURL) {
  228. return
  229. }
  230. client := opencode.NewClient(
  231. option.WithBaseURL(baseURL),
  232. )
  233. _, err := client.Session.Messages(context.TODO(), "id")
  234. if err != nil {
  235. var apierr *opencode.Error
  236. if errors.As(err, &apierr) {
  237. t.Log(string(apierr.DumpRequest(true)))
  238. }
  239. t.Fatalf("err should be nil: %s", err.Error())
  240. }
  241. }
  242. func TestSessionRevertWithOptionalParams(t *testing.T) {
  243. t.Skip("skipped: tests are disabled for the time being")
  244. baseURL := "http://localhost:4010"
  245. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  246. baseURL = envURL
  247. }
  248. if !testutil.CheckTestServer(t, baseURL) {
  249. return
  250. }
  251. client := opencode.NewClient(
  252. option.WithBaseURL(baseURL),
  253. )
  254. _, err := client.Session.Revert(
  255. context.TODO(),
  256. "id",
  257. opencode.SessionRevertParams{
  258. MessageID: opencode.F("msg"),
  259. PartID: opencode.F("prt"),
  260. },
  261. )
  262. if err != nil {
  263. var apierr *opencode.Error
  264. if errors.As(err, &apierr) {
  265. t.Log(string(apierr.DumpRequest(true)))
  266. }
  267. t.Fatalf("err should be nil: %s", err.Error())
  268. }
  269. }
  270. func TestSessionShare(t *testing.T) {
  271. t.Skip("skipped: tests are disabled for the time being")
  272. baseURL := "http://localhost:4010"
  273. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  274. baseURL = envURL
  275. }
  276. if !testutil.CheckTestServer(t, baseURL) {
  277. return
  278. }
  279. client := opencode.NewClient(
  280. option.WithBaseURL(baseURL),
  281. )
  282. _, err := client.Session.Share(context.TODO(), "id")
  283. if err != nil {
  284. var apierr *opencode.Error
  285. if errors.As(err, &apierr) {
  286. t.Log(string(apierr.DumpRequest(true)))
  287. }
  288. t.Fatalf("err should be nil: %s", err.Error())
  289. }
  290. }
  291. func TestSessionShell(t *testing.T) {
  292. t.Skip("skipped: tests are disabled for the time being")
  293. baseURL := "http://localhost:4010"
  294. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  295. baseURL = envURL
  296. }
  297. if !testutil.CheckTestServer(t, baseURL) {
  298. return
  299. }
  300. client := opencode.NewClient(
  301. option.WithBaseURL(baseURL),
  302. )
  303. _, err := client.Session.Shell(
  304. context.TODO(),
  305. "id",
  306. opencode.SessionShellParams{
  307. Agent: opencode.F("agent"),
  308. Command: opencode.F("command"),
  309. },
  310. )
  311. if err != nil {
  312. var apierr *opencode.Error
  313. if errors.As(err, &apierr) {
  314. t.Log(string(apierr.DumpRequest(true)))
  315. }
  316. t.Fatalf("err should be nil: %s", err.Error())
  317. }
  318. }
  319. func TestSessionSummarize(t *testing.T) {
  320. t.Skip("skipped: tests are disabled for the time being")
  321. baseURL := "http://localhost:4010"
  322. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  323. baseURL = envURL
  324. }
  325. if !testutil.CheckTestServer(t, baseURL) {
  326. return
  327. }
  328. client := opencode.NewClient(
  329. option.WithBaseURL(baseURL),
  330. )
  331. _, err := client.Session.Summarize(
  332. context.TODO(),
  333. "id",
  334. opencode.SessionSummarizeParams{
  335. ModelID: opencode.F("modelID"),
  336. ProviderID: opencode.F("providerID"),
  337. },
  338. )
  339. if err != nil {
  340. var apierr *opencode.Error
  341. if errors.As(err, &apierr) {
  342. t.Log(string(apierr.DumpRequest(true)))
  343. }
  344. t.Fatalf("err should be nil: %s", err.Error())
  345. }
  346. }
  347. func TestSessionUnrevert(t *testing.T) {
  348. t.Skip("skipped: tests are disabled for the time being")
  349. baseURL := "http://localhost:4010"
  350. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  351. baseURL = envURL
  352. }
  353. if !testutil.CheckTestServer(t, baseURL) {
  354. return
  355. }
  356. client := opencode.NewClient(
  357. option.WithBaseURL(baseURL),
  358. )
  359. _, err := client.Session.Unrevert(context.TODO(), "id")
  360. if err != nil {
  361. var apierr *opencode.Error
  362. if errors.As(err, &apierr) {
  363. t.Log(string(apierr.DumpRequest(true)))
  364. }
  365. t.Fatalf("err should be nil: %s", err.Error())
  366. }
  367. }
  368. func TestSessionUnshare(t *testing.T) {
  369. t.Skip("skipped: tests are disabled for the time being")
  370. baseURL := "http://localhost:4010"
  371. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  372. baseURL = envURL
  373. }
  374. if !testutil.CheckTestServer(t, baseURL) {
  375. return
  376. }
  377. client := opencode.NewClient(
  378. option.WithBaseURL(baseURL),
  379. )
  380. _, err := client.Session.Unshare(context.TODO(), "id")
  381. if err != nil {
  382. var apierr *opencode.Error
  383. if errors.As(err, &apierr) {
  384. t.Log(string(apierr.DumpRequest(true)))
  385. }
  386. t.Fatalf("err should be nil: %s", err.Error())
  387. }
  388. }