session_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. NoReply: opencode.F(true),
  350. System: opencode.F("system"),
  351. Tools: opencode.F(map[string]bool{
  352. "foo": true,
  353. }),
  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 TestSessionRevertWithOptionalParams(t *testing.T) {
  365. t.Skip("Prism tests are disabled")
  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.Revert(
  377. context.TODO(),
  378. "id",
  379. opencode.SessionRevertParams{
  380. MessageID: opencode.F("msgJ!"),
  381. Directory: opencode.F("directory"),
  382. PartID: opencode.F("prtJ!"),
  383. },
  384. )
  385. if err != nil {
  386. var apierr *opencode.Error
  387. if errors.As(err, &apierr) {
  388. t.Log(string(apierr.DumpRequest(true)))
  389. }
  390. t.Fatalf("err should be nil: %s", err.Error())
  391. }
  392. }
  393. func TestSessionShareWithOptionalParams(t *testing.T) {
  394. t.Skip("Prism tests are disabled")
  395. baseURL := "http://localhost:4010"
  396. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  397. baseURL = envURL
  398. }
  399. if !testutil.CheckTestServer(t, baseURL) {
  400. return
  401. }
  402. client := opencode.NewClient(
  403. option.WithBaseURL(baseURL),
  404. )
  405. _, err := client.Session.Share(
  406. context.TODO(),
  407. "id",
  408. opencode.SessionShareParams{
  409. Directory: opencode.F("directory"),
  410. },
  411. )
  412. if err != nil {
  413. var apierr *opencode.Error
  414. if errors.As(err, &apierr) {
  415. t.Log(string(apierr.DumpRequest(true)))
  416. }
  417. t.Fatalf("err should be nil: %s", err.Error())
  418. }
  419. }
  420. func TestSessionShellWithOptionalParams(t *testing.T) {
  421. t.Skip("Prism tests are disabled")
  422. baseURL := "http://localhost:4010"
  423. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  424. baseURL = envURL
  425. }
  426. if !testutil.CheckTestServer(t, baseURL) {
  427. return
  428. }
  429. client := opencode.NewClient(
  430. option.WithBaseURL(baseURL),
  431. )
  432. _, err := client.Session.Shell(
  433. context.TODO(),
  434. "id",
  435. opencode.SessionShellParams{
  436. Agent: opencode.F("agent"),
  437. Command: opencode.F("command"),
  438. Directory: opencode.F("directory"),
  439. },
  440. )
  441. if err != nil {
  442. var apierr *opencode.Error
  443. if errors.As(err, &apierr) {
  444. t.Log(string(apierr.DumpRequest(true)))
  445. }
  446. t.Fatalf("err should be nil: %s", err.Error())
  447. }
  448. }
  449. func TestSessionSummarizeWithOptionalParams(t *testing.T) {
  450. t.Skip("Prism tests are disabled")
  451. baseURL := "http://localhost:4010"
  452. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  453. baseURL = envURL
  454. }
  455. if !testutil.CheckTestServer(t, baseURL) {
  456. return
  457. }
  458. client := opencode.NewClient(
  459. option.WithBaseURL(baseURL),
  460. )
  461. _, err := client.Session.Summarize(
  462. context.TODO(),
  463. "id",
  464. opencode.SessionSummarizeParams{
  465. ModelID: opencode.F("modelID"),
  466. ProviderID: opencode.F("providerID"),
  467. Directory: opencode.F("directory"),
  468. },
  469. )
  470. if err != nil {
  471. var apierr *opencode.Error
  472. if errors.As(err, &apierr) {
  473. t.Log(string(apierr.DumpRequest(true)))
  474. }
  475. t.Fatalf("err should be nil: %s", err.Error())
  476. }
  477. }
  478. func TestSessionUnrevertWithOptionalParams(t *testing.T) {
  479. t.Skip("Prism tests are disabled")
  480. baseURL := "http://localhost:4010"
  481. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  482. baseURL = envURL
  483. }
  484. if !testutil.CheckTestServer(t, baseURL) {
  485. return
  486. }
  487. client := opencode.NewClient(
  488. option.WithBaseURL(baseURL),
  489. )
  490. _, err := client.Session.Unrevert(
  491. context.TODO(),
  492. "id",
  493. opencode.SessionUnrevertParams{
  494. Directory: opencode.F("directory"),
  495. },
  496. )
  497. if err != nil {
  498. var apierr *opencode.Error
  499. if errors.As(err, &apierr) {
  500. t.Log(string(apierr.DumpRequest(true)))
  501. }
  502. t.Fatalf("err should be nil: %s", err.Error())
  503. }
  504. }
  505. func TestSessionUnshareWithOptionalParams(t *testing.T) {
  506. t.Skip("Prism tests are disabled")
  507. baseURL := "http://localhost:4010"
  508. if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
  509. baseURL = envURL
  510. }
  511. if !testutil.CheckTestServer(t, baseURL) {
  512. return
  513. }
  514. client := opencode.NewClient(
  515. option.WithBaseURL(baseURL),
  516. )
  517. _, err := client.Session.Unshare(
  518. context.TODO(),
  519. "sesJ!",
  520. opencode.SessionUnshareParams{
  521. Directory: opencode.F("directory"),
  522. },
  523. )
  524. if err != nil {
  525. var apierr *opencode.Error
  526. if errors.As(err, &apierr) {
  527. t.Log(string(apierr.DumpRequest(true)))
  528. }
  529. t.Fatalf("err should be nil: %s", err.Error())
  530. }
  531. }