Repository navigation
refactor(stack-encrypt): move the JsonDocument EQL simulators into eql_simulator - #1758
Conversation
|
|
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
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change separating database-read simulation from the production JSON API.
No open issues 🎉
What changed in this PR
Separates database-read simulation from Stack Encrypt’s production JSON API, addressing #1755 and updating the child-read examples added in #1751. Stored bytes and production decryption behavior remain unchanged.
Changes:
- Moves four public
JsonDocumenthelpers intoeql_simulator, behind an off-by-default feature, while retaining private lookup for whole-document decryption. - Enables the feature for tests and migrates callers and examples to the new functions.
- Documents the database’s role and provides breaking-change migration steps.
| File | Description |
|---|---|
packages/stack-encrypt/tests/json_tree_vectors.rs |
Uses simulator token lookup for test vectors. |
packages/stack-encrypt/tests/json_read_checks.rs |
Migrates read-authentication test helpers. |
packages/stack-encrypt/tests/json_properties.rs |
Migrates property tests and updates explanatory comments. |
packages/stack-encrypt/tests/json_owned.rs |
Migrates owned-document read helpers. |
packages/stack-encrypt/tests/json_operators.rs |
Uses simulator functions to construct operator test rows. |
packages/stack-encrypt/tests/json_leakage/mod.rs |
Updates simulator naming in comments only. |
packages/stack-encrypt/tests/json_leakage/distinguishers.rs |
Updates walk descriptions in comments only. |
packages/stack-encrypt/tests/json_leakage/chain.rs |
Updates the simulator reference in a comment only. |
packages/stack-encrypt/tests/json_leakage/calibration.rs |
Compares the leakage harness with the relocated simulator. |
packages/stack-encrypt/tests/json_index.rs |
Migrates JSON index tests to simulator functions. |
packages/stack-encrypt/tests/json_field_references.rs |
Migrates token lookup and child-read tests. |
packages/stack-encrypt/tests/heap_hygiene.rs |
Uses simulator functions to prepare memory-hygiene test inputs. |
packages/stack-encrypt/src/lib.rs |
Exports the feature-gated module and documents test usage. |
packages/stack-encrypt/src/json/query.rs |
Updates the child-opening example and its SQL explanation. |
packages/stack-encrypt/src/json/plaintext.rs |
Updates the child-plaintext example and its SQL explanation. |
packages/stack-encrypt/src/json/mod.rs |
Makes helpers crate-private and gates simulation-only methods. |
packages/stack-encrypt/src/eql_simulator.rs |
Adds documented wrappers around the existing read helpers. |
packages/stack-encrypt/CHANGELOG.md |
Records the breaking change and migration steps. |
packages/stack-encrypt/Cargo.toml |
Adds the feature and self dev-dependency for tests. |
packages/eql/tests/encryption/tests/json_tree_field_references.rs |
Migrates simulated child reads in EQL tests. |
packages/eql/tests/encryption/tests/json_tree_data_plan.rs |
Migrates simulated subtree and extraction rows. |
packages/eql/tests/encryption/Cargo.toml |
Enables the simulator for EQL encryption tests. |
docs/plans/2026-10-17-json-tree-index.md |
Documents the helpers’ new location. |
Cargo.lock |
Records the self dev-dependency. |
AGENTS.md |
Documents simulator usage and SQL-parity expectations. |
Review effort: Balanced
Mutation testing (cargo-mutants,
|
| caught | missed | unviable | timeout |
|---|---|---|---|
| 14 | 0 | 14 | 0 |
Every mutant in the changed lines was caught by a test.
There was a problem hiding this comment.
Review attestation
Reviewed 63fa97c3 · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review · claude-opus-5-5; rust-security agent · claude-opus-5-5 (subagents ran with no model override)
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check, company-skills:review-post
Findings (4): 1 major, 3 minor. 3 inline, 1 below. rust-security found nothing: eql-simulator stays off in every shipped build (root workspace normal edges, the Go guests, eql-bindings, protect-ffi), and the moved functions handle no key or plaintext. Two other candidates were refuted at head: the mismatched cfg gate on node, and feature unification through the self dev-dependency. No current caller triggers either.
packages/stack-encrypt/src/json/mod.rs:549-640minor Issue #1755 item 1 asks to move the four methods into the module, and item 5 keeps onlyfindcrate-private. Herechildren,subtree,walkandnodestill live inimpl JsonDocument, with comments such as "as the server enumerates them". The public surface moved and the code did not. Moving the bodies intoeql_simulator.rsis feasible: they need publicheader()/entries(), andderive::self_tag/parent_tag/hit_tokenraised topub(crate). Gate the moduleany(test, feature)for the unit test atmod.rs:1161. That also removes the duplicated docs.
Generated by Claude Code
coderdan
left a comment
There was a problem hiding this comment.
Human review. LGTM assuming agent findings are addressed.
…l_simulator `JsonDocument` had four public methods: `find`, `children`, `subtree`, and `node`. Each one copies, in Rust, part of what the database (EQL) does when an app reads a stored JSON document. Production code never calls them, because the database does that work. Tests and doc examples call them so that they run without PostgreSQL. As public methods, they looked like part of the normal read, and any change to them was a breaking change. The four methods are now functions in a new module, `stack_encrypt::eql_simulator`. The module is behind a new feature, `eql-simulator`. The feature is off by default. - `json_tree_children(&doc, token)` copies `eql_v4.json_tree_children`. - `json_tree_subtree(&doc, tokens)` copies `eql_v4.json_tree_subtree` with a budget of 0. - `find_by_token(&doc, token)` copies how the EQL functions find the entry a token names. EQL has no public function for that step. - `entry_row(&doc, slot)` copies `eql_v4_internal.json_tree_graft`, the row the database returns for one entry. That SQL function is internal, so the Rust name says what it does instead. The new functions call crate-private `JsonDocument` methods, so the code is not copied. Decrypting a whole document uses `find`, so `find` is compiled in every build. The other three methods and the private `walk` compile only with the feature or in unit tests. stack-encrypt's integration tests and doctests turn the feature on through a path-only dev-dependency on the crate itself. That dependency turns default features off, so `--no-default-features` test builds stay free of `http`. The EQL encryption test crate turns the feature on in its `Cargo.toml`. No fuzz crate, bench, or Go guest used the methods. The Go guests build without the feature. The doc examples call the module and show the SQL each call stands in for. The CHANGELOG has a Breaking entry with the upgrade steps. No stored byte changes. Closes #1755
The `eql_simulator` functions called crate-private `JsonDocument` methods. So each behaviour was documented twice, once on the method and once on the function, and nothing kept the two in step. The code of `children`, `subtree`, `walk`, and `node` is now in `src/eql_simulator.rs`, as the functions themselves. The docs for each behaviour exist once. `JsonDocument::find` stays crate-private on `JsonDocument`, because decrypting a whole document uses it. `find_by_token` calls it, and has the full doc. The module reads the document through the public `header()` and `entries()`. The module also calls `derive::parent_tag` and `derive::hit_token`. Those two functions are now `pub(crate)`. The `json::derive` module is `pub(crate)` too. A new crate-private `JsonNode::new` builds the row that `entry_row` returns. The module compiles with the `eql-simulator` feature or in unit tests. So the unit test that walks a long forged chain calls `eql_simulator::json_tree_subtree`. The public API still shows the module only when the feature is on. The functions return the same rows, in the same order, with the same stopping rules. Also from the review: - The upgrade line in the CHANGELOG and in the module docs now names `version = "0.4"`. The Breaking entry is released as 0.4.0. Version 0.3.x has no `eql-simulator` feature. - The doc examples on `JsonSubtreeKey::open_child` and `JsonChildPlaintext` say, on the import line, that `eql_simulator` needs the `eql-simulator` feature.
d4ef7cc to
0d3ce6d
Compare
|
Review 6015579923, "move the bodies": done in 0d3ce6d. The code of the four read helpers is now in |
coderdan
left a comment
There was a problem hiding this comment.
Human pass. LGTM.
coderdan
left a comment
There was a problem hiding this comment.
Human pass. LGTM.
Summary
Stack Encrypt's
JsonDocumentloses four public methods. Each one copies, in Rust, what the database (EQL) does when your app reads part of an encrypted JSON document. The same code is now in a new module,stack_encrypt::eql_simulator, behind a new Cargo feature,eql-simulator. The feature is off by default. Production code never needed these methods, so the move only affects tests and examples that read a stored document without PostgreSQL.Changes
The four methods moved to functions in
stack_encrypt::eql_simulator. The names follow the EQL SQL function each one copies, where a public one exists.doc.children(token)json_tree_children(&doc, token)eql_v4.json_tree_childrendoc.subtree(tokens)json_tree_subtree(&doc, tokens)eql_v4.json_tree_subtree(doc, tokens, 0)doc.find(token)find_by_token(&doc, token)doc.node(slot)entry_row(&doc, slot)eql_v4_internal.json_tree_graft, the row for one entryLibrary code:
stack_encrypt::eql_simulatoritself:json_tree_children,json_tree_subtree(with a privatewalk),find_by_token, andentry_row.JsonDocumentkeeps only a crate-privatefind, because decrypting a whole document uses it.find_by_tokencalls it.eql-simulatorfeature, or in this crate's unit tests. The public docs show it only when the feature is on.derive::parent_tagandderive::hit_tokenare nowpub(crate).Callers:
--no-default-featurestest builds still leave outhttp.packages/eql/tests/encryption) turns the feature on in itsCargo.toml.eql_simulator::json_tree_subtreeinstead ofJsonDocument::subtree.JsonSubtreeKey::open_childandJsonChildPlaintext) call the module. Each one has one comment that shows the SQL query the call stands in for.Documentation:
AGENTS.mdand the JSON tree design plan name the new module.Verification
I ran these on this branch. Each one passed unless the line says otherwise.
cargo fmt --checkfor stack-encrypt and for the EQL workspace.cargo clippy -p stack-encrypt -- -D warningswith every feature, with--no-default-features, and with default features. Each ran with--all-targets, and again on the library alone, where the new feature stays off.cargo build -p stack-encryptwith default features and with--no-default-features, so the library builds withouteql-simulator.cargo test -p stack-encrypt --all-features: 1,655 tests passed and 1 was ignored. The count includes thetests/uisnapshots, and they did not change. With--no-default-features, 1,052 tests passed. The module's doc example and the two updated doc examples ran in both builds.cargo doc --no-deps -p stack-encryptwithRUSTDOCFLAGS='-D warnings', with default features, with--no-default-features, and with every feature. No page in the builds without the feature links toeql_simulator.cargo test -p eql-bindings -p eql-codegen -p eql-encryption-tests --all-featurespassed 622 tests, with 65 ignored, because those tests need PostgreSQL. I did not run the PostgreSQL suite. Clippy passed.cargo docfor eql-bindings fails with 10 rustdoc errors, such asunresolved link to super::all. This branch does not change eql-bindings, and an earlier branch in this stack showed the same 10 errors.go test ./...passed inlanguages/golang, andgo generate ./...changed no file.cargo mutants --in-diffon this branch's diff found 15 mutants. Tests caught 4. The other 11 did not compile. No mutant survived.cargo udeps. That check needs a pinned nightly toolchain that is not installed here.Related
Closes #1755
Follows #1751, now merged. That pull request added
JsonSubtreeKey::open_childand the doc examples this branch updates.Review notes
find_by_tokenhas no SQL function of its own: the EQL functions look the token's self tag up in the map thateql_v4_internal.json_tree_indexbuilds.entry_rowcopieseql_v4_internal.json_tree_graft. That function is internal and its name says little to a reader, so the Rust name says what the function returns.Cargo.tomlalready builds docs.rs pages with every feature on, so the module shows on docs.rs. I kept that, because test authors need to find the module. The module's first lines say what it is and that it needs the feature.cargo publishdrops it. The dependency addsstack-encryptto its own dependency list inCargo.lock.