The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(tui,desktop): cover authored link labels and not-found titles
Brooklyn Nicholson5c5f11d23a02
diff --git a/apps/desktop/src/lib/external-link.test.tsx b/apps/desktop/src/lib/external-link.test.tsxindex 5001f9c479a..77210564801 100644--- a/apps/desktop/src/lib/external-link.test.tsx+++ b/apps/desktop/src/lib/external-link.test.tsx@@ -23,6 +23,16 @@ function installDesktopBridge(partial: Partial<Window['hermesDesktop']> = {}) {} as unknown as Window['hermesDesktop']}+const FORGEJO_URL = 'https://forgejo.home.example/homelab/homelab-ops/issues/101'++function installTitleBridge(title: string) {+ const bridge = vi.fn().mockResolvedValue(title)++ installDesktopBridge({ fetchLinkTitle: bridge as unknown as Window['hermesDesktop']['fetchLinkTitle'] })++ return bridge+}+afterEach(() => {__resetLinkTitleCache()vi.restoreAllMocks()@@ -155,6 +165,39 @@ describe('external link helpers', () => {})})+ it('treats not-found fetched titles as unusable', async () => {+ const bridge = installTitleBridge('Page not found - Forgejo')++ await expect(fetchLinkTitle(FORGEJO_URL)).resolves.toBe('')+ expect(bridge).toHaveBeenCalledTimes(1)+ })++ it('keeps an authored fallbackLabel ahead of a fetched title, and skips the fetch', async () => {+ const bridge = installTitleBridge('Kinkolino Forgejo')++ // Chat markdown passes authored link text as `fallbackLabel`, not `label`.+ render(<PrettyLink fallbackLabel="FJ #101" href={FORGEJO_URL} />)++ const link = screen.getByTitle(FORGEJO_URL)++ await waitFor(() => {+ expect(link.textContent).toContain('FJ #101')+ })+ expect(link.textContent).not.toContain('Kinkolino Forgejo')+ expect(bridge).not.toHaveBeenCalled()+ })++ it('still resolves a title when no label was authored', async () => {+ const bridge = installTitleBridge('Homelab Ops Issue 101')++ render(<PrettyLink href={FORGEJO_URL} />)++ await waitFor(() => {+ expect(screen.getByTitle(FORGEJO_URL).textContent).toContain('Homelab Ops Issue 101')+ })+ expect(bridge).toHaveBeenCalledTimes(1)+ })+it('normalizes scheme-less links before opening', () => {installDesktopBridge()diff --git a/ui-tui/src/__tests__/markdown.test.ts b/ui-tui/src/__tests__/markdown.test.tsindex 0c2b2c5d28e..386a0e138ee 100644--- a/ui-tui/src/__tests__/markdown.test.ts+++ b/ui-tui/src/__tests__/markdown.test.ts@@ -2,12 +2,34 @@ import { PassThrough } from 'stream'import { Box, renderSync } from '@hermes/ink'import React from 'react'-import { describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { AUDIO_DIRECTIVE_RE, INLINE_RE, Md, MEDIA_LINE_RE, stripInlineMarkup } from '../components/markdown.js'+import { __resetLinkTitleCache, fetchLinkTitle } from '../lib/externalLink.js'import { stripAnsi } from '../lib/text.js'import { DEFAULT_THEME } from '../theme.js'+afterEach(() => {+ __resetLinkTitleCache()+ vi.unstubAllGlobals()+})++// Stub the network and warm the shared title cache, so a subsequent render+// has the resolved title available synchronously.+const stubFetchedTitle = (url: string, title: string) => {+ vi.stubGlobal(+ 'fetch',+ vi.fn().mockResolvedValue(+ new Response(`<html><head><title>${title}</title></head></html>`, {+ headers: { 'content-type': 'text/html' },+ status: 200+ })+ )+ )++ return fetchLinkTitle(url)+}+const matches = (text: string) => [...text.matchAll(INLINE_RE)].map(m => m[0])const BEL = String.fromCharCode(7)const ESC = String.fromCharCode(27)@@ -266,19 +288,37 @@ describe('Md link labels', () => {expect(rendered).not.toContain('https://www.expedia.com/things-to-do/puerto-rico-el-yunque-rainforest-adventure')})- it('keeps explicit markdown labels as the immediate fallback', () => {+ it('keeps the authored markdown label even when a page title resolves', async () => {+ const url = 'https://www.expedia.com/things-to-do/puerto-rico-el-yunque-rainforest-adventure'++ // Warm the shared cache so `useLinkTitle` would have a title to render+ // synchronously — the label must still win.+ await stubFetchedTitle(url, 'El Yunque Rainforest Adventure | Expedia')+const lines = renderPlain(React.createElement(Box,{ width: 80 },- React.createElement(Md, {- t: DEFAULT_THEME,- text: '[Trip details](https://www.expedia.com/things-to-do/puerto-rico-el-yunque-rainforest-adventure)'- })+ React.createElement(Md, { t: DEFAULT_THEME, text: `[Trip details](${url})` })))- expect(lines.join('\n')).toContain('Trip details')+ const rendered = lines.join('\n')++ expect(rendered).toContain('Trip details')+ expect(rendered).not.toContain('El Yunque Rainforest Adventure | Expedia')+ })++ it('still resolves titles for links whose label is just the URL', async () => {+ const url = 'https://www.expedia.com/things-to-do/puerto-rico-el-yunque-rainforest-adventure'++ await stubFetchedTitle(url, 'Rainforest Adventure Tour')++ const lines = renderPlain(+ React.createElement(Box, { width: 120 }, React.createElement(Md, { t: DEFAULT_THEME, text: `[${url}](${url})` }))+ )++ expect(lines.join('\n')).toContain('Rainforest Adventure Tour')})})