Repository navigation
fix(browser): keep cookie-import warnings readable from newer hosts - #15002
Conversation
The import summary is cast, not decoded, coming off the runtime RPC wire, so a newer host can publish a warning code or undecryptable reason this build has never seen. Both switches then matched nothing and returned undefined, which rendered as a blank toast.warning(undefined). #14683 replaced the absorbing default: arm with case 'unknown' to satisfy switch-exhaustiveness-check, which forbids default: on an exhaustive switch. Guard before each switch instead: narrow the wire value against the handled set and route anything else to a generic message. The handled sets are keyed by the unions themselves, so a fourth member still fails typecheck here.
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds localized fallback messages for unknown cookie-import warning codes and undecryptable-cookie reasons. Runtime validation now detects unsupported values before known-value handling. New tests verify that unknown and array-valued values produce non-empty warning toasts and preserve failed-cookie counts where applicable. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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.
🧹 Nitpick comments (1)
src/renderer/src/lib/browser-cookie-import-toast.test.ts (1)
104-124: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winOptionally tighten both fallback tests to assert the exact translated message.
The current checks confirm that each fallback produces a non-empty string, but exact-message assertions would also catch selecting the wrong localization key while still returning plausible text.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f8665c3f-42ca-4381-ba9b-07ec6b10f910
📒 Files selected for processing (3)
src/renderer/src/i18n/locales/en.jsonsrc/renderer/src/lib/browser-cookie-import-toast.test.tssrc/renderer/src/lib/browser-cookie-import-toast.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 0 remain after this review.
Object.hasOwn coerces its key, so the membership guards admitted any value whose toString() matched a handled variant. A host that widened reason to an array sends ['unknown'], which passed the guard and then fell straight back out of the switch -- the same undefined-to-toast.warning blank the guards exist to prevent. Take unknown and check typeof first, matching isTopLevelView and isTuiAgent. The Record membership sets still fail typecheck on a new union member.
Review loop — CLEAN at
|
| gate | result |
|---|---|
config/scripts/check-changed-code-quality.mjs |
exit 0 — 0/0/0, and all three scans proven live by injection (2/1/1 findings caught) |
pnpm run typecheck |
exit 0 |
| vitest | 585 files, 5419 passed |
| localization ×3 | exit 0 |
| CI | 44 pass, 0 fail |
Same defect class found elsewhere — reported, not fixed here
src/renderer/src/lib/folder-workspace-path-status.ts:11 and :39 switch on status.reason off the same cast wire (repos.ts:1658, :2580). An unrecognized reason returns undefined, and FolderPathStatusIndicator.tsx:20 treats that as "nothing to show" — so the broken-folder marker disappears entirely and a broken folder workspace renders as healthy. Worse than the blank toast, since the warning is lost rather than merely empty. Two other same-shaped switches were checked and cleared: their discriminants are computed locally.
Deliberately left for a separate change — see below.
Structural note
src/shared/runtime-rpc-envelope.ts:26 declares result: z.unknown() inside the zod-validated success envelope, and unwrapRuntimeRpcResult returns it as TResult with no decode. So the envelope is validated and the payload is asserted — across 277 callRuntimeRpc<…> call sites in 72 files. There is also no assertNever/softAssertNever helper in the tree, which is why this guard sits before the switch instead of in a default arm — the shape that produced the P1 above.
This PR is the right local fix. The recurring class wants a decode at the transport boundary, which is a separate piece of work.
…ds a new reason FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast #15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape #15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move #15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on #15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
…ds a new reason (#15027) FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast #15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape #15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move #15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on #15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
…tablyai#15002) * fix(browser): keep cookie-import warnings readable from newer hosts The import summary is cast, not decoded, coming off the runtime RPC wire, so a newer host can publish a warning code or undecryptable reason this build has never seen. Both switches then matched nothing and returned undefined, which rendered as a blank toast.warning(undefined). stablyai#14683 replaced the absorbing default: arm with case 'unknown' to satisfy switch-exhaustiveness-check, which forbids default: on an exhaustive switch. Guard before each switch instead: narrow the wire value against the handled set and route anything else to a generic message. The handled sets are keyed by the unions themselves, so a fourth member still fails typecheck here. * fix(browser): reject non-string cookie-import warning discriminants Object.hasOwn coerces its key, so the membership guards admitted any value whose toString() matched a handled variant. A host that widened reason to an array sends ['unknown'], which passed the guard and then fell straight back out of the switch -- the same undefined-to-toast.warning blank the guards exist to prevent. Take unknown and check typeof first, matching isTopLevelView and isTuiAgent. The Record membership sets still fail typecheck on a new union member.
…ds a new reason (stablyai#15027) FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast stablyai#15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape stablyai#15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move stablyai#15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on stablyai#15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
…tablyai#15002) * fix(browser): keep cookie-import warnings readable from newer hosts The import summary is cast, not decoded, coming off the runtime RPC wire, so a newer host can publish a warning code or undecryptable reason this build has never seen. Both switches then matched nothing and returned undefined, which rendered as a blank toast.warning(undefined). stablyai#14683 replaced the absorbing default: arm with case 'unknown' to satisfy switch-exhaustiveness-check, which forbids default: on an exhaustive switch. Guard before each switch instead: narrow the wire value against the handled set and route anything else to a generic message. The handled sets are keyed by the unions themselves, so a fourth member still fails typecheck here. * fix(browser): reject non-string cookie-import warning discriminants Object.hasOwn coerces its key, so the membership guards admitted any value whose toString() matched a handled variant. A host that widened reason to an array sends ['unknown'], which passed the guard and then fell straight back out of the switch -- the same undefined-to-toast.warning blank the guards exist to prevent. Take unknown and check typeof first, matching isTopLevelView and isTuiAgent. The Record membership sets still fail typecheck on a new union member.
…ds a new reason (stablyai#15027) FolderWorkspacePathStatus is cast, not decoded, off the runtime RPC wire -- runtime-rpc-envelope declares result: z.unknown(), so unwrapRuntimeRpcResult hands back whatever the host sent. Both title and description switch on status.reason with no runtime guard, so a newer host publishing a fifth reason matched nothing and returned undefined. FolderPathStatusIndicator's `!title` check then dropped the whole indicator, and a broken folder workspace rendered as healthy -- worse than the blank toast stablyai#15002 fixed, because there the warning was empty and here it is gone. Guard before each switch, the shape stablyai#15002 landed. A default: arm is not available: the type-aware config sets allowDefaultCaseForExhaustiveSwitch:false and rejects one with switch-exhaustiveness-check. Extract that guard into isHandledWireDiscriminant instead of hand-writing a third and fourth copy, and move stablyai#15002's two bespoke guards onto it. It takes unknown and checks typeof before Object.hasOwn -- hasOwn coerces its key, so a host that widened the field to an array sends ['missing'], which a hasOwn-only guard admits before the switch drops it straight back out. That was the P1 found in review on stablyai#15002; one implementation makes it structural instead of tribal. An unrecognized reason gets its own copy rather than reusing 'unavailable'. The unavailable remedy -- "Check the runtime or SSH connection and try again" -- is a false lead here: the host did check and reported the folder unusable, so retrying and inspecting a healthy connection wastes the user's time. Update Orca is the real remedy. Adding a fifth reason still fails typecheck in two places: TS2741 on the Record and TS2366 plus switch-exhaustiveness-check on both switches.
Problem
formatCookieImportWarningswitches onwarning.code, and insidecookies-undecryptableonwarning.reason, with explicit cases only and no fallback. TypeScript believes both switches are exhaustive because each union is closed at compile time. They are not exhaustive at runtime.The summary crosses the runtime RPC wire —
store/slices/browser.ts→orca-runtime-browser.ts— and the response is cast, not decoded (runtime/runtime-rpc-client.ts:91,response as RuntimeRpcResponse<TResult>). A newer remote host that publishes a fourthreason(or a thirdcode) therefore reaches an older client, nothing matches, the function returnsundefined, andemitBrowserCookieImportToastrenderstoast.warning(undefined)— a blank warning toast on a partly-failed import.This is a regression from #14683: the original code had a
default:arm that absorbed unknown reasons, and it was replaced withcase 'unknown':to satisfyswitch-exhaustiveness-check.Why not just restore
default:typescript/switch-exhaustiveness-checkis configured withallowDefaultCaseForExhaustiveSwitch: falsein both.oxlintrc.jsonandconfig/oxlint-code-quality-type-aware.json. Verified directly — adding adefault:arm produces:Fix
A runtime guard before each switch. The incoming value is widened to
string, checked against the set of variants this build actually handles, and anything else routes to a generic message. The switches stay exhaustive over the narrowed union, so the lint gate stays satisfied.The handled sets are
Record<Union, true>keyed by the unions themselves, so this strengthens rather than weakens the compile-time guarantee. Adding a fourth reason toBrowserCookieImportSummarybreaks the build here in two places:Fallback copy
Neither message claims a cause it cannot know, and both give the user something to do:
Both go through
translate()like their neighbours;en.jsonsynced viapnpm run sync:localization-catalog.Test evidence — red before, green after
Four tests feed a
reasonand acodeoutside the declared unions, cast at the test boundary since the point is that the wire can carry them. Two cover unrecognized string values; two cover non-string values (for example['unknown']), which an independent review found still slipped through —Object.hasOwncoerces its key, so an array whosetoString()matches a handled variant passed the first version of the guard and fell straight back out of the switch.Against unmodified main (
b6d5972ec4):After the fix:
Gates
node config/scripts/check-changed-code-quality.mjsChanged-code quality gate passed since b6d5972ec453.— 0 findings on all three scanspnpm run typecheck--config config/vitest.config.ts)verify:localization-catalogVerified 12231 localization key references against en.json.verify:localization-extractionverify:localization-coverageLocalization coverage check passed with 12 allowlisted candidates.All three oxlint scans were proven live, not silently dead, by injecting violations and confirming each caught them:
Scope
Three files. No refactor of the toast module, no renames, no changes to the cookie-import main-process code.