workdir: display working directory status

This commit is contained in:
2026-08-15 21:26:02 +09:00
parent f5a0e14991
commit eaaf2f6dcc
+36
View File
@@ -6,6 +6,7 @@
//! [`crate::http`]. //! [`crate::http`].
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt;
/// Stable Workspace identity for a Worker hosted by a Runtime. /// Stable Workspace identity for a Worker hosted by a Runtime.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
@@ -42,6 +43,24 @@ pub enum WorkingDirectoryStatusKind {
Unknown, Unknown,
} }
impl WorkingDirectoryStatusKind {
pub const fn as_str(&self) -> &'static str {
match self {
Self::Active => "active",
Self::CleanupPending => "cleanup_pending",
Self::Corrupted => "corrupted",
Self::NotFound => "not_found",
Self::Unknown => "unknown",
}
}
}
impl fmt::Display for WorkingDirectoryStatusKind {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct WorkingDirectoryCleanupTarget { pub struct WorkingDirectoryCleanupTarget {
@@ -200,6 +219,23 @@ pub struct WorkingDirectoryDetailResponse {
mod tests { mod tests {
use super::*; use super::*;
#[test]
fn working_directory_status_display_matches_wire_values() {
for (status, expected) in [
(WorkingDirectoryStatusKind::Active, "active"),
(
WorkingDirectoryStatusKind::CleanupPending,
"cleanup_pending",
),
(WorkingDirectoryStatusKind::Corrupted, "corrupted"),
(WorkingDirectoryStatusKind::NotFound, "not_found"),
(WorkingDirectoryStatusKind::Unknown, "unknown"),
] {
assert_eq!(status.to_string(), expected);
assert_eq!(serde_json::to_value(status).unwrap(), expected);
}
}
#[test] #[test]
fn occupied_and_free_list_response_round_trips() { fn occupied_and_free_list_response_round_trips() {
let response = WorkingDirectoryListResponse { let response = WorkingDirectoryListResponse {