fix(browser): report cookies omitted from a partial import

This commit is contained in:
Luke Parker 2026-11-13 14:44:06 +10:00
parent 4688a95bce
commit e6c423feac
5 changed files with 32 additions and 5 deletions

View file

@ -105,6 +105,8 @@ export default {
"signins.dismiss": "Not now",
"signins.imported.one": "Imported {{count}} cookie.",
"signins.imported.other": "Imported {{count}} cookies.",
"signins.imported.incomplete.one": "Imported {{count}} cookie. Not imported: {{omitted}}.",
"signins.imported.incomplete.other": "Imported {{count}} cookies. Not imported: {{omitted}}.",
"signins.imported.from.one": "Imported {{count}} cookie from {{browser}}",
"signins.imported.from.other": "Imported {{count}} cookies from {{browser}}",
"signins.imported.partial.one":

View file

@ -7,7 +7,7 @@ import { usePlugin } from "@opencode/plugin/gui"
import { choiceLabel, Glyph, profileChoices, type Choice } from "./choices"
import type definition from "./index"
import { createProfileJobs } from "./jobs"
import { importedCookies } from "./jobs-machine"
import { importedCookies, importLoss } from "./jobs-machine"
/**
* The pane's offer to bring sign-ins from the browser the user already uses, until they import or decline once. A
@ -45,8 +45,7 @@ export function SignInOffer(props: { variant: "bar" | "card"; imported: () => vo
const job = last.job
const choice = choices().find((item) => item.source.id === job.source && item.profile.id === job.profile)
const outcome = last.outcome
// Cookies the browser keeps for itself alone stayed behind: the message says how many, and what to do.
const partial = outcome.type === "imported" && outcome.result.type === "imported" && outcome.result.protected > 0
const partial = outcome.type === "imported" && outcome.result.type === "imported" && importLoss(outcome.result)
return {
choice,

View file

@ -1,6 +1,7 @@
import { expect, test } from "bun:test"
import {
importedCookies,
importLoss,
initialJobsState,
lastFinished,
runningJob,
@ -17,6 +18,14 @@ const imported = {
result: { type: "imported" as const, imported: 3, skipped: 0, protected: 1, failed: 0 },
}
test("a partial import counts every omitted row without blaming malformed or expired cookies on encryption", () => {
const result = imported.result
expect(importLoss({ ...result, protected: 0 })).toBeUndefined()
expect(importLoss(result)).toEqual({ reason: "protected", count: 1 })
expect(importLoss({ ...result, protected: 0, failed: 1 })).toEqual({ reason: "other", count: 1 })
expect(importLoss({ ...result, skipped: 2, failed: 3 })).toEqual({ reason: "other", count: 6 })
})
function replay(events: readonly JobsEvent[]) {
return events.reduce(
(result, event) => {

View file

@ -128,3 +128,11 @@ export function lastFinished(state: JobsState) {
export function importedCookies(outcome: Outcome) {
return outcome.type === "imported" && outcome.result.type === "imported" ? outcome.result.imported : 0
}
/** Give encryption-specific advice only when it accounts for every cookie that stayed behind. */
export function importLoss(result: Extract<ImportResult, { type: "imported" }>) {
if (result.failed || result.skipped)
return { reason: "other", count: result.failed + result.skipped + result.protected } as const
if (result.protected) return { reason: "protected", count: result.protected } as const
}

View file

@ -5,6 +5,7 @@ import type definition from "./index"
import { BrowserProfile, type ExtensionCompatibility, type ProfileSource } from "./profile/ipc"
import {
importedCookies,
importLoss,
initialJobsState,
lastFinished,
runningJob,
@ -190,14 +191,22 @@ export function createProfileJobs(
if (result.type === "failed") return { text: ctx.t(`signins.failed.${result.reason}`), error: true }
if (result.imported === 0 && result.protected > 0)
const loss = importLoss(result)
if (loss?.reason === "other")
return {
text: ctx.plural("signins.imported.incomplete", result.imported, { omitted: loss.count }),
error: result.imported === 0,
}
if (result.imported === 0 && loss)
return {
text: browser ? ctx.t("signins.protected.named", { browser }) : ctx.t("signins.protected"),
error: true,
}
// Chrome and Edge on Windows mix readable cookies with app-bound ones: say what was left behind and what to do.
if (result.protected > 0)
if (loss)
return {
text: browser
? ctx.plural("signins.imported.partial.named", result.imported, { browser, protected: result.protected })