-
Notifications
You must be signed in to change notification settings - Fork 1
Add an end-to-end test that exercises both event routers #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a promisified MessagePort utility, upgrades test-related devDependencies and TS lib targets, and introduces Vitest integration tests and minor test type-cast fixes for Thunderbird/Ghostbird messaging scenarios. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant PMP as PromisifiedMessagePort
participant MP as MessagePort
participant Q as PromisifyingQueue
App->>PMP: send(msg)
PMP->>MP: postMessage(msg)
MP-->>PMP: onmessage(data)
PMP->>Q: push(data)
App->>PMP: dequeueReceived()
PMP->>Q: dequeue()
Q-->>App: TResponse
App->>PMP: close()
PMP->>MP: postMessage(null)
MP-->>PMP: onmessage(null)
PMP->>PMP: handleClose()
PMP->>Q: notifyError()
PMP->>MP: close()
sequenceDiagram
participant Test as Ghostbird Test
participant BG as Background Router
participant Compose as Compose Router
participant Channel as MessageChannel
Test->>Channel: create()
Test->>BG: init with mocked injector + channel.port1
Test->>Compose: init with mocked injector + channel.port2
Test->>Compose: send EditorChangeResponse(initial text)
Compose->>Channel: forward message
Channel-->>BG: receive message
BG->>Test: record server snapshot
BG->>Compose: send updated content
Compose->>Test: assert body content updated
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/test/ghostbird.test.ts (1)
63-63: Consider simplifying the promise chain.The
.then(() => {})is redundant asPromise.allalready returns a promise that resolves toundefinedwhen both promises complete.Apply this diff:
- let closePromise = Promise.all([backgroundPromise, composePromise]).then(() => {}) + let closePromise = Promise.all([backgroundPromise, composePromise])src/thunderbird/util/promisified_message_port.ts (1)
66-68: Consider adding an explicit isOpen() check.The
IMessagePortinterface documentation indicates thatsend()should throw "Already disconnected" when the port is closed. Currently, the method relies on the native MessagePort to throw, which may produce less descriptive error messages.Apply this diff to provide clearer error messages:
send(msg: TRequest): void { + if (!this.isOpen()) { + throw new Error("Already disconnected") + } this.port.postMessage(msg) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (5)
package.json(1 hunks)src/test/ghostbird.test.ts(1 hunks)src/test/sanity.test.ts(1 hunks)src/test/tsconfig.json(1 hunks)src/thunderbird/util/promisified_message_port.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/test/ghostbird.test.ts (12)
src/ghosttext-runner/api.ts (1)
IHeart(11-17)src/app-background/api.ts (3)
IButtonMenu(52-62)IComposeWindowDetector(40-49)IUiUtil(18-21)src/ghosttext-adaptor/api.ts (8)
IManifestInfo(75-78)INotificationTray(5-8)IStoredOptionsLoader(89-92)IWebClient(11-24)BackgroundMessage(95-95)BodyState(98-98)ComposeDetails(27-35)StoredOptions(81-86)src/thunderbird/util/promisified_message_port.ts (1)
promisifyMessageChannel(9-14)src/app-compose/compose_event_router.ts (1)
ComposeEventRouter(6-37)src/app-background/background_event_router.ts (1)
BackgroundEventRouter(6-56)src/ghosttext-session/types.ts (2)
EditorChangeResponse(50-55)ServerInitialResponse(12-17)src/ghosttext-runner/message.ts (1)
IMessagePort(25-60)src/root/util/wireless.ts (2)
WirelessInjector(33-36)wireless(45-57)src/root/startup/startup_background.ts (1)
BackgroundCatalog(23-27)src/root/util/registry.ts (1)
makeRegistry(5-7)src/root/startup/startup_compose.ts (1)
ComposeCatalog(15-19)
src/thunderbird/util/promisified_message_port.ts (2)
src/ghosttext-runner/message.ts (1)
IMessagePort(25-60)src/util/promisifying_queue.ts (1)
PromisifyingQueue(5-100)
🔇 Additional comments (3)
src/test/tsconfig.json (1)
7-14: LGTM!The addition of DOM and modern ES library targets appropriately supports the test infrastructure that uses MessageChannel, DOMParser, and other DOM APIs introduced in this PR.
src/test/sanity.test.ts (1)
33-35: LGTM!The type casts appropriately align mock values with the expected DOM types, improving type safety without changing test behavior.
package.json (1)
75-75: Verify jsdom v27 compatibility by testing these key breaking changes.The upgrade from jsdom v26 to v27 introduces several breaking changes that require test verification:
- Node.js minimum is now v20 — verify your CI/dev environment meets this requirement.
- VirtualConsole API: sendTo() renamed to forwardTo(); jsdomErrors option replaces omitJSDOMErrors boolean — search your test code for these usages.
- User-agent stylesheet switched from Chromium-derived to the HTML Standard — getComputedStyle() results may change — re-run CSS/layout-related tests.
- Cookie behavior: localhost may now be treated as a secure context — verify localhost cookie expectations in tests.
- MouseEvent now exposes movementX and movementY; new event constructors added — check for related event tests.
Re-run your test suite to confirm no failures from these changes.
`ComposeEventRouter`
1af0a54 to
a889566
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/thunderbird/util/promisified_message_port.ts (1)
44-52: Consider type annotation precision for the disconnect sentinel.The
MessageEvent<TResponse>type annotation doesn't reflect thatnullcan also arrive through this channel (sent byclose()at line 72). While the runtime handling is correct—the== nullcheck appropriately catches the disconnect sentinel—the type annotation could be more precise.Consider this refinement for type accuracy:
- this.port.onmessage = ({ data }: MessageEvent<TResponse>): void => { + this.port.onmessage = ({ data }: MessageEvent<TResponse | null>): void => { if (data == null) {Note: The current use of
==(rather than===) correctly handles bothnullandundefined, which is appropriate for the disconnect signal.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/test/ghostbird.test.ts(1 hunks)src/test/sanity.test.ts(1 hunks)src/test/tsconfig.json(1 hunks)src/thunderbird/util/promisified_message_port.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- src/test/tsconfig.json
- src/test/sanity.test.ts
- src/test/ghostbird.test.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-24T17:53:47.113Z
Learnt from: snipsnipsnip
PR: exteditor/ghostbird#49
File: src/thunderbird/util/promisified_message_port.ts:70-74
Timestamp: 2025-10-24T17:53:47.113Z
Learning: In JavaScript, MessagePort.postMessage() does not throw exceptions when called on a closed channel. Instead, it silently drops the message. Therefore, try-catch blocks are not needed when calling postMessage() on potentially closed ports.
Applied to files:
src/thunderbird/util/promisified_message_port.ts
🧬 Code graph analysis (1)
src/thunderbird/util/promisified_message_port.ts (2)
src/ghosttext-runner/message.ts (1)
IMessagePort(25-60)src/util/promisifying_queue.ts (1)
PromisifyingQueue(5-100)
🔇 Additional comments (5)
src/thunderbird/util/promisified_message_port.ts (5)
1-14: LGTM! Clean factory function with proper type constraints.The
promisifyMessageChannelfunction correctly wraps a MessageChannel's ports with swapped type parameters to enable bidirectional, type-safe communication.
16-38: LGTM! Well-structured factory pattern.The static
listenTofactory method combined with a private constructor ensures proper initialization while maintaining good encapsulation. The type constraintextends object | stringcorrectly preventsnullorundefinedfrom being valid message types, which is essential sincenullis used as the disconnect sentinel.
54-64: LGTM! Clean delegation to the queue.The promise-based methods correctly delegate to
PromisifyingQueue, maintaining separation of concerns.
66-68: LGTM! Correct implementation.The
sendmethod correctly posts messages to the underlying port. No error handling is needed sinceMessagePort.postMessage()silently drops messages on closed channels rather than throwing exceptions.Based on learnings.
70-79: Close sequence is correct per previous feedback.The close implementation properly signals disconnect via
postMessage(null)and performs local cleanup. As noted in the retrieved learnings,MessagePort.postMessage()won't throw on closed channels, so the current implementation is safe even during simultaneous closes from both sides.Optional: The
console.infoon line 71 may be intended for debugging. Consider whether structured logging would be preferable for production code, and whether the error message on line 78 could be more descriptive (e.g., "MessagePort disconnected").Based on learnings.
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @snipsnipsnip. * #49 (comment) The following files were modified: * `src/thunderbird/util/promisified_message_port.ts`
Docstrings generation was requested by @snipsnipsnip. * #49 (comment)
Docstrings generation was requested by @snipsnipsnip. * #49 (comment) The following files were modified: * `src/thunderbird/util/promisified_message_port.ts` <details> <summary>These files were ignored</summary> * `src/test/ghostbird.test.ts` * `src/test/sanity.test.ts` </details> <details> <summary>These file types are not supported</summary> * `package.json` * `src/test/tsconfig.json` </details> <details> <summary>ℹ️ Note</summary><blockquote> CodeRabbit cannot perform edits on its own pull requests yet. </blockquote></details>
It's hardly a unit test, but I think it will be useful.