docs(tests): explain streaming import cursors and read-proof lifecycle

This commit is contained in:
2026-11-12 17:25:23 +08:00
parent 225170b024
commit 7ed36b1ae0
7 changed files with 15 additions and 2 deletions
+2 -1
View File
@@ -5,7 +5,8 @@ import {test} from 'node:test';
import assert from 'node:assert/strict';
import {importSourceDigest} from '../../src/lib/canvas-runtime/import-integrity.ts';
import {createImportJob,validateImportJob} from '../../src/lib/canvas-runtime/imports.ts';
// 标准 abc 向量和不同输入区分完整源摘要;预先取消及异步读取返回前取消都拒绝,不接受迟到结果。
// 标准 abc 向量和不同输入区分完整源摘要;预先取消及调用后立即取消都必须拒绝。
// 下方整 Blob gate 不拦截当前的 slice 读取,不能用它证明读取被挂起;真正挂起块的取消见 sha256.test.mjs。
test('source SHA256 binds complete bytes and cancellation fences both sides of asynchronous reading',async()=>{
assert.equal(await importSourceDigest(new Blob(['abc'])),'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad');assert.notEqual(await importSourceDigest(new Blob(['abc'])),await importSourceDigest(new Blob(['abd'])));
const controller=new AbortController();controller.abort();await assert.rejects(importSourceDigest(new Blob(['abc']),controller.signal),/import_aborted/);let release;const gate=new Promise(resolve=>{release=resolve;}),later=new AbortController(),bytes=new class extends Blob{/* 此替身只覆写整 Blob 的 arrayBuffer;当前摘要走 slice().arrayBuffer(),故 gate 不拦截分块读取。本例断言调用后取消的拒绝,读块挂起场景另由 sha256.test.mjs 覆盖。 */ async arrayBuffer(){await gate;return super.arrayBuffer();}}(['abc']),result=importSourceDigest(bytes,later.signal);later.abort();release();await assert.rejects(result,/import_aborted/);