-
Notifications
You must be signed in to change notification settings - Fork 557
improvement(client-container-loader): tighten Signal expectations #25522
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
d123305 to
06c211d
Compare
53f528a to
28ca32f
Compare
532fec0 to
4da8ea2
Compare
06c211d to
bc4e818
Compare
Signals specify `type` within message `content` next to inner content that is stringified JSON. Assert that internally (to avoid legacy API change) and leverage. Additionally, clean up system signal typing and type guard to reduce casts.
bc4e818 to
385b86a
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.
Pull Request Overview
This PR tightens Signal expectations in the client-container-loader package by ensuring signal messages conform to expected typing and structure. The changes improve type safety by asserting that signal content is properly formatted JSON and reducing type casting throughout the codebase.
Key changes:
- Converts SignalType from enum to const object and adds comprehensive type definitions for system signals
- Introduces runtime assertions to validate signal message structure and content format
- Replaces generic IProtocolHandler with more specific ProtocolHandlerInternal interface
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| protocol.ts | Adds system signal type definitions and creates ProtocolHandlerInternal interface with narrower signal constraints |
| deltaManager.ts | Updates signal handling to use JsonParse and adds JsonString type constraints |
| contracts.ts | Adds JsonString type constraint to signalHandler interface |
| container.ts | Updates to use InternalProtocolHandlerBuilder and ProtocolHandlerInternal types |
| connectionManager.ts | Adds assertExpectedSignals validation function and uses JsonStringify for signal creation |
| function assertExpectedSignals( | ||
| signals: ISignalMessage[], | ||
| ): asserts signals is ISignalMessage<{ type: never; content: JsonString<unknown> }>[] { | ||
| for (const signal of signals) { | ||
| if ("type" in signal) { | ||
| throw new Error("Unexpected type in ISignalMessage"); | ||
| } | ||
| if (typeof signal.content !== "string") { | ||
| throw new TypeError("Non-string content in ISignalMessage"); | ||
| } | ||
| } | ||
| } |
Copilot
AI
Oct 5, 2025
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.
Use string literals for assert error messages instead of generic descriptions. Replace 'Unexpected type in ISignalMessage' and 'Non-string content in ISignalMessage' with more descriptive string literals.
| export interface ProtocolHandlerInternal extends IProtocolHandler { | ||
| /** | ||
| * Process the audience related signal. | ||
| * @privateRemarks Internally only AudienceSignal messages need handled |
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.
typo: need to be handled* or need handling*
+ TSDoc link additions
Signals specify
typewithin messagecontentnext to inner content that is stringified JSON.Assert that internally (to avoid legacy API change) and leverage. Additionally, clean up system signal typing and type guard to reduce casts.
AB#49979