Skip to content

Commit 2fd77d4

Browse files
committed
fix(wrapper): correct disable guidance
1 parent 485a752 commit 2fd77d4

3 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎src/command/wrapper/socket-wrapper-addition.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function addSocketWrapper(file: string): Promise<void> {
2626
`The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉`,
2727
)
2828
logger.log(
29-
' If you want to disable it at any time, run `socket wrapper --disable`',
29+
' If you want to disable it at any time, run `socket wrapper off`',
3030
)
3131
logger.log('')
3232
logger.info(

‎test/integration/cli/cmd-wrapper.test.mts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
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'
1820
import 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

2225
import {
2326
FLAG_CONFIG,
@@ -43,6 +46,55 @@ const fixtureHome = path.join(
4346
const fixtureHomeEnv = { HOME: fixtureHome, USERPROFILE: fixtureHome }
4447

4548
describe('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}`,

‎test/unit/command/wrapper/socket-wrapper-addition.test.mts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,6 @@ describe('addSocketWrapper', () => {
108108
)
109109
})
110110

111-
it('logs disable instructions', async () => {
112-
await import('@socketsecurity/lib-stable/logger/default')
113-
const fs = await import('node:fs')
114-
const mockAppendFile = vi.mocked(fs.promises.appendFile)
115-
116-
mockAppendFile.mockResolvedValue(undefined)
117-
118-
await addSocketWrapper('/home/user/.bashrc')
119-
120-
expect(mockLogger.log).toHaveBeenCalledWith(
121-
' If you want to disable it at any time, run `socket wrapper --disable`',
122-
)
123-
})
124-
125111
it('handles different shell config files', async () => {
126112
const fs = await import('node:fs')
127113
const mockAppendFile = vi.mocked(fs.promises.appendFile)

0 commit comments

Comments
 (0)