feat(934): typed Stage enum replaces directory-string state model
The state machine's `Stage` enum becomes the source of truth for pipeline
state. Six stages of work land together:
1. Clean wire vocabulary (`coding`, `merge`, `merge_failure`, ...) replaces
legacy directory-style strings (`2_current`, `4_merge`, ...) on the wire.
`Stage::from_dir` accepted both during deployment; new writes always
emit the clean form via `stage_dir_name`. Lexicographic `dir >= "5_done"`
checks in lifecycle.rs become typed `matches!` checks since the new
vocabulary doesn't sort in pipeline order.
2. `crdt_state::write_item` takes typed `&Stage`, serialising via
`stage_dir_name` at the CRDT boundary. `#[cfg(test)] write_item_str`
parses legacy strings for test fixtures.
3. `WorkItem::stage()` returns typed `crdt_state::Stage`; `stage_str()`
is gone from the public API. Projection dispatches on the typed enum.
4. `frozen` becomes an orthogonal CRDT register. `Stage::Frozen` and
`PipelineEvent::Freeze`/`Unfreeze` are removed; `transition_to_frozen`/
`unfrozen` set the flag directly without touching the stage register.
5. Watcher sweep and `tool_update_story`'s `blocked` setter route through
`apply_transition` so the typed transition table validates every
stage change. `update_story` gains a `frozen` field for symmetry.
6. One-shot startup migration rewrites pre-934 directory-style stage
registers (and sets `frozen=true` on items previously at `7_frozen`).
`Stage::from_dir` drops legacy aliases. The db boundary keeps a small
normaliser so callers with legacy strings (MCP, tests) still work.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,32 +4,19 @@
|
||||
//! without performing any I/O. Parsing is delegated to `crate::io::story_metadata`.
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Return `true` if `stage` is a recognised pipeline stage directory name.
|
||||
/// Return `true` if `stage` is a recognised pipeline stage name.
|
||||
///
|
||||
/// Valid stage names match the `.huskies/work/N_name/` directory scheme.
|
||||
/// Accepts both the clean post-934 wire form (e.g. `"backlog"`) and the
|
||||
/// legacy directory-style form (e.g. `"1_backlog"`).
|
||||
pub fn is_valid_stage(stage: &str) -> bool {
|
||||
crate::pipeline_state::Stage::from_dir(stage).is_some()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Map a human-readable stage alias (e.g. `"backlog"`) to its directory name
|
||||
/// (e.g. `"1_backlog"`). Returns `None` for unrecognised aliases.
|
||||
/// Map any recognised stage alias (clean wire form or legacy directory form)
|
||||
/// to the canonical clean wire form. Returns `None` for unrecognised aliases.
|
||||
pub fn stage_alias_to_dir(alias: &str) -> Option<&'static str> {
|
||||
use crate::pipeline_state::Stage;
|
||||
// Canonical directory names (e.g. "1_backlog") round-trip through the typed enum.
|
||||
if let Some(stage) = Stage::from_dir(alias) {
|
||||
return Some(stage.dir_name());
|
||||
}
|
||||
// Short human-readable aliases (user-facing input normalization).
|
||||
match alias {
|
||||
"backlog" => Some("1_backlog"),
|
||||
"current" => Some("2_current"),
|
||||
"qa" => Some("3_qa"),
|
||||
"merge" => Some("4_merge"),
|
||||
"done" => Some("5_done"),
|
||||
"archived" => Some("6_archived"),
|
||||
_ => None,
|
||||
}
|
||||
crate::pipeline_state::Stage::from_dir(alias).map(|s| s.dir_name())
|
||||
}
|
||||
|
||||
// ── Tests ─────────────────────────────────────────────────────────────────────
|
||||
@@ -40,36 +27,42 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn is_valid_stage_accepts_all_known_stages() {
|
||||
assert!(is_valid_stage("1_backlog"));
|
||||
assert!(is_valid_stage("2_current"));
|
||||
assert!(is_valid_stage("3_qa"));
|
||||
assert!(is_valid_stage("4_merge"));
|
||||
assert!(is_valid_stage("5_done"));
|
||||
assert!(is_valid_stage("6_archived"));
|
||||
// Clean post-934 vocabulary.
|
||||
assert!(is_valid_stage("backlog"));
|
||||
assert!(is_valid_stage("coding"));
|
||||
assert!(is_valid_stage("qa"));
|
||||
assert!(is_valid_stage("merge"));
|
||||
assert!(is_valid_stage("done"));
|
||||
assert!(is_valid_stage("archived"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_valid_stage_rejects_unknown() {
|
||||
assert!(!is_valid_stage("current"));
|
||||
assert!(!is_valid_stage("backlog"));
|
||||
// Story 934 stage 6 dropped legacy directory-style aliases.
|
||||
assert!(!is_valid_stage("current")); // pre-934 short alias, no longer mapped
|
||||
assert!(!is_valid_stage("1_backlog"));
|
||||
assert!(!is_valid_stage("2_current"));
|
||||
assert!(!is_valid_stage("7_future"));
|
||||
assert!(!is_valid_stage(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stage_alias_maps_short_names() {
|
||||
assert_eq!(stage_alias_to_dir("backlog"), Some("1_backlog"));
|
||||
assert_eq!(stage_alias_to_dir("current"), Some("2_current"));
|
||||
assert_eq!(stage_alias_to_dir("qa"), Some("3_qa"));
|
||||
assert_eq!(stage_alias_to_dir("merge"), Some("4_merge"));
|
||||
assert_eq!(stage_alias_to_dir("done"), Some("5_done"));
|
||||
assert_eq!(stage_alias_to_dir("archived"), Some("6_archived"));
|
||||
assert_eq!(stage_alias_to_dir("backlog"), Some("backlog"));
|
||||
assert_eq!(stage_alias_to_dir("coding"), Some("coding"));
|
||||
assert_eq!(stage_alias_to_dir("qa"), Some("qa"));
|
||||
assert_eq!(stage_alias_to_dir("merge"), Some("merge"));
|
||||
assert_eq!(stage_alias_to_dir("done"), Some("done"));
|
||||
assert_eq!(stage_alias_to_dir("archived"), Some("archived"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stage_alias_maps_full_dir_names() {
|
||||
assert_eq!(stage_alias_to_dir("1_backlog"), Some("1_backlog"));
|
||||
assert_eq!(stage_alias_to_dir("6_archived"), Some("6_archived"));
|
||||
fn stage_alias_returns_none_for_legacy_dir_names() {
|
||||
// Story 934 stage 6: legacy directory-style aliases are no longer
|
||||
// recognised — startup migration rewrites stored CRDT values, and
|
||||
// user-facing aliases now use only the clean wire vocabulary.
|
||||
assert_eq!(stage_alias_to_dir("1_backlog"), None);
|
||||
assert_eq!(stage_alias_to_dir("6_archived"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user