Skip to content

Conversation

@jason-ha
Copy link
Contributor

@jason-ha jason-ha commented Sep 23, 2025

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.

AB#49979

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.
@jason-ha jason-ha force-pushed the loader/signal-typing branch from bc4e818 to 385b86a Compare October 5, 2025 23:35
@github-actions github-actions bot added area: loader Loader related issues base: main PRs targeted against main branch labels Oct 5, 2025
@jason-ha jason-ha marked this pull request as ready for review October 5, 2025 23:37
Copilot AI review requested due to automatic review settings October 5, 2025 23:37
Copy link
Contributor

Copilot AI left a 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

Comment on lines +118 to +129
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");
}
}
}
Copy link

Copilot AI Oct 5, 2025

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.

Copilot generated this review using guidance from repository custom instructions.
export interface ProtocolHandlerInternal extends IProtocolHandler {
/**
* Process the audience related signal.
* @privateRemarks Internally only AudienceSignal messages need handled
Copy link
Contributor

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*

@jason-ha jason-ha enabled auto-merge (squash) October 6, 2025 17:49
@jason-ha jason-ha requested a review from markfields October 6, 2025 17:49
@WillieHabi WillieHabi self-requested a review October 6, 2025 20:09
@jason-ha jason-ha merged commit 2f6817d into main Oct 6, 2025
38 checks passed
@jason-ha jason-ha deleted the loader/signal-typing branch October 6, 2025 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: loader Loader related issues base: main PRs targeted against main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants