feat(ai): 优化拆解重跑与结果展示
This commit is contained in:
@@ -147,9 +147,48 @@ describe('AiService', () => {
|
||||
expect(testCaseRequired).toContain('categoryCode');
|
||||
});
|
||||
|
||||
it('requires estimateHours for test case drafts', () => {
|
||||
it('requires aiEstimateHours for dev task and test case drafts', () => {
|
||||
const devRequired = (DECOMPOSE_TOOL_INPUT_SCHEMA.properties.devTaskDrafts as any).items.required;
|
||||
const testCaseRequired = (DECOMPOSE_TOOL_INPUT_SCHEMA.properties.testCaseDrafts as any).items.required;
|
||||
|
||||
expect(testCaseRequired).toContain('estimateHours');
|
||||
expect(devRequired).toContain('aiEstimateHours');
|
||||
expect(devRequired).not.toContain('estimateHours');
|
||||
expect(testCaseRequired).toContain('aiEstimateHours');
|
||||
expect(testCaseRequired).not.toContain('estimateHours');
|
||||
});
|
||||
|
||||
it('passes decomposition target into the model prompt', async () => {
|
||||
const callTool = jest.fn().mockResolvedValue({
|
||||
toolName: 'submit_decompose',
|
||||
toolInput: {
|
||||
report: { matched: [], reqOnly: ['req-1'], noteOnly: [], ambiguous: [] },
|
||||
devTaskDrafts: [],
|
||||
testCaseDrafts: [],
|
||||
},
|
||||
inputTokens: 100,
|
||||
outputTokens: 20,
|
||||
rawModel: 'claude-test',
|
||||
});
|
||||
|
||||
const gateway = {
|
||||
getActiveProvider: jest.fn().mockResolvedValue({ callTool }),
|
||||
getActiveModel: jest.fn().mockResolvedValue('claude-test'),
|
||||
} as unknown as AiGatewayService;
|
||||
|
||||
const service = new AiService(gateway);
|
||||
(service as any).fetchPrototype = jest.fn().mockResolvedValue('QY0001:手机号登录');
|
||||
|
||||
await service.decompose({
|
||||
prototypeUrl: 'https://example.com/prototype',
|
||||
requirements: [{ id: 'req-1', code: 'REQ001', title: '手机登录' }],
|
||||
members: [{ name: '张三', role: 'frontend' }],
|
||||
versionId: 'version-1',
|
||||
planId: 'plan-1',
|
||||
target: 'dev_tasks',
|
||||
});
|
||||
|
||||
const userPrompt = callTool.mock.calls[0][0].userPrompt;
|
||||
expect(userPrompt).toContain('本次只重新拆解开发任务');
|
||||
expect(userPrompt).toContain('testCaseDrafts 必须返回空数组');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
AgentDecomposeResponse,
|
||||
AgentDecomposeError,
|
||||
AgentDecomposeResult,
|
||||
AgentDecomposeTarget,
|
||||
} from '@ftb/shared';
|
||||
|
||||
const DECOMPOSE_CONTEXT_CHAR_STEPS = [1800, 1200, 800] as const;
|
||||
@@ -107,7 +108,7 @@ export class AiService {
|
||||
};
|
||||
}
|
||||
|
||||
const result = toolResp.toolInput as AgentDecomposeResult;
|
||||
const result = this.applyTargetToResult(toolResp.toolInput as AgentDecomposeResult, req.target);
|
||||
if (!result.report || !Array.isArray(result.devTaskDrafts) || !Array.isArray(result.testCaseDrafts)) {
|
||||
return {
|
||||
ok: false,
|
||||
@@ -195,6 +196,7 @@ export class AiService {
|
||||
.join('\n');
|
||||
|
||||
const memberList = req.members.map((m) => `- ${m.name} (${m.role})`).join('\n');
|
||||
const targetInstruction = this.buildTargetInstruction(req.target ?? 'all');
|
||||
|
||||
return `${isRetry ? '## 重试说明\n上一次 AI 服务未返回工具结果,本次已缩短原型上下文。仍然必须只通过 submit_decompose 工具返回结果。\n\n' : ''}## 产品方案原型
|
||||
|
||||
@@ -215,9 +217,36 @@ ${reqList || '(无)'}
|
||||
|
||||
${memberList || '(无)'}
|
||||
|
||||
## 本次拆解目标
|
||||
|
||||
${targetInstruction}
|
||||
|
||||
## 你的任务
|
||||
|
||||
按系统提示词的规则,拆解出开发任务草案、测试用例草案、对账报告。
|
||||
通过 tool 调用 submit_decompose 返回结果。`;
|
||||
}
|
||||
|
||||
private buildTargetInstruction(target: AgentDecomposeTarget): string {
|
||||
if (target === 'dev_tasks') {
|
||||
return '本次只重新拆解开发任务;devTaskDrafts 正常返回,testCaseDrafts 必须返回空数组。';
|
||||
}
|
||||
if (target === 'test_cases') {
|
||||
return '本次只重新拆解测试用例;testCaseDrafts 正常返回,devTaskDrafts 必须返回空数组。';
|
||||
}
|
||||
return '本次同时拆解开发任务和测试用例;devTaskDrafts 与 testCaseDrafts 都按实际需要返回。';
|
||||
}
|
||||
|
||||
private applyTargetToResult(
|
||||
result: AgentDecomposeResult,
|
||||
target: AgentDecomposeTarget = 'all',
|
||||
): AgentDecomposeResult {
|
||||
if (target === 'dev_tasks') {
|
||||
return { ...result, testCaseDrafts: [] };
|
||||
}
|
||||
if (target === 'test_cases') {
|
||||
return { ...result, devTaskDrafts: [] };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsString, IsArray, ValidateNested, IsOptional } from 'class-validator';
|
||||
import { IsString, IsArray, ValidateNested, IsOptional, IsIn } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class DecomposeReqMemberDto {
|
||||
@@ -34,6 +34,10 @@ export class DecomposeDto {
|
||||
@IsString()
|
||||
planId!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(['all', 'dev_tasks', 'test_cases'])
|
||||
target?: 'all' | 'dev_tasks' | 'test_cases';
|
||||
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => DecomposeReqRequirementDto)
|
||||
|
||||
@@ -38,15 +38,18 @@ export const DECOMPOSE_SYSTEM_PROMPT = `你是 FTB 项目管理系统的产品
|
||||
- 不输出数据库 categoryId
|
||||
- 不输出推荐负责人(用户后续手填)
|
||||
|
||||
5. 工时估算(小时,按团队使用 AI 辅助研发/测试估算,必须偏严格)
|
||||
5. AI 工时估算(字段名 aiEstimateHours,单位小时)
|
||||
- aiEstimateHours 只代表 AI 对工作量的判断,不代表负责人计划排期
|
||||
- 不要输出 estimateHours、预计开始时间、预计截止时间
|
||||
- 简单前端字段、文案、展示调整: 0.25-0.5h
|
||||
- 简单前端交互,如拖拽排序 UI、开关、筛选项: 0.5-1h
|
||||
- 拖拽排序并需要持久化接口: 1-1.5h
|
||||
- 简单 CRUD 接口: 0.75-1.5h
|
||||
- 数据库字段/索引调整: 0.5h
|
||||
- 中等业务规则变更: 1.5-3h
|
||||
- 简单功能测试用例执行: 0.25-0.5h
|
||||
- API/异常/兼容性测试用例执行: 0.5-1h
|
||||
- 简单前端交互,如拖拽排序 UI、开关、筛选项: 0.25-0.5h
|
||||
- 拖拽排序并需要持久化接口: 0.75-1h
|
||||
- 简单 CRUD 接口: 0.5-1h
|
||||
- 数据库字段/索引调整: 0.25-0.5h
|
||||
- 中等业务规则变更: 1-2h
|
||||
- 简单功能测试用例执行: 0.1-0.3h
|
||||
- API/异常测试用例执行: 0.2-0.5h
|
||||
- 兼容性测试用例执行: 0.3-0.75h
|
||||
- 只有跨端同步、复杂权限、历史数据迁移、强一致性、复杂兼容性时,才允许超过上述区间
|
||||
|
||||
6. 标题:中文动词开头,简洁
|
||||
@@ -133,7 +136,7 @@ export const DECOMPOSE_TOOL_INPUT_SCHEMA = {
|
||||
],
|
||||
},
|
||||
priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] },
|
||||
estimateHours: { type: 'number' },
|
||||
aiEstimateHours: { type: 'number' },
|
||||
references: {
|
||||
type: 'array',
|
||||
items: {
|
||||
@@ -148,7 +151,7 @@ export const DECOMPOSE_TOOL_INPUT_SCHEMA = {
|
||||
minItems: 1,
|
||||
},
|
||||
},
|
||||
required: ['title', 'categoryCode', 'priority', 'estimateHours', 'references'],
|
||||
required: ['title', 'categoryCode', 'priority', 'aiEstimateHours', 'references'],
|
||||
},
|
||||
},
|
||||
testCaseDrafts: {
|
||||
@@ -163,7 +166,7 @@ export const DECOMPOSE_TOOL_INPUT_SCHEMA = {
|
||||
enum: ['test_functional', 'test_api', 'test_exception', 'test_compatibility'],
|
||||
},
|
||||
priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] },
|
||||
estimateHours: { type: 'number' },
|
||||
aiEstimateHours: { type: 'number' },
|
||||
references: {
|
||||
type: 'array',
|
||||
items: {
|
||||
@@ -178,7 +181,7 @@ export const DECOMPOSE_TOOL_INPUT_SCHEMA = {
|
||||
minItems: 1,
|
||||
},
|
||||
},
|
||||
required: ['title', 'description', 'categoryCode', 'priority', 'estimateHours', 'references'],
|
||||
required: ['title', 'description', 'categoryCode', 'priority', 'aiEstimateHours', 'references'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -183,7 +183,7 @@ export function DevTaskCreateModal({ versionId, requirementIds, versionDeadline,
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">预计工时(自动)</label>
|
||||
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">执行预估工时(自动)</label>
|
||||
<div className="h-9 flex items-center px-3 rounded-lg border border-dashed border-[var(--line)] bg-[var(--bg-subtle)] text-[13px] text-[var(--ink-soft)] tabular-nums">
|
||||
{estimateHours > 0 ? formatWorkHours(estimateHours) : (startBeforeEnd ? '0h' : '请先选择有效起止时间')}
|
||||
</div>
|
||||
|
||||
@@ -50,6 +50,8 @@ export function DevTaskDetailDrawer({ taskId, allTaskIds, onClose, contextLabel
|
||||
const [showBlockInput, setShowBlockInput] = useState(false);
|
||||
|
||||
const estimate = useMemo(() => getEstimateHours(task), [task]);
|
||||
const executorEstimate = typeof task.estimateHours === 'number' && task.estimateHours > 0 ? task.estimateHours : undefined;
|
||||
const aiEstimate = typeof task.aiEstimateHours === 'number' && task.aiEstimateHours > 0 ? task.aiEstimateHours : undefined;
|
||||
const actual = useMemo(() => getActualHours(task), [task]);
|
||||
const overrun = actual > estimate && estimate > 0;
|
||||
const requireDelay = task.status === 'todo' && needsDelayReason(task);
|
||||
@@ -217,8 +219,12 @@ export function DevTaskDetailDrawer({ taskId, allTaskIds, onClose, contextLabel
|
||||
<span className="text-[var(--ink)] font-medium tabular-nums">{task.actualEndAt ? formatShortTime(task.actualEndAt) : '—'}</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-[10px] text-[var(--ink-muted)]">预计耗时</span>
|
||||
<span className="text-[var(--ink)] font-medium tabular-nums">{formatHours(estimate)}</span>
|
||||
<span className="text-[10px] text-[var(--ink-muted)]">AI 预估</span>
|
||||
<span className="text-[var(--ink)] font-medium tabular-nums">{aiEstimate ? formatHours(aiEstimate) : '—'}</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-[10px] text-[var(--ink-muted)]">执行预估</span>
|
||||
<span className="text-[var(--ink)] font-medium tabular-nums">{executorEstimate ? formatHours(executorEstimate) : '待负责人填写'}</span>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<span className="text-[10px] text-[var(--ink-muted)]">实际耗时</span>
|
||||
|
||||
@@ -34,8 +34,11 @@ function timeRangeText(task: DevTask): { text: string; tone: string } {
|
||||
return { text: '', tone: 'text-[var(--ink-muted)]' };
|
||||
}
|
||||
|
||||
function hoursText(estimate: number, actual: number): { text: string; tone: string } {
|
||||
if (actual <= 0) return { text: `预 ${formatWorkHours(estimate)}`, tone: 'text-[var(--ink-muted)]' };
|
||||
function hoursText(task: DevTask, estimate: number, actual: number): { text: string; tone: string } {
|
||||
const hasExecutorEstimate = typeof task.estimateHours === 'number' && task.estimateHours > 0;
|
||||
const hasAiEstimate = typeof task.aiEstimateHours === 'number' && task.aiEstimateHours > 0;
|
||||
const prefix = hasExecutorEstimate ? '执行预' : hasAiEstimate ? 'AI预' : '预';
|
||||
if (actual <= 0) return { text: `${prefix} ${formatWorkHours(estimate)}`, tone: 'text-[var(--ink-muted)]' };
|
||||
let tone = 'text-[var(--ink-soft)]';
|
||||
if (actual > estimate) tone = 'text-red-600';
|
||||
else if (actual < estimate) tone = 'text-emerald-600';
|
||||
@@ -46,7 +49,7 @@ export function DevTaskRow({ task, category, onClick }: Props) {
|
||||
const estimate = getEstimateHours(task);
|
||||
const actual = getActualHours(task);
|
||||
const range = timeRangeText(task);
|
||||
const hours = hoursText(estimate, actual);
|
||||
const hours = hoursText(task, estimate, actual);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -121,7 +121,7 @@ export function TestCaseCreateModal({ versionId, requirementIds, onClose }: Prop
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">预估耗时 *</label>
|
||||
<label className="block text-[12px] text-[var(--ink-soft)] mb-1">执行预估耗时 *</label>
|
||||
<input
|
||||
type="number"
|
||||
min="0.25"
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useRequirementStore } from '@/stores/useRequirementStore';
|
||||
import { useMemberStore } from '@/stores/useMemberStore';
|
||||
import { useTaskCategoryStore } from '@/stores/useTaskCategoryStore';
|
||||
import { CategoryChip } from '@/components/dev-task/CategoryChip';
|
||||
import { TC_ALLOWED_TRANSITIONS, TEST_CASE_STATUS_LABEL, getTestCaseActualHours, getTestCaseEstimateHours } from '@/lib/test-case';
|
||||
import { TC_ALLOWED_TRANSITIONS, TEST_CASE_STATUS_LABEL, getTestCaseActualHours } from '@/lib/test-case';
|
||||
import { formatWorkHours } from '@/lib/work-hours';
|
||||
import { formatDateTime } from '@/lib/format';
|
||||
import { BUG_SEVERITY_LABEL, BUG_SEVERITY_COLOR } from '@/lib/bug';
|
||||
@@ -39,7 +39,8 @@ export function TestCaseDetailDrawer({ testCaseId, onClose, onCreateBug, context
|
||||
const category = categories.find((c) => c.id === tc.categoryId);
|
||||
const relatedBugs = bugs.filter((b) => b.testCaseId === tc.id);
|
||||
const nextStatuses = TC_ALLOWED_TRANSITIONS[tc.status];
|
||||
const estimateHours = getTestCaseEstimateHours(tc);
|
||||
const executorEstimateHours = typeof tc.estimateHours === 'number' && tc.estimateHours > 0 ? tc.estimateHours : undefined;
|
||||
const aiEstimateHours = typeof tc.aiEstimateHours === 'number' && tc.aiEstimateHours > 0 ? tc.aiEstimateHours : undefined;
|
||||
const actualHours = getTestCaseActualHours(tc);
|
||||
|
||||
const [failReason, setFailReason] = useState('');
|
||||
@@ -159,7 +160,8 @@ export function TestCaseDetailDrawer({ testCaseId, onClose, onCreateBug, context
|
||||
<div><span className="text-[var(--ink-muted)]">优先级:</span><span className="text-[var(--ink)] font-medium">{tc.priority}</span></div>
|
||||
<div className="flex items-center gap-1.5"><span className="text-[var(--ink-muted)]">任务类型:</span><CategoryChip category={category} /></div>
|
||||
<div><span className="text-[var(--ink-muted)]">负责人:</span><span className="text-[var(--ink)] font-medium">{tc.assigneeId || '-'}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">预估耗时:</span><span className="text-[var(--ink)] font-medium">{formatWorkHours(estimateHours)}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">AI 预估:</span><span className="text-[var(--ink)] font-medium">{aiEstimateHours ? formatWorkHours(aiEstimateHours) : '—'}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">执行预估:</span><span className="text-[var(--ink)] font-medium">{executorEstimateHours ? formatWorkHours(executorEstimateHours) : '待负责人填写'}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">创建人:</span><span className="text-[var(--ink)]">{tc.createdBy}</span></div>
|
||||
<div><span className="text-[var(--ink-muted)]">创建日期:</span><span className="text-[var(--ink)]">{tc.createdAt.slice(0, 10)}</span></div>
|
||||
{tc.startedAt && <div><span className="text-[var(--ink-muted)]">开始执行:</span><span className="text-[var(--ink)]">{formatDateTime(tc.startedAt)}</span></div>}
|
||||
|
||||
@@ -25,6 +25,9 @@ const PRIORITY_DOT: Record<string, string> = {
|
||||
function TestCaseRowImpl({ testCase, category, bugCount, onClick }: Props) {
|
||||
const estimateHours = getTestCaseEstimateHours(testCase);
|
||||
const actualHours = getTestCaseActualHours(testCase);
|
||||
const hasExecutorEstimate = typeof testCase.estimateHours === 'number' && testCase.estimateHours > 0;
|
||||
const hasAiEstimate = typeof testCase.aiEstimateHours === 'number' && testCase.aiEstimateHours > 0;
|
||||
const estimatePrefix = hasExecutorEstimate ? '执行预' : hasAiEstimate ? 'AI预' : '预';
|
||||
return (
|
||||
<div onClick={onClick} className={`flex items-center gap-3 px-4 py-2.5 border-b border-[var(--line)] hover:bg-[var(--bg-subtle)] cursor-pointer transition-colors last:border-b-0 ${testCase.aiDraft ? 'border-l-2 border-l-purple-400 bg-purple-50/30' : ''}`}>
|
||||
<span className={`h-2 w-2 rounded-full shrink-0 ${PRIORITY_DOT[testCase.priority] || 'bg-zinc-300'}`} />
|
||||
@@ -40,7 +43,7 @@ function TestCaseRowImpl({ testCase, category, bugCount, onClick }: Props) {
|
||||
</div>
|
||||
<TestCaseStatusBadge status={testCase.status} />
|
||||
<span className="text-[11px] text-[var(--ink-muted)] tabular-nums w-32 text-right shrink-0 whitespace-nowrap">
|
||||
{actualHours > 0 ? `${formatWorkHours(actualHours)} / ${formatWorkHours(estimateHours)}` : `预 ${formatWorkHours(estimateHours)}`}
|
||||
{actualHours > 0 ? `${formatWorkHours(actualHours)} / ${formatWorkHours(estimateHours)}` : `${estimatePrefix} ${formatWorkHours(estimateHours)}`}
|
||||
</span>
|
||||
{bugCount > 0 && (
|
||||
<span className="text-[10px] text-red-500 bg-red-50 px-1.5 py-0.5 rounded shrink-0">{bugCount} Bug</span>
|
||||
|
||||
@@ -7,9 +7,14 @@ import type { VersionWithContext } from '@/lib/derive';
|
||||
import { useVersionPlanStore } from '@/stores/useVersionPlanStore';
|
||||
import { useRequirementStore } from '@/stores/useRequirementStore';
|
||||
import { useAuthStore } from '@/stores/useAuthStore';
|
||||
import { useDevTaskStore } from '@/stores/useDevTaskStore';
|
||||
import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
||||
import { useTaskCategoryStore } from '@/stores/useTaskCategoryStore';
|
||||
import { api } from '@/lib/api';
|
||||
import { filterDuplicateDecomposeDrafts } from '@/lib/ai-decompose-dedupe';
|
||||
import { DecomposeReportModal } from './DecomposeReportModal';
|
||||
import type {
|
||||
AgentDecomposeTarget,
|
||||
AgentDecomposeRequest,
|
||||
AgentDecomposeResponse,
|
||||
AgentDecomposeError,
|
||||
@@ -33,12 +38,18 @@ function formatElapsed(sec: number): string {
|
||||
export function AiDecomposeButton({ plan, version }: Props) {
|
||||
const { updatePlan } = useVersionPlanStore();
|
||||
const { requirements } = useRequirementStore();
|
||||
const devTasks = useDevTaskStore((s) => s.tasks);
|
||||
const testCases = useTestCaseStore((s) => s.testCases);
|
||||
const categories = useTaskCategoryStore((s) => s.categories);
|
||||
const user = useAuthStore((s) => s.user);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [activeTarget, setActiveTarget] = useState<AgentDecomposeTarget | null>(null);
|
||||
const [result, setResult] = useState<AgentDecomposeResponse | null>(null);
|
||||
const [resultTarget, setResultTarget] = useState<AgentDecomposeTarget>('all');
|
||||
const [dedupeSummary, setDedupeSummary] = useState({ removedDevTaskCount: 0, removedTestCaseCount: 0 });
|
||||
const [tick, setTick] = useState(0);
|
||||
const startedAtRef = useRef<number | null>(null);
|
||||
const loading = activeTarget !== null;
|
||||
|
||||
// plan 上的状态(持久化在 localStorage)
|
||||
const persistStatus = plan.aiDecomposeStatus;
|
||||
@@ -78,14 +89,20 @@ export function AiDecomposeButton({ plan, version }: Props) {
|
||||
description: r.description,
|
||||
}));
|
||||
|
||||
const handleClick = async () => {
|
||||
const targetText = (target: AgentDecomposeTarget) => {
|
||||
if (target === 'dev_tasks') return '开发任务';
|
||||
if (target === 'test_cases') return '测试用例';
|
||||
return '任务和用例';
|
||||
};
|
||||
|
||||
const handleClick = async (target: AgentDecomposeTarget) => {
|
||||
if (loading) return;
|
||||
// 即便 persistStatus 是 in_progress,只要超过阈值就允许重新点
|
||||
if (persistStatus === 'in_progress' && !isStaleInProgress) return;
|
||||
|
||||
startedAtRef.current = Date.now();
|
||||
setTick(Date.now());
|
||||
setLoading(true);
|
||||
setActiveTarget(target);
|
||||
|
||||
updatePlan(plan.id, {
|
||||
aiDecomposeStatus: 'in_progress',
|
||||
@@ -105,6 +122,7 @@ export function AiDecomposeButton({ plan, version }: Props) {
|
||||
members,
|
||||
versionId: version.id,
|
||||
planId: plan.id,
|
||||
target,
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -119,7 +137,19 @@ export function AiDecomposeButton({ plan, version }: Props) {
|
||||
aiDecomposeError: resp.error,
|
||||
});
|
||||
} else {
|
||||
setResult(resp);
|
||||
const requirementIdSet = new Set(linkedReqs.map((req) => req.id));
|
||||
const deduped = filterDuplicateDecomposeDrafts(resp.result, {
|
||||
existingDevTasks: devTasks.filter((task) => requirementIdSet.has(task.requirementId)),
|
||||
existingTestCases: testCases.filter((testCase) => testCase.versionId === version.id),
|
||||
categories,
|
||||
requirements: linkedReqs,
|
||||
});
|
||||
setResult({ ...resp, result: deduped.result });
|
||||
setDedupeSummary({
|
||||
removedDevTaskCount: deduped.removedDevTaskCount,
|
||||
removedTestCaseCount: deduped.removedTestCaseCount,
|
||||
});
|
||||
setResultTarget(target);
|
||||
updatePlan(plan.id, {
|
||||
aiDecomposeStatus: 'completed',
|
||||
aiDecomposeError: undefined,
|
||||
@@ -132,7 +162,7 @@ export function AiDecomposeButton({ plan, version }: Props) {
|
||||
aiDecomposeError: msg,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setActiveTarget(null);
|
||||
startedAtRef.current = null;
|
||||
}
|
||||
};
|
||||
@@ -143,39 +173,48 @@ export function AiDecomposeButton({ plan, version }: Props) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
onClick={handleClick}
|
||||
disabled={isInProgress}
|
||||
className={`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] font-medium disabled:cursor-not-allowed disabled:opacity-70 ${
|
||||
isError
|
||||
? 'border-red-200 bg-red-50 text-red-700 hover:bg-red-100'
|
||||
: 'border-purple-200 bg-purple-50 text-purple-700 hover:bg-purple-100'
|
||||
}`}
|
||||
title={
|
||||
isError
|
||||
? `上次失败:${persistError || '未知错误'}(点击重试)`
|
||||
: wasCompleted
|
||||
? '此前已拆解过,再次点击会重新拆解'
|
||||
: '使用 AI 把原型 + 关联需求拆解成开发任务和测试用例'
|
||||
}
|
||||
>
|
||||
{isInProgress ? (
|
||||
<>
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
拆解中 {formatElapsed(elapsedSec)}
|
||||
</>
|
||||
) : isError ? (
|
||||
<>
|
||||
<RotateCw className="h-3 w-3" />
|
||||
重试
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Sparkles className="h-3 w-3" />
|
||||
{wasCompleted ? '重新 AI 拆解' : 'AI 拆解'}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
{(['dev_tasks', 'test_cases'] as AgentDecomposeTarget[]).map((target) => {
|
||||
const showSpinner = isInProgress && (!activeTarget || activeTarget === target);
|
||||
const label = wasCompleted ? `重新拆解${targetText(target)}` : `AI 拆解${targetText(target)}`;
|
||||
return (
|
||||
<button
|
||||
key={target}
|
||||
onClick={() => handleClick(target)}
|
||||
disabled={isInProgress}
|
||||
className={`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] font-medium disabled:cursor-not-allowed disabled:opacity-70 ${
|
||||
isError
|
||||
? 'border-red-200 bg-red-50 text-red-700 hover:bg-red-100'
|
||||
: 'border-purple-200 bg-purple-50 text-purple-700 hover:bg-purple-100'
|
||||
}`}
|
||||
title={
|
||||
isError
|
||||
? `上次失败:${persistError || '未知错误'}(点击重试${targetText(target)})`
|
||||
: wasCompleted
|
||||
? `此前已拆解过,再次点击会重新拆解${targetText(target)}`
|
||||
: `使用 AI 把原型 + 关联需求拆解成${targetText(target)}`
|
||||
}
|
||||
>
|
||||
{showSpinner ? (
|
||||
<>
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
拆解中 {formatElapsed(elapsedSec)}
|
||||
</>
|
||||
) : isError ? (
|
||||
<>
|
||||
<RotateCw className="h-3 w-3" />
|
||||
重试{targetText(target)}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Sparkles className="h-3 w-3" />
|
||||
{label}
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
|
||||
{/* 错误信息:在按钮旁悬浮显示 */}
|
||||
{isError && persistError && (
|
||||
@@ -198,6 +237,8 @@ export function AiDecomposeButton({ plan, version }: Props) {
|
||||
version={version}
|
||||
plan={plan}
|
||||
requirements={linkedReqs}
|
||||
target={resultTarget}
|
||||
dedupeSummary={dedupeSummary}
|
||||
onClose={() => setResult(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -9,9 +9,10 @@ import { useTestCaseStore } from '@/stores/useTestCaseStore';
|
||||
import { useTaskCategoryStore } from '@/stores/useTaskCategoryStore';
|
||||
import { useAuthStore } from '@/stores/useAuthStore';
|
||||
import { findCategoryByCode, resolveCategoryIdFromCode } from '@/lib/task-category';
|
||||
import { addWorkHours } from '@/lib/work-hours';
|
||||
import { clampDevEstimateHours, clampTestCaseEstimateHours } from '@/lib/ai-estimation-policy';
|
||||
import { clampDevAiEstimateHours, clampTestCaseAiEstimateHours } from '@/lib/ai-estimation-policy';
|
||||
import { formatReportRequirementLabel } from '@/lib/ai-decompose-report';
|
||||
import type {
|
||||
AgentDecomposeTarget,
|
||||
AgentDecomposeResponse,
|
||||
AgentDevTaskDraft,
|
||||
AgentTestCaseDraft,
|
||||
@@ -22,16 +23,22 @@ interface Props {
|
||||
version: VersionWithContext;
|
||||
plan: VersionPlan;
|
||||
requirements: Array<{ id: string; code: string; title: string; description?: string }>;
|
||||
target: AgentDecomposeTarget;
|
||||
dedupeSummary?: { removedDevTaskCount: number; removedTestCaseCount: number };
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export function DecomposeReportModal({ result, version, plan, requirements, onClose }: Props) {
|
||||
export function DecomposeReportModal({ result, version, plan, requirements, target, dedupeSummary, onClose }: Props) {
|
||||
const { createTask } = useDevTaskStore();
|
||||
const { createTestCase } = useTestCaseStore();
|
||||
const { categories } = useTaskCategoryStore();
|
||||
const user = useAuthStore((s) => s.user);
|
||||
|
||||
const { result: data, meta } = result;
|
||||
const showDevDrafts = target !== 'test_cases';
|
||||
const showTestDrafts = target !== 'dev_tasks';
|
||||
const filteredDuplicateCount =
|
||||
(dedupeSummary?.removedDevTaskCount ?? 0) + (dedupeSummary?.removedTestCaseCount ?? 0);
|
||||
|
||||
const [selectedDevIdx, setSelectedDevIdx] = useState<Set<number>>(
|
||||
new Set(data.devTaskDrafts.map((_, i) => i)),
|
||||
@@ -90,9 +97,7 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
const reqRef = refs.find((r) => r.type === 'requirement');
|
||||
const requirementId = reqRef?.id ?? requirements[0]?.id ?? '';
|
||||
const categoryId = resolveCategoryIdFromCode(categories, draft.categoryCode, 'development');
|
||||
const estimateHours = clampDevEstimateHours(draft.categoryCode, draft.estimateHours);
|
||||
const startISO = new Date().toISOString();
|
||||
const endISO = addWorkHours(startISO, estimateHours);
|
||||
const aiEstimateHours = clampDevAiEstimateHours(draft.categoryCode, draft.aiEstimateHours);
|
||||
|
||||
createTask({
|
||||
requirementId,
|
||||
@@ -102,9 +107,10 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
assigneeId: '',
|
||||
reviewerId: undefined,
|
||||
priority: draft.priority,
|
||||
expectedStartAt: startISO,
|
||||
expectedEndAt: endISO,
|
||||
estimateHours,
|
||||
expectedStartAt: '',
|
||||
expectedEndAt: '',
|
||||
estimateHours: undefined,
|
||||
aiEstimateHours,
|
||||
actualStartAt: undefined,
|
||||
actualEndAt: undefined,
|
||||
status: 'todo',
|
||||
@@ -129,7 +135,7 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
const refs = normalizeRefs(draft.references);
|
||||
const reqRef = refs.find((r) => r.type === 'requirement');
|
||||
const categoryId = resolveCategoryIdFromCode(categories, draft.categoryCode, 'testing');
|
||||
const estimateHours = clampTestCaseEstimateHours(draft.categoryCode, draft.estimateHours);
|
||||
const aiEstimateHours = clampTestCaseAiEstimateHours(draft.categoryCode, draft.aiEstimateHours);
|
||||
|
||||
createTestCase({
|
||||
versionId: version.id,
|
||||
@@ -138,7 +144,8 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
description: draft.description,
|
||||
categoryId,
|
||||
priority: draft.priority,
|
||||
estimateHours,
|
||||
estimateHours: undefined,
|
||||
aiEstimateHours,
|
||||
assigneeId: undefined,
|
||||
references: refs,
|
||||
aiDraft: true,
|
||||
@@ -155,6 +162,8 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
setTimeout(() => onClose(), 1500);
|
||||
};
|
||||
|
||||
const selectedVisibleCount = (showDevDrafts ? selectedDevIdx.size : 0) + (showTestDrafts ? selectedTcIdx.size : 0);
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40" onClick={onClose}>
|
||||
<div
|
||||
@@ -178,6 +187,12 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
|
||||
{/* Body */}
|
||||
<div className="flex-1 overflow-y-auto px-5 py-4 space-y-4">
|
||||
{filteredDuplicateCount > 0 && (
|
||||
<div className="rounded-lg border border-purple-200 bg-purple-50 px-3 py-2 text-[12px] text-purple-700">
|
||||
已自动过滤 {dedupeSummary?.removedDevTaskCount ?? 0} 个重复开发任务、{dedupeSummary?.removedTestCaseCount ?? 0} 个重复测试用例。
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 对账报告 */}
|
||||
<section>
|
||||
<h4 className="text-[12px] font-semibold text-[var(--ink-soft)] mb-2">对账报告</h4>
|
||||
@@ -192,8 +207,14 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
</div>
|
||||
<ul className="text-[12px] text-emerald-800 space-y-1 ml-5">
|
||||
{data.report.matched.map((m, i) => (
|
||||
<li key={i}>
|
||||
{m.reqId} ↔ {m.noteIds.join(', ') || '(仅需求驱动)'} → 拆出 {m.taskCount} 个任务
|
||||
<li key={i} className="flex flex-wrap items-center gap-1">
|
||||
<span
|
||||
className="max-w-[280px] truncate font-medium"
|
||||
title={formatReportRequirementLabel(m.reqId, requirements)}
|
||||
>
|
||||
{formatReportRequirementLabel(m.reqId, requirements)}
|
||||
</span>
|
||||
<span>↔ {m.noteIds.join(', ') || '(仅需求驱动)'} → 拆出 {m.taskCount} 个任务</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -210,7 +231,10 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
以下需求在原型上未找到对应批注,已按需求文字拆解,请人工核对:
|
||||
</p>
|
||||
<ul className="text-[12px] text-amber-800 ml-5 list-disc">
|
||||
{data.report.reqOnly.map((id, i) => <li key={i}>{id}</li>)}
|
||||
{data.report.reqOnly.map((id, i) => {
|
||||
const label = formatReportRequirementLabel(id, requirements);
|
||||
return <li key={i} className="max-w-[360px] truncate" title={label}>{label}</li>;
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
@@ -248,6 +272,7 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
</section>
|
||||
|
||||
{/* DevTask 草案 */}
|
||||
{showDevDrafts && (
|
||||
<section>
|
||||
<h4 className="text-[12px] font-semibold text-[var(--ink-soft)] mb-2">
|
||||
开发任务草案({data.devTaskDrafts.length})
|
||||
@@ -277,7 +302,7 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
{d.priority}
|
||||
</span>
|
||||
<span className="text-[10px] text-[var(--ink-muted)]">
|
||||
{clampDevEstimateHours(d.categoryCode, d.estimateHours)}h
|
||||
AI预估 {clampDevAiEstimateHours(d.categoryCode, d.aiEstimateHours)}h
|
||||
</span>
|
||||
</div>
|
||||
{d.description && (
|
||||
@@ -299,8 +324,10 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* TestCase 草案 */}
|
||||
{showTestDrafts && (
|
||||
<section>
|
||||
<h4 className="text-[12px] font-semibold text-[var(--ink-soft)] mb-2">
|
||||
测试用例草案({data.testCaseDrafts.length})
|
||||
@@ -330,7 +357,7 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
{d.priority}
|
||||
</span>
|
||||
<span className="text-[10px] text-[var(--ink-muted)]">
|
||||
{clampTestCaseEstimateHours(d.categoryCode, d.estimateHours)}h
|
||||
AI预估 {clampTestCaseAiEstimateHours(d.categoryCode, d.aiEstimateHours)}h
|
||||
</span>
|
||||
</div>
|
||||
<pre className="mt-1 text-[11px] text-[var(--ink-soft)] whitespace-pre-wrap font-sans line-clamp-3">
|
||||
@@ -352,12 +379,13 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="flex items-center justify-between px-5 py-3 border-t border-[var(--line)]">
|
||||
<div className="text-[12px] text-[var(--ink-muted)]">
|
||||
已选 {selectedDevIdx.size} 个任务 + {selectedTcIdx.size} 个用例
|
||||
已选 {showDevDrafts ? selectedDevIdx.size : 0} 个任务 + {showTestDrafts ? selectedTcIdx.size : 0} 个用例
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
@@ -368,7 +396,7 @@ export function DecomposeReportModal({ result, version, plan, requirements, onCl
|
||||
</button>
|
||||
<button
|
||||
onClick={handleAdopt}
|
||||
disabled={submitting || submitted || (selectedDevIdx.size === 0 && selectedTcIdx.size === 0)}
|
||||
disabled={submitting || submitted || selectedVisibleCount === 0}
|
||||
className="h-8 px-4 rounded-lg text-[12px] font-medium bg-purple-600 text-white hover:bg-purple-700 disabled:opacity-50"
|
||||
>
|
||||
{submitted ? '✓ 已采纳' : submitting ? '采纳中...' : '采纳选中'}
|
||||
|
||||
@@ -5,10 +5,17 @@ import { X, Check, Link2, FileUp, ExternalLink, Play, ArrowRightLeft } from 'luc
|
||||
import { useVersionPlanStore } from '@/stores/useVersionPlanStore';
|
||||
import { useRequirementStore } from '@/stores/useRequirementStore';
|
||||
import { useMemberStore } from '@/stores/useMemberStore';
|
||||
import { calcPlanProgress, calcLinkedReqProgress } from '@/lib/version-plan';
|
||||
import {
|
||||
calcPlanProgress,
|
||||
calcLinkedReqProgress,
|
||||
PRODUCT_PLAN_KIND_LABEL,
|
||||
PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS,
|
||||
PRODUCT_PLAN_REVIEW_RESULT_LABEL,
|
||||
} from '@/lib/version-plan';
|
||||
import { formatDateTime } from '@/lib/format';
|
||||
import type { PlanTask, VersionPlan } from '@/lib/version-plan';
|
||||
import type { PlanTask, ProductPlanKind, ProductPlanReviewFailureType, ProductPlanReviewResult, VersionPlan } from '@/lib/version-plan';
|
||||
import { canEditPlanRequirementCoverage, canTogglePlanChecklist, getPlanCompletionState } from '@/lib/version-plan-workflow';
|
||||
import type { PlanResultPayload } from '@/lib/version-plan-workflow';
|
||||
|
||||
interface Props {
|
||||
planId: string;
|
||||
@@ -20,6 +27,24 @@ const STATUS_STYLE: Record<string, string> = { pending: 'bg-zinc-100 text-zinc-6
|
||||
const STATUS_LABEL: Record<string, string> = { pending: '未开始', in_progress: '进行中', completed: '已完成' };
|
||||
const TYPE_LABEL: Record<string, string> = { research: '调研', product: '产品方案', ui: 'UI设计' };
|
||||
|
||||
function getProductPlanKind(plan: VersionPlan): ProductPlanKind {
|
||||
return plan.productPlanKind ?? 'design';
|
||||
}
|
||||
|
||||
function getSubmitActionLabel(plan: VersionPlan): string {
|
||||
if (plan.type === 'product') {
|
||||
return getProductPlanKind(plan) === 'review' ? '提交评审结论' : '提交原型地址';
|
||||
}
|
||||
return '提交成果';
|
||||
}
|
||||
|
||||
function getFailureLabels(types?: ProductPlanReviewFailureType[]): string[] {
|
||||
if (!types?.length) return [];
|
||||
return types
|
||||
.map((type) => PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS.find((option) => option.value === type)?.label)
|
||||
.filter(Boolean) as string[];
|
||||
}
|
||||
|
||||
export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
const { plans, updatePlan, completePlan } = useVersionPlanStore();
|
||||
const { requirements } = useRequirementStore();
|
||||
@@ -31,6 +56,10 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
const [resultUrl, setResultUrl] = useState('');
|
||||
const [fileName, setFileName] = useState('');
|
||||
const [fileData, setFileData] = useState('');
|
||||
const [prototypeReviewConfirmed, setPrototypeReviewConfirmed] = useState(false);
|
||||
const [reviewResult, setReviewResult] = useState<ProductPlanReviewResult>('passed');
|
||||
const [reviewFailureTypes, setReviewFailureTypes] = useState<Set<ProductPlanReviewFailureType>>(new Set());
|
||||
const [reviewFailureReason, setReviewFailureReason] = useState('');
|
||||
const [showComplete, setShowComplete] = useState(false);
|
||||
|
||||
const plan = plans.find((p) => p.id === planId);
|
||||
@@ -42,6 +71,9 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
const linkedReqs = (plan.linkedRequirementIds || []).map((id) => requirements.find((r) => r.id === id)).filter(Boolean) as { id: string; code: string; title: string }[];
|
||||
const canToggle = canTogglePlanChecklist(plan);
|
||||
const canEditCoverage = canEditPlanRequirementCoverage(plan);
|
||||
const productPlanKind = plan.type === 'product' ? getProductPlanKind(plan) : undefined;
|
||||
const isProductDesignPlan = productPlanKind === 'design';
|
||||
const isProductReviewPlan = productPlanKind === 'review';
|
||||
|
||||
const handleToggleTask = (task: PlanTask) => {
|
||||
if (!canToggle) return;
|
||||
@@ -66,11 +98,49 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
reader.readAsDataURL(file);
|
||||
};
|
||||
|
||||
const toggleFailureType = (type: ProductPlanReviewFailureType) => {
|
||||
const next = new Set(reviewFailureTypes);
|
||||
if (next.has(type)) next.delete(type);
|
||||
else next.add(type);
|
||||
setReviewFailureTypes(next);
|
||||
};
|
||||
|
||||
const handleSubmitResult = () => {
|
||||
const url = resultType === 'link' ? resultUrl.trim() : fileData;
|
||||
const title = resultTitle.trim();
|
||||
if (!url || !title) return;
|
||||
const response = completePlan(plan.id, { resultType, resultTitle: title, resultUrl: url, resultFileName: fileName || undefined, resultFileData: resultType === 'file' ? fileData : undefined });
|
||||
let payload: PlanResultPayload | null = null;
|
||||
|
||||
if (isProductReviewPlan) {
|
||||
payload = {
|
||||
productPlanKind: 'review',
|
||||
reviewResult,
|
||||
reviewFailureTypes: reviewResult === 'failed' ? Array.from(reviewFailureTypes) : undefined,
|
||||
reviewFailureReason: reviewResult === 'failed' ? reviewFailureReason.trim() : undefined,
|
||||
resultTitle: PRODUCT_PLAN_REVIEW_RESULT_LABEL[reviewResult],
|
||||
};
|
||||
} else if (isProductDesignPlan) {
|
||||
const title = resultTitle.trim();
|
||||
const url = resultUrl.trim();
|
||||
if (!url || !title || !prototypeReviewConfirmed) return;
|
||||
payload = {
|
||||
productPlanKind: 'design',
|
||||
resultType: 'link',
|
||||
resultTitle: title,
|
||||
resultUrl: url,
|
||||
prototypeReviewConfirmed,
|
||||
};
|
||||
} else {
|
||||
const url = resultType === 'link' ? resultUrl.trim() : fileData;
|
||||
const title = resultTitle.trim();
|
||||
if (!url || !title) return;
|
||||
payload = {
|
||||
resultType,
|
||||
resultTitle: title,
|
||||
resultUrl: url,
|
||||
resultFileName: fileName || undefined,
|
||||
resultFileData: resultType === 'file' ? fileData : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const response = completePlan(plan.id, payload);
|
||||
if (response && typeof response === 'object' && 'ok' in response && !response.ok) {
|
||||
alert(response.message || '计划未满足完成条件');
|
||||
return;
|
||||
@@ -98,7 +168,13 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
<div className="flex items-center justify-between px-5 py-4 border-b border-[var(--line)] shrink-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-[10px] font-medium px-2 py-0.5 rounded-full bg-[var(--bg-subtle)] text-[var(--ink-muted)]">{TYPE_LABEL[plan.type]}</span>
|
||||
{plan.type === 'product' && (
|
||||
<span className="text-[10px] font-medium px-2 py-0.5 rounded-full bg-[var(--bg-subtle)] text-[var(--ink-muted)]">{PRODUCT_PLAN_KIND_LABEL[getProductPlanKind(plan)]}</span>
|
||||
)}
|
||||
<span className={`text-[10px] font-medium px-2 py-0.5 rounded-full ${STATUS_STYLE[plan.status]}`}>{STATUS_LABEL[plan.status]}</span>
|
||||
{plan.type === 'product' && plan.reviewResult && (
|
||||
<span className={`text-[10px] font-medium px-2 py-0.5 rounded-full ${plan.reviewResult === 'passed' ? 'bg-emerald-50 text-emerald-600' : 'bg-red-50 text-red-600'}`}>{PRODUCT_PLAN_REVIEW_RESULT_LABEL[plan.reviewResult]}</span>
|
||||
)}
|
||||
</div>
|
||||
<button onClick={onClose} className="p-1 rounded hover:bg-[var(--bg-subtle)] text-[var(--ink-muted)]"><X className="h-4 w-4" /></button>
|
||||
</div>
|
||||
@@ -198,6 +274,20 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{plan.status === 'completed' && plan.type === 'product' && getProductPlanKind(plan) === 'review' && plan.reviewResult && (
|
||||
<div className={`rounded-lg border p-3 ${plan.reviewResult === 'passed' ? 'border-emerald-200 bg-emerald-50' : 'border-red-200 bg-red-50'}`}>
|
||||
<div className={`text-[12px] font-medium ${plan.reviewResult === 'passed' ? 'text-emerald-700' : 'text-red-700'}`}>
|
||||
{PRODUCT_PLAN_REVIEW_RESULT_LABEL[plan.reviewResult]}
|
||||
</div>
|
||||
{plan.reviewResult === 'failed' && (
|
||||
<div className="mt-2 space-y-1 text-[12px] text-red-700">
|
||||
{getFailureLabels(plan.reviewFailureTypes).length > 0 && <div>类型:{getFailureLabels(plan.reviewFailureTypes).join('、')}</div>}
|
||||
{plan.reviewFailureReason && <div>原因:{plan.reviewFailureReason}</div>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{plan.remark && (
|
||||
<div className="rounded-lg bg-[var(--bg-subtle)] p-3">
|
||||
<div className="text-[11px] text-[var(--ink-muted)] mb-1">备注</div>
|
||||
@@ -223,22 +313,90 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
{/* Complete with result */}
|
||||
{showComplete && (
|
||||
<div className="rounded-lg border border-emerald-200 bg-emerald-50 p-3 space-y-2">
|
||||
<div className="text-[11px] font-medium text-emerald-700">提交成果</div>
|
||||
<input value={resultTitle} onChange={(e) => setResultTitle(e.target.value)} placeholder="成果标题(必填,如 v1.0 产品方案)" className="h-8 w-full rounded-lg border border-[var(--line)] px-2 text-[12px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
<div className="flex gap-2">
|
||||
<button onClick={() => setResultType('link')} className={`h-7 px-2.5 rounded text-[11px] font-medium border ${resultType === 'link' ? 'border-[var(--accent)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}><Link2 className="h-3 w-3 inline mr-1" />链接</button>
|
||||
<button onClick={() => setResultType('file')} className={`h-7 px-2.5 rounded text-[11px] font-medium border ${resultType === 'file' ? 'border-[var(--accent)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}><FileUp className="h-3 w-3 inline mr-1" />文件</button>
|
||||
</div>
|
||||
{resultType === 'link' ? (
|
||||
<input value={resultUrl} onChange={(e) => setResultUrl(e.target.value)} placeholder="https://..." className="h-8 w-full rounded-lg border border-[var(--line)] px-2 text-[12px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
<div className="text-[11px] font-medium text-emerald-700">{getSubmitActionLabel(plan)}</div>
|
||||
{isProductReviewPlan ? (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{(['passed', 'failed'] as ProductPlanReviewResult[]).map((result) => (
|
||||
<button
|
||||
key={result}
|
||||
onClick={() => setReviewResult(result)}
|
||||
className={`h-8 rounded-lg border text-[11px] font-medium ${reviewResult === result ? 'border-[var(--accent)] bg-white text-[var(--accent)]' : 'border-[var(--line)] bg-white/70 text-[var(--ink-soft)]'}`}
|
||||
>
|
||||
{PRODUCT_PLAN_REVIEW_RESULT_LABEL[result]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{reviewResult === 'failed' && (
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-1.5">
|
||||
{PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS.map((option) => (
|
||||
<label key={option.value} className="flex min-h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-[var(--line)] bg-white/70 px-2 py-1 text-[11px] text-[var(--ink-soft)]">
|
||||
<input type="checkbox" checked={reviewFailureTypes.has(option.value)} onChange={() => toggleFailureType(option.value)} className="h-3 w-3 shrink-0 rounded" />
|
||||
<span className="leading-4">{option.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<textarea
|
||||
value={reviewFailureReason}
|
||||
onChange={(e) => setReviewFailureReason(e.target.value)}
|
||||
rows={3}
|
||||
placeholder="写清楚具体问题、影响范围和建议调整方向"
|
||||
className="w-full rounded-lg border border-[var(--line)] bg-white px-2 py-2 text-[12px] focus:border-[var(--accent)] focus:outline-none resize-none"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<input type="file" onChange={handleFile} className="text-[11px] text-[var(--ink-soft)]" />
|
||||
{fileName && <p className="text-[10px] text-[var(--ink-muted)] mt-1">{fileName}</p>}
|
||||
</div>
|
||||
<>
|
||||
{isProductDesignPlan && (
|
||||
<div className="rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-[11px] leading-5 text-amber-800">
|
||||
请确认产品方案评审已通过后再提交原型地址;这里不再上传 Axure 文件。
|
||||
</div>
|
||||
)}
|
||||
<input value={resultTitle} onChange={(e) => setResultTitle(e.target.value)} placeholder={isProductDesignPlan ? '成果标题(如 v1.0 原型地址)' : '成果标题(必填,如 v1.0 产品方案)'} className="h-8 w-full rounded-lg border border-[var(--line)] px-2 text-[12px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
{!isProductDesignPlan && (
|
||||
<div className="flex gap-2">
|
||||
<button onClick={() => setResultType('link')} className={`h-7 px-2.5 rounded text-[11px] font-medium border ${resultType === 'link' ? 'border-[var(--accent)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}><Link2 className="h-3 w-3 inline mr-1" />链接</button>
|
||||
<button onClick={() => setResultType('file')} className={`h-7 px-2.5 rounded text-[11px] font-medium border ${resultType === 'file' ? 'border-[var(--accent)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}><FileUp className="h-3 w-3 inline mr-1" />文件</button>
|
||||
</div>
|
||||
)}
|
||||
{resultType === 'link' || isProductDesignPlan ? (
|
||||
<input value={resultUrl} onChange={(e) => setResultUrl(e.target.value)} placeholder="https://..." className="h-8 w-full rounded-lg border border-[var(--line)] px-2 text-[12px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
) : (
|
||||
<div>
|
||||
<input type="file" onChange={handleFile} className="text-[11px] text-[var(--ink-soft)]" />
|
||||
{fileName && <p className="text-[10px] text-[var(--ink-muted)] mt-1">{fileName}</p>}
|
||||
</div>
|
||||
)}
|
||||
{isProductDesignPlan && (
|
||||
<label className="flex items-start gap-2 rounded-lg border border-[var(--line)] bg-white/70 px-3 py-2 text-[11px] text-[var(--ink-soft)]">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={prototypeReviewConfirmed}
|
||||
onChange={(e) => setPrototypeReviewConfirmed(e.target.checked)}
|
||||
className="mt-0.5 h-3.5 w-3.5 rounded"
|
||||
/>
|
||||
<span>已确认该产品设计方案评审通过,可以作为后续开发任务和测试用例拆解依据。</span>
|
||||
</label>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
<button onClick={handleSubmitResult} disabled={!completionState.canSubmitResult || !resultTitle.trim() || (resultType === 'link' ? !resultUrl.trim() : !fileData)} className="h-7 px-3 rounded text-[11px] font-medium bg-emerald-500 text-white disabled:opacity-50">确认提交</button>
|
||||
<button
|
||||
onClick={handleSubmitResult}
|
||||
disabled={
|
||||
!completionState.canSubmitResult
|
||||
|| (isProductReviewPlan
|
||||
? reviewResult === 'failed' && (reviewFailureTypes.size === 0 || !reviewFailureReason.trim())
|
||||
: isProductDesignPlan
|
||||
? !resultTitle.trim() || !resultUrl.trim() || !prototypeReviewConfirmed
|
||||
: !resultTitle.trim() || (resultType === 'link' ? !resultUrl.trim() : !fileData))
|
||||
}
|
||||
className="h-7 px-3 rounded text-[11px] font-medium bg-emerald-500 text-white disabled:opacity-50"
|
||||
>
|
||||
确认提交
|
||||
</button>
|
||||
<button onClick={() => setShowComplete(false)} className="h-7 px-2 text-[11px] text-[var(--ink-muted)]">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -256,7 +414,7 @@ export function PlanDetailDrawer({ planId, onClose, contextLabel }: Props) {
|
||||
)}
|
||||
{plan.status === 'in_progress' && (
|
||||
<button onClick={() => setShowComplete(true)} disabled={!completionState.canSubmitResult} className="h-8 px-3 rounded-lg text-[12px] font-medium text-emerald-600 border border-emerald-200 hover:bg-emerald-50 disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
提交完成
|
||||
{getSubmitActionLabel(plan)}
|
||||
</button>
|
||||
)}
|
||||
<button onClick={() => setShowTransfer(true)} className="h-8 px-3 rounded-lg text-[12px] font-medium text-[var(--ink-soft)] border border-[var(--line)] hover:bg-[var(--bg-subtle)] flex items-center gap-1">
|
||||
|
||||
@@ -2,8 +2,17 @@
|
||||
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Plus, Pencil, Trash2, X, Check, ExternalLink, FileUp, Link2, Play, ArrowRightLeft } from 'lucide-react';
|
||||
import type { VersionPlan, PlanTask } from '@/lib/version-plan';
|
||||
import { calcPlanDuration, formatDuration, calcTotalDuration, calcPlanProgress, calcLinkedReqProgress } from '@/lib/version-plan';
|
||||
import type { ProductPlanKind, ProductPlanReviewFailureType, ProductPlanReviewResult, VersionPlan, PlanTask } from '@/lib/version-plan';
|
||||
import {
|
||||
calcPlanDuration,
|
||||
formatDuration,
|
||||
calcTotalDuration,
|
||||
calcPlanProgress,
|
||||
calcLinkedReqProgress,
|
||||
PRODUCT_PLAN_KIND_LABEL,
|
||||
PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS,
|
||||
PRODUCT_PLAN_REVIEW_RESULT_LABEL,
|
||||
} from '@/lib/version-plan';
|
||||
import { formatDateTime } from '@/lib/format';
|
||||
import { FieldError } from '@/components/FieldError';
|
||||
import { AiDecomposeButton } from './AiDecomposeButton';
|
||||
@@ -11,6 +20,7 @@ import type { VersionWithContext } from '@/lib/derive';
|
||||
import type { Requirement } from '@/lib/requirement';
|
||||
import { mergeSelectedRequirementOptions } from '@/lib/requirement-selector';
|
||||
import { canEditPlanRequirementCoverage, canTogglePlanChecklist, getPlanCompletionState } from '@/lib/version-plan-workflow';
|
||||
import type { PlanResultPayload } from '@/lib/version-plan-workflow';
|
||||
|
||||
interface Props {
|
||||
plans: VersionPlan[];
|
||||
@@ -24,7 +34,7 @@ interface Props {
|
||||
allRequirements?: Requirement[];
|
||||
onCreate: (data: Omit<VersionPlan, 'id' | 'createdAt'>) => void;
|
||||
onUpdate: (id: string, data: Partial<VersionPlan>) => void;
|
||||
onComplete: (id: string, result: { resultType: 'link' | 'file'; resultTitle: string; resultUrl?: string; resultFileName?: string; resultFileData?: string }) => { ok: boolean; message?: string } | void;
|
||||
onComplete: (id: string, result: PlanResultPayload) => { ok: boolean; message?: string } | void;
|
||||
onDelete: (id: string) => void;
|
||||
}
|
||||
|
||||
@@ -36,6 +46,24 @@ const STATUS_STYLE = {
|
||||
};
|
||||
const STATUS_LABEL = { pending: '未开始', in_progress: '进行中', completed: '已完成' };
|
||||
|
||||
function getProductPlanKind(plan: VersionPlan): ProductPlanKind {
|
||||
return plan.productPlanKind ?? 'design';
|
||||
}
|
||||
|
||||
function getSubmitActionLabel(plan: VersionPlan): string {
|
||||
if (plan.type === 'product') {
|
||||
return getProductPlanKind(plan) === 'review' ? '提交评审结论' : '提交原型地址';
|
||||
}
|
||||
return '提交成果';
|
||||
}
|
||||
|
||||
function getFailureLabels(types?: ProductPlanReviewFailureType[]): string[] {
|
||||
if (!types?.length) return [];
|
||||
return types
|
||||
.map((type) => PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS.find((option) => option.value === type)?.label)
|
||||
.filter(Boolean) as string[];
|
||||
}
|
||||
|
||||
export function PlanTab({ plans, versionId, version, versionDeadline, currentUserName, planType, versionMembers, linkedRequirements, allRequirements, onCreate, onUpdate, onComplete, onDelete }: Props) {
|
||||
const [showCreateModal, setShowCreateModal] = useState(false);
|
||||
const [editingPlan, setEditingPlan] = useState<VersionPlan | null>(null);
|
||||
@@ -96,6 +124,16 @@ export function PlanTab({ plans, versionId, version, versionDeadline, currentUse
|
||||
<span className={`inline-flex items-center rounded-md px-2 py-0.5 text-[10px] font-medium border ${STATUS_STYLE[effectiveStatus]}`}>
|
||||
{STATUS_LABEL[effectiveStatus]}
|
||||
</span>
|
||||
{plan.type === 'product' && (
|
||||
<span className="inline-flex items-center rounded-md border border-[var(--line)] bg-[var(--bg-subtle)] px-2 py-0.5 text-[10px] font-medium text-[var(--ink-muted)]">
|
||||
{PRODUCT_PLAN_KIND_LABEL[getProductPlanKind(plan)]}
|
||||
</span>
|
||||
)}
|
||||
{plan.type === 'product' && plan.reviewResult && (
|
||||
<span className={`inline-flex items-center rounded-md px-2 py-0.5 text-[10px] font-medium ${plan.reviewResult === 'passed' ? 'bg-emerald-50 text-emerald-700' : 'bg-red-50 text-red-700'}`}>
|
||||
{PRODUCT_PLAN_REVIEW_RESULT_LABEL[plan.reviewResult]}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-[12px] text-[var(--ink-soft)]">
|
||||
<span>计划:{formatDateTime(plan.startTime)} → {formatDateTime(plan.endTime)}</span>
|
||||
@@ -120,6 +158,19 @@ export function PlanTab({ plans, versionId, version, versionDeadline, currentUse
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{plan.status === 'completed' && plan.type === 'product' && getProductPlanKind(plan) === 'review' && plan.reviewResult && (
|
||||
<div className={`mt-2 rounded-lg border px-3 py-2 ${plan.reviewResult === 'passed' ? 'border-emerald-200 bg-emerald-50' : 'border-red-200 bg-red-50'}`}>
|
||||
<div className={`text-[12px] font-medium ${plan.reviewResult === 'passed' ? 'text-emerald-700' : 'text-red-700'}`}>
|
||||
{PRODUCT_PLAN_REVIEW_RESULT_LABEL[plan.reviewResult]}
|
||||
</div>
|
||||
{plan.reviewResult === 'failed' && (
|
||||
<div className="mt-1 space-y-1 text-[11px] text-red-700">
|
||||
{getFailureLabels(plan.reviewFailureTypes).length > 0 && <div>类型:{getFailureLabels(plan.reviewFailureTypes).join('、')}</div>}
|
||||
{plan.reviewFailureReason && <div>原因:{plan.reviewFailureReason}</div>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{/* 子任务 */}
|
||||
{plan.type === 'research' && plan.tasks && plan.tasks.length > 0 && (
|
||||
<div className="mt-3 space-y-2">
|
||||
@@ -226,8 +277,8 @@ export function PlanTab({ plans, versionId, version, versionDeadline, currentUse
|
||||
)}
|
||||
{plan.status !== 'completed' && completionState.canSubmitResult && (
|
||||
<div className="mt-3 rounded-lg bg-green-50 border border-green-200 px-3 py-2 flex items-center justify-between">
|
||||
<span className="text-[12px] text-green-700">已满足提交成果条件</span>
|
||||
<button onClick={() => setCompletingPlan(plan)} className="text-[11px] font-medium text-green-700 hover:text-green-900 underline">提交成果</button>
|
||||
<span className="text-[12px] text-green-700">已满足{getSubmitActionLabel(plan)}条件</span>
|
||||
<button onClick={() => setCompletingPlan(plan)} className="text-[11px] font-medium text-green-700 hover:text-green-900 underline">{getSubmitActionLabel(plan)}</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -257,6 +308,7 @@ export function PlanTab({ plans, versionId, version, versionDeadline, currentUse
|
||||
|
||||
{completingPlan && (
|
||||
<CompleteModal
|
||||
plan={completingPlan}
|
||||
onClose={() => setCompletingPlan(null)}
|
||||
onSubmit={(result) => {
|
||||
const response = onComplete(completingPlan.id, result);
|
||||
@@ -289,6 +341,7 @@ function PlanFormModal({ initial, planType, versionId, versionDeadline, currentU
|
||||
const [startTime, setStartTime] = useState(initial?.startTime?.slice(0, 16) ?? now);
|
||||
const [endTime, setEndTime] = useState(initial?.endTime?.slice(0, 16) ?? '');
|
||||
const [remark, setRemark] = useState(initial?.remark ?? '');
|
||||
const [productPlanKind, setProductPlanKind] = useState<ProductPlanKind>(initial?.productPlanKind ?? 'design');
|
||||
const [tasks, setTasks] = useState<PlanTask[]>(initial?.tasks ?? []);
|
||||
const [newTaskTitle, setNewTaskTitle] = useState('');
|
||||
const [overdueReason, setOverdueReason] = useState(initial?.overdueReason ?? '');
|
||||
@@ -318,6 +371,7 @@ function PlanFormModal({ initial, planType, versionId, versionDeadline, currentU
|
||||
startTime,
|
||||
endTime,
|
||||
status: initial?.status ?? 'pending',
|
||||
productPlanKind: planType === 'product' ? productPlanKind : undefined,
|
||||
linkedRequirementIds: requirementOptions.length > 0 ? Array.from(selectedReqs) : undefined,
|
||||
tasks: planType === 'research' && tasks.length > 0 ? tasks : undefined,
|
||||
remark: remark.trim() || undefined,
|
||||
@@ -342,6 +396,34 @@ function PlanFormModal({ initial, planType, versionId, versionDeadline, currentU
|
||||
<label className="text-[12px] font-medium text-[var(--ink-soft)] mb-1 block">负责人</label>
|
||||
<input value={owner} readOnly className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg-subtle)] px-3 text-[13px] text-[var(--ink-muted)] cursor-not-allowed" />
|
||||
</div>
|
||||
{planType === 'product' && (
|
||||
<div>
|
||||
<label className="text-[12px] font-medium text-[var(--ink-soft)] mb-1.5 block">方案类型</label>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{(['design', 'review'] as ProductPlanKind[]).map((kind) => (
|
||||
<label
|
||||
key={kind}
|
||||
className={`flex min-h-16 cursor-pointer items-start gap-2 rounded-lg border px-3 py-2 transition-colors ${productPlanKind === kind ? 'border-[var(--accent)] bg-[var(--accent-soft)]' : 'border-[var(--line)] bg-[var(--bg-card)] hover:bg-[var(--bg-subtle)]'}`}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="productPlanKind"
|
||||
value={kind}
|
||||
checked={productPlanKind === kind}
|
||||
onChange={() => setProductPlanKind(kind)}
|
||||
className="mt-0.5 h-3.5 w-3.5"
|
||||
/>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-[12px] font-medium text-[var(--ink)]">{PRODUCT_PLAN_KIND_LABEL[kind]}</span>
|
||||
<span className="mt-0.5 block text-[11px] leading-4 text-[var(--ink-muted)]">
|
||||
{kind === 'design' ? '提交最终原型链接,用于后续 AI 拆解。' : '记录方案是否通过评审,不通过时沉淀原因类型。'}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="text-[12px] font-medium text-[var(--ink-soft)] mb-1 block">计划开始时间</label>
|
||||
@@ -461,15 +543,24 @@ function PlanFormModal({ initial, planType, versionId, versionDeadline, currentU
|
||||
);
|
||||
}
|
||||
|
||||
function CompleteModal({ onClose, onSubmit }: {
|
||||
function CompleteModal({ plan, onClose, onSubmit }: {
|
||||
plan: VersionPlan;
|
||||
onClose: () => void;
|
||||
onSubmit: (result: { resultType: 'link' | 'file'; resultTitle: string; resultUrl?: string; resultFileName?: string; resultFileData?: string }) => void;
|
||||
onSubmit: (result: PlanResultPayload) => void;
|
||||
}) {
|
||||
const [resultType, setResultType] = useState<'link' | 'file'>('link');
|
||||
const [resultTitle, setResultTitle] = useState('');
|
||||
const [url, setUrl] = useState('');
|
||||
const [fileName, setFileName] = useState('');
|
||||
const [fileData, setFileData] = useState('');
|
||||
const [prototypeReviewConfirmed, setPrototypeReviewConfirmed] = useState(false);
|
||||
const [reviewResult, setReviewResult] = useState<ProductPlanReviewResult>('passed');
|
||||
const [reviewFailureTypes, setReviewFailureTypes] = useState<Set<ProductPlanReviewFailureType>>(new Set());
|
||||
const [reviewFailureReason, setReviewFailureReason] = useState('');
|
||||
|
||||
const productPlanKind = plan.type === 'product' ? getProductPlanKind(plan) : undefined;
|
||||
const isProductDesignPlan = productPlanKind === 'design';
|
||||
const isProductReviewPlan = productPlanKind === 'review';
|
||||
|
||||
const handleFile = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
@@ -480,35 +571,143 @@ function CompleteModal({ onClose, onSubmit }: {
|
||||
reader.readAsDataURL(file);
|
||||
};
|
||||
|
||||
const canSubmit = resultTitle.trim().length > 0 && (resultType === 'link' ? url.trim().length > 0 : fileData.length > 0);
|
||||
const canSubmit = isProductReviewPlan
|
||||
? reviewResult === 'passed' || (reviewFailureTypes.size > 0 && reviewFailureReason.trim().length > 0)
|
||||
: isProductDesignPlan
|
||||
? resultTitle.trim().length > 0 && url.trim().length > 0 && prototypeReviewConfirmed
|
||||
: resultTitle.trim().length > 0 && (resultType === 'link' ? url.trim().length > 0 : fileData.length > 0);
|
||||
|
||||
const toggleFailureType = (type: ProductPlanReviewFailureType) => {
|
||||
const next = new Set(reviewFailureTypes);
|
||||
if (next.has(type)) next.delete(type);
|
||||
else next.add(type);
|
||||
setReviewFailureTypes(next);
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (isProductReviewPlan) {
|
||||
onSubmit({
|
||||
productPlanKind: 'review',
|
||||
reviewResult,
|
||||
reviewFailureTypes: reviewResult === 'failed' ? Array.from(reviewFailureTypes) : undefined,
|
||||
reviewFailureReason: reviewResult === 'failed' ? reviewFailureReason.trim() : undefined,
|
||||
resultTitle: PRODUCT_PLAN_REVIEW_RESULT_LABEL[reviewResult],
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (isProductDesignPlan) {
|
||||
onSubmit({
|
||||
productPlanKind: 'design',
|
||||
resultType: 'link',
|
||||
resultTitle: resultTitle.trim(),
|
||||
resultUrl: url.trim(),
|
||||
prototypeReviewConfirmed,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
onSubmit({
|
||||
resultType,
|
||||
resultTitle: resultTitle.trim(),
|
||||
resultUrl: resultType === 'link' ? url.trim() : fileData,
|
||||
resultFileName: fileName || undefined,
|
||||
resultFileData: resultType === 'file' ? fileData : undefined,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40" onClick={onClose}>
|
||||
<div className="w-full max-w-sm rounded-2xl bg-[var(--bg-card)] border border-[var(--line)] p-5 shadow-[var(--shadow-md)]" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-[13px] font-semibold text-[var(--ink)]">提交成果</h3>
|
||||
<h3 className="text-[13px] font-semibold text-[var(--ink)]">{getSubmitActionLabel(plan)}</h3>
|
||||
<button onClick={onClose} className="p-1 rounded hover:bg-[var(--bg-subtle)] text-[var(--ink-muted)]"><X className="h-4 w-4" /></button>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-medium text-[var(--ink-soft)] mb-1">成果标题<span className="text-red-500 ml-0.5">*</span></label>
|
||||
<input value={resultTitle} onChange={(e) => setResultTitle(e.target.value)} placeholder="如 v1.0 产品方案" className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button type="button" onClick={() => setResultType('link')} className={`h-8 px-3 rounded-lg text-[12px] font-medium border transition-colors ${resultType === 'link' ? 'border-[var(--accent)] bg-[var(--accent-soft)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}>链接</button>
|
||||
<button type="button" onClick={() => setResultType('file')} className={`h-8 px-3 rounded-lg text-[12px] font-medium border transition-colors ${resultType === 'file' ? 'border-[var(--accent)] bg-[var(--accent-soft)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}>文件</button>
|
||||
</div>
|
||||
{resultType === 'link' ? (
|
||||
<input value={url} onChange={(e) => setUrl(e.target.value)} placeholder="https://..." className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
{isProductReviewPlan ? (
|
||||
<>
|
||||
<div>
|
||||
<label className="block text-[11px] font-medium text-[var(--ink-soft)] mb-1">评审结论<span className="text-red-500 ml-0.5">*</span></label>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{(['passed', 'failed'] as ProductPlanReviewResult[]).map((result) => (
|
||||
<button
|
||||
key={result}
|
||||
type="button"
|
||||
onClick={() => setReviewResult(result)}
|
||||
className={`h-9 rounded-lg border text-[12px] font-medium transition-colors ${reviewResult === result ? 'border-[var(--accent)] bg-[var(--accent-soft)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)] hover:bg-[var(--bg-subtle)]'}`}
|
||||
>
|
||||
{PRODUCT_PLAN_REVIEW_RESULT_LABEL[result]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{reviewResult === 'failed' && (
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<label className="block text-[11px] font-medium text-[var(--ink-soft)] mb-1">不通过类型<span className="text-red-500 ml-0.5">*</span></label>
|
||||
<div className="grid grid-cols-2 gap-1.5">
|
||||
{PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS.map((option) => (
|
||||
<label key={option.value} className="flex min-h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-[var(--line)] px-2 py-1 text-[11px] text-[var(--ink-soft)] hover:bg-[var(--bg-subtle)]">
|
||||
<input type="checkbox" checked={reviewFailureTypes.has(option.value)} onChange={() => toggleFailureType(option.value)} className="h-3 w-3 shrink-0 rounded" />
|
||||
<span className="leading-4">{option.label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-medium text-[var(--ink-soft)] mb-1">原因说明<span className="text-red-500 ml-0.5">*</span></label>
|
||||
<textarea
|
||||
value={reviewFailureReason}
|
||||
onChange={(e) => setReviewFailureReason(e.target.value)}
|
||||
rows={3}
|
||||
placeholder="写清楚具体问题、影响范围和建议调整方向"
|
||||
className="w-full rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 py-2 text-[13px] focus:border-[var(--accent)] focus:outline-none resize-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div>
|
||||
<input type="file" onChange={handleFile} className="text-[12px] text-[var(--ink-soft)]" />
|
||||
{fileName && <p className="text-[11px] text-[var(--ink-muted)] mt-1">已选:{fileName}</p>}
|
||||
</div>
|
||||
<>
|
||||
{isProductDesignPlan && (
|
||||
<div className="rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-[11px] leading-5 text-amber-800">
|
||||
请确认产品方案评审已通过后再提交原型地址;这里不再上传 Axure 文件,AI 后续会优先读取可访问的原型链接。
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label className="block text-[11px] font-medium text-[var(--ink-soft)] mb-1">成果标题<span className="text-red-500 ml-0.5">*</span></label>
|
||||
<input value={resultTitle} onChange={(e) => setResultTitle(e.target.value)} placeholder={isProductDesignPlan ? '如 v1.0 原型地址' : '如 v1.0 产品方案'} className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
</div>
|
||||
{!isProductDesignPlan && (
|
||||
<div className="flex gap-2">
|
||||
<button type="button" onClick={() => setResultType('link')} className={`h-8 px-3 rounded-lg text-[12px] font-medium border transition-colors ${resultType === 'link' ? 'border-[var(--accent)] bg-[var(--accent-soft)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}>链接</button>
|
||||
<button type="button" onClick={() => setResultType('file')} className={`h-8 px-3 rounded-lg text-[12px] font-medium border transition-colors ${resultType === 'file' ? 'border-[var(--accent)] bg-[var(--accent-soft)] text-[var(--accent)]' : 'border-[var(--line)] text-[var(--ink-soft)]'}`}>文件</button>
|
||||
</div>
|
||||
)}
|
||||
{resultType === 'link' || isProductDesignPlan ? (
|
||||
<input value={url} onChange={(e) => setUrl(e.target.value)} placeholder="https://..." className="h-9 w-full rounded-lg border border-[var(--line)] bg-[var(--bg-card)] px-3 text-[13px] focus:border-[var(--accent)] focus:outline-none" />
|
||||
) : (
|
||||
<div>
|
||||
<input type="file" onChange={handleFile} className="text-[12px] text-[var(--ink-soft)]" />
|
||||
{fileName && <p className="text-[11px] text-[var(--ink-muted)] mt-1">已选:{fileName}</p>}
|
||||
</div>
|
||||
)}
|
||||
{isProductDesignPlan && (
|
||||
<label className="flex items-start gap-2 rounded-lg border border-[var(--line)] bg-[var(--bg-subtle)] px-3 py-2 text-[12px] text-[var(--ink-soft)]">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={prototypeReviewConfirmed}
|
||||
onChange={(e) => setPrototypeReviewConfirmed(e.target.checked)}
|
||||
className="mt-0.5 h-3.5 w-3.5 rounded"
|
||||
/>
|
||||
<span>已确认该产品设计方案评审通过,可以作为后续开发任务和测试用例拆解依据。</span>
|
||||
</label>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<div className="flex justify-end gap-2 pt-2">
|
||||
<button onClick={onClose} className="h-8 px-3 rounded-lg text-[12px] font-medium border border-[var(--line)] text-[var(--ink-soft)] hover:bg-[var(--bg-subtle)]">取消</button>
|
||||
<button onClick={() => onSubmit({ resultType, resultTitle: resultTitle.trim(), resultUrl: resultType === 'link' ? url.trim() : fileData, resultFileName: fileName || undefined, resultFileData: resultType === 'file' ? fileData : undefined })} disabled={!canSubmit} className="h-8 px-4 rounded-lg text-[12px] font-medium bg-[var(--accent)] text-white hover:bg-[var(--accent-hover)] disabled:opacity-50">确认</button>
|
||||
<button onClick={handleSubmit} disabled={!canSubmit} className="h-8 px-4 rounded-lg text-[12px] font-medium bg-[var(--accent)] text-white hover:bg-[var(--accent-hover)] disabled:opacity-50">确认</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
138
apps/web/lib/ai-decompose-dedupe.test.ts
Normal file
138
apps/web/lib/ai-decompose-dedupe.test.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { filterDuplicateDecomposeDrafts } from './ai-decompose-dedupe';
|
||||
import type { AgentDecomposeResult } from '@ftb/shared';
|
||||
import type { DevTask } from './dev-task';
|
||||
import type { TestCase } from './test-case';
|
||||
import type { TaskCategory } from './task-category';
|
||||
|
||||
const categories: TaskCategory[] = [
|
||||
{
|
||||
id: 'cat-frontend',
|
||||
code: 'frontend_interaction',
|
||||
name: '前端交互',
|
||||
group: 'development',
|
||||
sortOrder: 1,
|
||||
isSystem: true,
|
||||
},
|
||||
{
|
||||
id: 'cat-test-functional',
|
||||
code: 'test_functional',
|
||||
name: '功能测试',
|
||||
group: 'testing',
|
||||
sortOrder: 2,
|
||||
isSystem: true,
|
||||
},
|
||||
];
|
||||
|
||||
const requirements = [{ id: 'req-1', code: 'REQ001' }];
|
||||
|
||||
function makeResult(patch: Partial<AgentDecomposeResult>): AgentDecomposeResult {
|
||||
return {
|
||||
report: { matched: [], reqOnly: [], noteOnly: [], ambiguous: [] },
|
||||
devTaskDrafts: [],
|
||||
testCaseDrafts: [],
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
test('filters dev task drafts already adopted into existing tasks', () => {
|
||||
const existingDevTasks = [
|
||||
{
|
||||
id: 'task-1',
|
||||
title: '实现拖拽排序',
|
||||
categoryId: 'cat-frontend',
|
||||
references: [
|
||||
{ type: 'requirement', id: 'req-1', label: 'REQ001 拖拽排序' },
|
||||
{ type: 'prototype_note', id: 'QY0001', label: 'QY0001' },
|
||||
],
|
||||
},
|
||||
] as DevTask[];
|
||||
|
||||
const result = filterDuplicateDecomposeDrafts(
|
||||
makeResult({
|
||||
devTaskDrafts: [
|
||||
{
|
||||
title: '实现拖拽排序',
|
||||
categoryCode: 'frontend_interaction',
|
||||
priority: 'P2',
|
||||
aiEstimateHours: 0.25,
|
||||
references: [
|
||||
{ type: 'requirement', id: 'REQ001', label: 'REQ001 拖拽排序' },
|
||||
{ type: 'prototype_note', id: 'QY0001', label: 'QY0001' },
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ existingDevTasks, existingTestCases: [], categories, requirements },
|
||||
);
|
||||
|
||||
assert.equal(result.removedDevTaskCount, 1);
|
||||
assert.equal(result.result.devTaskDrafts.length, 0);
|
||||
});
|
||||
|
||||
test('filters test case drafts already adopted into existing test cases', () => {
|
||||
const existingTestCases = [
|
||||
{
|
||||
id: 'tc-1',
|
||||
title: '验证拖拽排序成功',
|
||||
categoryId: 'cat-test-functional',
|
||||
references: [
|
||||
{ type: 'requirement', id: 'req-1', label: 'REQ001 拖拽排序' },
|
||||
{ type: 'prototype_note', id: 'QY0001', label: 'QY0001' },
|
||||
],
|
||||
},
|
||||
] as TestCase[];
|
||||
|
||||
const result = filterDuplicateDecomposeDrafts(
|
||||
makeResult({
|
||||
testCaseDrafts: [
|
||||
{
|
||||
title: '验证拖拽排序成功',
|
||||
description: '拖拽后顺序保存',
|
||||
categoryCode: 'test_functional',
|
||||
priority: 'P2',
|
||||
aiEstimateHours: 0.2,
|
||||
references: [
|
||||
{ type: 'requirement', id: 'REQ001', label: 'REQ001 拖拽排序' },
|
||||
{ type: 'prototype_note', id: 'QY0001', label: 'QY0001' },
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ existingDevTasks: [], existingTestCases, categories, requirements },
|
||||
);
|
||||
|
||||
assert.equal(result.removedTestCaseCount, 1);
|
||||
assert.equal(result.result.testCaseDrafts.length, 0);
|
||||
});
|
||||
|
||||
test('keeps drafts with same references but different normalized title', () => {
|
||||
const existingDevTasks = [
|
||||
{
|
||||
id: 'task-1',
|
||||
title: '实现拖拽排序',
|
||||
categoryId: 'cat-frontend',
|
||||
references: [{ type: 'prototype_note', id: 'QY0001', label: 'QY0001' }],
|
||||
},
|
||||
] as DevTask[];
|
||||
|
||||
const result = filterDuplicateDecomposeDrafts(
|
||||
makeResult({
|
||||
devTaskDrafts: [
|
||||
{
|
||||
title: '保存拖拽排序结果',
|
||||
categoryCode: 'frontend_interaction',
|
||||
priority: 'P2',
|
||||
aiEstimateHours: 0.5,
|
||||
references: [{ type: 'prototype_note', id: 'QY0001', label: 'QY0001' }],
|
||||
},
|
||||
],
|
||||
}),
|
||||
{ existingDevTasks, existingTestCases: [], categories, requirements },
|
||||
);
|
||||
|
||||
assert.equal(result.removedDevTaskCount, 0);
|
||||
assert.equal(result.result.devTaskDrafts.length, 1);
|
||||
});
|
||||
125
apps/web/lib/ai-decompose-dedupe.ts
Normal file
125
apps/web/lib/ai-decompose-dedupe.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import type {
|
||||
AgentDecomposeResult,
|
||||
AgentDevTaskDraft,
|
||||
AgentReference,
|
||||
AgentTestCaseDraft,
|
||||
} from '@ftb/shared';
|
||||
import type { DevTask, Reference } from './dev-task';
|
||||
import type { TestCase } from './test-case';
|
||||
import type { TaskCategory } from './task-category';
|
||||
|
||||
interface RequirementIdentity {
|
||||
id: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface DecomposeDedupeInput {
|
||||
existingDevTasks: DevTask[];
|
||||
existingTestCases: TestCase[];
|
||||
categories: TaskCategory[];
|
||||
requirements: RequirementIdentity[];
|
||||
}
|
||||
|
||||
export interface DecomposeDedupeResult {
|
||||
result: AgentDecomposeResult;
|
||||
removedDevTaskCount: number;
|
||||
removedTestCaseCount: number;
|
||||
}
|
||||
|
||||
export function filterDuplicateDecomposeDrafts(
|
||||
result: AgentDecomposeResult,
|
||||
input: DecomposeDedupeInput,
|
||||
): DecomposeDedupeResult {
|
||||
const devFingerprints = new Set(
|
||||
input.existingDevTasks
|
||||
.map((task) => existingItemFingerprint(task.title, task.categoryId, task.references ?? [], input))
|
||||
.filter(Boolean),
|
||||
);
|
||||
const testCaseFingerprints = new Set(
|
||||
input.existingTestCases
|
||||
.map((testCase) => existingItemFingerprint(testCase.title, testCase.categoryId, testCase.references ?? [], input))
|
||||
.filter(Boolean),
|
||||
);
|
||||
|
||||
const filteredDevTaskDrafts = filterDrafts(result.devTaskDrafts, devFingerprints, input, draftFingerprint);
|
||||
const filteredTestCaseDrafts = filterDrafts(result.testCaseDrafts, testCaseFingerprints, input, draftFingerprint);
|
||||
|
||||
return {
|
||||
result: {
|
||||
...result,
|
||||
devTaskDrafts: filteredDevTaskDrafts.items,
|
||||
testCaseDrafts: filteredTestCaseDrafts.items,
|
||||
},
|
||||
removedDevTaskCount: result.devTaskDrafts.length - filteredDevTaskDrafts.items.length,
|
||||
removedTestCaseCount: result.testCaseDrafts.length - filteredTestCaseDrafts.items.length,
|
||||
};
|
||||
}
|
||||
|
||||
function filterDrafts<T extends AgentDevTaskDraft | AgentTestCaseDraft>(
|
||||
drafts: T[],
|
||||
existingFingerprints: Set<string>,
|
||||
input: DecomposeDedupeInput,
|
||||
getFingerprint: (draft: T, input: DecomposeDedupeInput) => string,
|
||||
): { items: T[] } {
|
||||
const seen = new Set<string>();
|
||||
const items: T[] = [];
|
||||
for (const draft of drafts) {
|
||||
const fingerprint = getFingerprint(draft, input);
|
||||
if (existingFingerprints.has(fingerprint) || seen.has(fingerprint)) continue;
|
||||
seen.add(fingerprint);
|
||||
items.push(draft);
|
||||
}
|
||||
return { items };
|
||||
}
|
||||
|
||||
function draftFingerprint(
|
||||
draft: AgentDevTaskDraft | AgentTestCaseDraft,
|
||||
input: DecomposeDedupeInput,
|
||||
): string {
|
||||
return buildFingerprint(draft.title, draft.categoryCode, draft.references, input);
|
||||
}
|
||||
|
||||
function existingItemFingerprint(
|
||||
title: string,
|
||||
categoryId: string,
|
||||
references: Reference[],
|
||||
input: DecomposeDedupeInput,
|
||||
): string {
|
||||
const categoryCode = input.categories.find((category) => category.id === categoryId)?.code ?? categoryId;
|
||||
return buildFingerprint(title, categoryCode, references, input);
|
||||
}
|
||||
|
||||
function buildFingerprint(
|
||||
title: string,
|
||||
categoryCode: string,
|
||||
references: Array<AgentReference | Reference>,
|
||||
input: DecomposeDedupeInput,
|
||||
): string {
|
||||
const refKey = references
|
||||
.map((ref) => normalizeReferenceKey(ref, input.requirements))
|
||||
.filter(Boolean)
|
||||
.sort()
|
||||
.join('|');
|
||||
return `${categoryCode}::${normalizeTitle(title)}::${refKey}`;
|
||||
}
|
||||
|
||||
function normalizeTitle(title: string): string {
|
||||
return title
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[\s::,,.。;;、\-—_]/g, '');
|
||||
}
|
||||
|
||||
function normalizeReferenceKey(
|
||||
ref: AgentReference | Reference,
|
||||
requirements: RequirementIdentity[],
|
||||
): string {
|
||||
const rawId = String(ref.id || '').trim();
|
||||
if (!rawId) return '';
|
||||
if (ref.type === 'requirement') {
|
||||
const matched = requirements.find((requirement) => requirement.id === rawId || requirement.code === rawId);
|
||||
return `requirement:${matched?.id ?? rawId}`;
|
||||
}
|
||||
return `${ref.type}:${rawId.toLowerCase()}`;
|
||||
}
|
||||
|
||||
32
apps/web/lib/ai-decompose-report.test.ts
Normal file
32
apps/web/lib/ai-decompose-report.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { formatReportRequirementLabel } from './ai-decompose-report';
|
||||
|
||||
const requirements = [
|
||||
{
|
||||
id: 'rea-17823017283970',
|
||||
code: 'REQ0010',
|
||||
title: '支持主题拖拽排序',
|
||||
description: '用户可以调整主题顺序',
|
||||
},
|
||||
];
|
||||
|
||||
test('formatReportRequirementLabel resolves internal requirement id to code and title', () => {
|
||||
assert.equal(
|
||||
formatReportRequirementLabel('rea-17823017283970', requirements),
|
||||
'REQ0010 支持主题拖拽排序',
|
||||
);
|
||||
});
|
||||
|
||||
test('formatReportRequirementLabel resolves requirement code to code and title', () => {
|
||||
assert.equal(
|
||||
formatReportRequirementLabel('REQ0010', requirements),
|
||||
'REQ0010 支持主题拖拽排序',
|
||||
);
|
||||
});
|
||||
|
||||
test('formatReportRequirementLabel falls back to raw id when requirement is unknown', () => {
|
||||
assert.equal(formatReportRequirementLabel('rea-missing', requirements), 'rea-missing');
|
||||
});
|
||||
|
||||
13
apps/web/lib/ai-decompose-report.ts
Normal file
13
apps/web/lib/ai-decompose-report.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface ReportRequirement {
|
||||
id: string;
|
||||
code: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export function formatReportRequirementLabel(reqId: string, requirements: ReportRequirement[]): string {
|
||||
const requirement = requirements.find((item) => item.id === reqId || item.code === reqId);
|
||||
if (!requirement) return reqId;
|
||||
return `${requirement.code} ${requirement.title}`;
|
||||
}
|
||||
|
||||
@@ -2,24 +2,25 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import {
|
||||
clampDevEstimateHours,
|
||||
clampTestCaseEstimateHours,
|
||||
getDefaultTestCaseEstimateHours,
|
||||
clampDevAiEstimateHours,
|
||||
clampTestCaseAiEstimateHours,
|
||||
getDefaultTestCaseAiEstimateHours,
|
||||
} from './ai-estimation-policy';
|
||||
|
||||
test('clamps simple frontend interaction to AI-assisted range', () => {
|
||||
assert.equal(clampDevEstimateHours('frontend_interaction', 5), 1);
|
||||
assert.equal(clampDevEstimateHours('frontend_interaction', 0.1), 0.5);
|
||||
assert.equal(clampDevAiEstimateHours('frontend_interaction', 5), 0.5);
|
||||
assert.equal(clampDevAiEstimateHours('frontend_interaction', 0.1), 0.25);
|
||||
});
|
||||
|
||||
test('keeps backend API within strict range', () => {
|
||||
assert.equal(clampDevEstimateHours('backend_api', 0.25), 0.75);
|
||||
assert.equal(clampDevEstimateHours('backend_api', 2), 1.5);
|
||||
assert.equal(clampDevAiEstimateHours('backend_api', 0.25), 0.5);
|
||||
assert.equal(clampDevAiEstimateHours('backend_api', 2), 1);
|
||||
});
|
||||
|
||||
test('defaults and clamps test case estimates', () => {
|
||||
assert.equal(getDefaultTestCaseEstimateHours('test_functional'), 0.5);
|
||||
assert.equal(clampTestCaseEstimateHours('test_functional', 2), 0.5);
|
||||
assert.equal(clampTestCaseEstimateHours('test_api', 0.25), 0.5);
|
||||
assert.equal(clampTestCaseEstimateHours('test_exception', 2), 1);
|
||||
test('defaults and clamps test case AI estimates below half an hour when appropriate', () => {
|
||||
assert.equal(getDefaultTestCaseAiEstimateHours('test_functional'), 0.2);
|
||||
assert.equal(clampTestCaseAiEstimateHours('test_functional', 2), 0.3);
|
||||
assert.equal(clampTestCaseAiEstimateHours('test_functional', 0.05), 0.1);
|
||||
assert.equal(clampTestCaseAiEstimateHours('test_api', 0.1), 0.2);
|
||||
assert.equal(clampTestCaseAiEstimateHours('test_exception', 2), 0.5);
|
||||
});
|
||||
|
||||
@@ -3,41 +3,58 @@ import type { AgentTaskCategoryCode } from '@ftb/shared';
|
||||
type EstimateRange = { min: number; max: number; fallback: number };
|
||||
|
||||
const DEV_ESTIMATE_RANGES: Record<string, EstimateRange> = {
|
||||
frontend_development: { min: 0.5, max: 1.5, fallback: 1 },
|
||||
frontend_interaction: { min: 0.5, max: 1, fallback: 0.5 },
|
||||
backend_development: { min: 1, max: 3, fallback: 2 },
|
||||
backend_api: { min: 0.75, max: 1.5, fallback: 1 },
|
||||
database_schema: { min: 0.5, max: 0.5, fallback: 0.5 },
|
||||
api_integration: { min: 0.75, max: 1.5, fallback: 1 },
|
||||
data_processing: { min: 1, max: 2, fallback: 1.5 },
|
||||
implementation_support: { min: 0.5, max: 1.5, fallback: 1 },
|
||||
frontend_development: { min: 0.25, max: 1, fallback: 0.5 },
|
||||
frontend_interaction: { min: 0.25, max: 0.5, fallback: 0.25 },
|
||||
backend_development: { min: 0.75, max: 2, fallback: 1.25 },
|
||||
backend_api: { min: 0.5, max: 1, fallback: 0.75 },
|
||||
database_schema: { min: 0.25, max: 0.5, fallback: 0.25 },
|
||||
api_integration: { min: 0.5, max: 1.25, fallback: 0.75 },
|
||||
data_processing: { min: 0.75, max: 1.5, fallback: 1 },
|
||||
implementation_support: { min: 0.25, max: 1, fallback: 0.5 },
|
||||
documentation: { min: 0.25, max: 0.5, fallback: 0.5 },
|
||||
};
|
||||
|
||||
const TEST_ESTIMATE_RANGES: Record<string, EstimateRange> = {
|
||||
test_functional: { min: 0.25, max: 0.5, fallback: 0.5 },
|
||||
test_api: { min: 0.5, max: 1, fallback: 0.5 },
|
||||
test_exception: { min: 0.5, max: 1, fallback: 0.5 },
|
||||
test_compatibility: { min: 0.5, max: 1, fallback: 1 },
|
||||
test_functional: { min: 0.1, max: 0.3, fallback: 0.2 },
|
||||
test_api: { min: 0.2, max: 0.5, fallback: 0.3 },
|
||||
test_exception: { min: 0.2, max: 0.5, fallback: 0.3 },
|
||||
test_compatibility: { min: 0.3, max: 0.8, fallback: 0.4 },
|
||||
};
|
||||
|
||||
function roundQuarterHour(hours: number): number {
|
||||
return Math.round(hours * 4) / 4;
|
||||
const EXECUTOR_TEST_ESTIMATE_RANGES: Record<string, EstimateRange> = {
|
||||
test_functional: { min: 0.25, max: 2, fallback: 0.5 },
|
||||
test_api: { min: 0.25, max: 2, fallback: 0.5 },
|
||||
test_exception: { min: 0.25, max: 2, fallback: 0.5 },
|
||||
test_compatibility: { min: 0.25, max: 2, fallback: 0.5 },
|
||||
};
|
||||
|
||||
function roundToStep(hours: number, step: number): number {
|
||||
return Number((Math.round(hours / step) * step).toFixed(2));
|
||||
}
|
||||
|
||||
function clampToRange(raw: number | undefined, range: EstimateRange): number {
|
||||
function clampToRange(raw: number | undefined, range: EstimateRange, step: number): number {
|
||||
const base = typeof raw === 'number' && Number.isFinite(raw) && raw > 0 ? raw : range.fallback;
|
||||
return roundQuarterHour(Math.min(range.max, Math.max(range.min, base)));
|
||||
return roundToStep(Math.min(range.max, Math.max(range.min, base)), step);
|
||||
}
|
||||
|
||||
export function clampDevEstimateHours(code: AgentTaskCategoryCode | string | undefined, raw: number | undefined): number {
|
||||
return clampToRange(raw, DEV_ESTIMATE_RANGES[code ?? ''] ?? { min: 0.5, max: 2, fallback: 1 });
|
||||
export function clampDevAiEstimateHours(code: AgentTaskCategoryCode | string | undefined, raw: number | undefined): number {
|
||||
return clampToRange(raw, DEV_ESTIMATE_RANGES[code ?? ''] ?? { min: 0.25, max: 1.5, fallback: 0.75 }, 0.25);
|
||||
}
|
||||
|
||||
export function getDefaultTestCaseEstimateHours(code: AgentTaskCategoryCode | string | undefined): number {
|
||||
export function getDefaultTestCaseAiEstimateHours(code: AgentTaskCategoryCode | string | undefined): number {
|
||||
return (TEST_ESTIMATE_RANGES[code ?? ''] ?? TEST_ESTIMATE_RANGES.test_functional).fallback;
|
||||
}
|
||||
|
||||
export function clampTestCaseEstimateHours(code: AgentTaskCategoryCode | string | undefined, raw: number | undefined): number {
|
||||
return clampToRange(raw, TEST_ESTIMATE_RANGES[code ?? ''] ?? TEST_ESTIMATE_RANGES.test_functional);
|
||||
export function clampTestCaseAiEstimateHours(code: AgentTaskCategoryCode | string | undefined, raw: number | undefined): number {
|
||||
return clampToRange(raw, TEST_ESTIMATE_RANGES[code ?? ''] ?? TEST_ESTIMATE_RANGES.test_functional, 0.1);
|
||||
}
|
||||
|
||||
export const clampDevEstimateHours = clampDevAiEstimateHours;
|
||||
|
||||
export function getDefaultTestCaseEstimateHours(code: AgentTaskCategoryCode | string | undefined): number {
|
||||
return (EXECUTOR_TEST_ESTIMATE_RANGES[code ?? ''] ?? EXECUTOR_TEST_ESTIMATE_RANGES.test_functional).fallback;
|
||||
}
|
||||
|
||||
export function clampTestCaseEstimateHours(code: AgentTaskCategoryCode | string | undefined, raw: number | undefined): number {
|
||||
return clampToRange(raw, EXECUTOR_TEST_ESTIMATE_RANGES[code ?? ''] ?? EXECUTOR_TEST_ESTIMATE_RANGES.test_functional, 0.25);
|
||||
}
|
||||
|
||||
52
apps/web/lib/dev-task.test.ts
Normal file
52
apps/web/lib/dev-task.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
import { getEstimateHours, type DevTask } from './dev-task';
|
||||
|
||||
function makeTask(patch: Partial<DevTask>): DevTask {
|
||||
return {
|
||||
id: 'task-1',
|
||||
taskNo: 'DEV-001',
|
||||
requirementId: 'req-1',
|
||||
title: '实现筛选',
|
||||
categoryId: 'cat-frontend',
|
||||
assigneeId: '张三',
|
||||
priority: 'P2',
|
||||
expectedStartAt: '',
|
||||
expectedEndAt: '',
|
||||
status: 'todo',
|
||||
isBlocked: false,
|
||||
createdBy: 'tester',
|
||||
createdAt: '2026-06-26T01:00:00.000Z',
|
||||
updatedAt: '2026-06-26T01:00:00.000Z',
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
test('getEstimateHours prefers executor estimate over AI estimate', () => {
|
||||
const task = makeTask({
|
||||
estimateHours: 1.5,
|
||||
aiEstimateHours: 0.5,
|
||||
});
|
||||
|
||||
assert.equal(getEstimateHours(task), 1.5);
|
||||
});
|
||||
|
||||
test('getEstimateHours falls back to AI estimate before schedule-derived estimate', () => {
|
||||
const task = makeTask({
|
||||
aiEstimateHours: 0.25,
|
||||
expectedStartAt: '2026-06-26T01:00:00.000Z',
|
||||
expectedEndAt: '2026-06-26T03:00:00.000Z',
|
||||
});
|
||||
|
||||
assert.equal(getEstimateHours(task), 0.25);
|
||||
});
|
||||
|
||||
test('getEstimateHours uses schedule when no executor or AI estimate exists', () => {
|
||||
const task = makeTask({
|
||||
expectedStartAt: '2026-06-26T01:00:00.000Z',
|
||||
expectedEndAt: '2026-06-26T03:00:00.000Z',
|
||||
});
|
||||
|
||||
assert.equal(getEstimateHours(task), 2);
|
||||
});
|
||||
@@ -26,6 +26,7 @@ export interface DevTask {
|
||||
expectedStartAt: string;
|
||||
expectedEndAt: string;
|
||||
estimateHours?: number;
|
||||
aiEstimateHours?: number;
|
||||
actualStartAt?: string;
|
||||
actualEndAt?: string;
|
||||
|
||||
@@ -98,12 +99,19 @@ export function formatHours(hours: number): string {
|
||||
|
||||
export function getEstimateHours(task: DevTask): number {
|
||||
if (typeof task.estimateHours === 'number' && task.estimateHours > 0) {
|
||||
return Math.round(task.estimateHours * 2) / 2;
|
||||
return roundEffortHours(task.estimateHours);
|
||||
}
|
||||
if (typeof task.aiEstimateHours === 'number' && task.aiEstimateHours > 0) {
|
||||
return roundEffortHours(task.aiEstimateHours);
|
||||
}
|
||||
if (!task.expectedStartAt || !task.expectedEndAt) return 0;
|
||||
return calcWorkHours(task.expectedStartAt, task.expectedEndAt);
|
||||
}
|
||||
|
||||
function roundEffortHours(hours: number): number {
|
||||
return Number(hours.toFixed(2));
|
||||
}
|
||||
|
||||
export function getActualHours(task: DevTask, now: Date = new Date()): number {
|
||||
if (!task.actualStartAt) return 0;
|
||||
const end = task.actualEndAt ?? now.toISOString();
|
||||
|
||||
@@ -43,7 +43,7 @@ test('normalizeTestCase keeps existing categoryId', () => {
|
||||
assert.equal(tc.categoryId, 'cat-test-api');
|
||||
});
|
||||
|
||||
test('normalizeTestCase backfills missing estimateHours', () => {
|
||||
test('normalizeTestCase keeps missing executor estimate empty', () => {
|
||||
const tc = normalizeTestCase({
|
||||
id: 'tc-1',
|
||||
caseNo: 'TC-001',
|
||||
@@ -57,8 +57,45 @@ test('normalizeTestCase backfills missing estimateHours', () => {
|
||||
updatedAt: '2026-06-25',
|
||||
} as any);
|
||||
|
||||
assert.equal(tc.estimateHours, 0.5);
|
||||
assert.equal(getTestCaseEstimateHours(tc), 0.5);
|
||||
assert.equal(tc.estimateHours, undefined);
|
||||
assert.equal(getTestCaseEstimateHours(tc), 0);
|
||||
});
|
||||
|
||||
test('getTestCaseEstimateHours prefers executor estimate over AI estimate', () => {
|
||||
const tc = normalizeTestCase({
|
||||
id: 'tc-1',
|
||||
caseNo: 'TC-001',
|
||||
versionId: 'v1',
|
||||
title: '登录正常',
|
||||
priority: 'P2',
|
||||
status: 'pending',
|
||||
categoryId: 'cat-test-api',
|
||||
estimateHours: 0.7,
|
||||
aiEstimateHours: 0.2,
|
||||
createdBy: 'tester',
|
||||
createdAt: '2026-06-25',
|
||||
updatedAt: '2026-06-25',
|
||||
} as any);
|
||||
|
||||
assert.equal(getTestCaseEstimateHours(tc), 0.7);
|
||||
});
|
||||
|
||||
test('getTestCaseEstimateHours falls back to AI estimate', () => {
|
||||
const tc = normalizeTestCase({
|
||||
id: 'tc-1',
|
||||
caseNo: 'TC-001',
|
||||
versionId: 'v1',
|
||||
title: '登录正常',
|
||||
priority: 'P2',
|
||||
status: 'pending',
|
||||
categoryId: 'cat-test-api',
|
||||
aiEstimateHours: 0.2,
|
||||
createdBy: 'tester',
|
||||
createdAt: '2026-06-25',
|
||||
updatedAt: '2026-06-25',
|
||||
} as any);
|
||||
|
||||
assert.equal(getTestCaseEstimateHours(tc), 0.2);
|
||||
});
|
||||
|
||||
test('test case status labels use waiting and testing wording', () => {
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface TestCase {
|
||||
assigneeId?: string;
|
||||
status: TestCaseStatus;
|
||||
estimateHours?: number;
|
||||
aiEstimateHours?: number;
|
||||
startedAt?: string;
|
||||
completedAt?: string;
|
||||
executedAt?: string;
|
||||
@@ -88,7 +89,8 @@ export function normalizeTestCase(testCase: Partial<TestCase>, index = 0): TestC
|
||||
priority: testCase.priority || 'P2',
|
||||
assigneeId: testCase.assigneeId,
|
||||
status: testCase.status || 'pending',
|
||||
estimateHours: typeof testCase.estimateHours === 'number' && testCase.estimateHours > 0 ? testCase.estimateHours : 0.5,
|
||||
estimateHours: typeof testCase.estimateHours === 'number' && testCase.estimateHours > 0 ? testCase.estimateHours : undefined,
|
||||
aiEstimateHours: typeof testCase.aiEstimateHours === 'number' && testCase.aiEstimateHours > 0 ? testCase.aiEstimateHours : undefined,
|
||||
startedAt: testCase.startedAt,
|
||||
completedAt: testCase.completedAt,
|
||||
executedAt: testCase.executedAt,
|
||||
@@ -125,9 +127,13 @@ export function calcTestProgress(cases: TestCase[]): { total: number; executed:
|
||||
}
|
||||
|
||||
export function getTestCaseEstimateHours(tc: TestCase): number {
|
||||
return typeof tc.estimateHours === 'number' && tc.estimateHours > 0
|
||||
? Math.round(tc.estimateHours * 2) / 2
|
||||
: 0.5;
|
||||
if (typeof tc.estimateHours === 'number' && tc.estimateHours > 0) {
|
||||
return Number(tc.estimateHours.toFixed(2));
|
||||
}
|
||||
if (typeof tc.aiEstimateHours === 'number' && tc.aiEstimateHours > 0) {
|
||||
return Number(tc.aiEstimateHours.toFixed(2));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function getTestCaseActualHours(tc: TestCase, now: Date = new Date()): number {
|
||||
|
||||
@@ -52,6 +52,7 @@ test('allows completion only after result exists', () => {
|
||||
resultType: 'link',
|
||||
resultTitle: '原型',
|
||||
resultUrl: 'https://example.com/prototype',
|
||||
prototypeReviewConfirmed: true,
|
||||
}));
|
||||
assert.equal(state.canComplete, true);
|
||||
});
|
||||
@@ -83,3 +84,61 @@ test('detects link and file result payloads', () => {
|
||||
assert.equal(hasPlanResult({ resultType: 'file', resultTitle: '文件', resultFileName: 'a.pdf', resultFileData: 'data:pdf' }), true);
|
||||
assert.equal(hasPlanResult({ resultType: 'link', resultTitle: '原型' }), false);
|
||||
});
|
||||
|
||||
test('product design plans require a prototype link and review confirmation', () => {
|
||||
const withoutReviewConfirmation = getPlanCompletionState(plan({
|
||||
productPlanKind: 'design',
|
||||
completedRequirementIds: ['r1'],
|
||||
resultType: 'link',
|
||||
resultTitle: 'Prototype',
|
||||
resultUrl: 'https://example.com/prototype',
|
||||
} as Partial<VersionPlan>));
|
||||
assert.equal(withoutReviewConfirmation.canComplete, false);
|
||||
|
||||
const withReviewConfirmation = getPlanCompletionState(plan({
|
||||
productPlanKind: 'design',
|
||||
completedRequirementIds: ['r1'],
|
||||
resultType: 'link',
|
||||
resultTitle: 'Prototype',
|
||||
resultUrl: 'https://example.com/prototype',
|
||||
prototypeReviewConfirmed: true,
|
||||
} as Partial<VersionPlan>));
|
||||
assert.equal(withReviewConfirmation.canComplete, true);
|
||||
});
|
||||
|
||||
test('product design plans do not accept file results', () => {
|
||||
assert.equal(hasPlanResult({
|
||||
productPlanKind: 'design',
|
||||
resultType: 'file',
|
||||
resultTitle: 'Axure file',
|
||||
resultFileName: 'prototype.rp',
|
||||
resultFileData: 'data:application/octet-stream;base64,abc',
|
||||
} as any), false);
|
||||
});
|
||||
|
||||
test('product review plans can complete with a pass result without prototype link', () => {
|
||||
const state = getPlanCompletionState(plan({
|
||||
productPlanKind: 'review',
|
||||
completedRequirementIds: ['r1'],
|
||||
reviewResult: 'passed',
|
||||
} as Partial<VersionPlan>));
|
||||
assert.equal(state.canComplete, true);
|
||||
});
|
||||
|
||||
test('product review plans require failure type and detail when review fails', () => {
|
||||
const missingFailureDetail = getPlanCompletionState(plan({
|
||||
productPlanKind: 'review',
|
||||
completedRequirementIds: ['r1'],
|
||||
reviewResult: 'failed',
|
||||
} as Partial<VersionPlan>));
|
||||
assert.equal(missingFailureDetail.canComplete, false);
|
||||
|
||||
const completeFailureDetail = getPlanCompletionState(plan({
|
||||
productPlanKind: 'review',
|
||||
completedRequirementIds: ['r1'],
|
||||
reviewResult: 'failed',
|
||||
reviewFailureTypes: ['interaction_flow'],
|
||||
reviewFailureReason: 'Critical path is missing empty and rollback states.',
|
||||
} as Partial<VersionPlan>));
|
||||
assert.equal(completeFailureDetail.canComplete, true);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import type { VersionPlan } from './version-plan';
|
||||
import type { ProductPlanKind, ProductPlanReviewFailureType, ProductPlanReviewResult, VersionPlan } from './version-plan';
|
||||
|
||||
export interface PlanResultPayload {
|
||||
type?: VersionPlan['type'];
|
||||
productPlanKind?: ProductPlanKind;
|
||||
resultType?: 'link' | 'file';
|
||||
resultTitle?: string;
|
||||
resultUrl?: string;
|
||||
resultFileName?: string;
|
||||
resultFileData?: string;
|
||||
prototypeReviewConfirmed?: boolean;
|
||||
reviewResult?: ProductPlanReviewResult;
|
||||
reviewFailureTypes?: ProductPlanReviewFailureType[];
|
||||
reviewFailureReason?: string;
|
||||
}
|
||||
|
||||
export interface PlanCompletionState {
|
||||
@@ -20,6 +26,23 @@ export interface PlanCompletionState {
|
||||
}
|
||||
|
||||
export function hasPlanResult(plan: PlanResultPayload): boolean {
|
||||
if (plan.productPlanKind === 'review') {
|
||||
if (plan.reviewResult === 'passed') return true;
|
||||
if (plan.reviewResult === 'failed') {
|
||||
return Boolean(plan.reviewFailureTypes?.length && plan.reviewFailureReason?.trim());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plan.productPlanKind === 'design') {
|
||||
return Boolean(
|
||||
plan.resultType === 'link'
|
||||
&& plan.resultTitle?.trim()
|
||||
&& plan.resultUrl?.trim()
|
||||
&& plan.prototypeReviewConfirmed,
|
||||
);
|
||||
}
|
||||
|
||||
const hasTitle = Boolean(plan.resultTitle?.trim());
|
||||
if (!hasTitle || !plan.resultType) return false;
|
||||
if (plan.resultType === 'link') return Boolean(plan.resultUrl?.trim());
|
||||
@@ -34,6 +57,11 @@ function requiresChecklist(plan: VersionPlan): boolean {
|
||||
return plan.type === 'research';
|
||||
}
|
||||
|
||||
function getProductPlanKind(plan: VersionPlan): ProductPlanKind | undefined {
|
||||
if (plan.type !== 'product') return undefined;
|
||||
return plan.productPlanKind ?? 'design';
|
||||
}
|
||||
|
||||
export function getPlanCompletionState(plan: VersionPlan): PlanCompletionState {
|
||||
const tasks = plan.tasks ?? [];
|
||||
const checklistTotal = tasks.length;
|
||||
@@ -52,8 +80,25 @@ export function getPlanCompletionState(plan: VersionPlan): PlanCompletionState {
|
||||
}
|
||||
|
||||
const canSubmitResult = missingReasons.length === 0;
|
||||
const hasResult = hasPlanResult(plan);
|
||||
if (canSubmitResult && !hasResult) missingReasons.push('尚未提交成果');
|
||||
const productPlanKind = getProductPlanKind(plan);
|
||||
const resultPlan = productPlanKind ? { ...plan, productPlanKind } : plan;
|
||||
const hasResult = hasPlanResult(resultPlan);
|
||||
if (canSubmitResult && !hasResult) {
|
||||
if (productPlanKind === 'design') {
|
||||
if (plan.resultType === 'file') missingReasons.push('产品设计方案只支持原型链接');
|
||||
if (plan.resultType === 'link' && plan.resultUrl?.trim() && !plan.prototypeReviewConfirmed) {
|
||||
missingReasons.push('请先确认方案评审已通过');
|
||||
} else {
|
||||
missingReasons.push('尚未提交原型链接');
|
||||
}
|
||||
} else if (productPlanKind === 'review') {
|
||||
if (!plan.reviewResult) missingReasons.push('请选择评审结论');
|
||||
if (plan.reviewResult === 'failed' && !plan.reviewFailureTypes?.length) missingReasons.push('请选择评审不通过类型');
|
||||
if (plan.reviewResult === 'failed' && !plan.reviewFailureReason?.trim()) missingReasons.push('请填写评审不通过原因');
|
||||
} else {
|
||||
missingReasons.push('尚未提交成果');
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
checklistTotal,
|
||||
|
||||
@@ -1,4 +1,40 @@
|
||||
export type PlanTaskStatus = 'pending' | 'in_progress' | 'completed';
|
||||
export type ProductPlanKind = 'design' | 'review';
|
||||
export type ProductPlanReviewResult = 'passed' | 'failed';
|
||||
export type ProductPlanReviewFailureType =
|
||||
| 'requirement_mismatch'
|
||||
| 'information_architecture'
|
||||
| 'interaction_flow'
|
||||
| 'state_coverage'
|
||||
| 'edge_case_missing'
|
||||
| 'business_rule_gap'
|
||||
| 'role_permission_gap'
|
||||
| 'data_rule_gap'
|
||||
| 'copywriting_ambiguity'
|
||||
| 'risk_dependency';
|
||||
|
||||
export const PRODUCT_PLAN_KIND_LABEL: Record<ProductPlanKind, string> = {
|
||||
design: '设计方案',
|
||||
review: '方案评审',
|
||||
};
|
||||
|
||||
export const PRODUCT_PLAN_REVIEW_RESULT_LABEL: Record<ProductPlanReviewResult, string> = {
|
||||
passed: '评审通过',
|
||||
failed: '评审不通过',
|
||||
};
|
||||
|
||||
export const PRODUCT_PLAN_REVIEW_FAILURE_OPTIONS: { value: ProductPlanReviewFailureType; label: string }[] = [
|
||||
{ value: 'requirement_mismatch', label: '需求覆盖不完整/偏离需求' },
|
||||
{ value: 'information_architecture', label: '信息架构或页面层级不清晰' },
|
||||
{ value: 'interaction_flow', label: '关键交互流程不闭环' },
|
||||
{ value: 'state_coverage', label: '缺少状态、异常或空数据场景' },
|
||||
{ value: 'edge_case_missing', label: '边界场景考虑不足' },
|
||||
{ value: 'business_rule_gap', label: '业务规则、审批或口径缺失' },
|
||||
{ value: 'role_permission_gap', label: '角色权限与可见范围不明确' },
|
||||
{ value: 'data_rule_gap', label: '字段、数据来源或计算逻辑不清楚' },
|
||||
{ value: 'copywriting_ambiguity', label: '文案表达有歧义或误导' },
|
||||
{ value: 'risk_dependency', label: '依赖、风险或上线影响未说明' },
|
||||
];
|
||||
|
||||
export interface PlanTask {
|
||||
id: string;
|
||||
@@ -18,11 +54,16 @@ export interface VersionPlan {
|
||||
tasks?: PlanTask[];
|
||||
completedRequirementIds?: string[];
|
||||
linkedRequirementIds?: string[];
|
||||
productPlanKind?: ProductPlanKind;
|
||||
resultType?: 'link' | 'file';
|
||||
resultTitle?: string;
|
||||
resultUrl?: string;
|
||||
resultFileName?: string;
|
||||
resultFileData?: string;
|
||||
prototypeReviewConfirmed?: boolean;
|
||||
reviewResult?: ProductPlanReviewResult;
|
||||
reviewFailureTypes?: ProductPlanReviewFailureType[];
|
||||
reviewFailureReason?: string;
|
||||
remark?: string;
|
||||
overdueReason?: string;
|
||||
actualStartAt?: string;
|
||||
|
||||
@@ -21,6 +21,15 @@ test('aggregateWorkEffort calculates weighted progress by estimate', () => {
|
||||
assert.equal(result.progress, 75);
|
||||
});
|
||||
|
||||
test('aggregateWorkEffort preserves sub-half-hour AI estimates', () => {
|
||||
const result = aggregateWorkEffort([
|
||||
{ estimateHours: 0.2, actualHours: 0, progress: 50 },
|
||||
]);
|
||||
|
||||
assert.equal(result.estimateHours, 0.2);
|
||||
assert.equal(result.progress, 50);
|
||||
});
|
||||
|
||||
test('aggregateWorkEffort falls back to item average when estimates are zero', () => {
|
||||
const result = aggregateWorkEffort([
|
||||
{ estimateHours: 0, actualHours: 0, progress: 50 },
|
||||
|
||||
@@ -15,10 +15,15 @@ export function roundHalfHour(hours: number): number {
|
||||
return Math.round(hours * 2) / 2;
|
||||
}
|
||||
|
||||
export function roundEstimateHours(hours: number): number {
|
||||
if (!Number.isFinite(hours) || hours <= 0) return 0;
|
||||
return Number(hours.toFixed(2));
|
||||
}
|
||||
|
||||
export function aggregateWorkEffort(items: WorkEffortItem[]): WorkEffortSummary {
|
||||
if (items.length === 0) return { estimateHours: 0, actualHours: 0, progress: 0 };
|
||||
|
||||
const estimateHours = roundHalfHour(items.reduce((sum, item) => sum + Math.max(0, item.estimateHours || 0), 0));
|
||||
const estimateHours = roundEstimateHours(items.reduce((sum, item) => sum + Math.max(0, item.estimateHours || 0), 0));
|
||||
const actualHours = roundHalfHour(items.reduce((sum, item) => sum + Math.max(0, item.actualHours || 0), 0));
|
||||
|
||||
if (estimateHours <= 0) {
|
||||
|
||||
@@ -49,7 +49,6 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
|
||||
id: createEntityId('tc'),
|
||||
caseNo: generateCaseNo(list),
|
||||
status: 'pending',
|
||||
estimateHours: data.estimateHours ?? 0.5,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
} as TestCase);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { create } from 'zustand';
|
||||
import type { VersionPlan, PlanType } from '@/lib/version-plan';
|
||||
import { loadServerData, saveServerData } from '@/lib/server-data';
|
||||
import { getPlanCompletionState } from '@/lib/version-plan-workflow';
|
||||
import type { PlanResultPayload } from '@/lib/version-plan-workflow';
|
||||
|
||||
const MOCK_PLANS: VersionPlan[] = [];
|
||||
|
||||
@@ -22,7 +23,7 @@ interface VersionPlanState {
|
||||
fetchPlans: () => Promise<void>;
|
||||
createPlan: (data: Omit<VersionPlan, 'id' | 'createdAt'>) => void;
|
||||
updatePlan: (id: string, data: Partial<VersionPlan>) => void;
|
||||
completePlan: (id: string, result: { resultType: 'link' | 'file'; resultTitle: string; resultUrl?: string; resultFileName?: string; resultFileData?: string }) => { ok: boolean; message?: string };
|
||||
completePlan: (id: string, result: PlanResultPayload) => { ok: boolean; message?: string };
|
||||
deletePlan: (id: string) => void;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user