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
+1 -1
View File
@@ -2519,7 +2519,7 @@ fn build_resource_state_report(state_dir: &Path) -> anyhow::Result<serde_json::V
let flow_status_code = status_file let flow_status_code = status_file
.as_ref() .as_ref()
.and_then(|status| status.status_code.as_deref()) .and_then(|status| status.status_code.as_deref())
.and_then(ReleaseFlowStatusCode::from_str) .and_then(|code| code.parse::<ReleaseFlowStatusCode>().ok())
.or_else(|| { .or_else(|| {
if version_state if version_state
.as_ref() .as_ref()
+16 -1
View File
@@ -147,7 +147,7 @@ impl ReleaseFlowStatusCode {
} }
/// Parses a status code read from a persisted daemon/RPC snapshot. /// 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 { Some(match code {
"official.unavailable" => Self::OfficialUnavailable, "official.unavailable" => Self::OfficialUnavailable,
"official.checking" => Self::OfficialChecking, "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)] #[cfg(test)]
mod tests { mod tests {
use super::ReleaseFlowStatusCode; use super::ReleaseFlowStatusCode;
@@ -292,4 +300,11 @@ mod tests {
assert_eq!(labels.len(), unique.len()); assert_eq!(labels.len(), unique.len());
assert!(labels.iter().all(|label| label.contains('.'))); 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());
}
} }