1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//! MΓ‘quina de estados del workflow.
//!
//! Define los estados por los que pasa una historia, los actores
//! que pueden ejecutar transiciones, y las reglas de quΓ© transiciones
//! son vΓ‘lidas desde cada estado.
use serde::{Deserialize, Serialize};
/// Estados del workflow de una historia de usuario.
///
/// El flujo feliz es: Draft β Ready β TestsReady β InReview β BusinessReview β Done.
/// Los estados `Blocked` y `Failed` son estados laterales/terminales.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Status {
/// Historia creada pero no refinada. Pendiente de PO (groom).
Draft,
/// Historia refinada, cumple DoR. Pendiente de QA.
Ready,
/// Tests escritos por QA. Pendiente de Developer.
TestsReady,
/// Developer estΓ‘ corrigiendo tras un rechazo.
InProgress,
/// ImplementaciΓ³n lista. Pendiente de Reviewer.
InReview,
/// Reviewer aprobΓ³ DoD tΓ©cnico. Pendiente de PO (validate).
BusinessReview,
/// Historia completada y validada. Estado terminal exitoso.
Done,
/// Bloqueada por dependencias no resueltas.
Blocked,
/// SuperΓ³ el mΓ‘ximo de ciclos de rechazo. Estado terminal de fallo.
Failed,
}
/// Actores que pueden ejecutar transiciones.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub enum Actor {
/// Product Owner β refina (DraftβReady) y valida valor de negocio (BusinessReviewβDone).
ProductOwner,
/// QA Engineer β escribe tests (ReadyβTestsReady) y corrige tests (TestsReadyβTestsReady).
QaEngineer,
/// Developer β implementa (TestsReadyβInReview) y corrige tras rechazo (InProgressβInReview).
Developer,
/// Reviewer β puerta tΓ©cnica (InReviewβBusinessReview / InProgress).
Reviewer,
/// El propio orquestador β transiciones automΓ‘ticas (Blocked, Failed, desbloqueo).
Orchestrator,
}
/// Una transiciΓ³n entre dos estados, con el actor responsable.
///
/// Solo las transiciones definidas en las constantes de este mΓ³dulo
/// son vΓ‘lidas. Cualquier otra combinaciΓ³n es un error de estado.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub struct Transition {
pub from: Status,
pub to: Status,
pub actor: Actor,
}
impl Transition {
#[allow(dead_code)]
pub const fn new(from: Status, to: Status, actor: Actor) -> Self {
Self { from, to, actor }
}
}
// ββ Transiciones canΓ³nicas ββββββββββββββββββββββββββββββββββββββββββββββ
impl Status {
/// Todas las transiciones permitidas.
#[allow(dead_code)]
pub const ALL: &[Transition] = &[
// ββ PO ββββββββββββββββββββββββββββββββββββββββββββββββββ
Transition::new(Status::Draft, Status::Ready, Actor::ProductOwner),
Transition::new(Status::BusinessReview, Status::Done, Actor::ProductOwner),
Transition::new(
Status::BusinessReview,
Status::InReview,
Actor::ProductOwner,
),
Transition::new(
Status::BusinessReview,
Status::InProgress,
Actor::ProductOwner,
),
// ββ QA ββββββββββββββββββββββββββββββββββββββββββββββββββ
Transition::new(Status::Ready, Status::TestsReady, Actor::QaEngineer),
Transition::new(Status::Ready, Status::Draft, Actor::QaEngineer),
Transition::new(Status::TestsReady, Status::TestsReady, Actor::QaEngineer),
// ββ Developer βββββββββββββββββββββββββββββββββββββββββββ
Transition::new(Status::TestsReady, Status::InReview, Actor::Developer),
Transition::new(Status::InProgress, Status::InReview, Actor::Developer),
// ββ Reviewer ββββββββββββββββββββββββββββββββββββββββββββ
Transition::new(Status::InReview, Status::BusinessReview, Actor::Reviewer),
Transition::new(Status::InReview, Status::InProgress, Actor::Reviewer),
// ββ Orchestrator (automΓ‘tico) βββββββββββββββββββββββββββ
Transition::new(Status::Blocked, Status::Ready, Actor::Orchestrator),
];
/// Transiciones permitidas DESDE este estado.
#[allow(dead_code)]
pub fn allowed_from(&self) -> Vec<&'static Transition> {
Self::ALL.iter().filter(|t| t.from == *self).collect()
}
/// ΒΏEs vΓ‘lida la transiciΓ³n de `self` a `target` ejecutada por `actor`?
#[allow(dead_code)]
pub fn can_transition_to(&self, target: Status, actor: Actor) -> bool {
Self::ALL
.iter()
.any(|t| t.from == *self && t.to == target && t.actor == actor)
}
/// ΒΏEs un estado terminal? (el pipeline no volverΓ‘ a tocar esta historia).
pub fn is_terminal(&self) -> bool {
matches!(self, Status::Done | Status::Failed)
}
/// ΒΏEs un estado desde el que el loop normal puede disparar un agente?
/// (excluye Draft, Blocked, y terminales)
pub fn is_actionable(&self) -> bool {
matches!(
self,
Status::Ready
| Status::TestsReady
| Status::InProgress
| Status::InReview
| Status::BusinessReview
)
}
/// ΒΏEs un estado "stuck" que requiere intervenciΓ³n del PO?
/// (Draft siempre, Blocked depende del contexto de dependencias)
#[allow(dead_code)]
pub fn is_stuck(&self) -> bool {
matches!(self, Status::Draft)
}
}
impl std::fmt::Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Status::Draft => "Draft",
Status::Ready => "Ready",
Status::TestsReady => "Tests Ready",
Status::InProgress => "In Progress",
Status::InReview => "In Review",
Status::BusinessReview => "Business Review",
Status::Done => "Done",
Status::Blocked => "Blocked",
Status::Failed => "Failed",
};
write!(f, "{s}")
}
}
impl std::fmt::Display for Actor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Actor::ProductOwner => "PO",
Actor::QaEngineer => "QA",
Actor::Developer => "Dev",
Actor::Reviewer => "Reviewer",
Actor::Orchestrator => "Orchestrator",
};
write!(f, "{s}")
}
}
#[cfg(test)]
mod tests {
use super::*;
// ββ Transiciones felices ββββββββββββββββββββββββββββββββββββββββ
#[test]
fn draft_to_ready_by_po() {
assert!(Status::Draft.can_transition_to(Status::Ready, Actor::ProductOwner));
}
#[test]
fn ready_to_testsready_by_qa() {
assert!(Status::Ready.can_transition_to(Status::TestsReady, Actor::QaEngineer));
}
#[test]
fn testsready_to_inreview_by_dev() {
assert!(Status::TestsReady.can_transition_to(Status::InReview, Actor::Developer));
}
#[test]
fn inreview_to_businessreview_by_reviewer() {
assert!(Status::InReview.can_transition_to(Status::BusinessReview, Actor::Reviewer));
}
#[test]
fn businessreview_to_done_by_po() {
assert!(Status::BusinessReview.can_transition_to(Status::Done, Actor::ProductOwner));
}
// ββ Rechazos ββββββββββββββββββββββββββββββββββββββββββββββββββββ
#[test]
fn inreview_to_inprogress_by_reviewer() {
assert!(Status::InReview.can_transition_to(Status::InProgress, Actor::Reviewer));
}
#[test]
fn businessreview_to_inreview_by_po() {
assert!(Status::BusinessReview.can_transition_to(Status::InReview, Actor::ProductOwner));
}
#[test]
fn businessreview_to_inprogress_by_po() {
assert!(Status::BusinessReview.can_transition_to(Status::InProgress, Actor::ProductOwner));
}
#[test]
fn inprogress_to_inreview_by_dev() {
assert!(Status::InProgress.can_transition_to(Status::InReview, Actor::Developer));
}
// ββ Rollbacks βββββββββββββββββββββββββββββββββββββββββββββββββββ
#[test]
fn ready_to_draft_by_qa() {
assert!(Status::Ready.can_transition_to(Status::Draft, Actor::QaEngineer));
}
#[test]
fn testsready_to_testsready_by_qa() {
assert!(Status::TestsReady.can_transition_to(Status::TestsReady, Actor::QaEngineer));
}
// ββ AutomΓ‘ticas (Orchestrator) ββββββββββββββββββββββββββββββββββ
#[test]
fn blocked_to_ready_by_orchestrator() {
assert!(Status::Blocked.can_transition_to(Status::Ready, Actor::Orchestrator));
}
// ββ Transiciones PROHIBIDAS ββββββββββββββββββββββββββββββββββββββββββ
#[test]
fn draft_cannot_go_directly_to_done() {
assert!(!Status::Draft.can_transition_to(Status::Done, Actor::ProductOwner));
}
#[test]
fn ready_cannot_be_done_by_dev() {
assert!(!Status::Ready.can_transition_to(Status::Done, Actor::Developer));
}
#[test]
fn inreview_cannot_be_done_by_reviewer() {
assert!(!Status::InReview.can_transition_to(Status::Done, Actor::Reviewer));
}
#[test]
fn done_cannot_transition_to_anything() {
for target in [
Status::Ready,
Status::InReview,
Status::BusinessReview,
Status::Draft,
] {
for actor in [
Actor::ProductOwner,
Actor::QaEngineer,
Actor::Developer,
Actor::Reviewer,
] {
assert!(
!Status::Done.can_transition_to(target, actor),
"Done should not transition to {target} by {actor}"
);
}
}
}
#[test]
fn failed_cannot_transition_to_anything() {
for target in [Status::Ready, Status::InReview, Status::Draft] {
for actor in [Actor::ProductOwner, Actor::QaEngineer, Actor::Developer] {
assert!(
!Status::Failed.can_transition_to(target, actor),
"Failed should not transition to {target} by {actor}"
);
}
}
}
#[test]
fn qa_cannot_mark_done() {
assert!(!Status::TestsReady.can_transition_to(Status::Done, Actor::QaEngineer));
}
#[test]
fn dev_cannot_mark_done() {
assert!(!Status::InReview.can_transition_to(Status::Done, Actor::Developer));
}
// ββ Propiedades ββββββββββββββββββββββββββββββββββββββββββββββββββββ
#[test]
fn terminal_states() {
assert!(Status::Done.is_terminal());
assert!(Status::Failed.is_terminal());
assert!(!Status::Draft.is_terminal());
assert!(!Status::Ready.is_terminal());
assert!(!Status::InReview.is_terminal());
}
#[test]
fn actionable_states() {
assert!(Status::Ready.is_actionable());
assert!(Status::TestsReady.is_actionable());
assert!(Status::InProgress.is_actionable());
assert!(Status::InReview.is_actionable());
assert!(Status::BusinessReview.is_actionable());
assert!(!Status::Draft.is_actionable());
assert!(!Status::Done.is_actionable());
assert!(!Status::Failed.is_actionable());
assert!(!Status::Blocked.is_actionable());
}
#[test]
fn allowed_from_returns_valid_transitions() {
let ready_transitions = Status::Ready.allowed_from();
assert_eq!(ready_transitions.len(), 2); // β TestsReady (QA), β Draft (QA)
let targets: Vec<Status> = ready_transitions.iter().map(|t| t.to).collect();
assert!(targets.contains(&Status::TestsReady));
assert!(targets.contains(&Status::Draft));
}
#[test]
fn display_formats_correctly() {
assert_eq!(Status::TestsReady.to_string(), "Tests Ready");
assert_eq!(Status::InProgress.to_string(), "In Progress");
assert_eq!(Status::InReview.to_string(), "In Review");
assert_eq!(Status::BusinessReview.to_string(), "Business Review");
assert_eq!(Actor::ProductOwner.to_string(), "PO");
assert_eq!(Actor::Orchestrator.to_string(), "Orchestrator");
}
}