| ... | ... | @@ -5,9 +5,11 @@ import vm from 'node:vm'; |
| 5 | 5 | |
| 6 | 6 | const source = await readFile(new URL('../../crates/snowbound/web/glue.js', import.meta.url), 'utf8'); |
| 7 | 7 | |
| 8 | | test('an OPFS flush rejection retains ordered writes until storage recovers', async () => { |
| 8 | test('OPFS retries preserve write order and canonical handle ownership', async () => { |
| 9 | 9 | const files = new Map([['existing', new Uint8Array([0])]]); |
| 10 | 10 | const flushed = []; |
| 11 | const held = new Set(); |
| 12 | const opened = []; |
| 11 | 13 | const replies = []; |
| 12 | 14 | let unavailable = false; |
| 13 | 15 | const root = { |
| ... | ... | @@ -16,11 +18,19 @@ test('an OPFS flush rejection retains ordered writes until storage recovers', as |
| 16 | 18 | yield [name, { kind: 'file', getFile: async () => ({ arrayBuffer: async () => bytes.buffer }) }]; |
| 17 | 19 | } |
| 18 | 20 | }, |
| 21 | async removeEntry(path) { |
| 22 | assert.equal(held.has(path), false, 'Removal closes the existing access handle'); |
| 23 | files.delete(path); |
| 24 | }, |
| 19 | 25 | async getFileHandle(path) { |
| 20 | 26 | let bytes = files.get(path)?.slice() ?? new Uint8Array(); |
| 21 | 27 | return { |
| 22 | 28 | async createSyncAccessHandle() { |
| 29 | if (held.has(path)) throw new Error('Another access handle is open for ' + path); |
| 30 | held.add(path); |
| 31 | opened.push(path); |
| 23 | 32 | return { |
| 33 | close() { held.delete(path); }, |
| 24 | 34 | write(part, { at }) { |
| 25 | 35 | if (at + part.length > bytes.length) { |
| 26 | 36 | const extended = new Uint8Array(at + part.length); |
| ... | ... | @@ -70,4 +80,12 @@ test('an OPFS flush rejection retains ordered writes until storage recovers', as |
| 70 | 80 | assert.deepEqual(flushed, [['replica-wal', [1, 2]], ['replica-wal', [1, 3]], ['replica', [4]]]); |
| 71 | 81 | assert.equal((await send({ kind: 'settle' })).error, null); |
| 72 | 82 | assert.equal(flushed.length, 3); |
| 83 | assert.equal((await send({ kind: 'store', changes: [['/replica/', 1, [[0, new Uint8Array([5])]]]] })).error, null); |
| 84 | assert.deepEqual([...files.get('replica')], [5]); |
| 85 | assert.equal(opened.filter(path => path === 'replica').length, 1, 'Aliases reuse the existing handle'); |
| 86 | assert.equal((await send({ kind: 'store', changes: [['/replica/']] })).error, null); |
| 87 | assert.equal(files.has('replica'), false); |
| 88 | assert.equal((await send({ kind: 'store', changes: [['replica', 1, [[0, new Uint8Array([6])]]]] })).error, null); |
| 89 | assert.deepEqual([...files.get('replica')], [6]); |
| 90 | assert.equal(opened.filter(path => path === 'replica').length, 2, 'Recreation opens a new handle'); |
| 73 | 91 | }); |