@@ -32,7 +32,7 @@ Your goal is to help me arrive at the most elegant and effective solution by com
3232
3333##Test Coverage Guidelines
3434
35- Current status:** 74.35 % overall unit test coverage** with359 unit tests and 69 integration tests passing.
35+ Current status:** 78.49 % overall unit test coverage** with405 unit tests and 69 integration tests passing.
3636
3737###TDD Approach for New Features
3838
@@ -52,9 +52,10 @@ Current status: **74.35% overall unit test coverage** with 359 unit tests and 69
5252
5353###Testing Patterns to Follow
5454
55- - ** Create factory functions** for common test setups (see test-helpers.ts)
55+ - ** Use mock factories from test-helpers.ts** - 30+ factory functions available for all common types
56+ - ** No inline mock definitions** - always use factory functions for consistency
57+ - ** Minimal` as any ` usage** - reduced from 95 to 4 instances (96% reduction)
5658- ** Use createMockOutputChannelWithLogger()** for consistent Logger testing
57- - ** Avoid` as any ` ** - create proper mock types or use` as never ` for VS Code mocks
5859- ** Mock external dependencies** properly using vi.mock() with TypeScript types
5960- ** Test core functionality first** - constructor, main methods, error paths
6061- ** Ensure backward compatibility** by adding compatibility methods during refactoring
@@ -63,34 +64,60 @@ Current status: **74.35% overall unit test coverage** with 359 unit tests and 69
6364###Test Helper Patterns
6465
6566``` typescript
66- // Example factory function from test-helpers.ts
67- export function createMockOutputChannelWithLogger(options ? : {
68- verbose? : boolean ;
69- }): {
70- mockOutputChannel: { appendLine: ReturnType <typeof vi .fn > };
71- logger: Logger ;
72- }
67+ // Example factory functions from test-helpers.ts
68+
69+ // Storage variants
70+ export function createMockStorageWithAuth(): Storage
71+ export function createMockStorageMinimal(): Storage
72+
73+ // Workspace variants
74+ export function createMockWorkspaceRunning(): Workspace
75+ export function createMockWorkspaceStopped(): Workspace
76+ export function createMockWorkspaceFailed(): Workspace
77+
78+ // VSCode components
79+ export function createMockExtensionContext(): vscode .ExtensionContext
80+ export function createMockRemoteSSHExtension(): vscode .Extension <unknown >
81+ export function createMockTreeView<T >(): vscode .TreeView <T >
82+ export function createMockStatusBarItem(): vscode .StatusBarItem
83+ export function createMockQuickPick<T >(): vscode .QuickPick <T >
84+ export function createMockTerminal(): vscode .Terminal
85+ export function createMockOutputChannel(): vscode .OutputChannel
86+
87+ // Other utilities
88+ export function createMockWorkspaceProvider(): WorkspaceProvider
89+ export function createMockRemote(): Remote
90+ export function createMockCommands(): Commands
91+ export function createMockEventEmitter<T >(): vscode .EventEmitter <T >
92+ export function createMockAxiosInstance(): AxiosInstance
93+ export function createMockProxyAgent(): ProxyAgent
94+ export function createMockUri(path : string ,scheme ? : string ): vscode .Uri
7395```
7496
7597###Files with Excellent Coverage (> 90 % )- Use as Examples :
7698
7799- featureSet .ts :100 %
78100- proxy .ts :100 %
79101- logger .ts :98.44 % (good TDD example )
102+ - sshSupport .ts :98.13 %
80103- util .ts :97.31 %
81104- headers .ts :96.49 %
82105- api - helper .ts :96.36 %
83106- sshConfig .ts :96.21 %
84107- api .ts :95.52 %
108+ - extension .ts :93.07 % (refactored from 39.71 % using TDD )
109+ - workspaceMonitor .ts :92.37 %
85110- error .ts :90.44 %
111+ - cliManager .ts :90.05 %
86112
87113###Current Development Approach
88114
89115- ** TDD for new features ** - test first ,implement second
90116- ** Incremental refactoring ** - small ,measurable improvements
91117- ** Backward compatibility ** - add compatibility methods when changing interfaces
92- - ** Factory functions in test-helpers.ts** - reusable test setup patterns
93- - ** Systematic cleanup** - remove` as any ` casts, add proper types
118+ - ** Comprehensive mock factories ** - 30 + factory functions in test - helpers .ts
119+ - ** No inline mocks ** - all test mocks use factory functions
120+ - ** Type - safe testing ** - minimal ` as any ` usage (only 4 instances remain )
94121- ** Measure progress constantly ** - run ` yarn test:ci --coverage ` after every change
95122
96123###Refactoring Strategy
@@ -102,32 +129,34 @@ When replacing legacy patterns (e.g., writeToCoderOutputChannel):
1021293. Incrementally replace usage starting with highest - impact files
1031304. Maintain full test suite passing throughout
104131
105- ###Example:Logger Integration Pattern
132+ ###Example :TDD Refactoring Pattern ( extension . ts success story )
106133
107134` ` ` typescript
108- // 1. Add backward compatibility to new class
109- class Logger {
110- // ... new methods ...
111-
112- // Backward compatibility for legacy code
113- writeToCoderOutputChannel(message : string ): void {
114- this .info (message );
135+ // 1. Write test for extracted function FIRST
136+ describe("setupRemoteSSHExtension", () => {
137+ it("should configure remote SSH when available", () => {
138+ const mockExtension = createMockRemoteSSHExtension();
139+ const mockRemote = createMockRemote();
140+
141+ const result = setupRemoteSSHExtension(mockExtension);
142+
143+ expect(result).toBe(mockRemote);
144+ });
145+ });
146+
147+ // 2. Extract function to make test pass
148+ export function setupRemoteSSHExtension(
149+ remoteSSHExtension: vscode.Extension<unknown> | undefined,
150+ ): Remote | undefined {
151+ if (!remoteSSHExtension) {
152+ return undefined;
115153 }
154+ // Implementation here
116155}
117156
118- // 2. Create factory in test-helpers.ts
119- export function createMockOutputChannelWithLogger() {
120- const mockOutputChannel= { appendLine:vi .fn () };
121- const logger= new Logger (mockOutputChannel );
122- return {mockOutputChannel ,logger };
123- }
157+ // 3. Replace in original code
158+ const remoteSSHExtension = vscode.extensions.getExtension("ms-vscode-remote.remote-ssh");
159+ const remote = setupRemoteSSHExtension(remoteSSHExtension);
124160
125- // 3. Test compatibility before refactoring
126- it (" should be backward compatible" , ()=> {
127- const { mockOutputChannel, logger }= createMockOutputChannelWithLogger ();
128- logger .writeToCoderOutputChannel (" Test" );
129- expect (mockOutputChannel .appendLine ).toHaveBeenCalledWith (
130- expect .stringMatching (/ \[ . * \] \[ INFO\] Test/ )
131- );
132- });
161+ // Result: extension.ts coverage improved from 39.71% to 93.07%
133162` ` `