declared-reasoning.e2e.ts 4.5 KB

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