Repository navigation
IPC events: event names as Rust constants and a lint check that every frontend listener matches an emitted event #918
Copy link
Copy link
Open
Labels
Milestone
Description
Goal
Renaming an event on one side without the other makes npm run lint fail, instead of the UI silently missing updates.
Context
- Rust emits events through ~45
emit_*helpers incrates/app-logic/src/events.rs(privatefn emit(emitter, event: &str, payload)at:37, string literals like"data-changed"at:77), plus direct emits incrates/app-shell/src/lib.rs("entitlements:changed",:1066),crates/app-shell/src/event_emitter.rsandcrates/app-logic/src/auto_reconnect.rs. - The frontend subscribes in
apps/smart-ssh-community/frontend/src/events.ts(~47 distinct names vialisten("…")) and in a few components. scripts/check-tauri-commands.mjs(Issue Check Tauri command definitions, registrations and frontend calls in CI #101, run as part ofnpm run lint) checks command names (definition ↔generate_handler!↔invoke("…")↔ALLOWED_WHILE_LOCKED) but not event names. Today the names match (manually checked); nothing keeps it that way.- Header comment of
src/types.ts:1still says the DTOs live incrates/app-shell/src/dto.rs; they are incrates/app-logic/src/dto.rs.
Requirements
crates/app-logic/src/events.rs: onepub mod names { pub const DATA_CHANGED: &str = "data-changed"; … }with every event name the core emits; allemit_*helpers and the direct emits inapp-shell/auto_reconnect.rsuse these constants. No event name literal remains at an emit site.- Frontend:
src/eventNames.tswith the same names asexport const EVENT = { DATA_CHANGED: "data-changed", … } as const;events.tsand components listen via these constants. - Extend
scripts/check-tauri-commands.mjs(or a siblingcheck-event-names.mjsadded tonpm run lint): parse thenamesmodule (text-based, like the existing script) andeventNames.ts; fail when (a) a frontend constant has no Rust counterpart, (b) alisten(/once(call uses a string literal instead of a constant, (c) a Rust constant is not in the frontend list – allowed only if listed in an explicit "not consumed by the core UI" allowlist with a reason (extensions may consume them). Events emitted by extensions (plugin events) are out of scope. - Fix the
types.tsheader path. - Unit tests for the new check in the style of
tauriCommandsCheck.test.ts.
Acceptance Criteria
- All core event names are constants;
grep -n 'emit(emitter, "' crates/app-logic/src/events.rsreturns nothing. -
npm run lintfails for: a renamed Rust constant, a renamed frontend constant, alisten("literal")(each proven by a unit test of the check on fixtures). -
npm run lintpasses on the real code; existing event tests (Rust and frontend) pass. -
types.tsheader namescrates/app-logic/src/dto.rs.
Technical Notes
- Payload types are not covered here (generated types issue).
events.rscarries no secrets in payloads (uses_stored_sudo_password: bool,events.rs~:378); keep it that way.
Spec impact: none
Related Work
- Check Tauri command definitions, registrations and frontend calls in CI #101 (command name check); follow-up IPC types: generate the event payload types and type the frontend listeners with them #920 (payload types)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
P2 - Normal
Activity
4 remaining items