ddd
This commit is contained in:
parent
0a343ecbc5
commit
c3a6f5ff37
80 changed files with 2512 additions and 1625 deletions
|
|
@ -60,7 +60,7 @@ async function decode(blob,module=persistence){
|
|||
if(typeof CompressionStream==='function'&&typeof DecompressionStream==='function'){const compressed=await encode('gzip'),damaged=Buffer.from(compressed.bytes);damaged[Math.max(10,Math.floor(damaged.length/2))]^=0xff;let gzipRejected=false;try{await decode(new Blob([damaged]))}catch(_){gzipRejected=true}assert(gzipRejected,'Corrupt gzip archive was accepted')}
|
||||
const worker=read('field-persistence-worker.js'),moduleSource=read('field-persistence.js');
|
||||
class FakeWorker{
|
||||
constructor(){this.onmessage=null;this.onerror=null;const owner=this,context={TextEncoder,Uint8Array,Uint32Array,JSON,Error,self:{postMessage(data){queueMicrotask(()=>owner.onmessage?.({data}))}}};vm.createContext(context);vm.runInContext(worker,context);this.workerSelf=context.self}
|
||||
constructor(){this.onmessage=null;this.onerror=null;const owner=this,archiveCodec=require('../archive-codec'),context={TextEncoder,Uint8Array,Uint32Array,JSON,Error,importScripts:()=>{},self:{BendArchiveCodec:archiveCodec,postMessage(data){queueMicrotask(()=>owner.onmessage?.({data}))}}};vm.createContext(context);vm.runInContext(worker,context);this.workerSelf=context.self}
|
||||
postMessage(data){queueMicrotask(()=>{try{this.workerSelf.onmessage({data:structuredClone(data)})}catch(error){this.onerror?.({message:error.message})}})}
|
||||
terminate(){}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ async function decode(blob,module=persistence){
|
|||
const workerEncoded=await encode('identity',workerPersistence),workerDecoded=await decode(workerEncoded.blob,workerPersistence);
|
||||
assert(workerEncoded.result.worker===true&&workerDecoded.result.worker===true&&workerDecoded.seen.length===2,'Archive worker execution path did not round-trip records');
|
||||
delete global.Worker;global.BendFieldPersistence=persistence;
|
||||
assert(worker.includes('MAX_CHUNK_BYTES=1024*1024')&&worker.includes('postMessage({id,chunks,rawBytes,crc32:crc32Hex()},chunks)'),'Archive worker does not enforce transferable 1 MiB output chunks');
|
||||
assert(moduleSource.includes("new Worker('field-persistence-worker.js?v=47.77')")&&moduleSource.includes('item.byteLength>MAX_ARCHIVE_LINE_BYTES')&&moduleSource.includes('WORKER_TARGET_BYTES=1024*1024')&&moduleSource.includes('pendingLineBytes'),'Archive worker path, 1 MiB batching, or worker line limit is missing');
|
||||
assert(worker.includes("importScripts('archive-codec.js')")&&worker.includes('MAX_CHUNK_BYTES=1024*1024')&&worker.includes('postMessage({id,chunks,rawBytes,crc32:crc32Hex(crc)},chunks)'),'Archive worker does not share the codec or enforce transferable 1 MiB output chunks');
|
||||
assert(moduleSource.includes("new Worker('field-persistence-worker.js')")&&moduleSource.includes('item.byteLength>MAX_ARCHIVE_LINE_BYTES')&&moduleSource.includes('WORKER_TARGET_BYTES=1024*1024')&&moduleSource.includes('pendingLineBytes'),'Archive worker path, 1 MiB batching, or worker line limit is missing');
|
||||
console.log('Field archive round-trip and corruption checks passed');
|
||||
})().catch(error=>{console.error(error);process.exitCode=1});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue