mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-11-29 08:39:35 +08:00
* feat(ui-tool): fold program sub-call lists by default * feat(ui-tool): show a program call as one row over its source and sub-calls A run_code or cua_run_code call renders as one collapsed row with the program's description and its sub-call count. Opening it lists the PTC source code row and then the sub-calls. A failed call shows its first error line in place of the count, and an interrupted call shows that it stopped. A call with more than 32 sub-calls lists the first 10 and the last 10 around a row that states how many are omitted. The three numbers are constants in ToolCallTree. The row replaces the separate collapsed count row. A collapsed program call mounts neither its own toolview nor its sub-calls. * feat(ui-tool): title the program source row "Source code" The row also heads cua_run_code programs in Standard mode, where "PTC" names a different agent mode. * test(web): refresh the scoped PTC round goldens for the program call row The persistent-in-memory variant of the PTC round renders the same program call row as the per-call variant. * fix(ui-tool): keep the program call state whole and move the error line to the source row A failed program call shows "Failed" after its description, the way an interrupted call shows "Stopped". The count and both states never shrink, so a narrow row truncates only the description. The error line could shrink together with the description, which clipped "Stopped" beside a long description and hid a short description beside a long error line. The source code row shows the first error line without its "Error: " lead. * feat(ui-tool): mark the program call row with a hub icon Add the hub-outline product glyph, a central node wired to three satellite nodes, and use it for the program call header instead of layers-outline, which keeps its other uses. * feat(ui-tool): reveal omitted program sub-calls 50 per side on click Lower the sub-call list threshold to 24. The omission row becomes a "Show more (N hidden)" button that lists up to 50 more sub-calls on each side per activation; reopening the program call returns to the first and last 10. * docs(ui-tool): describe the sub-call list constants as the initial window * feat(ui-tool): list the first 20 sub-calls and double the list per show-more click A program call with more than 24 sub-calls now lists its first 20 followed by the "Show more" row; each click doubles the listed count (20, 40, 80, ...) until every sub-call is listed. Reopening the program call returns to the first 20. * fix(ui-tool): show a failed program call's error line with its "Error: " lead The source code row of a failed program call shows the result's first line unchanged, like every other failed tool row. The "Error: " lead is the tool pipeline's model-facing failure text; removing it in the card with a pattern match edited recorded text for one tool variant only. * feat(ui-tool): render a program call's own row through a dedicated source row `run_code` and `cua_run_code` register `SourceCodeRow` in `tool.call.toolview`. It shows the program and its output, with the first error line on failure, and no description, because the program call's header row shows it. `GenericToolCard` keeps no program-call branch. Image labels in flattened result text move to `formatResultImage`, which both rows use. The two registrations add two occupant lines to the `tool.call.toolview` slot report, so its catalog budget rises to 136.
122 lines
7.5 KiB
TypeScript
122 lines
7.5 KiB
TypeScript
/** Standard-mode CUA programs retain code cards, nested calls, images, and source inspection. */
|
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { chromium, type Browser } from 'playwright'
|
|
import { expect, it, onTestFailed, onTestFinished } from 'vitest'
|
|
import type { SessionEvent } from '@deepseek-ai/dsh-session'
|
|
import type {} from '@deepseek-ai/dsh-tools'
|
|
import type {} from '@deepseek-ai/dsh-tool-registry-ptc/types'
|
|
import {
|
|
assertFixtureInventory, captureStableAria, compareOrRefreshGolden, fixtureUserPrompts,
|
|
launchWebScaffold, selectedSessionFixture, watchConsole, webSnapshotMode, type WebScaffold,
|
|
} from './scaffold.ts'
|
|
import { connectFreshWorkspace, expandProgramCalls, newEnglishPage, saveFailureShot } from './support.ts'
|
|
|
|
const fixture = fileURLToPath(new URL('../../../snapshots/session/cua-run-code/session.v4.jsonl', import.meta.url))
|
|
const snapshotDirectory = fileURLToPath(new URL('../../../snapshots/web/cua-run-code', import.meta.url))
|
|
const mode = webSnapshotMode()
|
|
|
|
it.skipIf(mode === 'record')('shows standard CUA programs and their recorded source through the Web composition', async () => {
|
|
const directory = await mkdtemp(join(tmpdir(), 'cua-run-code-web-'))
|
|
const resources: { scaffold?: WebScaffold; browser?: Browser } = {}
|
|
onTestFinished(async () => {
|
|
try { await resources.browser?.close() } finally {
|
|
try { await resources.scaffold?.close() } finally { await rm(directory, { recursive: true, force: true }) }
|
|
}
|
|
})
|
|
const patch = join(directory, 'cua-fixture.yml')
|
|
await writeFile(patch, JSON.stringify([{ id: 'agent-default-model', config: {
|
|
provider: 'deepseek-official', model: 'deepseek-v4-flash-vision-exp',
|
|
} }, { insert: [
|
|
{ id: 'computer-use', name: '@deepseek-ai/dsh-computer-use' },
|
|
{ id: 'cua-run-code-fixture', name: fileURLToPath(new URL('../../../snapshots/session/cua-run-code/provider.mjs', import.meta.url)),
|
|
config: { allowedApps: [{ id: 'a'.repeat(64), name: 'Fixture', executablePath: '/fixture/app' }] } },
|
|
] }]))
|
|
const scaffold = resources.scaffold = await launchWebScaffold({
|
|
replayFixture: fixture, compareReplaySession: false, extraOverlayPath: patch,
|
|
})
|
|
const events: SessionEvent[] = []
|
|
scaffold.ctx.on('session/event', (_session, event) => { events.push(event) })
|
|
const browser = resources.browser = await chromium.launch()
|
|
const page = await newEnglishPage(browser), tripwire = watchConsole(page)
|
|
onTestFailed(() => saveFailureShot(page, 'web-e2e-cua-run-code'))
|
|
await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' })
|
|
await connectFreshWorkspace(page, scaffold.workspaceCwd)
|
|
const agent = scaffold.ctx.agents.list()[0]!
|
|
expect(scaffold.ctx.agentPresets.composedPreset(agent.ctx)).toBe('standard')
|
|
expect(scaffold.ctx.tools.getAll(agent).map(tool => tool.name)).toContain('cua_run_code')
|
|
expect(scaffold.ctx.tools.getAll(agent).map(tool => tool.name)).not.toContain('cua')
|
|
const prompts = fixtureUserPrompts(await readFile(await selectedSessionFixture(fixture), 'utf8'))
|
|
expect(prompts).toHaveLength(1)
|
|
const prompt = prompts.at(0)
|
|
if (prompt === undefined) throw new Error('The CUA recording must contain a user prompt')
|
|
const settled = scaffold.whenTurnSettled()
|
|
const input = page.locator('[data-composer-input]').first()
|
|
await input.fill(prompt)
|
|
await input.press('Enter')
|
|
await settled
|
|
const results = events.filter(event => event.type === 'tool/result')
|
|
expect(results).toHaveLength(2)
|
|
expect(results.every(event => !event.data.message.isError)).toBe(true)
|
|
const subcalls = events.filter(event => event.type === 'tool/ptc-dispatch')
|
|
expect(subcalls).toHaveLength(13)
|
|
const calls = page.locator('[data-program-call="cua_run_code"]')
|
|
const description = 'Select and capture the fixture window'
|
|
const turnControl = page.locator('[data-turn-process="1"]')
|
|
await turnControl.waitFor({ state: 'visible' })
|
|
await expect.poll(() => turnControl.getAttribute('aria-expanded')).toBe('false')
|
|
await turnControl.click()
|
|
await expect.poll(() => turnControl.getAttribute('aria-expanded')).toBe('true')
|
|
const group = calls.first().locator('xpath=ancestor::*[@data-chat-group-key][1]')
|
|
const groupControl = group.locator('[data-process-activity]').first()
|
|
await groupControl.waitFor({ state: 'visible' })
|
|
if (await groupControl.getAttribute('aria-expanded') === 'false') await groupControl.click()
|
|
await expect.poll(() => groupControl.getAttribute('aria-expanded')).toBe('true')
|
|
await expect.poll(() => calls.count()).toBe(2)
|
|
await calls.first().getByRole('button', { name: `${description} 6 tool calls`, exact: true }).click()
|
|
await calls.first().getByRole('button', { name: 'Source code', exact: true }).click()
|
|
const source = calls.first().locator('pre.shiki')
|
|
await source.waitFor()
|
|
expect(await source.textContent()).toContain('var app = await cua.getApp("test.fixture")')
|
|
await expandProgramCalls(page)
|
|
expect(await page.locator('[data-subcalls] [data-tool="cua"]').count()).toBe(subcalls.length)
|
|
expect(events.filter(event => event.type === 'tool/ptc-dispatch' && event.data.content.some(block => block.type === 'image'))).toHaveLength(1)
|
|
expect(events.filter(event => event.type === 'tool/result'
|
|
&& event.data.message.content.some(block => block.type === 'image'))).toHaveLength(1)
|
|
expect(await calls.first().textContent()).toContain('(1x1px, 90 bytes)')
|
|
expect(await calls.first().textContent()).not.toContain('"type": "image"')
|
|
await compareOrRefreshGolden(join(snapshotDirectory, 'ui.expected.md'),
|
|
await captureStableAria(page, '[class*="centerCol"]', scaffold.workspaceCwd), mode)
|
|
if (mode === 'refresh') {
|
|
const evidence = fileURLToPath(new URL('../../../.playwright-mcp/cua-run-code-ui', import.meta.url))
|
|
await mkdir(evidence, { recursive: true })
|
|
await page.screenshot({ path: join(evidence, 'standard-code-cards.png'), animations: 'disabled' })
|
|
const viewport = page.viewportSize()
|
|
await page.setViewportSize({ width: 800, height: 900 })
|
|
await page.screenshot({ path: join(evidence, 'standard-code-cards-narrow.png'), animations: 'disabled' })
|
|
if (viewport !== null) await page.setViewportSize(viewport)
|
|
}
|
|
await page.getByRole('tab', { name: 'Trajectory', exact: true }).click()
|
|
const row = page.getByRole('row', { name: new RegExp(`cua_run_code ${description}`) })
|
|
await row.click()
|
|
await page.getByRole('tab', { name: 'Code', exact: true }).click()
|
|
expect(await page.getByRole('tabpanel').textContent()).toContain('var app = await cua.getApp("test.fixture")')
|
|
await page.getByRole('button', { name: 'Wrap lines', exact: true }).click()
|
|
await compareOrRefreshGolden(join(snapshotDirectory, 'code.expected.md'),
|
|
await captureStableAria(page, '[role="tabpanel"]', scaffold.workspaceCwd), mode)
|
|
if (mode === 'refresh') {
|
|
await page.screenshot({ path: fileURLToPath(new URL('../../../.playwright-mcp/cua-run-code-ui/source-inspector.png', import.meta.url)), animations: 'disabled' })
|
|
}
|
|
const screenshot = page.locator('tr[data-kind="subtool"]').filter({ hasText: '"method":"screenshot"' })
|
|
await screenshot.click()
|
|
await page.getByRole('tab', { name: 'Result', exact: true }).click()
|
|
const image = page.getByRole('tabpanel').locator('img').first()
|
|
await image.waitFor({ state: 'visible' })
|
|
await expect.poll(() => image.evaluate((element: HTMLImageElement) => element.naturalWidth)).toBe(1)
|
|
expect(tripwire.pageErrors).toEqual([])
|
|
expect(tripwire.warnings).toEqual([])
|
|
await assertFixtureInventory(snapshotDirectory, ['ui.expected.md', 'code.expected.md'])
|
|
})
|