Skip to content

YNU-259: add app protocol enforcement#374

Merged
philanton merged 4 commits into
mainfrom
feat/app-protocol-enforcement
Sep 30, 2025
Merged

YNU-259: add app protocol enforcement#374
philanton merged 4 commits into
mainfrom
feat/app-protocol-enforcement

Conversation

@dimast-x
Copy link
Copy Markdown
Contributor

@dimast-x dimast-x commented Sep 30, 2025

Todos:

  • fix integration tests

Summary by CodeRabbit

  • New Features

    • Introduced protocol versioning (NitroRPC/0.2).
    • App creation now validates and rejects unsupported protocol versions.
    • API responses consistently expose NitroRPC/0.2 (no JSON schema changes).
  • Documentation

    • Updated API, protocol, and entities docs to require NitroRPC/0.2 and clarify enforcement.
    • Updated examples to use the new protocol version.
  • Tests

    • Updated tests to use the NitroRPC/0.2 protocol constant.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 30, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replaces string protocol fields with a typed rpc.Version across RPC APIs and SDK, adds VersionNitroRPCv0_2 and an IsSupportedVersion check, enforces protocol validation in CreateApplication, updates router serialization, tests, SDK schemas, and documentation to use NitroRPC/0.2.

Changes

Cohort / File(s) Summary
RPC version type and helpers
clearnode/pkg/rpc/api.go
Introduces rpc.Version, VersionNitroRPCv0_2, supported-version registry, Version.String() and IsSupportedVersion.
Core model type updates
clearnode/app_session.go, clearnode/rpc_router_public.go
Changes AppSession.Protocol / AppDefinition.Protocol from string to rpc.Version; router serializes protocol with .String().
Service validation
clearnode/app_session_service.go
Adds pre-check in CreateApplication that calls rpc.IsSupportedVersion and returns an RPC error for unsupported protocols.
Tests updated
clearnode/app_session_service_test.go, clearnode/rpc_router_private_test.go, sdk/test/unit/rpc/api.test.ts
Replace literal protocol strings with typed constants (rpc.VersionNitroRPCv0_2 or ProtocolVersion.NitroRPC_0_2) in test fixtures.
SDK types & parsing
sdk/src/rpc/types/common.ts, sdk/src/rpc/parse/common.ts, sdk/src/rpc/parse/app.ts
Adds ProtocolVersion enum export and protocolVersionEnum zod schema; replaces protocol fields types from string to ProtocolVersion in schemas and types.
Integration test usage
integration/tests/lifecycle.test.ts
Uses ProtocolVersion.NitroRPC_0_2 instead of hard-coded protocol string in app session definition.
Docs and examples
clearnode/docs/API.md, clearnode/docs/Clearnode.protocol.md, clearnode/docs/Entities.md, clearnode/pkg/rpc/README.md
Update examples and text to require/use NitroRPC/0.2 and note enforcement of that protocol in creation/validation flows.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Router as RPC Router
  participant Service as AppSessionService
  participant RPC as rpc (version registry)

  rect rgb(245,250,255)
  note right of Client: Create Application Session
  Client->>Router: POST /create_app_session (AppDefinition{protocol: Version})
  Router->>Service: CreateApplication(definition)
  Service->>RPC: IsSupportedVersion(definition.Protocol)
  alt supported
    Service-->>Router: create AppSession
    Router-->>Client: 200 OK (AppSession{protocol: Version.String()})
  else unsupported
    Service-->>Router: RPC error (unsupported protocol)
    Router-->>Client: 4xx error
  end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I thump my foot: typed versions bloom,
Strings hop out, new enums make room.
NitroRPC/0.2 lights our trail,
Tests and docs follow the trail.
A rabbit nods — tidy code, no gloom. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title “YNU-259: add app protocol enforcement” succinctly captures the primary change of enforcing application protocol version in the codebase, aligns with the ticket reference, and avoids extraneous details. It is clear, specific, and directly related to the pull request’s core functionality without including noise or overly broad terminology. A reviewer scanning the history can immediately understand the intent of the changes from the title.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/app-protocol-enforcement

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.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @dimast-x, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness and security of application session management by introducing a dedicated Protocol type and enforcing its usage. This change ensures that all application sessions adhere to predefined and supported communication protocols, preventing misconfigurations and improving the overall integrity of the system. The refactoring also improves code readability and maintainability by making protocol handling explicit.

Highlights

  • New Protocol Type: Introduced a new Protocol type (a string alias) to explicitly define and manage application protocols, enhancing type safety and clarity.
  • Protocol Enforcement: Implemented a validation step during application session creation to ensure that only supported protocols are accepted, preventing the use of arbitrary or undefined protocols.
  • Code Refactoring and Test Updates: Updated the AppSession struct, AppSessionService, and RPC router handlers to utilize the new Protocol type. Corresponding test cases were also refactored to reflect these changes and ensure correct behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
