mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-08-29 04:26:38 +00:00
feat(session): persist model selection and share its catalog
This commit is contained in:
@@ -46,9 +46,14 @@ describe('web e2e: the composer model switch is the default for later sessions',
|
||||
return response.sessionId
|
||||
}
|
||||
|
||||
/** The route the gateway reports for one session, through the real wire face. */
|
||||
const currentOf = async (sessionId: string): Promise<unknown> => {
|
||||
return (await scaffold.ctx.sessionController.models({ sessionId: SessionId(sessionId) })).current
|
||||
/** The route the Client derives from the Session projection and Host default. */
|
||||
const currentOf = (sessionId: string): Promise<unknown> => {
|
||||
const session = scaffold.ctx.sessions.get(SessionId(sessionId))
|
||||
if (session === undefined) throw new Error(`session "${sessionId}" is not live`)
|
||||
return Promise.resolve(
|
||||
scaffold.ctx.sessionProjections.snapshot(session).values.modelSelection?.next
|
||||
?? scaffold.ctx.agentDefaultModel.currentSelection(),
|
||||
)
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
|
||||
@@ -234,7 +234,7 @@ describe.skipIf(MODE === 'record')('web e2e: first-run DeepSeek credential setup
|
||||
// trigger — on the page; the scaffold boots without one.
|
||||
await connectFreshWorkspaceZh(page, scaffold.workspaceCwd, 'model-fallback-e2e')
|
||||
|
||||
const modelTrigger = page.getByRole('button', { name: '选择模型', exact: true })
|
||||
const modelTrigger = page.getByRole('button', { name: /^选择模型/ })
|
||||
await modelTrigger.waitFor({ timeout: 10_000 })
|
||||
await modelTrigger.click()
|
||||
await page.getByRole('menuitem', { name: /模型/ }).click()
|
||||
|
||||
@@ -1,46 +1,19 @@
|
||||
// Web e2e scenario: startup auto-selection keeps the hero on screen.
|
||||
//
|
||||
// A page load with a workspace already registered runs
|
||||
// `WorkspaceRuntime.startInitialSelection`: it connects the most recent
|
||||
// workspace and opens its blank session. `openState` flips to `loading` the
|
||||
// moment `open()` lands; driving `data-phase=settling` on the conversation
|
||||
// root from that flip would hide the composer seat and the header
|
||||
// (`visibility:hidden`) for the whole `session.page` round-trip — the
|
||||
// center column blanks and repaints like a full-page refresh on every launch.
|
||||
//
|
||||
// The unit spec pins the phase condition over hand-built stores. What only the
|
||||
// assembled application can show is that the path a user actually takes
|
||||
// reaches it: the real selection service, the real client session opening over
|
||||
// the real /api transport, and a real browser deciding what is painted.
|
||||
// The initial Workspace pick also records the resident Hero/composer nodes and
|
||||
// proves that opening the first blank Session fills the strict outlets without
|
||||
// replacing those nodes.
|
||||
//
|
||||
// The round-trip against a loopback host is far too fast to observe, so this
|
||||
// scenario HOLDS the `session.page` response open in the browser's network
|
||||
// handler and asserts the visible frame while it is in flight. That wait is
|
||||
// what makes the assertions non-vacuous: without the phase exemption, the held
|
||||
// window is exactly when `settling` would be painted and the composer hidden.
|
||||
//
|
||||
// Zero model calls: registering a workspace and opening its blank session are
|
||||
// host RPCs with no model involvement. A stray stream would fail loud with
|
||||
// NO_ADAPTER.
|
||||
/** Web acceptance that startup Session opening preserves the resident Hero tree. */
|
||||
import type { Browser, Page } from 'playwright'
|
||||
import { chromium } from 'playwright'
|
||||
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
|
||||
import { acknowledgeReloadConnectionLoss, launchWebScaffold, watchConsole, type WebScaffold } from './scaffold.ts'
|
||||
import { afterAll, beforeAll, describe, expect, it, onTestFailed, vi } from 'vitest'
|
||||
import {
|
||||
acknowledgeReloadConnectionLoss, launchWebScaffold, watchConsole, type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts'
|
||||
|
||||
/** Wire path of the history round-trip the conversation root waits out. */
|
||||
const HISTORY_ROUTE = '**/api/session/page'
|
||||
|
||||
/**
|
||||
* The conversation root's own phase attribute. `div` disambiguates it from the
|
||||
* composer textarea, which carries an unrelated `data-phase` of its own.
|
||||
*/
|
||||
const ROOT_PHASE = 'div[data-phase]'
|
||||
|
||||
/** Every distinct `data-phase` the conversation root shows, in order, across one page load. */
|
||||
/** Every distinct conversation-root phase observed during one page load. */
|
||||
function recordedPhases(page: Page): Promise<string[]> {
|
||||
return page.evaluate(() => (window as unknown as { __conversationPhases: string[] }).__conversationPhases)
|
||||
}
|
||||
@@ -114,10 +87,8 @@ describe('web e2e: startup auto-selection', () => {
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
}, 120_000)
|
||||
|
||||
it('keeps the hero and the composer on screen while the auto-selected blank session opens', async () => {
|
||||
it('keeps the hero and composer visible while the opening follow snapshot is pending', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-startup-auto-selection'))
|
||||
// Runs before any page script on the reload below, so the first phase the
|
||||
// root ever renders is recorded, not just the ones after a listener attaches.
|
||||
await page.addInitScript(() => {
|
||||
const phases: string[] = []
|
||||
;(window as unknown as { __conversationPhases: string[] }).__conversationPhases = phases
|
||||
@@ -128,41 +99,42 @@ describe('web e2e: startup auto-selection', () => {
|
||||
}, 8)
|
||||
})
|
||||
|
||||
let releaseHistory = (): void => {}
|
||||
const historyHeld = new Promise<void>((resolve) => { releaseHistory = resolve })
|
||||
let historyRequested = (): void => {}
|
||||
const historyInFlight = new Promise<void>((resolve) => { historyRequested = resolve })
|
||||
let releaseOpening = (): void => {}
|
||||
const openingHeld = new Promise<void>((resolve) => { releaseOpening = resolve })
|
||||
let openingRequested = (): void => {}
|
||||
const openingInFlight = new Promise<void>((resolve) => { openingRequested = resolve })
|
||||
let gated = false
|
||||
await page.route(HISTORY_ROUTE, async (route) => {
|
||||
// Only the auto-selection's own round-trip is held; later pages must not
|
||||
// deadlock behind a gate this test has already released.
|
||||
if (gated) { await route.continue(); return }
|
||||
gated = true
|
||||
historyRequested()
|
||||
await historyHeld
|
||||
await route.continue()
|
||||
})
|
||||
const readObservation = scaffold.ctx.sessionQuery.observeSession
|
||||
.bind(scaffold.ctx.sessionQuery)
|
||||
const observe = vi.spyOn(scaffold.ctx.sessionQuery, 'observeSession')
|
||||
.mockImplementation(async (sessionId, options) => {
|
||||
const observation = await readObservation(sessionId, options)
|
||||
if (gated) return observation
|
||||
gated = true
|
||||
openingRequested()
|
||||
await openingHeld
|
||||
return observation
|
||||
})
|
||||
|
||||
const warningsBefore = tripwire.warnings.length
|
||||
await page.reload({ waitUntil: 'commit' })
|
||||
await historyInFlight
|
||||
try {
|
||||
await page.reload({ waitUntil: 'commit' })
|
||||
await openingInFlight
|
||||
|
||||
// The frame a user sees while the session is still opening: hero phase, the
|
||||
// hero title, and a composer that is actually painted (`settling` hides the
|
||||
// seat with `visibility:hidden`, which Playwright reports as not visible).
|
||||
await page.waitForSelector(ROOT_PHASE, { timeout: 15_000 })
|
||||
expect(await page.locator(ROOT_PHASE).first().getAttribute('data-phase')).toBe('hero')
|
||||
expect(await page.getByText('Into the Unknown').isVisible()).toBe(true)
|
||||
expect(await page.locator('textarea').first().isVisible()).toBe(true)
|
||||
await page.waitForSelector(ROOT_PHASE, { timeout: 15_000 })
|
||||
expect(await page.locator(ROOT_PHASE).first().getAttribute('data-phase')).toBe('hero')
|
||||
expect(await page.getByText('Into the Unknown').isVisible()).toBe(true)
|
||||
expect(await page.locator('textarea').first().isVisible()).toBe(true)
|
||||
|
||||
releaseHistory()
|
||||
await page.locator('textarea:enabled[placeholder="Describe what you want to build"]')
|
||||
.waitFor({ timeout: 15_000 })
|
||||
acknowledgeReloadConnectionLoss(tripwire, warningsBefore)
|
||||
|
||||
// Settling is not merely absent from the frame sampled above: the root
|
||||
// never entered it at any point of the load.
|
||||
expect(await recordedPhases(page)).toEqual(['hero'])
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
releaseOpening()
|
||||
await page.locator('textarea:enabled[placeholder="Describe what you want to build"]')
|
||||
.waitFor({ timeout: 15_000 })
|
||||
acknowledgeReloadConnectionLoss(tripwire, warningsBefore)
|
||||
expect(await recordedPhases(page)).toEqual(['hero'])
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
} finally {
|
||||
releaseOpening()
|
||||
observe.mockRestore()
|
||||
}
|
||||
}, 120_000)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user