]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Refactor tester1 OPFS test to support both the "opfs" and "opfs-wl" VFSes.
authorstephan <stephan@noemail.net>
Sun, 8 Mar 2026 07:58:02 +0000 (07:58 +0000)
committerstephan <stephan@noemail.net>
Sun, 8 Mar 2026 07:58:02 +0000 (07:58 +0000)
FossilOrigin-Name: 17ac8d7bdfaf96510abea8c11019045c1703b7040655d9c4c8d7001636260b50

ext/wasm/tester1.c-pp.js
manifest
manifest.uuid

index 6ed66d785368bf37e6805c5e13a95f28542305f0..81bc37e26d2fb1a4444b1f41d5ed8ffac1a818ae 100644 (file)
@@ -451,9 +451,131 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
     T.assert( !initDb );
     tryKey('hexkey', hexFoo, 6);
     dbUnlink();
-  },
+  };
 //#endif enable-see
 
+  /* Tests common to "opfs" and "opfs-wl".  These tests manipulate
+     "this" and must run in order.
+  */
+  T.opfsCommon = {
+    sanityChecks: async function(vfsName, oo1Ctor, sqlite3){
+      T.assert(capi.sqlite3_vfs_find(vfsName));
+      const opfs = sqlite3.opfs;
+      const filename = this.opfsDbFile = '/dir/sqlite3-tester1.db';
+      const fileUri = 'file://'+filename+'?delete-before-open=1';
+      const initSql = [
+        'create table p(a);',
+        'insert into p(a) values(1),(2),(3)'
+      ];
+      let db = new oo1Ctor(fileUri);
+      try {
+        db.exec(initSql);
+        T.assert(3 === db.selectValue('select count(*) from p'));
+        db.close();
+        db = new oo1Ctor(filename);
+        db.exec('insert into p(a) values(4),(5),(6)');
+        T.assert(6 === db.selectValue('select count(*) from p'));
+        this.opfsDbExport = capi.sqlite3_js_db_export(db);
+        T.assert(this.opfsDbExport instanceof Uint8Array)
+          .assert(this.opfsDbExport.byteLength>0
+                  && 0===this.opfsDbExport.byteLength % 512);
+      }finally{
+        db.close();
+        db = null;
+      }
+      T.assert(await opfs.entryExists(filename));
+      try {
+        db = new oo1Ctor(fileUri);
+        db.exec(initSql) /* will throw if delete-before-open did not work */;
+        T.assert(3 === db.selectValue('select count(*) from p'));
+      }finally{
+        if(db) db.close();
+      }
+    },
+
+    importer: async function(vfsName, oo1Ctor, sqlite3){
+      let db;
+      const filename = this.opfsDbFile;
+      try {
+        const exp = this.opfsDbExport;
+        delete this.opfsDbExport;
+        this.opfsImportSize = await oo1Ctor.importDb(filename, exp);
+        db = new oo1Ctor(this.opfsDbFile);
+        T.assert(6 === db.selectValue('select count(*) from p')).
+          assert( this.opfsImportSize == exp.byteLength );
+        db.close();
+        db = null;
+        this.opfsUnlink =
+          (fn=filename)=>sqlite3.util.sqlite3__wasm_vfs_unlink(vfsName, fn);
+        this.opfsUnlink(filename);
+        T.assert(!(await sqlite3.opfs.entryExists(filename)));
+        // Try again with a function as an input source:
+        let cursor = 0;
+        const blockSize = 512, end = exp.byteLength;
+        const reader = async function(){
+          if(cursor >= exp.byteLength){
+            return undefined;
+          }
+          const rv = exp.subarray(cursor, cursor+blockSize>end ? end : cursor+blockSize);
+          cursor += blockSize;
+          return rv;
+        };
+        this.opfsImportSize = await oo1Ctor.importDb(filename, reader);
+        db = new oo1Ctor(this.opfsDbFile);
+        T.assert(6 === db.selectValue('select count(*) from p')).
+          assert( this.opfsImportSize == exp.byteLength );
+      }finally{
+        if(db) db.close();
+      }
+    },
+
+    opfsUtil: async function(vfsName, oo1Ctor, sqlite3){
+      const filename = this.opfsDbFile;
+      const unlink = this.opfsUnlink;
+      T.assert(filename && !!unlink);
+      delete this.opfsDbFile;
+      delete this.opfsUnlink;
+      /**************************************************************
+        ATTENTION CLIENT-SIDE USERS: sqlite3.opfs is NOT intended
+        for client-side use. It is only for this project's own
+        internal use. Its APIs are subject to change or removal at
+        any time. The sqlite3.opfs namespace is REMOVED from the
+        sqlite3 namespace in non-test runs of the library.
+      ***************************************************************/
+      const opfs = sqlite3.opfs;
+      const fSize = this.opfsImportSize;
+      delete this.opfsImportSize;
+      let sh;
+      try{
+        T.assert(await opfs.entryExists(filename));
+        const [dirHandle, filenamePart] = await opfs.getDirForFilename(filename, false);
+        const fh = await dirHandle.getFileHandle(filenamePart);
+        sh = await fh.createSyncAccessHandle();
+        T.assert(fSize === await sh.getSize());
+        await sh.close();
+        sh = undefined;
+        unlink();
+        T.assert(!(await opfs.entryExists(filename)));
+      }finally{
+        if(sh) await sh.close();
+        unlink();
+      }
+
+      // Some sanity checks of the opfs utility functions...
+      const testDir = '/sqlite3-opfs-'+opfs.randomFilename(12);
+      const aDir = testDir+'/test/dir';
+      T.assert(await opfs.mkdir(aDir), "mkdir failed")
+        .assert(await opfs.mkdir(aDir), "mkdir must pass if the dir exists")
+        .assert(!(await opfs.unlink(testDir+'/test')), "delete 1 should have failed (dir not empty)")
+        .assert((await opfs.unlink(testDir+'/test/dir')), "delete 2 failed")
+        .assert(!(await opfs.unlink(testDir+'/test/dir')),
+                "delete 2b should have failed (dir already deleted)")
+        .assert((await opfs.unlink(testDir, true)), "delete 3 failed")
+        .assert(!(await opfs.entryExists(testDir)),
+                "entryExists(",testDir,") should have failed");
+    }
+  }/*T.opfsCommon*/;
+
   ////////////////////////////////////////////////////////////////////////
   // End of infrastructure setup. Now define the tests...
   ////////////////////////////////////////////////////////////////////////
