MCPcopy Create free account
hub / github.com/acking-you/static_flow / validate_task_transition

Function validate_task_transition

crates/shared/src/task_status.rs:62–89  ·  view source on GitHub ↗

Validate a generic task status transition. The transition table is identical across wish / request / comment workflows (with one exception: wish and request allow `Failed -> Done`, comments do not). Use `allow_failed_to_done` to control that edge.

(
    current: TaskStatus,
    next: TaskStatus,
    allow_failed_to_done: bool,
)

Source from the content-addressed store, hash-verified

60/// workflows (with one exception: wish and request allow `Failed -> Done`,
61/// comments do not). Use `allow_failed_to_done` to control that edge.
62pub fn validate_task_transition(
63 current: TaskStatus,
64 next: TaskStatus,
65 allow_failed_to_done: bool,
66) -> anyhow::Result<()> {
67 if current == next {
68 anyhow::bail!("{current} -> {next}");
69 }
70
71 let ok = matches!(
72 (current, next),
73 (TaskStatus::Pending, TaskStatus::Approved | TaskStatus::Running | TaskStatus::Rejected)
74 | (TaskStatus::Approved, TaskStatus::Running | TaskStatus::Rejected)
75 | (TaskStatus::Running, TaskStatus::Done | TaskStatus::Failed)
76 | (
77 TaskStatus::Failed,
78 TaskStatus::Approved | TaskStatus::Running | TaskStatus::Rejected
79 )
80 ) || (allow_failed_to_done
81 && current == TaskStatus::Failed
82 && next == TaskStatus::Done);
83
84 if ok {
85 Ok(())
86 } else {
87 anyhow::bail!("{current} -> {next}")
88 }
89}
90
91#[cfg(test)]
92mod tests {

Callers 3

validate_transitionFunction · 0.85
validate_wish_transitionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected