@@ -7,13 +7,24 @@ import { TerminalProcess } from "../TerminalProcess"
77import { Terminal } from "../Terminal"
88import { TerminalRegistry } from "../TerminalRegistry"
99
10+ class TestTerminalProcess extends TerminalProcess {
11+ public callTrimRetrievedOutput ( ) : void {
12+ this . trimRetrievedOutput ( )
13+ }
14+ }
15+
1016vi . mock ( "execa" , ( ) => ( {
1117 execa : vi . fn ( ) ,
1218} ) )
1319
1420describe ( "TerminalProcess" , ( ) => {
15- let terminalProcess : TerminalProcess
21+ let terminalProcess : TestTerminalProcess
1622 let mockTerminal : any
23+ type TestVscodeTerminal = vscode . Terminal & {
24+ shellIntegration : {
25+ executeCommand : any
26+ }
27+ }
1728 let mockTerminalInfo : Terminal
1829 let mockExecution : any
1930 let mockStream : AsyncIterableIterator < string >
@@ -33,16 +44,12 @@ describe("TerminalProcess", () => {
3344 hide : vi . fn ( ) ,
3445 show : vi . fn ( ) ,
3546 sendText : vi . fn ( ) ,
36- } as unknown as vscode . Terminal & {
37- shellIntegration : {
38- executeCommand : any
39- }
40- }
47+ } as unknown as TestVscodeTerminal
4148
4249 mockTerminalInfo = new Terminal ( 1 , mockTerminal , "./" )
4350
4451 // Create a process for testing
45- terminalProcess = new TerminalProcess ( mockTerminalInfo )
52+ terminalProcess = new TestTerminalProcess ( mockTerminalInfo )
4653
4754 TerminalRegistry [ "terminals" ] . push ( mockTerminalInfo )
4855
@@ -239,6 +246,49 @@ describe("TerminalProcess", () => {
239246 } )
240247 } )
241248
249+ describe ( "trimRetrievedOutput" , ( ) => {
250+ it ( "clears buffer when all output has been retrieved" , ( ) => {
251+ // Set up a scenario where all output has been retrieved
252+ terminalProcess [ "fullOutput" ] = "test output data"
253+ terminalProcess [ "lastRetrievedIndex" ] = 16 // Same as fullOutput.length
254+
255+ terminalProcess . callTrimRetrievedOutput ( )
256+
257+ expect ( terminalProcess [ "fullOutput" ] ) . toBe ( "" )
258+ expect ( terminalProcess [ "lastRetrievedIndex" ] ) . toBe ( 0 )
259+ } )
260+
261+ it ( "does not clear buffer when there is unretrieved output" , ( ) => {
262+ // Set up a scenario where not all output has been retrieved
263+ terminalProcess [ "fullOutput" ] = "test output data"
264+ terminalProcess [ "lastRetrievedIndex" ] = 5 // Less than fullOutput.length
265+ terminalProcess . callTrimRetrievedOutput ( )
266+
267+ // Buffer should NOT be cleared - there's still unretrieved content
268+ expect ( terminalProcess [ "fullOutput" ] ) . toBe ( "test output data" )
269+ expect ( terminalProcess [ "lastRetrievedIndex" ] ) . toBe ( 5 )
270+ } )
271+
272+ it ( "does nothing when buffer is already empty" , ( ) => {
273+ terminalProcess [ "fullOutput" ] = ""
274+ terminalProcess [ "lastRetrievedIndex" ] = 0
275+ terminalProcess . callTrimRetrievedOutput ( )
276+
277+ expect ( terminalProcess [ "fullOutput" ] ) . toBe ( "" )
278+ expect ( terminalProcess [ "lastRetrievedIndex" ] ) . toBe ( 0 )
279+ } )
280+
281+ it ( "clears buffer when lastRetrievedIndex exceeds fullOutput length" , ( ) => {
282+ // Edge case: index is greater than current length (could happen if output was modified)
283+ terminalProcess [ "fullOutput" ] = "short"
284+ terminalProcess [ "lastRetrievedIndex" ] = 100
285+ terminalProcess . callTrimRetrievedOutput ( )
286+
287+ expect ( terminalProcess [ "fullOutput" ] ) . toBe ( "" )
288+ expect ( terminalProcess [ "lastRetrievedIndex" ] ) . toBe ( 0 )
289+ } )
290+ } )
291+
242292 describe ( "mergePromise" , ( ) => {
243293 it ( "merges promise methods with terminal process" , async ( ) => {
244294 const process = new TerminalProcess ( mockTerminalInfo )
0 commit comments