diff --git a/src/command/wrapper/socket-wrapper-addition.mts b/src/command/wrapper/socket-wrapper-addition.mts index 59f9947fe..883e7ce71 100644 --- a/src/command/wrapper/socket-wrapper-addition.mts +++ b/src/command/wrapper/socket-wrapper-addition.mts @@ -26,7 +26,7 @@ export async function addSocketWrapper(file: string): Promise { `The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉`, ) logger.log( - ' If you want to disable it at any time, run `socket wrapper --disable`', + ' If you want to disable it at any time, run `socket wrapper off`', ) logger.log('') logger.info( diff --git a/test/integration/cli/cmd-wrapper.test.mts b/test/integration/cli/cmd-wrapper.test.mts index 4394baf33..c0ce0b4be 100644 --- a/test/integration/cli/cmd-wrapper.test.mts +++ b/test/integration/cli/cmd-wrapper.test.mts @@ -15,9 +15,12 @@ * src/command/wrapper/handle-wrapper.mts - Wrapper management logic. */ +import { promises as fs } from 'node:fs' +import os from 'node:os' import path from 'node:path' -import { describe, expect } from 'vitest' +import { safeDelete } from '@socketsecurity/lib-stable/fs/safe' +import { describe, expect, it } from 'vitest' import { FLAG_CONFIG, @@ -43,6 +46,55 @@ const fixtureHome = path.join( const fixtureHomeEnv = { HOME: fixtureHome, USERPROFILE: fixtureHome } describe('socket wrapper', async () => { + it('prints the supported command to disable the wrapper', async () => { + const temporaryHome = await fs.mkdtemp( + path.join(os.tmpdir(), 'socket-wrapper-'), + ) + const profilePath = path.join(temporaryHome, '.bashrc') + const configDirectory = path.join(temporaryHome, 'config') + const env = { + HOME: temporaryHome, + USERPROFILE: temporaryHome, + XDG_CONFIG_HOME: configDirectory, + } + + try { + await fs.mkdir(configDirectory) + await fs.writeFile(profilePath, '') + + const enabled = await spawnSocketCli( + binCliPath, + ['wrapper', 'on', FLAG_CONFIG, '{}'], + { env }, + ) + expect(enabled.code).toBe(0) + expect(`${enabled.stdout}\n${enabled.stderr}`).toContain( + '`socket wrapper off`', + ) + expect(`${enabled.stdout}\n${enabled.stderr}`).not.toContain( + '`socket wrapper --disable`', + ) + expect(await fs.readFile(profilePath, 'utf8')).toContain( + 'alias npm="socket npm"', + ) + + const disabled = await spawnSocketCli( + binCliPath, + ['wrapper', 'off', FLAG_CONFIG, '{}'], + { env }, + ) + expect(disabled.code).toBe(0) + expect(await fs.readFile(profilePath, 'utf8')).not.toContain( + 'alias npm="socket npm"', + ) + expect(await fs.readFile(profilePath, 'utf8')).not.toContain( + 'alias npx="socket npx"', + ) + } finally { + await safeDelete(temporaryHome) + } + }) + cmdit( ['wrapper', FLAG_HELP, FLAG_CONFIG, '{}'], `should support ${FLAG_HELP}`, diff --git a/test/unit/command/wrapper/socket-wrapper-addition.test.mts b/test/unit/command/wrapper/socket-wrapper-addition.test.mts index 0342f6ceb..ea3f1ad90 100644 --- a/test/unit/command/wrapper/socket-wrapper-addition.test.mts +++ b/test/unit/command/wrapper/socket-wrapper-addition.test.mts @@ -108,20 +108,6 @@ describe('addSocketWrapper', () => { ) }) - it('logs disable instructions', async () => { - await import('@socketsecurity/lib-stable/logger/default') - const fs = await import('node:fs') - const mockAppendFile = vi.mocked(fs.promises.appendFile) - - mockAppendFile.mockResolvedValue(undefined) - - await addSocketWrapper('/home/user/.bashrc') - - expect(mockLogger.log).toHaveBeenCalledWith( - ' If you want to disable it at any time, run `socket wrapper --disable`', - ) - }) - it('handles different shell config files', async () => { const fs = await import('node:fs') const mockAppendFile = vi.mocked(fs.promises.appendFile)