Skip to content

Commit b7d50f0

Browse files
committed
chore(cleanup): trim 4 more cascade-dead helpers
These surfaced as truly-test-only after the previous batch deleted their last live callers. Same pattern: helper + matching test block both deleted. commands/fix/git.mts: drop createSocketFixBranchParser + the associated SocketFixBranchParser + SocketFixBranchParseResult types (was only consumed by genericSocketFixBranchParser, deleted in the previous batch). env/python-version.mts: drop getPythonMajorMinor (only consumed by getPythonSitePackagesPath, deleted previously). util/ecosystem/types.mts: drop ALL_SUPPORTED_ECOSYSTEMS (only consumed by isValidEcosystem, deleted previously). util/fs/path-resolve.mts: drop findNpmDirPathSync + its support imports (existsSync, path, NPM, WIN32, isDirSync, NODE_MODULES). Was only consumed by getNpmDirPath, deleted previously.
1 parent 1abcc2d commit b7d50f0

9 files changed

Lines changed: 1 addition & 286 deletions

File tree

packages/cli/src/commands/fix/git.mts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ const GITHUB_ADVISORIES_URL = 'https://github.com/advisories'
99
// GHSA ID pattern: GHSA-xxxx-xxxx-xxxx (4 alphanumeric segments).
1010
const GHSA_ID_PATTERN = /^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/i
1111

12-
type SocketFixBranchParser = (
13-
branch: string,
14-
) => SocketFixBranchParseResult | undefined
15-
16-
type SocketFixBranchParseResult = {
17-
ghsaId: string
18-
}
19-
20-
export function createSocketFixBranchParser(
21-
ghsaId?: string | undefined,
22-
): SocketFixBranchParser {
23-
const pattern = getSocketFixBranchPattern(ghsaId)
24-
return function parse(
25-
branch: string,
26-
): SocketFixBranchParseResult | undefined {
27-
const match = pattern.exec(branch) as [string, string] | null
28-
if (!match) {
29-
return undefined
30-
}
31-
const { 1: ghsaId } = match
32-
return { ghsaId } as SocketFixBranchParseResult
33-
}
34-
}
35-
3612
export function getSocketFixBranchName(ghsaId: string): string {
3713
return `socket/fix/${ghsaId}`
3814
}

packages/cli/src/env/python-version.mts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@
88

99
import process from 'node:process'
1010

11-
/**
12-
* Get the Python major.minor version for site-packages path (e.g., "3.11").
13-
* Used to construct: python/lib/python3.11/site-packages/
14-
*/
15-
export function getPythonMajorMinor(): string {
16-
const version = getPythonVersion()
17-
const parts = version?.split('.') ?? []
18-
if (parts.length < 2 || !parts[0] || !parts[1]) {
19-
// Return safe default instead of crashing CLI on startup.
20-
return '3.11'
21-
}
22-
return `${parts[0]}.${parts[1]}`
23-
}
24-
2511
/**
2612
* Get the full Python version (e.g., "3.11.14").
2713
*/

