fix(anatomy): R5.4 report guard as an allowlist (report_guard.rs), sweep of 762 probes incl. seeded random strings, NUL refused in field segments
This commit is contained in:
1 parent
077d91bdff
commit
124d954a0d
10 files changed
+246
-195
No files matched your search
@@ -4,9 +4,11 @@
|
||||
* 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
|
||||
* sha256 of the raw and formatted CHANGELOG and REVIEW-REPORT are frozen (400 of the probes
|
||||
* come from a seeded generator, so unknown classes surface on their own). `MAKE_R5_ORACLES=1` writes
|
||||
* crates/core/tests/oracles/r5/markdown-sweep.json.
|
||||
*/
|
||||
import { createHash } from 'node:crypto'
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
@@ -24,6 +26,10 @@ import { formatMarkdown } from '../src/format'
|
||||
import { MINI_REFERENCES, miniSheet } from './fixtures/mini-sheet'
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
function sha256(text: string): string {
|
||||
return createHash('sha256').update(text, 'utf8').digest('hex')
|
||||
}
|
||||
const OUT = resolve(HERE, '../../../crates/core/tests/oracles/r5')
|
||||
const MAKE = process.env.MAKE_R5_ORACLES === '1'
|
||||
|
||||
@@ -35,7 +41,7 @@ const LEGACY_ID_MAP = {
|
||||
assets: {},
|
||||
}
|
||||
|
||||
const CHARACTERS = [...'*_~\\`<>&[]!#$|+=^{}"\'%@:;?/()-.,']
|
||||
const CHARACTERS = [...'*_~\\`<>&[]!#$|+=^{}"\'%@:;?/()-.,’‘“”×≤≥±→–—…«»°≠']
|
||||
|
||||
function positions(c: string): string[] {
|
||||
return [c, `${c}x`, `x${c}`, `a ${c} b`, `a${c}b`, `${c}${c}`]
|
||||
@@ -88,6 +94,25 @@ const PATTERNS = [
|
||||
'한_한',
|
||||
'é_é',
|
||||
'[a]( https://x.org )',
|
||||
'**a****b**',
|
||||
'\\**a**',
|
||||
'x_**a**',
|
||||
'**a**_x',
|
||||
'** **',
|
||||
'**Total**',
|
||||
'(**a**)',
|
||||
'a **b** c',
|
||||
'Voir_https://example.org/x',
|
||||
'Voir_www.example.org',
|
||||
'https://x.org/**a **',
|
||||
'https://x.org/a_b',
|
||||
'Lien https://x.org/a_b fin',
|
||||
'a\u00a0b',
|
||||
'a\u2003b',
|
||||
'a\u3000b',
|
||||
'中文',
|
||||
'مرحبا',
|
||||
'e\u0301',
|
||||
'&',
|
||||
'# titre',
|
||||
'1. item',
|
||||
@@ -99,8 +124,34 @@ const PATTERNS = [
|
||||
'é ü ß ø Ω 中',
|
||||
]
|
||||
|
||||
/** A seeded generator (a 32-bit LCG): the random probes are the same on every run. */
|
||||
function randomProbes(count: number): string[] {
|
||||
const alphabet = [
|
||||
...'ab_*\\`[]()<>&#!~ :/.|"é中',
|
||||
'https://',
|
||||
'www.',
|
||||
'**',
|
||||
'\n',
|
||||
'\u00a0',
|
||||
]
|
||||
let state = 20261023
|
||||
const next = () => {
|
||||
state = (Math.imul(state, 1664525) + 1013904223) >>> 0
|
||||
return state
|
||||
}
|
||||
const out: string[] = []
|
||||
for (let i = 0; i < count; i += 1) {
|
||||
const length = 2 + (next() % 10)
|
||||
let text = ''
|
||||
for (let j = 0; j < length; j += 1)
|
||||
text += alphabet[next() % alphabet.length]
|
||||
out.push(text)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function probes(): string[] {
|
||||
return [...CHARACTERS.flatMap(positions), ...PATTERNS]
|
||||
return [...CHARACTERS.flatMap(positions), ...PATTERNS, ...randomProbes(400)]
|
||||
}
|
||||
|
||||
function changesFile(probe: string) {
|
||||
@@ -138,6 +189,12 @@ function changesFile(probe: string) {
|
||||
field: 'name.en',
|
||||
value: `Label ${probe}`,
|
||||
},
|
||||
{
|
||||
op: 'set',
|
||||
target: 'finding:hip/hip-dysfunctions/mobility/flexion',
|
||||
field: 'name.fr',
|
||||
value: probe,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -170,10 +227,10 @@ async function run(probe: string) {
|
||||
return {
|
||||
probe,
|
||||
changes_file: file,
|
||||
changelog_raw: changelogRaw,
|
||||
changelog: await formatMarkdown(changelogRaw),
|
||||
review_raw: reviewRaw,
|
||||
review: await formatMarkdown(reviewRaw),
|
||||
changelog_raw_sha256: sha256(changelogRaw),
|
||||
changelog_sha256: sha256(await formatMarkdown(changelogRaw)),
|
||||
review_raw_sha256: sha256(reviewRaw),
|
||||
review_sha256: sha256(await formatMarkdown(reviewRaw)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,5 +251,5 @@ describe('R5.4 Markdown sweep oracle', () => {
|
||||
writeFileSync(file, text)
|
||||
}
|
||||
expect(text).toBe(readFileSync(file, 'utf8'))
|
||||
})
|
||||
}, 120_000)
|
||||
})
|
||||
Reference in new issue
Block a user