fix(desktop): ignore log links in output cards (#714)

Output target detection should not promote URLs or markdown links embedded in fenced log/code blocks into assistant output cards. Keep explicit localhost and file references outside code blocks routable.

Tested: cd desktop && bun run test -- src/lib/assistantOutputTargets.test.ts src/components/chat/AssistantMessage.linkrouting.test.tsx
Tested: cd desktop && bun run lint
Confidence: high
Scope-risk: narrow
This commit is contained in:
程序员阿江(Relakkes) 2026-06-15 17:32:53 +08:00
parent 4573e71801
commit a2e954b0f9
3 changed files with 50 additions and 0 deletions

View File

@ -80,6 +80,24 @@ describe('AssistantMessage output-target cards', () => {
expect(screen.getByText('assistantOutputs.kind.localhost')).toBeInTheDocument()
})
it('does NOT render a localhost card for URLs shown inside a log code block', () => {
render(
<AssistantMessage
sessionId="s1"
content={[
'日志前 50 行:',
'```log',
'[08:29:36][INFO] 代理服务已启动: 127.0.0.1:15721',
'[08:29:36][INFO] Claude Live 配置已接管,代理地址: http://127.0.0.1:15721',
'```',
].join('\n')}
isStreaming={false}
/>,
)
expect(screen.queryByText('assistantOutputs.kind.localhost')).toBeNull()
})
it('renders a card for a markdown link with its Markdown badge', () => {
render(
<AssistantMessage

View File

@ -122,6 +122,30 @@ describe('extractAssistantOutputTargets', () => {
])
})
it('ignores localhost URLs printed inside fenced log output', () => {
const targets = extractAssistantOutputTargets(
[
'日志前 50 行:',
'```log',
'[08:29:36][INFO] 代理服务已启动: 127.0.0.1:15721',
'[08:29:36][INFO] Claude Live 配置已接管,代理地址: http://127.0.0.1:15721',
'```',
].join('\n'),
{ workDir },
)
expect(targets).toEqual([])
})
it('ignores markdown links printed inside fenced code blocks', () => {
const targets = extractAssistantOutputTargets(
['```md', '调试输出: [preview](http://localhost:5173/) [page](index.html)', '```'].join('\n'),
{ workDir },
)
expect(targets).toEqual([])
})
it('keeps markdown localhost links as markdown-link targets with authored labels', () => {
const targets = extractAssistantOutputTargets(
'[Preview](http://localhost:4173) then http://localhost:4173',

View File

@ -105,6 +105,10 @@ export function extractAssistantOutputTargets(
const localhostTarget = toLocalhostTarget(href)
const fileTarget = toWorkspaceFileTarget(href, workDir)
if (isInCodeBlock(match.start, codeBlocks)) {
continue
}
if (!title) {
continue
}
@ -144,6 +148,10 @@ export function extractAssistantOutputTargets(
continue
}
if (isInCodeBlock(position, codeBlocks)) {
continue
}
const href = trimTrailingPunctuation(match[0] ?? '')
if (!href) {