1515 * src/command/wrapper/handle-wrapper.mts - Wrapper management logic.
1616 */
1717
18+ import { promises as fs } from 'node:fs'
19+ import os from 'node:os'
1820import path from 'node:path'
1921
20- import { describe , expect } from 'vitest'
22+ import { safeDelete } from '@socketsecurity/lib-stable/fs/safe'
23+ import { describe , expect , it } from 'vitest'
2124
2225import {
2326 FLAG_CONFIG ,
@@ -43,6 +46,55 @@ const fixtureHome = path.join(
4346const fixtureHomeEnv = { HOME : fixtureHome , USERPROFILE : fixtureHome }
4447
4548describe ( 'socket wrapper' , async ( ) => {
49+ it ( 'prints the supported command to disable the wrapper' , async ( ) => {
50+ const temporaryHome = await fs . mkdtemp (
51+ path . join ( os . tmpdir ( ) , 'socket-wrapper-' ) ,
52+ )
53+ const profilePath = path . join ( temporaryHome , '.bashrc' )
54+ const configDirectory = path . join ( temporaryHome , 'config' )
55+ const env = {
56+ HOME : temporaryHome ,
57+ USERPROFILE : temporaryHome ,
58+ XDG_CONFIG_HOME : configDirectory ,
59+ }
60+
61+ try {
62+ await fs . mkdir ( configDirectory )
63+ await fs . writeFile ( profilePath , '' )
64+
65+ const enabled = await spawnSocketCli (
66+ binCliPath ,
67+ [ 'wrapper' , 'on' , FLAG_CONFIG , '{}' ] ,
68+ { env } ,
69+ )
70+ expect ( enabled . code ) . toBe ( 0 )
71+ expect ( `${ enabled . stdout } \n${ enabled . stderr } ` ) . toContain (
72+ '`socket wrapper off`' ,
73+ )
74+ expect ( `${ enabled . stdout } \n${ enabled . stderr } ` ) . not . toContain (
75+ '`socket wrapper --disable`' ,
76+ )
77+ expect ( await fs . readFile ( profilePath , 'utf8' ) ) . toContain (
78+ 'alias npm="socket npm"' ,
79+ )
80+
81+ const disabled = await spawnSocketCli (
82+ binCliPath ,
83+ [ 'wrapper' , 'off' , FLAG_CONFIG , '{}' ] ,
84+ { env } ,
85+ )
86+ expect ( disabled . code ) . toBe ( 0 )
87+ expect ( await fs . readFile ( profilePath , 'utf8' ) ) . not . toContain (
88+ 'alias npm="socket npm"' ,
89+ )
90+ expect ( await fs . readFile ( profilePath , 'utf8' ) ) . not . toContain (
91+ 'alias npx="socket npx"' ,
92+ )
93+ } finally {
94+ await safeDelete ( temporaryHome )
95+ }
96+ } )
97+
4698 cmdit (
4799 [ 'wrapper' , FLAG_HELP , FLAG_CONFIG , '{}' ] ,
48100 `should support ${ FLAG_HELP } ` ,
0 commit comments