lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit 1848b9a7977ff20e7da1fabb601773b01adbcfb4
parent 7388ebdbe3070664dcd5546ffdb05dfe212e5313
Author: triesap <tyson@radroots.org>
Date:   Mon, 12 Oct 2026 04:43:16 +0000

nostr: preserve numeric wire kinds in job adapters

- Preserve named and custom event kinds through both job conversion traits.
- Decode signed feedback consistently with direct conversion and retain kind admission.
- Verify 104 tests and doctests, conversion-only checks and warnings-denied Clippy.
- Close the contained conversion deviation while leaving consumer qualification separate.

Diffstat:
Mcontracts/architecture/deviations.toml | 28++++++++++++++++++++++++++++
Mcrates/nostr/README.md | 5+++++
Mcrates/nostr/src/job_adapter.rs | 13+++----------
Mcrates/nostr/tests/coverage.rs | 81++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml @@ -2,6 +2,34 @@ schema_version = 1 architecture_id = "radroots.crates.release.v1" [[deviation]] +id = "RCRV1-DEV-028" +date = "2026-10-12" +status = "closed" +approval = "The user approved the full successor refactor and local verified checkpoints; publication and consumer qualification remain separate." +affected_steps = ["010", "070", "130"] +spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#package.radroots_nostr"] +source_evidence = [ + "Both EventAdapter trait implementations replace every named upstream Nostr kind with profile kind zero; custom kinds retain their number.", + "The locked Nostr dependency represents feedback kind 7000 as the named JobFeedback variant; the public trait feedback decoder requires numeric kind 7000.", + "The direct conversion functions already preserve numeric kinds, while the existing adapter coverage checks only a custom request and profile kind zero.", +] +replacement_action = "Reevaluate the public adapter with actual signed feedback and named/custom wire cases; if reproduced, preserve every numeric wire kind in both trait implementations while retaining decoder-owned job admission, public API shapes, features and dependencies." +verification = [ + "Validate this standalone deviation before changing production conversion and record failing regressions against unchanged production source.", + "Exercise borrowed and owned adapters, real feedback metadata/index decoding, direct conversion agreement and wrong-job-kind rejection.", + "Run exact Rust 1.99.0 scoped formatting, all-target check, full Nostr package tests and warnings-as-errors Clippy; review the exact owner diff before a local commit.", +] +unresolved_risk = "The contained Lib conversion repair is locally verified. Separate RHI adapter correction and exact supported consumer adoption remain pending; no deployed incident or full platform qualification is claimed." +normative_architecture_change = false +adr_required = false +closure_evidence = [ + "Both regressions failed against unchanged production conversion: named kind 1 became zero and real signed kind-7000 feedback failed the public trait decoder while direct conversion succeeded.", + "Borrowed and owned adapters now preserve named/custom wire kinds, including zero and u16 maximum; actual feedback metadata/index decoding agrees with direct conversion, and wrong-job-kind admission remains rejected.", + "Exact Rust 1.99.0 scoped formatting, all-feature/all-target check, all-feature package tests including 104 passing tests/doctests and zero ignored, conversion-only no-default-features library check and warnings-as-errors all-target Clippy passed on local macOS arm64.", + "Only private numeric conversion, its regressions, package guidance and this deviation changed. Public API shapes, features, dependencies, signing, networking, persistence and decoder admission are unchanged.", +] + +[[deviation]] id = "RCRV1-DEV-027" date = "2026-10-12" status = "closed" diff --git a/crates/nostr/README.md b/crates/nostr/README.md @@ -73,6 +73,11 @@ admission proves the received event and its typed projection; it does not prove that referenced events, authors, addresses, relays, or external resources exist. +`event::EventAdapter` preserves the original numeric wire kind in its borrowed +and owned job conversions, including named Nostr kinds such as feedback kind +7000. The job decoder separately enforces its supported kind; conversion does +not establish event authenticity or job admission. + ## Local signing The `signing` feature provides an opaque `key::SecretKey` and a concrete local diff --git a/crates/nostr/src/job_adapter.rs b/crates/nostr/src/job_adapter.rs @@ -5,8 +5,7 @@ #![forbid(unsafe_code)] -use crate::types::{RadrootsNostrEvent, RadrootsNostrKind}; -use radroots_event::envelope::kind::KIND_PROFILE; +use crate::types::RadrootsNostrEvent; use radroots_event_codec::decode::job::{JobEventBorrow, JobEventLike}; #[derive(Clone, Debug)] @@ -51,10 +50,7 @@ impl<'a> JobEventBorrow<'a> for EventAdapter<'a> { } #[inline] fn raw_kind(&'a self) -> u32 { - match self.evt.kind { - RadrootsNostrKind::Custom(v) => v as u32, - _ => KIND_PROFILE, - } + u32::from(self.evt.kind.as_u16()) } } @@ -69,10 +65,7 @@ impl JobEventLike for EventAdapter<'_> { self.evt.created_at.as_secs() } fn raw_kind(&self) -> u32 { - match self.evt.kind { - RadrootsNostrKind::Custom(v) => v as u32, - _ => KIND_PROFILE, - } + u32::from(self.evt.kind.as_u16()) } fn raw_content(&self) -> String { self.evt.content.clone() diff --git a/crates/nostr/tests/coverage.rs b/crates/nostr/tests/coverage.rs @@ -7,7 +7,7 @@ use nostr::{Keys as RadrootsNostrKeys, RelayUrl as RadrootsNostrRelayUrl, nips:: #[cfg(feature = "events")] use radroots_event::post::reply::{AuthoredNip10Reply, Nip10ReplyReference}; #[cfg(feature = "events")] -use radroots_event_codec::decode::job::{JobEventBorrow, JobEventLike}; +use radroots_event_codec::decode::job::{BorrowedEventAdapter, JobEventBorrow, JobEventLike}; #[cfg(feature = "events")] use radroots_nostr::event::build_nip10_reply as build_nip10_reply_event; #[cfg(feature = "events")] @@ -408,6 +408,85 @@ fn event_and_job_adapters_cover_native_value_boundaries() { #[cfg(feature = "events")] #[test] +fn job_adapter_preserves_named_and_custom_wire_kinds() { + let keys = make_keys(); + for wire_kind in [0_u16, 1, 6, 5_001, 6_001, 7_000, u16::MAX] { + let event = nostr::EventBuilder::new(RadrootsNostrKind::from(wire_kind), "kind") + .custom_created_at(RadrootsNostrTimestamp::from(1_700_000_000)) + .sign_with_keys(&keys) + .expect("signed synthetic event"); + let adapter = EventAdapter::new(&event); + assert_eq!(JobEventLike::raw_kind(&adapter), u32::from(wire_kind)); + assert_eq!(JobEventBorrow::raw_kind(&adapter), u32::from(wire_kind)); + if wire_kind != 7_000 { + assert!(matches!( + adapter.to_job_feedback_metadata(), + Err( + radroots_event_codec::decode::job::JobParseError::InvalidTag( + "kind (expected 7000)" + ) + ) + )); + } + } +} + +#[cfg(feature = "events")] +#[test] +fn job_adapter_decodes_signed_named_feedback_through_both_traits() { + let keys = make_keys(); + let request = nostr::EventBuilder::new(RadrootsNostrKind::Custom(5_001), "request") + .custom_created_at(RadrootsNostrTimestamp::from(1_700_000_000)) + .sign_with_keys(&keys) + .expect("signed synthetic request"); + let feedback = build_event_job_feedback(&request, "processing", None, None) + .expect("feedback builder") + .sign_with_keys(&keys) + .expect("signed synthetic feedback"); + assert_eq!(feedback.kind, RadrootsNostrKind::JobFeedback); + feedback.verify().expect("valid signed feedback"); + let adapter = EventAdapter::new(&feedback); + let tags = JobEventLike::raw_tags(&adapter); + let borrowed = BorrowedEventAdapter::new( + &adapter, + feedback.created_at.as_secs(), + &tags, + feedback.sig.to_string(), + ); + let expected = to_job_feedback_metadata(&feedback).expect("direct feedback metadata"); + assert_eq!(expected.kind, 7_000); + assert_eq!(expected.data.kind, 7_000); + assert_eq!(expected.data.request_event.id, request.id.to_hex()); + assert_eq!( + adapter.to_job_feedback_metadata().expect("owned metadata"), + expected + ); + assert_eq!( + borrowed + .to_job_feedback_metadata() + .expect("borrowed metadata"), + expected + ); + for parsed in [ + adapter + .to_job_feedback_event_index() + .expect("owned feedback index"), + borrowed + .to_job_feedback_event_index() + .expect("borrowed feedback index"), + ] { + assert_eq!(parsed.data, expected); + assert_eq!(parsed.event.kind_u32(), 7_000); + assert_eq!(parsed.event.id_hex(), feedback.id.to_hex()); + } + assert_eq!( + to_job_feedback_index(&feedback).expect("direct index").data, + expected + ); +} + +#[cfg(feature = "events")] +#[test] fn application_handler_builder_covers_optional_metadata_and_tag_filters() { assert!(build_application_handler(&ApplicationHandlerSpec::new(Vec::new())).is_err()); let empty = nostr::Metadata::new();