@@ -3767,130 +3889,29 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
 
   ////////////////////////////////////////////////////////////////////////
   T.g('OPFS: Origin-Private File System',
-      (sqlite3)=>(hasOpfs() || 'requires "opfs" VFS'))
+      (sqlite3)=>(!!sqlite3.oo1.OpfsDb || 'requires "opfs" VFS'))
     .t({
       name: 'OPFS db sanity checks',
-      test: async function(sqlite3){
-        T.assert(capi.sqlite3_vfs_find('opfs'));
-        const opfs = sqlite3.opfs;
-        const filename = this.opfsDbFile = '/dir/sqlite3-tester1.db';
-        const fileUri = 'file://'+filename+'?delete-before-open=1';
-        const initSql = [
-          'create table p(a);',
-          'insert into p(a) values(1),(2),(3)'
-        ];
-        let db = new sqlite3.oo1.OpfsDb(fileUri);
-        try {
-          db.exec(initSql);
-          T.assert(3 === db.selectValue('select count(*) from p'));
-          db.close();
-          db = new sqlite3.oo1.OpfsDb(filename);
-          db.exec('insert into p(a) values(4),(5),(6)');
-          T.assert(6 === db.selectValue('select count(*) from p'));
-          this.opfsDbExport = capi.sqlite3_js_db_export(db);
-          T.assert(this.opfsDbExport instanceof Uint8Array)
-            .assert(this.opfsDbExport.byteLength>0
-                    && 0===this.opfsDbExport.byteLength % 512);
-        }finally{
-          db.close();
-        }
-        T.assert(await opfs.entryExists(filename));
-        try {
-          db = new sqlite3.oo1.OpfsDb(fileUri);
-          db.exec(initSql) /* will throw if delete-before-open did not work */;
-          T.assert(3 === db.selectValue('select count(*) from p'));
-        }finally{
-          if(db) db.close();
-        }
+      test: async (sqlite3)=>{
+        await T.opfsCommon.sanityChecks('opfs', sqlite3.oo1.OpfsDb, sqlite3);
       }
-    }/*OPFS db sanity checks*/)
+    })
     .t({
-      name: 'OPFS import',
-      test: async function(sqlite3){
-        let db;
-        const filename = this.opfsDbFile;
-        try {
-          const exp = this.opfsDbExport;
-          delete this.opfsDbExport;
-          this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(filename, exp);
-          db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
-          T.assert(6 === db.selectValue('select count(*) from p')).
-            assert( this.opfsImportSize == exp.byteLength );
-          db.close();
-          this.opfsUnlink =
-                (fn=filename)=>sqlite3.util.sqlite3__wasm_vfs_unlink("opfs",fn);
-          this.opfsUnlink(filename);
-          T.assert(!(await sqlite3.opfs.entryExists(filename)));
-          // Try again with a function as an input source:
-          let cursor = 0;
-          const blockSize = 512, end = exp.byteLength;
-          const reader = async function(){
-            if(cursor >= exp.byteLength){
-              return undefined;
-            }
-            const rv = exp.subarray(cursor, cursor+blockSize>end ? end : cursor+blockSize);
-            cursor += blockSize;
-            return rv;
-          };
-          this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(filename, reader);
-          db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
-          T.assert(6 === db.selectValue('select count(*) from p')).
-            assert( this.opfsImportSize == exp.byteLength );
-        }finally{
-          if(db) db.close();
-        }
+      name: 'OPFS import/export',
+      test: async (sqlite3)=>{
+        await T.opfsCommon.importer('opfs', sqlite3.oo1.OpfsDb, sqlite3);
       }
-    }/*OPFS export/import*/)
+    })
     .t({
       name: '(Internal-use) OPFS utility APIs',
-      test: async function(sqlite3){
-        const filename = this.opfsDbFile;
-        const unlink = this.opfsUnlink;
-        T.assert(filename && !!unlink);
-        delete this.opfsDbFile;
-        delete this.opfsUnlink;
-        /**************************************************************
-           ATTENTION CLIENT-SIDE USERS: sqlite3.opfs is NOT intended
-           for client-side use. It is only for this project's own
-           internal use. Its APIs are subject to change or removal at
-           any time.
-        ***************************************************************/
-        const opfs = sqlite3.opfs;
-        const fSize = this.opfsImportSize;
-        delete this.opfsImportSize;
-        let sh;
-        try{
-          T.assert(await opfs.entryExists(filename));
-          const [dirHandle, filenamePart] = await opfs.getDirForFilename(filename, false);
-          const fh = await dirHandle.getFileHandle(filenamePart);
-          sh = await fh.createSyncAccessHandle();
-          T.assert(fSize === await sh.getSize());
-          await sh.close();
-          sh = undefined;
-          unlink();
-          T.assert(!(await opfs.entryExists(filename)));
-        }finally{
-          if(sh) await sh.close();
-          unlink();
-        }
-
-        // Some sanity checks of the opfs utility functions...
-        const testDir = '/sqlite3-opfs-'+opfs.randomFilename(12);
-        const aDir = testDir+'/test/dir';
-        T.assert(await opfs.mkdir(aDir), "mkdir failed")
-          .assert(await opfs.mkdir(aDir), "mkdir must pass if the dir exists")
-          .assert(!(await opfs.unlink(testDir+'/test')), "delete 1 should have failed (dir not empty)")
-          .assert((await opfs.unlink(testDir+'/test/dir')), "delete 2 failed")
-          .assert(!(await opfs.unlink(testDir+'/test/dir')),
-                  "delete 2b should have failed (dir already deleted)")
-          .assert((await opfs.unlink(testDir, true)), "delete 3 failed")
-          .assert(!(await opfs.entryExists(testDir)),
-                  "entryExists(",testDir,") should have failed");
+      test: async (sqlite3)=>{
+        await T.opfsCommon.opfsUtil("opfs", sqlite3.oo1.OpfsDb, sqlite3);
       }
-    }/*OPFS util sanity checks*/)
+    })
 //#if enable-see
     .t({
       name: 'OPFS with SEE encryption',
+      predicate: ()=>!!sqlite3.oo1.OpfsDb,
       test: function(sqlite3){
         T.seeBaseCheck(
           sqlite3.oo1.OpfsDb,
@@ -3899,9 +3920,44 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
             if( isInit ) opt.filename += '?delete-before-open=1';
             return opt;
           },
-          ()=>{});
+          ()=>{}
+        );
       }
