11import { it , expect , describe } from "vitest" ;
2- import { type WorkspaceConfiguration } from "vscode" ;
32
43import { getGlobalFlags , getGlobalFlagsRaw , getSshFlags } from "@/cliConfig" ;
54
5+ import { MockConfigurationProvider } from "../mocks/testHelpers" ;
66import { isWindows } from "../utils/platform" ;
77
88describe ( "cliConfig" , ( ) => {
99 describe ( "getGlobalFlags" , ( ) => {
1010 it ( "should return global-config and header args when no global flags configured" , ( ) => {
11- const config = {
12- get : ( _key : string , defaultValue : unknown ) => defaultValue ,
13- } as unknown as WorkspaceConfiguration ;
11+ const config = new MockConfigurationProvider ( ) ;
1412
1513 expect ( getGlobalFlags ( config , "/config/dir" ) ) . toStrictEqual ( [
1614 "--global-config" ,
@@ -19,12 +17,11 @@ describe("cliConfig", () => {
1917 } ) ;
2018
2119 it ( "should return global flags from config with global-config appended" , ( ) => {
22- const config = {
23- get : ( key : string ) =>
24- key === "coder.globalFlags"
25- ? [ "--verbose" , "--disable-direct-connections" ]
26- : undefined ,
27- } as unknown as WorkspaceConfiguration ;
20+ const config = new MockConfigurationProvider ( ) ;
21+ config . set ( "coder.globalFlags" , [
22+ "--verbose" ,
23+ "--disable-direct-connections" ,
24+ ] ) ;
2825
2926 expect ( getGlobalFlags ( config , "/config/dir" ) ) . toStrictEqual ( [
3027 "--verbose" ,
@@ -35,16 +32,12 @@ describe("cliConfig", () => {
3532 } ) ;
3633
3734 it ( "should not filter duplicate global-config flags, last takes precedence" , ( ) => {
38- const config = {
39- get : ( key : string ) =>
40- key === "coder.globalFlags"
41- ? [
42- "-v" ,
43- "--global-config /path/to/ignored" ,
44- "--disable-direct-connections" ,
45- ]
46- : undefined ,
47- } as unknown as WorkspaceConfiguration ;
35+ const config = new MockConfigurationProvider ( ) ;
36+ config . set ( "coder.globalFlags" , [
37+ "-v" ,
38+ "--global-config /path/to/ignored" ,
39+ "--disable-direct-connections" ,
40+ ] ) ;
4841
4942 expect ( getGlobalFlags ( config , "/config/dir" ) ) . toStrictEqual ( [
5043 "-v" ,
@@ -57,17 +50,13 @@ describe("cliConfig", () => {
5750
5851 it ( "should not filter header-command flags, header args appended at end" , ( ) => {
5952 const headerCommand = "echo test" ;
60- const config = {
61- get : ( key : string ) => {
62- if ( key === "coder.headerCommand" ) {
63- return headerCommand ;
64- }
65- if ( key === "coder.globalFlags" ) {
66- return [ "-v" , "--header-command custom" , "--no-feature-warning" ] ;
67- }
68- return undefined ;
69- } ,
70- } as unknown as WorkspaceConfiguration ;
53+ const config = new MockConfigurationProvider ( ) ;
54+ config . set ( "coder.headerCommand" , headerCommand ) ;
55+ config . set ( "coder.globalFlags" , [
56+ "-v" ,
57+ "--header-command custom" ,
58+ "--no-feature-warning" ,
59+ ] ) ;
7160
7261 const result = getGlobalFlags ( config , "/config/dir" ) ;
7362 expect ( result ) . toStrictEqual ( [
@@ -84,20 +73,17 @@ describe("cliConfig", () => {
8473
8574 describe ( "getGlobalFlagsRaw" , ( ) => {
8675 it ( "returns empty array when no global flags configured" , ( ) => {
87- const config = {
88- get : ( _key : string , defaultValue : unknown ) => defaultValue ,
89- } as unknown as WorkspaceConfiguration ;
76+ const config = new MockConfigurationProvider ( ) ;
9077
9178 expect ( getGlobalFlagsRaw ( config ) ) . toStrictEqual ( [ ] ) ;
9279 } ) ;
9380
9481 it ( "returns global flags from config" , ( ) => {
95- const config = {
96- get : ( key : string ) =>
97- key === "coder.globalFlags"
98- ? [ "--verbose" , "--disable-direct-connections" ]
99- : undefined ,
100- } as unknown as WorkspaceConfiguration ;
82+ const config = new MockConfigurationProvider ( ) ;
83+ config . set ( "coder.globalFlags" , [
84+ "--verbose" ,
85+ "--disable-direct-connections" ,
86+ ] ) ;
10187
10288 expect ( getGlobalFlagsRaw ( config ) ) . toStrictEqual ( [
10389 "--verbose" ,
@@ -108,20 +94,18 @@ describe("cliConfig", () => {
10894
10995 describe ( "getSshFlags" , ( ) => {
11096 it ( "returns default flags when no SSH flags configured" , ( ) => {
111- const config = {
112- get : ( _key : string , defaultValue : unknown ) => defaultValue ,
113- } as unknown as WorkspaceConfiguration ;
97+ const config = new MockConfigurationProvider ( ) ;
11498
11599 expect ( getSshFlags ( config ) ) . toStrictEqual ( [ "--disable-autostart" ] ) ;
116100 } ) ;
117101
118102 it ( "returns SSH flags from config" , ( ) => {
119- const config = {
120- get : ( key : string ) =>
121- key === "coder.sshFlags"
122- ? [ "--disable-autostart" , "-- wait=yes", "--ssh-host-prefix=custom" ]
123- : undefined ,
124- } as unknown as WorkspaceConfiguration ;
103+ const config = new MockConfigurationProvider ( ) ;
104+ config . set ( "coder.sshFlags" , [
105+ "--disable-autostart" ,
106+ "--wait=yes" ,
107+ "--ssh-host-prefix=custom" ,
108+ ] ) ;
125109
126110 expect ( getSshFlags ( config ) ) . toStrictEqual ( [
127111 "--disable-autostart" ,
0 commit comments