Skip to content

Commit f1e53e4

Browse files
committed
Run cargo fmt for CI compliance
1 parent 859638e commit f1e53e4

15 files changed

Lines changed: 215 additions & 118 deletions

examples/rust_quickstart.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//!
1212
//! Requires a running LDP delegate at localhost:8090 (see examples/python_sdk/ldp_delegate.py)
1313
14-
use ldp_protocol::{register_ldp, LdpAdapterConfig, SessionConfig, PayloadMode};
1514
use ldp_protocol::protocol::ProtocolRegistry;
15+
use ldp_protocol::{register_ldp, LdpAdapterConfig, PayloadMode, SessionConfig};
1616

1717
#[tokio::main]
1818
async fn main() {
@@ -33,7 +33,10 @@ async fn main() {
3333
};
3434

3535
println!("Config: delegate_id={}", config.delegate_id);
36-
println!(" payload modes: {:?}", config.session.preferred_payload_modes);
36+
println!(
37+
" payload modes: {:?}",
38+
config.session.preferred_payload_modes
39+
);
3740
println!(" trust enforcement: {}", config.enforce_trust_domains);
3841
println!(" attach provenance: {}", config.attach_provenance);
3942

@@ -43,7 +46,10 @@ async fn main() {
4346

4447
// Now ldp:// URLs are handled by the LDP adapter
4548
println!("\nRegistered protocols: {:?}", registry.protocols());
46-
println!(" ldp:// adapter: {}", registry.adapter_for_url("ldp://localhost:8090").is_some());
49+
println!(
50+
" ldp:// adapter: {}",
51+
registry.adapter_for_url("ldp://localhost:8090").is_some()
52+
);
4753

4854
// 3. In production, use the registry to discover and invoke:
4955
//

src/adapter.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ use tokio::sync::RwLock;
2727
use tracing::{debug, info, instrument};
2828

2929
/// Validate a task result against its contract. Returns violation codes.
30-
fn validate_contract(
31-
contract: &DelegationContract,
32-
provenance: &Provenance,
33-
) -> Vec<String> {
30+
fn validate_contract(contract: &DelegationContract, provenance: &Provenance) -> Vec<String> {
3431
let mut violations = Vec::new();
3532

3633
// Deadline check (client's local UTC time is authoritative)
@@ -407,8 +404,14 @@ impl ProtocolAdapter for LdpAdapter {
407404
Ok(TaskStatus::Working)
408405
}
409406
}
410-
LdpMessageBody::TaskResult { output, mut provenance, .. } => {
411-
provenance.lineage.insert(0, build_lineage_entry(&provenance, "task"));
407+
LdpMessageBody::TaskResult {
408+
output,
409+
mut provenance,
410+
..
411+
} => {
412+
provenance
413+
.lineage
414+
.insert(0, build_lineage_entry(&provenance, "task"));
412415
provenance.normalize();
413416
let contracts = self.contracts.read().await;
414417
if let Some(contract) = contracts.get(task_id) {

src/client.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ impl LdpClient {
7070
///
7171
/// Identity cards are served at `{url}/ldp/identity`.
7272
#[instrument(skip(self), fields(url = %url))]
73-
pub async fn fetch_identity_card(
74-
&self,
75-
url: &str,
76-
) -> Result<LdpIdentityCard, String> {
73+
pub async fn fetch_identity_card(&self, url: &str) -> Result<LdpIdentityCard, String> {
7774
let endpoint = format!("{}/ldp/identity", url.trim_end_matches('/'));
7875

7976
debug!(endpoint = %endpoint, "Fetching LDP identity card");
@@ -105,9 +102,10 @@ impl LdpClient {
105102
let wellknown = format!("{}/.well-known/ldp-identity", url.trim_end_matches('/'));
106103

107104
match self.http.get(&wellknown).send().await {
108-
Ok(resp) if resp.status().is_success() => {
109-
resp.json().await.map_err(|e| format!("Failed to parse identity: {e}"))
110-
}
105+
Ok(resp) if resp.status().is_success() => resp
106+
.json()
107+
.await
108+
.map_err(|e| format!("Failed to parse identity: {e}")),
111109
_ => self.fetch_identity_card(url).await,
112110
}
113111
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub mod client;
3838
pub mod config;
3939
pub mod plugin;
4040
pub mod protocol;
41+
pub mod replay;
4142
pub mod server;
4243
pub mod session_manager;
4344
pub mod signing;
44-
pub mod replay;
4545
pub mod types;
4646

4747
pub use adapter::LdpAdapter;

src/plugin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ mod tests {
8383
let mut registry = ProtocolRegistry::new();
8484
register_ldp(&mut registry, None);
8585

86-
assert!(registry.adapter_for_url("ldp://delegate.example.com").is_some());
86+
assert!(registry
87+
.adapter_for_url("ldp://delegate.example.com")
88+
.is_some());
8789
assert!(registry.adapter_for_url("https://not-ldp.com").is_none());
8890
}
8991

src/replay.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,24 @@ impl ReplayGuard {
2121
}
2222

2323
/// Check if a message should be accepted. Returns Err with reason if rejected.
24-
pub fn check(&mut self, message_id: &str, nonce: Option<&str>, timestamp: &str) -> Result<(), String> {
24+
pub fn check(
25+
&mut self,
26+
message_id: &str,
27+
nonce: Option<&str>,
28+
timestamp: &str,
29+
) -> Result<(), String> {
2530
// 1. Timestamp freshness check
2631
if let Ok(msg_time) = chrono::DateTime::parse_from_rfc3339(timestamp) {
2732
let now = chrono::Utc::now();
28-
let diff = (now - msg_time.with_timezone(&chrono::Utc)).num_seconds().unsigned_abs();
33+
let diff = (now - msg_time.with_timezone(&chrono::Utc))
34+
.num_seconds()
35+
.unsigned_abs();
2936
if diff > self.window.as_secs() {
30-
return Err(format!("Message timestamp too old: {}s > {}s window", diff, self.window.as_secs()));
37+
return Err(format!(
38+
"Message timestamp too old: {}s > {}s window",
39+
diff,
40+
self.window.as_secs()
41+
));
3142
}
3243
}
3344

src/server.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ impl LdpServer {
110110
metadata: HashMap::new(),
111111
};
112112

113-
let handler: TaskHandler = Arc::new(|_skill, input| {
114-
json!({ "echo": input })
115-
});
113+
let handler: TaskHandler = Arc::new(|_skill, input| json!({ "echo": input }));
116114

117115
Self::new(identity, handler)
118116
}
@@ -152,24 +150,32 @@ impl LdpServer {
152150
}
153151

154152
let mut response = match &envelope.body {
155-
LdpMessageBody::Hello { delegate_id, supported_modes } => {
156-
self.handle_hello(&envelope, delegate_id, supported_modes).await
153+
LdpMessageBody::Hello {
154+
delegate_id,
155+
supported_modes,
156+
} => {
157+
self.handle_hello(&envelope, delegate_id, supported_modes)
158+
.await
157159
}
158160
LdpMessageBody::SessionPropose { config } => {
159161
self.handle_session_propose(&envelope, config).await
160162
}
161-
LdpMessageBody::TaskSubmit { task_id, skill, input, .. } => {
162-
self.handle_task_submit(&envelope, task_id, skill, input).await
163+
LdpMessageBody::TaskSubmit {
164+
task_id,
165+
skill,
166+
input,
167+
..
168+
} => {
169+
self.handle_task_submit(&envelope, task_id, skill, input)
170+
.await
163171
}
164172
LdpMessageBody::TaskUpdate { task_id, .. } => {
165173
self.handle_task_status_query(&envelope, task_id).await
166174
}
167175
LdpMessageBody::TaskCancel { task_id } => {
168176
self.handle_task_cancel(&envelope, task_id).await
169177
}
170-
LdpMessageBody::SessionClose { .. } => {
171-
self.handle_session_close(&envelope).await
172-
}
178+
LdpMessageBody::SessionClose { .. } => self.handle_session_close(&envelope).await,
173179
_ => Err(format!("Unhandled message type")),
174180
}?;
175181

@@ -315,10 +321,8 @@ impl LdpServer {
315321
}
316322

317323
// Build provenance.
318-
let mut provenance = Provenance::new(
319-
&self.identity.delegate_id,
320-
&self.identity.model_version,
321-
);
324+
let mut provenance =
325+
Provenance::new(&self.identity.delegate_id, &self.identity.model_version);
322326
provenance.verification_status = VerificationStatus::SelfVerified;
323327
#[allow(deprecated)]
324328
{
@@ -358,10 +362,8 @@ impl LdpServer {
358362
if let Some(record) = tasks.get(task_id) {
359363
let body = match record.state {
360364
TaskRecordState::Completed => {
361-
let mut provenance = Provenance::new(
362-
&self.identity.delegate_id,
363-
&self.identity.model_version,
364-
);
365+
let mut provenance =
366+
Provenance::new(&self.identity.delegate_id, &self.identity.model_version);
365367
provenance.verification_status = VerificationStatus::SelfVerified;
366368
#[allow(deprecated)]
367369
{
@@ -372,12 +374,15 @@ impl LdpServer {
372374
output: record.output.clone().unwrap_or(json!(null)),
373375
provenance,
374376
}
375-
},
377+
}
376378
TaskRecordState::Failed => LdpMessageBody::TaskFailed {
377379
task_id: task_id.to_string(),
378380
error: LdpError::runtime(
379381
"TASK_FAILED",
380-
record.error.clone().unwrap_or_else(|| "unknown error".into()),
382+
record
383+
.error
384+
.clone()
385+
.unwrap_or_else(|| "unknown error".into()),
381386
),
382387
},
383388
_ => LdpMessageBody::TaskUpdate {
@@ -423,10 +428,7 @@ impl LdpServer {
423428
}
424429

425430
/// Handle SESSION_CLOSE.
426-
async fn handle_session_close(
427-
&self,
428-
envelope: &LdpEnvelope,
429-
) -> Result<LdpEnvelope, String> {
431+
async fn handle_session_close(&self, envelope: &LdpEnvelope) -> Result<LdpEnvelope, String> {
430432
info!(session_id = %envelope.session_id, "Session closed");
431433

432434
let mut sessions = self.sessions.write().await;

src/session_manager.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ impl SessionManager {
119119
let remote_delegate_id = hello_response.from.clone();
120120

121121
// Step 3: Negotiate payload mode
122-
let negotiated = negotiate_payload_mode(
123-
&session_config.preferred_payload_modes,
124-
&remote_modes,
125-
);
122+
let negotiated =
123+
negotiate_payload_mode(&session_config.preferred_payload_modes, &remote_modes);
126124

127125
debug!(
128126
mode = %negotiated.mode,

src/signing.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ pub fn sign_envelope(envelope: &LdpEnvelope, secret: &str) -> String {
5050
mac.update(reason.as_bytes());
5151
"SESSION_REJECT"
5252
}
53-
LdpMessageBody::TaskSubmit {
54-
task_id, skill, ..
55-
} => {
53+
LdpMessageBody::TaskSubmit { task_id, skill, .. } => {
5654
mac.update(task_id.as_bytes());
5755
mac.update(b"|");
5856
mac.update(skill.as_bytes());
@@ -148,10 +146,7 @@ mod tests {
148146
let mut envelope = make_envelope();
149147
apply_signature(&mut envelope, "test-secret");
150148
assert!(envelope.signature.is_some());
151-
assert_eq!(
152-
envelope.signature_algorithm.as_deref(),
153-
Some("hmac-sha256")
154-
);
149+
assert_eq!(envelope.signature_algorithm.as_deref(), Some("hmac-sha256"));
155150
}
156151

157152
#[test]

src/types/contract.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,30 @@ mod tests {
9393

9494
#[test]
9595
fn contract_creation() {
96-
let contract = DelegationContract::new("Summarize the document", vec!["<=300 words".into()]);
96+
let contract =
97+
DelegationContract::new("Summarize the document", vec!["<=300 words".into()]);
9798
assert!(!contract.contract_id.is_empty());
9899
assert_eq!(contract.objective, "Summarize the document");
99100
assert!(contract.deadline.is_none());
100101
}
101102

102103
#[test]
103104
fn contract_with_deadline() {
104-
let contract = DelegationContract::new("task", vec![]).with_deadline("2026-12-31T23:59:59Z");
105+
let contract =
106+
DelegationContract::new("task", vec![]).with_deadline("2026-12-31T23:59:59Z");
105107
assert_eq!(contract.deadline.as_deref(), Some("2026-12-31T23:59:59Z"));
106108
}
107109

108110
#[test]
109111
fn contract_with_budget() {
110-
let contract = DelegationContract::new("task", vec![])
111-
.with_budget(BudgetPolicy { max_tokens: Some(5000), max_cost_usd: Some(0.05) });
112-
assert_eq!(contract.policy.budget.as_ref().unwrap().max_tokens, Some(5000));
112+
let contract = DelegationContract::new("task", vec![]).with_budget(BudgetPolicy {
113+
max_tokens: Some(5000),
114+
max_cost_usd: Some(0.05),
115+
});
116+
assert_eq!(
117+
contract.policy.budget.as_ref().unwrap().max_tokens,
118+
Some(5000)
119+
);
113120
}
114121

115122
#[test]
@@ -122,7 +129,10 @@ mod tests {
122129
fn serialization_roundtrip() {
123130
let contract = DelegationContract::new("Analyze data", vec!["accuracy > 0.9".into()])
124131
.with_deadline("2026-06-01T00:00:00Z")
125-
.with_budget(BudgetPolicy { max_tokens: Some(10000), max_cost_usd: None })
132+
.with_budget(BudgetPolicy {
133+
max_tokens: Some(10000),
134+
max_cost_usd: None,
135+
})
126136
.with_failure_policy(FailurePolicy::FailClosed);
127137
let json = serde_json::to_value(&contract).unwrap();
128138
let restored: DelegationContract = serde_json::from_value(json).unwrap();

0 commit comments

Comments
 (0)