declared-reasoning.e2e.ts 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Web e2e scenario: a hand-declared model's `reasoningEfforts` reaches the
  2. // composer's effort pane — the levels a settings profile declares are exactly
  3. // what the picker offers, and picking one records it with the Agent default.
  4. // Zero model calls: declaring, describing, and switching are settings/llm
  5. // traffic only, so there is no fixture and a stray stream would fail loud.
  6. import { readFile } from 'node:fs/promises'
  7. import { fileURLToPath } from 'node:url'
  8. import { join } from 'node:path'
  9. import type { Browser, Page } from 'playwright'
  10. import { chromium } from 'playwright'
  11. import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
  12. import {
  13. assertFixtureInventory, captureStableAria, compareOrRefreshGolden,
  14. launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold,
  15. } from './scaffold.ts'
  16. import { ZH_BROWSER_LOCALE, connectFreshWorkspaceZh, saveFailureShot } from './support.ts'
  17. /** Starts the shipped default on this scenario's declared reasoning model. */
  18. const OVERLAY = fileURLToPath(new URL('./declared-reasoning.overlay.yml', import.meta.url))
  19. const SNAPSHOT_DIR = fileURLToPath(new URL('./expected/declared-reasoning', import.meta.url))
  20. const UI_EXPECTED = fileURLToPath(new URL('./expected/declared-reasoning/ui.expected.md', import.meta.url))
  21. const MODE = webSnapshotMode()
  22. describe.skipIf(MODE === 'record')('web e2e: declared reasoning efforts reach the composer', () => {
  23. let scaffold: WebScaffold
  24. let browser: Browser
  25. let page: Page
  26. let tripwire: ReturnType<typeof watchConsole>
  27. beforeAll(async () => {
  28. scaffold = await launchWebScaffold({ extraOverlayPath: OVERLAY })
  29. // The whole reasoning offer is the profile: key = selectable level, value
  30. // = the wire spelling dispatch would send (`max: ultra` renames; the
  31. // valueless `off` means "supported, send nothing"). The route sets no
  32. // deployment default, so the pane leads with the provider-default entry.
  33. await scaffold.ctx.settings.update('llm-pi-ai', {
  34. providers: {
  35. 'acme-gateway': {
  36. displayName: 'Acme Gateway',
  37. api: 'openai-completions',
  38. baseURL: 'https://gateway.acme.example/v1',
  39. models: [{
  40. id: 'acme-think',
  41. name: 'Acme Think',
  42. reasoningEfforts: { off: null, high: 'high', max: 'ultra' },
  43. }],
  44. },
  45. },
  46. })
  47. browser = await chromium.launch()
  48. page = await browser.newPage({ viewport: { width: 1680, height: 1000 }, locale: ZH_BROWSER_LOCALE })
  49. tripwire = watchConsole(page)
  50. await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
  51. await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
  52. await connectFreshWorkspaceZh(page, scaffold.workspaceCwd)
  53. }, 120_000)
  54. afterAll(async () => {
  55. await browser?.close()
  56. await scaffold?.close()
  57. })
  58. it('offers exactly the declared levels and records the picked one', async () => {
  59. onTestFailed(() => saveFailureShot(page, 'web-e2e-declared-reasoning'))
  60. const trigger = page.getByRole('button', { name: /^选择模型/ })
  61. await trigger.waitFor({ timeout: 15_000 })
  62. await trigger.click()
  63. await page.getByRole('menuitem', { name: /推理等级/ }).click()
  64. // Declared levels, nothing else: the provider-default entry (the route
  65. // configures no `reasoning`), then Off/High/Max — minimal, low, medium,
  66. // and xhigh were not declared and must not be offered.
  67. const levels = page.getByRole('menuitemradio')
  68. await expect.poll(async () => levels.allTextContents(), { timeout: 10_000 })
  69. .toEqual(['Default', 'Off', 'High', 'Max'])
  70. const snapshot = await captureStableAria(page, '[role="menu"]', scaffold.workspaceCwd)
  71. await compareOrRefreshGolden(UI_EXPECTED, snapshot, MODE)
  72. // Picking a level is the same gesture that saves the default selection, so
  73. // the effort lands in the Agent default Settings section beside provider/model.
  74. await page.getByRole('menuitemradio', { name: 'High' }).click()
  75. await expect.poll(
  76. async () => readFile(join(scaffold.harnessHome, 'settings.yaml'), 'utf8'),
  77. { timeout: 10_000 },
  78. ).toContain('reasoningEffort: high')
  79. await expect.poll(() => trigger.getAttribute('aria-label'), { timeout: 10_000 })
  80. .toBe('选择模型,当前 Acme Think,推理等级 High')
  81. expect(tripwire.pageErrors).toEqual([])
  82. }, 60_000)
  83. it('keeps its snapshot inventory closed', async () => {
  84. await assertFixtureInventory(SNAPSHOT_DIR, ['ui.expected.md'])
  85. })
  86. })