gitlab-duo.test.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. export {}
  2. // TODO: UNCOMMENT WHEN GITLAB SUPPORT IS COMPLETED
  3. //
  4. //
  5. //
  6. // import { test, expect, describe } from "bun:test"
  7. // import path from "path"
  8. // import { ProviderID, ModelID } from "../../src/provider/schema"
  9. // import { tmpdir } from "../fixture/fixture"
  10. // import { Instance } from "../../src/project/instance"
  11. // import { Provider } from "@/provider/provider"
  12. // import { Env } from "../../src/env"
  13. // import { Global } from "@opencode-ai/core/global"
  14. // import { GitLabWorkflowLanguageModel } from "gitlab-ai-provider"
  15. // test("GitLab Duo: loads provider with API key from environment", async () => {
  16. // await using tmp = await tmpdir({
  17. // init: async (dir) => {
  18. // await Bun.write(
  19. // path.join(dir, "opencode.json"),
  20. // JSON.stringify({
  21. // $schema: "https://opencode.ai/config.json",
  22. // }),
  23. // )
  24. // },
  25. // })
  26. // await Instance.provide({
  27. // directory: tmp.path,
  28. // init: async () => {
  29. // Env.set("GITLAB_TOKEN", "test-gitlab-token")
  30. // },
  31. // fn: async () => {
  32. // const providers = await list()
  33. // expect(providers[ProviderID.gitlab]).toBeDefined()
  34. // expect(providers[ProviderID.gitlab].key).toBe("test-gitlab-token")
  35. // },
  36. // })
  37. // })
  38. // test("GitLab Duo: config instanceUrl option sets baseURL", async () => {
  39. // await using tmp = await tmpdir({
  40. // init: async (dir) => {
  41. // await Bun.write(
  42. // path.join(dir, "opencode.json"),
  43. // JSON.stringify({
  44. // $schema: "https://opencode.ai/config.json",
  45. // provider: {
  46. // gitlab: {
  47. // options: {
  48. // instanceUrl: "https://gitlab.example.com",
  49. // },
  50. // },
  51. // },
  52. // }),
  53. // )
  54. // },
  55. // })
  56. // await Instance.provide({
  57. // directory: tmp.path,
  58. // init: async () => {
  59. // Env.set("GITLAB_TOKEN", "test-token")
  60. // Env.set("GITLAB_INSTANCE_URL", "https://gitlab.example.com")
  61. // },
  62. // fn: async () => {
  63. // const providers = await list()
  64. // expect(providers[ProviderID.gitlab]).toBeDefined()
  65. // expect(providers[ProviderID.gitlab].options?.instanceUrl).toBe("https://gitlab.example.com")
  66. // },
  67. // })
  68. // })
  69. // test("GitLab Duo: loads with OAuth token from auth.json", async () => {
  70. // await using tmp = await tmpdir({
  71. // init: async (dir) => {
  72. // await Bun.write(
  73. // path.join(dir, "opencode.json"),
  74. // JSON.stringify({
  75. // $schema: "https://opencode.ai/config.json",
  76. // }),
  77. // )
  78. // },
  79. // })
  80. // const authPath = path.join(Global.Path.data, "auth.json")
  81. // await Bun.write(
  82. // authPath,
  83. // JSON.stringify({
  84. // gitlab: {
  85. // type: "oauth",
  86. // access: "test-access-token",
  87. // refresh: "test-refresh-token",
  88. // expires: Date.now() + 3600000,
  89. // },
  90. // }),
  91. // )
  92. // await Instance.provide({
  93. // directory: tmp.path,
  94. // init: async () => {
  95. // Env.set("GITLAB_TOKEN", "")
  96. // },
  97. // fn: async () => {
  98. // const providers = await list()
  99. // expect(providers[ProviderID.gitlab]).toBeDefined()
  100. // },
  101. // })
  102. // })
  103. // test("GitLab Duo: loads with Personal Access Token from auth.json", async () => {
  104. // await using tmp = await tmpdir({
  105. // init: async (dir) => {
  106. // await Bun.write(
  107. // path.join(dir, "opencode.json"),
  108. // JSON.stringify({
  109. // $schema: "https://opencode.ai/config.json",
  110. // }),
  111. // )
  112. // },
  113. // })
  114. // const authPath2 = path.join(Global.Path.data, "auth.json")
  115. // await Bun.write(
  116. // authPath2,
  117. // JSON.stringify({
  118. // gitlab: {
  119. // type: "api",
  120. // key: "glpat-test-pat-token",
  121. // },
  122. // }),
  123. // )
  124. // await Instance.provide({
  125. // directory: tmp.path,
  126. // init: async () => {
  127. // Env.set("GITLAB_TOKEN", "")
  128. // },
  129. // fn: async () => {
  130. // const providers = await list()
  131. // expect(providers[ProviderID.gitlab]).toBeDefined()
  132. // expect(providers[ProviderID.gitlab].key).toBe("glpat-test-pat-token")
  133. // },
  134. // })
  135. // })
  136. // test("GitLab Duo: supports self-hosted instance configuration", async () => {
  137. // await using tmp = await tmpdir({
  138. // init: async (dir) => {
  139. // await Bun.write(
  140. // path.join(dir, "opencode.json"),
  141. // JSON.stringify({
  142. // $schema: "https://opencode.ai/config.json",
  143. // provider: {
  144. // gitlab: {
  145. // options: {
  146. // instanceUrl: "https://gitlab.company.internal",
  147. // apiKey: "glpat-internal-token",
  148. // },
  149. // },
  150. // },
  151. // }),
  152. // )
  153. // },
  154. // })
  155. // await Instance.provide({
  156. // directory: tmp.path,
  157. // init: async () => {
  158. // Env.set("GITLAB_INSTANCE_URL", "https://gitlab.company.internal")
  159. // },
  160. // fn: async () => {
  161. // const providers = await list()
  162. // expect(providers[ProviderID.gitlab]).toBeDefined()
  163. // expect(providers[ProviderID.gitlab].options?.instanceUrl).toBe("https://gitlab.company.internal")
  164. // },
  165. // })
  166. // })
  167. // test("GitLab Duo: config apiKey takes precedence over environment variable", async () => {
  168. // await using tmp = await tmpdir({
  169. // init: async (dir) => {
  170. // await Bun.write(
  171. // path.join(dir, "opencode.json"),
  172. // JSON.stringify({
  173. // $schema: "https://opencode.ai/config.json",
  174. // provider: {
  175. // gitlab: {
  176. // options: {
  177. // apiKey: "config-token",
  178. // },
  179. // },
  180. // },
  181. // }),
  182. // )
  183. // },
  184. // })
  185. // await Instance.provide({
  186. // directory: tmp.path,
  187. // init: async () => {
  188. // Env.set("GITLAB_TOKEN", "env-token")
  189. // },
  190. // fn: async () => {
  191. // const providers = await list()
  192. // expect(providers[ProviderID.gitlab]).toBeDefined()
  193. // },
  194. // })
  195. // })
  196. // test("GitLab Duo: includes context-1m beta header in aiGatewayHeaders", async () => {
  197. // await using tmp = await tmpdir({
  198. // init: async (dir) => {
  199. // await Bun.write(
  200. // path.join(dir, "opencode.json"),
  201. // JSON.stringify({
  202. // $schema: "https://opencode.ai/config.json",
  203. // }),
  204. // )
  205. // },
  206. // })
  207. // await Instance.provide({
  208. // directory: tmp.path,
  209. // init: async () => {
  210. // Env.set("GITLAB_TOKEN", "test-token")
  211. // },
  212. // fn: async () => {
  213. // const providers = await list()
  214. // expect(providers[ProviderID.gitlab]).toBeDefined()
  215. // expect(providers[ProviderID.gitlab].options?.aiGatewayHeaders?.["anthropic-beta"]).toContain(
  216. // "context-1m-2025-08-07",
  217. // )
  218. // },
  219. // })
  220. // })
  221. // test("GitLab Duo: supports feature flags configuration", async () => {
  222. // await using tmp = await tmpdir({
  223. // init: async (dir) => {
  224. // await Bun.write(
  225. // path.join(dir, "opencode.json"),
  226. // JSON.stringify({
  227. // $schema: "https://opencode.ai/config.json",
  228. // provider: {
  229. // gitlab: {
  230. // options: {
  231. // featureFlags: {
  232. // duo_agent_platform_agentic_chat: true,
  233. // duo_agent_platform: true,
  234. // },
  235. // },
  236. // },
  237. // },
  238. // }),
  239. // )
  240. // },
  241. // })
  242. // await Instance.provide({
  243. // directory: tmp.path,
  244. // init: async () => {
  245. // Env.set("GITLAB_TOKEN", "test-token")
  246. // },
  247. // fn: async () => {
  248. // const providers = await list()
  249. // expect(providers[ProviderID.gitlab]).toBeDefined()
  250. // expect(providers[ProviderID.gitlab].options?.featureFlags).toBeDefined()
  251. // expect(providers[ProviderID.gitlab].options?.featureFlags?.duo_agent_platform_agentic_chat).toBe(true)
  252. // },
  253. // })
  254. // })
  255. // test("GitLab Duo: has multiple agentic chat models available", async () => {
  256. // await using tmp = await tmpdir({
  257. // init: async (dir) => {
  258. // await Bun.write(
  259. // path.join(dir, "opencode.json"),
  260. // JSON.stringify({
  261. // $schema: "https://opencode.ai/config.json",
  262. // }),
  263. // )
  264. // },
  265. // })
  266. // await Instance.provide({
  267. // directory: tmp.path,
  268. // init: async () => {
  269. // Env.set("GITLAB_TOKEN", "test-token")
  270. // },
  271. // fn: async () => {
  272. // const providers = await list()
  273. // expect(providers[ProviderID.gitlab]).toBeDefined()
  274. // const models = Object.keys(providers[ProviderID.gitlab].models)
  275. // expect(models.length).toBeGreaterThan(0)
  276. // expect(models).toContain("duo-chat-haiku-4-5")
  277. // expect(models).toContain("duo-chat-sonnet-4-5")
  278. // expect(models).toContain("duo-chat-opus-4-5")
  279. // },
  280. // })
  281. // })
  282. // describe("GitLab Duo: workflow model routing", () => {
  283. // test("duo-workflow-* model routes through workflowChat", async () => {
  284. // await using tmp = await tmpdir({
  285. // init: async (dir) => {
  286. // await Bun.write(path.join(dir, "opencode.json"), JSON.stringify({ $schema: "https://opencode.ai/config.json" }))
  287. // },
  288. // })
  289. // await Instance.provide({
  290. // directory: tmp.path,
  291. // init: async () => {
  292. // Env.set("GITLAB_TOKEN", "test-token")
  293. // },
  294. // fn: async () => {
  295. // const providers = await list()
  296. // const gitlab = providers[ProviderID.gitlab]
  297. // expect(gitlab).toBeDefined()
  298. // gitlab.models["duo-workflow-sonnet-4-6"] = {
  299. // id: ModelID.make("duo-workflow-sonnet-4-6"),
  300. // providerID: ProviderID.make("gitlab"),
  301. // name: "Agent Platform (Claude Sonnet 4.6)",
  302. // family: "",
  303. // api: { id: "duo-workflow-sonnet-4-6", url: "https://gitlab.com", npm: "gitlab-ai-provider" },
  304. // status: "active",
  305. // headers: {},
  306. // options: { workflowRef: "claude_sonnet_4_6" },
  307. // cost: { input: 0, output: 0, cache: { read: 0, write: 0 } },
  308. // limit: { context: 200000, output: 64000 },
  309. // capabilities: {
  310. // temperature: false,
  311. // reasoning: true,
  312. // attachment: true,
  313. // toolcall: true,
  314. // input: { text: true, audio: false, image: true, video: false, pdf: true },
  315. // output: { text: true, audio: false, image: false, video: false, pdf: false },
  316. // interleaved: false,
  317. // },
  318. // release_date: "",
  319. // variants: {},
  320. // }
  321. // const model = await getModel(ProviderID.gitlab, ModelID.make("duo-workflow-sonnet-4-6"))
  322. // expect(model).toBeDefined()
  323. // expect(model.options?.workflowRef).toBe("claude_sonnet_4_6")
  324. // const language = await getLanguage(model)
  325. // expect(language).toBeDefined()
  326. // expect(language).toBeInstanceOf(GitLabWorkflowLanguageModel)
  327. // },
  328. // })
  329. // })
  330. // test("duo-chat-* model routes through agenticChat (not workflow)", async () => {
  331. // await using tmp = await tmpdir({
  332. // init: async (dir) => {
  333. // await Bun.write(path.join(dir, "opencode.json"), JSON.stringify({ $schema: "https://opencode.ai/config.json" }))
  334. // },
  335. // })
  336. // await Instance.provide({
  337. // directory: tmp.path,
  338. // init: async () => {
  339. // Env.set("GITLAB_TOKEN", "test-token")
  340. // },
  341. // fn: async () => {
  342. // const providers = await list()
  343. // expect(providers[ProviderID.gitlab]).toBeDefined()
  344. // const model = await getModel(ProviderID.gitlab, ModelID.make("duo-chat-sonnet-4-5"))
  345. // expect(model).toBeDefined()
  346. // const language = await getLanguage(model)
  347. // expect(language).toBeDefined()
  348. // expect(language).not.toBeInstanceOf(GitLabWorkflowLanguageModel)
  349. // },
  350. // })
  351. // })
  352. // test("model.options merged with provider.options in getLanguage", async () => {
  353. // await using tmp = await tmpdir({
  354. // init: async (dir) => {
  355. // await Bun.write(path.join(dir, "opencode.json"), JSON.stringify({ $schema: "https://opencode.ai/config.json" }))
  356. // },
  357. // })
  358. // await Instance.provide({
  359. // directory: tmp.path,
  360. // init: async () => {
  361. // Env.set("GITLAB_TOKEN", "test-token")
  362. // },
  363. // fn: async () => {
  364. // const providers = await list()
  365. // const gitlab = providers[ProviderID.gitlab]
  366. // expect(gitlab.options?.featureFlags).toBeDefined()
  367. // const model = await getModel(ProviderID.gitlab, ModelID.make("duo-chat-sonnet-4-5"))
  368. // expect(model).toBeDefined()
  369. // expect(model.options).toBeDefined()
  370. // },
  371. // })
  372. // })
  373. // })
  374. // describe("GitLab Duo: static models", () => {
  375. // test("static duo-chat models always present regardless of discovery", async () => {
  376. // await using tmp = await tmpdir({
  377. // init: async (dir) => {
  378. // await Bun.write(path.join(dir, "opencode.json"), JSON.stringify({ $schema: "https://opencode.ai/config.json" }))
  379. // },
  380. // })
  381. // await Instance.provide({
  382. // directory: tmp.path,
  383. // init: async () => {
  384. // Env.set("GITLAB_TOKEN", "test-token")
  385. // },
  386. // fn: async () => {
  387. // const providers = await list()
  388. // const models = Object.keys(providers[ProviderID.gitlab].models)
  389. // expect(models).toContain("duo-chat-haiku-4-5")
  390. // expect(models).toContain("duo-chat-sonnet-4-5")
  391. // expect(models).toContain("duo-chat-opus-4-5")
  392. // },
  393. // })
  394. // })
  395. // })