@waffle-os/runtime 0.0.154 → 0.0.155

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.
@@ -861,6 +861,67 @@ async function pendingRuntimeOpenCase(
861
861
  }
862
862
  }
863
863
 
864
+ /**
865
+ * A multitab Host renews its lease with verifyEpoch. A readonly epoch read queues behind the
866
+ * connection's own checkpoint commit, which on a loaded device can hold "metadata" for seconds,
867
+ * so the lease lapsed and running calls were cancelled. The commit's own epoch read answers:
868
+ * right after that read, once its last write is issued, and from a later task while a large
869
+ * commit is still writing (WebKit then already reports the transaction as committing).
870
+ */
871
+ async function epochCheckDuringCommitCase(open: () => Promise<StorageBackend>): Promise<void> {
872
+ const storage = (await open()) as IndexedDBStorage;
873
+ await storage.persist(batch(1));
874
+ await epochCheckDuring(storage, "get", "epoch", 2, "success");
875
+ await epochCheckDuring(storage, "put", "active", 3, "success");
876
+ await epochCheckDuring(storage, "put", "active", 4, "later", "x".repeat(16 << 20));
877
+ await storage.close();
878
+ }
879
+
880
+ /**
881
+ * Runs one commit and checks the epoch when the commit's `method` on metadata `key` succeeds, or
882
+ * in a later task after the commit issues it.
883
+ */
884
+ async function epochCheckDuring(
885
+ storage: IndexedDBStorage,
886
+ method: "get" | "put",
887
+ key: string,
888
+ generation: number,
889
+ when: "success" | "later",
890
+ text?: string,
891
+ ): Promise<void> {
892
+ const order: string[] = [];
893
+ let checked: Promise<boolean> | undefined;
894
+ const original = IDBObjectStore.prototype[method] as (...args: unknown[]) => IDBRequest;
895
+ const watched = function (this: IDBObjectStore, ...args: unknown[]): IDBRequest {
896
+ const request = original.apply(this, args);
897
+ const requestKey = method === "get" ? args[0] : args[1];
898
+ if (requestKey !== key || this.transaction.mode !== "readwrite" || checked) return request;
899
+ const check = () =>
900
+ storage.verifyEpoch().then((owned) => {
901
+ order.push("verified");
902
+ return owned;
903
+ });
904
+ const { promise, resolve } = Promise.withResolvers<boolean>();
905
+ checked = promise;
906
+ if (when === "success") request.addEventListener("success", () => resolve(check()));
907
+ else request.addEventListener("success", () => setTimeout(() => resolve(check()), 0));
908
+ return request;
909
+ };
910
+ Object.assign(IDBObjectStore.prototype, { [method]: watched });
911
+ try {
912
+ await storage.persist(batch(generation, text));
913
+ order.push("committed");
914
+ } finally {
915
+ Object.assign(IDBObjectStore.prototype, { [method]: original });
916
+ }
917
+ assert(checked !== undefined, `the commit issued ${method} ${key}`);
918
+ assert((await checked) === true, `the owner's epoch is confirmed at ${method} ${key}`);
919
+ assert(
920
+ order.join() === "verified,committed",
921
+ `epoch check at ${method} ${key} (${when}): ${order}`,
922
+ );
923
+ }
924
+
864
925
  function indexedDBCases(
865
926
  filesystemWorkerURL?: string | URL,
866
927
  gatedWorkerURL?: string | URL,
@@ -872,6 +933,8 @@ function indexedDBCases(
872
933
  };
873
934
  test("IndexedDB takeover fences cold pages served from memory", async (_name, open) =>
874
935
  warmColdReadTakeoverCase(open));
936
+ test("IndexedDB epoch check answers during an open commit", async (_name, open) =>
937
+ epochCheckDuringCommitCase(open));
875
938
  test("IndexedDB persists format identity and adopts validated unmarked data", async (name, open) => {
876
939
  const storage = await open();
877
940
  await storage.persist(batch(1, "legacy data"));
@@ -1789,6 +1852,72 @@ function indexedDBCases(
1789
1852
  });
1790
1853
  });
1791
1854
 
1855
+ test("persist rejects own serializer nodes without corrupting reopen and isolates nested extra fields", async (name, open) => {
1856
+ const storage = await open();
1857
+ const bad = batch(1);
1858
+ Object.assign(bad.upserts[0]!, {
1859
+ toJSON() {
1860
+ return { ino: 1, kind: "dir", atime: "0", mtime: "0", ctime: "0", size: 0 };
1861
+ },
1862
+ });
1863
+ let rejected = false;
1864
+ try {
1865
+ await storage.persist(bad);
1866
+ } catch (error) {
1867
+ rejected = /DataCloneError|clone/i.test(String(error));
1868
+ }
1869
+ assert(rejected, "own serializer node must reject with clone error");
1870
+ await storage.close();
1871
+ const clean = await open();
1872
+ assert((await clean.load()) === undefined, "reopen after rejected serializer stays empty");
1873
+
1874
+ const nested = { tag: "before" };
1875
+ const extraBatch = batch(1);
1876
+ Object.assign(extraBatch.upserts[0]!, { extra: nested });
1877
+ const saving = clean.persist(extraBatch);
1878
+ nested.tag = "after";
1879
+ await saving;
1880
+ await raw(name, async (db) => {
1881
+ const snap = (await request(db.transaction("metadata").objectStore("metadata").get(0))) as {
1882
+ json: string;
1883
+ };
1884
+ assert(snap.json.includes('"before"'), "persisted snapshot kept pre-mutation nested field");
1885
+ assert(!snap.json.includes('"after"'), "post-submission nested mutation must not leak");
1886
+ });
1887
+ await clean.close();
1888
+ const reloaded = await open();
1889
+ assert((await reloaded.load())?.generation === 1, "reopen succeeds cleanly");
1890
+ });
1891
+
1892
+ test("recovery root lookup matches full retention across commit, abort, retry, compaction and journal reopen", async (_name, open) => {
1893
+ const storage = await open();
1894
+ await storage.persist(batch(1));
1895
+ const pin1 = storage.retainPayload("file:1", 2);
1896
+ const originalPut = IDBObjectStore.prototype.put;
1897
+ IDBObjectStore.prototype.put = function (value: unknown, key?: IDBValidKey) {
1898
+ if (this.name === "journal") throw new DOMException("injected abort", "AbortError");
1899
+ return originalPut.call(this, value, key);
1900
+ };
1901
+ try {
1902
+ await rejects(storage.persist(batch(2)), "abort");
1903
+ } finally {
1904
+ IDBObjectStore.prototype.put = originalPut;
1905
+ }
1906
+ storage.checkPayload("file:1", 2);
1907
+ await storage.persist(batch(2));
1908
+ await storage.persist({ ...batch(3), retainedData: ["file:1"] });
1909
+ pin1.release();
1910
+ storage.checkPayload("file:1", 2);
1911
+ await storage.persist(batch(4));
1912
+ await storage.close();
1913
+ const reopened = await open();
1914
+ assert((await reopened.load())?.generation === 4, "reopen recovers generation 4");
1915
+ assert(
1916
+ new TextDecoder().decode(await reopened.read("file:4")) === "v4",
1917
+ "latest payload readable",
1918
+ );
1919
+ });
1920
+
1792
1921
  return cases;
1793
1922
  }
1794
1923
 
@@ -1 +1 @@
1
- {"commit":"d5c6dc5f37fb4cbbf8b40f3d82741cb9e00cdfff","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
1
+ {"commit":"b2cbaa1b6b80ccf3d082d6cb6af8075e2b607006","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}