fix: CI Node 18/20 下 aria-crypto 失败 — SubtleCrypto 跨 realm ArrayBuffer 兼容
CI / test (18.x) (push) Successful in 9m58s
CI / test (20.x) (push) Successful in 9m58s
CI / test (22.x) (push) Successful in 9m58s
CI / test (24.x) (push) Successful in 9m54s

- crypto.ts encryptPage/decryptPage 改传 TypedArray 视图(ArrayBuffer.isView 检查跨 realm 可靠)
- jest.setup.js structuredClone polyfill 用跨 realm toString 标签检查
  (修复 fake-indexeddb 存储 ArrayBuffer 被 JSON 破坏成 {} 的问题)
- 新增 SSTable 加密真实路径测试(加密落盘→重载解密, 8 个测试)
- aria/v025 固定 db 名改随机(fake-indexeddb 真实持久化后防表残留冲突)
- Node 18/20/22/24 全矩阵 837 测试通过
This commit is contained in:
thzxx
2026-08-08 11:07:35 +08:00
parent d544501e1c
commit fda3f1ad34
12 changed files with 1369 additions and 1306 deletions
+46
View File
@@ -4,6 +4,7 @@
*
* v0.2.6 补强:此前仅验证实例化,现在验证真实的加解密往返一致性。
*/
import 'fake-indexeddb/auto';
import {
CryptoManager,
initCrypto,
@@ -109,3 +110,48 @@ describe('AriaEngine — CryptoManager', () => {
cm.close();
});
});
// ===================================================================
// 真实存储路径:SSTable 加密 → 持久化 → 重载解密(v0.3.2 CI 修复)
// ===================================================================
describe('AriaEngine — SSTable 加密存储真实路径', () => {
test('加密落盘后重载可完整解密', async () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { AriaEngine } = require('../../src/engine/aria/index');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createSchema } = require('../../src/table/schema');
const dbName = `enc-store-${Date.now()}`;
await initCrypto('engine-store-password');
const engine = new AriaEngine({
storageBackend: 'indexeddb',
walSyncMode: 'none',
} as any);
await engine.open(dbName, 1);
await engine.createTable(createSchema('t', {
id: { type: 'string', primaryKey: true },
v: { type: 'number' },
}));
await engine.insert('t', [{ id: '1', v: 42 }, { id: '2', v: 99 }]);
// 强制刷盘:SSTable 经加密保存(encryptPage 真实路径)
await (engine as any).lsm.flush();
await engine.close();
// 重载:SSTable 解密恢复
const engine2 = new AriaEngine({
storageBackend: 'indexeddb',
walSyncMode: 'none',
} as any);
await engine2.open(dbName, 1);
const rows = await engine2.find('t', { table: 't' });
expect(rows).toHaveLength(2);
const byId = Object.fromEntries(rows.map((r: any) => [r.id, r.v]));
expect(byId['1']).toBe(42);
expect(byId['2']).toBe(99);
await engine2.close();
closeCrypto();
});
});