Repository navigation
fix: match the server's NATS subject encoding for segments with dots - #13
Merged
Merged
Conversation
The server now maps each URI segment to one subject token and percent-encodes every byte outside [A-Za-z0-9_-] (priompt/priompt#33), so priompt://acme.corp/x/a.b publishes on priompt.acme%2Ecorp.x.a%2Eb. subject() still joined segments with "." unencoded, so subscribe() on such a URI listened on a subject the server no longer uses. Dot-free URIs keep their subject. subject() is exported for the tests, which reuse the server's cases. Adds an npm test suite (node:test) and runs it in CI. Fixes #12 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
priompt/priompt#33 changes the server's URI-to-subject mapping (
internal/pubsub.Subject). Each URI segment becomes one subject token, and every byte outside[A-Za-z0-9_-]is percent-encoded with uppercase hex:subject()inclient.jsstill replaced/with.and left segment contents as they were. So against that server,subscribe()on a URI with a dot (or any other encoded byte) in a segment listened on a subject that never receives events.Fix
subject()now does the same thing as the server'sSubject/subjectToken. It strips thepriompt://prefix, splits on/, and percent-encodes each segment per UTF-8 byte (Go's loop works on bytes too), using uppercase two-digit hex. Dot-free URIs keep their subject, so nothing changes against current servers for them.subjectis now exported next toPromptClientso the tests can call it.Test evidence
test/subject.test.jsreuses the server's cases fromTestSubjectIsInjective/TestSubjectMapping: the three collision pairs,agent-v2_x,priompt://acme.corp/x/a.b, and a non-ASCII segment.Before the fix (main):
After:
Cross-check against the server's own Go
Subject()on the #33 branch (91eb76b): JS output equals Go output for 10 URIs (the collision pairs plusacme/café→priompt.acme.caf%C3%A9andacme/a b/~x→priompt.acme.a%20b.%7Ex).Real run with a server built from priompt/priompt#33, on
priompt://acme/support/agent.v2(subscribe, then publish over gRPC):Notes
npm testscript and CI line.Fixes #12
🤖 Generated with Claude Code