Skip to content

refactor(events): add typed IPC contracts for compile-time safety#2843

Merged
afonsojramos merged 4 commits intomainfrom
typed-ipc-contracts
May 6, 2026
Merged

refactor(events): add typed IPC contracts for compile-time safety#2843
afonsojramos merged 4 commits intomainfrom
typed-ipc-contracts

Conversation

@afonsojramos
Copy link
Copy Markdown
Member

Summary

Adds an EventContracts type map keyed by every IPC channel ({request, response}) and makes handleMainEvent, invokeMainEvent, sendMainEvent, onMainEvent, sendRendererEvent, and onRendererEvent generic on the event key. Handler return types and renderer call sites are now compile-checked against the same single source of truth in src/shared/events.ts.

This is the only layer that would have caught #2839's decryptStringAsync regression at tsc time. Any future drift between IPC handler signatures and renderer expectations now fails the build instead of shipping.

What it catches

Verified with deliberate breakages — all error at compile time:

  • Handler returning the wrong type (number for an event whose response is string).
  • Handler returning an object when contract says string (the exact chore(deps): update electron to v42 and migrate to async safeStorage #2839 bug).
  • invokeMainEvent called with extra args on a no-payload event.
  • invokeMainEvent called with no args on a payload-required event.
  • sendMainEvent called with the wrong arg type.
  • New event added to EVENTS without a contract entry — AssertEventCoverage fires.

Notable changes

  • Drops invokeMainEventWithData (subsumed by the now-generic invokeMainEvent).
  • Drops the manual as Promise<IKeyboardShortcutResult> cast at the keyboard-shortcut call site.
  • Drops the runtime as IKeyboardShortcut cast inside system.ts.
  • Inlines the gitify: event prefix as a literal so EVENTS.* values are literal types.

Test plan

  • pnpm tsc --noEmit passes.
  • pnpm test — 933/933 (renderer route timeouts are a preexisting flake; they pass on retry and when run in isolation).
  • pnpm lint:check — 0 errors.
  • Manual contract drift verification: 6 deliberate breakages, all caught.

@github-actions github-actions Bot added the refactor Refactoring of existing feature label May 6, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

@afonsojramos afonsojramos merged commit e94aaba into main May 6, 2026
17 checks passed
@afonsojramos afonsojramos deleted the typed-ipc-contracts branch May 6, 2026 22:16
@github-actions github-actions Bot added this to the Release 7.0.0 milestone May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring of existing feature

Development

Successfully merging this pull request may close these issues.

2 participants