Skip to content

refactor: unify token types under NatsToken in trogon-nats#44

Merged
yordis merged 4 commits intoTrogonStack:mainfrom
tsitsiridakisiosif:refactor-single-token-and-multi-token-under-nats-token
Apr 1, 2026
Merged

refactor: unify token types under NatsToken in trogon-nats#44
yordis merged 4 commits intoTrogonStack:mainfrom
tsitsiridakisiosif:refactor-single-token-and-multi-token-under-nats-token

Conversation

@tsitsiridakisiosif
Copy link
Copy Markdown
Contributor

No description provided.

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 23, 2026

PR Summary

Medium Risk
Moderate risk because it changes the concrete types and validation paths for NATS subject components used across acp-nats, which could affect runtime subject formatting/validation and error propagation, though behavior is largely preserved and covered by tests.

Overview
Refactors acp-nats subject component value objects (AcpPrefix, ExtMethodName, AcpSessionId) to delegate validation and storage to new shared types in trogon-nats (DottedNatsToken/NatsToken) instead of local validation helpers.

Introduces trogon-nats token primitives and exports (nats_token.rs, SubjectTokenViolation, MAX_NATS_TOKEN_LENGTH) and makes token helper functions public, while removing acp-nats-local token constants/modules (MAX_*_LENGTH, nats::token, subject_token_violation).

Written by Cursor Bugbot for commit ceef35e. This will update automatically on new commits. Configure here.

@tsitsiridakisiosif tsitsiridakisiosif marked this pull request as draft March 23, 2026 19:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 51ccb1ed-58c4-40ce-9980-2a77b77fed85

📥 Commits

Reviewing files that changed from the base of the PR and between 28a86f4 and ceef35e.

📒 Files selected for processing (1)
  • rsworkspace/crates/trogon-nats/src/nats_token.rs
✅ Files skipped from review due to trivial changes (1)
  • rsworkspace/crates/trogon-nats/src/nats_token.rs

Walkthrough

Centralized NATS subject-token validation into a new trogon-nats crate surface by adding NatsToken and DottedNatsToken types and SubjectTokenViolation. acp-nats value objects (prefix, method name, session id) now wrap those token types and delegate validation; related constants and module exports were removed or relocated.

Changes

Cohort / File(s) Summary
New token value objects & errors
rsworkspace/crates/trogon-nats/src/nats_token.rs, rsworkspace/crates/trogon-nats/src/subject_token_violation.rs
Added NatsToken and DottedNatsToken with construction-time validation, trait impls, and unit tests; added SubjectTokenViolation enum for validation failures.
trogon-nats exports & helpers
rsworkspace/crates/trogon-nats/src/lib.rs, rsworkspace/crates/trogon-nats/src/token.rs, rsworkspace/crates/trogon-nats/src/constants.rs
Re-exported NatsToken, DottedNatsToken, and SubjectTokenViolation at crate root; promoted token helper functions to pub; added MAX_NATS_TOKEN_LENGTH.
acp-nats value-object migrations
rsworkspace/crates/acp-nats/src/acp_prefix.rs, rsworkspace/crates/acp-nats/src/ext_method_name.rs, rsworkspace/crates/acp-nats/src/session_id.rs
Replaced Arc<str> backing types with DottedNatsToken/NatsToken; constructors now delegate validation to trogon-nats and map errors; as_str() now forwards to token as_str().
acp-nats cleanup & module changes
rsworkspace/crates/acp-nats/src/constants.rs, rsworkspace/crates/acp-nats/src/lib.rs, rsworkspace/crates/acp-nats/src/nats/mod.rs
Removed local MAX_* length constants and deleted pub mod subject_token_violation; and the pub(crate) mod token; declaration from nats barrel.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I nibbled dots and chased each star,
Tokens gathered from near and far.
One crate now guards each valid name,
No more duplicate hops in the game—
Hooray! — signed, the patch-loving hare 🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate relatedness to the changeset. Add a brief description explaining the refactoring goals, such as token type unification, validation consolidation, and the use of NatsToken and DottedNatsToken structs.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactoring objective: consolidating token types and validation logic under a NatsToken abstraction in trogon-nats.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Copy link
Copy Markdown

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rsworkspace/crates/acp-nats/src/lib.rs (1)

24-24: ⚠️ Potential issue | 🟡 Minor