clearnode/app_session_service.go 0.00% 2 Missing and 1 partial ⚠️
clearnode/pkg/rpc/api.go 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces protocol enforcement for application sessions, ensuring only supported protocols like 'NitroRPC/0.2' are used. The changes involve adding a new Protocol type, validating it upon application creation, and updating various parts of the codebase and tests to use this new type. The implementation is clean and effective. I've added a couple of suggestions to improve maintainability and test coverage.

Comment thread clearnode/protocol.go Outdated
Comment thread clearnode/app_session_service.go Outdated
Comment thread clearnode/protocol.go Outdated
@dimast-x dimast-x added the wip label Sep 30, 2025
@philanton philanton force-pushed the feat/app-protocol-enforcement branch from de2976c to d4aec0f Compare September 30, 2025 12:43
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a 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)
clearnode/docs/Entities.md (1)

44-44: Consider updating the type description.

The description states Protocol is a string, but the code now uses rpc.Version type. While rpc.Version is likely a string alias, consider updating the documentation to reflect the actual type for consistency.

Apply this diff to update the type description:

-- `Protocol` (string): Protocol version used (must be "NitroRPC/0.2")
+- `Protocol` (rpc.Version): Protocol version used (must be "NitroRPC/0.2")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d218592 and d4aec0f.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (10)
  • clearnode/app_session.go (1 hunks)
  • clearnode/app_session_service.go (2 hunks)
  • clearnode/app_session_service_test.go (10 hunks)
  • clearnode/docs/API.md (3 hunks)
  • clearnode/docs/Clearnode.protocol.md (1 hunks)
  • clearnode/docs/Entities.md (2 hunks)
  • clearnode/pkg/rpc/README.md (1 hunks)
  • clearnode/pkg/rpc/api.go (3 hunks)
  • clearnode/rpc_router_private_test.go (3 hunks)
  • clearnode/rpc_router_public.go (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • clearnode/docs/API.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • clearnode/rpc_router_private_test.go
  • clearnode/rpc_router_public.go
  • clearnode/app_session_service.go
🧰 Additional context used
🧬 Code graph analysis (2)
clearnode/app_session.go (1)
clearnode/pkg/rpc/api.go (1)
  • Version (27-27)
clearnode/app_session_service_test.go (1)
clearnode/pkg/rpc/api.go (1)
  • VersionNitroRPCv0_2 (31-31)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build and Publish (Clearnode)
  • GitHub Check: Test (Integration) / Test Integration
  • GitHub Check: Analyze (go)
🔇 Additional comments (10)
clearnode/app_session.go (2)

6-6: LGTM!

The import of the rpc package is appropriate for using the rpc.Version type.


13-13: No GORM compatibility issues with rpc.Version default
rpc.Version is a simple type Version string alias with no custom Scan/Value methods, so the gorm:"default:'NitroRPC/0.2'" tag will function as intended.

clearnode/pkg/rpc/README.md (1)

185-185: LGTM!

The example has been correctly updated to use the typed constant rpc.VersionNitroRPCv0_2 instead of a string literal, aligning with the new protocol enforcement.

clearnode/docs/Entities.md (1)

55-56: LGTM!

The added note clearly communicates the protocol enforcement requirement to users of the API.

clearnode/docs/Clearnode.protocol.md (1)

22-22: LGTM!

The documentation correctly describes the new protocol version validation requirement in the Virtual Application Creation flow.

clearnode/app_session_service_test.go (2)

7-7: LGTM!

The import of the rpc package is necessary for using the rpc.VersionNitroRPCv0_2 constant throughout the tests.


51-51: LGTM! Tests correctly updated to use the enforced protocol version.

All test cases have been updated to use rpc.VersionNitroRPCv0_2 instead of the previous "test-proto" string literal. This ensures tests use the valid, enforced protocol version and will properly exercise the new validation logic.

Also applies to: 124-124, 155-155, 182-182, 215-215, 265-265, 321-321, 409-409, 463-463

clearnode/pkg/rpc/api.go (3)

21-49: Well-structured protocol versioning implementation.

The typed Version approach with a validation registry is clean and extensible. The implementation correctly uses a map for O(1) lookup.


519-521: LGTM! Type-safe protocol enforcement.

Changing Protocol from string to Version enforces type safety while maintaining JSON compatibility. The validation logic in app_session_service.go (per AI summary) ensures only supported versions are accepted.


544-545: Consistent type change for AppSession.

The Protocol field change mirrors AppDefinition and maintains consistency. JSON serialization is handled correctly via String() conversion in the router (per AI summary).

@philanton philanton merged commit 74dab06 into main Sep 30, 2025
11 of 12 checks passed
@philanton philanton deleted the feat/app-protocol-enforcement branch September 30, 2025 14:25
@dimast-x dimast-x removed the wip label Nov 5, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants