Skip to content

ci: Add patch for events#6

Merged
tomasz-blasz merged 1 commit intomainfrom
topic/ci-event-patch
Dec 12, 2025
Merged

ci: Add patch for events#6
tomasz-blasz merged 1 commit intomainfrom
topic/ci-event-patch

Conversation

@tomasz-blasz
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 11, 2025 15:11
Copy link

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 adds a patch file for the mock-firebolt server that introduces bidirectional event handling improvements and a new raw payload testing API. The patch modifies event validation logic, updates OpenRPC method lookup to support SDK-specific queries, and adds a raw API endpoint for testing purposes.

Key changes:

  • Enhanced event validation for bidirectional mode with support for wrapped values and x-notifier-for tags
  • Added raw payload API endpoint for testing websocket communications
  • Renamed createBidirectionalPayload to createBidirectionalEventPayload and removed auto-incrementing ID

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error in comment: "paload" should be "payload".

Copilot uses AI. Check for mistakes.
+ }
+ const resultErrors = fireboltOpenRpc.validateMethodResult(resultToValidate, method);
if ( resultErrors && resultErrors.length > 0 ) {
+ logger.error(`${method} validation error for ${method} with ${JSON.stringify(resultToValidate)}, err: ${JSON.stringify(resultErrors)}`);
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message duplicates the method name: "${method} validation error for ${method}". This should likely say something like "Event validation error for ${method}" or just "Validation error for ${method}".

Suggested change
+ logger.error(`${method} validation error for ${method} with ${JSON.stringify(resultToValidate)}, err: ${JSON.stringify(resultErrors)}`);
+ logger.error(`Validation error for ${method} with ${JSON.stringify(resultToValidate)}, err: ${JSON.stringify(resultErrors)}`);

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +205
+// POST /api/v1/raw
+// Expected body: Any
+function rawPayload(req, res) {
+ try {
+ const userId = getUserIdFromReq(req);
+ const ws = userManagement.getWsForUser(userId)
+
+ const payload = {
+ jsonrpc: "2.0",
+ ...req.body
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling: If 'ws' is null or undefined (when getWsForUser returns no connection), calling ws.send() will throw an error. Add validation to check if ws exists before attempting to send the payload.

Copilot uses AI. Check for mistakes.
+ try {
+ const userId = getUserIdFromReq(req);
+ const ws = userManagement.getWsForUser(userId)
+
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security concern: The raw API endpoint accepts arbitrary JSON payloads without any validation and sends them directly to websocket connections. This could allow malicious or malformed payloads to be sent to clients. Consider adding at least basic validation to ensure the payload structure is safe and expected fields are present.

Suggested change
+
+
+ // Basic validation: payload must be a non-null object, not an array
+ if (
+ typeof req.body !== 'object' ||
+ req.body === null ||
+ Array.isArray(req.body)
+ ) {
+ return res.status(400).send({
+ status: "Invalid payload: must be a JSON object"
+ });
+ }
+
+ // Optionally, check for required fields (e.g., method)
+ // if (!('method' in req.body)) {
+ // return res.status(400).send({
+ // status: "Invalid payload: missing 'method' field"
+ // });
+ // }
+

Copilot uses AI. Check for mistakes.
+
+// --- Route Handlers ---
+
+// POST /api/v1/raw
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon at the end of the statement. While JavaScript allows this, the codebase appears to use semicolons consistently (as seen throughout the patch file).

Copilot uses AI. Check for mistakes.
+ * limitations under the License.
+ */
+
+// HTTP-based API routes: Raw, without any validation, just "jsonrpc": "2.0" field is being added to the paload
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon at the end of the statement. While JavaScript allows this, the codebase appears to use semicolons consistently (as seen throughout the patch file).

Copilot uses AI. Check for mistakes.
+ let oResult = undefined;
+ if (config.dotConfig.bidirectional && methodName.includes('.on')) {
+ let oMethod = getMethod(methodName, "coreToApp");
+ if (oMethod && oMethod.tags) {
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null/undefined error: If 'oMethod' is undefined or null (when getMethod returns undefined), accessing 'oMethod.tags' will throw a TypeError. The code should verify 'oMethod' exists before accessing its properties.

Suggested change
+ if (oMethod && oMethod.tags) {
+ if (oMethod && Array.isArray(oMethod.tags)) {

Copilot uses AI. Check for mistakes.

try {
- const oMethod = getMethod(methodName);
- const oResult = oMethod.result;
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable shadowing issue: A new variable 'oMethod' is declared with 'let' inside the if block, which shadows the outer 'oMethod' variable declared on line 119. This prevents the outer variable from being assigned and causes the condition check on line 134 to always be true. Remove the 'let' keyword on this line to assign to the outer variable instead.

Copilot uses AI. Check for mistakes.
Comment on lines +203 to +211
+ const payload = {
+ jsonrpc: "2.0",
+ ...req.body
+ };
+
+ console.log(`Sending raw payload: ${JSON.stringify(payload)}`);
+
+ ws.send(JSON.stringify(payload));
+
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use logger instead of console.log/console.error for consistency. Other parts of the codebase use the logger module for logging (as seen in the fireboltOpenRpc.mjs and events.mjs changes), but this new route uses console methods. Import and use the logger module for consistent logging practices.

Copilot uses AI. Check for mistakes.
@tomasz-blasz tomasz-blasz merged commit 1bf8ffe into main Dec 12, 2025
12 checks passed
@tomasz-blasz tomasz-blasz deleted the topic/ci-event-patch branch December 12, 2025 07:13
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2025
@tomasz-blasz
Copy link
Contributor Author

🎉 This PR is included in version 0.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants