fix: complete runtime and workspace workflows

Restore Ask workspace reads and output paging without granting write access,
and let programming Subagents reuse their parent's browser page. Allocate
browser resources only when used, keep Agent pages aligned with workbar tabs,
recover released bindings, and remove unused automatic screenshot work.

Preserve inherited Runtime selections during remote usage persistence and
manual compression. Keep viable channel model fallbacks, display the actual
scheduled-task mode and Harness model source, and avoid rediscovery delays
when calling healthy MCP tools. Fix directory/history refresh, case-only
renames, rename-aware commit diffs, and FastGPT probe success reporting.

Add regression coverage and align feature documentation. The Agent-side
connection timeout fix requires deploying an updated Agent; existing Ask
read-only and Execute authorization boundaries remain unchanged.

Final validation: 3839 tests passed, 66 skipped; typecheck, lint, development
build, and diff checks passed. Isolated Electron UI/MCP workflows passed with
a loopback model fixture. Current-source Linux x64 Host checks passed with
three successful real model requests. Chromium loadURL rejection was not
reproduced in the UI; released-binding recovery has automated coverage.

Release note: 修复 Ask 读取项目文件、浏览器页面显示与恢复、文件管理及模型配置跟随中的不一致,并减少无用截图和 MCP 等待。定时任务显示实际工作模式,远程会话可正常保存继承 Runtime 的用量;远端连接超时修复需更新 Agent 后生效。
This commit is contained in:
mesalogo
2026-09-10 12:48:30 +08:00
parent 020a9ad0dc
commit c037d7fb20
62 changed files with 2637 additions and 521 deletions
+49
View File
@@ -6,6 +6,7 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
import type { KnowledgeService } from '../src/main/knowledge/knowledge-service'
import { KnowledgeMcpGateway } from '../src/main/agent/knowledge-mcp-gateway'
import { BrowserService } from '../src/main/browser/browser-service'
import type { BrowserLiveState } from '../src/shared/contracts'
const conversationId = 'browser-tabs-electron-e2e'
const otherConversationId = 'browser-tabs-electron-e2e-other'
@@ -50,6 +51,54 @@ async function main(): Promise<void> {
let client: Client | undefined
let token: string | undefined
try {
const beforeReservations = webContents.getAllWebContents().length
const states: BrowserLiveState[] = []
const removeStateListener = browser.onState((state) => states.push(state))
const unused = Array.from({ length: 4 }, (_, index) =>
browser.reserveRequestTab(`unused-request-${index}`, `request-${index}`, window.webContents.id)
)
assert.equal(browser.getSessionCount(), 0)
assert.equal(browser.getTabCount(), 0)
assert.equal(webContents.getAllWebContents().length, beforeReservations)
assert.equal(states.length, 0)
for (const lease of unused) {
lease.release()
assert.equal(browser.getOwnerWindowId(lease.conversationId), undefined)
}
console.log('Four unused request reservations created no Electron sessions, WebContents, or UI events')
const reserved = browser.reserveRequestTab(conversationId, 'reserved-request', window.webContents.id)
await gateway.start()
token = gateway.grant('reserved-request', [], controller.signal, 'none', undefined, conversationId, reserved.tabId, reserved)
assert(token)
client = new Client({ name: 'reserved-browser-electron-e2e', version: '1.0.0' })
await client.connect(new StreamableHTTPClientTransport(new URL(gateway.getEndpoint()!), {
requestInit: { headers: { Authorization: `Bearer ${token}` } }
}))
assert.equal(browser.getSessionCount(), 0)
const reservedNavigation = await client.callTool({ name: 'browser_navigate', arguments: { url: `${origin}/mcp` } })
assert.notEqual(reservedNavigation.isError, true)
assert.equal(browser.getSessionCount(), 1)
assert.equal(states[0]?.status, 'creating')
assert.equal(states[0]?.tabId, reserved.tabId)
assert.equal(states[0]?.workbarInstanceId, reserved.tabId)
assert(states.every((state) => state.workbarInstanceId === reserved.tabId && !('frameDataUrl' in state)))
const restoredRequestTab = await browser.createTab(conversationId, window.webContents.id, controller.signal, reserved.tabId)
assert.equal(restoredRequestTab.tabId, reserved.tabId)
assert.equal(restoredRequestTab.workbarInstanceId, reserved.tabId)
assert.equal(browser.getTabCount(), 1)
assert.match(JSON.stringify(await client.callTool({ name: 'browser_snapshot', arguments: {} })), /MCP target/u)
await assert.rejects(browser.closeTab(conversationId, reserved.tabId, window.webContents.id), /正在被.*请求使用/u)
gateway.revoke(token)
token = undefined
await client.close()
client = undefined
await browser.closeTab(conversationId, reserved.tabId, window.webContents.id)
await browser.closeTab(conversationId, reserved.tabId, window.webContents.id)
assert.equal(browser.getSessionCount(), 0)
removeStateListener()
console.log('MCP navigation materialized the exact reserved tab/workbar identity and released its request lease')
await browser.navigate(conversationId, `${origin}/first`, controller.signal, undefined, window.webContents.id)
const [unownedPrimary] = browser.listTabs(conversationId, window.webContents.id)
assert(unownedPrimary)
@@ -0,0 +1,133 @@
import { execFile } from 'node:child_process'
import { resolve } from 'node:path'
import { pathToFileURL } from 'node:url'
import { promisify } from 'node:util'
import { describe, expect, it } from 'vitest'
type Fixture = {
status?: number
body?: unknown
raw?: string
error?: string
}
type ProviderReport = {
catalog: { success: boolean; failure?: string; count?: number }
retrievals: Array<{
searchMode: string
usingRerank?: boolean
success: boolean
failure?: string
count?: number
contentPresent?: boolean
}>
features: { searchModes: string[]; rerankProbed: boolean; rerankSucceeded: boolean }
operations: Array<{ name: string; status: number | 'failed' }>
}
const success = (list: unknown[] = []): Fixture => ({
body: { code: 200, data: { list } }
})
async function probe(
retrievalFixtures: Record<string, Fixture>,
catalog: Fixture = { body: { code: 200, data: [{ _id: 'fixture-dataset', type: 'dataset' }] } }
): Promise<ProviderReport> {
// Run the actual CLI with an entirely in-process fetch fixture. No server,
// credentials file, external provider, or real knowledge request is used.
const script = `
const fixtures = ${JSON.stringify(retrievalFixtures)};
const catalog = ${JSON.stringify(catalog)};
globalThis.fetch = async (url, init) => {
const path = new URL(url).pathname;
let fixture;
if (path.endsWith('/list')) fixture = catalog;
else if (path.endsWith('/detail')) fixture = {body: {code: 200, data: {}}};
else if (path.endsWith('/searchTest')) {
const input = JSON.parse(init.body);
fixture = fixtures[input.usingReRank ? 'rerank' : input.searchMode];
} else throw new Error('Unexpected fixture request');
if (!fixture) throw new Error('Missing fixture');
if (fixture.error) throw new DOMException('fixture request failure', fixture.error);
return new Response(fixture.raw ?? JSON.stringify(fixture.body), {
status: fixture.status ?? 200, headers: {'Content-Type': 'application/json'}
});
};
process.argv = [process.execPath, 'probe', '--provider=fastgpt', '--extended'];
await import(${JSON.stringify(pathToFileURL(resolve('scripts/external-knowledge-probe.mjs')).href)});
`
const { stdout } = await promisify(execFile)(
process.execPath, ['--input-type=module', '--eval', script],
{
env: {
...process.env,
GOODBUDDY_FASTGPT_BASE_URL: 'http://fixture.invalid',
GOODBUDDY_FASTGPT_API_KEY: 'fixture-only-key'
},
timeout: 10_000
}
)
expect(stdout).not.toContain('fixture-only-key')
expect(stdout).not.toContain('fixture.invalid')
expect(stdout).not.toContain('fixture-dataset')
return JSON.parse(stdout).providers[0] as ProviderReport
}
describe('FastGPT probe success evidence', () => {
it.each([
[{ status: 401, body: { code: 200, data: [] } }, 'http-error'],
[{ status: 500, body: { code: 200, data: { list: [] } } }, 'http-error'],
[{ body: { code: 403, data: { list: [] } } }, 'business-error'],
[{ body: { data: { list: [] } } }, 'business-error'],
[{ body: { code: 200, data: {} } }, 'invalid-shape'],
[{ body: { code: 200, data: { list: null } } }, 'invalid-shape'],
[{ raw: '{malformed' }, 'request-failed'],
[{ error: 'TimeoutError' }, 'request-failed'],
[{ error: 'TypeError' }, 'request-failed']
] as const)('does not advertise failed retrievals: %j', async (fixture, failure) => {
const report = await probe({
embedding: fixture, fullTextRecall: fixture, mixedRecall: fixture, rerank: fixture
})
expect(report.features).toEqual({
searchModes: [], rerankProbed: true, rerankSucceeded: false,
extensionQueryProbed: false
})
expect(report.retrievals).toHaveLength(4)
for (const retrieval of report.retrievals) {
expect(retrieval).toMatchObject({ success: false, failure })
expect(retrieval).not.toHaveProperty('count')
expect(retrieval).not.toHaveProperty('contentPresent')
}
})
it('distinguishes successful empty lists from failures and successful nonempty results', async () => {
const report = await probe({
embedding: success(),
fullTextRecall: { body: { code: 200, data: [] } },
mixedRecall: { body: { code: 500, data: { list: [] } } },
rerank: success([{ q: 'private fixture content', score: 0.9 }])
})
expect(report.features).toMatchObject({
searchModes: ['embedding', 'fullTextRecall'],
rerankProbed: true, rerankSucceeded: true
})
expect(report.retrievals[0]).toMatchObject({ success: true, count: 0, contentPresent: false })
expect(report.retrievals[1]).toMatchObject({ success: true, count: 0 })
expect(report.retrievals[2]).toMatchObject({ success: false, failure: 'business-error' })
expect(report.retrievals[3]).toMatchObject({ success: true, count: 1, contentPresent: true })
expect(JSON.stringify(report)).not.toContain('private fixture content')
})
it('does not claim an extended rerank probe when catalog discovery fails', async () => {
const report = await probe({}, {
status: 403,
body: { code: 200, data: [{ _id: 'fixture-dataset', type: 'dataset' }] }
})
expect(report.catalog).toMatchObject({ success: false, failure: 'http-error' })
expect(report.catalog).not.toHaveProperty('count')
expect(report.retrievals).toEqual([])
expect(report.features).toMatchObject({
searchModes: [], rerankProbed: false, rerankSucceeded: false
})
expect(report.operations).toHaveLength(1)
})
})