Models exactly the levels production walks, and nothing looser:
root.getDirectoryHandle(name) accepts only OPFS_NAMESPACE_DIR.
Anything else throws — a store that reaches for a dataset directory at
the origin root (the pre-namespace layout) fails every test that mounts
it, not just the one asserting the layout. create: false before the
namespace dir exists throws the platform NotFoundError, so
OPFSStore.listAll on a cold origin is testable.
luxarDir.getDirectoryHandle(id, …) records id in datasetIds and
returns FakeOpfsRoot.datasetDir; luxarDir.removeEntry(id, …)
wipes it; luxarDir.entries() yields one [id, datasetDir] per
recorded id (what listAll iterates).
The dataset dir is FLAT: every bucket getDirectoryHandle returns the
dataset dir itself and files are keyed by name alone. Bucket names carry
no information the tests need (a key's base64url file name is unique on
its own), and the flat shape is what lets tests monkeypatch ONE handle's
getFileHandle / removeEntry to inject faults at any depth.
Both datasetDir and every handle it returns are plain objects with
own-property methods, so tests may spread or reassign them freely.
Build an in-memory OPFS root for cache tests.
Models exactly the levels production walks, and nothing looser:
root.getDirectoryHandle(name)accepts only OPFS_NAMESPACE_DIR. Anything else throws — a store that reaches for a dataset directory at the origin root (the pre-namespace layout) fails every test that mounts it, not just the one asserting the layout.create: falsebefore the namespace dir exists throws the platformNotFoundError, soOPFSStore.listAllon a cold origin is testable.luxarDir.getDirectoryHandle(id, …)recordsidindatasetIdsand returns FakeOpfsRoot.datasetDir;luxarDir.removeEntry(id, …)wipes it;luxarDir.entries()yields one[id, datasetDir]per recorded id (whatlistAlliterates).getDirectoryHandlereturns the dataset dir itself and files are keyed by name alone. Bucket names carry no information the tests need (a key's base64url file name is unique on its own), and the flat shape is what lets tests monkeypatch ONE handle'sgetFileHandle/removeEntryto inject faults at any depth.Both
datasetDirand every handle it returns are plain objects with own-property methods, so tests may spread or reassign them freely.