docs(tests): clarify entry migration and renderer contract coverage

This commit is contained in:
2026-11-12 17:41:32 +08:00
parent b768c2d6bf
commit ea3df9877d
4 changed files with 7 additions and 0 deletions
@@ -8,6 +8,7 @@ import {digestWorkerSource,nativeDigestByteLimit} from '../../src/lib/canvas-run
// 空输入、Unicode 和二进制分别比较原生/流式结果,确认预算内原生路径只调用一次正确的 SHA-256 算法。
test('native Worker hashing and streaming fallback produce identical SHA256 for empty, UTF8 and binary sources',async()=>{
for(const bytes of [new Blob(),new Blob(['中文 😀']),new Blob([new Uint8Array([0,255,128,10])])]){
// 注入的 native 只计数并委托 Node WebCrypto;这里执行 Worker 的算法函数,没有启动真实浏览器 Worker。
let calls=0;const native={digest(algorithm,input){calls++;assert.equal(algorithm,'SHA-256');assert.equal(input.byteLength,bytes.size);return crypto.subtle.digest(algorithm,input);}};
assert.equal(await digestWorkerSource(bytes,native),await digestWorkerSource(bytes,null));assert.equal(calls,1);
}
@@ -28,5 +29,6 @@ test('inputs above the native allocation budget use bounded chunks and never req
// 伪 Blob 报告大尺寸,禁止整块 arrayBuffer,只允许 slice 返回有限大小的零字节块并记录峰值。
class ChunkOnly extends Blob{get size(){return size;}arrayBuffer(){throw Error('unbounded read');}slice(start=0,end=size){const count=Math.max(0,Math.min(size,end)-start);largest=Math.max(largest,count);return new Blob([new Uint8Array(count)]);}}
for(let cursor=0;cursor<size;cursor+=1024*1024)hash.update(new Uint8Array(Math.min(1024*1024,size-cursor)));
// 逻辑大 Blob 按需生成零字节切片,峰值只统计单次 slice 大小,不代表整个进程的内存上界。
const digest=await digestWorkerSource(new ChunkOnly(),{digest(){throw Error('native budget exceeded');}});assert.equal(digest,hash.digest('hex'));assert.ok(largest<=1024*1024);
});