From fdfc7c96b9a9c821e4828f124fe1be56801f4814 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Wed, 7 May 2025 13:34:23 +0200 Subject: [PATCH 1/2] Improve handling of non-sdk api calls --- src/commands/diff-scan/fetch-diff-scan.mts | 31 +--- .../package/fetch-purl-deep-score.mts | 62 +------ src/commands/scan/fetch-diff-scan.mts | 32 +--- src/commands/scan/fetch-report-data.mts | 79 ++++----- src/commands/scan/fetch-scan.mts | 65 +++---- .../threat-feed/fetch-threat-feed.mts | 61 +------ src/utils/api.mts | 115 +++++++++++- src/utils/meow-with-subcommands.mts | 163 ++++++++++++------ test/smoke.sh | 145 ++++++++++------ 9 files changed, 380 insertions(+), 373 deletions(-) diff --git a/src/commands/diff-scan/fetch-diff-scan.mts b/src/commands/diff-scan/fetch-diff-scan.mts index 90612da176..4ba42e9137 100644 --- a/src/commands/diff-scan/fetch-diff-scan.mts +++ b/src/commands/diff-scan/fetch-diff-scan.mts @@ -1,6 +1,4 @@ -import constants from '../../constants.mts' -import { handleApiError, queryApi } from '../../utils/api.mts' -import { getDefaultToken } from '../../utils/sdk.mts' +import { queryApiSafeJson } from '../../utils/api.mts' import type { CResult } from '../../types.mts' import type { SocketSdkReturnType } from '@socketsecurity/sdk' @@ -14,31 +12,8 @@ export async function fetchDiffScan({ before: string orgSlug: string }): Promise['data']>> { - const apiToken = getDefaultToken() - - // Lazily access constants.spinner. - const { spinner } = constants - - spinner.start('Fetching diff-scan...') - - const response = await queryApi( + return await queryApiSafeJson['data']>( `orgs/${orgSlug}/full-scans/diff?before=${encodeURIComponent(before)}&after=${encodeURIComponent(after)}`, - apiToken || '' + 'a scan diff' ) - - spinner.successAndStop('Received diff-scan response') - - if (!response.ok) { - const err = await handleApiError(response.status) - return { - ok: false, - message: 'Socket API returned an error', - cause: `${response.statusText}${err ? ` ( Reason: ${err} )` : ''}` - } - } - - const result = - (await response.json()) as SocketSdkReturnType<'GetOrgDiffScan'>['data'] - - return { ok: true, data: result } } diff --git a/src/commands/package/fetch-purl-deep-score.mts b/src/commands/package/fetch-purl-deep-score.mts index 90b5914cdd..8753e08aa7 100644 --- a/src/commands/package/fetch-purl-deep-score.mts +++ b/src/commands/package/fetch-purl-deep-score.mts @@ -1,8 +1,6 @@ import { logger } from '@socketsecurity/registry/lib/logger' -import constants from '../../constants.mts' -import { handleApiError, queryApi } from '../../utils/api.mts' -import { getDefaultToken } from '../../utils/sdk.mts' +import { queryApiSafeJson } from '../../utils/api.mts' import type { CResult } from '../../types.mts' @@ -60,58 +58,8 @@ export async function fetchPurlDeepScore( ): Promise> { logger.error(`Requesting deep score data for this purl: ${purl}`) - const apiToken = getDefaultToken() - if (!apiToken) { - return { - ok: false, - message: 'Authentication Error', - cause: - 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.' - } - } - - // Lazily access constants.spinner. - const { spinner } = constants - - spinner.start('Getting deep package score...') - - let result - try { - result = await queryApi(`purl/score/${encodeURIComponent(purl)}`, apiToken) - } catch (e) { - spinner.failAndStop('The request was unsuccessful.') - const msg = (e as undefined | { message: string })?.message - - return { - ok: false, - message: 'API Request failed to complete', - ...(msg ? { cause: msg } : {}) - } - } - - spinner.successAndStop('Received deep package score response.') - - if (!result.ok) { - const cause = await handleApiError(result.status) - return { - ok: false, - message: 'Socket API returned an error', - cause: `${result.statusText}${cause ? ` (cause: ${cause})` : ''}` - } - } - - const data = await result.text() - - try { - return { - ok: true, - data: JSON.parse(data) // as PurlDataResponse - } - } catch (e) { - return { - ok: false, - message: 'Server returned invalid JSON', - cause: `Please report this. JSON.parse threw an error over the following response: \`${data}\`` - } - } + return await queryApiSafeJson( + `purl/score/${encodeURIComponent(purl)}`, + 'the deep package scores' + ) } diff --git a/src/commands/scan/fetch-diff-scan.mts b/src/commands/scan/fetch-diff-scan.mts index af3645c416..65bddeedc5 100644 --- a/src/commands/scan/fetch-diff-scan.mts +++ b/src/commands/scan/fetch-diff-scan.mts @@ -1,8 +1,6 @@ import { logger } from '@socketsecurity/registry/lib/logger' -import constants from '../../constants.mts' -import { handleApiError, queryApi } from '../../utils/api.mts' -import { getDefaultToken } from '../../utils/sdk.mts' +import { queryApiSafeJson } from '../../utils/api.mts' import type { CResult } from '../../types.mts' import type { SocketSdkReturnType } from '@socketsecurity/sdk' @@ -16,34 +14,12 @@ export async function fetchDiffScan({ id2: string orgSlug: string }): Promise['data']>> { - const apiToken = getDefaultToken() - - // Lazily access constants.spinner. - const { spinner } = constants - logger.error('Scan ID 1:', id1) logger.error('Scan ID 2:', id2) + logger.error('Note: this request may take some time if the scans are big') - spinner.start('Fetching scan diff... (this may take a while)') - - const response = await queryApi( + return await queryApiSafeJson['data']>( `orgs/${orgSlug}/full-scans/diff?before=${encodeURIComponent(id1)}&after=${encodeURIComponent(id2)}`, - apiToken || '' + 'a scan diff' ) - - spinner.successAndStop('Received scan diff response') - - if (!response.ok) { - const cause = await handleApiError(response.status) - return { - ok: false, - message: 'Socket API returned an error', - cause: `${response.statusText}${cause ? ` (cause: ${cause})` : ''}` - } - } - - const fullScan = - (await response.json()) as SocketSdkReturnType<'GetOrgDiffScan'>['data'] - - return { ok: true, data: fullScan } } diff --git a/src/commands/scan/fetch-report-data.mts b/src/commands/scan/fetch-report-data.mts index 4b3d918796..e6b3e8fd6b 100644 --- a/src/commands/scan/fetch-report-data.mts +++ b/src/commands/scan/fetch-report-data.mts @@ -2,13 +2,8 @@ import { debugLog } from '@socketsecurity/registry/lib/debug' import { logger } from '@socketsecurity/registry/lib/logger' import constants from '../../constants.mts' -import { - handleApiCallNoSpinner, - handleApiError, - queryApi, - tmpHandleApiCall -} from '../../utils/api.mts' -import { getDefaultToken, setupSdk } from '../../utils/sdk.mts' +import { handleApiCallNoSpinner, queryApiSafeText } from '../../utils/api.mts' +import { setupSdk } from '../../utils/sdk.mts' import type { CResult } from '../../types.mts' import type { SocketSdkReturnType } from '@socketsecurity/sdk' @@ -28,17 +23,7 @@ export async function fetchReportData( securityPolicy: SocketSdkReturnType<'getOrgSecurityPolicy'>['data'] }> > { - const apiToken = getDefaultToken() - if (!apiToken) { - return { - ok: false, - message: 'Authentication Error', - cause: - 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.' - } - } - - const sockSdk = await setupSdk(apiToken) + const sockSdk = await setupSdk() let scanStatus = 'requested..' let policyStatus = 'requested..' @@ -70,50 +55,48 @@ export async function fetchReportData( } } - async function fetchScanResult( - apiToken: string - ): Promise>> { - const response = await tmpHandleApiCall( - queryApi( - `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}${includeLicensePolicy ? '?include_license_details=true' : ''}`, - apiToken - ), - 'fetchScanResult' + async function fetchScanResult(): Promise< + CResult> + > { + const result = await queryApiSafeText( + `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}${includeLicensePolicy ? '?include_license_details=true' : ''}` ) - updateScan('received response') + updateScan(`response received`) - if (!response.ok) { - const cause = await handleApiError(response.status) - updateScan(`request resulted in status code ${response.status}`) - return { - ok: false, - message: 'Socket API returned an error', - cause: `${response.statusText}${cause ? ` (cause: ${cause})` : ''}` - } + if (!result.ok) { + return result } - updateScan(`ok, downloading response..`) - const jsons = await response.text() - updateScan(`received policy`) + const jsonsString = result.data - const lines = jsons.split('\n').filter(Boolean) + // This is nd-json; each line is a json object + const lines = jsonsString.split('\n').filter(Boolean) + let ok = true const data = lines.map(line => { try { return JSON.parse(line) } catch { - scanStatus = `received invalid JSON response` - spinner.stop() - logger.error( - 'Response was not valid JSON but it ought to be (please report if this persists)' - ) + ok = false + debugLog('ndjson failed to parse the following line:') debugLog(line) - updateProgress() return } }) as unknown as Array - return { ok: true, data } + if (ok) { + updateScan(`success`) + return { ok: true, data } + } + + updateScan(`received invalid JSON response`) + + return { + ok: false, + message: 'Invalid API response', + cause: + 'The API responded with at least one line that was not valid JSON. Please report if this persists.' + } } async function fetchSecurityPolicy(): Promise< @@ -135,7 +118,7 @@ export async function fetchReportData( CResult>, CResult['data']> ] = await Promise.all([ - fetchScanResult(apiToken).catch(e => { + fetchScanResult().catch(e => { updateScan(`failure; unknown blocking problem occurred`) return { ok: false as const, diff --git a/src/commands/scan/fetch-scan.mts b/src/commands/scan/fetch-scan.mts index 4e2133f507..a789face12 100644 --- a/src/commands/scan/fetch-scan.mts +++ b/src/commands/scan/fetch-scan.mts @@ -1,6 +1,6 @@ -import constants from '../../constants.mts' -import { handleApiError, queryApi } from '../../utils/api.mts' -import { getDefaultToken } from '../../utils/sdk.mts' +import { debugLog } from '@socketsecurity/registry/lib/debug' + +import { queryApiSafeText } from '../../utils/api.mts' import type { CResult } from '../../types.mts' import type { components } from '@socketsecurity/sdk/types/api' @@ -9,58 +9,39 @@ export async function fetchScan( orgSlug: string, scanId: string ): Promise>> { - const apiToken = getDefaultToken() - if (!apiToken) { - return { - ok: false, - message: 'Authentication Error', - cause: - 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.' - } - } - - // Lazily access constants.spinner. - const { spinner } = constants - - spinner.start('Fetching scan data...') - - const response = await queryApi( + const result = await queryApiSafeText( `orgs/${orgSlug}/full-scans/${encodeURIComponent(scanId)}`, - apiToken + 'a scan' ) - spinner.successAndStop('Received response while fetching scan data.') - - if (!response.ok) { - const cause = await handleApiError(response.status) - return { - ok: false, - message: 'Socket API returned an error', - cause: `${response.statusText}${cause ? ` (cause: ${cause})` : ''}` - } + if (!result.ok) { + return result } + const jsonsString = result.data + // This is nd-json; each line is a json object - const jsons = await response.text() - const lines = jsons.split('\n').filter(Boolean) - let failed = false + const lines = jsonsString.split('\n').filter(Boolean) + let ok = true const data = lines.map(line => { try { return JSON.parse(line) } catch { - failed = true - return {} + ok = false + debugLog('ndjson failed to parse the following line:') + debugLog(line) + return null } }) as unknown as Array - if (failed) { - return { - ok: false, - message: 'API response was invalid', - cause: - 'At least one line item was returned that could not be parsed as JSON... Please report.' - } + if (ok) { + return { ok: true, data } } - return { ok: true, data } + return { + ok: false, + message: 'Invalid API response', + cause: + 'The API responded with at least one line that was not valid JSON. Please report if this persists.' + } } diff --git a/src/commands/threat-feed/fetch-threat-feed.mts b/src/commands/threat-feed/fetch-threat-feed.mts index 9aacf59e47..f97852ba02 100644 --- a/src/commands/threat-feed/fetch-threat-feed.mts +++ b/src/commands/threat-feed/fetch-threat-feed.mts @@ -1,6 +1,4 @@ -import constants from '../../constants.mts' -import { handleApiError, queryApi } from '../../utils/api.mts' -import { getDefaultToken } from '../../utils/sdk.mts' +import { queryApiSafeJson } from '../../utils/api.mts' import type { ThreadFeedResponse } from './types.mts' import type { CResult } from '../../types.mts' @@ -26,57 +24,8 @@ export async function fetchThreatFeed({ ['per_page', String(perPage)] ]) - const apiToken = getDefaultToken() - if (!apiToken) { - return { - ok: false, - message: 'Authentication Error', - cause: - 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.' - } - } - - // Lazily access constants.spinner. - const { spinner } = constants - - spinner.start('Fetching Threat Feed data...') - - let result - try { - result = await queryApi(`threat-feed?${queryParams}`, apiToken) - } catch (e) { - spinner.failAndStop('The request was unsuccessful.') - const msg = (e as undefined | { message: string })?.message - - return { - ok: false, - message: 'API Request failed to complete', - ...(msg ? { cause: msg } : {}) - } - } - - spinner.successAndStop('Received response while fetching Threat Feed data.') - - if (!result.ok) { - const cause = await handleApiError(result.status) - return { - ok: false, - message: 'Socket API returned an error', - cause: `${result.statusText}${cause ? ` (cause: ${cause})` : ''}` - } - } - - const data = (await result.json()) as - | ThreadFeedResponse - | { error: { message: string } } - - if ('error' in data && data.error) { - return { - ok: false, - message: 'Socket API returned an error', - cause: data.error.message - } - } - - return { ok: true, data: data as ThreadFeedResponse } + return await queryApiSafeJson( + `threat-feed?${queryParams}`, + 'the Threat Feed data' + ) } diff --git a/src/utils/api.mts b/src/utils/api.mts index ca08244458..76e2881c14 100644 --- a/src/utils/api.mts +++ b/src/utils/api.mts @@ -6,6 +6,7 @@ import { getConfigValueOrUndef } from './config.mts' import { AuthError } from './errors.mts' import constants from '../constants.mts' import { failMsgWithBadge } from './fail-msg-with-badge.mts' +import { getDefaultToken } from './sdk.mts' import type { CResult } from '../types.mts' import type { @@ -162,15 +163,18 @@ export async function handleApiCallNoSpinner( } } -export async function handleApiError(code: number) { +export async function getErrorMessageForHttpStatusCode(code: number) { if (code === 400) { return 'One of the options passed might be incorrect' } - if (code === 403) { + if (code === 403 || code === 401) { return 'Your API token may not have the required permissions for this command or you might be trying to access (data from) an organization that is not linked to the API key you are logged in with' } if (code === 404) { - return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. This could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.' + return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. If unexpected, this could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.' + } + if (code === 500) { + return 'There was an unknown server side problem with your request. This ought to be temporary. Please let us know if this problem persists.' } return `Server responded with status code ${code}` } @@ -209,3 +213,108 @@ export async function queryApi(path: string, apiToken: string) { } }) } + +export async function queryApiSafeText( + path: string, + fetchSpinnerDesc?: string +): Promise> { + const apiToken = getDefaultToken() + if (!apiToken) { + return { + ok: false, + message: 'Authentication Error', + cause: + 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.' + } + } + + if (fetchSpinnerDesc) { + // Lazily access constants.spinner. + const { spinner } = constants + + spinner.start(`Requesting ${fetchSpinnerDesc} from API...`) + } + + let result + try { + result = await queryApi(path, apiToken) + if (fetchSpinnerDesc) { + // Lazily access constants.spinner. + const { spinner } = constants + + spinner.successAndStop( + `Received API response (after requesting ${fetchSpinnerDesc}).` + ) + } + } catch (e) { + if (fetchSpinnerDesc) { + // Lazily access constants.spinner. + const { spinner } = constants + + spinner.failAndStop( + `An error was thrown while requesting ${fetchSpinnerDesc}` + ) + } + debugLog('Error thrown trying to await queryApi():') + debugLog(e) + + const msg = (e as undefined | { message: string })?.message + + return { + ok: false, + message: 'API Request failed to complete', + ...(msg ? { cause: msg } : {}) + } + } + + if (!result.ok) { + const cause = await getErrorMessageForHttpStatusCode(result.status) + return { + ok: false, + message: 'Socket API returned an error', + cause: `${result.statusText}${cause ? ` (cause: ${cause})` : ''}` + } + } + + try { + const data = await result.text() + + return { + ok: true, + data + } + } catch (e) { + debugLog('Error thrown trying to await result.text():') + debugLog(e) + + return { + ok: false, + message: 'API Request failed to complete', + cause: 'There was an unexpected error trying to read the response text' + } + } +} + +export async function queryApiSafeJson( + path: string, + fetchSpinnerDesc = '' +): Promise> { + const result = await queryApiSafeText(path, fetchSpinnerDesc) + + if (!result.ok) { + return result + } + + try { + return { + ok: true, + data: JSON.parse(result.data) as T + } + } catch (e) { + return { + ok: false, + message: 'Server returned invalid JSON', + cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) || '').trim() + (result.data?.length > 100 ? '...' : '')}\`` + } + } +} diff --git a/src/utils/meow-with-subcommands.mts b/src/utils/meow-with-subcommands.mts index 72da3271d8..a4ef291424 100644 --- a/src/utils/meow-with-subcommands.mts +++ b/src/utils/meow-with-subcommands.mts @@ -109,53 +109,19 @@ export async function meowWithSubcommands( } } - const cli = meow( - ` - Usage - $ ${name} - - Commands - ${getHelpListOutput( - { - ...toSortedObject( - Object.fromEntries( - Object.entries(subcommands).filter( - ({ 1: subcommand }) => !subcommand.hidden - ) - ) - ), - ...toSortedObject( - Object.fromEntries( - Object.entries(aliases).filter(({ 1: alias }) => { - const { hidden } = alias - const cmdName = hidden ? '' : alias.argv[0] - const subcommand = cmdName ? subcommands[cmdName] : undefined - return subcommand && !subcommand.hidden - }) - ) - ) - }, - 6 - )} - - Options - ${getFlagListOutput(flags, 6)} - - Examples - $ ${name} --help - `, - { - argv, - importMeta, - ...additionalOptions, - flags, - // Do not strictly check for flags here. - allowUnknownFlags: true, - // We will emit help when we're ready - // Plus, if we allow this then meow() can just exit here. - autoHelp: false - } - ) + // This is basically a dry-run parse of cli args and flags. We use this to + // determine config overrides and expected output mode. + const cli1 = meow(`(this should never be printed)`, { + argv, + importMeta, + ...additionalOptions, + flags, + // Do not strictly check for flags here. + allowUnknownFlags: true, + // We will emit help when we're ready + // Plus, if we allow this then meow() can just exit here. + autoHelp: false + }) // Hard override the config if instructed to do so. // The env var overrides the --flag, which overrides the persisted config @@ -167,9 +133,9 @@ export async function meowWithSubcommands( // Lazily access constants.ENV.SOCKET_CLI_CONFIG. constants.ENV.SOCKET_CLI_CONFIG ) - } else if (cli.flags['config']) { + } else if (cli1.flags['config']) { configOverrideResult = overrideCachedConfig( - String(cli.flags['config'] || '') + String(cli1.flags['config'] || '') ) } @@ -212,16 +178,73 @@ export async function meowWithSubcommands( } } + if (isTestingV1()) { + delete subcommands['diff-scan'] + delete subcommands['info'] + delete subcommands['report'] + } + + // Parse it again. Config overrides should now be applied (may affect help). + const cli2 = meow( + ` + Usage + $ ${name} + + Commands + ${getHelpListOutput( + { + ...toSortedObject( + Object.fromEntries( + Object.entries(subcommands).filter( + ({ 1: subcommand }) => !subcommand.hidden + ) + ) + ), + ...toSortedObject( + Object.fromEntries( + Object.entries(aliases).filter(({ 1: alias }) => { + const { hidden } = alias + const cmdName = hidden ? '' : alias.argv[0] + const subcommand = cmdName ? subcommands[cmdName] : undefined + return subcommand && !subcommand.hidden + }) + ) + ) + }, + 6 + )} + + Options + ${getFlagListOutput(flags, 6)} + + Examples + $ ${name} --help + `, + { + argv, + importMeta, + ...additionalOptions, + flags, + // Do not strictly check for flags here. + allowUnknownFlags: true, + // We will emit help when we're ready + // Plus, if we allow this then meow() can just exit here. + autoHelp: false + } + ) + // ...else we provide basic instructions and help. - if (!cli.flags['silent']) { + if (!cli2.flags['silent']) { emitBanner(name) } - if (!cli.flags['help'] && cli.flags['dryRun']) { + if (!cli2.flags['help'] && cli2.flags['dryRun']) { process.exitCode = 0 // Lazily access constants.DRY_RUN_LABEL. logger.log(`${constants.DRY_RUN_LABEL}: No-op, call a sub-command; ok`) } else { - cli.showHelp() + // When you explicitly request --help, the command should be successful + // so we exit(0). If we do it because we need more input, we exit(2). + cli2.showHelp(cli2.flags['help'] ? 0 : 2) } } @@ -251,16 +274,46 @@ export function meowOrExit({ help: config.help(command, config), importMeta, flags: config.flags, - allowUnknownFlags: Boolean(allowUnknownFlags), - autoHelp: false // otherwise we can't exit(0) + allowUnknownFlags: true, // meow will exit(1) before printing the banner + autoHelp: false // meow will exit(0) before printing the banner }) if (!cli.flags['silent']) { emitBanner(command) } + if (!allowUnknownFlags) { + // Run meow specifically with the flag setting. It will exit(2) if an + // invalid flag is set and print a message. + meow({ + argv, + description: config.description, + help: config.help(command, config), + importMeta, + flags: config.flags, + allowUnknownFlags: false, + autoHelp: false + }) + } + if (cli.flags['help']) { - cli.showHelp() + cli.showHelp(0) } + // Now test for help state. Run meow again. If it exits now, it must be due + // to wanting to print the help screen. But it would exit(0) and we want a + // consistent exit(2) for that case (missing input). TODO: move away from meow + process.exitCode = 2 + meow({ + argv, + description: config.description, + help: config.help(command, config), + importMeta, + flags: config.flags, + allowUnknownFlags: Boolean(allowUnknownFlags), + autoHelp: false + }) + // Ok, no help, reset to default. + process.exitCode = 0 + return cli } diff --git a/test/smoke.sh b/test/smoke.sh index a1a8523961..929b61c6b1 100755 --- a/test/smoke.sh +++ b/test/smoke.sh @@ -12,6 +12,14 @@ ## ###### +## +# Adding commands: +# +# All run functions accept an exit code as first arg and the command to run as remaining args. +# +# - `run_socket` Use for most commands. +# - `run_json` Use for commands that return JSON. It will confirm that stdout contains valid JSON and assert the toplevel structure matches exit code logic. +# # Colors for output GREEN='\033[0;32m' @@ -34,6 +42,15 @@ TEST_COUNTER=0 # node 22+ COMMAND_PREFIX="./sd" +# Function to restore config on exit +restore_config() { + echo -e "\n${YELLOW}Restoring backed up configuration values...${NC}" + eval "${COMMAND_PREFIX} config set defaultOrg ${DEFORG_BAK}" + eval "${COMMAND_PREFIX} config set apiToken ${TOKEN_BAK}" + eval "${COMMAND_PREFIX} config set isTestingV1 ${TESTV1_BAK}" + echo -e "${GREEN}Configuration restored!${NC}" +} + # Get target subcommand from first argument TARGET_SUBCOMMAND="$1" @@ -238,10 +255,23 @@ else npm run build fi +# Backup config +echo "Backing up default org and apitoken..." +DEFORG_BAK=$(eval "$COMMAND_PREFIX config get defaultOrg --json" | jq -r '.data' ) +TOKEN_BAK=$(eval "$COMMAND_PREFIX config get apiToken --json" | jq -r '.data' ) +TESTV1_BAK=$(eval "$COMMAND_PREFIX config get isTestingV1 --json" | jq -r '.data' ) +echo "Backing complete!" + +# Set up trap to restore config on any exit +trap restore_config EXIT + +# This smoke test assumes the Date: Wed, 7 May 2025 13:57:04 +0200 Subject: [PATCH 2/2] Update exit code expectation in snapshots --- src/commands/analytics/cmd-analytics.test.mts | 4 ++-- src/commands/audit-log/cmd-audit-log.test.mts | 2 +- src/commands/cdxgen/cmd-cdxgen.test.mts | 2 +- src/commands/ci/cmd-ci.test.mts | 2 +- src/commands/config/cmd-config-get.test.mts | 2 +- src/commands/config/cmd-config-list.test.mts | 2 +- src/commands/config/cmd-config-set.test.mts | 2 +- src/commands/config/cmd-config-unset.test.mts | 2 +- src/commands/config/cmd-config.test.mts | 2 +- src/commands/dependencies/cmd-dependencies.test.mts | 2 +- src/commands/diff-scan/cmd-diff-scan-get.test.mts | 2 +- src/commands/diff-scan/cmd-diff-scan.test.mts | 2 +- src/commands/fix/cmd-fix.test.mts | 2 +- src/commands/info/cmd-info.test.mts | 2 +- src/commands/login/cmd-login.test.mts | 2 +- src/commands/logout/cmd-logout.test.mts | 2 +- src/commands/manifest/cmd-manifest-auto.test.mts | 2 +- src/commands/manifest/cmd-manifest-conda.test.mts | 2 +- src/commands/manifest/cmd-manifest-gradle.test.mts | 2 +- src/commands/manifest/cmd-manifest-kotlin.test.mts | 2 +- src/commands/manifest/cmd-manifest-scala.test.mts | 2 +- src/commands/manifest/cmd-manifest.test.mts | 2 +- src/commands/npm/cmd-npm.test.mts | 2 +- src/commands/npx/cmd-npx.test.mts | 2 +- src/commands/oops/cmd-oops.test.mts | 2 +- src/commands/optimize/cmd-optimize.test.mts | 2 +- src/commands/organization/cmd-organization-list.test.mts | 2 +- .../organization/cmd-organization-policy-license.test.mts | 2 +- .../organization/cmd-organization-policy-security.test.mts | 2 +- src/commands/organization/cmd-organization-policy.test.mts | 2 +- src/commands/organization/cmd-organization-quota.test.mts | 2 +- src/commands/organization/cmd-organization.test.mts | 2 +- src/commands/package/cmd-package-score.test.mts | 2 +- src/commands/package/cmd-package-shallow.test.mts | 2 +- src/commands/package/cmd-package.test.mts | 2 +- src/commands/raw-npm/cmd-raw-npm.test.mts | 2 +- src/commands/raw-npx/cmd-raw-npx.test.mts | 2 +- src/commands/report/cmd-report-create.test.mts | 2 +- src/commands/report/cmd-report-view.test.mts | 2 +- src/commands/report/cmd-report.test.mts | 2 +- src/commands/repos/cmd-repos-create.test.mts | 2 +- src/commands/repos/cmd-repos-del.test.mts | 2 +- src/commands/repos/cmd-repos-list.test.mts | 2 +- src/commands/repos/cmd-repos-update.test.mts | 2 +- src/commands/repos/cmd-repos-view.test.mts | 2 +- src/commands/repos/cmd-repos.test.mts | 2 +- src/commands/scan/cmd-scan-create.test.mts | 2 +- src/commands/scan/cmd-scan-del.test.mts | 2 +- src/commands/scan/cmd-scan-diff.test.mts | 2 +- src/commands/scan/cmd-scan-list.test.mts | 2 +- src/commands/scan/cmd-scan-metadata.test.mts | 2 +- src/commands/scan/cmd-scan-report.test.mts | 2 +- src/commands/scan/cmd-scan-view.test.mts | 2 +- src/commands/scan/cmd-scan.test.mts | 2 +- src/commands/threat-feed/cmd-threat-feed.test.mts | 2 +- src/commands/wrapper/cmd-wrapper.test.mts | 2 +- 56 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/commands/analytics/cmd-analytics.test.mts b/src/commands/analytics/cmd-analytics.test.mts index 224817f1c7..646c77951c 100644 --- a/src/commands/analytics/cmd-analytics.test.mts +++ b/src/commands/analytics/cmd-analytics.test.mts @@ -53,7 +53,7 @@ describe('socket analytics', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket analytics\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket analytics`' ) @@ -159,7 +159,7 @@ describe('socket analytics', async () => { \\x1b[39m" `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket analytics`' ) diff --git a/src/commands/audit-log/cmd-audit-log.test.mts b/src/commands/audit-log/cmd-audit-log.test.mts index 424ba67e44..aad3af4fa7 100644 --- a/src/commands/audit-log/cmd-audit-log.test.mts +++ b/src/commands/audit-log/cmd-audit-log.test.mts @@ -52,7 +52,7 @@ describe('socket audit-log', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket audit-log\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket audit-log`' ) diff --git a/src/commands/cdxgen/cmd-cdxgen.test.mts b/src/commands/cdxgen/cmd-cdxgen.test.mts index 182d0e9849..d6f1c22a77 100644 --- a/src/commands/cdxgen/cmd-cdxgen.test.mts +++ b/src/commands/cdxgen/cmd-cdxgen.test.mts @@ -86,7 +86,7 @@ describe('socket cdxgen', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket cdxgen\`, cwd: " `) - // expect(code, 'help should exit with code 2').toBe(2) + // expect(code, 'explicit help should exit with code 0').toBe(0) expect(code, 'help should exit with code 2').toBe(0) // cdxgen special case expect(stderr, 'banner includes base command').toContain('`socket cdxgen`') }) diff --git a/src/commands/ci/cmd-ci.test.mts b/src/commands/ci/cmd-ci.test.mts index 8c2c7777dd..88b5850e07 100644 --- a/src/commands/ci/cmd-ci.test.mts +++ b/src/commands/ci/cmd-ci.test.mts @@ -38,7 +38,7 @@ describe('socket ci', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket ci\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket ci`') } ) diff --git a/src/commands/config/cmd-config-get.test.mts b/src/commands/config/cmd-config-get.test.mts index 644652a8f8..8bf89add2d 100644 --- a/src/commands/config/cmd-config-get.test.mts +++ b/src/commands/config/cmd-config-get.test.mts @@ -49,7 +49,7 @@ describe('socket config get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config get\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket config get`' ) diff --git a/src/commands/config/cmd-config-list.test.mts b/src/commands/config/cmd-config-list.test.mts index 3abad083e9..5d96dba8eb 100644 --- a/src/commands/config/cmd-config-list.test.mts +++ b/src/commands/config/cmd-config-list.test.mts @@ -50,7 +50,7 @@ describe('socket config get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config list\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket config list`' ) diff --git a/src/commands/config/cmd-config-set.test.mts b/src/commands/config/cmd-config-set.test.mts index be0ec848aa..c505c3ec5d 100644 --- a/src/commands/config/cmd-config-set.test.mts +++ b/src/commands/config/cmd-config-set.test.mts @@ -54,7 +54,7 @@ describe('socket config get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config set\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket config set`' ) diff --git a/src/commands/config/cmd-config-unset.test.mts b/src/commands/config/cmd-config-unset.test.mts index 788550d18e..4f86526cb4 100644 --- a/src/commands/config/cmd-config-unset.test.mts +++ b/src/commands/config/cmd-config-unset.test.mts @@ -49,7 +49,7 @@ describe('socket config unset', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config unset\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket config unset`' ) diff --git a/src/commands/config/cmd-config.test.mts b/src/commands/config/cmd-config.test.mts index dfd2a432bb..05e5fb1b90 100644 --- a/src/commands/config/cmd-config.test.mts +++ b/src/commands/config/cmd-config.test.mts @@ -45,7 +45,7 @@ describe('socket config', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket config\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket config`' ) diff --git a/src/commands/dependencies/cmd-dependencies.test.mts b/src/commands/dependencies/cmd-dependencies.test.mts index 6ce5ef5e0a..c8d6f46745 100644 --- a/src/commands/dependencies/cmd-dependencies.test.mts +++ b/src/commands/dependencies/cmd-dependencies.test.mts @@ -46,7 +46,7 @@ describe('socket dependencies', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket dependencies\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket dependencies`' ) diff --git a/src/commands/diff-scan/cmd-diff-scan-get.test.mts b/src/commands/diff-scan/cmd-diff-scan-get.test.mts index aaa20ccd4d..8ff2c20560 100644 --- a/src/commands/diff-scan/cmd-diff-scan-get.test.mts +++ b/src/commands/diff-scan/cmd-diff-scan-get.test.mts @@ -54,7 +54,7 @@ describe('socket diff-scan get', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan get\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket diff-scan get`' ) diff --git a/src/commands/diff-scan/cmd-diff-scan.test.mts b/src/commands/diff-scan/cmd-diff-scan.test.mts index 4ebfbd4875..819ae64ad9 100644 --- a/src/commands/diff-scan/cmd-diff-scan.test.mts +++ b/src/commands/diff-scan/cmd-diff-scan.test.mts @@ -41,7 +41,7 @@ describe('socket diff-scan', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket diff-scan\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket diff-scan`' ) diff --git a/src/commands/fix/cmd-fix.test.mts b/src/commands/fix/cmd-fix.test.mts index 1353a34f62..4d130893e9 100644 --- a/src/commands/fix/cmd-fix.test.mts +++ b/src/commands/fix/cmd-fix.test.mts @@ -53,7 +53,7 @@ describe('socket fix', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket fix\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket fix`') } ) diff --git a/src/commands/info/cmd-info.test.mts b/src/commands/info/cmd-info.test.mts index cf163103c6..2320cef3df 100644 --- a/src/commands/info/cmd-info.test.mts +++ b/src/commands/info/cmd-info.test.mts @@ -45,7 +45,7 @@ describe('socket info', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket info\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket info`') } ) diff --git a/src/commands/login/cmd-login.test.mts b/src/commands/login/cmd-login.test.mts index b5d446116e..167769bea8 100644 --- a/src/commands/login/cmd-login.test.mts +++ b/src/commands/login/cmd-login.test.mts @@ -46,7 +46,7 @@ describe('socket login', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket login\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket login`') } ) diff --git a/src/commands/logout/cmd-logout.test.mts b/src/commands/logout/cmd-logout.test.mts index 4815d15e9a..23db3cfcc4 100644 --- a/src/commands/logout/cmd-logout.test.mts +++ b/src/commands/logout/cmd-logout.test.mts @@ -34,7 +34,7 @@ describe('socket logout', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket logout\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket logout`' ) diff --git a/src/commands/manifest/cmd-manifest-auto.test.mts b/src/commands/manifest/cmd-manifest-auto.test.mts index c45078a319..6ef7fd57d0 100644 --- a/src/commands/manifest/cmd-manifest-auto.test.mts +++ b/src/commands/manifest/cmd-manifest-auto.test.mts @@ -41,7 +41,7 @@ describe('socket manifest auto', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest auto\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket manifest auto`' ) diff --git a/src/commands/manifest/cmd-manifest-conda.test.mts b/src/commands/manifest/cmd-manifest-conda.test.mts index 23e0c064af..5acd91abf7 100644 --- a/src/commands/manifest/cmd-manifest-conda.test.mts +++ b/src/commands/manifest/cmd-manifest-conda.test.mts @@ -53,7 +53,7 @@ describe('socket manifest conda', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest conda\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket manifest conda`' ) diff --git a/src/commands/manifest/cmd-manifest-gradle.test.mts b/src/commands/manifest/cmd-manifest-gradle.test.mts index ffd4004455..1f6d13d95b 100644 --- a/src/commands/manifest/cmd-manifest-gradle.test.mts +++ b/src/commands/manifest/cmd-manifest-gradle.test.mts @@ -65,7 +65,7 @@ describe('socket manifest gradle', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest gradle\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket manifest gradle`' ) diff --git a/src/commands/manifest/cmd-manifest-kotlin.test.mts b/src/commands/manifest/cmd-manifest-kotlin.test.mts index e5e2663e08..4ee5180af8 100644 --- a/src/commands/manifest/cmd-manifest-kotlin.test.mts +++ b/src/commands/manifest/cmd-manifest-kotlin.test.mts @@ -65,7 +65,7 @@ describe('socket manifest kotlin', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest kotlin\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket manifest kotlin`' ) diff --git a/src/commands/manifest/cmd-manifest-scala.test.mts b/src/commands/manifest/cmd-manifest-scala.test.mts index dafb8c2ef4..3b00f6f0a6 100644 --- a/src/commands/manifest/cmd-manifest-scala.test.mts +++ b/src/commands/manifest/cmd-manifest-scala.test.mts @@ -71,7 +71,7 @@ describe('socket manifest scala', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest scala\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket manifest scala`' ) diff --git a/src/commands/manifest/cmd-manifest.test.mts b/src/commands/manifest/cmd-manifest.test.mts index ed526d707a..5c9ae22d3f 100644 --- a/src/commands/manifest/cmd-manifest.test.mts +++ b/src/commands/manifest/cmd-manifest.test.mts @@ -45,7 +45,7 @@ describe('socket manifest', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket manifest\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket manifest`' ) diff --git a/src/commands/npm/cmd-npm.test.mts b/src/commands/npm/cmd-npm.test.mts index 4bc7788e03..c7de051b26 100644 --- a/src/commands/npm/cmd-npm.test.mts +++ b/src/commands/npm/cmd-npm.test.mts @@ -32,7 +32,7 @@ describe('socket npm', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket npm\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket npm`') } ) diff --git a/src/commands/npx/cmd-npx.test.mts b/src/commands/npx/cmd-npx.test.mts index d633179b03..a21e917d5c 100644 --- a/src/commands/npx/cmd-npx.test.mts +++ b/src/commands/npx/cmd-npx.test.mts @@ -32,7 +32,7 @@ describe('socket npx', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket npx\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket npx`') } ) diff --git a/src/commands/oops/cmd-oops.test.mts b/src/commands/oops/cmd-oops.test.mts index 92c092a62c..f3d87e914d 100644 --- a/src/commands/oops/cmd-oops.test.mts +++ b/src/commands/oops/cmd-oops.test.mts @@ -34,7 +34,7 @@ describe('socket oops', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket oops\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket oops`') } ) diff --git a/src/commands/optimize/cmd-optimize.test.mts b/src/commands/optimize/cmd-optimize.test.mts index c3ed3b0a60..f8bb97a72d 100644 --- a/src/commands/optimize/cmd-optimize.test.mts +++ b/src/commands/optimize/cmd-optimize.test.mts @@ -41,7 +41,7 @@ describe('socket optimize', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket optimize\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket optimize`' ) diff --git a/src/commands/organization/cmd-organization-list.test.mts b/src/commands/organization/cmd-organization-list.test.mts index 26b35a6e0f..93e3b13b58 100644 --- a/src/commands/organization/cmd-organization-list.test.mts +++ b/src/commands/organization/cmd-organization-list.test.mts @@ -41,7 +41,7 @@ describe('socket organization list', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization list\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket organization list`' ) diff --git a/src/commands/organization/cmd-organization-policy-license.test.mts b/src/commands/organization/cmd-organization-policy-license.test.mts index 5f0157b51c..e500ca614f 100644 --- a/src/commands/organization/cmd-organization-policy-license.test.mts +++ b/src/commands/organization/cmd-organization-policy-license.test.mts @@ -50,7 +50,7 @@ describe('socket organization policy license', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy license\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket organization policy license`' ) diff --git a/src/commands/organization/cmd-organization-policy-security.test.mts b/src/commands/organization/cmd-organization-policy-security.test.mts index 0a8225105d..cbc1048aa5 100644 --- a/src/commands/organization/cmd-organization-policy-security.test.mts +++ b/src/commands/organization/cmd-organization-policy-security.test.mts @@ -50,7 +50,7 @@ describe('socket organization policy security', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy security\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket organization policy security`' ) diff --git a/src/commands/organization/cmd-organization-policy.test.mts b/src/commands/organization/cmd-organization-policy.test.mts index f71c9f1df6..8e4285209b 100644 --- a/src/commands/organization/cmd-organization-policy.test.mts +++ b/src/commands/organization/cmd-organization-policy.test.mts @@ -41,7 +41,7 @@ describe('socket organization list', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization policy\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket organization policy`' ) diff --git a/src/commands/organization/cmd-organization-quota.test.mts b/src/commands/organization/cmd-organization-quota.test.mts index 9c4212bfb7..59ef6c1bd4 100644 --- a/src/commands/organization/cmd-organization-quota.test.mts +++ b/src/commands/organization/cmd-organization-quota.test.mts @@ -37,7 +37,7 @@ describe('socket organization quota', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization quota\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket organization quota`' ) diff --git a/src/commands/organization/cmd-organization.test.mts b/src/commands/organization/cmd-organization.test.mts index b5485fa63f..3111bede8e 100644 --- a/src/commands/organization/cmd-organization.test.mts +++ b/src/commands/organization/cmd-organization.test.mts @@ -41,7 +41,7 @@ describe('socket organization', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket organization\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket organization`' ) diff --git a/src/commands/package/cmd-package-score.test.mts b/src/commands/package/cmd-package-score.test.mts index f76ea3d169..ea83c8ee65 100644 --- a/src/commands/package/cmd-package-score.test.mts +++ b/src/commands/package/cmd-package-score.test.mts @@ -62,7 +62,7 @@ describe('socket package score', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket package score\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect( stderr, 'header should include command (without params)' diff --git a/src/commands/package/cmd-package-shallow.test.mts b/src/commands/package/cmd-package-shallow.test.mts index cb7bafa4cc..adcfb4f964 100644 --- a/src/commands/package/cmd-package-shallow.test.mts +++ b/src/commands/package/cmd-package-shallow.test.mts @@ -62,7 +62,7 @@ describe('socket package shallow', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket package shallow`' ) diff --git a/src/commands/package/cmd-package.test.mts b/src/commands/package/cmd-package.test.mts index 659e50490b..1263a5ce7b 100644 --- a/src/commands/package/cmd-package.test.mts +++ b/src/commands/package/cmd-package.test.mts @@ -42,7 +42,7 @@ describe('socket package', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket package\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket package`' ) diff --git a/src/commands/raw-npm/cmd-raw-npm.test.mts b/src/commands/raw-npm/cmd-raw-npm.test.mts index 14640a3b58..0078094c29 100644 --- a/src/commands/raw-npm/cmd-raw-npm.test.mts +++ b/src/commands/raw-npm/cmd-raw-npm.test.mts @@ -35,7 +35,7 @@ describe('socket raw-npm', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket raw-npm\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket raw-npm`' ) diff --git a/src/commands/raw-npx/cmd-raw-npx.test.mts b/src/commands/raw-npx/cmd-raw-npx.test.mts index 3763cd60a1..e46e3465a3 100644 --- a/src/commands/raw-npx/cmd-raw-npx.test.mts +++ b/src/commands/raw-npx/cmd-raw-npx.test.mts @@ -35,7 +35,7 @@ describe('socket raw-npx', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket raw-npx\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket raw-npx`' ) diff --git a/src/commands/report/cmd-report-create.test.mts b/src/commands/report/cmd-report-create.test.mts index 666513d391..6a43ae3ea7 100644 --- a/src/commands/report/cmd-report-create.test.mts +++ b/src/commands/report/cmd-report-create.test.mts @@ -32,7 +32,7 @@ describe('socket report create', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket report create`' ) diff --git a/src/commands/report/cmd-report-view.test.mts b/src/commands/report/cmd-report-view.test.mts index 666513d391..6a43ae3ea7 100644 --- a/src/commands/report/cmd-report-view.test.mts +++ b/src/commands/report/cmd-report-view.test.mts @@ -32,7 +32,7 @@ describe('socket report create', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket report create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket report create`' ) diff --git a/src/commands/report/cmd-report.test.mts b/src/commands/report/cmd-report.test.mts index 32f688e6c5..ebc03e6b32 100644 --- a/src/commands/report/cmd-report.test.mts +++ b/src/commands/report/cmd-report.test.mts @@ -42,7 +42,7 @@ describe('socket report', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket report\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket report`' ) diff --git a/src/commands/repos/cmd-repos-create.test.mts b/src/commands/repos/cmd-repos-create.test.mts index 5f6d5fb48d..a53bf22dda 100644 --- a/src/commands/repos/cmd-repos-create.test.mts +++ b/src/commands/repos/cmd-repos-create.test.mts @@ -51,7 +51,7 @@ describe('socket repos create', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket repos create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket repos create`' ) diff --git a/src/commands/repos/cmd-repos-del.test.mts b/src/commands/repos/cmd-repos-del.test.mts index bf645a94f0..f451bdc481 100644 --- a/src/commands/repos/cmd-repos-del.test.mts +++ b/src/commands/repos/cmd-repos-del.test.mts @@ -46,7 +46,7 @@ describe('socket repos del', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket repos del\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket repos del`' ) diff --git a/src/commands/repos/cmd-repos-list.test.mts b/src/commands/repos/cmd-repos-list.test.mts index 8041988055..8671ff4a9d 100644 --- a/src/commands/repos/cmd-repos-list.test.mts +++ b/src/commands/repos/cmd-repos-list.test.mts @@ -50,7 +50,7 @@ describe('socket repos list', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket repos list\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket repos list`' ) diff --git a/src/commands/repos/cmd-repos-update.test.mts b/src/commands/repos/cmd-repos-update.test.mts index f351872f2b..84b753b4d4 100644 --- a/src/commands/repos/cmd-repos-update.test.mts +++ b/src/commands/repos/cmd-repos-update.test.mts @@ -51,7 +51,7 @@ describe('socket repos update', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket repos update\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket repos update`' ) diff --git a/src/commands/repos/cmd-repos-view.test.mts b/src/commands/repos/cmd-repos-view.test.mts index cdaba8dc99..864f6711c0 100644 --- a/src/commands/repos/cmd-repos-view.test.mts +++ b/src/commands/repos/cmd-repos-view.test.mts @@ -47,7 +47,7 @@ describe('socket repos view', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket repos view\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket repos view`' ) diff --git a/src/commands/repos/cmd-repos.test.mts b/src/commands/repos/cmd-repos.test.mts index 64cfaf8929..7820713801 100644 --- a/src/commands/repos/cmd-repos.test.mts +++ b/src/commands/repos/cmd-repos.test.mts @@ -45,7 +45,7 @@ describe('socket repos', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket repos\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket repos`') } ) diff --git a/src/commands/scan/cmd-scan-create.test.mts b/src/commands/scan/cmd-scan-create.test.mts index bf5bf2d722..41b0268bd8 100644 --- a/src/commands/scan/cmd-scan-create.test.mts +++ b/src/commands/scan/cmd-scan-create.test.mts @@ -80,7 +80,7 @@ describe('socket scan create', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan create\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan create`' ) diff --git a/src/commands/scan/cmd-scan-del.test.mts b/src/commands/scan/cmd-scan-del.test.mts index f0ce2eb23a..6111d6529a 100644 --- a/src/commands/scan/cmd-scan-del.test.mts +++ b/src/commands/scan/cmd-scan-del.test.mts @@ -46,7 +46,7 @@ describe('socket scan del', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan del\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan del`' ) diff --git a/src/commands/scan/cmd-scan-diff.test.mts b/src/commands/scan/cmd-scan-diff.test.mts index addf94e7b2..2a8fc03ea8 100644 --- a/src/commands/scan/cmd-scan-diff.test.mts +++ b/src/commands/scan/cmd-scan-diff.test.mts @@ -56,7 +56,7 @@ describe('socket scan diff', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan diff\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan diff`' ) diff --git a/src/commands/scan/cmd-scan-list.test.mts b/src/commands/scan/cmd-scan-list.test.mts index 82ecf0152b..38d0266d83 100644 --- a/src/commands/scan/cmd-scan-list.test.mts +++ b/src/commands/scan/cmd-scan-list.test.mts @@ -54,7 +54,7 @@ describe('socket scan list', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan list\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan list`' ) diff --git a/src/commands/scan/cmd-scan-metadata.test.mts b/src/commands/scan/cmd-scan-metadata.test.mts index 4c58a69d21..169a1a570c 100644 --- a/src/commands/scan/cmd-scan-metadata.test.mts +++ b/src/commands/scan/cmd-scan-metadata.test.mts @@ -46,7 +46,7 @@ describe('socket scan metadata', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan metadata\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan metadata`' ) diff --git a/src/commands/scan/cmd-scan-report.test.mts b/src/commands/scan/cmd-scan-report.test.mts index 938fdb2745..f4427d1cc7 100644 --- a/src/commands/scan/cmd-scan-report.test.mts +++ b/src/commands/scan/cmd-scan-report.test.mts @@ -60,7 +60,7 @@ describe('socket scan report', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan report\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan report`' ) diff --git a/src/commands/scan/cmd-scan-view.test.mts b/src/commands/scan/cmd-scan-view.test.mts index c89775a5d2..336d8aefb9 100644 --- a/src/commands/scan/cmd-scan-view.test.mts +++ b/src/commands/scan/cmd-scan-view.test.mts @@ -49,7 +49,7 @@ describe('socket scan view', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan view\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket scan view`' ) diff --git a/src/commands/scan/cmd-scan.test.mts b/src/commands/scan/cmd-scan.test.mts index 597603537b..d7a0188653 100644 --- a/src/commands/scan/cmd-scan.test.mts +++ b/src/commands/scan/cmd-scan.test.mts @@ -47,7 +47,7 @@ describe('socket scan', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket scan\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain('`socket scan`') } ) diff --git a/src/commands/threat-feed/cmd-threat-feed.test.mts b/src/commands/threat-feed/cmd-threat-feed.test.mts index 5519621908..4ddf7c7330 100644 --- a/src/commands/threat-feed/cmd-threat-feed.test.mts +++ b/src/commands/threat-feed/cmd-threat-feed.test.mts @@ -79,7 +79,7 @@ describe('socket threat-feed', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket threat-feed\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket threat-feed`' ) diff --git a/src/commands/wrapper/cmd-wrapper.test.mts b/src/commands/wrapper/cmd-wrapper.test.mts index 7f424b5cad..af89147ef7 100644 --- a/src/commands/wrapper/cmd-wrapper.test.mts +++ b/src/commands/wrapper/cmd-wrapper.test.mts @@ -41,7 +41,7 @@ describe('socket wrapper', async () => { |_____|___|___|_,_|___|_|.dev | Command: \`socket wrapper\`, cwd: " `) - expect(code, 'help should exit with code 2').toBe(2) + expect(code, 'explicit help should exit with code 0').toBe(0) expect(stderr, 'banner includes base command').toContain( '`socket wrapper`' )