|
| 1 | +import { describe, it, expect, expectTypeOf } from 'vitest'; |
| 2 | +import { |
| 3 | + TaskStatus, |
| 4 | + LogLevel, |
| 5 | + LogCategory, |
| 6 | + LogAction, |
| 7 | + type TaskStep, |
| 8 | + type TaskPlan, |
| 9 | + type CurrentTask, |
| 10 | + type TaskLog, |
| 11 | +} from './index.js'; |
| 12 | + |
| 13 | +describe('基础数据类型测试', () => { |
| 14 | + describe('TaskStatus 枚举', () => { |
| 15 | + it('应该包含所有必需的状态值', () => { |
| 16 | + expect(TaskStatus.ToDo).toBe('to_do'); |
| 17 | + expect(TaskStatus.InProgress).toBe('in_progress'); |
| 18 | + expect(TaskStatus.Completed).toBe('completed'); |
| 19 | + expect(TaskStatus.Blocked).toBe('blocked'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('应该是字符串类型', () => { |
| 23 | + expectTypeOf(TaskStatus.ToDo).toBeString(); |
| 24 | + expectTypeOf(TaskStatus.InProgress).toBeString(); |
| 25 | + expectTypeOf(TaskStatus.Completed).toBeString(); |
| 26 | + expectTypeOf(TaskStatus.Blocked).toBeString(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('应该支持类型检查', () => { |
| 30 | + const status: TaskStatus = TaskStatus.ToDo; |
| 31 | + expectTypeOf(status).toMatchTypeOf<TaskStatus>(); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + describe('日志相关枚举', () => { |
| 36 | + it('LogLevel 应该包含所有级别', () => { |
| 37 | + expect(LogLevel.Info).toBe('INFO'); |
| 38 | + expect(LogLevel.Warning).toBe('WARNING'); |
| 39 | + expect(LogLevel.Error).toBe('ERROR'); |
| 40 | + expect(LogLevel.Teach).toBe('TEACH'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('LogCategory 应该包含所有类别', () => { |
| 44 | + expect(LogCategory.Plan).toBe('PLAN'); |
| 45 | + expect(LogCategory.Step).toBe('STEP'); |
| 46 | + expect(LogCategory.Task).toBe('TASK'); |
| 47 | + expect(LogCategory.Knowledge).toBe('KNOWLEDGE'); |
| 48 | + expect(LogCategory.Discussion).toBe('DISCUSSION'); |
| 49 | + expect(LogCategory.Exception).toBe('EXCEPTION'); |
| 50 | + expect(LogCategory.Test).toBe('TEST'); |
| 51 | + expect(LogCategory.Health).toBe('HEALTH'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('LogAction 应该包含所有操作', () => { |
| 55 | + expect(LogAction.Update).toBe('UPDATE'); |
| 56 | + expect(LogAction.Create).toBe('CREATE'); |
| 57 | + expect(LogAction.Modify).toBe('MODIFY'); |
| 58 | + expect(LogAction.Switch).toBe('SWITCH'); |
| 59 | + expect(LogAction.Handle).toBe('HANDLE'); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('TaskStep 接口类型测试', () => { |
| 64 | + it('应该具有正确的类型结构', () => { |
| 65 | + const taskStep: TaskStep = { |
| 66 | + id: 'step-001', |
| 67 | + description: '测试步骤描述', |
| 68 | + status: TaskStatus.ToDo, |
| 69 | + hints: [], |
| 70 | + created_at: '2025-09-21T22:00:00.000Z', |
| 71 | + }; |
| 72 | + |
| 73 | + expectTypeOf(taskStep).toEqualTypeOf<TaskStep>(); |
| 74 | + expectTypeOf(taskStep.id).toBeString(); |
| 75 | + expectTypeOf(taskStep.description).toBeString(); |
| 76 | + expectTypeOf(taskStep.status).toEqualTypeOf<TaskStatus>(); |
| 77 | + expectTypeOf(taskStep.hints).toEqualTypeOf<string[]>(); |
| 78 | + expectTypeOf(taskStep.created_at).toBeString(); |
| 79 | + }); |
| 80 | + |
| 81 | + it('应该支持可选字段', () => { |
| 82 | + const taskStepWithOptionals: TaskStep = { |
| 83 | + id: 'step-002', |
| 84 | + description: '带可选字段的步骤', |
| 85 | + status: TaskStatus.Completed, |
| 86 | + evidence: 'https://example.com/evidence', |
| 87 | + notes: '完成说明', |
| 88 | + hints: ['提示1', '提示2'], |
| 89 | + created_at: '2025-09-21T22:00:00.000Z', |
| 90 | + completed_at: '2025-09-21T22:30:00.000Z', |
| 91 | + }; |
| 92 | + |
| 93 | + expectTypeOf(taskStepWithOptionals.evidence).toEqualTypeOf< |
| 94 | + string | undefined |
| 95 | + >(); |
| 96 | + expectTypeOf(taskStepWithOptionals.notes).toEqualTypeOf< |
| 97 | + string | undefined |
| 98 | + >(); |
| 99 | + expectTypeOf(taskStepWithOptionals.completed_at).toEqualTypeOf< |
| 100 | + string | undefined |
| 101 | + >(); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + describe('TaskPlan 接口类型测试', () => { |
| 106 | + it('应该具有正确的类型结构', () => { |
| 107 | + const taskPlan: TaskPlan = { |
| 108 | + id: 'plan-001', |
| 109 | + description: '测试计划描述', |
| 110 | + status: TaskStatus.InProgress, |
| 111 | + hints: [], |
| 112 | + steps: [], |
| 113 | + created_at: '2025-09-21T22:00:00.000Z', |
| 114 | + }; |
| 115 | + |
| 116 | + expectTypeOf(taskPlan).toEqualTypeOf<TaskPlan>(); |
| 117 | + expectTypeOf(taskPlan.id).toBeString(); |
| 118 | + expectTypeOf(taskPlan.description).toBeString(); |
| 119 | + expectTypeOf(taskPlan.status).toEqualTypeOf<TaskStatus>(); |
| 120 | + expectTypeOf(taskPlan.hints).toEqualTypeOf<string[]>(); |
| 121 | + expectTypeOf(taskPlan.steps).toEqualTypeOf<TaskStep[]>(); |
| 122 | + expectTypeOf(taskPlan.created_at).toBeString(); |
| 123 | + }); |
| 124 | + |
| 125 | + it('应该支持可选字段', () => { |
| 126 | + const taskPlanWithOptionals: TaskPlan = { |
| 127 | + id: 'plan-002', |
| 128 | + description: '带可选字段的计划', |
| 129 | + status: TaskStatus.Completed, |
| 130 | + evidence: 'https://example.com/plan-evidence', |
| 131 | + hints: ['计划提示'], |
| 132 | + steps: [], |
| 133 | + created_at: '2025-09-21T22:00:00.000Z', |
| 134 | + completed_at: '2025-09-21T22:45:00.000Z', |
| 135 | + }; |
| 136 | + |
| 137 | + expectTypeOf(taskPlanWithOptionals.evidence).toEqualTypeOf< |
| 138 | + string | undefined |
| 139 | + >(); |
| 140 | + expectTypeOf(taskPlanWithOptionals.completed_at).toEqualTypeOf< |
| 141 | + string | undefined |
| 142 | + >(); |
| 143 | + }); |
| 144 | + }); |
| 145 | + |
| 146 | + describe('CurrentTask 接口类型测试', () => { |
| 147 | + it('应该具有正确的类型结构', () => { |
| 148 | + const currentTask: CurrentTask = { |
| 149 | + id: 'task-001', |
| 150 | + title: '测试任务', |
| 151 | + slug: 'test-task', |
| 152 | + knowledge_refs: [], |
| 153 | + goal: '测试目标', |
| 154 | + task_hints: [], |
| 155 | + overall_plan: [], |
| 156 | + logs: [], |
| 157 | + created_at: '2025-09-21T22:00:00.000Z', |
| 158 | + updated_at: '2025-09-21T22:00:00.000Z', |
| 159 | + }; |
| 160 | + |
| 161 | + expectTypeOf(currentTask).toEqualTypeOf<CurrentTask>(); |
| 162 | + expectTypeOf(currentTask.id).toBeString(); |
| 163 | + expectTypeOf(currentTask.title).toBeString(); |
| 164 | + expectTypeOf(currentTask.slug).toBeString(); |
| 165 | + expectTypeOf(currentTask.knowledge_refs).toEqualTypeOf<string[]>(); |
| 166 | + expectTypeOf(currentTask.goal).toBeString(); |
| 167 | + expectTypeOf(currentTask.task_hints).toEqualTypeOf<string[]>(); |
| 168 | + expectTypeOf(currentTask.overall_plan).toEqualTypeOf<TaskPlan[]>(); |
| 169 | + expectTypeOf(currentTask.logs).toEqualTypeOf<TaskLog[]>(); |
| 170 | + expectTypeOf(currentTask.created_at).toBeString(); |
| 171 | + expectTypeOf(currentTask.updated_at).toBeString(); |
| 172 | + }); |
| 173 | + |
| 174 | + it('应该支持可选字段', () => { |
| 175 | + const currentTaskWithOptionals: CurrentTask = { |
| 176 | + id: 'task-002', |
| 177 | + title: '带可选字段的任务', |
| 178 | + slug: 'task-with-optionals', |
| 179 | + story: { |
| 180 | + id: 'story-001', |
| 181 | + slug: 'story-slug', |
| 182 | + url: 'https://example.com/story', |
| 183 | + title: 'Story 标题', |
| 184 | + }, |
| 185 | + requirement: { |
| 186 | + id: 'req-001', |
| 187 | + url: 'https://example.com/requirement', |
| 188 | + title: 'Requirement 标题', |
| 189 | + }, |
| 190 | + knowledge_refs: ['ref1', 'ref2'], |
| 191 | + goal: '测试目标', |
| 192 | + task_hints: ['任务提示'], |
| 193 | + overall_plan: [], |
| 194 | + current_plan_id: 'plan-001', |
| 195 | + current_step_details: '当前步骤详情', |
| 196 | + logs: [], |
| 197 | + provenance: { |
| 198 | + git: { |
| 199 | + repo: 'test-repo', |
| 200 | + branch: 'main', |
| 201 | + since: 'abc123', |
| 202 | + until: 'def456', |
| 203 | + commits: ['commit1', 'commit2'], |
| 204 | + }, |
| 205 | + pr_links: ['https://github.com/test/pr/1'], |
| 206 | + issue_links: ['https://github.com/test/issues/1'], |
| 207 | + doc_links: ['https://docs.example.com'], |
| 208 | + sources: ['source1', 'source2'], |
| 209 | + }, |
| 210 | + created_at: '2025-09-21T22:00:00.000Z', |
| 211 | + updated_at: '2025-09-21T22:00:00.000Z', |
| 212 | + completed_at: '2025-09-21T23:00:00.000Z', |
| 213 | + }; |
| 214 | + |
| 215 | + expectTypeOf(currentTaskWithOptionals.story).toEqualTypeOf< |
| 216 | + | { |
| 217 | + id?: string; |
| 218 | + slug?: string; |
| 219 | + url?: string; |
| 220 | + title?: string; |
| 221 | + } |
| 222 | + | undefined |
| 223 | + >(); |
| 224 | + expectTypeOf(currentTaskWithOptionals.requirement).toEqualTypeOf< |
| 225 | + | { |
| 226 | + id?: string; |
| 227 | + url?: string; |
| 228 | + title?: string; |
| 229 | + } |
| 230 | + | undefined |
| 231 | + >(); |
| 232 | + expectTypeOf(currentTaskWithOptionals.current_plan_id).toEqualTypeOf< |
| 233 | + string | undefined |
| 234 | + >(); |
| 235 | + expectTypeOf(currentTaskWithOptionals.current_step_details).toEqualTypeOf< |
| 236 | + string | undefined |
| 237 | + >(); |
| 238 | + expectTypeOf(currentTaskWithOptionals.completed_at).toEqualTypeOf< |
| 239 | + string | undefined |
| 240 | + >(); |
| 241 | + }); |
| 242 | + }); |
| 243 | + |
| 244 | + describe('TaskLog 接口类型测试', () => { |
| 245 | + it('应该具有正确的类型结构', () => { |
| 246 | + const taskLog: TaskLog = { |
| 247 | + timestamp: '2025-09-21T22:00:00.000Z', |
| 248 | + level: LogLevel.Info, |
| 249 | + category: LogCategory.Task, |
| 250 | + action: LogAction.Create, |
| 251 | + message: '测试日志消息', |
| 252 | + }; |
| 253 | + |
| 254 | + expectTypeOf(taskLog).toEqualTypeOf<TaskLog>(); |
| 255 | + expectTypeOf(taskLog.timestamp).toBeString(); |
| 256 | + expectTypeOf(taskLog.level).toEqualTypeOf<LogLevel>(); |
| 257 | + expectTypeOf(taskLog.category).toEqualTypeOf<LogCategory>(); |
| 258 | + expectTypeOf(taskLog.action).toEqualTypeOf<LogAction>(); |
| 259 | + expectTypeOf(taskLog.message).toBeString(); |
| 260 | + }); |
| 261 | + |
| 262 | + it('应该支持可选字段', () => { |
| 263 | + const taskLogWithOptionals: TaskLog = { |
| 264 | + timestamp: '2025-09-21T22:00:00.000Z', |
| 265 | + level: LogLevel.Warning, |
| 266 | + category: LogCategory.Exception, |
| 267 | + action: LogAction.Handle, |
| 268 | + message: '带可选字段的日志', |
| 269 | + ai_notes: 'AI 详细说明', |
| 270 | + details: { key: 'value', count: 42 }, |
| 271 | + }; |
| 272 | + |
| 273 | + expectTypeOf(taskLogWithOptionals.ai_notes).toEqualTypeOf< |
| 274 | + string | undefined |
| 275 | + >(); |
| 276 | + expectTypeOf(taskLogWithOptionals.details).toEqualTypeOf< |
| 277 | + Record<string, any> | undefined |
| 278 | + >(); |
| 279 | + }); |
| 280 | + }); |
| 281 | +}); |
0 commit comments