session_test.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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 TestSessionNewWithOptionalParams(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(), opencode.SessionNewParams{
  25. ParentID: opencode.F("parentID"),
  26. Title: opencode.F("title"),
  27. })
  28. if err != nil {
  29. var apierr *opencode.Error
  30. if errors.As(err, &apierr) {
  31. t.Log(string(apierr.DumpRequest(true)))
  32. }
  33. t.Fatalf("err should be nil: %s", err.Error())
  34. }
  35. }
  36. func TestSessionUpdateWithOptionalParams(t *testing.T) {
  37. t.Skip("skipped: tests are disabled for the time being")
  38. baseURL := "http://localhost:4010"
  39. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  40. baseURL = envURL
  41. }
  42. if !testutil.CheckTestServer(t, baseURL) {
  43. return
  44. }
  45. client := opencode.NewClient(
  46. option.WithBaseURL(baseURL),
  47. )
  48. _, err := client.Session.Update(
  49. context.TODO(),
  50. "id",
  51. opencode.SessionUpdateParams{
  52. Title: opencode.F("title"),
  53. },
  54. )
  55. if err != nil {
  56. var apierr *opencode.Error
  57. if errors.As(err, &apierr) {
  58. t.Log(string(apierr.DumpRequest(true)))
  59. }
  60. t.Fatalf("err should be nil: %s", err.Error())
  61. }
  62. }
  63. func TestSessionList(t *testing.T) {
  64. t.Skip("skipped: tests are disabled for the time being")
  65. baseURL := "http://localhost:4010"
  66. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  67. baseURL = envURL
  68. }
  69. if !testutil.CheckTestServer(t, baseURL) {
  70. return
  71. }
  72. client := opencode.NewClient(
  73. option.WithBaseURL(baseURL),
  74. )
  75. _, err := client.Session.List(context.TODO())
  76. if err != nil {
  77. var apierr *opencode.Error
  78. if errors.As(err, &apierr) {
  79. t.Log(string(apierr.DumpRequest(true)))
  80. }
  81. t.Fatalf("err should be nil: %s", err.Error())
  82. }
  83. }
  84. func TestSessionDelete(t *testing.T) {
  85. t.Skip("skipped: tests are disabled for the time being")
  86. baseURL := "http://localhost:4010"
  87. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  88. baseURL = envURL
  89. }
  90. if !testutil.CheckTestServer(t, baseURL) {
  91. return
  92. }
  93. client := opencode.NewClient(
  94. option.WithBaseURL(baseURL),
  95. )
  96. _, err := client.Session.Delete(context.TODO(), "id")
  97. if err != nil {
  98. var apierr *opencode.Error
  99. if errors.As(err, &apierr) {
  100. t.Log(string(apierr.DumpRequest(true)))
  101. }
  102. t.Fatalf("err should be nil: %s", err.Error())
  103. }
  104. }
  105. func TestSessionAbort(t *testing.T) {
  106. t.Skip("skipped: tests are disabled for the time being")
  107. baseURL := "http://localhost:4010"
  108. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  109. baseURL = envURL
  110. }
  111. if !testutil.CheckTestServer(t, baseURL) {
  112. return
  113. }
  114. client := opencode.NewClient(
  115. option.WithBaseURL(baseURL),
  116. )
  117. _, err := client.Session.Abort(context.TODO(), "id")
  118. if err != nil {
  119. var apierr *opencode.Error
  120. if errors.As(err, &apierr) {
  121. t.Log(string(apierr.DumpRequest(true)))
  122. }
  123. t.Fatalf("err should be nil: %s", err.Error())
  124. }
  125. }
  126. func TestSessionChatWithOptionalParams(t *testing.T) {
  127. t.Skip("skipped: tests are disabled for the time being")
  128. baseURL := "http://localhost:4010"
  129. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  130. baseURL = envURL
  131. }
  132. if !testutil.CheckTestServer(t, baseURL) {
  133. return
  134. }
  135. client := opencode.NewClient(
  136. option.WithBaseURL(baseURL),
  137. )
  138. _, err := client.Session.Chat(
  139. context.TODO(),
  140. "id",
  141. opencode.SessionChatParams{
  142. ModelID: opencode.F("modelID"),
  143. Parts: opencode.F([]opencode.SessionChatParamsPartUnion{opencode.TextPartInputParam{
  144. Text: opencode.F("text"),
  145. Type: opencode.F(opencode.TextPartInputTypeText),
  146. ID: opencode.F("id"),
  147. Synthetic: opencode.F(true),
  148. Time: opencode.F(opencode.TextPartInputTimeParam{
  149. Start: opencode.F(0.000000),
  150. End: opencode.F(0.000000),
  151. }),
  152. }}),
  153. ProviderID: opencode.F("providerID"),
  154. Agent: opencode.F("agent"),
  155. MessageID: opencode.F("msg"),
  156. System: opencode.F("system"),
  157. Tools: opencode.F(map[string]bool{
  158. "foo": true,
  159. }),
  160. },
  161. )
  162. if err != nil {
  163. var apierr *opencode.Error
  164. if errors.As(err, &apierr) {
  165. t.Log(string(apierr.DumpRequest(true)))
  166. }
  167. t.Fatalf("err should be nil: %s", err.Error())
  168. }
  169. }
  170. func TestSessionChildren(t *testing.T) {
  171. t.Skip("skipped: tests are disabled for the time being")
  172. baseURL := "http://localhost:4010"
  173. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  174. baseURL = envURL
  175. }
  176. if !testutil.CheckTestServer(t, baseURL) {
  177. return
  178. }
  179. client := opencode.NewClient(
  180. option.WithBaseURL(baseURL),
  181. )
  182. _, err := client.Session.Children(context.TODO(), "id")
  183. if err != nil {
  184. var apierr *opencode.Error
  185. if errors.As(err, &apierr) {
  186. t.Log(string(apierr.DumpRequest(true)))
  187. }
  188. t.Fatalf("err should be nil: %s", err.Error())
  189. }
  190. }
  191. func TestSessionGet(t *testing.T) {
  192. t.Skip("skipped: tests are disabled for the time being")
  193. baseURL := "http://localhost:4010"
  194. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  195. baseURL = envURL
  196. }
  197. if !testutil.CheckTestServer(t, baseURL) {
  198. return
  199. }
  200. client := opencode.NewClient(
  201. option.WithBaseURL(baseURL),
  202. )
  203. _, err := client.Session.Get(context.TODO(), "id")
  204. if err != nil {
  205. var apierr *opencode.Error
  206. if errors.As(err, &apierr) {
  207. t.Log(string(apierr.DumpRequest(true)))
  208. }
  209. t.Fatalf("err should be nil: %s", err.Error())
  210. }
  211. }
  212. func TestSessionInit(t *testing.T) {
  213. t.Skip("skipped: tests are disabled for the time being")
  214. baseURL := "http://localhost:4010"
  215. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  216. baseURL = envURL
  217. }
  218. if !testutil.CheckTestServer(t, baseURL) {
  219. return
  220. }
  221. client := opencode.NewClient(
  222. option.WithBaseURL(baseURL),
  223. )
  224. _, err := client.Session.Init(
  225. context.TODO(),
  226. "id",
  227. opencode.SessionInitParams{
  228. MessageID: opencode.F("messageID"),
  229. ModelID: opencode.F("modelID"),
  230. ProviderID: opencode.F("providerID"),
  231. },
  232. )
  233. if err != nil {
  234. var apierr *opencode.Error
  235. if errors.As(err, &apierr) {
  236. t.Log(string(apierr.DumpRequest(true)))
  237. }
  238. t.Fatalf("err should be nil: %s", err.Error())
  239. }
  240. }
  241. func TestSessionMessage(t *testing.T) {
  242. t.Skip("skipped: tests are disabled for the time being")
  243. baseURL := "http://localhost:4010"
  244. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  245. baseURL = envURL
  246. }
  247. if !testutil.CheckTestServer(t, baseURL) {
  248. return
  249. }
  250. client := opencode.NewClient(
  251. option.WithBaseURL(baseURL),
  252. )
  253. _, err := client.Session.Message(
  254. context.TODO(),
  255. "id",
  256. "messageID",
  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 TestSessionMessages(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.Messages(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 TestSessionRevertWithOptionalParams(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.Revert(
  300. context.TODO(),
  301. "id",
  302. opencode.SessionRevertParams{
  303. MessageID: opencode.F("msg"),
  304. PartID: opencode.F("prt"),
  305. },
  306. )
  307. if err != nil {
  308. var apierr *opencode.Error
  309. if errors.As(err, &apierr) {
  310. t.Log(string(apierr.DumpRequest(true)))
  311. }
  312. t.Fatalf("err should be nil: %s", err.Error())
  313. }
  314. }
  315. func TestSessionShare(t *testing.T) {
  316. t.Skip("skipped: tests are disabled for the time being")
  317. baseURL := "http://localhost:4010"
  318. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  319. baseURL = envURL
  320. }
  321. if !testutil.CheckTestServer(t, baseURL) {
  322. return
  323. }
  324. client := opencode.NewClient(
  325. option.WithBaseURL(baseURL),
  326. )
  327. _, err := client.Session.Share(context.TODO(), "id")
  328. if err != nil {
  329. var apierr *opencode.Error
  330. if errors.As(err, &apierr) {
  331. t.Log(string(apierr.DumpRequest(true)))
  332. }
  333. t.Fatalf("err should be nil: %s", err.Error())
  334. }
  335. }
  336. func TestSessionShell(t *testing.T) {
  337. t.Skip("skipped: tests are disabled for the time being")
  338. baseURL := "http://localhost:4010"
  339. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  340. baseURL = envURL
  341. }
  342. if !testutil.CheckTestServer(t, baseURL) {
  343. return
  344. }
  345. client := opencode.NewClient(
  346. option.WithBaseURL(baseURL),
  347. )
  348. _, err := client.Session.Shell(
  349. context.TODO(),
  350. "id",
  351. opencode.SessionShellParams{
  352. Agent: opencode.F("agent"),
  353. Command: opencode.F("command"),
  354. },
  355. )
  356. if err != nil {
  357. var apierr *opencode.Error
  358. if errors.As(err, &apierr) {
  359. t.Log(string(apierr.DumpRequest(true)))
  360. }
  361. t.Fatalf("err should be nil: %s", err.Error())
  362. }
  363. }
  364. func TestSessionSummarize(t *testing.T) {
  365. t.Skip("skipped: tests are disabled for the time being")
  366. baseURL := "http://localhost:4010"
  367. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  368. baseURL = envURL
  369. }
  370. if !testutil.CheckTestServer(t, baseURL) {
  371. return
  372. }
  373. client := opencode.NewClient(
  374. option.WithBaseURL(baseURL),
  375. )
  376. _, err := client.Session.Summarize(
  377. context.TODO(),
  378. "id",
  379. opencode.SessionSummarizeParams{
  380. ModelID: opencode.F("modelID"),
  381. ProviderID: opencode.F("providerID"),
  382. },
  383. )
  384. if err != nil {
  385. var apierr *opencode.Error
  386. if errors.As(err, &apierr) {
  387. t.Log(string(apierr.DumpRequest(true)))
  388. }
  389. t.Fatalf("err should be nil: %s", err.Error())
  390. }
  391. }
  392. func TestSessionUnrevert(t *testing.T) {
  393. t.Skip("skipped: tests are disabled for the time being")
  394. baseURL := "http://localhost:4010"
  395. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  396. baseURL = envURL
  397. }
  398. if !testutil.CheckTestServer(t, baseURL) {
  399. return
  400. }
  401. client := opencode.NewClient(
  402. option.WithBaseURL(baseURL),
  403. )
  404. _, err := client.Session.Unrevert(context.TODO(), "id")
  405. if err != nil {
  406. var apierr *opencode.Error
  407. if errors.As(err, &apierr) {
  408. t.Log(string(apierr.DumpRequest(true)))
  409. }
  410. t.Fatalf("err should be nil: %s", err.Error())
  411. }
  412. }
  413. func TestSessionUnshare(t *testing.T) {
  414. t.Skip("skipped: tests are disabled for the time being")
  415. baseURL := "http://localhost:4010"
  416. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  417. baseURL = envURL
  418. }
  419. if !testutil.CheckTestServer(t, baseURL) {
  420. return
  421. }
  422. client := opencode.NewClient(
  423. option.WithBaseURL(baseURL),
  424. )
  425. _, err := client.Session.Unshare(context.TODO(), "id")
  426. if err != nil {
  427. var apierr *opencode.Error
  428. if errors.As(err, &apierr) {
  429. t.Log(string(apierr.DumpRequest(true)))
  430. }
  431. t.Fatalf("err should be nil: %s", err.Error())
  432. }
  433. }