AtlatestRepositorysigil-http3
sigil-http3 / tree / scriptsgenerate-spike-tests.mjs
1
// Linux direct native fixture, using the original test bodies verbatim.2
import { createHash } from 'node:crypto';3
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';4
import { resolve } from 'node:path';6
const files = ['frame', 'qpack', 'streams', 'control', 'request', 'connection',7
'webtransport-wire', 'webtransport-session', 'webtransport-router'].map(name => `test/test-${name}.sgl`);8
files.push(...['profile', 'echo', 'echo-integration', 'observations'].map(name => `tools/interop/test/test-${name}.sgl`));9
const traceTests = process.env.HTTP3_TRACE_TESTS === '1';10
if (traceTests) files.push('.deps/sigil-quic/test/test-idle-timeout.sgl', '.deps/sigil-quic/test/test-network-receive.sgl');11
const imports = new Set(['(sigil io)', '(sigil process)']);12
const manifest = [];13
let total = 0;14
const bodies = files.map(file => {15
const text = readFileSync(file, 'utf8');16
const boundary = text.indexOf('\n\n');17
if (!text.startsWith('(import ') || boundary < 0) throw new Error('Unexpected test header: ' + file);18
const header = text.slice(0, boundary);19
for (const match of header.matchAll(/\(sigil [a-z0-9 -]+\)/g)) imports.add(match[0]);20
const body = text.slice(boundary + 2).trimEnd();21
const count = [...body.matchAll(/\(test\s+"/g)].length;22
total += count;23
manifest.push({ file, tests: count, sha256: createHash('sha256').update(text).digest('hex') });24
return body;25
});26
if ((!traceTests && total !== 123) || (traceTests && manifest.slice(0, 13).reduce((sum, file) => sum + file.tests, 0) !== 123))27
throw new Error('Expected all 123 unchanged HTTP3 cases plus selected trace regressions');28
mkdirSync('build/spike-tests/src/sigil/http3/spike', { recursive: true });29
writeFileSync('build/spike-echo/test-sources.json', JSON.stringify(manifest, null, 2) + '\n');30
writeFileSync('build/spike-tests/src/sigil/http3/spike/checks.sgl', `(define-library (sigil http3 spike checks)31
(import ${[...imports].join('\n ')})32
(export main)33
(begin34
${bodies.map(body => body.split('\n').map(line => ' ' + line).join('\n')).join('\n\n')}36
(define (main . arguments)37
(let ((summary (run-tests-filtered (lambda (descriptor) #t))))38
(for-each39
(lambda (result)40
(unless (test-result-passed? result)41
(println "SPIKE-FAIL ~a: ~a" (test-result-name result) (test-result-message result))))42
(test-summary-results summary))43
(println "SPIKE-CHECKS total=~a passed=~a failed=~a"44
(test-summary-total summary) (test-summary-passed summary) (test-summary-failed summary))45
(exit (if (and (= (test-summary-total summary) ${total}) (= (test-summary-failed summary) 0)) 0 1))))))46
`);47
writeFileSync('build/spike-tests/package.sgl', `(package48
name: "sigil-http3-spike-checks"49
version: "0.1.0"50
sigil: "0.22"51
entry: '(sigil http3 spike checks)52
dependencies: (list53
(from-path dir: "../.." name: "sigil-http3")54
(from-path dir: "../../tools/interop" name: "sigil-http3-interop")55
(from-path dir: "../../.deps/sigil-quic" name: "sigil-quic")56
(from-git url: "codeberg:sigil/sigil-crypto" version: "^0.18.1")57
(from-git url: "codeberg:sigil/sigil" package: "sigil-test" version: "^0.22")58
(from-git url: "codeberg:sigil/sigil" package: "sigil-lib" version: "^0.22")59
(from-git url: "codeberg:sigil/sigil" package: "sigil-stdlib" version: "^0.22"))60
configs: (list61
(config name: 'native backend: 'native debug?: #f optimize: 262
bundle?: #t output-dir: "build/native"))63
bundle-name: "http3-spike-checks")64
`);65
console.log('RESULT generated-native-checks=' + total + ' sourceFiles=' + manifest.length);