Missing SessionIdError export violates coding guidelines.

The acp_prefix module correctly exports both AcpPrefix and AcpPrefixError, but session_id only exports AcpSessionId. As per coding guidelines: "Export value objects in lib.rs as pub use {module}::{Type, TypeError}".

Proposed fix
-pub use session_id::AcpSessionId;
+pub use session_id::{AcpSessionId, SessionIdError};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/acp-nats/src/lib.rs` at line 24, The module export is
missing the error type for session_id; update lib.rs to re-export the paired
error type along with AcpSessionId by adding a pub use for the session_id error
(e.g., add "pub use session_id::SessionIdError;") so both AcpSessionId and its
corresponding SessionIdError are exported from the crate.
🧹 Nitpick comments (1)
rsworkspace/crates/trogon-nats/src/subject_token_violation.rs (1)

2-2: Consider adding Eq derive for consistency.

The enum has PartialEq but not Eq. Since all variants are trivially equal to themselves (no floating-point or NaN-like semantics), Eq should be derivable and would enable use in hash sets or as map keys.

Proposed fix
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Eq)]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/trogon-nats/src/subject_token_violation.rs` at line 2, The
derive on the enum in subject_token_violation.rs currently uses #[derive(Debug,
Clone, PartialEq)]—add Eq to the derive list so it becomes #[derive(Debug,
Clone, PartialEq, Eq)] to enable full equality semantics; update the derive
attribute adjacent to the enum declaration (the same #[derive(...)] attribute in
this file) to include Eq.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@rsworkspace/crates/trogon-nats/src/nats_token.rs`:
- Around line 73-86: The REQUIRE_ASCII branch currently rejects '.'
unconditionally; update the loop in nats_token.rs that checks P::REQUIRE_ASCII
so it consults P::ALLOW_DOTS (i.e., only reject '.' when P::ALLOW_DOTS is
false), while still rejecting '*' , '>' and whitespace and returning the same
SubjectTokenViolation variants; when P::ALLOW_DOTS is true, allow ASCII dots but
add the same consecutive/boundary dot validation used elsewhere (the dot
adjacency/boundary checks present around lines ~95-97) to ensure
leading/trailing or consecutive dots are handled and return the appropriate
SubjectTokenViolation when violated.

---

Outside diff comments:
In `@rsworkspace/crates/acp-nats/src/lib.rs`:
- Line 24: The module export is missing the error type for session_id; update
lib.rs to re-export the paired error type along with AcpSessionId by adding a
pub use for the session_id error (e.g., add "pub use
session_id::SessionIdError;") so both AcpSessionId and its corresponding
SessionIdError are exported from the crate.

---

Nitpick comments:
In `@rsworkspace/crates/trogon-nats/src/subject_token_violation.rs`:
- Line 2: The derive on the enum in subject_token_violation.rs currently uses
#[derive(Debug, Clone, PartialEq)]—add Eq to the derive list so it becomes
#[derive(Debug, Clone, PartialEq, Eq)] to enable full equality semantics; update
the derive attribute adjacent to the enum declaration (the same #[derive(...)]
attribute in this file) to include Eq.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9fe3aae2-c9cc-412c-8e13-15fdb1ba2bac

📥 Commits

Reviewing files that changed from the base of the PR and between 035824c and 3616890.

📒 Files selected for processing (11)
  • rsworkspace/crates/acp-nats/src/acp_prefix.rs
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs
  • rsworkspace/crates/acp-nats/src/lib.rs
  • rsworkspace/crates/acp-nats/src/nats/mod.rs
  • rsworkspace/crates/acp-nats/src/nats_token_policies.rs
  • rsworkspace/crates/acp-nats/src/session_id.rs
  • rsworkspace/crates/acp-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/lib.rs
  • rsworkspace/crates/trogon-nats/src/nats_token.rs
  • rsworkspace/crates/trogon-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/token.rs
💤 Files with no reviewable changes (1)
  • rsworkspace/crates/acp-nats/src/nats/mod.rs

@tsitsiridakisiosif tsitsiridakisiosif force-pushed the refactor-single-token-and-multi-token-under-nats-token branch from 3616890 to 7011e46 Compare March 23, 2026 19:17
@yordis
Copy link
Copy Markdown
Member

yordis commented Mar 24, 2026

The direction is right — deduplicating the validation and moving NatsToken + SubjectTokenViolation to trogon-nats is the correct call. But the NatsTokenPolicy trait + PhantomData<P> + hand-rolled trait impls adds too much machinery for what's essentially two boolean flags.

Requested changes

Replace the generic NatsToken<P: NatsTokenPolicy> with two concrete structs:

  • NatsToken — single token, no dots, ASCII-only (used by AcpSessionId)
  • DottedNatsToken — dotted segments allowed, UTF-8 (used by AcpPrefix, ExtMethodName)

This removes:

  • NatsTokenPolicy trait
  • PhantomData<P>
  • Hand-rolled Clone, Debug, PartialEq, Eq, Hash impls (just #[derive(...)] instead)
  • nats_token_policies.rs in acp-nats

Both structs share the existing private token.rs validation helpers. The ACP wrapper types stay the same — just swap the inner type.

@tsitsiridakisiosif tsitsiridakisiosif force-pushed the refactor-single-token-and-multi-token-under-nats-token branch from 7011e46 to d25f9b0 Compare April 1, 2026 08:13
@tsitsiridakisiosif tsitsiridakisiosif marked this pull request as ready for review April 1, 2026 08:13
@tsitsiridakisiosif tsitsiridakisiosif force-pushed the refactor-single-token-and-multi-token-under-nats-token branch from d25f9b0 to b952bac Compare April 1, 2026 08:13
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
rsworkspace/crates/acp-nats/src/acp_prefix.rs (1)

38-40: Use AsRef<str> in AcpPrefix::new to avoid unnecessary allocation.

impl Into<String> forces allocation for borrowed inputs; impl AsRef<str> aligns with DottedNatsToken::new() which already expects AsRef<str>, eliminating a redundant conversion layer.

♻️ Proposed refactor
-    pub fn new(s: impl Into<String>) -> Result<Self, AcpPrefixError> {
-        let s = s.into();
-        DottedNatsToken::new(s).map(Self).map_err(AcpPrefixError)
+    pub fn new(s: impl AsRef<str>) -> Result<Self, AcpPrefixError> {
+        DottedNatsToken::new(s.as_ref()).map(Self).map_err(AcpPrefixError)
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/acp-nats/src/acp_prefix.rs` around lines 38 - 40, Change
AcpPrefix::new to accept impl AsRef<str> instead of impl Into<String> to avoid
allocating for borrowed inputs; call DottedNatsToken::new(s.as_ref()) and
propagate errors as before (map(Self).map_err(AcpPrefixError)). Update the
parameter name if needed and remove the s.into() allocation so the function
forwards the borrowed &str directly to DottedNatsToken::new while preserving
error mapping to AcpPrefixError.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rsworkspace/crates/acp-nats/src/acp_prefix.rs`:
- Around line 38-40: Change AcpPrefix::new to accept impl AsRef<str> instead of
impl Into<String> to avoid allocating for borrowed inputs; call
DottedNatsToken::new(s.as_ref()) and propagate errors as before
(map(Self).map_err(AcpPrefixError)). Update the parameter name if needed and
remove the s.into() allocation so the function forwards the borrowed &str
directly to DottedNatsToken::new while preserving error mapping to
AcpPrefixError.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 59990479-0d34-4602-982b-c2926fd5bb8e

📥 Commits

Reviewing files that changed from the base of the PR and between 3616890 and b952bac.

📒 Files selected for processing (10)
  • rsworkspace/crates/acp-nats/src/acp_prefix.rs
  • rsworkspace/crates/acp-nats/src/constants.rs
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs
  • rsworkspace/crates/acp-nats/src/nats/mod.rs
  • rsworkspace/crates/acp-nats/src/session_id.rs
  • rsworkspace/crates/acp-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/lib.rs
  • rsworkspace/crates/trogon-nats/src/nats_token.rs
  • rsworkspace/crates/trogon-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/token.rs
💤 Files with no reviewable changes (2)
  • rsworkspace/crates/acp-nats/src/nats/mod.rs
  • rsworkspace/crates/acp-nats/src/constants.rs
✅ Files skipped from review due to trivial changes (2)
  • rsworkspace/crates/trogon-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/token.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • rsworkspace/crates/acp-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/lib.rs
  • rsworkspace/crates/acp-nats/src/session_id.rs
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs

Signed-off-by: itsitsiridakis <iosif.tsitsiridakis@fanatics.live>
Signed-off-by: itsitsiridakis <iosif.tsitsiridakis@fanatics.live>
@yordis yordis force-pushed the refactor-single-token-and-multi-token-under-nats-token branch from b952bac to 243ba85 Compare April 1, 2026 18:18
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (3)
rsworkspace/crates/trogon-nats/src/nats_token.rs (3)

207-214: Add one multibyte boundary test for the 128-byte rule.

The current dotted-token length coverage only uses ASCII input, so it does not actually lock in the advertised byte-based limit. A small é.repeat(64) / é.repeat(65) case would catch an accidental switch from len() to chars().count() later.

Suggested test
     #[test]
     fn dotted_accepts_non_ascii() {
         assert!(DottedNatsToken::new("préfixe").is_ok());
     }
+
+    #[test]
+    fn dotted_length_is_measured_in_bytes() {
+        let max = "é".repeat(64); // 128 bytes
+        let too_long = "é".repeat(65); // 130 bytes
+
+        assert!(DottedNatsToken::new(&max).is_ok());
+        assert_eq!(
+            DottedNatsToken::new(&too_long),
+            Err(SubjectTokenViolation::TooLong(130))
+        );
+    }

Also applies to: 241-244

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/trogon-nats/src/nats_token.rs` around lines 207 - 214, Add
a test that verifies the 128-byte limit using multibyte characters so the
implementation is measured in bytes not chars: create a new test (or extend the
existing dotted_too_long and the similar test around lines 241-244) that uses a
multibyte character like "é" repeated 64 (which is 128 bytes) and 65 (130 bytes)
and assert DottedNatsToken::new(&multibyte64) is Ok and
DottedNatsToken::new(&multibyte65) returns
Err(SubjectTokenViolation::TooLong(...)); reference DottedNatsToken::new and
SubjectTokenViolation::TooLong to locate where to add the checks.