packages/cli/src/util/ecosystem/types.mts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ export const ALL_ECOSYSTEMS = [
9191
// export type _Check_ALL_ECOSYSTEMS_has_no_extras =
9292
// ExpectNever<ExtraInAllEcosystems>
9393

94-
export const ALL_SUPPORTED_ECOSYSTEMS = new Set<string>(ALL_ECOSYSTEMS)
95-
9694
export function getEcosystemChoicesForMeow(): string[] {
9795
return [...ALL_ECOSYSTEMS]
9896
}

packages/cli/src/util/fs/path-resolve.mts

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
import { existsSync } from 'node:fs'
2-
import path from 'node:path'
3-
41
import { resolveRealBinSync } from '@socketsecurity/lib-stable/bin/resolve'
52
import { whichRealSync } from '@socketsecurity/lib-stable/bin/which'
6-
import { NPM } from '@socketsecurity/lib-stable/constants/agents'
7-
import { WIN32 } from '@socketsecurity/lib-stable/constants/platform'
8-
import { isDirSync } from '@socketsecurity/lib-stable/fs/inspect'
93

104
import {
115
createSupportedFilesFilter,
126
globWithGitIgnore,
137
pathsToGlobPatterns,
148
} from './glob.mts'
15-
import { NODE_MODULES } from '../../constants/packages.mts'
169

1710
import type { SocketYml } from '../socket-yaml.mts'
1811
import type { SocketSdkSuccessResult } from '@socketsecurity/sdk-stable'
@@ -42,73 +35,6 @@ export function findBinPathDetailsSync(binName: string): {
4235
return { name: binName, path: theBinPath }
4336
}
4437

45-
export function findNpmDirPathSync(npmBinPath: string): string | undefined {
46-
// On Windows, reject Unix absolute paths (starting with / but not //).
47-
// This allows UNC paths: //server/share, \\server\share.
48-
// And long paths: \\?\C:\..., //?/C:/...
49-
// Backslash paths (\\...) don't match startsWith('/') so they pass through.
50-
/* c8 ignore start - WIN32-only branch, tests run on macOS/Linux */
51-
if (WIN32 && npmBinPath.startsWith('/') && !npmBinPath.startsWith('//')) {
52-
return undefined
53-
}
54-
/* c8 ignore stop */
55-
const MAX_ITERATIONS = 100
56-
let thePath = npmBinPath
57-
let iterations = 0
58-
while (true) {
59-
/* c8 ignore start - safety guard against infinite loop on circular symlinks */
60-
if (iterations >= MAX_ITERATIONS) {
61-
throw new Error(
62-
`npm path resolution walked ${MAX_ITERATIONS} directories without finding lib/node_modules/npm starting from "${npmBinPath}" (current: "${thePath}"); check for a circular symlink or corrupt node install`,
63-
)
64-
}
65-
/* c8 ignore stop */
66-
iterations += 1
67-
const libNmNpmPath = path.join(thePath, `lib/${NODE_MODULES}/${NPM}`)
68-
// mise, which uses opaque binaries, puts its npm bin in a path like:
69-
// /Users/<user>/.local/share/mise/installs/node/vX.X.X/bin/npm.
70-
// HOWEVER, the location of the npm install is:
71-
// /Users/<user>/.local/share/mise/installs/node/vX.X.X/lib/node_modules/npm.
72-
if (
73-
// Use existsSync here because statsSync, even with { throwIfNoEntry: false },
74-
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
75-
// See https://github.com/nodejs/node/issues/56993.
76-
isDirSync(libNmNpmPath)
77-
) {
78-
thePath = libNmNpmPath
79-
}
80-
const hasNmInCurrPath = isDirSync(path.join(thePath, NODE_MODULES))
81-
const hasNmInParentPath =
82-
!hasNmInCurrPath && isDirSync(path.join(thePath, `../${NODE_MODULES}`))
83-
if (
84-
// npm bin paths may look like:
85-
// /usr/local/share/npm/bin/npm
86-
// ~/.nvm/versions/node/vX.X.X/bin/npm
87-
// %USERPROFILE%\AppData\Roaming\npm\bin\npm.cmd
88-
// OR
89-
// C:\Program Files\nodejs\npm.cmd
90-
//
91-
// In practically all cases the npm path contains a node_modules folder:
92-
// /usr/local/share/npm/bin/npm/node_modules
93-
// C:\Program Files\nodejs\node_modules
94-
(hasNmInCurrPath ||
95-
// In some bespoke cases the node_modules folder is in the parent directory.
96-
hasNmInParentPath) &&
97-
// Optimistically look for the default location.
98-
(path.basename(thePath) === NPM ||
99-
// Chocolatey installs npm bins in the same directory as node bins.
100-
(!!WIN32 && existsSync(path.join(thePath, `${NPM}.cmd`))))
101-
) {
102-
return hasNmInParentPath ? path.dirname(thePath) : thePath
103-
}
104-
const parent = path.dirname(thePath)
105-
if (parent === thePath) {
106-
return undefined
107-
}
108-
thePath = parent
109-
}
110-
}
111-
11238
type PackageFilesForScanOptions = {
11339
cwd?: string | undefined
11440
config?: SocketYml | undefined

packages/cli/test/unit/commands/fix/git.test.mts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import { describe, expect, it } from 'vitest'
1515

1616
import {
17-
createSocketFixBranchParser,
1817
getSocketFixBranchName,
1918
getSocketFixBranchPattern,
2019
getSocketFixCommitMessage,
@@ -154,29 +153,6 @@ describe('fix/git utilities', () => {
154153
})
155154
})
156155

157-
describe('createSocketFixBranchParser', () => {
158-
it('parses socket fix branch names', () => {
159-
const parser = createSocketFixBranchParser()
160-
const result = parser('socket/fix/GHSA-1234-5678-9abc')
161-
expect(result).toEqual({ ghsaId: 'GHSA-1234-5678-9abc' })
162-
})
163-
164-
it('returns undefined for non-matching branches', () => {
165-
const parser = createSocketFixBranchParser()
166-
expect(parser('main')).toBeUndefined()
167-
expect(parser('feature/something')).toBeUndefined()
168-
expect(parser('socket/other/GHSA-1234')).toBeUndefined()
169-
})
170-
171-
it('parses with specific GHSA ID filter', () => {
172-
const parser = createSocketFixBranchParser('GHSA-1234-5678-9abc')
173-
expect(parser('socket/fix/GHSA-1234-5678-9abc')).toEqual({
174-
ghsaId: 'GHSA-1234-5678-9abc',
175-
})
176-
expect(parser('socket/fix/GHSA-other-ghsa-idxx')).toBeUndefined()
177-
})
178-
})
179-
180156
describe('getSocketFixCommitMessage', () => {
181157
it('returns basic commit message without details', () => {
182158
expect(getSocketFixCommitMessage('GHSA-1234-5678-9abc')).toBe(

packages/cli/test/unit/env/python-version.test.mts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
88

9-
import {
10-
getPythonMajorMinor,
11-
getPythonVersion,
12-
} from '../../../src/env/python-version.mts'
9+
import { getPythonVersion } from '../../../src/env/python-version.mts'
1310

1411
describe('env/python-version', () => {
1512
let original: string | undefined
@@ -33,30 +30,4 @@ describe('env/python-version', () => {
3330
})
3431
})
3532

36-
describe('getPythonMajorMinor', () => {
37-
it('returns major.minor from a full semver-style string', () => {
38-
process.env['INLINED_PYTHON_VERSION'] = '3.12.5'
39-
expect(getPythonMajorMinor()).toBe('3.12')
40-
})
41-
42-
it('returns major.minor when only major.minor is set', () => {
43-
process.env['INLINED_PYTHON_VERSION'] = '3.13'
44-
expect(getPythonMajorMinor()).toBe('3.13')
45-
})
46-
47-
it('falls back to 3.11 when version is missing', () => {
48-
delete process.env['INLINED_PYTHON_VERSION']
49-
expect(getPythonMajorMinor()).toBe('3.11')
50-
})
51-
52-
it('falls back to 3.11 when version is malformed (one part)', () => {
53-
process.env['INLINED_PYTHON_VERSION'] = '3'
54-
expect(getPythonMajorMinor()).toBe('3.11')
55-
})
56-
57-
it('falls back to 3.11 when version is empty', () => {
58-
process.env['INLINED_PYTHON_VERSION'] = ''
59-
expect(getPythonMajorMinor()).toBe('3.11')
60-
})
61-
})
6233
})

packages/cli/test/unit/util/basics/vfs-extract.test.mts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ vi.mock('../../../../src/util/sea/detect.mts', () => ({
3232
isSeaBinary: mockIsSeaBinary,
3333
}))
3434

35-
const mockGetPythonMajorMinor = vi.hoisted(() => vi.fn(() => '3.12'))
36-
vi.mock('../../../../src/env/python-version.mts', () => ({
37-
getPythonMajorMinor: mockGetPythonMajorMinor,
38-
}))
39-
4035
vi.mock('../../../../src/constants/paths.mts', () => ({
4136
UPDATE_STORE_DIR: '.socket/_dlx',
4237
}))

packages/cli/test/unit/util/ecosystem/types.test.mts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { describe, expect, it } from 'vitest'
1616

1717
import {
1818
ALL_ECOSYSTEMS,
19-
ALL_SUPPORTED_ECOSYSTEMS,
2019
getEcosystemChoicesForMeow,
2120
} from '../../../../src/util/ecosystem/types.mts'
2221

@@ -41,18 +40,6 @@ describe('ecosystem utilities', () => {
4140
})
4241
})
4342

44-
describe('ALL_SUPPORTED_ECOSYSTEMS', () => {
45-
it('is a Set containing all ecosystems', () => {
46-
expect(ALL_SUPPORTED_ECOSYSTEMS).toBeInstanceOf(Set)
47-
expect(ALL_SUPPORTED_ECOSYSTEMS.size).toBe(ALL_ECOSYSTEMS.length)
48-
49-
for (let i = 0, { length } = ALL_ECOSYSTEMS; i < length; i += 1) {
50-
const ecosystem = ALL_ECOSYSTEMS[i]
51-
expect(ALL_SUPPORTED_ECOSYSTEMS.has(ecosystem)).toBe(true)
52-
}
53-
})
54-
})
55-
5643
describe('getEcosystemChoicesForMeow', () => {
5744
it('returns array of all ecosystems', () => {
5845
const choices = getEcosystemChoicesForMeow()

packages/cli/test/unit/util/fs/path-resolve.test.mts

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '../../../../src/constants/packages.mts'
2626
import {
2727
findBinPathDetailsSync,
28-
findNpmDirPathSync,
2928
getPackageFilesForScan,
3029
} from '../../../../src/util/fs/path-resolve.mts'
3130
import { createTestWorkspace } from '../../../helpers/workspace-helper.mts'
@@ -439,103 +438,4 @@ describe('Path Resolve', () => {
439438
})
440439
})
441440

442-
describe('findNpmDirPathSync', () => {
443-
beforeEach(() => {
444-
vi.clearAllMocks()
445-
})
446-
447-
it('finds npm directory in lib/node_modules structure', async () => {
448-
const { isDirSync } = vi.mocked(await import('@socketsecurity/lib-stable/fs/inspect'))
449-
450-
isDirSync.mockImplementation(p => {
451-
const pathStr = normalizePath(String(p))
452-
if (pathStr.includes('lib/node_modules/npm')) {
453-
return true
454-
}
455-
if (pathStr.endsWith('/node_modules')) {
456-
return true
457-
}
458-
return false
459-
})
460-
461-
const result = findNpmDirPathSync('/usr/local/bin/npm')
462-
463-
expect(WIN32 ? result : normalizePath(result)).toBe(
464-
WIN32
465-
? undefined
466-
: normalizePath('/usr/local/bin/npm/lib/node_modules/npm'),
467-
)
468-
})
469-
470-
it('finds npm directory with node_modules in current path', async () => {
471-
const { isDirSync } = vi.mocked(await import('@socketsecurity/lib-stable/fs/inspect'))
472-
473-
isDirSync.mockImplementation(p => {
474-
const pathStr = normalizePath(String(p))
475-
if (pathStr === normalizePath('/usr/local/npm/node_modules')) {
476-
return true
477-
}
478-
return false
479-
})
480-
481-
const result = findNpmDirPathSync('/usr/local/npm')
482-
483-
expect(WIN32 ? result : normalizePath(result)).toBe(
484-
WIN32 ? undefined : normalizePath('/usr/local/npm'),
485-
)
486-
})
487-
488-
it('finds npm directory with node_modules in parent path', async () => {
489-
const { isDirSync } = vi.mocked(await import('@socketsecurity/lib-stable/fs/inspect'))
490-
491-
isDirSync.mockImplementation(p => {
492-
const pathStr = normalizePath(String(p))
493-
if (pathStr === normalizePath('/usr/local/npm/node_modules')) {
494-
return false
495-
}
496-
if (pathStr === normalizePath('/usr/local/node_modules')) {
497-
return true
498-
}
499-
return false
500-
})
501-
502-
const result = findNpmDirPathSync('/usr/local/npm')
503-
504-
expect(WIN32 ? result : normalizePath(result)).toBe(
505-
WIN32 ? undefined : normalizePath('/usr/local'),
506-
)
507-
})
508-
509-
it('returns undefined when no npm directory found', async () => {
510-
const { isDirSync } = vi.mocked(await import('@socketsecurity/lib-stable/fs/inspect'))
511-
512-
isDirSync.mockReturnValue(false)
513-
514-
const result = findNpmDirPathSync('/random/path')
515-
516-
expect(result).toBeUndefined()
517-
})
518-
519-
it('handles nvm directory structure', async () => {
520-
const { isDirSync } = vi.mocked(await import('@socketsecurity/lib-stable/fs/inspect'))
521-
522-
isDirSync.mockImplementation(p => {
523-
const pathStr = normalizePath(String(p))
524-
if (pathStr.includes('.nvm') && pathStr.endsWith('/node_modules')) {
525-
return true
526-
}
527-
return false
528-
})
529-
530-
const result = findNpmDirPathSync(
531-
'/Users/user/.nvm/versions/node/v18.0.0/bin/npm',
532-
)
533-
534-
expect(WIN32 ? result : normalizePath(result)).toBe(
535-
WIN32
536-
? undefined
537-
: normalizePath('/Users/user/.nvm/versions/node/v18.0.0/bin/npm'),
538-
)
539-
})
540-
})
541441
})

0 commit comments

Comments
 (0)