session_test.go 13 KB

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