fix(anatomy): R5.4 Markdown guard from a TypeScript sweep, strict drawing comparison, unwritable characters refused, indexed renderers

This commit is contained in:
bchanot committed 2026-10-23 11:51:41 +02:00
1 parent 0a79c52e62
commit 94f8b35105
14 files changed
+647 -50

No files matched your search

@@ -0,0 +1,171 @@
/**
* R5.4 freeze (final gates, 2026-10-23): what Prettier's Markdown printer does to authored text
* in the two draft reports. The port reproduces only the table alignment and refuses the text
* Prettier would rewrite; this sweep, written by the TypeScript, holds it to that: every probe
* (a special character in six positions, whitespace patterns, Markdown constructs) is placed
* in a change title, rationale and question, a cited reference and a changed label, and the
* raw and formatted CHANGELOG and REVIEW-REPORT are frozen. `MAKE_R5_ORACLES=1` writes
* crates/core/tests/oracles/r5/markdown-sweep.json.
*/
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import {
applyChangeset,
buildReportMigrationMap,
ChangesetSchema,
documentStats,
renderChangelog,
renderReviewReport,
} from '../src'
import { changeSummary } from '../src/curation/schema'
import { formatMarkdown } from '../src/format'
import { MINI_REFERENCES, miniSheet } from './fixtures/mini-sheet'
const HERE = dirname(fileURLToPath(import.meta.url))
const OUT = resolve(HERE, '../../../crates/core/tests/oracles/r5')
const MAKE = process.env.MAKE_R5_ORACLES === '1'
const LEGACY_ID_MAP = {
views: { head: 'head' },
annotations: { 'legacy-hip': 'hip', 'legacy-neck': 'neck' },
categories: {},
finding_nodes: {},
assets: {},
}
const CHARACTERS = [...'*_~\\`<>&[]!#$|+=^{}"\'%@:;?/()-.,']
function positions(c: string): string[] {
return [c, `${c}x`, `x${c}`, `a ${c} b`, `a${c}b`, `${c}${c}`]
}
const PATTERNS = [
'a b',
'a\tb',
' a',
'a ',
'a\nb',
'a\rb',
'a\n\nb',
'*important*',
'**gras**',
'a **b c** d',
'a**b**c',
'__init__ et _x',
'to_confirm',
'`code`',
'``double``',
'a\\|b',
'a|b',
'<b>gras</b>',
'[lien](https://example.org/x)',
'&amp;',
'# titre',
'1. item',
'- item',
'> citation',
'Carmalt 2013 (≠ « palpation »), 3 %, 40 °C',
'a = b; c ? d : e',
'{"fr":"x"}',
'é ü ß ø Ω 中',
]
function probes(): string[] {
return [...CHARACTERS.flatMap(positions), ...PATTERNS]
}
function changesFile(probe: string) {
return {
changes: [
{
id: 'CHG-001',
level: 'C',
kind: 'correction',
title: { fr: `Titre ${probe}`, en: 'Title' },
rationale: `Raison ${probe} fin.`,
reference_ids: [],
question: `Question ${probe} ?`,
ops: [
{
op: 'add',
target: 'document',
field: 'references',
value: {
id: 'probe-ref',
type: 'web',
citation: `Citation ${probe}`,
url: null,
doi: null,
},
},
{
op: 'cite',
target: 'finding:hip/hip-dysfunctions/mobility',
reference_ids: ['probe-ref'],
},
{
op: 'set',
target: 'finding:hip/hip-dysfunctions/mobility',
field: 'name.en',
value: `Label ${probe}`,
},
],
},
],
}
}
async function run(probe: string) {
const file = changesFile(probe)
const changeset = ChangesetSchema.parse(file)
const baseline = miniSheet()
const result = applyChangeset(baseline, MINI_REFERENCES, changeset)
const before = documentStats(baseline)
const after = documentStats(result.document)
const migration = buildReportMigrationMap({
baseline: miniSheet() as never,
final: result.document as never,
legacyIdMap: LEGACY_ID_MAP,
records: result.records,
sheet: { sheetId: 's', versionId: null, documentSha256: '0'.repeat(64) },
mainViewId: 'main',
})
const changelogRaw = renderChangelog(result, before, after, migration.stats)
const reviewRaw = renderReviewReport({
changes: changeset.changes.map(changeSummary),
records: result.records,
document: result.document,
statsBefore: before,
legacyAnomalies: [],
})
return {
probe,
changes_file: file,
changelog_raw: changelogRaw,
changelog: await formatMarkdown(changelogRaw),
review_raw: reviewRaw,
review: await formatMarkdown(reviewRaw),
}
}
describe('R5.4 Markdown sweep oracle', () => {
it('markdown-sweep.json', async () => {
const rows = []
for (const probe of probes()) rows.push(await run(probe))
const oracle = {
baseline: miniSheet(),
references: MINI_REFERENCES,
legacy_id_map: LEGACY_ID_MAP,
cases: rows,
}
const text = `${JSON.stringify(oracle)}\n`
const file = resolve(OUT, 'markdown-sweep.json')
if (MAKE) {
mkdirSync(OUT, { recursive: true })
writeFileSync(file, text)
}
expect(text).toBe(readFileSync(file, 'utf8'))
})
})