Spike 61: filesystem watcher and UI simplification

Add notify-based filesystem watcher for .story_kit/work/ that
auto-commits changes with deterministic messages and broadcasts
events over WebSocket. Push full pipeline state (Upcoming, Current,
QA, To Merge) to frontend on connect and after every watcher event.

Strip dead UI: remove ReviewPanel, GatePanel, TodoPanel,
UpcomingPanel and all associated REST polling. Replace with 4
generic StagePanel components driven by WebSocket. Simplify
AgentPanel to roster-only.

Delete all 11 workflow HTTP endpoints and 16 request/response types
from the server. Clean dead code from workflow module. MCP tools
call Rust functions directly and need none of the HTTP layer.

Net: ~4,100 lines deleted, ~400 added.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dave
2026-02-20 19:39:19 +00:00
parent 65b104edc5
commit 810608d3d8
29 changed files with 1041 additions and 4526 deletions

View File

@@ -1,14 +1,5 @@
//! Workflow module: story gating and test result tracking.
//!
//! This module provides the in-memory primitives for:
//! - reading story metadata (front matter) for gating decisions
//! - tracking test run results
//! - evaluating acceptance readiness
//!
//! NOTE: This is a naive, local-only implementation that will be
//! refactored later into orchestration-aware components.
//! Workflow module: test result tracking and acceptance evaluation.
use crate::io::story_metadata::{StoryMetadata, TestPlanStatus};
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -24,11 +15,9 @@ pub struct TestCaseResult {
pub details: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TestRunSummary {
pub total: usize,
pub passed: usize,
pub failed: usize,
struct TestRunSummary {
total: usize,
failed: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -45,44 +34,12 @@ pub struct StoryTestResults {
}
#[derive(Debug, Clone, Default)]
#[allow(dead_code)]
pub struct WorkflowState {
pub stories: HashMap<String, StoryMetadata>,
pub results: HashMap<String, StoryTestResults>,
pub coverage: HashMap<String, CoverageReport>,
}
#[allow(dead_code)]
impl WorkflowState {
pub fn upsert_story(&mut self, story_id: String, metadata: StoryMetadata) {
self.stories.insert(story_id, metadata);
}
pub fn load_story_metadata(&mut self, stories: Vec<(String, StoryMetadata)>) {
for (story_id, metadata) in stories {
self.stories.insert(story_id, metadata);
}
}
pub fn refresh_story_metadata(&mut self, story_id: String, metadata: StoryMetadata) -> bool {
match self.stories.get(&story_id) {
Some(existing) if existing == &metadata => false,
_ => {
self.stories.insert(story_id, metadata);
true
}
}
}
pub fn record_test_results(
&mut self,
story_id: String,
unit: Vec<TestCaseResult>,
integration: Vec<TestCaseResult>,
) {
let _ = self.record_test_results_validated(story_id, unit, integration);
}
pub fn record_test_results_validated(
&mut self,
story_id: String,
@@ -107,65 +64,23 @@ impl WorkflowState {
Ok(())
}
pub fn record_coverage(
&mut self,
story_id: String,
current_percent: f64,
threshold_percent: Option<f64>,
) {
let threshold = threshold_percent.unwrap_or(80.0);
let baseline = self
.coverage
.get(&story_id)
.map(|existing| existing.baseline_percent.unwrap_or(existing.current_percent));
self.coverage.insert(
story_id,
CoverageReport {
current_percent,
threshold_percent: threshold,
baseline_percent: baseline,
},
);
}
}
#[allow(dead_code)]
pub fn can_start_implementation(metadata: &StoryMetadata) -> Result<(), String> {
match metadata.test_plan {
Some(TestPlanStatus::Approved) => Ok(()),
Some(TestPlanStatus::WaitingForApproval) => {
Err("Test plan is waiting for approval; implementation is blocked.".to_string())
}
Some(TestPlanStatus::Unknown(ref value)) => Err(format!(
"Test plan state is unknown ({value}); implementation is blocked."
)),
None => Err("Missing test plan status; implementation is blocked.".to_string()),
}
}
pub fn summarize_results(results: &StoryTestResults) -> TestRunSummary {
fn summarize_results(results: &StoryTestResults) -> TestRunSummary {
let mut total = 0;
let mut passed = 0;
let mut failed = 0;
for test in results.unit.iter().chain(results.integration.iter()) {
total += 1;
match test.status {
TestStatus::Pass => passed += 1,
TestStatus::Fail => failed += 1,
if test.status == TestStatus::Fail {
failed += 1;
}
}
TestRunSummary {
total,
passed,
failed,
}
TestRunSummary { total, failed }
}
pub fn evaluate_acceptance(results: &StoryTestResults) -> AcceptanceDecision {
fn evaluate_acceptance(results: &StoryTestResults) -> AcceptanceDecision {
let summary = summarize_results(results);
if summary.failed == 0 && summary.total > 0 {
@@ -211,32 +126,6 @@ pub struct CoverageReport {
pub baseline_percent: Option<f64>,
}
/// Parse coverage percentage from a vitest coverage-summary.json string.
/// Expects JSON with `{"total": {"lines": {"pct": <number>}}}`.
pub fn parse_coverage_json(json_str: &str) -> Result<f64, String> {
let value: serde_json::Value =
serde_json::from_str(json_str).map_err(|e| format!("Invalid coverage JSON: {e}"))?;
value
.get("total")
.and_then(|t| t.get("lines"))
.and_then(|l| l.get("pct"))
.and_then(|p| p.as_f64())
.ok_or_else(|| "Missing total.lines.pct in coverage JSON.".to_string())
}
/// Check whether coverage meets the threshold.
#[allow(dead_code)]
pub fn check_coverage_threshold(current: f64, threshold: f64) -> Result<(), String> {
if current >= threshold {
Ok(())
} else {
Err(format!(
"Coverage below threshold ({current:.1}% < {threshold:.1}%)."
))
}
}
/// Evaluate acceptance with optional coverage data.
pub fn evaluate_acceptance_with_coverage(
results: &StoryTestResults,
@@ -269,43 +158,7 @@ pub fn evaluate_acceptance_with_coverage(
mod tests {
use super::*;
// === parse_coverage_json ===
#[test]
fn parses_valid_coverage_json() {
let json = r#"{"total":{"lines":{"total":100,"covered":85,"pct":85.0},"statements":{"pct":85.0}}}"#;
assert_eq!(parse_coverage_json(json).unwrap(), 85.0);
}
#[test]
fn rejects_invalid_coverage_json() {
assert!(parse_coverage_json("not json").is_err());
}
#[test]
fn rejects_missing_total_lines_pct() {
let json = r#"{"total":{"branches":{"pct":90.0}}}"#;
assert!(parse_coverage_json(json).is_err());
}
// === AC1: check_coverage_threshold ===
#[test]
fn coverage_threshold_passes_when_met() {
assert!(check_coverage_threshold(80.0, 80.0).is_ok());
assert!(check_coverage_threshold(95.5, 80.0).is_ok());
}
#[test]
fn coverage_threshold_fails_when_below() {
let result = check_coverage_threshold(72.3, 80.0);
assert!(result.is_err());
let err = result.unwrap_err();
assert!(err.contains("72.3%"));
assert!(err.contains("80.0%"));
}
// === AC2: evaluate_acceptance_with_coverage ===
// === evaluate_acceptance_with_coverage ===
#[test]
fn acceptance_blocked_by_coverage_below_threshold() {
@@ -403,49 +256,7 @@ mod tests {
assert!(decision.can_accept);
}
// === record_coverage ===
#[test]
fn record_coverage_first_time_has_no_baseline() {
let mut state = WorkflowState::default();
state.record_coverage("story-27".to_string(), 85.0, Some(80.0));
let report = state.coverage.get("story-27").unwrap();
assert_eq!(report.current_percent, 85.0);
assert_eq!(report.threshold_percent, 80.0);
assert_eq!(report.baseline_percent, None);
}
#[test]
fn record_coverage_subsequent_sets_baseline() {
let mut state = WorkflowState::default();
state.record_coverage("story-27".to_string(), 85.0, Some(80.0));
state.record_coverage("story-27".to_string(), 78.0, Some(80.0));
let report = state.coverage.get("story-27").unwrap();
assert_eq!(report.current_percent, 78.0);
assert_eq!(report.baseline_percent, Some(85.0));
}
#[test]
fn record_coverage_default_threshold() {
let mut state = WorkflowState::default();
state.record_coverage("story-27".to_string(), 90.0, None);
let report = state.coverage.get("story-27").unwrap();
assert_eq!(report.threshold_percent, 80.0);
}
#[test]
fn record_coverage_custom_threshold() {
let mut state = WorkflowState::default();
state.record_coverage("story-27".to_string(), 90.0, Some(95.0));
let report = state.coverage.get("story-27").unwrap();
assert_eq!(report.threshold_percent, 95.0);
}
// === Existing tests ===
// === evaluate_acceptance ===
#[test]
fn warns_when_multiple_tests_fail() {
@@ -478,32 +289,6 @@ mod tests {
);
}
#[test]
fn rejects_recording_multiple_failures() {
let mut state = WorkflowState::default();
let unit = vec![
TestCaseResult {
name: "unit-1".to_string(),
status: TestStatus::Fail,
details: None,
},
TestCaseResult {
name: "unit-2".to_string(),
status: TestStatus::Fail,
details: None,
},
];
let integration = vec![TestCaseResult {
name: "integration-1".to_string(),
status: TestStatus::Pass,
details: None,
}];
let result = state.record_test_results_validated("story-26".to_string(), unit, integration);
assert!(result.is_err());
}
#[test]
fn accepts_when_all_tests_pass() {
let results = StoryTestResults {
@@ -557,49 +342,32 @@ mod tests {
assert!(decision.warning.is_none());
}
#[test]
fn summarize_results_counts_correctly() {
let results = StoryTestResults {
unit: vec![
TestCaseResult { name: "u1".to_string(), status: TestStatus::Pass, details: None },
TestCaseResult { name: "u2".to_string(), status: TestStatus::Fail, details: None },
],
integration: vec![
TestCaseResult { name: "i1".to_string(), status: TestStatus::Pass, details: None },
],
};
let summary = summarize_results(&results);
assert_eq!(summary.total, 3);
assert_eq!(summary.passed, 2);
assert_eq!(summary.failed, 1);
}
// === record_test_results_validated ===
#[test]
fn can_start_implementation_requires_approved_plan() {
let approved = StoryMetadata {
name: Some("Test".to_string()),
test_plan: Some(TestPlanStatus::Approved),
};
assert!(can_start_implementation(&approved).is_ok());
fn rejects_recording_multiple_failures() {
let mut state = WorkflowState::default();
let unit = vec![
TestCaseResult {
name: "unit-1".to_string(),
status: TestStatus::Fail,
details: None,
},
TestCaseResult {
name: "unit-2".to_string(),
status: TestStatus::Fail,
details: None,
},
];
let integration = vec![TestCaseResult {
name: "integration-1".to_string(),
status: TestStatus::Pass,
details: None,
}];
let waiting = StoryMetadata {
name: Some("Test".to_string()),
test_plan: Some(TestPlanStatus::WaitingForApproval),
};
assert!(can_start_implementation(&waiting).is_err());
let result = state.record_test_results_validated("story-26".to_string(), unit, integration);
let unknown = StoryMetadata {
name: Some("Test".to_string()),
test_plan: Some(TestPlanStatus::Unknown("draft".to_string())),
};
assert!(can_start_implementation(&unknown).is_err());
let missing = StoryMetadata {
name: Some("Test".to_string()),
test_plan: None,
};
assert!(can_start_implementation(&missing).is_err());
assert!(result.is_err());
}
#[test]
@@ -626,22 +394,4 @@ mod tests {
assert_eq!(state.results["story-29"].unit.len(), 1);
assert_eq!(state.results["story-29"].integration.len(), 1);
}
#[test]
fn refresh_story_metadata_returns_false_when_unchanged() {
let mut state = WorkflowState::default();
let meta = StoryMetadata {
name: Some("Test".to_string()),
test_plan: Some(TestPlanStatus::Approved),
};
assert!(state.refresh_story_metadata("s1".to_string(), meta.clone()));
assert!(!state.refresh_story_metadata("s1".to_string(), meta.clone()));
let updated = StoryMetadata {
name: Some("Updated".to_string()),
test_plan: Some(TestPlanStatus::Approved),
};
assert!(state.refresh_story_metadata("s1".to_string(), updated));
}
}