Story 26: Establish TDD workflow and quality gates

Add workflow engine with acceptance gates, test recording, and review
queue. Frontend displays gate status (blocked/ready), test summaries,
failing badges, and warnings. Proceed action is disabled when gates
are not met. Includes 13 unit tests (Vitest) and 9 E2E tests
(Playwright) covering all five acceptance criteria.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dave
2026-02-19 12:54:04 +00:00
parent 3a98669c4c
commit 013b28d77f
31 changed files with 3627 additions and 417 deletions

View File

@@ -3,7 +3,12 @@ import Markdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
import { api, ChatWebSocket } from "../api/client";
import type { ReviewStory } from "../api/workflow";
import { workflowApi } from "../api/workflow";
import type { Message, ProviderConfig, ToolCall } from "../types";
import { ChatHeader } from "./ChatHeader";
import { GatePanel } from "./GatePanel";
import { ReviewPanel } from "./ReviewPanel";
const { useCallback, useEffect, useRef, useState } = React;
@@ -12,6 +17,18 @@ interface ChatProps {
onCloseProject: () => void;
}
interface GateState {
canAccept: boolean;
reasons: string[];
warning: string | null;
summary: {
total: number;
passed: number;
failed: number;
};
missingCategories: string[];
}
export function Chat({ projectPath, onCloseProject }: ChatProps) {
const [messages, setMessages] = useState<Message[]>([]);
const [input, setInput] = useState("");
@@ -24,6 +41,31 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
const [showApiKeyDialog, setShowApiKeyDialog] = useState(false);
const [apiKeyInput, setApiKeyInput] = useState("");
const [hasAnthropicKey, setHasAnthropicKey] = useState(false);
const [gateState, setGateState] = useState<GateState | null>(null);
const [gateError, setGateError] = useState<string | null>(null);
const [isGateLoading, setIsGateLoading] = useState(false);
const [reviewQueue, setReviewQueue] = useState<ReviewStory[]>([]);
const [reviewError, setReviewError] = useState<string | null>(null);
const [isReviewLoading, setIsReviewLoading] = useState(false);
const [proceedingStoryId, setProceedingStoryId] = useState<string | null>(
null,
);
const [proceedError, setProceedError] = useState<string | null>(null);
const [proceedSuccess, setProceedSuccess] = useState<string | null>(null);
const [lastReviewRefresh, setLastReviewRefresh] = useState<Date | null>(null);
const [lastGateRefresh, setLastGateRefresh] = useState<Date | null>(null);
const storyId = "26_establish_tdd_workflow_and_gates";
const gateStatusColor = isGateLoading
? "#aaa"
: gateState?.canAccept
? "#7ee787"
: "#ff7b72";
const gateStatusLabel = isGateLoading
? "Checking..."
: gateState?.canAccept
? "Ready to accept"
: "Blocked";
const wsRef = useRef<ChatWebSocket | null>(null);
const messagesEndRef = useRef<HTMLDivElement>(null);
@@ -76,12 +118,6 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
const contextUsage = calculateContextUsage();
const getContextEmoji = (percentage: number): string => {
if (percentage >= 90) return "🔴";
if (percentage >= 75) return "🟡";
return "🟢";
};
useEffect(() => {
api
.getOllamaModels()
@@ -134,6 +170,146 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
});
}, []);
useEffect(() => {
let active = true;
setIsGateLoading(true);
setGateError(null);
workflowApi
.getAcceptance({ story_id: storyId })
.then((response) => {
if (!active) return;
setGateState({
canAccept: response.can_accept,
reasons: response.reasons,
warning: response.warning ?? null,
summary: response.summary,
missingCategories: response.missing_categories,
});
setLastGateRefresh(new Date());
})
.catch((error) => {
if (!active) return;
const message =
error instanceof Error
? error.message
: "Failed to load workflow gates.";
setGateError(message);
setGateState(null);
})
.finally(() => {
if (active) {
setIsGateLoading(false);
}
});
return () => {
active = false;
};
}, [storyId]);
useEffect(() => {
let active = true;
setIsReviewLoading(true);
setReviewError(null);
workflowApi
.getReviewQueueAll()
.then((response) => {
if (!active) return;
setReviewQueue(response.stories);
setLastReviewRefresh(new Date());
})
.catch((error) => {
if (!active) return;
const message =
error instanceof Error
? error.message
: "Failed to load review queue.";
setReviewError(message);
setReviewQueue([]);
})
.finally(() => {
if (active) {
setIsReviewLoading(false);
}
});
return () => {
active = false;
};
}, []);
const refreshGateState = async (targetStoryId: string = storyId) => {
setIsGateLoading(true);
setGateError(null);
try {
const response = await workflowApi.getAcceptance({
story_id: targetStoryId,
});
setGateState({
canAccept: response.can_accept,
reasons: response.reasons,
warning: response.warning ?? null,
summary: response.summary,
missingCategories: response.missing_categories,
});
setLastGateRefresh(new Date());
} catch (error) {
const message =
error instanceof Error
? error.message
: "Failed to load workflow gates.";
setGateError(message);
setGateState(null);
} finally {
setIsGateLoading(false);
}
};
const refreshReviewQueue = async () => {
setIsReviewLoading(true);
setReviewError(null);
try {
const response = await workflowApi.getReviewQueueAll();
setReviewQueue(response.stories);
setLastReviewRefresh(new Date());
} catch (error) {
const message =
error instanceof Error ? error.message : "Failed to load review queue.";
setReviewError(message);
setReviewQueue([]);
} finally {
setIsReviewLoading(false);
}
};
const handleProceed = async (storyIdToProceed: string) => {
setProceedingStoryId(storyIdToProceed);
setProceedError(null);
setProceedSuccess(null);
try {
await workflowApi.ensureAcceptance({
story_id: storyIdToProceed,
});
setProceedSuccess(`Proceeding with ${storyIdToProceed}.`);
await refreshReviewQueue();
if (storyIdToProceed === storyId) {
await refreshGateState(storyId);
}
} catch (error) {
const message =
error instanceof Error
? error.message
: "Failed to proceed with review.";
setProceedError(message);
} finally {
setProceedingStoryId(null);
}
};
useEffect(() => {
const ws = new ChatWebSocket();
wsRef.current = ws;
@@ -321,209 +497,61 @@ export function Chat({ projectPath, onCloseProject }: ChatProps) {
color: "#ececec",
}}
>
<ChatHeader
projectPath={projectPath}
onCloseProject={onCloseProject}
contextUsage={contextUsage}
onClearSession={clearSession}
model={model}
availableModels={availableModels}
claudeModels={claudeModels}
hasAnthropicKey={hasAnthropicKey}
onModelChange={(newModel) => {
setModel(newModel);
api.setModelPreference(newModel).catch(console.error);
}}
enableTools={enableTools}
onToggleTools={setEnableTools}
/>
<div
style={{
padding: "12px 24px",
borderBottom: "1px solid #333",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
background: "#171717",
flexShrink: 0,
fontSize: "0.9rem",
color: "#ececec",
maxWidth: "768px",
margin: "0 auto",
width: "100%",
padding: "12px 24px 0",
}}
>
<div
style={{
display: "flex",
alignItems: "center",
flexDirection: "column",
gap: "12px",
overflow: "hidden",
flex: 1,
marginRight: "20px",
}}
>
<div
title={projectPath}
style={{
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
fontWeight: "500",
color: "#aaa",
direction: "rtl",
textAlign: "left",
fontFamily: "monospace",
fontSize: "0.85em",
}}
>
{projectPath}
</div>
<button
type="button"
onClick={onCloseProject}
style={{
background: "transparent",
border: "none",
cursor: "pointer",
color: "#999",
fontSize: "0.8em",
padding: "4px 8px",
borderRadius: "4px",
}}
onMouseOver={(e) => {
e.currentTarget.style.background = "#333";
}}
onMouseOut={(e) => {
e.currentTarget.style.background = "transparent";
}}
onFocus={(e) => {
e.currentTarget.style.background = "#333";
}}
onBlur={(e) => {
e.currentTarget.style.background = "transparent";
}}
>
</button>
</div>
<ReviewPanel
reviewQueue={reviewQueue}
isReviewLoading={isReviewLoading}
reviewError={reviewError}
proceedingStoryId={proceedingStoryId}
storyId={storyId}
isGateLoading={isGateLoading}
proceedError={proceedError}
proceedSuccess={proceedSuccess}
lastReviewRefresh={lastReviewRefresh}
onRefresh={refreshReviewQueue}
onProceed={handleProceed}
/>
<div style={{ display: "flex", alignItems: "center", gap: "16px" }}>
<div
style={{
fontSize: "0.9em",
color: "#ccc",
whiteSpace: "nowrap",
}}
title={`Context: ${contextUsage.used.toLocaleString()} / ${contextUsage.total.toLocaleString()} tokens (${contextUsage.percentage}%)`}
>
{getContextEmoji(contextUsage.percentage)} {contextUsage.percentage}
%
</div>
<button
type="button"
onClick={clearSession}
style={{
padding: "6px 12px",
borderRadius: "99px",
border: "none",
fontSize: "0.85em",
backgroundColor: "#2f2f2f",
color: "#888",
cursor: "pointer",
outline: "none",
transition: "all 0.2s",
}}
onMouseOver={(e) => {
e.currentTarget.style.backgroundColor = "#3f3f3f";
e.currentTarget.style.color = "#ccc";
}}
onMouseOut={(e) => {
e.currentTarget.style.backgroundColor = "#2f2f2f";
e.currentTarget.style.color = "#888";
}}
onFocus={(e) => {
e.currentTarget.style.backgroundColor = "#3f3f3f";
e.currentTarget.style.color = "#ccc";
}}
onBlur={(e) => {
e.currentTarget.style.backgroundColor = "#2f2f2f";
e.currentTarget.style.color = "#888";
}}
>
🔄 New Session
</button>
{availableModels.length > 0 || claudeModels.length > 0 ? (
<select
value={model}
onChange={(e) => {
const newModel = e.target.value;
setModel(newModel);
api.setModelPreference(newModel).catch(console.error);
}}
style={{
padding: "6px 32px 6px 16px",
borderRadius: "99px",
border: "none",
fontSize: "0.9em",
backgroundColor: "#2f2f2f",
color: "#ececec",
cursor: "pointer",
outline: "none",
appearance: "none",
WebkitAppearance: "none",
backgroundImage: `url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23ececec%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E")`,
backgroundRepeat: "no-repeat",
backgroundPosition: "right 12px center",
backgroundSize: "10px",
}}
>
{(claudeModels.length > 0 || !hasAnthropicKey) && (
<optgroup label="Anthropic">
{claudeModels.length > 0 ? (
claudeModels.map((m: string) => (
<option key={m} value={m}>
{m}
</option>
))
) : (
<option value="" disabled>
Add Anthropic API key to load models
</option>
)}
</optgroup>
)}
{availableModels.length > 0 && (
<optgroup label="Ollama">
{availableModels.map((m: string) => (
<option key={m} value={m}>
{m}
</option>
))}
</optgroup>
)}
</select>
) : (
<input
value={model}
onChange={(e) => {
const newModel = e.target.value;
setModel(newModel);
api.setModelPreference(newModel).catch(console.error);
}}
placeholder="Model"
style={{
padding: "6px 12px",
borderRadius: "99px",
border: "none",
fontSize: "0.9em",
background: "#2f2f2f",
color: "#ececec",
outline: "none",
}}
/>
)}
<label
style={{
display: "flex",
alignItems: "center",
gap: "6px",
cursor: "pointer",
fontSize: "0.9em",
color: "#aaa",
}}
title="Allow the Agent to read/write files"
>
<input
type="checkbox"
checked={enableTools}
onChange={(e) => setEnableTools(e.target.checked)}
style={{ accentColor: "#000" }}
/>
<span>Tools</span>
</label>
<GatePanel
gateState={gateState}
gateStatusLabel={gateStatusLabel}
gateStatusColor={gateStatusColor}
isGateLoading={isGateLoading}
gateError={gateError}
lastGateRefresh={lastGateRefresh}
onRefresh={() => refreshGateState(storyId)}
/>
</div>
</div>