Repository navigation
refactor(stack-encrypt)!: clearer names and modules for the dynamic record path - #2042
Conversation
The function returns the records of a source, one per row. The old name said how it worked and not what it returned.
The type is an error, so it is named as one and implements std::error::Error through thiserror, as the crate's other errors do. The function that converted it is now From<SourceRecordError> for the dynamic Error, so the caller uses the ? operator.
The dynamic module is behind a cargo feature, so rust-analyzer skipped it and showed no types or errors there.
SplitSource and Rows were the same shape under two names, and source_rows matched on one to build the other. Both are now OneOrMany<T>.
The type holds the row and the field the reader is at, which is what a cursor is. The variables that hold one are renamed with it.
It is the sink the whole source is walked into.
It is the sink for a row of a batch that is a sequence, as RecordMap is the sink for a row that is a map. The old name is wanted for an error type.
A SourceRecord was Result<_, Found>, with a description of a value in the place of an error. Its error is now NotARecord, which holds the Found and implements std::error::Error.
The file's other sinks use the short form: FieldSeq, SeqSink.
Only dynamic::record reads a source into records, so the reader now lives at dynamic/record/source.rs and its items are visible to record alone. The one test that reached it from dynamic::found moves with it.
… the plan Row is renamed SourceRecord, and source_rows is renamed into_source_records and takes the plan. They move into record::source with source_row (now source_record) and check_field, so record sees one function and one type for reading a source. The reader that runs before the plan is applied is private to the module: into_raw_fields, which returns RawFields.
It is the encrypted form of a record, and pairs with SourceRecord. A caller may not have stored it.
Plan, FieldPlan, Output, NullMode, Verb, the parser and its wire types move out of dynamic/record.rs into dynamic/plan.rs. record keeps the entry points and the conversions between a record's forms. No public path changes: record re-exports the plan's public items, so dynamic::record::plan and dynamic::record::Plan still resolve. Code outside the new module reads a plan through its accessors where it read private fields before. The tests stay in record.rs for now.
Only the dynamic module uses them, so they move out of the top-level plan module, which now holds PlanError alone. IntoLabel's public path is now stack_encrypt::dynamic::IntoLabel.
…ecord A plan describes a record, and Planned runs one, so both now live under dynamic/record with the source reader and FieldValues. record's helpers and the source module's items are visible to record and its submodules alone. The query module is the one user outside record. It reads a plan through record's public re-exports and two methods that stay visible to dynamic: FieldPlan::indexes and Plan::declared_context. dynamic::planned is now dynamic::record::planned. Its public types are still re-exported from dynamic.
The parser was a function named plan in a module that now has a submodule named plan. It is now an associated function: record::plan(frame) Plan::from_frame(frame) record::plan_with(frame, resolver) Plan::from_frame_with(frame, resolver) The _with form follows the crate's other pairs: Plan::new and Plan::new_with, encrypt and encrypt_with. Callers are updated in stack-encrypt, its fuzz target, eql-bindings, the EQL encryption tests, the Go guest and the current docs. The changelog entry also records the two paths that moved in earlier commits on this branch: plan::IntoLabel and dynamic::planned.
The module moved under dynamic/record, so the compiler's note points there.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
coderdan
left a comment
There was a problem hiding this comment.
Code review at 3a9d31623eaabbbdf221f40b42cf19284b0fdee6, by /code-review medium in Claude Code (Claude Opus 5.5).
The reviewer compared the moved code with next, using git's moved-code detection. Apart from plain moves, the changes are renames, narrower visibility, .fields becoming the .fields() accessor, and split_refusal becoming From<SourceRecordError> for Error. Each behaves as before. Both sides have 2,652 tests. The one test removed from found.rs is now in record/source.rs.
It found no behaviour defects. It found four doc comments that name the old paths, and I checked each one against the code. Three are inline below. The fourth is in a file this pull request does not change:
packages/stack-encrypt/src/target/operations.rs:739: the doc comment names its caller asdynamic::planned::compose. The module is nowdynamic::record::planned.
ADR 0007 and docs/plans/2026-10-24-stack-encrypt-api-plan.md also say dynamic::planned. They record the design as it was when they were written, so I will leave them as they are.
The record module's docs, the Absent type and a comment in target::operations named dynamic::planned, which is now dynamic::record::planned. The language integration guide pointed at plan.rs for the grammar, which record.rs still describes, and the source reader's docs now say a value that is not a record is a NotARecord error.
|
The fourth finding, in |
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed db03a5cf · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; code-review agent (manual pass) · claude-opus-5-5; mattpocock-skills:code-review · claude-opus-5-5; rust-security · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check
No behaviour defects. All three reviews compared the moved bodies with next and found them the same apart from the renames. The rust-security pass found no change to what is encrypted, what is bound into a context, or what input is accepted.
Findings (11): 11 minor — 7 inline, 4 below.
packages/stack-encrypt/src/target/index.rs:97(outside diff) minorIndexSpec's rustdoc says "dynamic::record::plandocuments that shape". That function is nowPlan::from_frame, and the name is in backticks, so rustdoc cannot catch it.packages/stack-encrypt/CHANGELOG.md:1201(outside diff) minor The "To upgrade" table in the same[Unreleased]section still tells users to parse a plan withdynamic::record::plan, which this PR removes. Lines 1310 and 1476 namerecord::planandrecord::plan_withthe same way. WritePlan::from_frameandPlan::from_frame_with.docs/plans/2026-11-22-recipher-typescript-sdk.md:454(outside diff) minor This plan is still in progress and tells implementers to calldynamic::record::plan(lines 454, 477, 1151 and 1366) and citessrc/dynamic/planned.rs(line 1302). Both are gone after this PR. Unlike ADR 0007 and the API plan, it is not a record of finished work.generalminor The #2040 plan pins its citations tonextat54e647124, but namesinto_raw_fields(its lines 77 and 478), which this PR adds. After this PR merges, its other citations move too, for examplerecord.rs:177(EQL_KEY) is nowrecord/plan.rs:25. Re-pin that plan after this merges.
Generated by Claude Code
…paths The IndexSpec rustdoc, three unreleased changelog entries and the TypeScript SDK plan named record::plan, which is now Plan::from_frame, and the plan cited planned.rs at its old path. Output's link to the stability section resolved against the wrong module after the move. The source reader's docs say what "the split" is now that split_source is renamed, and a test's doc comment names the rule it refers to.
|
The four findings outside the diff:
|
…to raw fields source.rs wrote Result<RawFields, NotARecord> out sixteen times. The type had the name SourceRecord before that name went to the record the plan checks.
…d the type is private The conversion from SourceRecordError to the dynamic Error moved to record/source.rs, and its test stayed in record.rs. That kept the struct and its fields visible to record, with two imports for tests alone. The test now sits in source.rs's tests, with a helper of its own for the one error variant it checks, so the struct and its fields are private.
NotARecord and SourceRecordError derive thiserror::Error, and nothing showed either message, so the text could change with no test failing. The test pins both. NotARecord names the kind of the value and never the value; SourceRecordError names no row, field or cause.
…crypted_records and encrypted_record The encrypt side says record (into_source_records, EncryptedRecord), and the stack-encrypt glossary lists row as a word to avoid for a field-by-field record. The decrypt side now matches. Both functions are private to the record module.
The spike in #2043 showed that a target can be declared once, as a sink for one walk of the value and a finishing step, and that the one declaration encrypts the target, decrypts it and gives its query terms. The combinators become adapters over that trait, as the standard library's iterator adapters are. This is how the plan's third decision is built, so the question of whether it still stands is answered. The plan now has: - the decisions made during the spike; - the declaration design, and what the compiler checks; - what the spike checked for encrypt, decrypt and query, what it did not cover, and the four ways it differs from today's code; - the layout of stack-encrypt and vitaminc-aead: the three calls as top-level modules, one place for each index, the order of the modules, and the crate root's 29 names; - the groundwork that can start now: #2042, the AES cipher in #2044, vitaminc-normalize and the layout moves; - step 1.4 as eight pull requests; - twelve new open questions, and answers to questions 1, 6 and 17. It replaces the record-sink design of the last commit, which the declaration design superseded.
The plan's file:line citations now point at next at b939de4, the merge of #2042. They were read at 54e6471. #2042 moved the dynamic record code. The match options' object form and EQL_KEY are now in dynamic/record/plan.rs, and bytes_node and the record decrypt doc are further up dynamic/record.rs. #2003 shifted lines in the Go SDK's query.go and records.go, and the EQL guest builds in tests-golang.yml. Every citation was updated. None could not be.
Summary
This pull request renames and moves code in stack-encrypt's dynamic record module, so it is easier to read before the changes planned in #2040. Behaviour does not change. Stored bytes do not change.
Three public paths change, and the stack-encrypt changelog records each one:
Plan::from_frame(frame)in place ofrecord::plan(frame).IntoLabelis now atstack_encrypt::dynamic::IntoLabel.dynamic::plannedis nowdynamic::record::planned. Its types are still re-exported fromdynamic.The dynamic module turns a record from a language binding into encrypted fields. A binding is the layer between the Rust code and another language, such as the Go guest. A plan is the description of a record that the binding sends with it. It says how each field is encrypted.
Changes
Module layout
dynamic/record/plan.rs.planned.rsand the source reader also move underdynamic/record/.FieldValuesandIntoLabelmove from the top-levelplanmodule intodynamic. The top-levelplanmodule now hasPlanErroralone.Names
Plan::from_frameandPlan::from_frame_withreplacerecord::planandrecord::plan_with.StoredRowbecomesEncryptedRecord, the pair ofSourceRecord.split_sourcebecomesinto_source_records. It now takes the plan and returns records that fit it.SplitRefusalbecomesSourceRecordError, an error type withthiserror.SplitSourceandRowsbecome one type,OneOrMany<T>.TopSinkbecomesSourceSink,PlacebecomesCursor, and theNotARecordsink becomesRecordSeq. The nameNotARecordnow belongs to an error type.Callers
Editor
.vscode/settings.jsonturns on stack-encrypt'sdynamicfeature for rust-analyzer.Verification
At
3a9d31623, on a Mac, with Rust 1.94.1:-D warnings.nexton this machine, and a different set fails on each run.-D warnings.go testpasses for every package.Related
Review notes
tests/ui, because the message namesplanned.rsat its new path.