1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ import { strictEqual } from 'assert' ;
7
+ import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js' ;
8
+ import { detectsCommonPromptPattern } from '../../browser/executeStrategy/executeStrategy.js' ;
9
+
10
+ suite ( 'Execute Strategy - Prompt Detection' , ( ) => {
11
+ ensureNoDisposablesAreLeakedInTestSuite ( ) ;
12
+
13
+ test ( 'detectsCommonPromptPattern should detect PowerShell prompts' , ( ) => {
14
+ strictEqual ( detectsCommonPromptPattern ( 'PS C:\\>' ) , true ) ;
15
+ strictEqual ( detectsCommonPromptPattern ( 'PS C:\\Windows\\System32>' ) , true ) ;
16
+ strictEqual ( detectsCommonPromptPattern ( 'PS C:\\Users\\test> ' ) , true ) ;
17
+ } ) ;
18
+
19
+ test ( 'detectsCommonPromptPattern should detect Command Prompt' , ( ) => {
20
+ strictEqual ( detectsCommonPromptPattern ( 'C:\\>' ) , true ) ;
21
+ strictEqual ( detectsCommonPromptPattern ( 'C:\\Windows\\System32>' ) , true ) ;
22
+ strictEqual ( detectsCommonPromptPattern ( 'D:\\test> ' ) , true ) ;
23
+ } ) ;
24
+
25
+ test ( 'detectsCommonPromptPattern should detect Bash prompts' , ( ) => {
26
+ strictEqual ( detectsCommonPromptPattern ( 'user@host:~$ ' ) , true ) ;
27
+ strictEqual ( detectsCommonPromptPattern ( '$ ' ) , true ) ;
28
+ strictEqual ( detectsCommonPromptPattern ( '[user@host ~]$ ' ) , true ) ;
29
+ } ) ;
30
+
31
+ test ( 'detectsCommonPromptPattern should detect root prompts' , ( ) => {
32
+ strictEqual ( detectsCommonPromptPattern ( 'root@host:~# ' ) , true ) ;
33
+ strictEqual ( detectsCommonPromptPattern ( '# ' ) , true ) ;
34
+ strictEqual ( detectsCommonPromptPattern ( '[root@host ~]# ' ) , true ) ;
35
+ } ) ;
36
+
37
+ test ( 'detectsCommonPromptPattern should detect Python REPL' , ( ) => {
38
+ strictEqual ( detectsCommonPromptPattern ( '>>> ' ) , true ) ;
39
+ strictEqual ( detectsCommonPromptPattern ( '>>>' ) , true ) ;
40
+ } ) ;
41
+
42
+ test ( 'detectsCommonPromptPattern should detect starship prompts' , ( ) => {
43
+ strictEqual ( detectsCommonPromptPattern ( '~ ❯ ' ) , true ) ;
44
+ strictEqual ( detectsCommonPromptPattern ( '/path/to/project ❯' ) , true ) ;
45
+ } ) ;
46
+
47
+ test ( 'detectsCommonPromptPattern should detect generic prompts' , ( ) => {
48
+ strictEqual ( detectsCommonPromptPattern ( 'test> ' ) , true ) ;
49
+ strictEqual ( detectsCommonPromptPattern ( 'someprompt% ' ) , true ) ;
50
+ } ) ;
51
+
52
+ test ( 'detectsCommonPromptPattern should handle multiline content' , ( ) => {
53
+ const multilineContent = `command output line 1
54
+ command output line 2
55
+ user@host:~$ ` ;
56
+ strictEqual ( detectsCommonPromptPattern ( multilineContent ) , true ) ;
57
+ } ) ;
58
+
59
+ test ( 'detectsCommonPromptPattern should reject non-prompt content' , ( ) => {
60
+ strictEqual ( detectsCommonPromptPattern ( 'just some output' ) , false ) ;
61
+ strictEqual ( detectsCommonPromptPattern ( 'error: command not found' ) , false ) ;
62
+ strictEqual ( detectsCommonPromptPattern ( '' ) , false ) ;
63
+ strictEqual ( detectsCommonPromptPattern ( ' ' ) , false ) ;
64
+ } ) ;
65
+
66
+ test ( 'detectsCommonPromptPattern should handle edge cases' , ( ) => {
67
+ strictEqual ( detectsCommonPromptPattern ( 'output\n\n\n' ) , false ) ;
68
+ strictEqual ( detectsCommonPromptPattern ( '\n\n$ \n\n' ) , true ) ; // prompt with surrounding whitespace
69
+ strictEqual ( detectsCommonPromptPattern ( 'output\nPS C:\\> ' ) , true ) ; // prompt at end after output
70
+ } ) ;
71
+ } ) ;
0 commit comments