From 00fbf0732b2c0ae7cdc7b7c6baee8f50b2cd8827 Mon Sep 17 00:00:00 2001 From: dawn Date: Mon, 5 Oct 2026 19:28:25 +0300 Subject: [PATCH] knot-record: encode strongRef cids as strings Signed-off-by: dawn --- knot2/crates/knot-record/src/comment.rs | 16 ++++++++++------ knot2/crates/knot-record/src/lib.rs | 19 +++++++++++++++++-- knot2/crates/knot-record/src/reaction.rs | 2 +- knot2/crates/knot-xrpc/src/tests.rs | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/knot2/crates/knot-record/src/comment.rs b/knot2/crates/knot-record/src/comment.rs index e7dd23bfe..6422a0131 100644 --- a/knot2/crates/knot-record/src/comment.rs +++ b/knot2/crates/knot-record/src/comment.rs @@ -4,7 +4,7 @@ use knot_types::{ use serde::{Deserialize, Serialize, Serializer}; use crate::ticket::MarkdownBody; -use crate::{CreatedAt, RecordError, encoded}; +use crate::{CidString, CreatedAt, RecordError, encoded}; pub const COMMENT_COLLECTION: &str = "org.tangled.feed.comment"; @@ -102,13 +102,13 @@ impl CommentRecord { #[derive(Serialize)] pub(crate) struct CommentRefEncoding { uri: AtUri, - cid: RecordCid, + cid: CidString, } pub(crate) fn ref_encoding(reference: &CommentRef, repo: &RepoDid) -> CommentRefEncoding { CommentRefEncoding { uri: reference.address.at_uri(repo), - cid: reference.cid, + cid: reference.cid.into(), } } @@ -172,7 +172,7 @@ mod tests { use crate::frozen; use knot_types::RecordRkey; - const COMMENT: &str = "a564626f6479a26474657874646b656c70652474797065781b6f72672e74616e676c65642e6d61726b75702e6d61726b646f776e65247479706578186f72672e74616e676c65642e666565642e636f6d6d656e74677375626a656374a263636964d82a58250001711220a9491f4c1bf7b0cffbadcba2db8f028e4b3f2867cb59e1f3a0bc1968f3c5124263757269783961743a2f2f6469643a706c633a73717569642f6f72672e74616e676c65642e747261636b2e7469636b65742f336c75627270747835376432326963726561746564417474313937302d30312d30315430303a30303a30315a6d782d746e676c2d656469746f7278206469643a706c633a3366776563646e76746373636a6e72783270346e37616c7a"; + const COMMENT: &str = "a564626f6479a26474657874646b656c70652474797065781b6f72672e74616e676c65642e6d61726b75702e6d61726b646f776e65247479706578186f72672e74616e676c65642e666565642e636f6d6d656e74677375626a656374a263636964783b62616679726569666a6a6570757967377877646837786c6f6c756c6e793661756f6a6d3773717a366c6c687137686966346466757068726973696963757269783961743a2f2f6469643a706c633a73717569642f6f72672e74616e676c65642e747261636b2e7469636b65742f336c75627270747835376432326963726561746564417474313937302d30312d30315430303a30303a30315a6d782d746e676c2d656469746f7278206469643a706c633a3366776563646e76746373636a6e72783270346e37616c7a"; use crate::test_support::{editor, squid, subject}; @@ -209,6 +209,7 @@ mod tests { #[derive(serde::Deserialize)] struct DecodedRef { uri: String, + cid: String, } #[derive(serde::Deserialize)] struct DecodedBody { @@ -228,7 +229,7 @@ mod tests { squid(), subject(), CommentMarkup::new(MarkdownBody::new("kelp").unwrap(), None), - Some(reply), + Some(reply.clone()), UnixSeconds::new(1), editor(), ) @@ -242,9 +243,12 @@ mod tests { decoded.subject.uri, "at://did:plc:squid/org.tangled.track.ticket/3lubrptx57d22" ); + assert_eq!(decoded.subject.cid, subject().cid().to_string()); + let reply_to = decoded.reply_to.unwrap(); assert_eq!( - decoded.reply_to.unwrap().uri, + reply_to.uri, "at://did:plc:squid/org.tangled.feed.comment/3lubrptx57d44" ); + assert_eq!(reply_to.cid, reply.cid().to_string()); } } diff --git a/knot2/crates/knot-record/src/lib.rs b/knot2/crates/knot-record/src/lib.rs index 0c3959828..1de2e2d71 100644 --- a/knot2/crates/knot-record/src/lib.rs +++ b/knot2/crates/knot-record/src/lib.rs @@ -22,8 +22,8 @@ pub mod ticket; use crate::ticket::{MAX_MENTIONS, MAX_REFERENCES, MarkdownBody, ProseError, TicketTitle}; use bytes::Bytes; use cid::Cid; -use knot_types::{AccountDid, AtUri, RecordBody, RecordBodyError, UnixSeconds}; -use serde::{Deserialize, Serialize}; +use knot_types::{AccountDid, AtUri, RecordBody, RecordBodyError, RecordCid, UnixSeconds}; +use serde::{Deserialize, Serialize, Serializer}; #[derive(Debug, thiserror::Error)] pub enum RecordError { #[error("atproto block error: {0}")] @@ -50,6 +50,21 @@ impl CreatedAt { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) struct CidString(RecordCid); + +impl From for CidString { + fn from(cid: RecordCid) -> Self { + Self(cid) + } +} + +impl Serialize for CidString { + fn serialize(&self, serializer: S) -> Result { + serializer.collect_str(&self.0) + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct Prose { pub(crate) title: TicketTitle, diff --git a/knot2/crates/knot-record/src/reaction.rs b/knot2/crates/knot-record/src/reaction.rs index 95a7f4ffc..3a585938a 100644 --- a/knot2/crates/knot-record/src/reaction.rs +++ b/knot2/crates/knot-record/src/reaction.rs @@ -94,7 +94,7 @@ mod tests { use crate::frozen; use crate::test_support::{editor, squid, subject}; - const REACTION: &str = "a565247479706578196f72672e74616e676c65642e666565642e7265616374696f6e677375626a656374a263636964d82a58250001711220a9491f4c1bf7b0cffbadcba2db8f028e4b3f2867cb59e1f3a0bc1968f3c5124263757269783961743a2f2f6469643a706c633a73717569642f6f72672e74616e676c65642e747261636b2e7469636b65742f336c7562727074783537643232687265616374696f6e66e29da4efb88f6963726561746564417474313937302d30312d30315430303a30303a30315a6d782d746e676c2d656469746f7278206469643a706c633a3366776563646e76746373636a6e72783270346e37616c7a"; + const REACTION: &str = "a565247479706578196f72672e74616e676c65642e666565642e7265616374696f6e677375626a656374a263636964783b62616679726569666a6a6570757967377877646837786c6f6c756c6e793661756f6a6d3773717a366c6c687137686966346466757068726973696963757269783961743a2f2f6469643a706c633a73717569642f6f72672e74616e676c65642e747261636b2e7469636b65742f336c7562727074783537643232687265616374696f6e66e29da4efb88f6963726561746564417474313937302d30312d30315430303a30303a30315a6d782d746e676c2d656469746f7278206469643a706c633a3366776563646e76746373636a6e72783270346e37616c7a"; #[test] fn reaction_record_bytes_frozen() { diff --git a/knot2/crates/knot-xrpc/src/tests.rs b/knot2/crates/knot-xrpc/src/tests.rs index ce3883c9a..128560d28 100644 --- a/knot2/crates/knot-xrpc/src/tests.rs +++ b/knot2/crates/knot-xrpc/src/tests.rs @@ -6165,7 +6165,7 @@ async fn comment_opens_edits_and_deletes_along_its_version_chain() { assert_eq!(record["value"]["$type"], COMMENT); assert_eq!(record["value"]["subject"]["uri"], issue.uri.as_str()); assert_eq!( - record["value"]["subject"]["cid"]["$link"], + record["value"]["subject"]["cid"], issue.cid.to_string(), "subject strongRef must name the exact issue versoon the comment was made on" ); -- 2.51.2