AtlatestRepositorysigil-quic
sigil-quic / tree / scriptsinject-early-faults.mjs
1
// Remote-only sensitivity mutations for early protected packet tests.2
import { readFileSync, writeFileSync } from 'node:fs';4
const [kind, input, output] = process.argv.slice(2);5
if (!['connection', 'frame'].includes(kind) || !input || !output || input === output) {6
throw new Error('Usage: inject-early-faults.mjs connection|frame INPUT OUTPUT');7
}8
let source = readFileSync(input, 'utf8');9
if (source.includes('TEST ONLY')) throw new Error('Expected canonical source');10
function replaceOnce(before, after) {11
if (source.split(before).length !== 2) throw new Error('Expected one canonical early-packet guard');12
source = source.replace(before, () => after);13
}14
if (kind === 'connection') {15
replaceOnce(` (unless (quic-complete? connection)16
(raise-quic-error 10 30 "QUIC HANDSHAKE_DONE before client Finished was sent"))`, ' #t');17
replaceOnce('(< (length (connection-level-deferred state)) 16)',18
'(< (length (connection-level-deferred state)) 32)');19
replaceOnce('(<= (+ (connection-level-deferred-bytes state) size) 65536)',20
'(<= (+ (connection-level-deferred-bytes state) size) 131072)');21
} else {22
replaceOnce("(when (and (eq? sender 'client) (memv type '(7 30)))",23
"(when (and (eq? sender 'client) (memv type '(7)))");24
}25
writeFileSync(output, ';;; TEST ONLY: early-packet guards weakened for sensitivity.\n' + source);