-    })/*OPFS with SEE*/
+    })
+//#endif enable-see
+  ;/* end OPFS tests */
+
+  ////////////////////////////////////////////////////////////////////////
+  T.g('OPFS-WL: Origin-Private File System with Web Locks',
+      (sqlite3)=>(!!sqlite3.oo1.OpfsWlDb || 'requires "opfs-wl" VFS'))
+    .t({
+      name: 'OPFS-WL db sanity checks',
+      test: async (sqlite3)=>{
+        await T.opfsCommon.sanityChecks('opfs-wl', sqlite3.oo1.OpfsWlDb, sqlite3);
+      }
+    })
+    .t({
+      name: 'OPFS-WL import/export',
+      test: async (sqlite3)=>{
+        await T.opfsCommon.importer('opfs-wl', sqlite3.oo1.OpfsWlDb, sqlite3);
+      }
+    })
+//#if enable-see
+    .t({
+      name: 'OPFS-WL with SEE encryption',
+      predicate: ()=>!!sqlite3.oo1.OpfsWlDb,
+      test: function(sqlite3){
+        T.seeBaseCheck(
+          sqlite3.oo1.OpfsWlDb,
+          function(isInit){
+            const opt = {filename: 'file:///sqlite3-see.edb'};
+            if( isInit ) opt.filename += '?delete-before-open=1';
+            return opt;
+          },
+          ()=>{}
+        );
+      }
+    })
 //#endif enable-see
   ;/* end OPFS tests */
 
