fix(sync): 规范 release flow 状态码解析

This commit is contained in:
2026-07-31 17:45:50 +08:00
parent 6af7706190
commit 1e466d3374
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -147,7 +147,7 @@ impl ReleaseFlowStatusCode {
}
/// Parses a status code read from a persisted daemon/RPC snapshot.
pub fn from_str(code: &str) -> Option<Self> {
fn parse_wire_code(code: &str) -> Option<Self> {
Some(match code {
"official.unavailable" => Self::OfficialUnavailable,
"official.checking" => Self::OfficialChecking,
@@ -255,6 +255,14 @@ impl ReleaseFlowStatusCode {
}
}
impl std::str::FromStr for ReleaseFlowStatusCode {
type Err = ();
fn from_str(code: &str) -> Result<Self, Self::Err> {
Self::parse_wire_code(code).ok_or(())
}
}
#[cfg(test)]
mod tests {
use super::ReleaseFlowStatusCode;
@@ -292,4 +300,11 @@ mod tests {
assert_eq!(labels.len(), unique.len());
assert!(labels.iter().all(|label| label.contains('.')));
}
#[test]
fn status_codes_round_trip_through_from_str() {
let code = ReleaseFlowStatusCode::LocalizedPublished;
assert_eq!(code.as_str().parse::<ReleaseFlowStatusCode>(), Ok(code));
assert!("unknown.status".parse::<ReleaseFlowStatusCode>().is_err());
}
}