session_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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("Prism tests are disabled")
  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. Directory: opencode.F("directory"),
  26. ParentID: opencode.F("sesJ!"),
  27. Title: opencode.F("title"),
  28. })
  29. if err != nil {
  30. var apierr *opencode.Error
  31. if errors.As(err, &apierr) {
  32. t.Log(string(apierr.DumpRequest(true)))
  33. }
  34. t.Fatalf("err should be nil: %s", err.Error())
  35. }
  36. }
  37. func TestSessionUpdateWithOptionalParams(t *testing.T) {
  38. t.Skip("Prism tests are disabled")
  39. baseURL := "http://localhost:4010"
  40. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  41. baseURL = envURL
  42. }
  43. if !testutil.CheckTestServer(t, baseURL) {
  44. return
  45. }
  46. client := opencode.NewClient(
  47. option.WithBaseURL(baseURL),
  48. )
  49. _, err := client.Session.Update(
  50. context.TODO(),
  51. "id",
  52. opencode.SessionUpdateParams{
  53. Directory: opencode.F("directory"),
  54. Title: opencode.F("title"),
  55. },
  56. )
  57. if err != nil {
  58. var apierr *opencode.Error
  59. if errors.As(err, &apierr) {
  60. t.Log(string(apierr.DumpRequest(true)))
  61. }
  62. t.Fatalf("err should be nil: %s", err.Error())
  63. }
  64. }
  65. func TestSessionListWithOptionalParams(t *testing.T) {
  66. t.Skip("Prism tests are disabled")
  67. baseURL := "http://localhost:4010"
  68. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  69. baseURL = envURL
  70. }
  71. if !testutil.CheckTestServer(t, baseURL) {
  72. return
  73. }
  74. client := opencode.NewClient(
  75. option.WithBaseURL(baseURL),
  76. )
  77. _, err := client.Session.List(context.TODO(), opencode.SessionListParams{
  78. Directory: opencode.F("directory"),
  79. })
  80. if err != nil {
  81. var apierr *opencode.Error
  82. if errors.As(err, &apierr) {
  83. t.Log(string(apierr.DumpRequest(true)))
  84. }
  85. t.Fatalf("err should be nil: %s", err.Error())
  86. }
  87. }
  88. func TestSessionDeleteWithOptionalParams(t *testing.T) {
  89. t.Skip("Prism tests are disabled")
  90. baseURL := "http://localhost:4010"
  91. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  92. baseURL = envURL
  93. }
  94. if !testutil.CheckTestServer(t, baseURL) {
  95. return
  96. }
  97. client := opencode.NewClient(
  98. option.WithBaseURL(baseURL),
  99. )
  100. _, err := client.Session.Delete(
  101. context.TODO(),
  102. "sesJ!",
  103. opencode.SessionDeleteParams{
  104. Directory: opencode.F("directory"),
  105. },
  106. )
  107. if err != nil {
  108. var apierr *opencode.Error
  109. if errors.As(err, &apierr) {
  110. t.Log(string(apierr.DumpRequest(true)))
  111. }
  112. t.Fatalf("err should be nil: %s", err.Error())
  113. }
  114. }
  115. func TestSessionAbortWithOptionalParams(t *testing.T) {
  116. t.Skip("Prism tests are disabled")
  117. baseURL := "http://localhost:4010"
  118. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  119. baseURL = envURL
  120. }
  121. if !testutil.CheckTestServer(t, baseURL) {
  122. return
  123. }
  124. client := opencode.NewClient(
  125. option.WithBaseURL(baseURL),
  126. )
  127. _, err := client.Session.Abort(
  128. context.TODO(),
  129. "id",
  130. opencode.SessionAbortParams{
  131. Directory: opencode.F("directory"),
  132. },
  133. )
  134. if err != nil {
  135. var apierr *opencode.Error
  136. if errors.As(err, &apierr) {
  137. t.Log(string(apierr.DumpRequest(true)))
  138. }
  139. t.Fatalf("err should be nil: %s", err.Error())
  140. }
  141. }
  142. func TestSessionChildrenWithOptionalParams(t *testing.T) {
  143. t.Skip("Prism tests are disabled")
  144. baseURL := "http://localhost:4010"
  145. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  146. baseURL = envURL
  147. }
  148. if !testutil.CheckTestServer(t, baseURL) {
  149. return
  150. }
  151. client := opencode.NewClient(
  152. option.WithBaseURL(baseURL),
  153. )
  154. _, err := client.Session.Children(
  155. context.TODO(),
  156. "sesJ!",
  157. opencode.SessionChildrenParams{
  158. Directory: opencode.F("directory"),
  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 TestSessionCommandWithOptionalParams(t *testing.T) {
  170. t.Skip("Prism tests are disabled")
  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.Command(
  182. context.TODO(),
  183. "id",
  184. opencode.SessionCommandParams{
  185. Arguments: opencode.F("arguments"),
  186. Command: opencode.F("command"),
  187. Directory: opencode.F("directory"),
  188. Agent: opencode.F("agent"),
  189. MessageID: opencode.F("msgJ!"),
  190. Model: opencode.F("model"),
  191. },
  192. )
  193. if err != nil {
  194. var apierr *opencode.Error
  195. if errors.As(err, &apierr) {
  196. t.Log(string(apierr.DumpRequest(true)))
  197. }
  198. t.Fatalf("err should be nil: %s", err.Error())
  199. }
  200. }
  201. func TestSessionGetWithOptionalParams(t *testing.T) {
  202. t.Skip("Prism tests are disabled")
  203. baseURL := "http://localhost:4010"
  204. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  205. baseURL = envURL
  206. }
  207. if !testutil.CheckTestServer(t, baseURL) {
  208. return
  209. }
  210. client := opencode.NewClient(
  211. option.WithBaseURL(baseURL),
  212. )
  213. _, err := client.Session.Get(
  214. context.TODO(),
  215. "sesJ!",
  216. opencode.SessionGetParams{
  217. Directory: opencode.F("directory"),
  218. },
  219. )
  220. if err != nil {
  221. var apierr *opencode.Error
  222. if errors.As(err, &apierr) {
  223. t.Log(string(apierr.DumpRequest(true)))
  224. }
  225. t.Fatalf("err should be nil: %s", err.Error())
  226. }
  227. }
  228. func TestSessionInitWithOptionalParams(t *testing.T) {
  229. t.Skip("Prism tests are disabled")
  230. baseURL := "http://localhost:4010"
  231. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  232. baseURL = envURL
  233. }
  234. if !testutil.CheckTestServer(t, baseURL) {
  235. return
  236. }
  237. client := opencode.NewClient(
  238. option.WithBaseURL(baseURL),
  239. )
  240. _, err := client.Session.Init(
  241. context.TODO(),
  242. "id",
  243. opencode.SessionInitParams{
  244. MessageID: opencode.F("msgJ!"),
  245. ModelID: opencode.F("modelID"),
  246. ProviderID: opencode.F("providerID"),
  247. Directory: opencode.F("directory"),
  248. },
  249. )
  250. if err != nil {
  251. var apierr *opencode.Error
  252. if errors.As(err, &apierr) {
  253. t.Log(string(apierr.DumpRequest(true)))
  254. }
  255. t.Fatalf("err should be nil: %s", err.Error())
  256. }
  257. }
  258. func TestSessionMessageWithOptionalParams(t *testing.T) {
  259. t.Skip("Prism tests are disabled")
  260. baseURL := "http://localhost:4010"
  261. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  262. baseURL = envURL
  263. }
  264. if !testutil.CheckTestServer(t, baseURL) {
  265. return
  266. }
  267. client := opencode.NewClient(
  268. option.WithBaseURL(baseURL),
  269. )
  270. _, err := client.Session.Message(
  271. context.TODO(),
  272. "id",
  273. "messageID",
  274. opencode.SessionMessageParams{
  275. Directory: opencode.F("directory"),
  276. },
  277. )
  278. if err != nil {
  279. var apierr *opencode.Error
  280. if errors.As(err, &apierr) {
  281. t.Log(string(apierr.DumpRequest(true)))
  282. }
  283. t.Fatalf("err should be nil: %s", err.Error())
  284. }
  285. }
  286. func TestSessionMessagesWithOptionalParams(t *testing.T) {
  287. t.Skip("Prism tests are disabled")
  288. baseURL := "http://localhost:4010"
  289. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  290. baseURL = envURL
  291. }
  292. if !testutil.CheckTestServer(t, baseURL) {
  293. return
  294. }
  295. client := opencode.NewClient(
  296. option.WithBaseURL(baseURL),
  297. )
  298. _, err := client.Session.Messages(
  299. context.TODO(),
  300. "id",
  301. opencode.SessionMessagesParams{
  302. Directory: opencode.F("directory"),
  303. },
  304. )
  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 TestSessionPromptWithOptionalParams(t *testing.T) {
  314. t.Skip("Prism tests are disabled")
  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.Prompt(
  326. context.TODO(),
  327. "id",
  328. opencode.SessionPromptParams{
  329. Parts: opencode.F([]opencode.SessionPromptParamsPartUnion{opencode.TextPartInputParam{
  330. Text: opencode.F("text"),
  331. Type: opencode.F(opencode.TextPartInputTypeText),
  332. ID: opencode.F("id"),
  333. Metadata: opencode.F(map[string]interface{}{
  334. "foo": "bar",
  335. }),
  336. Synthetic: opencode.F(true),
  337. Time: opencode.F(opencode.TextPartInputTimeParam{
  338. Start: opencode.F(0.000000),
  339. End: opencode.F(0.000000),
  340. }),
  341. }}),
  342. Directory: opencode.F("directory"),
  343. Agent: opencode.F("agent"),
  344. MessageID: opencode.F("msgJ!"),
  345. Model: opencode.F(opencode.SessionPromptParamsModel{
  346. ModelID: opencode.F("modelID"),
  347. ProviderID: opencode.F("providerID"),
  348. }),
  349. System: opencode.F("system"),
  350. Tools: opencode.F(map[string]bool{
  351. "foo": true,
  352. }),
  353. },
  354. )
  355. if err != nil {
  356. var apierr *opencode.Error
  357. if errors.As(err, &apierr) {
  358. t.Log(string(apierr.DumpRequest(true)))
  359. }
  360. t.Fatalf("err should be nil: %s", err.Error())
  361. }
  362. }
  363. func TestSessionRevertWithOptionalParams(t *testing.T) {
  364. t.Skip("Prism tests are disabled")
  365. baseURL := "http://localhost:4010"
  366. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  367. baseURL = envURL
  368. }
  369. if !testutil.CheckTestServer(t, baseURL) {
  370. return
  371. }
  372. client := opencode.NewClient(
  373. option.WithBaseURL(baseURL),
  374. )
  375. _, err := client.Session.Revert(
  376. context.TODO(),
  377. "id",
  378. opencode.SessionRevertParams{
  379. MessageID: opencode.F("msgJ!"),
  380. Directory: opencode.F("directory"),
  381. PartID: opencode.F("prtJ!"),
  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 TestSessionShareWithOptionalParams(t *testing.T) {
  393. t.Skip("Prism tests are disabled")
  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.Share(
  405. context.TODO(),
  406. "id",
  407. opencode.SessionShareParams{
  408. Directory: opencode.F("directory"),
  409. },
  410. )
  411. if err != nil {
  412. var apierr *opencode.Error
  413. if errors.As(err, &apierr) {
  414. t.Log(string(apierr.DumpRequest(true)))
  415. }
  416. t.Fatalf("err should be nil: %s", err.Error())
  417. }
  418. }
  419. func TestSessionShellWithOptionalParams(t *testing.T) {
  420. t.Skip("Prism tests are disabled")
  421. baseURL := "http://localhost:4010"
  422. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  423. baseURL = envURL
  424. }
  425. if !testutil.CheckTestServer(t, baseURL) {
  426. return
  427. }
  428. client := opencode.NewClient(
  429. option.WithBaseURL(baseURL),
  430. )
  431. _, err := client.Session.Shell(
  432. context.TODO(),
  433. "id",
  434. opencode.SessionShellParams{
  435. Agent: opencode.F("agent"),
  436. Command: opencode.F("command"),
  437. Directory: opencode.F("directory"),
  438. },
  439. )
  440. if err != nil {
  441. var apierr *opencode.Error
  442. if errors.As(err, &apierr) {
  443. t.Log(string(apierr.DumpRequest(true)))
  444. }
  445. t.Fatalf("err should be nil: %s", err.Error())
  446. }
  447. }
  448. func TestSessionSummarizeWithOptionalParams(t *testing.T) {
  449. t.Skip("Prism tests are disabled")
  450. baseURL := "http://localhost:4010"
  451. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  452. baseURL = envURL
  453. }
  454. if !testutil.CheckTestServer(t, baseURL) {
  455. return
  456. }
  457. client := opencode.NewClient(
  458. option.WithBaseURL(baseURL),
  459. )
  460. _, err := client.Session.Summarize(
  461. context.TODO(),
  462. "id",
  463. opencode.SessionSummarizeParams{
  464. ModelID: opencode.F("modelID"),
  465. ProviderID: opencode.F("providerID"),
  466. Directory: opencode.F("directory"),
  467. },
  468. )
  469. if err != nil {
  470. var apierr *opencode.Error
  471. if errors.As(err, &apierr) {
  472. t.Log(string(apierr.DumpRequest(true)))
  473. }
  474. t.Fatalf("err should be nil: %s", err.Error())
  475. }
  476. }
  477. func TestSessionUnrevertWithOptionalParams(t *testing.T) {
  478. t.Skip("Prism tests are disabled")
  479. baseURL := "http://localhost:4010"
  480. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  481. baseURL = envURL
  482. }
  483. if !testutil.CheckTestServer(t, baseURL) {
  484. return
  485. }
  486. client := opencode.NewClient(
  487. option.WithBaseURL(baseURL),
  488. )
  489. _, err := client.Session.Unrevert(
  490. context.TODO(),
  491. "id",
  492. opencode.SessionUnrevertParams{
  493. Directory: opencode.F("directory"),
  494. },
  495. )
  496. if err != nil {
  497. var apierr *opencode.Error
  498. if errors.As(err, &apierr) {
  499. t.Log(string(apierr.DumpRequest(true)))
  500. }
  501. t.Fatalf("err should be nil: %s", err.Error())
  502. }
  503. }
  504. func TestSessionUnshareWithOptionalParams(t *testing.T) {
  505. t.Skip("Prism tests are disabled")
  506. baseURL := "http://localhost:4010"
  507. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  508. baseURL = envURL
  509. }
  510. if !testutil.CheckTestServer(t, baseURL) {
  511. return
  512. }
  513. client := opencode.NewClient(
  514. option.WithBaseURL(baseURL),
  515. )
  516. _, err := client.Session.Unshare(
  517. context.TODO(),
  518. "sesJ!",
  519. opencode.SessionUnshareParams{
  520. Directory: opencode.F("directory"),
  521. },
  522. )
  523. if err != nil {
  524. var apierr *opencode.Error
  525. if errors.As(err, &apierr) {
  526. t.Log(string(apierr.DumpRequest(true)))
  527. }
  528. t.Fatalf("err should be nil: %s", err.Error())
  529. }
  530. }