From c18ea225213ceaa1f0078884e03115abc86ab488 Mon Sep 17 00:00:00 2001 From: jonwiggins Date: Thu, 19 Nov 2026 19:54:20 -0700 Subject: [PATCH 1/2] fix: preserve original marks in page previews (PRO-7986) --- e2e/upload.spec.ts | 44 ++++++-- src/components/TryIt.tsx | 4 +- src/components/results/FindingCard.tsx | 143 ++++++++++++------------- src/components/results/ResultsView.tsx | 5 +- src/lib/analyzer/client.ts | 11 +- 5 files changed, 114 insertions(+), 93 deletions(-) diff --git a/e2e/upload.spec.ts b/e2e/upload.spec.ts index aca1fe7..936c9a7 100644 --- a/e2e/upload.spec.ts +++ b/e2e/upload.spec.ts @@ -72,9 +72,7 @@ test.describe('upload flow detects and alerts', () => { await expect(page.getByText('Redaction grade')).toBeVisible() // Recovered text is masked until the user clicks reveal. - await page - .getByRole('button', {name: /reveal what was under the box/i}) - .click() + await page.getByRole('button', {name: 'Reveal text for area 1'}).click() await expect(page.getByText('Jordan Hayes')).toBeVisible() }) @@ -108,12 +106,24 @@ test.describe('upload flow detects and alerts', () => { ).toHaveCount(2) await expect(first.getByText('4 findings', {exact: true})).toBeVisible() await expect(second.getByText('1 finding', {exact: true})).toBeVisible() + await expect( + first.getByRole('heading', { + name: 'Text is still under the box', + exact: true, + }) + ).toHaveCount(1) + await expect( + first.getByText( + 'A black box was drawn over this text, but the text itself was never removed. It stays selectable, searchable, and copy-pasteable.', + {exact: true} + ) + ).toHaveCount(1) await expect( first.getByText('This redaction leaks its length') ).toBeVisible() await expect(first.getByText('Northwind', {exact: true})).toHaveCount(0) const reveal = first.getByRole('button', { - name: 'Reveal what was under the box', + name: /^Reveal text for area/, }) await expect(reveal).toHaveCount(3) // Revealing one passage must not reveal the other passages. @@ -125,14 +135,32 @@ test.describe('upload flow detects and alerts', () => { await expect( first.getByText('Project Cardinal', {exact: true}) ).toBeVisible() - await first - .getByRole('button', {name: 'Show all findings on this page'}) - .click() + await first.getByRole('button', {name: 'Show original page'}).click() await expect( first.getByRole('img', {name: 'Page 1', exact: true}) ).toHaveCount(1) await expect(first.locator('[aria-label^="Finding "]')).toHaveCount(4) - await expect(first.getByText(/Annotation marks are hidden/)).toBeVisible() + // The synthetic square annotation covers [72, 180, 164.5, 195] on a + // 612x792 page. Its interior must remain black even after text is revealed. + const blackFraction = await first + .getByRole('img', {name: 'Page 1', exact: true}) + .evaluate(async (element) => { + const image = element as HTMLImageElement + await image.decode() + const canvas = document.createElement('canvas') + canvas.width = 612 + canvas.height = 792 + const context = canvas.getContext('2d')! + context.drawImage(image, 0, 0, 612, 792) + const pixels = context.getImageData(80, 185, 70, 5).data + let black = 0 + for (let i = 0; i < pixels.length; i += 4) { + if (pixels[i]! < 40 && pixels[i + 1]! < 40 && pixels[i + 2]! < 40) + black++ + } + return black / (pixels.length / 4) + }) + expect(blackFraction).toBeGreaterThan(0.98) await expect( second.getByRole('img', {name: 'Page 2', exact: true}) ).toHaveCount(0) diff --git a/src/components/TryIt.tsx b/src/components/TryIt.tsx index 8b65055..a07fae0 100644 --- a/src/components/TryIt.tsx +++ b/src/components/TryIt.tsx @@ -81,9 +81,9 @@ export function TryIt() { }, []) const renderPage = useCallback( - (page: number, opts?: {revealAnnotations?: boolean}) => + (page: number) => analyzerRef.current - ? analyzerRef.current.renderPage(page, opts) + ? analyzerRef.current.renderPage(page) : Promise.reject(new Error('No document')), [] ) diff --git a/src/components/results/FindingCard.tsx b/src/components/results/FindingCard.tsx index a061933..03c47f9 100644 --- a/src/components/results/FindingCard.tsx +++ b/src/components/results/FindingCard.tsx @@ -3,7 +3,6 @@ import {useState} from 'react' import {FiEye, FiEyeOff, FiImage, FiAlertTriangle} from 'react-icons/fi' import type {Finding} from '@/lib/analyzer/types' -import {CHECK_META} from '@/lib/checkMeta' import {cn} from '@/lib/cn' import {WordSizeGuess} from './WordSizeGuess' @@ -35,30 +34,31 @@ export function FindingCard({ }: { findings: Finding[] docTokens: string[] - onRenderPage?: ( - page: number, - opts?: {revealAnnotations?: boolean} - ) => Promise + onRenderPage?: (page: number) => Promise }) { const page = findings[0]!.page + const explanations = [ + ...new Map( + findings.map((finding) => [ + JSON.stringify([ + finding.check, + finding.severity, + finding.title, + finding.detail, + ]), + finding, + ]) + ).values(), + ] const [render, setRender] = useState(null) const [rendering, setRendering] = useState(false) const [renderError, setRenderError] = useState(false) - // Removing annotations exposes their contents; drawn covers remain in place. - const hasAnnotationCover = findings.some((finding) => - ['redact-annot', 'square-annot', 'highlight-annot'].includes( - finding.coverKind - ) - ) - const handleViewInDoc = async () => { if (!onRenderPage || page < 1 || render || rendering) return setRendering(true) setRenderError(false) try { - setRender( - await onRenderPage(page, {revealAnnotations: hasAnnotationCover}) - ) + setRender(await onRenderPage(page)) } catch { setRenderError(true) } finally { @@ -79,17 +79,26 @@ export function FindingCard({ -
    - {findings.map((finding, index) => ( -
  1. - -
  2. +
    + {explanations.map((finding) => ( +
    +
    +

    {finding.title}

    + + {SEVERITY_STYLE[finding.severity].label} + +
    +

    + {finding.detail} +

    +
    ))} -
+ {onRenderPage && page > 0 && findings.some((f) => f.bbox) && (
@@ -101,9 +110,7 @@ export function FindingCard({ className="inline-flex items-center gap-1.5 text-xs font-medium text-brand-blue hover:underline disabled:opacity-50" > - {rendering - ? 'Rendering page…' - : 'Show all findings on this page'} + {rendering ? 'Rendering page…' : 'Show original page'} )} {renderError && ( @@ -114,12 +121,9 @@ export function FindingCard({ )} {render && ( <> - {hasAnnotationCover && ( -

- Annotation marks are hidden in this preview to show the - content underneath. -

- )} +

+ Original page. Numbered outlines show the affected areas. +

{/* eslint-disable-next-line @next/next/no-img-element */} )} + +
    + {findings.map((finding, index) => ( +
  1. + +
  2. + ))} +
) @@ -169,60 +185,43 @@ function FindingDetail({ number: number docTokens: string[] }) { - const meta = CHECK_META[finding.check] - const sev = SEVERITY_STYLE[finding.severity] const [revealed, setRevealed] = useState(false) const revealText = finding.recovered?.text return ( <> -
-
- - {number} - -
-

{finding.title}

-

- {meta.short} -

-
-
- - {sev.label} - -
-

- {finding.detail} -

- {revealText && ( -
+
+
Area {number}
+ {revealText && ( -
- {revealed ? revealText : '•••••••••••••••••••'} -
+ )} +
+ {revealText ? ( +
+ {revealed ? revealText : '•••••••••••••••••••'}
+ ) : ( +

+ No readable text recovered. +

)} {finding.width && ( diff --git a/src/components/results/ResultsView.tsx b/src/components/results/ResultsView.tsx index 0a329bd..3aa2e85 100644 --- a/src/components/results/ResultsView.tsx +++ b/src/components/results/ResultsView.tsx @@ -19,10 +19,7 @@ export function ResultsView({ }: { result: AnalysisResult onReset: () => void - onRenderPage?: ( - page: number, - opts?: {revealAnnotations?: boolean} - ) => Promise + onRenderPage?: (page: number) => Promise }) { const {summary} = result const meta = GRADE_META[summary.grade] diff --git a/src/lib/analyzer/client.ts b/src/lib/analyzer/client.ts index c789a4e..ab1d906 100644 --- a/src/lib/analyzer/client.ts +++ b/src/lib/analyzer/client.ts @@ -181,13 +181,12 @@ export class PdfAnalyzer { } /** - * Render one page to a PNG data URL for the results view. `revealAnnotations` - * disables annotation rendering, so sticky-note redactions vanish and the - * text they were covering becomes visible — the "before/after" proof. + * Render the original page, including its annotation marks. Recovered text + * is shown separately in the results view, never by altering this preview. */ async renderPage( pageNum: number, - opts: {scale?: number; revealAnnotations?: boolean} = {} + opts: {scale?: number} = {} ): Promise<{dataUrl: string; pageWidth: number; pageHeight: number}> { if (!this.doc) throw new AnalyzerError('unknown', 'No document open.') const pdfjs = await getPdfjs() @@ -212,9 +211,7 @@ export class PdfAnalyzer { await page.render({ canvasContext: ctx, viewport, - annotationMode: opts.revealAnnotations - ? pdfjs.AnnotationMode.DISABLE - : pdfjs.AnnotationMode.ENABLE, + annotationMode: pdfjs.AnnotationMode.ENABLE, }).promise const dataUrl = canvas.toDataURL('image/png') page.cleanup() From 869e22e151d165e8dbfdcad0269ca706ecf447da Mon Sep 17 00:00:00 2001 From: jonwiggins Date: Thu, 19 Nov 2026 19:55:57 -0700 Subject: [PATCH 2/2] fix: link page explanations to numbered areas (PRO-7986) --- e2e/upload.spec.ts | 1 + src/components/results/FindingCard.tsx | 30 ++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/e2e/upload.spec.ts b/e2e/upload.spec.ts index 936c9a7..2353c07 100644 --- a/e2e/upload.spec.ts +++ b/e2e/upload.spec.ts @@ -106,6 +106,7 @@ test.describe('upload flow detects and alerts', () => { ).toHaveCount(2) await expect(first.getByText('4 findings', {exact: true})).toBeVisible() await expect(second.getByText('1 finding', {exact: true})).toBeVisible() + await expect(first.getByText('Areas 1, 2', {exact: true})).toBeVisible() await expect( first.getByRole('heading', { name: 'Text is still under the box', diff --git a/src/components/results/FindingCard.tsx b/src/components/results/FindingCard.tsx index 03c47f9..a800548 100644 --- a/src/components/results/FindingCard.tsx +++ b/src/components/results/FindingCard.tsx @@ -37,19 +37,18 @@ export function FindingCard({ onRenderPage?: (page: number) => Promise }) { const page = findings[0]!.page - const explanations = [ - ...new Map( - findings.map((finding) => [ - JSON.stringify([ - finding.check, - finding.severity, - finding.title, - finding.detail, - ]), - finding, - ]) - ).values(), - ] + const explanations = new Map() + findings.forEach((finding, index) => { + const key = JSON.stringify([ + finding.check, + finding.severity, + finding.title, + finding.detail, + ]) + const explanation = explanations.get(key) + if (explanation) explanation.areas.push(index + 1) + else explanations.set(key, {finding, areas: [index + 1]}) + }) const [render, setRender] = useState(null) const [rendering, setRendering] = useState(false) const [renderError, setRenderError] = useState(false) @@ -80,7 +79,7 @@ export function FindingCard({
- {explanations.map((finding) => ( + {[...explanations.values()].map(({finding, areas}) => (

{finding.title}

@@ -93,6 +92,9 @@ export function FindingCard({ {SEVERITY_STYLE[finding.severity].label}
+

+ {areas.length === 1 ? 'Area' : 'Areas'} {areas.join(', ')} +

{finding.detail}