Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(acceptance): show plain-text evidence verbatim instead of as markdown (#19390)

Arvin Xuee57e544ebe4
diff --git a/src/features/Acceptance/Report/MarkdownEvidence.tsx b/src/features/Acceptance/Report/MarkdownEvidence.tsx
index 234493d010a..715fceed54c 100644
--- a/src/features/Acceptance/Report/MarkdownEvidence.tsx
+++ b/src/features/Acceptance/Report/MarkdownEvidence.tsx
@@ -20,6 +20,19 @@ import { AcceptanceDrawer } from '../AcceptanceDrawer';
*/
export const markdownTextEvidenceTypes = new Set(['markdown', 'text']);
+/**
+ * Which of those two render as prose, and which stay verbatim.
+ *
+ * Only a document that says it is markdown gets markdown rendering. A `text`
+ * artifact is usually captured command output, where `###`, `-` and `*` are
+ * literal characters the reviewer is meant to read: rendering it as markdown
+ * turned transcript sections into headings, argument lists into bullets, and
+ * reflowed the lines so column alignment β€” often the point of the capture β€”
+ * was lost. Everything that is not explicitly markdown is shown verbatim.
+ */
+export const rendersAsMarkdown = (evidence: { fileName?: string | null; type: string }): boolean =>
+ evidence.type === 'markdown' || /\.(?:md|markdown)$/i.test(evidence.fileName ?? '');
+
export const filenameFromUrl = (url: string): string => {
try {
return new URL(url).pathname.split('/').pop() || 'document';
@@ -239,55 +252,69 @@ export const resolveMarkdownEvidenceFold = (content: string, authoredTitle?: str
* card of space showing the least informative part of the document β€” and read
* as noise. Need it β†’ expand; don't β†’ one quiet line.
*/
-export const CollapsibleMarkdownEvidence = memo<{ children: string; title?: string }>(
- ({ children, title }) => {
- const { t } = useTranslation('verify');
- const [expanded, setExpanded] = useState(false);
- const { fold, foldTitle } = useMemo(
- () => resolveMarkdownEvidenceFold(children, title),
- [children, title],
- );
-
- if (!fold) {
- return (
- <Markdown fontSize={13} variant={'chat'}>
- {children}
- </Markdown>
- );
- }
+export const CollapsibleMarkdownEvidence = memo<{
+ children: string;
+ fileName?: string | null;
+ /** False renders the document verbatim β€” see `rendersAsMarkdown`. */
+ markdown?: boolean;
+ title?: string;
+}>(({ children, fileName, markdown = true, title }) => {
+ const { t } = useTranslation('verify');
+ const [expanded, setExpanded] = useState(false);
+ const { fold, foldTitle } = useMemo(
+ () => resolveMarkdownEvidenceFold(children, title),
+ [children, title],
+ );
+ const body = markdown ? (
+ <Markdown fontSize={13} headerMultiple={0.1} variant={'chat'}>
+ {children}
+ </Markdown>
+ ) : (
+ <Highlighter
+ wrap
+ language={getLanguageFromFilename(fileName)}
+ showLanguage={false}
+ variant={'borderless'}
+ >
+ {children}
+ </Highlighter>
+ );
- return (
- <Flexbox className={styles.foldCard}>
- <button
- aria-expanded={expanded}
- className={styles.foldHeader}
- title={t(expanded ? 'report.evidence.collapse' : 'report.evidence.expand')}
- type={'button'}
- onClick={() => setExpanded(!expanded)}
- >
- <Icon
- className={cx(styles.foldChevron, expanded && styles.foldChevronOpen)}
- icon={ChevronRight}
- size={14}
- />
- <span className={styles.fileCardIcon}>
- <Icon icon={FileText} size={13} />
- </span>
- <span data-fold-title className={styles.foldTitle}>
- {foldTitle}
- </span>
- </button>
- {expanded && (
- <div className={styles.foldBody}>
- <Markdown fontSize={13} headerMultiple={0.1} variant={'chat'}>
- {children}
- </Markdown>
- </div>
- )}
- </Flexbox>
+ if (!fold) {
+ return markdown ? (
+ <Markdown fontSize={13} variant={'chat'}>
+ {children}
+ </Markdown>
+ ) : (
+ body
);
- },
-);
+ }
+
+ return (
+ <Flexbox className={styles.foldCard}>
+ <button
+ aria-expanded={expanded}
+ className={styles.foldHeader}
+ title={t(expanded ? 'report.evidence.collapse' : 'report.evidence.expand')}
+ type={'button'}
+ onClick={() => setExpanded(!expanded)}
+ >
+ <Icon
+ className={cx(styles.foldChevron, expanded && styles.foldChevronOpen)}
+ icon={ChevronRight}
+ size={14}
+ />
+ <span className={styles.fileCardIcon}>
+ <Icon icon={FileText} size={13} />
+ </span>
+ <span data-fold-title className={styles.foldTitle}>
+ {foldTitle}
+ </span>
+ </button>
+ {expanded && <div className={styles.foldBody}>{body}</div>}
+ </Flexbox>
+ );
+});
CollapsibleMarkdownEvidence.displayName = 'CollapsibleMarkdownEvidence';
diff --git a/src/features/Acceptance/Report/ReportViewer.tsx b/src/features/Acceptance/Report/ReportViewer.tsx
index 2672aba7a70..c0d4c6856d1 100644
--- a/src/features/Acceptance/Report/ReportViewer.tsx
+++ b/src/features/Acceptance/Report/ReportViewer.tsx
@@ -68,6 +68,7 @@ import {
DocumentViewer,
filenameFromUrl,
markdownTextEvidenceTypes,
+ rendersAsMarkdown,
} from './MarkdownEvidence';
import { readVisualizationManifest } from './visualization';
import { VisualizationRenderer } from './VisualizationRenderer';
@@ -830,11 +831,7 @@ const EvidenceItem = memo<{
/>
) : e.fileUrl ? (
<div className={styles.evidenceDoc}>
- <DocumentViewer
- fileName={e.fileName}
- markdown={markdownTextEvidenceTypes.has(e.type)}
- url={e.fileUrl}
- />
+ <DocumentViewer fileName={e.fileName} markdown={rendersAsMarkdown(e)} url={e.fileUrl} />
</div>
) : e.content && markdownTextEvidenceTypes.has(e.type) ? (
// Same dialect as the acceptance viewer: an authored alt/description
@@ -842,6 +839,8 @@ const EvidenceItem = memo<{
// raw description, not the caption filter β€” with no fileName the label
// IS the description, and the filter would null it out.
<CollapsibleMarkdownEvidence
+ fileName={e.fileName}
+ markdown={rendersAsMarkdown(e)}
title={e.description?.trim() || e.fileName?.trim() || undefined}
>
{e.content}
diff --git a/src/features/Acceptance/Report/markdownEvidenceTitle.test.ts b/src/features/Acceptance/Report/markdownEvidenceTitle.test.ts
index 3fdc71c26b2..dc489e30d72 100644
--- a/src/features/Acceptance/Report/markdownEvidenceTitle.test.ts
+++ b/src/features/Acceptance/Report/markdownEvidenceTitle.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, it } from 'vitest';
-import { evidenceTitleFromMarkdown, resolveMarkdownEvidenceFold } from './MarkdownEvidence';
+import {
+ evidenceTitleFromMarkdown,
+ rendersAsMarkdown,
+ resolveMarkdownEvidenceFold,
+} from './MarkdownEvidence';
describe('evidenceTitleFromMarkdown β€” the collapsed row label', () => {
it('strips heading syntax so the first line reads as a sentence', () => {
@@ -99,3 +103,20 @@ it('folds short JSON payloads behind a readable type label', () => {
foldTitle: 'JSON',
});
});
+
+describe('rendersAsMarkdown β€” only a markdown document is rendered as prose', () => {
+ it('renders a captured transcript verbatim so its ### and - stay literal', () => {
+ expect(rendersAsMarkdown({ fileName: '04-confirmation.txt', type: 'text' })).toBe(false);
+ expect(rendersAsMarkdown({ fileName: 'server.log', type: 'text' })).toBe(false);
+ // No extension at all is the same case: nothing says it is markdown.
+ expect(rendersAsMarkdown({ fileName: 'transcript', type: 'text' })).toBe(false);
+ expect(rendersAsMarkdown({ type: 'text' })).toBe(false);
+ });
+
+ it('renders a markdown document as prose, by type or by extension', () => {
+ expect(rendersAsMarkdown({ fileName: 'findings.md', type: 'markdown' })).toBe(true);
+ expect(rendersAsMarkdown({ type: 'markdown' })).toBe(true);
+ // Uploaded as text but named .md β€” the name is the explicit signal.
+ expect(rendersAsMarkdown({ fileName: 'report.MARKDOWN', type: 'text' })).toBe(true);
+ });
+});
diff --git a/src/features/Acceptance/Viewer/Evidence/EvidenceList.tsx b/src/features/Acceptance/Viewer/Evidence/EvidenceList.tsx
index 19cfb05c35f..e89d5409176 100644
--- a/src/features/Acceptance/Viewer/Evidence/EvidenceList.tsx
+++ b/src/features/Acceptance/Viewer/Evidence/EvidenceList.tsx
@@ -16,6 +16,7 @@ import {
CollapsibleMarkdownEvidence,
EvidenceFileCard,
markdownTextEvidenceTypes,
+ rendersAsMarkdown,
} from '../../Report/MarkdownEvidence';
import type { AcceptanceEvidence } from '../Checks/types';
import { AnnotatedImage } from '../Evidence/Annotation';
@@ -268,7 +269,9 @@ export const EvidenceList = memo<{
// An authored alt/description becomes the fold row's title itself β€”
// the supplement below the row duplicated it one line later.
<CollapsibleMarkdownEvidence
+ fileName={item.fileName}
key={item.id}
+ markdown={rendersAsMarkdown(item)}
title={item.description?.trim() || item.fileName?.trim() || undefined}
>
{item.content}
@@ -284,10 +287,10 @@ export const EvidenceList = memo<{
if (item.fileUrl && markdownTextEvidenceTypes.has(item.type))
return (
<EvidenceFileCard
- markdown
description={item.description}
fileName={item.fileName}
key={item.id}
+ markdown={rendersAsMarkdown(item)}
url={item.fileUrl}
/>
);