open-standards/smart-byte/smart-byte-rs/crates/smart-byte-activitypub/tests/follow_accept.rs
Transaction Science fdc9cf6ab0 ingest wave C: 3 crates · op-statements + smart-byte-activitypub + eoc-observability
OpenPay (1 crate, ~2940 LOC, 40 tests)
  op-statements         Statement generation + reconciliation + fee accounting.
                        Render targets: PDF (template), CSV, JSON, 94-char
                        NACHA fixed-width. ISO 20022 camt.053 with full
                        BkToCstmrStmt envelope (GrpHdr/Stmt/Bal/Ntry). BAI2
                        with 01/02/03/16/49/98/99 records. MT940/MT942
                        SWIFT with :20:/:25:/:28C:/:60F:/:61:/:86:/:62F:
                        + :90C:/:90D: counters. FeeBucket (interchange/scheme/
                        acquirer/fx/settlement-network/bnpl) + FeeSchedule
                        with bps + flat rules. Cadence (daily/weekly/monthly/
                        custom). Two-tier Reconciler (external_id → window
                        heuristic).

Smart Byte (1 crate, 3032 LOC, 39 tests)
  smart-byte-activitypub ActivityPub W3C Rec (2018). AS2 vocab + Public
                         addressing; Actor (Person/Application/Group/
                         Organization/Service) with publicKey + shared-inbox;
                         Object (Note/Article/Image/Video/Tombstone) with
                         Mastodon extensions (sensitive, CW summary,
                         conversation, blurhash); 12 Activity types
                         (Create/Update/Delete/Follow/Accept/Reject/Announce/
                         Like/Undo/Move/Block/Flag) with side-effect rules;
                         OrderedCollection + Page; Webfinger (RFC 7033);
                         HTTP Signatures (cavage draft-12 + RFC 9421);
                         SHA-256 Digest; Ed25519 sign/verify.

EOC (1 crate, 2759 LOC, 20 tests)
  eoc-observability     OpenTelemetry-compatible tracing + metrics + logs.
                        W3C tracecontext + baggage. Span / SpanKind / Status.
                        Samplers: AlwaysOn/Off/RatioBased/ParentBased. Sync
                        BatchSpanProcessor + Exporter trait. Counter / Gauge /
                        Histogram. Prometheus text exposition (HELP/TYPE/
                        _bucket/_sum/_count/+Inf). StatsD / DogStatsD lines.
                        GenAI semconv (gen_ai.{operation,system,request.*,
                        response.*,usage.*}) + EOC extensions (eoc.joules.*,
                        eoc.co2e_grams, eoc.cost.usd). USD + gCO2e attribution
                        with PUE. LangSmith + LangFuse export adapters.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
2026-05-24 13:51:09 -04:00

89 lines
2.6 KiB
Rust

//! Follow → Accept round-trip via the inbox state.
use smart_byte_activitypub::{
Activity, ActivityObject, InboxEffect, InboxState, Object, Result,
};
#[test]
fn follow_then_accept_records_follower() -> Result<()> {
let mut state = InboxState::new();
// Alice sends a Follow to Bob. Bob's server receives it.
let follow = Activity::follow(
"https://a.test/activities/follow-1",
"https://a.test/users/alice",
"https://b.test/users/bob",
);
let effect = state.handle(&follow)?;
assert_eq!(
effect,
InboxEffect::FollowPending("https://a.test/activities/follow-1".into())
);
// Bob's server sends back an Accept referencing the Follow IRI.
let accept = Activity::accept(
"https://b.test/activities/accept-1",
"https://b.test/users/bob",
ActivityObject::iri("https://a.test/activities/follow-1"),
);
let effect = state.handle(&accept)?;
assert_eq!(
effect,
InboxEffect::FollowAccepted {
target: "https://b.test/users/bob".into(),
follower: "https://a.test/users/alice".into(),
}
);
// Bob now has Alice as a follower.
let followers = state
.followers
.get("https://b.test/users/bob")
.expect("bob has followers");
assert!(followers.contains("https://a.test/users/alice"));
Ok(())
}
#[test]
fn accept_with_embedded_follow_object() -> Result<()> {
let mut state = InboxState::new();
let mut embedded = Object::note(
"https://a.test/activities/follow-2",
"https://a.test/users/alice",
"",
);
embedded.type_field = "Follow".into();
let accept = Activity::accept(
"https://b.test/activities/accept-2",
"https://b.test/users/bob",
ActivityObject::embedded(embedded),
);
let effect = state.handle(&accept)?;
assert!(matches!(effect, InboxEffect::FollowAccepted { .. }));
Ok(())
}
#[test]
fn reject_clears_pending_follow() -> Result<()> {
let mut state = InboxState::new();
let follow = Activity::follow(
"https://a.test/activities/follow-x",
"https://a.test/users/alice",
"https://b.test/users/bob",
);
state.handle(&follow)?;
assert!(state
.pending_follows
.contains_key("https://a.test/activities/follow-x"));
let reject = Activity::reject(
"https://b.test/activities/reject-x",
"https://b.test/users/bob",
ActivityObject::iri("https://a.test/activities/follow-x"),
);
state.handle(&reject)?;
assert!(!state
.pending_follows
.contains_key("https://a.test/activities/follow-x"));
Ok(())
}