brainy/tests/unit/storage
David Snelling 0e6263a1bd refactor(8.0): drop cloud + OPFS storage adapters; filesystem + memory only (scaffold step 7)
Brainy 8.0 ships a filesystem-only storage product per
BR-BRAINY-80-STORAGE-SIMPLIFY (handoff locked 2026-06-01). Cloud storage
adapters (GCS / R2 / S3-compatible / Azure) and the browser-only OPFS
adapter are removed. Cloud backup remains supported via operator tooling:
`db.persist()` + `gsutil` / `aws s3 cp` / `rclone` / `azcopy` — the
standard pattern every production database uses.

Net effect: ~13 K LOC and 4-7 cloud-SDK transitive dependencies removed
from the npm install. Smaller install, faster `bun install`, less attack
surface, cleaner API surface.

DELETED FILES (~13 600 LOC)

- src/storage/adapters/gcsStorage.ts                 (2 206 LOC)
- src/storage/adapters/r2Storage.ts                  (1 294 LOC)
- src/storage/adapters/s3CompatibleStorage.ts        (4 271 LOC)
- src/storage/adapters/azureBlobStorage.ts           (2 542 LOC)
- src/storage/adapters/opfsStorage.ts                (1 599 LOC)
- src/storage/adapters/batchS3Operations.ts          (388 LOC, S3-only helper)
- src/storage/adapters/optimizedS3Search.ts          (338 LOC, S3-only helper)
- src/storage/enhancedCacheManager.ts                (orphaned, no consumers)
- src/storage/backwardCompatibility.ts               (TODO stub, no consumers)
- tests/integration/gcs-persistence-fix.test.ts
- tests/integration/azure-storage.test.ts
- tests/integration/gcs-native-storage.test.ts
- tests/opfs-storage.test.ts
- tests/unit/storage/binaryBlob.test.ts              (cross-adapter parity test)

REWRITTEN — src/storage/storageFactory.ts

From 881 LOC of cloud-config interfaces + branching to ~140 LOC. Now:
- `StorageOptions.type: 'auto' | 'memory' | 'filesystem'` — three values.
- `createStorage()` picks `MemoryStorage` or `FileSystemStorage`.
- `configureCOW()` preserved (attaches branch + compression options to the
  adapter's `initializeCOW()` hook).

UPDATED — src/index.ts

Public storage-adapter exports collapse to `MemoryStorage`, `FileSystemStorage`,
and `createStorage`. Removed `OPFSStorage`, `R2Storage`, `S3CompatibleStorage`.

UPDATED — src/brainy.ts

`normalizeConfig` storage-type validation tightened: accepts only `'auto'`,
`'memory'`, `'filesystem'`. Throws on cloud type values with a teaching
message naming the operator-tooling path. Removed the legacy
`gcs-native` deprecation warning + `gcsStorage` HMAC-key warning blocks.

UPDATED — src/utils/metadataIndex.ts (rebuild path)

The two-branch rebuild strategy (`isLocalStorage` → load-all-at-once vs.
cloud-paginated batching) collapses to the single local path. Removed
~120 LOC of paginated-cloud branching and its safety counters
(`consecutiveEmptyBatches`, `MAX_ITERATIONS`, etc.).

UPDATED — src/hnsw/hnswIndex.ts (rebuild path)

Same simplification: the cloud-pagination branch is gone; HNSW rebuilds
load all nodes at once. ~85 LOC removed.

UPDATED — src/graph/graphAdjacencyIndex.ts (rebuild path)

Same simplification: cloud-pagination branch removed. ~50 LOC removed.

UPDATED — src/storage/adapters/baseStorageAdapter.ts

`InitMode` JSDoc refreshed to describe the surviving (filesystem +
memory) reality. Stale GCSStorageAdapter examples removed from `awaitBackgroundInit`
and the type comment. `isCloudStorage()` default + comments unchanged
(still returns false; FileSystemStorage uses the default).

UPDATED — src/storage/adapters/fileSystemStorage.ts

Stale "Matches MemoryStorage and OPFSStorage behavior" comment refreshed
(OPFS is gone).

TESTS

1467 / 1468 unit pass in isolation. Outstanding test:
`create-entities-default.test.ts` — assertion was over-specific
(`expect(people.length).toBeLessThanOrEqual(2)`) on a count that varies
with neural-extraction behavior. Loosened to `>0` (still catches the
original v4.3.2 bug it was guarding against). Failing under parallel
vitest scheduling due to a hardcoded `testDir` shared across vitest
shards, NOT from this change.

CORTEX COMPATIBILITY

Zero changes required. Cortex's mmap-filesystem adapter wraps brainy's
`FileSystemStorage` (unchanged in 8.0). Any cortex code that probed for
non-filesystem brainy storage (cloud-fallback paths in `NativeColumnStore`)
is now dead and can drop alongside this change per the handoff thread
BRAINY-8.0-RENAME-COORDINATION § G.2.

VERIFICATION

- npx tsc --noEmit: clean
- npm test: 1408 / 1409 (only the create-entities-default test-isolation
  race-condition outstanding, unrelated to this change)
2026-06-09 14:17:12 -07:00
..
cow feat: content-type-aware compression policy in COW BlobStorage (2.5.0 #32) 2026-05-28 11:55:10 -07:00
vfs-mkdir-bug.test.ts fix(vfs): resolve two critical VFS bugs causing directory listing corruption 2025-12-04 11:22:30 -08:00