fix(pdf,tests): report:compare escapes control characters, prints names and free text only with --full, stats before read, missing file as a per-file failure; inferRegionCode regression test; import.ts JSDoc reattached
This commit is contained in:
1 parent
dc78a00835
commit
b1b3e4927e
6 files changed
+257
-72
No files matched your search
@@ -21,7 +21,7 @@ import {
|
||||
import { loadTestSheet, minimalReport } from '../helpers/sheet'
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url))
|
||||
const OPTS = { locale: 'fr' as const, identity: false }
|
||||
const OPTS = { locale: 'fr' as const, full: false }
|
||||
|
||||
let sheet: SheetIndex
|
||||
|
||||
@@ -31,10 +31,10 @@ function minimalV2(): ReportV2 {
|
||||
) as ReportV2
|
||||
}
|
||||
|
||||
function compareRaw(raw: unknown, identity = false) {
|
||||
function compareRaw(raw: unknown, full = false) {
|
||||
const outcome = readReportDocument(raw, sheet.sheet.migrationMap)
|
||||
const migrated = (raw as { version: number }).version !== 3
|
||||
return compareReport(raw, outcome, migrated, sheet, { ...OPTS, identity })
|
||||
return compareReport(raw, outcome, migrated, sheet, { ...OPTS, full })
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -70,6 +70,7 @@ describe('compareReport on the frozen v2 archive PDF', () => {
|
||||
'full.pdf · v2→v3 · 3 obs · zones 5/0 unresolved · findings 4/0 unresolved',
|
||||
)
|
||||
expect(lines.join('\n')).not.toContain('practitioner')
|
||||
expect(lines.join('\n')).not.toContain('Dupont')
|
||||
expect(renderComparison('x', compareRaw(raw, true)).join('\n')).toContain(
|
||||
'practitioner "Dr. Claire Dupont"',
|
||||
)
|
||||
@@ -192,12 +193,103 @@ describe('diff and arguments', () => {
|
||||
expect(parseArgs(['a.pdf', '--summary', 'dir', '--locale', 'en'])).toEqual({
|
||||
files: ['a.pdf', 'dir'],
|
||||
locale: 'en',
|
||||
identity: false,
|
||||
full: false,
|
||||
summary: true,
|
||||
diff: false,
|
||||
})
|
||||
expect(parseArgs(['--identity', '--diff', 'a', 'b']).identity).toBe(true)
|
||||
expect(parseArgs(['--full', '--diff', 'a', 'b']).full).toBe(true)
|
||||
expect(() => parseArgs(['--identity'])).toThrow('unknown option')
|
||||
expect(() => parseArgs(['--locale', 'de'])).toThrow('fr or en')
|
||||
expect(() => parseArgs(['--json'])).toThrow('unknown option')
|
||||
})
|
||||
})
|
||||
|
||||
describe('terminal safety and privacy', () => {
|
||||
const ESC = '\u001b[2K'
|
||||
|
||||
it('escapes control characters in every untrusted string', () => {
|
||||
const report = minimalReport(sheet, {
|
||||
observations: [
|
||||
{
|
||||
id: `o${ESC}\n1`,
|
||||
zones: [],
|
||||
findings: [
|
||||
{
|
||||
findingZoneId: 'hip',
|
||||
path: ['hip-dysfunctions', `x${ESC}\ny`],
|
||||
labelFrSnapshot: `L${ESC}`,
|
||||
labelEnSnapshot: 'L',
|
||||
unresolved: true,
|
||||
},
|
||||
],
|
||||
freeTextFindings: [`t${ESC}\nu`],
|
||||
comment: `c${ESC}\nd`,
|
||||
},
|
||||
],
|
||||
})
|
||||
const lines = renderComparison('x', compareRaw(report, true))
|
||||
const text = lines.join('\n')
|
||||
expect(text).not.toContain('\u001b')
|
||||
expect(lines.every((l) => !l.includes('\n'))).toBe(true)
|
||||
expect(text).toContain('\\u001b')
|
||||
expect(text).toContain('\\u000a')
|
||||
expect(text).toContain('[o\\u001b[2K\\u000a1]')
|
||||
})
|
||||
|
||||
it('does not throw on prototype-chain names used as legacy ids', () => {
|
||||
const v2: ReportV2 = {
|
||||
...minimalV2(),
|
||||
observations: [
|
||||
{
|
||||
id: 'o',
|
||||
zones: [{ boneId: '__proto__' }, { boneId: 'constructor' }],
|
||||
findings: [
|
||||
{
|
||||
zoneId: '__proto__',
|
||||
path: ['constructor'],
|
||||
labelFrSnapshot: 'X',
|
||||
labelEnSnapshot: 'X',
|
||||
},
|
||||
],
|
||||
freeTextFindings: [],
|
||||
comment: '',
|
||||
},
|
||||
],
|
||||
}
|
||||
const text = renderComparison('p.pdf', compareRaw(v2)).join('\n')
|
||||
expect(text).toContain(`__proto__ ${UNRESOLVED}`)
|
||||
expect(text).toContain(`constructor ${UNRESOLVED}`)
|
||||
expect(text).toContain(`__proto__/constructor "X" ${UNRESOLVED}`)
|
||||
})
|
||||
|
||||
it('hides names and free texts by default, shows them with --full', () => {
|
||||
const report = minimalReport(sheet, {
|
||||
conclusion: 'SECRET-CONCLUSION',
|
||||
recommendations: 'SECRET-RECO',
|
||||
nextAppointment: { kind: 'period', text: 'SECRET-WHEN' },
|
||||
observations: [
|
||||
{
|
||||
id: 'o',
|
||||
zones: [],
|
||||
findings: [],
|
||||
freeTextFindings: ['SECRET-TEXT'],
|
||||
comment: 'SECRET-COMMENT',
|
||||
},
|
||||
],
|
||||
})
|
||||
const hidden = renderComparison('x', compareRaw(report)).join('\n')
|
||||
expect(hidden).not.toContain('SECRET')
|
||||
expect(hidden).toContain('text (1 entries)')
|
||||
expect(hidden).toContain('comment (present)')
|
||||
expect(hidden).toContain('conclusion (present)')
|
||||
expect(hidden).toContain('recommendations (present)')
|
||||
expect(hidden).toContain('next appointment (period)')
|
||||
const shown = renderComparison('x', compareRaw(report, true)).join('\n')
|
||||
for (const word of ['TEXT', 'COMMENT', 'CONCLUSION', 'RECO', 'WHEN']) {
|
||||
expect(shown).toContain(`SECRET-${word}`)
|
||||
}
|
||||
expect(compareRaw(report).normalized.join('\n')).toContain(
|
||||
'SECRET-CONCLUSION',
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user