From 21be47f56097b865b0f778d958ad9b5b6fdc54e6 Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 9 Mar 2026 11:29:52 +0800 Subject: [PATCH] test(e2e): make tgz fixture gzip header deterministic --- tests/e2e/scripts/generate-fixtures.mjs | 36 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/e2e/scripts/generate-fixtures.mjs b/tests/e2e/scripts/generate-fixtures.mjs index 848553bb..0d8b083f 100644 --- a/tests/e2e/scripts/generate-fixtures.mjs +++ b/tests/e2e/scripts/generate-fixtures.mjs @@ -38,22 +38,36 @@ const ensureArchive = (name, generator) => { }; const buildDeterministicTar = (out, gzip = false) => { - const py = String.raw`import io, tarfile + const py = String.raw`import io, tarfile, gzip from pathlib import Path out = Path(r'''${out}''') inner_path = Path(r'''${innerFile}''') data = inner_path.read_bytes() -mode = 'w:gz' if ${gzip ? 'True' : 'False'} else 'w' -with tarfile.open(out, mode=mode, format=tarfile.USTAR_FORMAT) as tf: - info = tarfile.TarInfo('inner.txt') - info.size = len(data) - info.mtime = 946684800 # 2000-01-01 00:00:00 UTC - info.uid = 0 - info.gid = 0 - info.uname = 'root' - info.gname = 'root' - tf.addfile(info, io.BytesIO(data)) +use_gzip = ${gzip ? 'True' : 'False'} + +if use_gzip: + with out.open('wb') as f: + with gzip.GzipFile(filename='', mode='wb', fileobj=f, mtime=0) as gz: + with tarfile.open(fileobj=gz, mode='w', format=tarfile.USTAR_FORMAT) as tf: + info = tarfile.TarInfo('inner.txt') + info.size = len(data) + info.mtime = 946684800 # 2000-01-01 00:00:00 UTC + info.uid = 0 + info.gid = 0 + info.uname = 'root' + info.gname = 'root' + tf.addfile(info, io.BytesIO(data)) +else: + with tarfile.open(out, mode='w', format=tarfile.USTAR_FORMAT) as tf: + info = tarfile.TarInfo('inner.txt') + info.size = len(data) + info.mtime = 946684800 # 2000-01-01 00:00:00 UTC + info.uid = 0 + info.gid = 0 + info.uname = 'root' + info.gname = 'root' + tf.addfile(info, io.BytesIO(data)) `; execFileSync('python3', ['-c', py]); };