|
| 1 | +--- |
| 2 | +status: planned |
| 3 | +created: '2025-12-18' |
| 4 | +tags: |
| 5 | + - testing |
| 6 | + - rust |
| 7 | + - quality |
| 8 | +priority: high |
| 9 | +created_at: '2025-12-18T05:55:17.246448125+00:00' |
| 10 | +--- |
| 11 | + |
| 12 | +# Port TypeScript E2E Test Suite to Rust CLI |
| 13 | + |
| 14 | +> **Status**: 🗓️ Planned · **Created**: 2025-12-18 |
| 15 | +
|
| 16 | +## Overview |
| 17 | + |
| 18 | +Port the comprehensive TypeScript E2E test suite (40+ test files) to Rust integration tests for the CLI. This ensures feature parity and prevents regressions as we migrate from TypeScript to Rust. |
| 19 | + |
| 20 | +### Background |
| 21 | + |
| 22 | +The TypeScript CLI has excellent test coverage: |
| 23 | +- **E2E tests**: spec-lifecycle, init, mcp-tools, create-with-content, regression tests |
| 24 | +- **Unit tests**: validators, frontmatter parsing, git utilities, spec loader |
| 25 | +- **Integration tests**: full command workflows |
| 26 | + |
| 27 | +The Rust implementation currently has: |
| 28 | +- ✅ Unit tests in `leanspec-core` (validators, spec_loader) |
| 29 | +- ❌ NO tests in `leanspec-cli` |
| 30 | +- ❌ NO integration/e2e tests |
| 31 | + |
| 32 | +### Goals |
| 33 | + |
| 34 | +1. Port all TypeScript E2E tests to Rust integration tests |
| 35 | +2. Establish test infrastructure (helpers, fixtures, assertions) |
| 36 | +3. Ensure all CLI commands are covered |
| 37 | +4. Catch regressions during TS→Rust migration |
| 38 | +5. Provide CI/CD test coverage for future development |
| 39 | + |
| 40 | +### Existing TypeScript Test Coverage |
| 41 | + |
| 42 | +**E2E Tests** (`packages/cli/src/__e2e__/`): |
| 43 | +- `spec-lifecycle.e2e.test.ts` - Create→Update→Archive workflows |
| 44 | +- `init.e2e.test.ts` - Project initialization |
| 45 | +- `mcp-tools.e2e.test.ts` - MCP server tools |
| 46 | +- `create-with-content.e2e.test.ts` - Template content at creation |
| 47 | +- `regression-template.e2e.test.ts` - Regression tests |
| 48 | + |
| 49 | +**Integration Tests**: |
| 50 | +- `integration.test.ts` - Multi-command workflows |
| 51 | +- `list-integration.test.ts` - List filtering |
| 52 | + |
| 53 | +**Unit Tests**: |
| 54 | +- Frontmatter parsing/validation |
| 55 | +- Git timestamp utilities |
| 56 | +- Spec loader functionality |
| 57 | +- Structure/corruption validators |
| 58 | +- Token counting |
| 59 | +- Variable resolution |
| 60 | + |
| 61 | +## Plan |
| 62 | + |
| 63 | +### Phase 1: Test Infrastructure |
| 64 | +- [ ] Add test dependencies (`assert_cmd`, `predicates`, optionally `insta`) |
| 65 | +- [ ] Create `tests/helpers/mod.rs` with utilities: |
| 66 | + - Temporary directory management |
| 67 | + - CLI binary execution wrapper |
| 68 | + - Frontmatter parsing utilities |
| 69 | + - File/directory assertion helpers |
| 70 | + - Output capture and validation |
| 71 | +- [ ] Create test fixtures directory structure |
| 72 | +- [ ] Set up CI/CD test pipeline integration |
| 73 | + |
| 74 | +### Phase 2: Port Core E2E Tests |
| 75 | +Priority order (highest impact): |
| 76 | +- [ ] Port `spec-lifecycle.e2e.test.ts` → `tests/integration/spec_lifecycle.rs` |
| 77 | + - Create→update→archive workflows |
| 78 | + - Multi-spec creation with sequential numbering |
| 79 | + - Status transitions |
| 80 | +- [ ] Port `init.e2e.test.ts` → `tests/integration/init.rs` |
| 81 | + - Fresh initialization |
| 82 | + - Re-initialization (upgrade mode) |
| 83 | + - Force re-initialization |
| 84 | + - Template selection |
| 85 | + - Agent tool symlinks |
| 86 | + - MCP configuration |
| 87 | + - Error handling |
| 88 | +- [ ] Port `create-with-content.e2e.test.ts` → `tests/integration/create.rs` |
| 89 | + - Content from file |
| 90 | + - Content from stdin |
| 91 | + - Template with content |
| 92 | +- [ ] Port `mcp-tools.e2e.test.ts` → `tests/integration/mcp_tools.rs` |
| 93 | + - MCP server startup |
| 94 | + - Tool invocations |
| 95 | + - Error handling |
| 96 | +- [ ] Port `regression-template.e2e.test.ts` → `tests/integration/regression.rs` |
| 97 | + - Known regression tests |
| 98 | + - Edge cases |
| 99 | + |
| 100 | +### Phase 3: Integration Test Coverage |
| 101 | +- [ ] Port `list-integration.test.ts` → `tests/integration/list.rs` |
| 102 | + - Status filtering |
| 103 | + - Tag filtering |
| 104 | + - Priority filtering |
| 105 | + - Assignee filtering |
| 106 | + - Compact output |
| 107 | +- [ ] Create `tests/integration/link.rs` for dependency management |
| 108 | + - Link specs (depends_on) |
| 109 | + - Unlink specs |
| 110 | + - Circular dependency detection |
| 111 | +- [ ] Create `tests/integration/update.rs` for metadata updates |
| 112 | + - Status updates |
| 113 | + - Priority updates |
| 114 | + - Tag operations (add/remove) |
| 115 | + - Assignee updates |
| 116 | +- [ ] Create `tests/integration/board.rs` for board view |
| 117 | + - Group by status |
| 118 | + - Group by priority |
| 119 | + - Group by assignee |
| 120 | + - Group by tag |
| 121 | +- [ ] Create `tests/integration/search.rs` for search functionality |
| 122 | + - Basic search |
| 123 | + - Advanced search syntax |
| 124 | + - Limit results |
| 125 | +- [ ] Create `tests/integration/validate.rs` for validation |
| 126 | + - Single spec validation |
| 127 | + - All specs validation |
| 128 | + - Dependency alignment check |
| 129 | + - Strict mode |
| 130 | + - Warnings only mode |
| 131 | + |
| 132 | +### Phase 4: Command Coverage Validation |
| 133 | +Ensure every CLI command has test coverage: |
| 134 | +- [ ] `agent` - AI agent dispatch |
| 135 | +- [ ] `analyze` - Spec complexity analysis |
| 136 | +- [ ] `archive` - Move spec to archived/ |
| 137 | +- [ ] `backfill` - Git timestamp backfill |
| 138 | +- [ ] `board` - Project board view (covered in Phase 3) |
| 139 | +- [ ] `check` - Sequence conflict detection |
| 140 | +- [ ] `compact` - Remove line ranges |
| 141 | +- [ ] `create` - Spec creation (covered in Phase 2) |
| 142 | +- [ ] `deps` - Dependency graph |
| 143 | +- [ ] `examples` - List example projects |
| 144 | +- [ ] `files` - List spec files |
| 145 | +- [ ] `gantt` - Timeline with dependencies |
| 146 | +- [ ] `init` - Project initialization (covered in Phase 2) |
| 147 | +- [ ] `link` - Link specs (covered in Phase 3) |
| 148 | +- [ ] `list` - List specs (covered in Phase 3) |
| 149 | +- [ ] `mcp` - MCP server (see spec 176) |
| 150 | +- [ ] `migrate` - Migrate from other tools |
| 151 | +- [ ] `open` - Open spec in editor |
| 152 | +- [ ] `search` - Search specs (covered in Phase 3) |
| 153 | +- [ ] `split` - Split spec into files |
| 154 | +- [ ] `stats` - Project statistics |
| 155 | +- [ ] `templates` - Manage templates |
| 156 | +- [ ] `timeline` - Creation/completion timeline |
| 157 | +- [ ] `tokens` - Token counting |
| 158 | +- [ ] `ui` - Start web UI |
| 159 | +- [ ] `unlink` - Remove dependency link (covered in Phase 3) |
| 160 | +- [ ] `update` - Update metadata (covered in Phase 3) |
| 161 | +- [ ] `validate` - Validate specs (covered in Phase 3) |
| 162 | +- [ ] `view` - View spec details |
| 163 | + |
| 164 | +### Phase 5: CI/CD Integration |
| 165 | +- [ ] Configure test execution in GitHub Actions |
| 166 | +- [ ] Set up test coverage reporting |
| 167 | +- [ ] Add test performance benchmarks |
| 168 | +- [ ] Document testing guidelines for contributors |
| 169 | + |
| 170 | +## Test Structure |
| 171 | + |
| 172 | +``` |
| 173 | +rust/leanspec-cli/ |
| 174 | + tests/ |
| 175 | + helpers/ |
| 176 | + mod.rs # Test utilities |
| 177 | + fixtures.rs # Fixture management |
| 178 | + assertions.rs # Custom assertions |
| 179 | + integration/ |
| 180 | + mod.rs # Integration test helpers |
| 181 | + spec_lifecycle.rs # Create→update→archive |
| 182 | + init.rs # Init command |
| 183 | + create.rs # Spec creation |
| 184 | + update.rs # Metadata updates |
| 185 | + link.rs # Dependency linking |
| 186 | + list.rs # List & filtering |
| 187 | + board.rs # Board view |
| 188 | + search.rs # Search |
| 189 | + validate.rs # Validation |
| 190 | + backfill.rs # Git backfill |
| 191 | + mcp_tools.rs # MCP tools (basic CLI tests) |
| 192 | + regression.rs # Regression tests |
| 193 | + commands/ # Individual command tests |
| 194 | + agent.rs |
| 195 | + analyze.rs |
| 196 | + archive.rs |
| 197 | + check.rs |
| 198 | + compact.rs |
| 199 | + deps.rs |
| 200 | + examples.rs |
| 201 | + files.rs |
| 202 | + gantt.rs |
| 203 | + migrate.rs |
| 204 | + open.rs |
| 205 | + split.rs |
| 206 | + stats.rs |
| 207 | + templates.rs |
| 208 | + timeline.rs |
| 209 | + tokens.rs |
| 210 | + ui.rs |
| 211 | + view.rs |
| 212 | + fixtures/ |
| 213 | + minimal-project/ # Test fixtures |
| 214 | + multi-spec/ |
| 215 | + with-dependencies/ |
| 216 | + archived/ |
| 217 | +``` |
| 218 | + |
| 219 | +## Dependencies |
| 220 | + |
| 221 | +Add to `Cargo.toml`: |
| 222 | + |
| 223 | +```toml |
| 224 | +[dev-dependencies] |
| 225 | +tempfile.workspace = true |
| 226 | +pretty_assertions.workspace = true |
| 227 | +assert_cmd = "2.0" # CLI testing utilities |
| 228 | +predicates = "3.0" # Assertion predicates |
| 229 | +insta = "1.34" # Snapshot testing (optional) |
| 230 | +``` |
| 231 | + |
| 232 | +## Success Criteria |
| 233 | + |
| 234 | +- [ ] All TypeScript E2E tests ported to Rust |
| 235 | +- [ ] Test infrastructure established and documented |
| 236 | +- [ ] All 29 CLI commands have test coverage |
| 237 | +- [ ] CI/CD integration test pipeline configured |
| 238 | +- [ ] Test execution time <30 seconds |
| 239 | +- [ ] Test coverage report available |
| 240 | +- [ ] Documentation for adding new tests |
| 241 | +- [ ] Zero test failures on main branch |
| 242 | + |
| 243 | +## Notes |
| 244 | + |
| 245 | +### Test Helper Examples |
| 246 | + |
| 247 | +Reference TypeScript `e2e-helpers.ts` patterns: |
| 248 | + |
| 249 | +```typescript |
| 250 | +// TypeScript |
| 251 | +export function execCli(args: string[], options: { cwd: string }): ExecResult { |
| 252 | + const command = `node "${CLI_PATH}" ${args.join(' ')}`; |
| 253 | + const stdout = execSync(command, { cwd, encoding: 'utf-8' }); |
| 254 | + return { stdout, stderr: '', exitCode: 0 }; |
| 255 | +} |
| 256 | +``` |
| 257 | + |
| 258 | +Rust equivalent: |
| 259 | + |
| 260 | +```rust |
| 261 | +// Rust |
| 262 | +pub fn exec_cli(args: &[&str], cwd: &Path) -> TestResult { |
| 263 | + Command::cargo_bin("lean-spec")? |
| 264 | + .args(args) |
| 265 | + .current_dir(cwd) |
| 266 | + .assert() |
| 267 | + .success(); |
| 268 | + Ok(()) |
| 269 | +} |
| 270 | +``` |
| 271 | + |
| 272 | +### Related Specs |
| 273 | + |
| 274 | +- **Spec 176**: Rust MCP Server Test Suite (MCP protocol testing) |
| 275 | +- **Spec 177**: UI E2E Test Suite with Playwright (UI testing) |
| 276 | +- **Spec 170**: CLI/MCP/Core Rust Migration Evaluation (context) |
| 277 | +- **Spec 173**: Rust Binaries CI/CD Pipeline (test execution infrastructure) |
0 commit comments