Skip to content

Unpack the payload in the dotrain TryFrom impls - #246

Merged
thedavidmeister merged 3 commits into
mainfrom
2026-08-25-issue-162
Aug 31, 2026
Merged

Unpack the payload in the dotrain TryFrom impls#246
thedavidmeister merged 3 commits into
mainfrom
2026-08-25-issue-162

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Closes #162

DotrainSourceV1 and OrderBuilderStateV1 built themselves from value.payload directly, ignoring the item's content_encoding. A ContentEncoding::Deflate item that unpack() decodes correctly failed with FromUtf8Error / SerdeCborError on the compressed bytes.

Both now go through value.unpack()?, which is what every other TryFrom<RainMetaDocumentV1Item> in the crate does: OpMeta, AuthoringMeta, AuthoringMetaV2, SolidityAbiMeta, JsonAbi, InterpreterCallerMeta, RaindexSignedContextOracleV1, String, Vec<u8>.

The issue flags a fork — either dotrain metas are defined to be ContentEncoding::None always (and the constraint should be checked), or unpack() should be used. This takes the second branch, because the crate has already ruled that way for RaindexSignedContextOracleV1: test_try_from_unpacks_content_encoding there is on main asserting "TryFrom must unpack() the payload (honouring content_encoding), not read the raw bytes".

ContentEncoding::None and Identity decode to the same bytes, so items produced by the encoders here (From<DotrainSourceV1> and TryFrom<OrderBuilderStateV1>, both emitting ContentEncoding::None) round-trip unchanged. No caller outside these two files reaches these impls other than through unpack_into, which routes both magics here already.

QA

  • Discriminating tests: meta::types::dotrain::source_v1::tests::test_try_from_unpacks_content_encoding and meta::types::dotrain::order_builder_state_v1::tests::test_try_from_unpacks_content_encoding — each fails on base (both impls reverted in the working tree to the pre-fix value.payload reads, tests kept: test result: FAILED. 30 passed; 2 failed, panicking on FromUtf8Error { bytes: [120, 156, ...], valid_up_to: 1 } and SerdeCborError(InvalidUtf8, offset: 2) — the zlib 78 9c header). With the fix: test result: ok. 32 passed; 0 failed (cargo test -p rain-metadata --lib meta::types::dotrain::).
  • Mutations applied: crates/cli/src/meta/types/dotrain/source_v1.rs:94 String::from_utf8(value.unpack()?) -> String::from_utf8(value.payload.to_vec()) -> killed by source_v1::tests::test_try_from_unpacks_content_encoding; crates/cli/src/meta/types/dotrain/order_builder_state_v1.rs:147 from_slice::<OrderBuilderStateV1>(&value.unpack()?) -> from_slice::<OrderBuilderStateV1>(&value.payload) -> killed by order_builder_state_v1::tests::test_try_from_unpacks_content_encoding. Both mutations restore exactly the reported defect; the 30 pre-existing dotrain tests survive them, which is why the two new ones are needed.
  • Oracle: the envelope contract, not the impls under test. The expected value is the input given to ContentEncoding::Deflate.encode() before the item is built ("/* some dotrain code */"; the create_test_instance() struct), and RainMetaDocumentV1Item::unpack() is documented to decode the payload "based on the configuration". Every other TryFrom<RainMetaDocumentV1Item> in the crate already honours it.
  • Category check: issue names two units — DotrainSourceV1::try_from reading value.payload and OrderBuilderStateV1::try_from reading value.payload; both covered, one discriminating test each. The issue's alternative branch (assert ContentEncoding::None instead of unpacking) is deliberately not taken, for the reason above.

🤖 Generated with Claude Code

DotrainSourceV1 and OrderBuilderStateV1 read value.payload directly, so a
Deflate-encoded item that unpack() decodes correctly failed with a utf8 or
cbor error. Every other TryFrom<RainMetaDocumentV1Item> honours
content_encoding via unpack().

Closes #162

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 29 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 82baf3d4-e5ed-406d-9488-da72ae030497

📥 Commits

Reviewing files that changed from the base of the PR and between 40b3c43 and ee042f5.

📒 Files selected for processing (2)
  • crates/cli/src/meta/types/dotrain/order_builder_state_v1.rs
  • crates/cli/src/meta/types/dotrain/source_v1.rs

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.

…_meta nesting bound

Both sides appended to the tail of order_builder_state_v1.rs's test module.
Kept the PR's test_try_from_unpacks_content_encoding and main's
nest_document helper plus its three MAX_NESTED_DOCUMENT_DEPTH tests; the
TryFrom impl keeps value.unpack()? and extract_from_meta keeps its
depth-bounded walk.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Conflict in `order_builder_state_v1.rs`: this branch still carried
`test_extract_from_meta_nested_rain_document`, which #303 deleted when it
made an item claiming the document magic corrupt rather than a document
to descend into. Resolved to main's side - the nesting tests are
`..._nested_document_is_corrupt` and `..._deep_nesting_costs_one_decode`
now - keeping this branch's `test_try_from_unpacks_content_encoding`.

The two do not interact: one is about what an item's magic may be, the
other about honouring its content_encoding.

cargo test --workspace --lib 353 passed 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014RoHV66knQy6ya7NNkFLpK
@thedavidmeister
thedavidmeister merged commit 2aa3578 into main Aug 31, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

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.

DotrainSourceV1/OrderBuilderStateV1 TryFrom<RainMetaDocumentV1Item> read raw payload, ignoring content_encoding

1 participant