Skip to content
This repository was archived by the owner on Oct 15, 2026. It is now read-only.

refactor(cloudSync): extract SyncProvider interface - #8

Merged
kevinraymond merged 4 commits into
mainfrom
claude/extract-sync-provider-interface-eA5xa
Apr 27, 2026
Merged

kevinraymond merged 4 commits into
mainfrom
claude/extract-sync-provider-interface-eA5xa

Conversation

@kevinraymond

@kevinraymond kevinraymond commented Apr 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 1 step 1 of the post-review plan: extract a backend-agnostic SyncProvider interface so the sync engine no longer depends on Google Drive directly. Pure refactor — no behavior change.

  • New src/shared/cloudSync/providers/types.ts defines SyncProvider (getManifest/setManifest, list/read/write/delete, getKeyData/setKeyData, clearAll) plus SyncObjectInfo and ProviderKeyData. No Drive-isms in the contract.
  • New src/shared/cloudSync/providers/gdriveProvider.ts exposes createGoogleDriveProvider(accessToken) and adapts the existing Drive client to the interface. Calls dispatch through import * as gdrive from './gdrive' so existing vi.mock setups in the test suite keep intercepting at the gdrive seam.
  • syncEngine.ts now talks exclusively to a SyncProvider via a getProvider() helper — every gdrive.*(tokens.accessToken, …) call site is replaced. DriveApiError is still imported for the auth-error instanceof check.
  • providers/gdrive.ts is otherwise unchanged; the DriveKeyData interface is removed in favor of the shared ProviderKeyData type.

This unblocks Phase 2 features #2 (alt backends — WebDAV / iCloud / encrypted file export) and #5 (encrypted .raftbundle session sharing).

Out of scope (intentional)

  • src/background/index.ts still imports gdrive directly for the CLOUD_RECOVER_WITH_KEY / setup / disconnect flows. Migrating those touches setup semantics and broadens this PR — they can adopt the interface alongside the bg modularization step.

Env hygiene (separate commit on this branch)

While bringing up the local toolchain I hit two pre-existing issues:

  1. eslint.config.js imports @eslint/js but it was not in package.json — pnpm lint failed on a fresh clone any time pnpm didn't transitively hoist it. Added as an explicit devDependency.
  2. pnpm-lock.yaml was at lockfileVersion 6 (pnpm 8 era), so anyone on current pnpm regenerates it on install. Added "packageManager": "pnpm@10.33.0" to pin via corepack and regenerated the lockfile to v9.

The lockfile diff is large (~6.5k lines) because of the v6→v9 format conversion; actual dependency churn is just the new @eslint/js entry.

Test plan

  • pnpm typecheck — clean
  • pnpm lint — clean (now works on a fresh install)
  • pnpm vitest run — 734/734 passing, including all tests/unit/syncEngine.test.ts mocks that exercise the gdrive seam
  • Manual smoke: connect to Drive, push a session, delete it, full sync, disconnect — confirm no behavior change vs main
  • Spot-check CLOUD_RECOVER_WITH_KEY path in src/background/index.ts (uses gdrive directly — left as-is, should be unaffected)

https://claude.ai/code/session_01PzcBu8A6n4joSexQRhEWHv


Generated by Claude Code

claude added 2 commits April 26, 2026 06:22
Introduce a backend-agnostic SyncProvider contract (list, read, write,
delete, getManifest/setManifest, getKeyData/setKeyData, clearAll) in
providers/types.ts. The Drive client in providers/gdrive.ts is
unchanged; a new providers/gdriveProvider.ts adapts it to the interface
and is what syncEngine consumes.

Pure refactor — no behavior change, no new network surface, encryption
layer untouched. Unblocks alt sync backends (WebDAV/iCloud) and
encrypted bundle export by giving the engine a single seam to swap.

Background's direct gdrive imports (recovery flow) are intentionally
left as-is for this PR; they can adopt the interface in a follow-up.

https://claude.ai/code/session_01PzcBu8A6n4joSexQRhEWHv
eslint.config.js imports @eslint/js but the package was not declared as
a direct devDependency, so it only resolved when pnpm happened to hoist
it transitively — pnpm lint failed cleanly on a fresh clone with strict
hoisting. Add it explicitly.

Pin packageManager to pnpm@10.33.0 (corepack) so contributors no longer
silently produce mismatched lockfile versions; the lockfile is
regenerated to v9 to match.

https://claude.ai/code/session_01PzcBu8A6n4joSexQRhEWHv
@codecov-commenter

codecov-commenter commented Apr 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

claude added 2 commits April 27, 2026 05:17
The previous pin (version: 8) conflicts with the packageManager pin in
package.json (pnpm@10.33.0) and can't read a v9 lockfile, which broke
all four CI jobs at the install step. Dropping the explicit version
makes the action read pnpm@10.33.0 directly from package.json, so any
future bump only needs a single edit.

https://claude.ai/code/session_01PzcBu8A6n4joSexQRhEWHv
Adds unit tests for the SyncProvider adapter built on top of providers/
gdrive.ts. Pins each method's delegation contract (correct gdrive
function called with correct args) and the list() translation from
DriveFile metadata to SyncObjectInfo (.enc-suffix stripping, size
parseInt, modifiedTime → epoch ms, undefined passthrough for missing
fields).

Establishes the test pattern future SyncProvider implementations
(WebDAV, iCloud, encrypted bundle) will follow.

https://claude.ai/code/session_01PzcBu8A6n4joSexQRhEWHv
@kevinraymond
kevinraymond merged commit c659ff1 into main Apr 27, 2026
7 checks passed
@kevinraymond
kevinraymond deleted the claude/extract-sync-provider-interface-eA5xa branch April 27, 2026 05:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants