@@ -43,6 +43,94 @@ describe("opencode check", () => {
4343 } )
4444 } )
4545
46+ describe ( "command helpers" , ( ) => {
47+ it ( "selects where on Windows" , ( ) => {
48+ // #given win32 platform
49+ // #when selecting lookup command
50+ // #then should use where
51+ expect ( opencode . getBinaryLookupCommand ( "win32" ) ) . toBe ( "where" )
52+ } )
53+
54+ it ( "selects which on non-Windows" , ( ) => {
55+ // #given linux platform
56+ // #when selecting lookup command
57+ // #then should use which
58+ expect ( opencode . getBinaryLookupCommand ( "linux" ) ) . toBe ( "which" )
59+ expect ( opencode . getBinaryLookupCommand ( "darwin" ) ) . toBe ( "which" )
60+ } )
61+
62+ it ( "parses command output into paths" , ( ) => {
63+ // #given raw output with multiple lines and spaces
64+ const output = "C:\\\\bin\\\\opencode.ps1\r\nC:\\\\bin\\\\opencode.exe\n\n"
65+
66+ // #when parsing
67+ const paths = opencode . parseBinaryPaths ( output )
68+
69+ // #then should return trimmed, non-empty paths
70+ expect ( paths ) . toEqual ( [ "C:\\\\bin\\\\opencode.ps1" , "C:\\\\bin\\\\opencode.exe" ] )
71+ } )
72+
73+ it ( "prefers exe/cmd/bat over ps1 on Windows" , ( ) => {
74+ // #given windows paths
75+ const paths = [
76+ "C:\\\\bin\\\\opencode.ps1" ,
77+ "C:\\\\bin\\\\opencode.cmd" ,
78+ "C:\\\\bin\\\\opencode.exe" ,
79+ ]
80+
81+ // #when selecting binary
82+ const selected = opencode . selectBinaryPath ( paths , "win32" )
83+
84+ // #then should prefer exe
85+ expect ( selected ) . toBe ( "C:\\\\bin\\\\opencode.exe" )
86+ } )
87+
88+ it ( "falls back to ps1 when it is the only Windows candidate" , ( ) => {
89+ // #given only ps1 path
90+ const paths = [ "C:\\\\bin\\\\opencode.ps1" ]
91+
92+ // #when selecting binary
93+ const selected = opencode . selectBinaryPath ( paths , "win32" )
94+
95+ // #then should return ps1 path
96+ expect ( selected ) . toBe ( "C:\\\\bin\\\\opencode.ps1" )
97+ } )
98+
99+ it ( "builds PowerShell command for ps1 on Windows" , ( ) => {
100+ // #given a ps1 path on Windows
101+ const command = opencode . buildVersionCommand (
102+ "C:\\\\bin\\\\opencode.ps1" ,
103+ "win32"
104+ )
105+
106+ // #when building command
107+ // #then should use PowerShell
108+ expect ( command ) . toEqual ( [
109+ "powershell" ,
110+ "-NoProfile" ,
111+ "-ExecutionPolicy" ,
112+ "Bypass" ,
113+ "-File" ,
114+ "C:\\\\bin\\\\opencode.ps1" ,
115+ "--version" ,
116+ ] )
117+ } )
118+
119+ it ( "builds direct command for non-ps1 binaries" , ( ) => {
120+ // #given an exe on Windows and a binary on linux
121+ const winCommand = opencode . buildVersionCommand (
122+ "C:\\\\bin\\\\opencode.exe" ,
123+ "win32"
124+ )
125+ const linuxCommand = opencode . buildVersionCommand ( "opencode" , "linux" )
126+
127+ // #when building commands
128+ // #then should execute directly
129+ expect ( winCommand ) . toEqual ( [ "C:\\\\bin\\\\opencode.exe" , "--version" ] )
130+ expect ( linuxCommand ) . toEqual ( [ "opencode" , "--version" ] )
131+ } )
132+ } )
133+
46134 describe ( "getOpenCodeInfo" , ( ) => {
47135 it ( "returns installed: false when binary not found" , async ( ) => {
48136 // #given no opencode binary
0 commit comments