models-settings.e2e.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. // Web e2e scenario: the Models settings page end to end through the real
  2. // wire — the add card offers the dormant pi-ai catalog, a blank key saves a
  3. // reference-free profile for provider-native auth, and typing an API key later
  4. // stores it write-only under the derived reference (`MINIMAX_CN_API_KEY`)
  5. // while the settings document records only that reference. Each saved row
  6. // appears after route topology invalidation without presenting liveness as
  7. // provider status. The customized-settings fold writes its curated fields —
  8. // the endpoint, and a declared route's own name and protocol — as merge
  9. // patches against the stored profile. Zero model calls: configuration is pure
  10. // settings/credentials/llm-domain traffic, so there is no fixture and a
  11. // stray stream would fail loud because the adapter registry is empty. The provider under test is
  12. // minimax-cn so a developer's real ANTHROPIC/OPENAI environment keys can
  13. // never shadow the derived reference. The deletion dialog distinguishes a
  14. // reference-free profile from a page-managed key before the credential and
  15. // settings unsets reach the wire.
  16. import { assertModelInputLayout } from './model-input-layout.ts'
  17. import { readFile } from 'node:fs/promises'
  18. import { fileURLToPath } from 'node:url'
  19. import { join } from 'node:path'
  20. import type { Browser, Page } from 'playwright'
  21. import { chromium } from 'playwright'
  22. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  23. import {
  24. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  25. launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold,
  26. } from './scaffold.ts'
  27. import { ZH_BROWSER_LOCALE, saveFailureShot } from './support.ts'
  28. const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/models-settings', import.meta.url))
  29. const EMPTY_EXPECTED = join(SNAPSHOT_DIR, 'empty.expected.md')
  30. const CONFIGURED_EXPECTED = join(SNAPSHOT_DIR, 'configured.expected.md')
  31. const DECLARED_EXPECTED = join(SNAPSHOT_DIR, 'declared.expected.md')
  32. const DECLARED_EDIT_EXPECTED = join(SNAPSHOT_DIR, 'declared-edit.expected.md')
  33. const MODEL_PICKER_EXPECTED = join(SNAPSHOT_DIR, 'model-picker.expected.md')
  34. const NATIVE_DELETE_EXPECTED = join(SNAPSHOT_DIR, 'native-delete.expected.md')
  35. const DELETE_EXPECTED = join(SNAPSHOT_DIR, 'delete.expected.md')
  36. const MODE = webSnapshotMode()
  37. describe('web e2e: Models settings page configures a dormant provider', () => {
  38. let scaffold: WebScaffold
  39. let browser: Browser
  40. let page: Page
  41. let tripwire: ReturnType<typeof watchConsole>
  42. beforeAll(async () => {
  43. scaffold = await launchWebScaffold({})
  44. browser = await chromium.launch()
  45. // The scenario asserts the shipped Chinese copy, so the browser asks for it.
  46. page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  47. tripwire = watchConsole(page)
  48. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  49. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  50. }, 120_000)
  51. afterAll(async () => {
  52. await browser?.close()
  53. await scaffold?.close()
  54. })
  55. it('opens the add card over the dormant directory vocabulary', async () => {
  56. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-empty'))
  57. await page.getByRole('button', { name: '设置', exact: true }).click()
  58. const dialog = page.getByRole('dialog', { name: '设置' })
  59. await dialog.waitFor({ timeout: 10_000 })
  60. await dialog.getByRole('button', { name: '模型' }).click()
  61. await dialog.getByText('填入各提供方的 API 密钥即可使用其模型。').waitFor({ timeout: 10_000 })
  62. // The dormant pi-ai adapter contributes its whole installed catalog; no
  63. // provider is configured yet, so the page is one add button.
  64. const add = dialog.getByRole('button', { name: '添加提供方' })
  65. await add.waitFor({ timeout: 10_000 })
  66. // The button enables once the dormant catalog lands in the join.
  67. await expect.poll(async () => add.isEnabled(), { timeout: 10_000 }).toBe(true)
  68. await add.click()
  69. const pick = dialog.getByLabel('提供方')
  70. await pick.waitFor({ timeout: 10_000 })
  71. await expect.poll(async () => pick.locator('option').count(), { timeout: 10_000 }).toBeGreaterThan(30)
  72. const options = await pick.locator('option').allTextContents()
  73. expect(options).toContain('anthropic')
  74. expect(options).toContain('minimax-cn')
  75. await pick.selectOption('minimax-cn')
  76. await dialog.getByRole('textbox', { name: 'API 密钥', exact: true }).waitFor({ timeout: 10_000 })
  77. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  78. await compareOrRefreshGolden(EMPTY_EXPECTED, snapshot, MODE)
  79. }, 60_000)
  80. it('refuses a key no HTTP header can carry before anything is written', async () => {
  81. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-illegal-key'))
  82. const dialog = page.getByRole('dialog', { name: '设置' })
  83. const key = dialog.getByLabel('API 密钥')
  84. const save = dialog.getByRole('button', { name: '保存', exact: true })
  85. // A key no HTTP header can carry would save cleanly and fail the first
  86. // turn with a ByteString TypeError; the form names the offending field
  87. // instead.
  88. await key.fill('sk-\u{1F600}minimax')
  89. await dialog.getByText('该 API 密钥格式错误,请检查。').waitFor({ timeout: 10_000 })
  90. await expect.poll(async () => save.isEnabled(), { timeout: 10_000 }).toBe(false)
  91. // Clearing it restores submit: an empty field means "keep what is stored",
  92. // never a refusal, or editing any other setting would demand the key.
  93. await key.fill('')
  94. await expect.poll(async () => save.isEnabled(), { timeout: 10_000 }).toBe(true)
  95. expect(await dialog.getByText('该 API 密钥格式错误,请检查。').count()).toBe(0)
  96. }, 60_000)
  97. it('saves a blank key as a reference-free provider-native profile', async () => {
  98. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-native-auth'))
  99. const dialog = page.getByRole('dialog', { name: '设置' })
  100. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  101. const row = dialog.getByText('minimax-cn', { exact: true }).first()
  102. await row.waitFor({ timeout: 10_000 })
  103. await dialog.getByText('已保存 minimax-cn。', { exact: true }).waitFor({ timeout: 10_000 })
  104. expect(await dialog.getByRole('img', { name: 'API 密钥已配置' }).count()).toBe(0)
  105. expect(await dialog.getByRole('img', { name: 'API 密钥缺失' }).count()).toBe(0)
  106. const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  107. expect(document).toContain('minimax-cn: {}')
  108. expect(document).not.toContain('MINIMAX_CN_API_KEY')
  109. }, 60_000)
  110. it('describes reference-free deletion without claiming a credential exists', async () => {
  111. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-native-delete'))
  112. const settingsDialog = page.getByRole('dialog', { name: '设置' })
  113. await settingsDialog.getByRole('button', { name: '删除 minimax-cn', exact: true }).click()
  114. const deleteDialog = page.getByRole('dialog', { name: '删除 minimax-cn?' })
  115. await deleteDialog.waitFor({ timeout: 10_000 })
  116. const snapshot = await captureStableAria(
  117. page,
  118. '[role="dialog"][aria-label="删除 minimax-cn?"]',
  119. scaffold.workspaceCwd,
  120. )
  121. await compareOrRefreshGolden(NATIVE_DELETE_EXPECTED, snapshot, MODE)
  122. await deleteDialog.getByRole('button', { name: '取消', exact: true }).click()
  123. }, 60_000)
  124. it('stores the key under the derived reference and keeps the route live', async () => {
  125. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-add'))
  126. const dialog = page.getByRole('dialog', { name: '设置' })
  127. await dialog.getByRole('button', { name: '编辑 minimax-cn' }).click()
  128. await dialog.getByRole('textbox', { name: 'API 密钥', exact: true }).fill('sk-e2e-minimax')
  129. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  130. // The profile lands in settings.yaml with only the derived reference, the
  131. // key value lands in the harness home's .credentials.yaml, the dormant route
  132. // registers, and the topology frame invalidates the page into the row.
  133. await expect.poll(
  134. async () => dialog.getByRole('textbox', { name: 'API 密钥', exact: true }).count(),
  135. { timeout: 10_000 },
  136. ).toBe(0)
  137. await dialog.getByRole('img', { name: 'API 密钥已配置' }).waitFor({ timeout: 10_000 })
  138. await dialog.getByText('已保存 minimax-cn。', { exact: true }).waitFor({ timeout: 10_000 })
  139. const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  140. expect(document).toContain('minimax-cn:')
  141. expect(document).toContain('apiKeyEnv: MINIMAX_CN_API_KEY')
  142. expect(document).not.toContain('sk-e2e-minimax')
  143. const credentialFile = join(scaffold.harnessHome, '.credentials.yaml')
  144. await expect.poll(
  145. async () => readFile(credentialFile, 'utf8').catch(() => ''),
  146. { timeout: 10_000 },
  147. ).toContain('MINIMAX_CN_API_KEY: sk-e2e-minimax')
  148. expect(await page.content()).not.toContain('sk-e2e-minimax')
  149. }, 60_000)
  150. it('applies a customized-settings field as a merge patch', async () => {
  151. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-customized'))
  152. const dialog = page.getByRole('dialog', { name: '设置' })
  153. await dialog.getByRole('button', { name: '编辑 minimax-cn' }).click()
  154. await dialog.getByText('自定义设置').click()
  155. const url = dialog.getByLabel('API 地址')
  156. await url.waitFor({ timeout: 10_000 })
  157. await url.fill('https://gateway.minimax.example/v1')
  158. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  159. // The editor closes back to the row; the fold's write merged into the
  160. // stored profile beside the reference.
  161. await expect.poll(async () => dialog.getByLabel('API 地址').count(), { timeout: 10_000 }).toBe(0)
  162. await dialog.getByText('已保存 minimax-cn。', { exact: true }).waitFor({ timeout: 10_000 })
  163. const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  164. expect(document).toContain('baseURL: https://gateway.minimax.example/v1')
  165. expect(document).toContain('apiKeyEnv: MINIMAX_CN_API_KEY')
  166. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  167. await compareOrRefreshGolden(CONFIGURED_EXPECTED, snapshot, MODE)
  168. expect(tripwire.pageErrors).toEqual([])
  169. }, 60_000)
  170. it('filters the discovered model catalog and clears hidden selections', async () => {
  171. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-picker'))
  172. const settingsDialog = page.getByRole('dialog', { name: '设置' })
  173. await settingsDialog.getByRole('button', { name: '编辑 minimax-cn' }).click()
  174. await settingsDialog.getByText('自定义设置').click()
  175. await settingsDialog.getByRole('button', { name: '获取可用模型' }).click()
  176. const picker = page.getByRole('dialog', { name: '选择要添加的模型' })
  177. await picker.waitFor({ timeout: 10_000 })
  178. const boxes = picker.getByRole('checkbox')
  179. const count = await boxes.count()
  180. expect(count).toBeGreaterThan(0)
  181. expect(await boxes.evaluateAll(nodes => nodes.map(node => (node as HTMLInputElement).checked))).toEqual(
  182. Array.from({ length: count }, () => true),
  183. )
  184. const search = picker.getByRole('searchbox', { name: '搜索模型' })
  185. await search.fill('highspeed')
  186. await expect.poll(async () => boxes.count()).toBe(1)
  187. await picker.getByRole('button', { name: '取消全选' }).click()
  188. expect(await boxes.evaluateAll(nodes => nodes.map(node => (node as HTMLInputElement).checked))).toEqual(
  189. [false],
  190. )
  191. await search.fill('')
  192. await expect.poll(async () => boxes.count()).toBe(count)
  193. const restored = await boxes.evaluateAll(nodes => nodes.map(node => (node as HTMLInputElement).checked))
  194. expect(restored).toEqual(Array.from({ length: count }, () => false))
  195. await picker.getByRole('button', { name: '全选' }).waitFor()
  196. await picker.getByRole('button', { name: '全选' }).click()
  197. const snapshot = await captureStableAria(
  198. page,
  199. '[role="dialog"][aria-label="选择要添加的模型"]',
  200. scaffold.workspaceCwd,
  201. )
  202. await compareOrRefreshGolden(MODEL_PICKER_EXPECTED, snapshot, MODE)
  203. expect(await boxes.evaluateAll(nodes => nodes.map(node => (node as HTMLInputElement).checked))).toEqual(
  204. Array.from({ length: count }, () => true),
  205. )
  206. await picker.getByRole('button', { name: '取消', exact: true }).click()
  207. await settingsDialog.getByRole('button', { name: '取消', exact: true }).click()
  208. }, 60_000)
  209. it('declares a route the adapter does not ship', async () => {
  210. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-declare'))
  211. const dialog = page.getByRole('dialog', { name: '设置' })
  212. const declare = dialog.getByRole('button', { name: '添加自定义提供方' })
  213. await expect.poll(async () => declare.isEnabled(), { timeout: 10_000 }).toBe(true)
  214. await declare.click()
  215. await dialog.getByLabel('Provider ID').fill('acme-gateway')
  216. await dialog.getByLabel('显示名称').fill('Acme Gateway')
  217. await dialog.getByLabel('API 地址').fill('https://gateway.acme.example/v1')
  218. // No reasoning effort on a provider card at all: effort is a per-model
  219. // capability, the models under one provider disagree about it, and a
  220. // switch in the composer already records provider+model+effort together.
  221. expect(await dialog.getByLabel('推理强度').count()).toBe(0)
  222. await dialog.getByRole('button', { name: '添加模型' }).click()
  223. await dialog.getByLabel('模型 ID 1').fill('acme-large')
  224. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  225. expect(await dialog.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).isChecked()).toBe(false)
  226. await dialog.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).check()
  227. await dialog.getByRole('button', { name: '创建提供方', exact: true }).click()
  228. const row = dialog.getByText('Acme Gateway', { exact: true }).first()
  229. await row.waitFor({ timeout: 10_000 })
  230. const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  231. expect(document).toContain('acme-gateway:')
  232. await expect(scaffold.ctx.llm.resolveModelInfo('acme-gateway', 'acme-large')).resolves.toMatchObject({
  233. inputModalities: ['text', 'image'],
  234. })
  235. // The tag follows the adapter's installed catalog: this route is in no
  236. // catalog, while minimax-cn is — even though both now have profiles.
  237. const rowCard = (name: string) => dialog.locator('li').filter({ hasText: name }).first()
  238. await expect.poll(async () => rowCard('Acme Gateway').getByText('自定义').count(), { timeout: 10_000 }).toBe(1)
  239. expect(await rowCard('minimax-cn').getByText('自定义').count()).toBe(0)
  240. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  241. await compareOrRefreshGolden(DECLARED_EXPECTED, snapshot, MODE)
  242. expect(tripwire.pageErrors).toEqual([])
  243. }, 60_000)
  244. it('reopens the name and protocol a declared route was created with', async () => {
  245. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-declared-identity'))
  246. const dialog = page.getByRole('dialog', { name: '设置' })
  247. await dialog.getByRole('button', { name: '编辑 Acme Gateway (acme-gateway)' }).click()
  248. await dialog.getByText('自定义设置').click()
  249. // The create card asked this route for a name and a protocol because
  250. // nothing can default them; the editor reaches the same two fields rather
  251. // than sending the user to settings.yaml for what only this route names.
  252. const protocol = dialog.getByLabel('API 协议')
  253. await protocol.waitFor({ timeout: 10_000 })
  254. expect(await protocol.inputValue()).toBe('openai-completions')
  255. const name = dialog.getByLabel('显示名称', { exact: true })
  256. expect(await name.inputValue()).toBe('Acme Gateway')
  257. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  258. expect(await dialog.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).isChecked()).toBe(true)
  259. await assertModelInputLayout(page, dialog)
  260. const snapshot = await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd)
  261. await compareOrRefreshGolden(DECLARED_EDIT_EXPECTED, snapshot, MODE)
  262. await protocol.selectOption('anthropic-messages')
  263. await name.fill('Acme 网关')
  264. await dialog.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).uncheck()
  265. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  266. await expect.poll(async () => dialog.getByLabel('API 协议').count(), { timeout: 10_000 }).toBe(0)
  267. // The adapter re-resolved the route under the new protocol and re-registered
  268. // it under the new name: an unserviceable profile would have been refused
  269. // at the write instead, and a rename that did not re-register would leave
  270. // the old label on the row.
  271. await dialog.getByText('Acme 网关', { exact: true }).first().waitFor({ timeout: 10_000 })
  272. // The status line names the route as the refreshed directory reports it;
  273. // the target captured when the card opened still carries the old name.
  274. await dialog.getByText('已保存 Acme 网关 (acme-gateway)。', { exact: true }).waitFor({ timeout: 10_000 })
  275. const document = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  276. expect(document).toContain('api: anthropic-messages')
  277. expect(document).toContain('displayName: Acme 网关')
  278. await expect(scaffold.ctx.llm.resolveModelInfo('acme-gateway', 'acme-large')).resolves.toMatchObject({
  279. inputModalities: ['text'],
  280. })
  281. expect(tripwire.pageErrors).toEqual([])
  282. }, 60_000)
  283. it('saves image-only input and reopens the same selection', async () => {
  284. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-input-types'))
  285. const dialog = page.getByRole('dialog', { name: '设置' })
  286. await dialog.getByRole('button', { name: '编辑 Acme 网关 (acme-gateway)' }).click()
  287. await dialog.getByText('自定义设置').click()
  288. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  289. expect(await dialog.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).isChecked()).toBe(false)
  290. const inputs = dialog.getByRole('group', { name: '输入类型 1' })
  291. expect(await inputs.getByRole('checkbox', { name: '文本' }).isChecked()).toBe(true)
  292. expect(await inputs.getByRole('checkbox', { name: '文本' }).isDisabled()).toBe(true)
  293. await inputs.getByRole('checkbox', { name: '图片' }).check()
  294. await inputs.getByRole('checkbox', { name: '文本' }).uncheck()
  295. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  296. await dialog.getByLabel('模型 ID 1').waitFor({ state: 'detached', timeout: 10_000 })
  297. await expect(scaffold.ctx.llm.resolveModelInfo('acme-gateway', 'acme-large')).resolves.toMatchObject({
  298. inputModalities: ['image'],
  299. })
  300. await dialog.getByRole('button', { name: '编辑 Acme 网关 (acme-gateway)' }).click()
  301. await dialog.getByText('自定义设置').click()
  302. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  303. expect(await dialog.getByRole('group', { name: '输入类型 1' }).getByRole('checkbox', { name: '图片' }).isChecked()).toBe(true)
  304. expect(await inputs.getByRole('checkbox', { name: '文本' }).isChecked()).toBe(false)
  305. expect(await inputs.getByRole('checkbox', { name: '图片' }).isDisabled()).toBe(true)
  306. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  307. expect(tripwire.pageErrors).toEqual([])
  308. }, 60_000)
  309. it('inherits installed vision input and retains it when adopting a discovered model', async () => {
  310. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-catalog-inputs'))
  311. await scaffold.ctx.settings.mutate('llm-pi-ai', [{
  312. op: 'set', path: ['providers', 'openai'],
  313. value: { models: [{ id: 'gpt-6-astra', name: 'GPT-6 Astra', contextWindow: 272000, maxTokens: 128000 }] },
  314. }])
  315. const dialog = page.getByRole('dialog', { name: '设置' })
  316. const edit = dialog.getByRole('button', { name: '编辑 openai', exact: true })
  317. await edit.click()
  318. await dialog.getByText('自定义设置').click()
  319. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  320. const types = dialog.getByRole('group', { name: '输入类型 1' })
  321. const image = types.getByRole('checkbox', { name: '图片', exact: true })
  322. await expect.poll(() => image.isChecked()).toBe(true)
  323. expect(await types.getByRole('checkbox', { name: '文本', exact: true }).isChecked()).toBe(true)
  324. const before = await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')
  325. await compareOrRefreshGolden(join(SNAPSHOT_DIR, 'catalog-inputs.expected.md'),
  326. await captureStableAria(page, '[role="dialog"]', scaffold.workspaceCwd), MODE)
  327. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  328. await types.waitFor({ state: 'detached' })
  329. expect(await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')).toBe(before)
  330. await edit.click()
  331. await dialog.getByText('自定义设置').click()
  332. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  333. await expect.poll(() => image.isEnabled()).toBe(true)
  334. await image.uncheck()
  335. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  336. await types.waitFor({ state: 'detached' })
  337. await expect(scaffold.ctx.llm.resolveModelInfo('openai', 'gpt-6-astra')).resolves.toMatchObject({ inputModalities: ['text'] })
  338. await edit.click()
  339. await dialog.getByText('自定义设置').click()
  340. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  341. await expect.poll(() => image.isEnabled()).toBe(true)
  342. expect(await image.isChecked()).toBe(false)
  343. await dialog.getByRole('button', { name: '删除模型 1' }).click()
  344. await dialog.getByRole('button', { name: '获取可用模型' }).click()
  345. const picker = page.getByRole('dialog', { name: '选择要添加的模型' })
  346. await picker.getByRole('button', { name: '取消全选' }).click()
  347. await picker.getByRole('searchbox', { name: '搜索模型' }).fill('gpt-6-astra')
  348. await picker.getByRole('checkbox', { name: 'gpt-6-astra', exact: true }).check()
  349. await picker.getByRole('button', { name: '添加所选' }).click()
  350. await dialog.getByRole('button', { name: '模型选项 1' }).click()
  351. expect(await image.isChecked()).toBe(true)
  352. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  353. await types.waitFor({ state: 'detached' })
  354. await expect(scaffold.ctx.llm.resolveModelInfo('openai', 'gpt-6-astra')).resolves.toMatchObject({ inputModalities: ['text', 'image'] })
  355. await scaffold.ctx.settings.mutate('llm-pi-ai', [{ op: 'unset', path: ['providers', 'openai'] }])
  356. await edit.waitFor({ state: 'detached' })
  357. expect(tripwire.pageErrors).toEqual([])
  358. }, 60_000)
  359. it('confirms an identified provider deletion before removing its profile and key', async () => {
  360. onTestFailed(() => saveFailureShot(page, 'web-e2e-models-delete'))
  361. const settingsDialog = page.getByRole('dialog', { name: '设置' })
  362. await settingsDialog.getByRole('button', { name: '删除 minimax-cn', exact: true }).click()
  363. const deleteDialog = page.getByRole('dialog', { name: '删除 minimax-cn?' })
  364. await deleteDialog.waitFor({ timeout: 10_000 })
  365. const snapshot = await captureStableAria(
  366. page,
  367. '[role="dialog"][aria-label="删除 minimax-cn?"]',
  368. scaffold.workspaceCwd,
  369. )
  370. await compareOrRefreshGolden(DELETE_EXPECTED, snapshot, MODE)
  371. await deleteDialog.getByRole('button', { name: '取消', exact: true }).click()
  372. expect(await readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8')).toContain('minimax-cn:')
  373. await settingsDialog.getByRole('button', { name: '删除 minimax-cn', exact: true }).click()
  374. await page.getByRole('dialog', { name: '删除 minimax-cn?' })
  375. .getByRole('button', { name: '删除 minimax-cn', exact: true }).click()
  376. await expect.poll(
  377. async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'),
  378. { timeout: 10_000 },
  379. ).not.toContain('minimax-cn:')
  380. expect(await readFile(join(scaffold.harnessHome, '.credentials.yaml'), 'utf8'))
  381. .not.toContain('MINIMAX_CN_API_KEY')
  382. await expect.poll(
  383. async () => page.getByRole('dialog', { name: '删除 minimax-cn?' }).count(),
  384. { timeout: 10_000 },
  385. ).toBe(0)
  386. await page.keyboard.press('Escape')
  387. expect(tripwire.pageErrors).toEqual([])
  388. }, 60_000)
  389. it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => {
  390. await assertFixtureInventory(SNAPSHOT_DIR, [
  391. 'configured.expected.md', 'declared-edit.expected.md', 'declared.expected.md',
  392. 'delete.expected.md', 'empty.expected.md', 'model-picker.expected.md',
  393. 'native-delete.expected.md', 'catalog-inputs.expected.md',
  394. ])
  395. })
  396. })