winters27_obsidian-byoc/tests/_workerShim.cjs
winters27 bc3ac8d100 fix(sync): repair encrypted sync data loss (#5) and pCloud rename
Encrypted sync could delete local files on the second sync. The encrypted
walk exposed the ciphertext name as keyRaw while local and baseline used the
plaintext name, so the node map never matched and every encrypted file looked
remote-deleted. Fixes, each with regression tests:

- fsEncrypt exposes the plaintext key as keyRaw (keyEnc stays ciphertext) so
  remote, local, and baseline entries merge in the sync node map.
- The equal-commit path preserves the encryption baseline anchors (sizeEnc,
  mtimeSvr) so a synced file is not later misread as remotely changed.
- isVaildText no longer rejects legitimate filename format characters (ZWNJ,
  ZWJ, bidi marks, soft hyphen) common in Persian, Arabic, Hindi, and Hebrew.
- Undecryptable remote entries are recorded, not silently dropped: sync aborts
  if nothing decrypts, otherwise keeps local files and warns, and never treats
  an undecryptable entry as a remote deletion.
- A one-time post-upgrade safety net keeps local files on the first encrypted
  sync so a residual broken baseline cannot mass-delete.
- pCloud rename no longer throws: supportsRename is false (delete+create
  fallback) with a defensive copy+delete, matching S3 and Azure.

Tests: an account-free encrypted end-to-end suite (delete/no-resurrection with
sample passwords, non-ASCII names, undecryptable handling) plus a real-disk
integration test (push, encrypt, re-sync, edit, delete, cross-device decrypt
of non-ASCII notes), and a worker/crypto shim so encryption loads under Node.
2026-07-15 02:47:11 -07:00

17 lines
750 B
JavaScript

// Test-only globals so modules that transitively import the encryption web
// worker (fsEncrypt -> encryptRClone -> encryptRClone.worker) can load under
// Node. The worker module references `self` / `addEventListener` at import
// time, before any mocha before() hook runs, so this must be a --require.
// Source is unchanged; production runs these in a real Worker context.
if (typeof globalThis.self === "undefined") {
globalThis.self = globalThis;
}
if (typeof globalThis.addEventListener !== "function") {
globalThis.addEventListener = () => {};
}
if (typeof globalThis.postMessage !== "function") {
globalThis.postMessage = () => {};
}
if (typeof globalThis.crypto === "undefined") {
globalThis.crypto = require("crypto").webcrypto;
}