Repository navigation
refactor(cli): build the SSE event body from flatten_row_event - #1146
Merged
Merged
Conversation
The HTTP /events serializer was the third hand-written flattening of RowEvent, repeating the action strings, the Update new_row/old_row split and the Error variant's nullable table and lossy path. It now consumes the core's flatten_row_event and adds only the transport's own shape: a presence check on the flat error that picks between the row keys and the error key. The wire body is unchanged byte for byte. serde_json's Map is a BTreeMap here, so the hand-built map renders in the same alphabetical key order as the json! literals it replaces.
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.
Fixes #1139. Part of #1072.
event_to_valueinpackages/rust/src/cli/serialize.rswas the thirdhand-written
RowEventflattening: an arm-for-armmatchrepeating thelowercase action strings, the
Updatenew_row/old_row split, and theErrorvariant's nullable table and
to_string_lossypath. #1131 moved thosedecisions into
dirsql::flatten_row_eventand cut both bindings over; this isthe missed call site.
The SSE shape is not the flat struct — the error arm omits
row/old_rowentirely and the row arms carry no
errorkey — so the serializer consumesflatten_row_eventand adds only that transport detail: a presence check onflat.error.row_to_jsonstill does the cell marshaling, blob-to-hexincluded.
Key order is unchanged because
serde_json::Mapis aBTreeMaphere(
cargo tree -p dirsql -i serde_json -e features | grep -c preserve_order→0), so the hand-built map renders alphabetically exactly as thejson!literals did.
Two assertions were added, neither weakening an existing one: the insert test
now asserts no
errorkey, and a new test covers the error arm'stable: nullplus the absence of
row/old_row.PARITY.mdgains a line noting the SSE serializer shares the same source.This restores parity rather than introducing drift; no SDK API or CLI flag
changed.
Byte-identical SSE proof
Built the CLI twice from the same worktree — once at
origin/main, once withthe change — and ran the identical scenario against the same fixture path
(insert, update, error, delete) with
curl -sN http://localhost:7139/events.Fixture (
/tmp/dirsql-1139-fixture): apoststable overposts/*/*.jsonwhose
on-filehook emitsbasename/size, and prints non-JSON for any filenamed
bad*so the error arm fires. Driven by:Both binaries produced, byte for byte:
(The captures also contain a duplicate error line from the hook running twice
on the create+write pair; it is present identically in both.)
Coverage
cargo +nightly llvm-cov --lib --features cli --branchinpackages/rust:regions 93.67%, functions 93.16%, lines 94.54%, branch 79.49% — all above the
[rust.coverage]floors (lines 92 / functions 91 / regions 91 / branch 72).No floor moved.
unit mutation(rust): 1 mutant tested, 0 survivors.E2E Verification
packages/python/e2e-attestations/<branch>.jsonreceipt written ifpackages/pythonchanged (just e2e-attest-python)packages/ts/e2e-attestations/<branch>.jsonreceipt written ifpackages/tschanged (just e2e-attest-ts)cargo test --workspace --features cli;just e2e-attest-python;just e2e-attest-ts;just preflightjust preflight→0 failing pair(s), 3 skipped.Changelog / Migrations
<root>/<pkg>/changelog.d/for each changed package (or:skip-changelogtrailer on a commit with reason)<root>/<pkg>/migrations.d/(or: not required -- additive/bugfix only)Changelog:
packages/rust/changelog.d/2026-09-18-sse-shares-flatten-row-event.md(Changed). No migration fragment: the refactor is behavior-preserving and
the wire body is unchanged.