33-40: Still duplicates shared validation.

DottedNatsToken::new already gets the * / > / whitespace rule from rsworkspace/crates/trogon-nats/src/token.rs, but NatsToken::new re-implements that branch inline. That reintroduces drift between the two constructors. I’d pull the shared wildcard/whitespace predicate into token.rs and keep only the ASCII / dot-specific checks here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/trogon-nats/src/nats_token.rs` around lines 33 - 40,
Extract the shared wildcard/whitespace predicate used by DottedNatsToken::new
into token.rs (e.g., a small function like is_wildcard_or_whitespace(ch: char)
-> bool or is_invalid_wildcard_or_whitespace) and have both DottedNatsToken::new
and NatsToken::new call that predicate instead of duplicating the logic; then
simplify NatsToken::new to only perform the ASCII/dot checks and the MAX_LENGTH
check (keeping SubjectTokenViolation::TooLong and InvalidCharacter for
'.'/non-ascii) while delegating the '*'/'>'/whitespace checks to the new
function in token.rs so the validation logic stays centralized and consistent.

73-79: Move DottedNatsToken into its own file.

This file now contains two public value objects. The repository convention expects each value object to live in a file named after the type, so DottedNatsToken should live in dotted_nats_token.rs and be re-exported from the crate root.

As per coding guidelines "Every value object lives in its own file named after the type (e.g., acp_prefix.rs, ext_method_name.rs, session_id.rs), never inlined into config, aggregate, or service files".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/trogon-nats/src/nats_token.rs` around lines 73 - 79, Move
the public value object DottedNatsToken out of its current file into its own
module file named dotted_nats_token.rs: copy the pub struct
DottedNatsToken(Arc<str>) plus its derives and any impls, ensure it imports Arc
and other dependencies, and keep visibility as pub; then add a module
declaration and a pub re-export from the crate root (e.g., add pub mod
dotted_nats_token; and pub use dotted_nats_token::DottedNatsToken) so external
code imports remain unchanged; update any local uses/imports in the original
file to reference the re-export or the new module as needed and run tests to
confirm compile.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rsworkspace/crates/trogon-nats/src/nats_token.rs`:
- Around line 207-214: Add a test that verifies the 128-byte limit using
multibyte characters so the implementation is measured in bytes not chars:
create a new test (or extend the existing dotted_too_long and the similar test
around lines 241-244) that uses a multibyte character like "é" repeated 64
(which is 128 bytes) and 65 (130 bytes) and assert
DottedNatsToken::new(&multibyte64) is Ok and DottedNatsToken::new(&multibyte65)
returns Err(SubjectTokenViolation::TooLong(...)); reference DottedNatsToken::new
and SubjectTokenViolation::TooLong to locate where to add the checks.
- Around line 33-40: Extract the shared wildcard/whitespace predicate used by
DottedNatsToken::new into token.rs (e.g., a small function like
is_wildcard_or_whitespace(ch: char) -> bool or
is_invalid_wildcard_or_whitespace) and have both DottedNatsToken::new and
NatsToken::new call that predicate instead of duplicating the logic; then
simplify NatsToken::new to only perform the ASCII/dot checks and the MAX_LENGTH
check (keeping SubjectTokenViolation::TooLong and InvalidCharacter for
'.'/non-ascii) while delegating the '*'/'>'/whitespace checks to the new
function in token.rs so the validation logic stays centralized and consistent.
- Around line 73-79: Move the public value object DottedNatsToken out of its
current file into its own module file named dotted_nats_token.rs: copy the pub
struct DottedNatsToken(Arc<str>) plus its derives and any impls, ensure it
imports Arc and other dependencies, and keep visibility as pub; then add a
module declaration and a pub re-export from the crate root (e.g., add pub mod
dotted_nats_token; and pub use dotted_nats_token::DottedNatsToken) so external
code imports remain unchanged; update any local uses/imports in the original
file to reference the re-export or the new module as needed and run tests to
confirm compile.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 261cf29e-a463-4769-b4ab-f923319f33f8

📥 Commits

Reviewing files that changed from the base of the PR and between b952bac and 243ba85.

📒 Files selected for processing (10)
  • rsworkspace/crates/acp-nats/src/acp_prefix.rs
  • rsworkspace/crates/acp-nats/src/constants.rs
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs
  • rsworkspace/crates/acp-nats/src/nats/mod.rs
  • rsworkspace/crates/acp-nats/src/session_id.rs
  • rsworkspace/crates/acp-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/lib.rs
  • rsworkspace/crates/trogon-nats/src/nats_token.rs
  • rsworkspace/crates/trogon-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/token.rs
💤 Files with no reviewable changes (2)
  • rsworkspace/crates/acp-nats/src/constants.rs
  • rsworkspace/crates/acp-nats/src/nats/mod.rs
✅ Files skipped from review due to trivial changes (3)
  • rsworkspace/crates/trogon-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/token.rs
  • rsworkspace/crates/acp-nats/src/acp_prefix.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • rsworkspace/crates/acp-nats/src/subject_token_violation.rs
  • rsworkspace/crates/trogon-nats/src/lib.rs
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs

yordis added 2 commits April 1, 2026 15:23
…o constants

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
rsworkspace/crates/trogon-nats/src/nats_token.rs (2)

205-213: Consider adding a test for multi-byte UTF-8 length behavior.

The dotted_too_long test uses ASCII strings where chars == bytes. Since DottedNatsToken accepts UTF-8 and enforces a byte-length limit, consider adding a test that verifies behavior with multi-byte characters (e.g., a string with 100 characters but 150 bytes should be rejected).

Example test
#[test]
fn dotted_too_long_multibyte() {
    // 'é' is 2 bytes in UTF-8; 65 of them = 130 bytes > 128
    let multibyte = "é".repeat(65);
    assert!(DottedNatsToken::new(&multibyte).is_err());
    // 64 'é' = 128 bytes, should be ok
    assert!(DottedNatsToken::new("é".repeat(64)).is_ok());
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/trogon-nats/src/nats_token.rs` around lines 205 - 213, Add
a unit test that verifies byte-length enforcement with multi-byte UTF-8
characters: call DottedNatsToken::new with a string of multi-byte chars (e.g.,
"é".repeat(65)) that exceeds the 128-byte limit and assert it errors, and also
assert that a string at the byte limit (e.g., "é".repeat(64)) is accepted; place
this alongside the existing dotted_too_long test so DottedNatsToken::new and the
byte-length behavior (SubjectTokenViolation::TooLong) are covered for UTF-8
multibyte inputs.

