Skip to content

Commit 8f870e4

Browse files
committed
add --silence flag to suppress non-output stdout/stderr when running socket fix
1 parent 4761498 commit 8f870e4

13 files changed

+247
-76
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [1.1.52](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.52) - 2026-01-02
8+
9+
### Added
10+
- Added `--silence` flag to `socket fix` to suppress intermediate output and show only the final result.
11+
712
## [1.1.51](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.51) - 2025-12-23
813

914
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "1.1.51",
3+
"version": "1.1.52",
44
"description": "CLI for Socket.dev",
55
"homepage": "https://github.com/SocketDev/socket-cli",
66
"license": "MIT AND OFL-1.1",

src/commands/ci/fetch-default-org-slug.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { fetchOrganization } from '../organization/fetch-organization-list.mts'
77
import type { CResult } from '../../types.mts'
88

99
// Use the config defaultOrg when set, otherwise discover from remote.
10-
export async function getDefaultOrgSlug(): Promise<CResult<string>> {
10+
export async function getDefaultOrgSlug(silence?: boolean): Promise<CResult<string>> {
1111
const defaultOrgResult = getConfigValueOrUndef('defaultOrg')
1212
if (defaultOrgResult) {
1313
debugFn(
@@ -28,7 +28,7 @@ export async function getDefaultOrgSlug(): Promise<CResult<string>> {
2828
return { ok: true, data: envOrgSlug }
2929
}
3030

31-
const orgsCResult = await fetchOrganization()
31+
const orgsCResult = await fetchOrganization({ silence })
3232
if (!orgsCResult.ok) {
3333
return orgsCResult
3434
}

src/commands/fix/cmd-fix.e2e.test.mts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,70 @@ describe('socket fix (E2E tests)', async () => {
402402
},
403403
{ timeout: testTimeout },
404404
)
405+
406+
cmdit(
407+
['fix', '--silence', '--json', '.'],
408+
'should output only parseable JSON when --silence and --json flags are used',
409+
async cmd => {
410+
const tempFixture = await createTempFixtureCopy('e2e-test-js')
411+
let stdout = ''
412+
let stderr = ''
413+
let code = -1
414+
415+
try {
416+
const result = await spawnSocketCli(binCliPath, cmd, {
417+
cwd: tempFixture.path,
418+
env: getTestEnv(apiToken),
419+
})
420+
stdout = result.stdout
421+
stderr = result.stderr
422+
code = result.code
423+
424+
if (code !== 0) {
425+
logCommandOutput(code, stdout, stderr)
426+
}
427+
428+
expect(code, 'should exit with code 0').toBe(0)
429+
430+
// Verify stdout is valid JSON and nothing else.
431+
const trimmedStdout = stdout.trim()
432+
expect(
433+
trimmedStdout.length,
434+
'stdout should not be empty',
435+
).toBeGreaterThan(0)
436+
437+
let parsedJson: unknown
438+
try {
439+
parsedJson = JSON.parse(trimmedStdout)
440+
} catch {
441+
// Log the actual output to help debug what extra content was included.
442+
logger.error('stdout is not valid JSON:', trimmedStdout)
443+
throw new Error(
444+
`Expected stdout to be valid JSON, but got: ${trimmedStdout.slice(0, 200)}...`,
445+
)
446+
}
447+
448+
expect(parsedJson).toBeDefined()
449+
expect(typeof parsedJson).toBe('object')
450+
451+
// Verify stderr is empty (no extra logging output).
452+
expect(
453+
stderr.trim(),
454+
'stderr should be empty when --silence is used',
455+
).toBe('')
456+
457+
logger.info('\nSuccessfully verified --silence --json outputs only JSON')
458+
} catch (e) {
459+
if (code !== 0) {
460+
logCommandOutput(code, stdout, stderr)
461+
}
462+
throw e
463+
} finally {
464+
await tempFixture.cleanup()
465+
}
466+
},
467+
{ timeout: testTimeout },
468+
)
405469
})
406470

407471
describe('Python projects', () => {

src/commands/fix/cmd-fix.integration.test.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('socket fix', async () => {
172172
--fix-version Override the version of @coana-tech/cli used for fix analysis. Default: <coana-version>.
173173
--id Provide a list of vulnerability identifiers to compute fixes for:
174174
- GHSA IDs (https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids) (e.g., GHSA-xxxx-xxxx-xxxx)
175-
- CVE IDs (https://cve.mitre.org/cve/identifiers/) (e.g., CVE-2025-1234) - automatically converted to GHSA
175+
- CVE IDs (https://cve.mitre.org/cve/identifiers/) (e.g., CVE-2026-1234) - automatically converted to GHSA
176176
- PURLs (https://github.com/package-url/purl-spec) (e.g., pkg:npm/[email protected]) - automatically converted to GHSA
177177
Can be provided as comma separated values or as multiple flags. Cannot be used with --all.
178178
--include Include workspaces matching these glob patterns. Can be provided as comma separated values or as multiple flags
@@ -188,6 +188,7 @@ describe('socket fix', async () => {
188188
* pin - Use the exact version (e.g. 1.2.3)
189189
* preserve - Retain the existing version range style as-is
190190
--show-affected-direct-dependencies List the direct dependencies responsible for introducing transitive vulnerabilities and list the updates required to resolve the vulnerabilities
191+
--silence Silence all output except the final result
191192
192193
Environment Variables (for CI/PR mode)
193194
CI Set to enable CI mode

src/commands/fix/cmd-fix.mts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ Available styles:
167167
description:
168168
'List the direct dependencies responsible for introducing transitive vulnerabilities and list the updates required to resolve the vulnerabilities',
169169
},
170+
silence: {
171+
type: 'boolean',
172+
default: false,
173+
description:
174+
'Silence all output except the final result',
175+
},
170176
}
171177

172178
const hiddenFlags: MeowFlags = {
@@ -303,6 +309,7 @@ async function run(
303309
prLimit,
304310
rangeStyle,
305311
showAffectedDirectDependencies,
312+
silence,
306313
// We patched in this feature with `npx custompatch meow` at
307314
// socket-cli/patches/meow#13.2.0.patch.
308315
unknownFlags = [],
@@ -326,6 +333,7 @@ async function run(
326333
prLimit: number
327334
rangeStyle: RangeStyle
328335
showAffectedDirectDependencies: boolean
336+
silence: boolean
329337
unknownFlags?: string[]
330338
}
331339

@@ -391,7 +399,7 @@ async function run(
391399
return
392400
}
393401

394-
const orgSlugCResult = await getDefaultOrgSlug()
402+
const orgSlugCResult = await getDefaultOrgSlug(silence)
395403
if (!orgSlugCResult.ok) {
396404
process.exitCode = orgSlugCResult.code ?? 1
397405
logger.fail(
@@ -433,6 +441,7 @@ async function run(
433441
prLimit,
434442
rangeStyle,
435443
showAffectedDirectDependencies,
444+
silence,
436445
spinner,
437446
unknownFlags,
438447
})

0 commit comments

Comments
 (0)