Repository navigation
fix(browser): preserve partitioned Google cookies on import - #14086
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe cookie import flow now removes existing cookies individually through 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/browser/browser-cookie-import-policy.test.ts (1)
234-257: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the rollback-failure branch.
This test covers the successful rollback path.
removeAllCookiesExcepthas a second failure branch: whenrestoreImportedDomainCookiesalso fails, it throwsAggregateErrorwith the messageCookie clearing and rollback failed. That branch stays untested. Add a case wheresetrejects after aremoverejection.♻️ Proposed additional test
+ it('reports clearing and rollback failure when restoration also fails', async () => { + const get = vi + .fn() + .mockResolvedValue([ + cookie('.example.com', 'first', '/one'), + cookie('.example.com', 'second', '/two') + ]) + const remove = vi.fn().mockImplementation(async (_url: string, name: string) => { + if (name === 'second') { + throw new Error('store unavailable') + } + }) + const set = vi.fn().mockRejectedValue(new Error('set unavailable')) + + await expect( + removeAllCookiesExcept({ get, remove, set }, () => false) + ).rejects.toThrow('Cookie clearing and rollback failed') + })src/main/browser/browser-cookie-import-partition.electron.test.ts (1)
112-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDo not derive the policy entry path from
process.cwd().
process.cwd()depends on how Vitest starts. If a project config sets a different root, the Vite build resolves a wrong entry and the fixture fails. Derive the path from the test file location instead.♻️ Proposed fix
+import { fileURLToPath } from 'node:url' ... - lib: { - entry: join(process.cwd(), 'src/main/browser/browser-cookie-import-policy.ts'), + lib: { + entry: fileURLToPath(new URL('./browser-cookie-import-policy.ts', import.meta.url)),
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 74a34b89-d206-40cc-807c-6c43f59d6009
📒 Files selected for processing (6)
src/main/browser/browser-cookie-import-google-exclusion.test.tssrc/main/browser/browser-cookie-import-partition.electron.test.tssrc/main/browser/browser-cookie-import-policy.test.tssrc/main/browser/browser-cookie-import-policy.tssrc/main/browser/browser-cookie-import.test.tssrc/main/browser/browser-cookie-import.ts
Electron QA (STA-4013) — partitioned Google cookie survives native importResult: PASS. A real partitioned Google-family cookie was present before a native Chromium import, the import was run through the app UI, and the same cookie was still present afterward with the same partition identity. Import still succeeded and the stale non-excluded cookie was replaced, so the fix did not disable importing. Evidence lives on scratch branch CDP owner verificationIsolated dev instance launched from this worktree via
HEAD confirmed: What each screenshot proves1. Before import — partitioned cookie present Seeded 2. Native Chromium import menu (not file import) Import browser data detected Google Chrome and Safari. Menu shows From Google Chrome. 3. UI path used: From Google Chrome → stably.ai Clicked the real Import control through to Chrome profile stably.ai. 4. After import — same cookie, same partition key; stale gone; import not a no-op CDP re-read: 5. Import succeeded in product UI Settings → Browser → Session & Cookies shows Default Active with source Google Chrome (stably.ai). Gaps
|
Independent Electron QA (Grok / Playwright CDP)HEAD: Identity: ActionPrepared isolated profile CDP assertions (
|
…A-4065) PR #14086 replaced the bulk clear with one Electron cookies.remove() per removable cookie so partitioned excluded cookies survive an import. That is required whenever something must be preserved, but it also runs when nothing is excluded, where a single clearStorageData is equivalent and far cheaper: 421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43. The fast path is gated on the same unfiltered cookies.get() the exclusion predicate already reads, which an Electron fixture now proves returns partitioned cookies, so "no exclusions in the snapshot" means "nothing in the jar to preserve".
…e family (STA-4065) (#14131) * perf(browser): bulk clear cookies when an import excludes nothing (STA-4065) PR #14086 replaced the bulk clear with one Electron cookies.remove() per removable cookie so partitioned excluded cookies survive an import. That is required whenever something must be preserved, but it also runs when nothing is excluded, where a single clearStorageData is equivalent and far cheaper: 421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43. The fast path is gated on the same unfiltered cookies.get() the exclusion predicate already reads, which an Electron fixture now proves returns partitioned cookies, so "no exclusions in the snapshot" means "nothing in the jar to preserve". * fix(browser): protect cookie clear fast-path race (STA-4065) * test(browser): keep the no-bulk-clear assertion honest after the clearData switch The mocked session still exposed clearStorageData, so asserting it was never called could no longer fail once the fast path moved to clearData. * docs(browser): stop the fallback comment from asserting a rollback The per-cookie path's rollback is being removed by STA-4061; the comment only needs to say the fallback re-removes what survived. * test(browser): keep the STA-4061 rollback fixture on the per-cookie path The bulk fast path clears a jar with no excluded cookie in one call, which would have made every assertion in the partition-rollback fixture vacuous. Give it a live Google cookie so the partial-failure clear still runs, and assert the bulk call count is zero so a future widening fails loudly. * perf(browser): always bulk clear cookies, not only when nothing is excluded The fast path only fired when the jar held no Google cookie, but this import exists for Google, so a Google cookie is normally present and the common case still paid one native remove per cookie. Measured on Electron 43, clearData excludeOrigins preserves the whole google.com registrable family -- host, leading-dot, subdomain and partitioned cookies -- so the bulk call is safe with cookies to keep, and the gate was never load-bearing for preservation. Drop the caller-supplied exclusion predicate so the preserved set has exactly one source of truth: a predicate that disagreed with NON_TRANSPLANTABLE_DOMAINS would have deleted cookies the bulk call is meant to keep. The per-cookie loop stays as the fallback for a rejected bulk clear, carrying the same exclusion. * fix(browser): re-read the cookie jar after a rejected bulk clear clearData can empty part of the jar before rejecting, so the per-cookie fallback was working from a snapshot taken before the attempt: it retried removals for cookies that were already gone and could not see cookies that arrived during the clear. Re-read on rejection only. Also repairs three fixtures that mocked the session with clearStorageData after the call moved to clearData. The missing method threw, the catch swallowed it, and every one of those tests silently asserted per-cookie behaviour while believing it covered exclusion. Records the registrable-domain invariant at NON_TRANSPLANTABLE_DOMAINS, since excludeOrigins derives one origin per entry, and extends the real-Electron fixture to prove http-only and domain-scoped Google cookies survive alongside the partitioned one.
…e family (STA-4065) (stablyai#14131) * perf(browser): bulk clear cookies when an import excludes nothing (STA-4065) PR stablyai#14086 replaced the bulk clear with one Electron cookies.remove() per removable cookie so partitioned excluded cookies survive an import. That is required whenever something must be preserved, but it also runs when nothing is excluded, where a single clearStorageData is equivalent and far cheaper: 421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43. The fast path is gated on the same unfiltered cookies.get() the exclusion predicate already reads, which an Electron fixture now proves returns partitioned cookies, so "no exclusions in the snapshot" means "nothing in the jar to preserve". * fix(browser): protect cookie clear fast-path race (STA-4065) * test(browser): keep the no-bulk-clear assertion honest after the clearData switch The mocked session still exposed clearStorageData, so asserting it was never called could no longer fail once the fast path moved to clearData. * docs(browser): stop the fallback comment from asserting a rollback The per-cookie path's rollback is being removed by STA-4061; the comment only needs to say the fallback re-removes what survived. * test(browser): keep the STA-4061 rollback fixture on the per-cookie path The bulk fast path clears a jar with no excluded cookie in one call, which would have made every assertion in the partition-rollback fixture vacuous. Give it a live Google cookie so the partial-failure clear still runs, and assert the bulk call count is zero so a future widening fails loudly. * perf(browser): always bulk clear cookies, not only when nothing is excluded The fast path only fired when the jar held no Google cookie, but this import exists for Google, so a Google cookie is normally present and the common case still paid one native remove per cookie. Measured on Electron 43, clearData excludeOrigins preserves the whole google.com registrable family -- host, leading-dot, subdomain and partitioned cookies -- so the bulk call is safe with cookies to keep, and the gate was never load-bearing for preservation. Drop the caller-supplied exclusion predicate so the preserved set has exactly one source of truth: a predicate that disagreed with NON_TRANSPLANTABLE_DOMAINS would have deleted cookies the bulk call is meant to keep. The per-cookie loop stays as the fallback for a rejected bulk clear, carrying the same exclusion. * fix(browser): re-read the cookie jar after a rejected bulk clear clearData can empty part of the jar before rejecting, so the per-cookie fallback was working from a snapshot taken before the attempt: it retried removals for cookies that were already gone and could not see cookies that arrived during the clear. Re-read on rejection only. Also repairs three fixtures that mocked the session with clearStorageData after the call moved to clearData. The missing method threw, the catch swallowed it, and every one of those tests silently asserted per-cookie behaviour while believing it covered exclusion. Records the registrable-domain invariant at NON_TRANSPLANTABLE_DOMAINS, since excludeOrigins derives one origin per entry, and extends the real-Electron fixture to prove http-only and domain-scoped Google cookies survive alongside the partitioned one. (cherry picked from commit e590683)
…e family (STA-4065) (stablyai#14131) * perf(browser): bulk clear cookies when an import excludes nothing (STA-4065) PR stablyai#14086 replaced the bulk clear with one Electron cookies.remove() per removable cookie so partitioned excluded cookies survive an import. That is required whenever something must be preserved, but it also runs when nothing is excluded, where a single clearStorageData is equivalent and far cheaper: 421ms -> 7.3ms at 1k cookies and 1764ms -> 20.1ms at 3k on Electron 43. The fast path is gated on the same unfiltered cookies.get() the exclusion predicate already reads, which an Electron fixture now proves returns partitioned cookies, so "no exclusions in the snapshot" means "nothing in the jar to preserve". * fix(browser): protect cookie clear fast-path race (STA-4065) * test(browser): keep the no-bulk-clear assertion honest after the clearData switch The mocked session still exposed clearStorageData, so asserting it was never called could no longer fail once the fast path moved to clearData. * docs(browser): stop the fallback comment from asserting a rollback The per-cookie path's rollback is being removed by STA-4061; the comment only needs to say the fallback re-removes what survived. * test(browser): keep the STA-4061 rollback fixture on the per-cookie path The bulk fast path clears a jar with no excluded cookie in one call, which would have made every assertion in the partition-rollback fixture vacuous. Give it a live Google cookie so the partial-failure clear still runs, and assert the bulk call count is zero so a future widening fails loudly. * perf(browser): always bulk clear cookies, not only when nothing is excluded The fast path only fired when the jar held no Google cookie, but this import exists for Google, so a Google cookie is normally present and the common case still paid one native remove per cookie. Measured on Electron 43, clearData excludeOrigins preserves the whole google.com registrable family -- host, leading-dot, subdomain and partitioned cookies -- so the bulk call is safe with cookies to keep, and the gate was never load-bearing for preservation. Drop the caller-supplied exclusion predicate so the preserved set has exactly one source of truth: a predicate that disagreed with NON_TRANSPLANTABLE_DOMAINS would have deleted cookies the bulk call is meant to keep. The per-cookie loop stays as the fallback for a rejected bulk clear, carrying the same exclusion. * fix(browser): re-read the cookie jar after a rejected bulk clear clearData can empty part of the jar before rejecting, so the per-cookie fallback was working from a snapshot taken before the attempt: it retried removals for cookies that were already gone and could not see cookies that arrived during the clear. Re-read on rejection only. Also repairs three fixtures that mocked the session with clearStorageData after the call moved to clearData. The missing method threw, the catch swallowed it, and every one of those tests silently asserted per-cookie behaviour while believing it covered exclusion. Records the registrable-domain invariant at NON_TRANSPLANTABLE_DOMAINS, since excludeOrigins derives one origin per entry, and extends the real-Electron fixture to prove http-only and domain-scoped Google cookies survive alongside the partitioned one.









Summary
Electron coverage
A real Electron 43 process creates a partitioned accounts.google.com cookie through Chromium CDP, runs the production selective-removal implementation, and verifies the complete CDP cookie remains unchanged while a stale non-Google cookie is removed. The test also pins the public API gap: Electron Cookies.get exposes the cookie but omits partitionKey, so snapshot/restore cannot preserve partition identity. Linux runs the same fixture through Xvfb with the required sandbox override.
Performance
This intentionally restores the O(N) bounded-concurrency removal path. The real-Electron measurements recorded for #13966 were 3.6 ms at 100 cookies, 195.2 ms at 1,000, and 2,226.6 ms at 3,300 versus 1.0 ms, 8.8 ms, and 35.8 ms for bulk clear (3.5x to 62.1x slower); correctness takes priority because the bulk path can invalidate active Google sessions.
Validation
Fixes STA-4013.