Skip to content

Commit f912fff

Browse files
authored
Merge branch 'main' into barslev/add-option-reach-use-unreachable-from-precomputation
2 parents dbd1c0b + 47ef4a3 commit f912fff

26 files changed

+477
-356
lines changed

packages/bootstrap/.config/esbuild.npm.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { build } from 'esbuild'
1111
import { unicodeTransformPlugin } from '@socketsecurity/build-infra/lib/esbuild-plugin-unicode-transform'
1212

1313
import nodeVersionConfig from '../node-version.json' with { type: 'json' }
14+
import socketPackageJson from '../../socket/package.json' with { type: 'json' }
1415

1516
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1617
const rootPath = path.resolve(__dirname, '..')
@@ -22,6 +23,7 @@ const config = {
2223
bundle: true,
2324
define: {
2425
__MIN_NODE_VERSION__: JSON.stringify(nodeVersionConfig.versionSemver),
26+
__SOCKET_CLI_VERSION__: JSON.stringify(socketPackageJson.version),
2527
},
2628
entryPoints: [path.join(rootPath, 'src', 'bootstrap-npm.mts')],
2729
external: [],

packages/bootstrap/.config/esbuild.sea.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { build } from 'esbuild'
1111
import { unicodeTransformPlugin } from '@socketsecurity/build-infra/lib/esbuild-plugin-unicode-transform'
1212

1313
import nodeVersionConfig from '../node-version.json' with { type: 'json' }
14+
import socketPackageJson from '../../socket/package.json' with { type: 'json' }
1415

1516
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1617
const rootPath = path.resolve(__dirname, '..')
@@ -22,6 +23,7 @@ const config = {
2223
bundle: true,
2324
define: {
2425
__MIN_NODE_VERSION__: JSON.stringify(nodeVersionConfig.versionSemver),
26+
__SOCKET_CLI_VERSION__: JSON.stringify(socketPackageJson.version),
2527
},
2628
entryPoints: [path.join(rootPath, 'src', 'bootstrap-sea.mts')],
2729
external: [],

packages/bootstrap/.config/esbuild.smol.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { build } from 'esbuild'
1111
import { unicodeTransformPlugin } from '@socketsecurity/build-infra/lib/esbuild-plugin-unicode-transform'
1212

1313
import nodeVersionConfig from '../node-version.json' with { type: 'json' }
14+
import socketPackageJson from '../../socket/package.json' with { type: 'json' }
1415

1516
import { smolTransformPlugin } from './esbuild-plugin-smol-transform.mjs'
1617

@@ -21,6 +22,7 @@ const config = {
2122
bundle: true,
2223
define: {
2324
__MIN_NODE_VERSION__: JSON.stringify(nodeVersionConfig.versionSemver),
25+
__SOCKET_CLI_VERSION__: JSON.stringify(socketPackageJson.version),
2426
},
2527
entryPoints: [path.join(rootPath, 'src', 'bootstrap-smol.mts')],
2628
external: [],

packages/bootstrap/src/shared/bootstrap-shared.mjs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ const SOCKET_CLI_DISABLE_NODE_FORWARDING = envAsBoolean(
3535
// @ts-expect-error - Injected by esbuild define.
3636
const MIN_NODE_VERSION = __MIN_NODE_VERSION__
3737

38+
/**
39+
* Socket CLI version.
40+
* This constant is injected at build time by esbuild.
41+
* @type {string}
42+
*/
43+
// @ts-expect-error - Injected by esbuild define.
44+
const SOCKET_CLI_VERSION = __SOCKET_CLI_VERSION__
45+
3846
/**
3947
* Get CLI package paths.
4048
*/
@@ -173,8 +181,10 @@ export async function downloadCli() {
173181
spinner: Spinner({ shimmer: { dir: 'random' } }),
174182
operation: async () =>
175183
// Download and cache @socketsecurity/cli package.
184+
// Uses caret range (^) to auto-update within same major version.
185+
// Update notifications will only trigger for major version changes.
176186
await downloadPackage({
177-
package: '@socketsecurity/cli',
187+
package: `@socketsecurity/cli@^${SOCKET_CLI_VERSION}`,
178188
binaryName: 'socket',
179189
// Use cached version if available.
180190
force: false,
@@ -206,6 +216,12 @@ export async function findAndExecuteCli(args) {
206216
const result = await downloadCli()
207217
const cliPackageDir = result.packageDir
208218

219+
// Pass metadata to CLI for manifest writing.
220+
// CLI will use this to write entries to ~/.socket/_dlx/.dlx-manifest.json
221+
const spec = `@socketsecurity/cli@^${SOCKET_CLI_VERSION}`
222+
process.env.SOCKET_CLI_BOOTSTRAP_SPEC = spec
223+
process.env.SOCKET_CLI_BOOTSTRAP_CACHE_DIR = cliPackageDir
224+
209225
// Get CLI entry path (dist/index.js handles brotli decompression internally).
210226
const { cliEntry } = getCliPaths(cliPackageDir)
211227

packages/cli/src/cli-entry.mts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import './polyfills/intl-stub.mts'
77
import { setTheme } from '@socketsecurity/lib/themes'
88
setTheme('socket')
99

10+
import path from 'node:path'
1011
import process from 'node:process'
1112
import { fileURLToPath, pathToFileURL } from 'node:url'
1213

@@ -33,9 +34,12 @@ import { messageWithCauses, stackWithCauses } from 'pony-cause'
3334
import lookupRegistryAuthToken from 'registry-auth-token'
3435
import lookupRegistryUrl from 'registry-url'
3536

36-
import { debug, debugDir } from '@socketsecurity/lib/debug'
37+
import { debug as debugNs, debugDir } from '@socketsecurity/lib/debug'
3738
import { getDefaultLogger } from '@socketsecurity/lib/logger'
3839

40+
// Debug logger for manifest operations
41+
const debug = debugNs
42+
3943
import { rootAliases, rootCommands } from './commands.mts'
4044
import ENV from './constants/env.mts'
4145
import { SOCKET_CLI_BIN_NAME } from './constants/packages.mts'
@@ -51,9 +55,55 @@ import { serializeResultJson } from './utils/output/result-json.mts'
5155
import { runPreflightDownloads } from './utils/preflight/downloads.mts'
5256
import { isSeaBinary } from './utils/sea/detect.mts'
5357
import { scheduleUpdateCheck } from './utils/update/manager.mts'
58+
import { dlxManifest } from '@socketsecurity/lib/dlx-manifest'
5459

5560
const __filename = fileURLToPath(import.meta.url)
5661

62+
/**
63+
* Write manifest entry for CLI installed via bootstrap.
64+
* Bootstrap passes spec and cache dir via environment variables.
65+
*/
66+
async function writeBootstrapManifestEntry(): Promise<void> {
67+
const spec = ENV.SOCKET_CLI_BOOTSTRAP_SPEC
68+
const cacheDir = ENV.SOCKET_CLI_BOOTSTRAP_CACHE_DIR
69+
70+
if (!spec || !cacheDir) {
71+
// Not launched via bootstrap, skip.
72+
return
73+
}
74+
75+
try {
76+
// Extract cache key from path (last segment)
77+
const cacheKey = path.basename(cacheDir)
78+
79+
// Read package.json to get installed version
80+
const pkgJsonPath = path.join(
81+
cacheDir,
82+
'node_modules',
83+
'@socketsecurity',
84+
'cli',
85+
'package.json',
86+
)
87+
88+
let installedVersion = '0.0.0'
89+
try {
90+
const fs = await import('node:fs/promises')
91+
const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, 'utf8'))
92+
installedVersion = pkgJson.version || '0.0.0'
93+
} catch {
94+
// Failed to read version, use default
95+
}
96+
97+
// Write manifest entry.
98+
await dlxManifest.setPackageEntry(spec, cacheKey, {
99+
installed_version: installedVersion,
100+
})
101+
} catch (error) {
102+
// Silently ignore manifest write errors - not critical
103+
debug(`Failed to write bootstrap manifest entry: ${error}`)
104+
}
105+
}
106+
57107
void (async () => {
58108
// Skip update checks in test environments.
59109
if (!ENV.VITEST && !ENV.CI) {
@@ -68,6 +118,10 @@ void (async () => {
68118
version: ENV.INLINED_SOCKET_CLI_VERSION || '0.0.0',
69119
})
70120

121+
// Write manifest entry if launched via bootstrap (SEA/smol).
122+
// Bootstrap passes spec and cache dir via env vars.
123+
await writeBootstrapManifestEntry()
124+
71125
// Background preflight downloads for optional dependencies.
72126
// This silently downloads @coana-tech/cli and @socketbin/cli-ai in the
73127
// background to ensure they're cached for future use.

packages/cli/src/commands/audit-log/fetch-audit-log.test.mts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ describe('fetchAuditLog', () => {
5050
const result = await fetchAuditLog(config)
5151

5252
expect(mockSdk.getAuditLogEvents).toHaveBeenCalledWith('test-org', {
53-
outputJson: 'true',
54-
outputMarkdown: 'false',
53+
outputJson: true,
54+
outputMarkdown: false,
5555
orgSlug: 'test-org',
5656
type: 'all',
57-
page: '1',
58-
per_page: '100',
57+
page: 1,
58+
per_page: 100,
5959
})
6060
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
6161
description: 'audit log for test-org',
@@ -137,8 +137,8 @@ describe('fetchAuditLog', () => {
137137
expect(mockSdk.getAuditLogEvents).toHaveBeenCalledWith(
138138
'test-org',
139139
expect.objectContaining({
140-
page: '5',
141-
per_page: '25',
140+
page: 5,
141+
per_page: 25,
142142
}),
143143
)
144144
})

packages/cli/src/commands/repository/fetch-list-all-repos.test.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ describe('fetchListAllRepos', () => {
5151
expect(mockSdk.listRepositories).toHaveBeenCalledWith('test-org', {
5252
sort: undefined,
5353
direction: undefined,
54-
per_page: '100',
55-
page: '0',
54+
per_page: 100,
55+
page: 0,
5656
})
5757
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
5858
description: 'list of repositories',
@@ -164,8 +164,8 @@ describe('fetchListAllRepos', () => {
164164
expect(mockSdk.listRepositories).toHaveBeenCalledWith('sorted-org', {
165165
sort: 'name',
166166
direction: 'asc',
167-
per_page: '100',
168-
page: '0',
167+
per_page: 100,
168+
page: 0,
169169
})
170170
})
171171

packages/cli/src/commands/repository/fetch-list-repos.test.mts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ describe('fetchListRepos', () => {
6363
expect(mockSdk.listRepositories).toHaveBeenCalledWith('test-org', {
6464
sort: 'created_at',
6565
direction: 'desc',
66-
per_page: '10',
67-
page: '1',
66+
per_page: 10,
67+
page: 1,
6868
})
6969
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
7070
description: 'list of repositories',
@@ -190,8 +190,8 @@ describe('fetchListRepos', () => {
190190
expect(mockSdk.listRepositories).toHaveBeenCalledWith('large-org', {
191191
sort: 'stars',
192192
direction: 'desc',
193-
per_page: '100',
194-
page: '0',
193+
per_page: 100,
194+
page: 0,
195195
})
196196
})
197197

@@ -223,8 +223,8 @@ describe('fetchListRepos', () => {
223223
expect(mockSdk.listRepositories).toHaveBeenCalledWith('sort-org', {
224224
sort: 'alphabetical',
225225
direction: 'asc',
226-
per_page: '25',
227-
page: '0',
226+
per_page: 25,
227+
page: 0,
228228
})
229229
})
230230

packages/cli/src/commands/scan/fetch-create-org-full-scan.test.mts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ describe('fetchCreateOrgFullScan', () => {
5353
commit_hash: 'abc123',
5454
commit_message: 'Initial commit',
5555
committers: '[email protected]',
56-
make_default_branch: 'undefined',
5756
pull_request: '42',
5857
repo: 'test-repo',
59-
set_as_pending_head: 'undefined',
60-
tmp: 'undefined',
6158
},
6259
)
6360
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
@@ -171,11 +168,11 @@ describe('fetchCreateOrgFullScan', () => {
171168
commit_hash: 'xyz789',
172169
commit_message: 'Feature commit',
173170
committers: '[email protected]',
174-
make_default_branch: 'true',
171+
make_default_branch: true,
175172
pull_request: '123',
176173
repo: 'feature-repo',
177-
set_as_pending_head: 'false',
178-
tmp: 'true',
174+
set_as_pending_head: false,
175+
tmp: true,
179176
},
180177
)
181178
})
@@ -203,10 +200,7 @@ describe('fetchCreateOrgFullScan', () => {
203200
['/path/to/package.json'],
204201
{
205202
pathsRelativeTo: process.cwd(),
206-
make_default_branch: 'undefined',
207203
repo: 'test-repo',
208-
set_as_pending_head: 'undefined',
209-
tmp: 'undefined',
210204
},
211205
)
212206
})

packages/cli/src/commands/scan/fetch-list-scans.test.mts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe('fetchOrgFullScanList', () => {
4444
sort: 'created_at',
4545
direction: 'desc',
4646
from: '2023-01-01',
47-
page: '1',
48-
per_page: '10',
47+
page: 1,
48+
per_page: 10,
4949
})
5050
expect(mockHandleApi).toHaveBeenCalledWith(expect.any(Promise), {
5151
description: 'list of scans',
@@ -141,8 +141,8 @@ describe('fetchOrgFullScanList', () => {
141141
sort: 'updated_at',
142142
direction: 'asc',
143143
from: '2023-06-01',
144-
page: '2',
145-
per_page: '25',
144+
page: 2,
145+
per_page: 25,
146146
})
147147
})
148148

@@ -168,8 +168,8 @@ describe('fetchOrgFullScanList', () => {
168168
sort: 'created_at',
169169
direction: 'desc',
170170
from: '2023-01-01',
171-
page: '1',
172-
per_page: '10',
171+
page: 1,
172+
per_page: 10,
173173
})
174174
})
175175

@@ -206,8 +206,8 @@ describe('fetchOrgFullScanList', () => {
206206
sort: 'created_at',
207207
direction: 'desc',
208208
from: '2023-01-01',
209-
page: String(page),
210-
per_page: String(perPage),
209+
page,
210+
per_page: perPage,
211211
})
212212
}
213213
})
@@ -245,8 +245,8 @@ describe('fetchOrgFullScanList', () => {
245245
sort,
246246
direction,
247247
from: '2023-01-01',
248-
page: '1',
249-
per_page: '10',
248+
page: 1,
249+
per_page: 10,
250250
})
251251
}
252252
})

0 commit comments

Comments
 (0)