diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab5243..1c74159 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + + - Fixed `cargo supply-chain update` failing after crates.io removed `gh_login` from its user CSV dump, while preserving compatibility with existing caches + ## v0.3.7 (2026-02-05) - Updated the caching code to handle the recent changes to crates.io dump format diff --git a/src/crates_cache.rs b/src/crates_cache.rs index d19ad5b..3f4573b 100644 --- a/src/crates_cache.rs +++ b/src/crates_cache.rs @@ -86,6 +86,8 @@ struct User { id: u64, gh_avatar: Option, gh_id: Option, + // Accept the dump's new field name while preserving the JSON cache format. + #[serde(alias = "username")] gh_login: String, name: Option, } @@ -395,6 +397,42 @@ fn read_csv_data( reader.deserialize().collect() } +#[cfg(test)] +mod tests { + use super::{read_csv_data, User}; + use serde_json::json; + + #[test] + fn current_user_csv_preserves_cache_format() { + let csv = "created_at,gh_id,id,name,username\n2026-10-01,123,42,Example,example\n"; + let users: Vec = read_csv_data(csv.as_bytes()).unwrap(); + assert_eq!(users.len(), 1); + assert_eq!( + serde_json::to_value(&users[0]).unwrap(), + json!({ + "id": 42, + "gh_avatar": null, + "gh_id": "123", + "gh_login": "example", + "name": "Example" + }) + ); + } + + #[test] + fn existing_user_cache_round_trips() { + let cached = json!({ + "id": 42, + "gh_avatar": "https://example.com/avatar.png", + "gh_id": "123", + "gh_login": "example", + "name": "Example" + }); + let user: User = serde_json::from_value(cached.clone()).unwrap(); + assert_eq!(serde_json::to_value(user).unwrap(), cached); + } +} + impl MetadataStored { fn validate(&self, max_age: Duration) -> Option { match self.age() {