mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-26 15:03:34 +08:00
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:
parent
4573e71801
commit
a2e954b0f9
@ -80,6 +80,24 @@ describe('AssistantMessage output-target cards', () => {
|
|||||||
expect(screen.getByText('assistantOutputs.kind.localhost')).toBeInTheDocument()
|
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', () => {
|
it('renders a card for a markdown link with its Markdown badge', () => {
|
||||||
render(
|
render(
|
||||||
<AssistantMessage
|
<AssistantMessage
|
||||||
|
|||||||
@ -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', () => {
|
it('keeps markdown localhost links as markdown-link targets with authored labels', () => {
|
||||||
const targets = extractAssistantOutputTargets(
|
const targets = extractAssistantOutputTargets(
|
||||||
'[Preview](http://localhost:4173) then http://localhost:4173',
|
'[Preview](http://localhost:4173) then http://localhost:4173',
|
||||||
|
|||||||
@ -105,6 +105,10 @@ export function extractAssistantOutputTargets(
|
|||||||
const localhostTarget = toLocalhostTarget(href)
|
const localhostTarget = toLocalhostTarget(href)
|
||||||
const fileTarget = toWorkspaceFileTarget(href, workDir)
|
const fileTarget = toWorkspaceFileTarget(href, workDir)
|
||||||
|
|
||||||
|
if (isInCodeBlock(match.start, codeBlocks)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if (!title) {
|
if (!title) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -144,6 +148,10 @@ export function extractAssistantOutputTargets(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isInCodeBlock(position, codeBlocks)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const href = trimTrailingPunctuation(match[0] ?? '')
|
const href = trimTrailingPunctuation(match[0] ?? '')
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user