Skip to content

Commit 1d9688c

Browse files
authored
add --silence flag to socket fix (#1008)
* add --silence flag to suppress non-output stdout/stderr when running socket fix * fix silence bug. debug output to e2e reachability tests * upgrade coana. fix formatting
1 parent 4761498 commit 1d9688c

16 files changed

+317
-90
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ 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+
12+
### Changed
13+
- Updated the Coana CLI to v `14.12.139`.
14+
715
## [1.1.51](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.51) - 2025-12-23
816

917
### Added

package.json

Lines changed: 2 additions & 2 deletions
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",
@@ -94,7 +94,7 @@
9494
"@babel/preset-typescript": "7.27.1",
9595
"@babel/runtime": "7.28.4",
9696
"@biomejs/biome": "2.2.4",
97-
"@coana-tech/cli": "14.12.138",
97+
"@coana-tech/cli": "14.12.139",
9898
"@cyclonedx/cdxgen": "11.11.0",
9999
"@dotenvx/dotenvx": "1.49.0",
100100
"@eslint/compat": "1.3.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ 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(
11+
silence?: boolean,
12+
): Promise<CResult<string>> {
1113
const defaultOrgResult = getConfigValueOrUndef('defaultOrg')
1214
if (defaultOrgResult) {
1315
debugFn(
@@ -28,7 +30,7 @@ export async function getDefaultOrgSlug(): Promise<CResult<string>> {
2830
return { ok: true, data: envOrgSlug }
2931
}
3032

31-
const orgsCResult = await fetchOrganization()
33+
const orgsCResult = await fetchOrganization({ silence })
3234
if (!orgsCResult.ok) {
3335
return orgsCResult
3436
}

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,72 @@ 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(
458+
'\nSuccessfully verified --silence --json outputs only JSON',
459+
)
460+
} catch (e) {
461+
if (code !== 0) {
462+
logCommandOutput(code, stdout, stderr)
463+
}
464+
throw e
465+
} finally {
466+
await tempFixture.cleanup()
467+
}
468+
},
469+
{ timeout: testTimeout },
470+
)
405471
})
406472

407473
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/package@1.0.0) - 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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ 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: 'Silence all output except the final result',
174+
},
170175
}
171176

172177
const hiddenFlags: MeowFlags = {
@@ -303,6 +308,7 @@ async function run(
303308
prLimit,
304309
rangeStyle,
305310
showAffectedDirectDependencies,
311+
silence,
306312
// We patched in this feature with `npx custompatch meow` at
307313
// socket-cli/patches/meow#13.2.0.patch.
308314
unknownFlags = [],
@@ -326,6 +332,7 @@ async function run(
326332
prLimit: number
327333
rangeStyle: RangeStyle
328334
showAffectedDirectDependencies: boolean
335+
silence: boolean
329336
unknownFlags?: string[]
330337
}
331338

@@ -391,7 +398,7 @@ async function run(
391398
return
392399
}
393400

394-
const orgSlugCResult = await getDefaultOrgSlug()
401+
const orgSlugCResult = await getDefaultOrgSlug(silence)
395402
if (!orgSlugCResult.ok) {
396403
process.exitCode = orgSlugCResult.code ?? 1
397404
logger.fail(
@@ -433,6 +440,7 @@ async function run(
433440
prLimit,
434441
rangeStyle,
435442
showAffectedDirectDependencies,
443+
silence,
436444
spinner,
437445
unknownFlags,
438446
})

0 commit comments

Comments
 (0)