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:
@@ -102,14 +102,14 @@ fn rebuild_index_maps_story_ids() {
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn subscribe_receives_stage_transition_events() {
|
||||
use super::super::types::CrdtEvent;
|
||||
use super::super::write::write_item;
|
||||
use super::super::write::write_item_str;
|
||||
|
||||
crate::crdt_state::init_for_test();
|
||||
|
||||
let mut rx = super::subscribe().expect("subscribe must return Some after init_for_test");
|
||||
|
||||
// Insert a new item — emit_event fires with from_stage=None.
|
||||
write_item(
|
||||
write_item_str(
|
||||
"906_story_subscribe",
|
||||
"1_backlog",
|
||||
Some("Subscribe Wiring"),
|
||||
@@ -125,10 +125,10 @@ async fn subscribe_receives_stage_transition_events() {
|
||||
let evt: CrdtEvent = rx.try_recv().expect("expected CrdtEvent on insert");
|
||||
assert_eq!(evt.story_id, "906_story_subscribe");
|
||||
assert!(evt.from_stage.is_none());
|
||||
assert_eq!(evt.to_stage, "1_backlog");
|
||||
assert_eq!(evt.to_stage, "backlog");
|
||||
|
||||
// Update stage — emit_event fires again with the real from_stage.
|
||||
write_item(
|
||||
write_item_str(
|
||||
"906_story_subscribe",
|
||||
"2_current",
|
||||
None,
|
||||
@@ -143,8 +143,8 @@ async fn subscribe_receives_stage_transition_events() {
|
||||
|
||||
let evt: CrdtEvent = rx.try_recv().expect("expected CrdtEvent on stage change");
|
||||
assert_eq!(evt.story_id, "906_story_subscribe");
|
||||
assert_eq!(evt.from_stage.as_deref(), Some("1_backlog"));
|
||||
assert_eq!(evt.to_stage, "2_current");
|
||||
assert_eq!(evt.from_stage.as_deref(), Some("backlog"));
|
||||
assert_eq!(evt.to_stage, "coding");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user