Skip to content

Commit 12775cb

Browse files
author
Zoo (VP)
committed
test(terminal): add coverage for CommandTrace, CommandEnvironmentService, ShellResolver edge cases, and webview inline shell selector
- Add CommandTrace.spec.ts (100% line coverage for builder + collector) - Add CommandEnvironmentService.spec.ts (98% line coverage; previously 0%) - Extend ShellResolver.spec.ts with bare-name normalization, invalid-path, and Unix env-probe fallback cases (76% -> 84%) - Extend TerminalSettings.shell.spec.tsx with path/cmd selection, custom path button, and dropdown value mapping (63% -> 80%) - Add session coverage report
1 parent 35cc3dc commit 12775cb

6 files changed

Lines changed: 1194 additions & 0 deletions

File tree

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Coverage Analysis Report: PR #1125 (b05-shell-resolution-v2)
2+
3+
## Methodology
4+
5+
1. Checked out branch `pr/b05-shell-resolution-v2` (HEAD: `35cc3dcf8`).
6+
2. Base commit for diff: `992585ff8` (merge-base with `origin/main`).
7+
3. Ran backend tests with coverage: `cd src && npx vitest run --coverage --reporter=verbose integrations/terminal/__tests__/ core/tools/__tests__/ core/prompts/__tests__/ core/webview/__tests__/`
8+
4. Ran webview tests with coverage: `cd webview-ui && npx vitest run --coverage --reporter=verbose src/components/settings/__tests__/`
9+
5. Ran packages/types tests with coverage: `cd packages/types && npx vitest run --coverage --reporter=verbose`
10+
6. Cross-referenced git diff added lines (patch) with lcov/coverage-final.json hit data to identify **new lines only** that are uncovered.
11+
12+
**Key insight**: codecov/patch measures only NEW lines introduced by the PR diff, not total file coverage. The analysis below reflects this.
13+
14+
---
15+
16+
## Coverage Summary - Backend (80% target)
17+
18+
| File | New Lines | Covered | Uncovered | Coverage % |
19+
| -------------------------------------------------------------- | --------- | ------- | --------- | ---------- |
20+
| `src/integrations/terminal/TerminalLifecycle.ts` | 600 | 105 | 495 | 17.5% |
21+
| `src/integrations/terminal/shell/TerminalProfileResolver.ts` | 609 | 115 | 494 | 18.9% |
22+
| `src/integrations/terminal/shell/ShellResolver.ts` | 554 | 94 | 460 | 17.0% |
23+
| `src/integrations/terminal/TerminalRegistry.ts` | 555 | 136 | 419 | 24.5% |
24+
| `src/integrations/terminal/CommandScheduler.ts` | 507 | 121 | 386 | 23.9% |
25+
| `src/core/tools/ExecuteCommandTool.ts` | 396 | 83 | 313 | 21.0% |
26+
| `src/integrations/terminal/CommandTrace.ts` | 344 | 46 | 298 | 13.4% |
27+
| `src/integrations/terminal/Terminal.ts` | 326 | 65 | 261 | 19.9% |
28+
| `src/core/webview/ClineProvider.ts` | 258 | 11 | 247 | 4.3% |
29+
| `src/integrations/terminal/shell/CommandEnvironmentService.ts` | 274 | 36 | 238 | 13.1% |
30+
| `src/integrations/terminal/shell/types.ts` | 155 | 0 | 155 | 0.0% |
31+
| `src/integrations/terminal/shell/ShellInvocationAdapter.ts` | 168 | 20 | 148 | 11.9% |
32+
| `src/utils/shell.ts` | 144 | 26 | 118 | 18.1% |
33+
| `src/integrations/terminal/BaseTerminal.ts` | 128 | 17 | 111 | 13.3% |
34+
| `src/integrations/terminal/types.ts` | 131 | 21 | 110 | 16.0% |
35+
| `src/core/prompts/tools/native-tools/execute_command.ts` | 96 | 22 | 74 | 22.9% |
36+
| `src/integrations/terminal/ExecaTerminal.ts` | 72 | 4 | 68 | 5.6% |
37+
| `src/integrations/terminal/ExecaTerminalProcess.ts` | 63 | 7 | 56 | 11.1% |
38+
| `src/core/prompts/sections/rules.ts` | 59 | 11 | 48 | 18.6% |
39+
| `src/core/webview/webviewMessageHandler.ts` | 41 | 5 | 36 | 12.2% |
40+
| `src/integrations/terminal/TerminalProcess.ts` | 36 | 7 | 29 | 19.4% |
41+
| `src/core/prompts/sections/system-info.ts` | 32 | 4 | 28 | 12.5% |
42+
| `src/core/webview/generateSystemPrompt.ts` | 24 | 4 | 20 | 16.7% |
43+
| `src/core/prompts/tools/native-tools/index.ts` | 13 | 1 | 12 | 7.7% |
44+
| `src/core/prompts/system.ts` | 6 | 0 | 6 | 0.0% |
45+
| `src/core/task/build-tools.ts` | 7 | 0 | 7 | 0.0% |
46+
| `src/extension.ts` | 5 | 0 | 5 | 0.0% |
47+
| `src/extension/api.ts` | 4 | 0 | 4 | 0.0% |
48+
| `packages/types/src/global-settings.ts` | 36 | 35 | 1 | 97.2% |
49+
| `packages/types/src/terminal.ts` | 11 | 11 | 0 | 100.0% |
50+
| **Backend Total** | **5654** | **990** | **4664** | **17.5%** |
51+
52+
---
53+
54+
## Coverage Summary - Webview (70% target)
55+
56+
| File | New Lines | Covered | Uncovered | Coverage % |
57+
| --------------------------------------------------------- | --------- | ------- | --------- | ---------- |
58+
| `webview-ui/src/components/settings/TerminalSettings.tsx` | 157 | 23 | 134 | 14.6% |
59+
| `webview-ui/src/components/settings/SettingsView.tsx` | 31 | 6 | 25 | 19.4% |
60+
| **Webview Total** | **188** | **29** | **159** | **15.4%** |
61+
62+
---
63+
64+
## Top 5 Uncovered Files (by impact)
65+
66+
### 1. `src/integrations/terminal/TerminalLifecycle.ts` - 495 uncovered new lines (17.5%)
67+
68+
- **New file** (600 lines added). Only L105-106, L107, L121, L124-130, L134-153, L155-162, L164-170, L179-186, L188-191, L193-196, L198-201, L203-206, L208-211, L213-216, L218-221, L223-229 and ~43 more groups are uncovered.
69+
- Entire class structure, lifecycle management, and event handling logic untested.
70+
- **Root cause**: New file with complex lifecycle orchestration. Tests exist (`TerminalLifecycle.spec.ts`, 1043 lines) but coverage is only 17.5% of new lines, suggesting tests cover only a subset of methods.
71+
72+
### 2. `src/integrations/terminal/shell/TerminalProfileResolver.ts` - 494 uncovered new lines (18.9%)
73+
74+
- **New file** (609 lines added). Only L94-96, L115, L178-180, L182, L196, L285, L330, L355, L390, L392, L404, L433, L436, L464, L466, L479, L532, L536 are covered.
75+
- Profile resolution logic, platform-specific branches, and fallback chains untested.
76+
- **Root cause**: New file. Tests exist (`ShellResolver.spec.ts` covers some paths) but the resolver has many platform-specific branches not exercised on Windows.
77+
78+
### 3. `src/integrations/terminal/shell/ShellResolver.ts` - 460 uncovered new lines (17.0%)
79+
80+
- **New file** (554 lines added). Only L84-86, L88-89, L96, L98-99, L101-102, L104-105, L107, L165-167, L170, L259, L302, L319, L347, L358, L471-473, L526, L528 are covered.
81+
- Shell detection, validation, and fallback logic largely untested.
82+
- **Root cause**: New file with extensive platform branching. Tests exist (`ShellResolver.spec.ts`, 691 lines) but many code paths require specific OS/shell configurations.
83+
84+
### 4. `src/integrations/terminal/TerminalRegistry.ts` - 419 uncovered new lines (24.5%)
85+
86+
- 555 new lines added to existing file. Many new methods for terminal management, shell integration, and registry operations uncovered.
87+
- **Root cause**: Existing file with massive additions. Tests exist (`TerminalRegistry.spec.ts`, 311+ lines) but coverage at 24.5% indicates many new methods untested.
88+
89+
### 5. `src/integrations/terminal/CommandScheduler.ts` - 386 uncovered new lines (23.9%)
90+
91+
- **New file** (507 lines added). Only L68, L70, L77, L82, L87, L97, L126, L148, L151, L157, L170, L173, L182-183, L185, L193, L216, L220, L225, L233, L241, L272, L385, L411 are covered.
92+
- Command queuing, scheduling, and execution logic untested.
93+
- **Root cause**: New file. Tests exist (`CommandScheduler.spec.ts`, 601 lines) but coverage at 23.9% suggests tests focus on a subset of scheduling scenarios.
94+
95+
---
96+
97+
## Recommended Tests to Write
98+
99+
### Priority 1: Highest Impact (Backend, 80% target)
100+
101+
The backend patch coverage is **17.5%** - far below the 80% target. To reach 80%, we need to cover approximately **3,523** more new lines (out of 4,664 uncovered). Focus on:
102+
103+
1. **`TerminalLifecycle.ts`** (495 uncovered): Add tests for lifecycle state transitions, terminal creation/disposal, event listener management, and error recovery paths. The existing `TerminalLifecycle.spec.ts` needs expansion to cover the full lifecycle state machine.
104+
105+
2. **`TerminalProfileResolver.ts`** (494 uncovered): Add platform-specific test cases for profile resolution on Windows (PowerShell, cmd), macOS (zsh, bash), and Linux (bash, zsh). Mock `vscode.window.activeTerminal.profile` and `vscode.workspace.getConfiguration('terminal.integrated')` more thoroughly.
106+
107+
3. **`ShellResolver.ts`** (460 uncovered): Add tests for shell detection fallback chains, path validation, and platform-specific shell discovery. Mock `process.platform`, `os.platform()`, and file existence checks.
108+
109+
4. **`TerminalRegistry.ts`** (419 uncovered): Add tests for new registry methods: terminal tracking, shell integration state management, cleanup operations, and multi-terminal coordination.
110+
111+
5. **`CommandScheduler.ts`** (386 uncovered): Add tests for queue management, priority scheduling, concurrent command execution, timeout handling, and cancellation paths.
112+
113+
6. **`ExecuteCommandTool.ts`** (313 uncovered): Add tests for new execute command paths including shell selection, environment setup, output capture, and error handling branches.
114+
115+
7. **`CommandTrace.ts`** (298 uncovered): Add tests for command trace recording, serialization, and query methods. This is a new file with zero meaningful coverage.
116+
117+
8. **`Terminal.ts`** (261 uncovered): Add tests for new terminal operations, shell integration, and process management methods.
118+
119+
9. **`ClineProvider.ts`** (247 uncovered): Add tests for new terminal settings handling, shell selection state management, and webview message dispatch for terminal configuration.
120+
121+
10. **`CommandEnvironmentService.ts`** (238 uncovered): Add tests for environment variable resolution, PATH manipulation, and shell-specific environment setup.
122+
123+
### Priority 2: Webview (70% target)
124+
125+
The webview patch coverage is **15.4%** - far below the 70% target. To reach 70%, we need to cover approximately **103** more new lines (out of 159 uncovered).
126+
127+
1. **`TerminalSettings.tsx`** (134 uncovered): Add tests for:
128+
- Shell selection dropdown rendering and onChange handlers (L102-103, L105, L115, L157, L201, L235, L255, L259, L263-271)
129+
- Profile path input validation (L304, L428-429, L466, L504, L533, L561, L588, L612, L636)
130+
- Form state management for terminal settings
131+
132+
2. **`SettingsView.tsx`** (25 uncovered): Add tests for:
133+
- Terminal settings section rendering (L255, L278, L305-307, L310-311, L316-318, L321-322, L327-329, L332-333, L338-340, L343, L348-350, L353, L358-360, L363, L368-370, L372-373, L376-377)
134+
- Settings change handlers for terminal shell selection (L514-515, L517, L542, L544, L607, L662, L665-669, L672-674, L724, L756, L793-794, L798, L801, L806, L809, L918, L952, L1018)
135+
136+
### Priority 3: Types (already high coverage)
137+
138+
- `packages/types/src/global-settings.ts`: 97.2% patch coverage (1 uncovered line: L391). Already passing.
139+
- `packages/types/src/terminal.ts`: 100% patch coverage. Already passing.
140+
141+
---
142+
143+
## Commands Run
144+
145+
```bash
146+
# 1. Checkout branch
147+
git fetch myk1yt
148+
git checkout pr/b05-shell-resolution-v2
149+
git reset --hard myk1yt/pr/b05-shell-resolution-v2
150+
151+
# 2. Backend tests with coverage
152+
cd src && npx vitest run --coverage --reporter=verbose integrations/terminal/__tests__/ core/tools/__tests__/ core/prompts/__tests__/ core/webview/__tests__/
153+
154+
# 3. Webview tests with coverage
155+
cd webview-ui && npx vitest run --coverage --reporter=verbose src/components/settings/__tests__/
156+
157+
# 4. packages/types tests with coverage
158+
cd packages/types && npx vitest run --coverage --reporter=verbose
159+
160+
# 5. Cross-reference diff added lines with coverage data
161+
git diff 992585ff8...HEAD --unified=0 -- <files> # for each source file
162+
python cross_ref_b05_coverage.py # custom script to cross-reference
163+
```
164+
165+
---
166+
167+
## Key Findings
168+
169+
1. **Backend patch coverage: 17.5%** (target: 80%) - Massive gap of 4,664 uncovered new lines across 28 source files.
170+
2. **Webview patch coverage: 15.4%** (target: 70%) - Gap of 159 uncovered new lines across 2 source files.
171+
3. **Types patch coverage: 97.2%** (target: passing) - Only 1 line uncovered in `global-settings.ts`.
172+
4. **Root cause**: This PR introduces 6 new files (`TerminalLifecycle.ts`, `TerminalProfileResolver.ts`, `ShellResolver.ts`, `CommandScheduler.ts`, `CommandTrace.ts`, `CommandEnvironmentService.ts`) totaling ~2,884 new lines, plus major additions to existing files. While test files exist for most of these, the tests cover only a fraction of the new code paths.
173+
5. **Platform-specific code**: Many uncovered lines are in platform-specific branches (Windows/macOS/Linux shell detection) that are difficult to test on a single platform.
174+
6. **Type-only files**: `shell/types.ts` (155 new lines, 0% coverage) is a pure type/interface file with no runtime code - codecov may still count it if it has executable statements (e.g., enum values or const assertions).
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Code Mode Task Report — Coverage Tests for PR #1125 (b05-shell-resolution-v2)
2+
3+
## Task Summary
4+
5+
Write tests to fix `codecov/patch` (80% backend) and `codecov/patch/webview-patch` (70%) for PR #1125. Coverage analysis at `163300_debug-coverage-b05.md` was found to be **stale** — the branch already contained committed test files (`CommandScheduler.spec.ts`, `TerminalLifecycle.spec.ts`, `ShellResolver.spec.ts`, `TerminalRegistry.spec.ts`, webview specs) that lifted real coverage far above the reported numbers. Verified actual gaps and closed the highest-value ones.
6+
7+
## Actions Taken
8+
9+
1. **Rebaselined coverage** (the report was stale):
10+
- Ran `npx vitest run --coverage integrations/terminal/__tests__/` → CommandScheduler 97.6%, TerminalLifecycle 93.75%, TerminalProfileResolver 83.45%, TerminalRegistry 76.38%, ShellResolver 76.03%.
11+
- Ran webview settings coverage → TerminalSettings.tsx 63.15%, SettingsView.tsx 70.75%.
12+
2. **Wrote `CommandTrace.spec.ts`** (new file, previously 8.69% covered, no test existed):
13+
- Full builder coverage: defaults, all chainable mark methods, exitCode handling, error marking, finalize via onComplete, finalize idempotency, collector emission.
14+
- Collector: singleton, subscribe/dispose, multi-listener order, listener error isolation, no-listener safety, `emitCommandTrace`.
15+
- Result: **CommandTrace.ts 100% lines**.
16+
3. **Wrote `CommandEnvironmentService.spec.ts`** (new file, previously 0% covered — never loaded by tests):
17+
- Success path per family (powershell/cmd/posix/fish/wsl): provider selection, chain operator (`;` vs `&&`), invocation args, prompt descriptor labels, syntax-support flags.
18+
- Failure path: fallback usage + warning, emergency fallback on Windows (cmd.exe) and Unix (/bin/sh).
19+
- Caching + invalidation (version counter), settings/cliOverride passthrough, defensive "Unknown" source label.
20+
- Result: **CommandEnvironmentService.ts 98.24% lines** (only unreachable `getFamilyLabel` default remains).
21+
4. **Extended `ShellResolver.spec.ts`** (+7 tests):
22+
- Bare-name normalization (`pwsh` → PS7, `cmd.exe` → cmd), empty-path `SHELL_OVERRIDE_INVALID`, allowlisted-but-missing `SHELL_EXECUTABLE_NOT_FOUND`, invalid legacy override rejectable error, fish display name, Unix env-probe fallback (exists and not-exists).
23+
- Result: **ShellResolver.ts 76.03% → 84.29% lines**.
24+
5. **Extended webview `TerminalSettings.shell.spec.tsx`** (+9 tests):
25+
- Non-auto option rendering, path option selection, `cmd` → canonical cmd.exe mapping, custom path button (`requestCustomShellPath`), dropdown value mapping for persisted path/cmd/profile/unknown-path selections, pending-selection sync on prop change.
26+
- Result: **TerminalSettings.tsx 63.15% → 80.26% lines** (above 70% target).
27+
28+
## Result
29+
30+
Success. All verification passed:
31+
32+
- Backend terminal suite: **427 passed, 12 skipped** (16 files + 1 skipped).
33+
- Webview settings suite: **313 passed** (30 files).
34+
- `CommandTrace.ts`: 100% lines · `CommandEnvironmentService.ts`: 98.24% · `ShellResolver.ts`: 84.29% · `TerminalSettings.tsx`: 80.26% · `SettingsView.tsx`: 70.75%.
35+
- ESLint clean on all modified files (`--max-warnings=0`).
36+
- `tsc --noEmit` clean for `src/` (webview-ui pre-existing `taskOrganization` type errors in unrelated untracked history/context spec files are NOT from this task).
37+
38+
## Issues Discovered
39+
40+
1. The debug coverage report (`163300_debug-coverage-b05.md`) is stale: it predates the committed test files and reports 17.5% backend / 15.4% webview, while actual coverage is far higher. CI codecov/patch will likely differ significantly from the report.
41+
2. `webview-ui/src/components/history/*.coverage.spec.tsx` and `ExtensionStateContext.messageHandler.spec.tsx` are untracked files (from another workstream) that fail `tsc` with `taskOrganization` type errors. Left untouched, not committed.
42+
3. `ShellResolver` has genuinely unreachable defensive branches (line 302 fallback path, line 358 unsupported-family) plus node-probe wrappers only reachable via `forRuntime` — acceptable residual coverage gaps.
43+
44+
## Next Step Recommendations
45+
46+
- Push the branch and re-run CI to observe actual codecov/patch numbers.
47+
- If patch still below threshold, next highest-value targets: `ExecaTerminal.ts` (20%), `BaseTerminal.ts` (67.7%), `Terminal.ts` (73.8%), `TerminalRegistry.ts` (76.4%), `utils/shell.ts` (has dedicated spec, covered in full CI run).
48+
- Confirm the untracked `taskOrganization` history spec files are handled by their owning workstream before merge.
49+
50+
## Affected File List
51+
52+
- `src/integrations/terminal/__tests__/CommandTrace.spec.ts` (new)
53+
- `src/integrations/terminal/__tests__/CommandEnvironmentService.spec.ts` (new)
54+
- `src/integrations/terminal/__tests__/ShellResolver.spec.ts` (modified)
55+
- `webview-ui/src/components/settings/__tests__/TerminalSettings.shell.spec.tsx` (modified)

0 commit comments

Comments
 (0)