mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Merge remote-tracking branch 'origin/master' into feat/web-message-feedback-ui
This commit is contained in:
@@ -55,6 +55,10 @@ describe('minimal agent preset', () => {
|
||||
|
||||
const requestHeader = agentHandle.agent.session.requestHeader()
|
||||
if (requestHeader === undefined) throw new Error('the minimal agent issued no model request')
|
||||
const presetFileSystem = scaffold.ctx.agentPresets.serviceFor(agentHandle.agent, 'fs')
|
||||
expect(presetFileSystem).toBeDefined()
|
||||
expect(presetFileSystem?.sandboxMode).toBeUndefined()
|
||||
expect(scaffold.ctx.agentPresets.serviceFor(agentHandle.agent, 'compact')).toBeUndefined()
|
||||
|
||||
const stateDir = join(scaffold.workspaceCwd, 'persistent-state')
|
||||
await mkdir(stateDir)
|
||||
|
||||
@@ -1,28 +1,107 @@
|
||||
// Web e2e scenario: the produced-files row a finished turn ends with. Cold-seeds
|
||||
// a recorded write turn (zero model calls). Package tests cover the derivation
|
||||
// in isolation, but only the assembled application shows that a turn's writes
|
||||
// reach the transcript as an openable row (docs/testing.md snapshot rule). The
|
||||
// click itself is not driven here: it hands the path to the Host's opener,
|
||||
// which would launch a real application on the machine running the suite.
|
||||
import { readFile, writeFile, mkdir } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
// Web e2e scenario: the single-line produced-files summary a finished turn
|
||||
// ends with. Cold-seeds ten writes (zero model calls), then verifies the real
|
||||
// assembled lane keeps a precise +N and a capability-gated folder handoff.
|
||||
// The folder request is intercepted so one real browser click can exercise
|
||||
// the full client carrier without launching a native application in CI.
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import type { Browser, Page } from 'playwright'
|
||||
import { chromium } from 'playwright'
|
||||
import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest'
|
||||
import { afterAll, beforeAll, describe, expect, it, onTestFailed, vi } from 'vitest'
|
||||
import { CallId, createAssistantMessage, createToolResultMessage, createUserMessage } from '@deepseek-ai/dsh-llm'
|
||||
import { SESSION_FORMAT_VERSION, Session, SessionId } from '@deepseek-ai/dsh-session'
|
||||
import type {} from '@deepseek-ai/dsh-session-title'
|
||||
import {
|
||||
launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold,
|
||||
} from './scaffold.ts'
|
||||
import { newEnglishPage, saveFailureShot } from './support.ts'
|
||||
|
||||
// Borrowed read-only: this scenario needs any settled turn whose tools WROTE a
|
||||
// file, not a new recording (the message-actions borrowing pattern).
|
||||
const SEED = fileURLToPath(new URL('./snapshots/permission-policy-context/session.jsonl', import.meta.url))
|
||||
const MODE = webSnapshotMode()
|
||||
const OVERLAY = fileURLToPath(new URL('./produced-files.overlay.yml', import.meta.url))
|
||||
const SEED_ID = 'produced-files-web-e2e'
|
||||
const DONE = 'PRODUCED_FILES_DONE'
|
||||
|
||||
/** The file the borrowed recording's write tool produces. */
|
||||
const PRODUCED = 'policy-neutral.txt'
|
||||
/** Short leading names plus a long third name make the narrow lane deterministically show two. */
|
||||
const PRODUCED = [
|
||||
'关于我.md',
|
||||
'index.html',
|
||||
'long-generated-experience-specification-for-produced-files-overflow.md',
|
||||
'styles.css',
|
||||
'app.ts',
|
||||
'schema.json',
|
||||
'README.md',
|
||||
'preview.svg',
|
||||
'notes.txt',
|
||||
'manifest.yaml',
|
||||
] as const
|
||||
|
||||
/** Build one settled turn whose successful write calls carry ten locations. */
|
||||
function producedFixture(): string {
|
||||
const session = Session.create(SessionId('produced-files-source'))
|
||||
const eventTimeOrigin = new Date().setHours(12, 0, 0, 0)
|
||||
session.append('turn/start', { turn: 1 })
|
||||
const user = session.append('user/message', createUserMessage({
|
||||
content: [{ type: 'text', text: 'Create the site files.' }],
|
||||
source: { kind: 'user' },
|
||||
}), { surfaceOp: 'append' })
|
||||
session.append('session/title', {
|
||||
title: 'Produced files overflow', messageSeqs: [user.seq], source: { kind: 'fallback' },
|
||||
})
|
||||
session.append('step/start', { turn: 1, step: 1 })
|
||||
const calls = PRODUCED.map((path, index) => ({
|
||||
path,
|
||||
callId: CallId(`produced-files-${String(index)}`),
|
||||
args: JSON.stringify({ file_path: path, content: `content of ${path}\n` }),
|
||||
}))
|
||||
session.append('assistant/message', {
|
||||
turn: 1,
|
||||
step: 1,
|
||||
message: createAssistantMessage({
|
||||
content: calls.map(call => ({
|
||||
type: 'tool-call' as const,
|
||||
id: call.callId,
|
||||
name: 'write',
|
||||
arguments: call.args,
|
||||
})),
|
||||
source: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
|
||||
}),
|
||||
}, { surfaceOp: 'append' })
|
||||
for (const call of calls) {
|
||||
const source = session.append('tool/call', {
|
||||
turn: 1, step: 1, callId: call.callId, name: 'write', arguments: call.args,
|
||||
})
|
||||
session.append('tool/result', {
|
||||
turn: 1,
|
||||
step: 1,
|
||||
message: createToolResultMessage({
|
||||
callId: call.callId,
|
||||
content: [{ type: 'text', text: `Created ${call.path}` }],
|
||||
isError: false,
|
||||
}),
|
||||
}, { surfaceOp: 'append', sourceEventSeqs: [source.seq] })
|
||||
}
|
||||
session.append('step/start', { turn: 1, step: 2 })
|
||||
session.append('assistant/message', {
|
||||
turn: 1,
|
||||
step: 2,
|
||||
message: createAssistantMessage({
|
||||
content: [{ type: 'text', text: `Created the site.\n\n${DONE}` }],
|
||||
source: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
|
||||
}),
|
||||
}, { surfaceOp: 'append' })
|
||||
session.append('step/end', { turn: 1, step: 2 })
|
||||
session.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
||||
|
||||
return [
|
||||
JSON.stringify({
|
||||
type: 'session', version: SESSION_FORMAT_VERSION, id: '{{sessionId}}',
|
||||
createdAt: 0, cwd: '{{cwd}}',
|
||||
}),
|
||||
...session.events.map(event => JSON.stringify({
|
||||
...event, time: eventTimeOrigin + event.seq * 1_000,
|
||||
})),
|
||||
'',
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
describe('web e2e: a finished turn ends with the files it produced', () => {
|
||||
let scaffold: WebScaffold
|
||||
@@ -31,16 +110,13 @@ describe('web e2e: a finished turn ends with the files it produced', () => {
|
||||
let tripwire: ReturnType<typeof watchConsole>
|
||||
|
||||
beforeAll(async () => {
|
||||
scaffold = await launchWebScaffold({})
|
||||
// The seeded Session's cwd is the scaffold workspace; the recording's own
|
||||
// nested directory is created too, so its paths stay resolvable.
|
||||
await mkdir(join(scaffold.workspaceCwd, 'workspace'), { recursive: true })
|
||||
await writeFile(join(scaffold.workspaceCwd, PRODUCED), 'neutral\n')
|
||||
const raw = await readFile(SEED, 'utf8')
|
||||
expect(raw, 'borrowed recording must carry the write this scenario reads').toContain(PRODUCED)
|
||||
await seedSession(scaffold, raw, SEED_ID)
|
||||
scaffold = await launchWebScaffold({ extraOverlayPath: OVERLAY })
|
||||
await seedSession(scaffold, producedFixture(), SEED_ID)
|
||||
browser = await chromium.launch()
|
||||
page = await newEnglishPage(browser)
|
||||
// Keep the responsive sidebar available while selecting the cold seed;
|
||||
// the assertion itself narrows the conversation after navigation.
|
||||
await page.setViewportSize({ width: 1280, height: 900 })
|
||||
tripwire = watchConsole(page)
|
||||
await page.goto(scaffold.baseUrl, { waitUntil: 'load' })
|
||||
await page.waitForSelector('[class*="frame"]', { timeout: 30_000 })
|
||||
@@ -51,24 +127,52 @@ describe('web e2e: a finished turn ends with the files it produced', () => {
|
||||
await scaffold?.close()
|
||||
})
|
||||
|
||||
it.skipIf(MODE === 'record')('lists the written file under the closing message, as an opener', async () => {
|
||||
it.skipIf(MODE === 'record')('keeps a narrow ten-file summary on one line with +8 and a folder action', async () => {
|
||||
onTestFailed(() => saveFailureShot(page, 'web-e2e-produced-files'))
|
||||
const groupRow = page.locator('[role="treeitem"]').first()
|
||||
await groupRow.waitFor({ timeout: 15_000 })
|
||||
await groupRow.click()
|
||||
if (await groupRow.getAttribute('aria-expanded') !== 'true') await groupRow.click()
|
||||
const sessionRow = page.locator('[role="treeitem"]').nth(1)
|
||||
await sessionRow.waitFor({ timeout: 10_000 })
|
||||
await sessionRow.click()
|
||||
|
||||
// The row the turn ends with — derived from the write call's locations,
|
||||
// not from whatever the closing message happened to say.
|
||||
const chip = page.getByRole('button', { name: `Open ${PRODUCED}`, exact: true }).first()
|
||||
await chip.waitFor({ timeout: 15_000 })
|
||||
expect(await chip.innerText()).toBe(PRODUCED)
|
||||
// The full path stays reachable for a reader who wants to copy it.
|
||||
expect(await chip.getAttribute('title')).toContain(PRODUCED)
|
||||
// A turn's produced files are labelled, not left as bare chips.
|
||||
expect(await page.getByText('Produced', { exact: true }).count()).toBeGreaterThan(0)
|
||||
await expect.poll(() => page.getByText(DONE, { exact: true }).count(), { timeout: 15_000 }).toBe(1)
|
||||
await page.setViewportSize({ width: 780, height: 900 })
|
||||
const row = page.locator('[data-produced-files-row]')
|
||||
await row.waitFor({ timeout: 15_000 })
|
||||
const chips = row.getByRole('button')
|
||||
await expect.poll(() => chips.count()).toBe(2)
|
||||
expect(await chips.nth(0).innerText()).toBe('关于我.md')
|
||||
expect(await chips.nth(1).innerText()).toBe('index.html')
|
||||
expect(await row.getByText('+ 8 files', { exact: true }).count()).toBe(1)
|
||||
const showFolder = page.getByRole('button', { name: 'Show in folder', exact: true })
|
||||
expect(await showFolder.count()).toBe(1)
|
||||
expect(await page.getByText('Produced', { exact: true }).count()).toBe(1)
|
||||
|
||||
const openPath = vi.spyOn(scaffold.ctx.apiProxy.host, 'openPath')
|
||||
.mockImplementation(async (request, _signal) => ({
|
||||
rpcId: request.rpcId,
|
||||
result: { ok: true, value: { opened: true as const } },
|
||||
}))
|
||||
try {
|
||||
const [response] = await Promise.all([
|
||||
page.waitForResponse(response => new URL(response.url()).pathname === '/api/host.openPath'),
|
||||
showFolder.click({ clickCount: 1 }),
|
||||
])
|
||||
expect(response.status()).toBe(200)
|
||||
expect(openPath).toHaveBeenCalledTimes(1)
|
||||
expect(openPath.mock.calls[0]![0].payload).toEqual({ path: `${scaffold.workspaceCwd}/.` })
|
||||
} finally {
|
||||
openPath.mockRestore()
|
||||
}
|
||||
|
||||
const tops = await row.locator(':scope > *').evaluateAll(elements =>
|
||||
elements.map(element => element.getBoundingClientRect().top))
|
||||
expect(new Set(tops.map(top => Math.round(top))).size).toBe(1)
|
||||
const geometry = await row.evaluate(element => ({
|
||||
clientWidth: element.clientWidth, scrollWidth: element.scrollWidth,
|
||||
}))
|
||||
expect(geometry.scrollWidth).toBeLessThanOrEqual(geometry.clientWidth)
|
||||
|
||||
expect(tripwire.pageErrors).toEqual([])
|
||||
expect(tripwire.warnings).toEqual([])
|
||||
|
||||
6
apps/web/tests/produced-files.overlay.yml
Normal file
6
apps/web/tests/produced-files.overlay.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
# The summary test asserts the native-folder action without launching it. Pin
|
||||
# the capability so headless Linux CI and desktop developer hosts expose the
|
||||
# same UI branch; platform opener behavior belongs to the Host unit tests.
|
||||
- id: api-gateway
|
||||
config:
|
||||
nativeOpen: true
|
||||
@@ -13,7 +13,6 @@
|
||||
- img
|
||||
- img
|
||||
- text: Context injection @deepseek-ai/dsh-system-prompt
|
||||
- text: Running
|
||||
- button "Think The user wants me to ask them a checkpoint question first, then continue with whatever they interject. Let me do exactly that.":
|
||||
- img
|
||||
- img
|
||||
|
||||
@@ -354,10 +354,10 @@ describe('web e2e: empty-draft Cmd+Enter steers the whole queue', () => {
|
||||
{ timeout: 10_000 },
|
||||
).toBe(2)
|
||||
expect(await page.locator('[data-queue-dock]').count()).toBe(0)
|
||||
// The reasoning row streams independently of the steering handoff; wait
|
||||
// for it so the mid snapshot pins the assistant step, not the pre-render
|
||||
// gap a fast machine can catch between steering acceptance and the block.
|
||||
await page.locator('[data-variant="think"]').first().waitFor({ timeout: 10_000 })
|
||||
// The reasoning row streams independently of the steering handoff. Wait
|
||||
// for the block to settle so the mid snapshot does not race its transient
|
||||
// visually-hidden Running label while the question keeps the turn open.
|
||||
await page.locator('[data-variant="think"][data-state="ok"]').first().waitFor({ timeout: 10_000 })
|
||||
const mid = await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd)
|
||||
await compareOrRefreshGolden(STEER_ALL_MID, mid, MODE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user