32-36: Inconsistent unit (chars vs bytes) for TooLong error across types.

NatsToken::new (line 36) reports TooLong(char_count) counting characters, while DottedNatsToken::new (line 94) reports TooLong(s.len()) counting bytes. Although the doc comments reflect this difference ("max 128 chars" vs "max 128 bytes"), the shared SubjectTokenViolation::TooLong(usize) variant provides no indication of the unit.

For pure ASCII in NatsToken, chars == bytes so it's effectively consistent. However, this dual interpretation of MAX_NATS_TOKEN_LENGTH could confuse callers or lead to inconsistent error messages.

Consider documenting in SubjectTokenViolation that TooLong represents "the exceeded measurement" or—if stricter consistency is desired—using byte length for both types.

Also applies to: 93-94

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rsworkspace/crates/trogon-nats/src/nats_token.rs` around lines 32 - 36,
SubjectTokenViolation::TooLong currently carries a bare usize but is populated
by NatsToken::new using char count and by DottedNatsToken::new using byte
length, which is ambiguous; either (A) make the semantics explicit by updating
SubjectTokenViolation (e.g., document TooLong as "exceeded measurement" and add
enum docs/comments stating whether the usize is bytes or chars) and update
NatsToken::new and DottedNatsToken::new errors to clearly state the unit in
their error construction/logging, or (B) standardize to a single unit (prefer
bytes) by changing NatsToken::new to measure s.len() (or change DottedNatsToken
to use s.chars().count()) and update MAX_NATS_TOKEN_LENGTH docstring
accordingly; locate and modify the enum SubjectTokenViolation::TooLong, the
constructors NatsToken::new and DottedNatsToken::new, and the constant
MAX_NATS_TOKEN_LENGTH to keep units consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rsworkspace/crates/trogon-nats/src/nats_token.rs`:
- Around line 205-213: Add a unit test that verifies byte-length enforcement
with multi-byte UTF-8 characters: call DottedNatsToken::new with a string of
multi-byte chars (e.g., "é".repeat(65)) that exceeds the 128-byte limit and
assert it errors, and also assert that a string at the byte limit (e.g.,
"é".repeat(64)) is accepted; place this alongside the existing dotted_too_long
test so DottedNatsToken::new and the byte-length behavior
(SubjectTokenViolation::TooLong) are covered for UTF-8 multibyte inputs.
- Around line 32-36: SubjectTokenViolation::TooLong currently carries a bare
usize but is populated by NatsToken::new using char count and by
DottedNatsToken::new using byte length, which is ambiguous; either (A) make the
semantics explicit by updating SubjectTokenViolation (e.g., document TooLong as
"exceeded measurement" and add enum docs/comments stating whether the usize is
bytes or chars) and update NatsToken::new and DottedNatsToken::new errors to
clearly state the unit in their error construction/logging, or (B) standardize
to a single unit (prefer bytes) by changing NatsToken::new to measure s.len()
(or change DottedNatsToken to use s.chars().count()) and update
MAX_NATS_TOKEN_LENGTH docstring accordingly; locate and modify the enum
SubjectTokenViolation::TooLong, the constructors NatsToken::new and
DottedNatsToken::new, and the constant MAX_NATS_TOKEN_LENGTH to keep units
consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 363dd4b3-903d-4fa5-a5d6-595b342dca54

📥 Commits

Reviewing files that changed from the base of the PR and between 243ba85 and 28a86f4.

📒 Files selected for processing (6)
  • rsworkspace/crates/acp-nats/src/acp_prefix.rs
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs
  • rsworkspace/crates/acp-nats/src/lib.rs
  • rsworkspace/crates/acp-nats/src/session_id.rs
  • rsworkspace/crates/trogon-nats/src/constants.rs
  • rsworkspace/crates/trogon-nats/src/nats_token.rs
💤 Files with no reviewable changes (1)
  • rsworkspace/crates/acp-nats/src/lib.rs
✅ Files skipped from review due to trivial changes (1)
  • rsworkspace/crates/trogon-nats/src/constants.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • rsworkspace/crates/acp-nats/src/ext_method_name.rs
  • rsworkspace/crates/acp-nats/src/session_id.rs

@yordis yordis merged commit 84355c0 into TrogonStack:main Apr 1, 2026
3 checks passed
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.

2 participants