15 lines
1.7 KiB
JavaScript
15 lines
1.7 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { createHash, randomUUID } from 'node:crypto';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { archiveWindowsDirectory } from '../scripts/release-archive.mjs';
|
|
const root = path.resolve('.qa/model-entry-k-longpath-' + randomUUID()), source = path.join(root, 'source'); fs.mkdirSync(source, { recursive: true });
|
|
const relative = path.join('owned-long-path-segment'.repeat(5), 'owned-evidence-segment'.repeat(5), 'owned.txt');
|
|
const file = path.join(source, relative), content = Buffer.from('owned-long-path-archive\n'); fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content);
|
|
const destination = path.join(root, 'probe.zip'); archiveWindowsDirectory(source, destination);
|
|
const script = 'import sys,zipfile,hashlib,json\nwith zipfile.ZipFile(sys.argv[1]) as z:\n assert z.testzip() is None\n names=z.namelist()\n assert names==[sys.argv[2]]\n print(json.dumps({"files":names,"sha256":hashlib.sha256(z.read(names[0])).hexdigest()}))';
|
|
const proof = JSON.parse(execFileSync(path.resolve('.qa/python-qa-1.7.0/Scripts/python.exe'), ['-I','-c',script,destination,'source/' + relative.replaceAll('\\','/')], { encoding: 'utf8', windowsHide: true }));
|
|
assert.equal(proof.sha256, createHash('sha256').update(content).digest('hex')); assert.throws(() => archiveWindowsDirectory(source, destination), /already exists/);
|
|
const result = { success: true, root, fileCharacters: file.length, proof, existingArchiveRejected: true, realModelRequests: 0 }; fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify(result,null,2)+'\n'); console.log(JSON.stringify(result));
|