@waffle-os/runtime 0.0.153 → 0.0.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/net/helper.ts +114 -19
- package/browser/net/ring.ts +18 -6
- package/browser/net/runtime.ts +2 -2
- package/browser/notification-relay.ts +105 -18
- package/browser/notification-wait.ts +45 -4
- package/browser/notification-worker.ts +169 -76
- package/browser/preview.ts +15 -2
- package/core/filesystem.ts +4 -0
- package/core/wasi.ts +49 -0
- package/dist/browser/net/helper.js +83 -18
- package/dist/browser/net/ring.js +6 -5
- package/dist/browser/net/runtime.js +2 -2
- package/dist/browser/notification-relay.js +78 -15
- package/dist/browser/notification-wait.js +37 -5
- package/dist/browser/notification-worker.js +146 -67
- package/dist/core/wasi.js +40 -0
- package/dist/fs/backend.js +7 -0
- package/dist/fs/client.js +69 -15
- package/dist/fs/dirty-admission.js +15 -8
- package/dist/fs/indexeddb.js +288 -96
- package/dist/fs/memory.js +106 -20
- package/dist/fs/multitab-backend.js +121 -37
- package/dist/fs/multitab-protocol.js +1 -0
- package/dist/fs/persistent.js +70 -16
- package/dist/fs/protocol.js +15 -7
- package/dist/fs/publication-attachment.js +9 -7
- package/dist/fs/service.js +34 -9
- package/dist/fs/shared.js +96 -6
- package/dist/proc/command-stdio.js +1 -1
- package/dist/tooling/program/program-transformer.json +1 -1
- package/fs/backend.ts +11 -0
- package/fs/client.ts +93 -16
- package/fs/dirty-admission.ts +22 -7
- package/fs/guest-watch.ts +1 -1
- package/fs/indexeddb.ts +379 -110
- package/fs/memory.ts +120 -19
- package/fs/multitab-backend.ts +206 -61
- package/fs/multitab-protocol.ts +1 -0
- package/fs/persistent.ts +82 -16
- package/fs/protocol.ts +26 -7
- package/fs/publication-attachment.ts +9 -7
- package/fs/service.ts +35 -7
- package/fs/shared.ts +106 -8
- package/package.json +1 -1
- package/proc/command-stdio.ts +1 -1
- package/testing/idle-workspace-cancellation-browser.ts +22 -13
- package/testing/indexeddb-storage-browser.ts +435 -1
- package/tooling/program/program-transformer.json +1 -1
|
@@ -32,11 +32,17 @@ import {
|
|
|
32
32
|
createFilesystemConnection,
|
|
33
33
|
} from "../fs/index.js";
|
|
34
34
|
import { INDEXEDDB_FORMAT } from "../fs/vfs-format.js";
|
|
35
|
+
import { CHUNK_SIZE } from "../fs/indexeddb-chunks.js";
|
|
35
36
|
import { IndexedDBStorage } from "../fs/indexeddb.js";
|
|
36
37
|
import { FilesystemError, PAGE } from "../fs/protocol.js";
|
|
37
38
|
import { gatedIndexedDB } from "./gated-indexeddb.js";
|
|
38
39
|
import { assertRuntimeStartupTrace } from "./runtime-startup-proof.js";
|
|
39
|
-
import type {
|
|
40
|
+
import type {
|
|
41
|
+
ChecksummedRecord,
|
|
42
|
+
PersistenceBatch,
|
|
43
|
+
PersistedNode,
|
|
44
|
+
StorageBackend,
|
|
45
|
+
} from "../fs/storage.js";
|
|
40
46
|
import { storedTimes } from "./fixtures/file-times.js";
|
|
41
47
|
import {
|
|
42
48
|
busyDeletesNothingCase,
|
|
@@ -51,6 +57,133 @@ function request<T>(value: IDBRequest<T>): Promise<T> {
|
|
|
51
57
|
value.onerror = () => reject(value.error);
|
|
52
58
|
});
|
|
53
59
|
}
|
|
60
|
+
/** One directory of `files` small files, each with its own payload. */
|
|
61
|
+
function wideBatch(generation: number, files: number): PersistenceBatch {
|
|
62
|
+
const saved = batch(generation);
|
|
63
|
+
const file = saved.upserts[1]!;
|
|
64
|
+
const root = { ...saved.upserts[0]!, children: [] as [string, number][] };
|
|
65
|
+
const upserts: PersistedNode[] = [root];
|
|
66
|
+
const data = new Map<string, Uint8Array>();
|
|
67
|
+
for (let index = 0; index < files; index++) {
|
|
68
|
+
const content = bytes(`file ${index}`);
|
|
69
|
+
const key = `wide:${generation}:${index}`;
|
|
70
|
+
root.children.push([`f${index}`, index + 2]);
|
|
71
|
+
upserts.push({ ...file, ino: index + 2, size: content.length, data: key });
|
|
72
|
+
data.set(key, content);
|
|
73
|
+
}
|
|
74
|
+
return { ...saved, upserts, data };
|
|
75
|
+
}
|
|
76
|
+
async function countTransactions<T>(
|
|
77
|
+
action: () => Promise<T>,
|
|
78
|
+
): Promise<{ result: T; count: number }> {
|
|
79
|
+
const transaction = IDBDatabase.prototype.transaction;
|
|
80
|
+
let count = 0;
|
|
81
|
+
IDBDatabase.prototype.transaction = function (
|
|
82
|
+
this: IDBDatabase,
|
|
83
|
+
...args: Parameters<IDBDatabase["transaction"]>
|
|
84
|
+
) {
|
|
85
|
+
count++;
|
|
86
|
+
return transaction.apply(this, args);
|
|
87
|
+
} as IDBDatabase["transaction"];
|
|
88
|
+
try {
|
|
89
|
+
return { result: await action(), count };
|
|
90
|
+
} finally {
|
|
91
|
+
IDBDatabase.prototype.transaction = transaction;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** One file of `size` bytes, each byte its index modulo 251. */
|
|
95
|
+
function chunkedBatch(size: number): PersistenceBatch {
|
|
96
|
+
const saved = batch(1);
|
|
97
|
+
saved.upserts[1]!.size = size;
|
|
98
|
+
saved.data = new Map([["file:1", Uint8Array.from({ length: size }, (_, index) => index % 251)]]);
|
|
99
|
+
return saved;
|
|
100
|
+
}
|
|
101
|
+
/** Chunk gets the action placed, and the most that were unanswered at once. */
|
|
102
|
+
async function observeChunkGets<T>(
|
|
103
|
+
action: () => Promise<T>,
|
|
104
|
+
): Promise<{ result: T; gets: number; inFlight: number }> {
|
|
105
|
+
const get = IDBObjectStore.prototype.get;
|
|
106
|
+
let gets = 0;
|
|
107
|
+
let open = 0;
|
|
108
|
+
let inFlight = 0;
|
|
109
|
+
const answered = () => open--;
|
|
110
|
+
IDBObjectStore.prototype.get = function (key: IDBValidKey | IDBKeyRange) {
|
|
111
|
+
const request = get.call(this, key);
|
|
112
|
+
if (this.name !== "data" || !Array.isArray(key)) return request;
|
|
113
|
+
gets++;
|
|
114
|
+
inFlight = Math.max(inFlight, ++open);
|
|
115
|
+
request.addEventListener("success", answered);
|
|
116
|
+
request.addEventListener("error", answered);
|
|
117
|
+
return request;
|
|
118
|
+
};
|
|
119
|
+
try {
|
|
120
|
+
return { result: await action(), gets, inFlight };
|
|
121
|
+
} finally {
|
|
122
|
+
IDBObjectStore.prototype.get = get;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Runs a read, closes the storage as soon as it returns, and reports whether every readonly
|
|
126
|
+
* transaction had settled when the connection closed. */
|
|
127
|
+
async function settledBeforeClose(
|
|
128
|
+
storage: IndexedDBStorage,
|
|
129
|
+
read: () => Promise<unknown>,
|
|
130
|
+
): Promise<boolean> {
|
|
131
|
+
const transaction = IDBDatabase.prototype.transaction;
|
|
132
|
+
const close = IDBDatabase.prototype.close;
|
|
133
|
+
let unsettled = 0;
|
|
134
|
+
let settled = true;
|
|
135
|
+
const done = () => unsettled--;
|
|
136
|
+
IDBDatabase.prototype.transaction = function (
|
|
137
|
+
this: IDBDatabase,
|
|
138
|
+
...args: Parameters<IDBDatabase["transaction"]>
|
|
139
|
+
) {
|
|
140
|
+
const tx = transaction.apply(this, args);
|
|
141
|
+
if (tx.mode !== "readonly") return tx;
|
|
142
|
+
unsettled++;
|
|
143
|
+
tx.addEventListener("complete", done);
|
|
144
|
+
tx.addEventListener("abort", done);
|
|
145
|
+
return tx;
|
|
146
|
+
} as IDBDatabase["transaction"];
|
|
147
|
+
IDBDatabase.prototype.close = function (this: IDBDatabase) {
|
|
148
|
+
settled &&= unsettled === 0;
|
|
149
|
+
close.call(this);
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
await read();
|
|
153
|
+
await storage.close();
|
|
154
|
+
return settled;
|
|
155
|
+
} finally {
|
|
156
|
+
IDBDatabase.prototype.transaction = transaction;
|
|
157
|
+
IDBDatabase.prototype.close = close;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function binaryBytes(values: readonly unknown[]): number {
|
|
161
|
+
let total = 0;
|
|
162
|
+
for (const value of values) if (value instanceof Uint8Array) total += value.byteLength;
|
|
163
|
+
return total;
|
|
164
|
+
}
|
|
165
|
+
/** Bytes of Uint8Array values that bulk data-store reads returned while `action` ran. */
|
|
166
|
+
async function bulkBytesDuring(
|
|
167
|
+
action: () => Promise<unknown>,
|
|
168
|
+
): Promise<{ bytes: number; failure: unknown }> {
|
|
169
|
+
const getAll = IDBObjectStore.prototype.getAll;
|
|
170
|
+
let bytes = 0;
|
|
171
|
+
IDBObjectStore.prototype.getAll = function (...args: Parameters<IDBObjectStore["getAll"]>) {
|
|
172
|
+
const request = getAll.apply(this, args);
|
|
173
|
+
if (this.name !== "data") return request;
|
|
174
|
+
request.addEventListener("success", () => (bytes += binaryBytes(request.result)));
|
|
175
|
+
return request;
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
const failure = await action().then(
|
|
179
|
+
() => undefined,
|
|
180
|
+
(error: unknown) => error,
|
|
181
|
+
);
|
|
182
|
+
return { bytes, failure };
|
|
183
|
+
} finally {
|
|
184
|
+
IDBObjectStore.prototype.getAll = getAll;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
54
187
|
async function raw(name: string, work: (db: IDBDatabase) => Promise<void>): Promise<void> {
|
|
55
188
|
const db = await request(indexedDB.open(name));
|
|
56
189
|
try {
|
|
@@ -1252,6 +1385,307 @@ function indexedDBCases(
|
|
|
1252
1385
|
128,
|
|
1253
1386
|
);
|
|
1254
1387
|
|
|
1388
|
+
test("IndexedDB reopen reads every payload manifest in one transaction", async (_name, open) => {
|
|
1389
|
+
const files = 300;
|
|
1390
|
+
const storage = await open();
|
|
1391
|
+
await storage.persist(wideBatch(1, files));
|
|
1392
|
+
await storage.close();
|
|
1393
|
+
const cold = await open();
|
|
1394
|
+
const result = Object.getOwnPropertyDescriptor(IDBRequest.prototype, "result")!;
|
|
1395
|
+
let resultReads = 0;
|
|
1396
|
+
Object.defineProperty(IDBRequest.prototype, "result", {
|
|
1397
|
+
...result,
|
|
1398
|
+
get(this: IDBRequest) {
|
|
1399
|
+
resultReads++;
|
|
1400
|
+
return result.get!.call(this);
|
|
1401
|
+
},
|
|
1402
|
+
});
|
|
1403
|
+
const reopen = await countTransactions(() => cold.load()).finally(() =>
|
|
1404
|
+
Object.defineProperty(IDBRequest.prototype, "result", result),
|
|
1405
|
+
);
|
|
1406
|
+
assert(reopen.result?.nodes.length === files + 1, "every file survives reopen");
|
|
1407
|
+
assert(reopen.count === 1, `reopen used ${reopen.count} transactions for ${files} payloads`);
|
|
1408
|
+
// WebKit rebuilds a request's whole result array on every read of `result`.
|
|
1409
|
+
assert(resultReads < files, `reopen read IDBRequest.result ${resultReads} times`);
|
|
1410
|
+
for (const index of [0, 150, files - 1])
|
|
1411
|
+
assert(
|
|
1412
|
+
new TextDecoder().decode(await cold.read(`wide:1:${index}`)) === `file ${index}`,
|
|
1413
|
+
"payload bytes survive reopen",
|
|
1414
|
+
);
|
|
1415
|
+
await cold.close();
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1418
|
+
test("IndexedDB cold reads take one transaction and verify every chunk", async (name, open) => {
|
|
1419
|
+
const size = 3 * CHUNK_SIZE + 100;
|
|
1420
|
+
const content = Uint8Array.from({ length: size }, (_, index) => index % 251);
|
|
1421
|
+
const saved = batch(1);
|
|
1422
|
+
saved.upserts[1]!.size = size;
|
|
1423
|
+
saved.data = new Map([["file:1", content]]);
|
|
1424
|
+
const storage = await open();
|
|
1425
|
+
await storage.persist(saved);
|
|
1426
|
+
await storage.close();
|
|
1427
|
+
const cold = await open();
|
|
1428
|
+
await cold.load();
|
|
1429
|
+
const full = await countTransactions(() => cold.read("file:1"));
|
|
1430
|
+
assert(full.count === 1, `a full read used ${full.count} transactions`);
|
|
1431
|
+
assert(
|
|
1432
|
+
full.result.length === size && full.result.every((byte, index) => byte === index % 251),
|
|
1433
|
+
"full read bytes match",
|
|
1434
|
+
);
|
|
1435
|
+
const part = await countTransactions(() =>
|
|
1436
|
+
cold.readRange("file:1", { offset: 10, length: 2 * CHUNK_SIZE }),
|
|
1437
|
+
);
|
|
1438
|
+
assert(part.count === 1, `a range read used ${part.count} transactions`);
|
|
1439
|
+
assert(
|
|
1440
|
+
part.result.length === 2 * CHUNK_SIZE &&
|
|
1441
|
+
part.result.every((byte, index) => byte === (index + 10) % 251),
|
|
1442
|
+
"range bytes match",
|
|
1443
|
+
);
|
|
1444
|
+
await cold.close();
|
|
1445
|
+
// Damage a chunk that a range covers whole, keeping its stored checksum.
|
|
1446
|
+
let middle: { bytes: Uint8Array; checksum: string } | undefined;
|
|
1447
|
+
await raw(name, async (db) => {
|
|
1448
|
+
middle = await request(db.transaction("data").objectStore("data").get(["file:1", 1]));
|
|
1449
|
+
});
|
|
1450
|
+
middle!.bytes[7] = middle!.bytes[7]! ^ 1;
|
|
1451
|
+
await change(name, "data", ["file:1", 1], middle);
|
|
1452
|
+
const damaged = await open();
|
|
1453
|
+
await damaged.load();
|
|
1454
|
+
await rejects(
|
|
1455
|
+
damaged.readRange("file:1", { offset: 0, length: 3 * CHUNK_SIZE }),
|
|
1456
|
+
"Invalid filesystem payload chunks",
|
|
1457
|
+
);
|
|
1458
|
+
await rejects(damaged.read("file:1"), "Invalid filesystem payload chunks");
|
|
1459
|
+
const edge = await damaged.readRange("file:1", { offset: 5, length: 100 });
|
|
1460
|
+
assert(
|
|
1461
|
+
edge.every((byte, index) => byte === (index + 5) % 251),
|
|
1462
|
+
"an undamaged chunk still reads",
|
|
1463
|
+
);
|
|
1464
|
+
await damaged.close();
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
test("IndexedDB cold reads of empty ranges and large files stay bounded", async (_name, open) => {
|
|
1468
|
+
const chunks = 40;
|
|
1469
|
+
const size = chunks * CHUNK_SIZE + 10;
|
|
1470
|
+
const storage = await open();
|
|
1471
|
+
await storage.persist(chunkedBatch(size));
|
|
1472
|
+
await storage.close();
|
|
1473
|
+
const cold = await open();
|
|
1474
|
+
await cold.load();
|
|
1475
|
+
const empty = await observeChunkGets(() =>
|
|
1476
|
+
Promise.all([
|
|
1477
|
+
cold.readRange("file:1", { offset: 17, length: 0 }),
|
|
1478
|
+
cold.readRange("file:1", { offset: size, length: 1 }),
|
|
1479
|
+
cold.readRange("file:1", { offset: size + 5 * CHUNK_SIZE, length: 1 }),
|
|
1480
|
+
]),
|
|
1481
|
+
);
|
|
1482
|
+
assert(
|
|
1483
|
+
empty.result.every((bytes) => bytes.length === 0),
|
|
1484
|
+
"empty ranges return no bytes",
|
|
1485
|
+
);
|
|
1486
|
+
assert(empty.gets === 0, `empty ranges requested ${empty.gets} chunks`);
|
|
1487
|
+
const whole = await observeChunkGets(() => cold.read("file:1"));
|
|
1488
|
+
assert(
|
|
1489
|
+
whole.result.length === size && whole.result.every((byte, index) => byte === index % 251),
|
|
1490
|
+
"large read bytes match",
|
|
1491
|
+
);
|
|
1492
|
+
assert(whole.gets === chunks + 1, `large read requested ${whole.gets} chunks`);
|
|
1493
|
+
assert(
|
|
1494
|
+
whole.inFlight < chunks / 2,
|
|
1495
|
+
`large read kept ${whole.inFlight} of ${chunks + 1} chunk requests in flight`,
|
|
1496
|
+
);
|
|
1497
|
+
await cold.close();
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
test("IndexedDB cold reads stop checksums on takeover and settle before close", async (name) => {
|
|
1501
|
+
const chunks = 40;
|
|
1502
|
+
const stale = await IndexedDBStorage.open(name);
|
|
1503
|
+
await stale.persist(chunkedBatch(chunks * CHUNK_SIZE));
|
|
1504
|
+
const original = crypto.subtle.digest.bind(crypto.subtle);
|
|
1505
|
+
const entered = Promise.withResolvers<void>();
|
|
1506
|
+
const held = Promise.withResolvers<void>();
|
|
1507
|
+
let digests = 0;
|
|
1508
|
+
crypto.subtle.digest = async (...args) => {
|
|
1509
|
+
if (++digests === 1) {
|
|
1510
|
+
entered.resolve();
|
|
1511
|
+
await held.promise;
|
|
1512
|
+
}
|
|
1513
|
+
return original(...args);
|
|
1514
|
+
};
|
|
1515
|
+
const reading = stale.read("file:1").then(
|
|
1516
|
+
() => undefined,
|
|
1517
|
+
(error: unknown) => error,
|
|
1518
|
+
);
|
|
1519
|
+
let newest: IndexedDBStorage | undefined;
|
|
1520
|
+
try {
|
|
1521
|
+
await entered.promise;
|
|
1522
|
+
newest = await IndexedDBStorage.open(name);
|
|
1523
|
+
held.resolve();
|
|
1524
|
+
const outcome = await reading;
|
|
1525
|
+
assert(
|
|
1526
|
+
String(outcome).includes("opened in another tab"),
|
|
1527
|
+
`stale read got ${String(outcome)}`,
|
|
1528
|
+
);
|
|
1529
|
+
assert(digests < chunks, `the displaced read still hashed ${digests} of ${chunks} chunks`);
|
|
1530
|
+
} finally {
|
|
1531
|
+
crypto.subtle.digest = original;
|
|
1532
|
+
held.resolve();
|
|
1533
|
+
await reading;
|
|
1534
|
+
await stale.close();
|
|
1535
|
+
}
|
|
1536
|
+
const settled = await settledBeforeClose(newest!, () =>
|
|
1537
|
+
newest!.readRange("file:1", { offset: 0, length: 0 }),
|
|
1538
|
+
);
|
|
1539
|
+
assert(settled, "close released the connection before a returned read settled");
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
test("IndexedDB cold reads check the caller once more before returning bytes", async (_name, open) => {
|
|
1543
|
+
const storage = await open();
|
|
1544
|
+
await storage.persist(chunkedBatch(3 * CHUNK_SIZE));
|
|
1545
|
+
await storage.close();
|
|
1546
|
+
const cold = await open();
|
|
1547
|
+
await cold.load();
|
|
1548
|
+
const controller = new AbortController();
|
|
1549
|
+
const reason = new Error("cancelled after the last checksum");
|
|
1550
|
+
const original = crypto.subtle.digest.bind(crypto.subtle);
|
|
1551
|
+
let digests = 0;
|
|
1552
|
+
crypto.subtle.digest = async (...args) => {
|
|
1553
|
+
const digest = await original(...args);
|
|
1554
|
+
digests++;
|
|
1555
|
+
return digest;
|
|
1556
|
+
};
|
|
1557
|
+
// The first caller check after every chunk was hashed schedules the cancellation, so it
|
|
1558
|
+
// lands before the read resumes from its verifier.
|
|
1559
|
+
const signal = controller.signal;
|
|
1560
|
+
signal.throwIfAborted = function (this: AbortSignal) {
|
|
1561
|
+
if (digests === 3) queueMicrotask(() => controller.abort(reason));
|
|
1562
|
+
return AbortSignal.prototype.throwIfAborted.call(this);
|
|
1563
|
+
};
|
|
1564
|
+
try {
|
|
1565
|
+
const outcome = await cold
|
|
1566
|
+
.readRange("file:1", { offset: 0, length: 3 * CHUNK_SIZE, signal })
|
|
1567
|
+
.then(
|
|
1568
|
+
(bytes) => bytes,
|
|
1569
|
+
(error: unknown) => error,
|
|
1570
|
+
);
|
|
1571
|
+
assert(
|
|
1572
|
+
outcome === reason,
|
|
1573
|
+
outcome instanceof Uint8Array
|
|
1574
|
+
? `a read cancelled after its checksums returned ${outcome.length} bytes`
|
|
1575
|
+
: `a read cancelled after its checksums rejected with ${String(outcome)}`,
|
|
1576
|
+
);
|
|
1577
|
+
} finally {
|
|
1578
|
+
crypto.subtle.digest = original;
|
|
1579
|
+
await cold.close();
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
test("IndexedDB cold reads abort their transaction when setup throws", async (_name, open) => {
|
|
1584
|
+
const storage = await open();
|
|
1585
|
+
await storage.persist(chunkedBatch(CHUNK_SIZE));
|
|
1586
|
+
await storage.close();
|
|
1587
|
+
const cold = await open();
|
|
1588
|
+
await cold.load();
|
|
1589
|
+
const failure = new Error("injected setup failure");
|
|
1590
|
+
const get = IDBObjectStore.prototype.get;
|
|
1591
|
+
const transaction = IDBDatabase.prototype.transaction;
|
|
1592
|
+
const outcomes: string[] = [];
|
|
1593
|
+
IDBObjectStore.prototype.get = function (key: IDBValidKey | IDBKeyRange) {
|
|
1594
|
+
if (this.name === "data" && typeof key === "string") throw failure;
|
|
1595
|
+
return get.call(this, key);
|
|
1596
|
+
};
|
|
1597
|
+
IDBDatabase.prototype.transaction = function (
|
|
1598
|
+
this: IDBDatabase,
|
|
1599
|
+
...args: Parameters<IDBDatabase["transaction"]>
|
|
1600
|
+
) {
|
|
1601
|
+
const tx = transaction.apply(this, args);
|
|
1602
|
+
tx.addEventListener("complete", () => outcomes.push("complete"));
|
|
1603
|
+
tx.addEventListener("abort", () => outcomes.push("abort"));
|
|
1604
|
+
return tx;
|
|
1605
|
+
} as IDBDatabase["transaction"];
|
|
1606
|
+
const controller = new AbortController();
|
|
1607
|
+
let listeners = 0;
|
|
1608
|
+
const signal = controller.signal;
|
|
1609
|
+
const add = signal.addEventListener.bind(signal);
|
|
1610
|
+
const remove = signal.removeEventListener.bind(signal);
|
|
1611
|
+
signal.addEventListener = ((...args: Parameters<AbortSignal["addEventListener"]>) => {
|
|
1612
|
+
listeners++;
|
|
1613
|
+
add(...args);
|
|
1614
|
+
}) as AbortSignal["addEventListener"];
|
|
1615
|
+
signal.removeEventListener = ((...args: Parameters<AbortSignal["removeEventListener"]>) => {
|
|
1616
|
+
listeners--;
|
|
1617
|
+
remove(...args);
|
|
1618
|
+
}) as AbortSignal["removeEventListener"];
|
|
1619
|
+
try {
|
|
1620
|
+
const outcome = await cold.readRange("file:1", { offset: 0, length: 1, signal }).then(
|
|
1621
|
+
() => undefined,
|
|
1622
|
+
(error: unknown) => error,
|
|
1623
|
+
);
|
|
1624
|
+
assert(outcome === failure, `setup failure surfaced as ${String(outcome)}`);
|
|
1625
|
+
} finally {
|
|
1626
|
+
IDBObjectStore.prototype.get = get;
|
|
1627
|
+
IDBDatabase.prototype.transaction = transaction;
|
|
1628
|
+
}
|
|
1629
|
+
await cold.close();
|
|
1630
|
+
assert(
|
|
1631
|
+
outcomes.length === 1 && outcomes[0] === "abort",
|
|
1632
|
+
`the failed read's transaction ended with ${JSON.stringify(outcomes)}`,
|
|
1633
|
+
);
|
|
1634
|
+
assert(listeners === 0, `${listeners} abort listeners left on the caller's signal`);
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
test("IndexedDB payload sizes follow commits, recovery bases and journals", async (_name, open) => {
|
|
1638
|
+
const storage = await open();
|
|
1639
|
+
const retain = (key: string, size: number) => storage.retainPayload(key, size).release();
|
|
1640
|
+
await storage.persist(batch(1, "one"));
|
|
1641
|
+
retain("file:1", 3);
|
|
1642
|
+
await rejects(
|
|
1643
|
+
Promise.resolve().then(() => retain("file:1", 4)),
|
|
1644
|
+
"size mismatch",
|
|
1645
|
+
);
|
|
1646
|
+
for (let generation = 2; generation <= 4; generation++)
|
|
1647
|
+
await storage.persist(batch(generation, "x".repeat(generation)));
|
|
1648
|
+
// Replaced in the tree, file:3 is still named by a recovery base or a kept journal.
|
|
1649
|
+
retain("file:3", 3);
|
|
1650
|
+
retain("file:4", 4);
|
|
1651
|
+
for (let generation = 5; generation <= 8; generation++)
|
|
1652
|
+
await storage.persist(batch(generation, "x".repeat(generation)));
|
|
1653
|
+
await rejects(
|
|
1654
|
+
Promise.resolve().then(() => retain("file:1", 3)),
|
|
1655
|
+
"Missing",
|
|
1656
|
+
);
|
|
1657
|
+
retain("file:8", 8);
|
|
1658
|
+
await storage.close();
|
|
1659
|
+
const reopened = await open();
|
|
1660
|
+
await reopened.load();
|
|
1661
|
+
reopened.retainPayload("file:8", 8).release();
|
|
1662
|
+
await rejects(
|
|
1663
|
+
Promise.resolve().then(() => reopened.retainPayload("file:8", 7)),
|
|
1664
|
+
"size mismatch",
|
|
1665
|
+
);
|
|
1666
|
+
await reopened.close();
|
|
1667
|
+
});
|
|
1668
|
+
|
|
1669
|
+
test("IndexedDB reopen rejects binary data keys without loading their values", async (name, open) => {
|
|
1670
|
+
const storage = await open();
|
|
1671
|
+
await storage.persist(batch(1));
|
|
1672
|
+
await storage.close();
|
|
1673
|
+
const binary = new Uint8Array([1, 2, 3]).buffer;
|
|
1674
|
+
await change(name, "data", binary, new Uint8Array(8 * 1024 * 1024));
|
|
1675
|
+
const reopened = await open();
|
|
1676
|
+
const loaded = await bulkBytesDuring(() => reopened.load());
|
|
1677
|
+
await reopened.close();
|
|
1678
|
+
assert(
|
|
1679
|
+
String(loaded.failure).includes("Invalid"),
|
|
1680
|
+
`binary key must stay fatal, got ${String(loaded.failure)}`,
|
|
1681
|
+
);
|
|
1682
|
+
assert(loaded.bytes === 0, `reopen loaded ${loaded.bytes} bytes under invalid keys`);
|
|
1683
|
+
await raw(name, async (db) => {
|
|
1684
|
+
const kept = await request(db.transaction("data").objectStore("data").getKey(binary));
|
|
1685
|
+
assert(kept !== undefined, "fatal reopen keeps the invalid record");
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1255
1689
|
test("IndexedDB pin validation does not hydrate cold payloads", async (_name, open) => {
|
|
1256
1690
|
const storage = await open();
|
|
1257
1691
|
await storage.persist(batch(1));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commit":"
|
|
1
|
+
{"commit":"d5c6dc5f37fb4cbbf8b40f3d82741cb9e00cdfff","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
|