index d2f8ed23319cc1620a42dad5f76caed6104629bc..852b2ca2e8d11e502953440cb1c93c101a24ab04 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Extend\sthe\sJS\spre-bootstrapping\sconfiguration\sto\sinclude\san\soption\sto\sdisable\sinclusion\sof\sany\sgiven\sextension\sVFS\s(not\sthe\sdefault\sVFSes,\slike\smemdb).\sThe\sprimary\smotivation\sfor\sthis\sis\sto\sgive\speople\swho\sdon't\suse\sOPFS\sto\sa\sway\sto\skeep\sthe\sOPFS\sVFSes\sfrom\sloading\stheir\sproxy\sworkers,\swhich\sare\sexpensive.
-D 2026-03-07T06:10:29.452
+C Refactor\stester1\sOPFS\stest\sto\ssupport\sboth\sthe\s"opfs"\sand\s"opfs-wl"\sVFSes.
+D 2026-03-08T07:58:02.639
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -644,7 +644,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
 F ext/wasm/tester1-worker.c-pp.html d0032241d0b24d996cf1c4dd0dde364189693af9b5c986e48af7d3d720fcd244
 F ext/wasm/tester1.c-pp.html 52d88fe2c6f21a046030a36410b4839b632f4424028197a45a3d5669ea724ddb
-F ext/wasm/tester1.c-pp.js 31cde3c4db4b955d5554c21cb0aa6ec3a0743b03d7c5262a38bfa303e7955942
+F ext/wasm/tester1.c-pp.js bccc66cdb09477ef09bf7c871bdba85f2c8b936a32d5dc07dc8c882517f73b50
 F ext/wasm/tests/opfs/concurrency/index.html c8ac239f6fb45440adbdddb33a0fde2c61a20799189d60b8926be702a27dd226
 F ext/wasm/tests/opfs/concurrency/test.js 46c772bc18abb0fcbb058d57b5aaee9e7938f948ecdd802c6ca0850ad3519f92
 F ext/wasm/tests/opfs/concurrency/worker.js fc985ec86b70b057224e8caaa9c5a11892ea9b980a5c5da21b1efdf5f12bc3f6
@@ -2191,8 +2191,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P c1cb61f473a11a325ef421ba8edfb20257203688565f7db62309044be183af5f
-R bd137899af2cd4094f0a4f5a1f4094af
+P 9a07eb7a941479510891d1444aacbeb440efaad3e9a13f186833618d8b60a8da
+R 2c796a522d5a1762226997586fbd0bf5
 U stephan
-Z 147d7dd643bc15130deceeb0e6d52d6f
+Z 681d2e8fff944e3c89259f16f4209f56
 # Remove this line to create a well-formed Fossil manifest.
index 06ded776dcb64566ec8269075d9ced075b9b86a8..7e39b0e048424ff8ed5ee9b7a8d89086e3111c3a 100644 (file)
@@ -1 +1 @@
-9a07eb7a941479510891d1444aacbeb440efaad3e9a13f186833618d8b60a8da
+17ac8d7bdfaf96510abea8c11019045c1703b7040655d9c4c8d7001636260b50