Add user message wire contract - #32
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 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. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new usermessage package that defines and validates a v1 JSON wire contract for fetching resolved in-app user messages, along with embedded fixtures and compatibility/validation tests.
Changes:
- Introduces v1 request/response/message/action types with explicit wire-size limits.
- Adds validation for request, response, resolved message content, and allowlisted actions (including HTTPS URL validation).
- Adds versioned embedded JSON fixtures and tests covering round-trip JSON compatibility and validation rules.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| usermessage/types.go | Defines the v1 wire-contract structs, enums, and size-limit constants. |
| usermessage/validation.go | Implements validation for the v1 request/response/message/action contract. |
| usermessage/types_test.go | Adds fixture round-trip tests and targeted validation/limits tests. |
| usermessage/testfixtures/fixtures.go | Exposes embedded, versioned JSON fixtures via an embed.FS. |
| usermessage/testfixtures/v1/request.json | Adds a v1 request fixture used for compatibility tests. |
| usermessage/testfixtures/v1/response_empty.json | Adds a v1 “no message” response fixture. |
| usermessage/testfixtures/v1/response_message.json | Adds a v1 response fixture containing a message with an HTTPS URL action. |
| usermessage/testfixtures/v1/response_no_action.json | Adds a v1 response fixture containing a message without an action. |
| usermessage/testfixtures/v1/response_open_plans.json | Adds a v1 response fixture containing a message with an open_plans action. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| parts := strings.Split(value, "-") | ||
| if len(parts) == 1 && (strings.EqualFold(parts[0], "x") || strings.EqualFold(parts[0], "i")) { | ||
| return invalid(field, "must include a subtag after the private-use or grandfathered prefix") | ||
| } | ||
| for i, part := range parts { | ||
| if len(part) == 0 || len(part) > 8 { | ||
| return invalid(field, "must be a BCP 47 language tag") | ||
| } | ||
| for _, r := range part { | ||
| if r > unicode.MaxASCII || !unicode.IsLetter(r) && !unicode.IsDigit(r) { | ||
| return invalid(field, "must contain only BCP 47 subtags") | ||
| } | ||
| } | ||
| if i == 0 { | ||
| if len(part) < 2 && !strings.EqualFold(part, "x") && !strings.EqualFold(part, "i") { | ||
| return invalid(field, "must begin with a language subtag") | ||
| } | ||
| for _, r := range part { | ||
| if !unicode.IsLetter(r) { | ||
| return invalid(field, "must begin with a language subtag") | ||
| } | ||
| } | ||
| } | ||
| } |
For https://github.com/getlantern/engineering/issues/3784