AtlatestRepositorysigil-quic

sigil-quic / tree / scriptsinject-early-faults.mjs

1// Remote-only sensitivity mutations for early protected packet tests.
2import { readFileSync, writeFileSync } from 'node:fs';
3
4const [kind, input, output] = process.argv.slice(2);
5if (!['connection', 'frame'].includes(kind) || !input || !output || input === output) {
6 throw new Error('Usage: inject-early-faults.mjs connection|frame INPUT OUTPUT');
7}
8let source = readFileSync(input, 'utf8');
9if (source.includes('TEST ONLY')) throw new Error('Expected canonical source');
10function 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);
14if (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)))");
25writeFileSync(output, ';;; TEST ONLY: early-packet guards weakened for sensitivity.\n' + source);