-
Notifications
You must be signed in to change notification settings - Fork 7
refactor: Replace kernel-UI communication with BroadcastChannel
#349
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
3c8dc92 to
e710d96
Compare
e710d96 to
b16d809
Compare
BroadcastChannelBroadcastChannel
BroadcastChannelBroadcastChannel
sirtimid
left a comment
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.
Since the broadcast API supports one-to-many connections, I initially thought that opening the kernel panel both from the extension button and directly from the popup URL would create two channels connecting to the kernel. However, this is not the case. It appears that only one connection at a time is supported. If a second connection is attempted, the stream encounters errors, requiring a restart of the extension. This issue might be outside the scope of this PR, so I am approving it, but I wanted to highlight this concern.
|
Follow-up: #371 |
Closes #370 #349 surfaced a number of long-standing issues with our unit tests. These issues stemmed from a lack of standardization between packages, and impedance mismatches between SES / lockdown and Vitest. This PR performs a variety of changes with a view to standardizing our unit test setups, and making it easier to debug tests locally. First and foremost, a `development` mode is introduced to our unit (and some e2e) tests. This is accessible via the `test:dev` command in all packages except the root. For all packages, running tests in this mode disables test coverage, which is generally a distraction during debugging. For `streams`, it also replaces the `endoify` environment with the mock version thereof. `development` mode tests do not run in CI, and do not necessarily pass, since some unit tests (again in `streams`) must run under lockdown. Most importantly, we now have a pattern for optionally not running tests under lockdown. I will perhaps follow up with a conversion of the extension unit test suite to running under lockdown by default. Second (and already implied), `streams` tests once again run in the browser under lockdown. Third, the extension unit test `mock-endoify` imports have been consolidated into the extension's test setup file. Finally, sundry tweaks are made to the test suite for cleanliness purposes, such as dead code removal.
We removed stream multiplexing in #349 because we no longer had a use for it. With some of the plans we have for our logger, we once again find ourselves in a position where we'd like to differentiate traffic over a single stream. Multiplexing was pretty complex, so we'd prefer not to go back to it if possible. With these requirements in mind, this PR introduces "stream splitting" via the function `split()` exported from `@ocap/streams`. The idea is simple: pass `split()` a duplex stream and a number of type predicates, and receive an array of streams in return. Each stream represents the subset of the parent stream's traffic satisfying the corresponding predicate. Not very efficient for large numbers of channels or complex predicates, but our usage should be simple enough.
Closes #280
Establishes a
BroadcastChannelchannel between the UI and kernel worker for kernel-UI messages. This removes the necessity of routing this traffic through the offscreen page, and entirely removes the need for stream multiplexing, which is removed. In order to handle reloading the UI (which closes and then reopens the stream andBroadcastChannelon that end), extends the duplex stream synchronization protocol to support "re-synchronization". In consequence, the UI no longer returns its stream before it closes, in order to keep the remote (i.e. kernel) side open for when the UI reopens.In addition:
DuplexStream.drain()is completely orthogonal to synchronization (i.e. it can be called at any time, before, during, or after (re-)synchronization).jsdomand the mock endo environment for@ocap/streamsunit tests.This currently prevents us from having multiple UI instances at once, but
we will fix this in #371.
For reviewers
To test this PR, just build the branch and check that everything is functioning normally.