session_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 TestSessionCommandWithOptionalParams(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.Command(
  204. context.TODO(),
  205. "id",
  206. opencode.SessionCommandParams{
  207. Arguments: opencode.F("arguments"),
  208. Command: opencode.F("command"),
  209. Agent: opencode.F("agent"),
  210. MessageID: opencode.F("msg"),
  211. Model: opencode.F("model"),
  212. },
  213. )
  214. if err != nil {
  215. var apierr *opencode.Error
  216. if errors.As(err, &apierr) {
  217. t.Log(string(apierr.DumpRequest(true)))
  218. }
  219. t.Fatalf("err should be nil: %s", err.Error())
  220. }
  221. }
  222. func TestSessionGet(t *testing.T) {
  223. t.Skip("skipped: tests are disabled for the time being")
  224. baseURL := "http://localhost:4010"
  225. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  226. baseURL = envURL
  227. }
  228. if !testutil.CheckTestServer(t, baseURL) {
  229. return
  230. }
  231. client := opencode.NewClient(
  232. option.WithBaseURL(baseURL),
  233. )
  234. _, err := client.Session.Get(context.TODO(), "id")
  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 TestSessionInit(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.Init(
  256. context.TODO(),
  257. "id",
  258. opencode.SessionInitParams{
  259. MessageID: opencode.F("messageID"),
  260. ModelID: opencode.F("modelID"),
  261. ProviderID: opencode.F("providerID"),
  262. },
  263. )
  264. if err != nil {
  265. var apierr *opencode.Error
  266. if errors.As(err, &apierr) {
  267. t.Log(string(apierr.DumpRequest(true)))
  268. }
  269. t.Fatalf("err should be nil: %s", err.Error())
  270. }
  271. }
  272. func TestSessionMessage(t *testing.T) {
  273. t.Skip("skipped: tests are disabled for the time being")
  274. baseURL := "http://localhost:4010"
  275. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  276. baseURL = envURL
  277. }
  278. if !testutil.CheckTestServer(t, baseURL) {
  279. return
  280. }
  281. client := opencode.NewClient(
  282. option.WithBaseURL(baseURL),
  283. )
  284. _, err := client.Session.Message(
  285. context.TODO(),
  286. "id",
  287. "messageID",
  288. )
  289. if err != nil {
  290. var apierr *opencode.Error
  291. if errors.As(err, &apierr) {
  292. t.Log(string(apierr.DumpRequest(true)))
  293. }
  294. t.Fatalf("err should be nil: %s", err.Error())
  295. }
  296. }
  297. func TestSessionMessages(t *testing.T) {
  298. t.Skip("skipped: tests are disabled for the time being")
  299. baseURL := "http://localhost:4010"
  300. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  301. baseURL = envURL
  302. }
  303. if !testutil.CheckTestServer(t, baseURL) {
  304. return
  305. }
  306. client := opencode.NewClient(
  307. option.WithBaseURL(baseURL),
  308. )
  309. _, err := client.Session.Messages(context.TODO(), "id")
  310. if err != nil {
  311. var apierr *opencode.Error
  312. if errors.As(err, &apierr) {
  313. t.Log(string(apierr.DumpRequest(true)))
  314. }
  315. t.Fatalf("err should be nil: %s", err.Error())
  316. }
  317. }
  318. func TestSessionRevertWithOptionalParams(t *testing.T) {
  319. t.Skip("skipped: tests are disabled for the time being")
  320. baseURL := "http://localhost:4010"
  321. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  322. baseURL = envURL
  323. }
  324. if !testutil.CheckTestServer(t, baseURL) {
  325. return
  326. }
  327. client := opencode.NewClient(
  328. option.WithBaseURL(baseURL),
  329. )
  330. _, err := client.Session.Revert(
  331. context.TODO(),
  332. "id",
  333. opencode.SessionRevertParams{
  334. MessageID: opencode.F("msg"),
  335. PartID: opencode.F("prt"),
  336. },
  337. )
  338. if err != nil {
  339. var apierr *opencode.Error
  340. if errors.As(err, &apierr) {
  341. t.Log(string(apierr.DumpRequest(true)))
  342. }
  343. t.Fatalf("err should be nil: %s", err.Error())
  344. }
  345. }
  346. func TestSessionShare(t *testing.T) {
  347. t.Skip("skipped: tests are disabled for the time being")
  348. baseURL := "http://localhost:4010"
  349. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  350. baseURL = envURL
  351. }
  352. if !testutil.CheckTestServer(t, baseURL) {
  353. return
  354. }
  355. client := opencode.NewClient(
  356. option.WithBaseURL(baseURL),
  357. )
  358. _, err := client.Session.Share(context.TODO(), "id")
  359. if err != nil {
  360. var apierr *opencode.Error
  361. if errors.As(err, &apierr) {
  362. t.Log(string(apierr.DumpRequest(true)))
  363. }
  364. t.Fatalf("err should be nil: %s", err.Error())
  365. }
  366. }
  367. func TestSessionShell(t *testing.T) {
  368. t.Skip("skipped: tests are disabled for the time being")
  369. baseURL := "http://localhost:4010"
  370. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  371. baseURL = envURL
  372. }
  373. if !testutil.CheckTestServer(t, baseURL) {
  374. return
  375. }
  376. client := opencode.NewClient(
  377. option.WithBaseURL(baseURL),
  378. )
  379. _, err := client.Session.Shell(
  380. context.TODO(),
  381. "id",
  382. opencode.SessionShellParams{
  383. Agent: opencode.F("agent"),
  384. Command: opencode.F("command"),
  385. },
  386. )
  387. if err != nil {
  388. var apierr *opencode.Error
  389. if errors.As(err, &apierr) {
  390. t.Log(string(apierr.DumpRequest(true)))
  391. }
  392. t.Fatalf("err should be nil: %s", err.Error())
  393. }
  394. }
  395. func TestSessionSummarize(t *testing.T) {
  396. t.Skip("skipped: tests are disabled for the time being")
  397. baseURL := "http://localhost:4010"
  398. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  399. baseURL = envURL
  400. }
  401. if !testutil.CheckTestServer(t, baseURL) {
  402. return
  403. }
  404. client := opencode.NewClient(
  405. option.WithBaseURL(baseURL),
  406. )
  407. _, err := client.Session.Summarize(
  408. context.TODO(),
  409. "id",
  410. opencode.SessionSummarizeParams{
  411. ModelID: opencode.F("modelID"),
  412. ProviderID: opencode.F("providerID"),
  413. },
  414. )
  415. if err != nil {
  416. var apierr *opencode.Error
  417. if errors.As(err, &apierr) {
  418. t.Log(string(apierr.DumpRequest(true)))
  419. }
  420. t.Fatalf("err should be nil: %s", err.Error())
  421. }
  422. }
  423. func TestSessionUnrevert(t *testing.T) {
  424. t.Skip("skipped: tests are disabled for the time being")
  425. baseURL := "http://localhost:4010"
  426. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  427. baseURL = envURL
  428. }
  429. if !testutil.CheckTestServer(t, baseURL) {
  430. return
  431. }
  432. client := opencode.NewClient(
  433. option.WithBaseURL(baseURL),
  434. )
  435. _, err := client.Session.Unrevert(context.TODO(), "id")
  436. if err != nil {
  437. var apierr *opencode.Error
  438. if errors.As(err, &apierr) {
  439. t.Log(string(apierr.DumpRequest(true)))
  440. }
  441. t.Fatalf("err should be nil: %s", err.Error())
  442. }
  443. }
  444. func TestSessionUnshare(t *testing.T) {
  445. t.Skip("skipped: tests are disabled for the time being")
  446. baseURL := "http://localhost:4010"
  447. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  448. baseURL = envURL
  449. }
  450. if !testutil.CheckTestServer(t, baseURL) {
  451. return
  452. }
  453. client := opencode.NewClient(
  454. option.WithBaseURL(baseURL),
  455. )
  456. _, err := client.Session.Unshare(context.TODO(), "id")
  457. if err != nil {
  458. var apierr *opencode.Error
  459. if errors.As(err, &apierr) {
  460. t.Log(string(apierr.DumpRequest(true)))
  461. }
  462. t.Fatalf("err should be nil: %s", err.Error())
  463. }
  464. }