Skip to content

Commit f5ae591

Browse files
authored
Pin @coana-tech/cli version; make reachability auto-update opt-in (#230)
* Pin @coana-tech/cli version; make reachability auto-update opt-in The Python CLI auto-updated the reachability (Coana) engine to the latest published version on every --reach run via `npm install -g @coana-tech/cli`. Automatically pulling a brand-new engine version without opting in is undesirable for environments that need to review/approve dependency updates before adopting them. Run a fixed, pinned version (DEFAULT_COANA_CLI_VERSION = 15.3.22) via `npx @coana-tech/cli@<pinned>` instead, so the engine version only changes through a standard pip upgrade of this CLI. Opt into newest with `--reach-version latest`; pin an explicit version with `--reach-version <semver>`. The global `npm install -g` step is dropped entirely, so an existing global install is never auto-updated or downgraded. * Disable npx caching and add npm-install + node fallback for coana Mirror the Socket Node CLI's coana launcher: - Run the engine via `npx --yes --force` so the npx cache is bypassed; a corrupt or partial cache entry can no longer wedge a reachability run. - Fall back to `npm install --no-save --prefix <tmp> @coana-tech/cli@<ver>` + `node <bin>` when the npx launcher is missing or dies before coana starts (spawn error / signal / exit >= 128). Small positive exit codes are treated as real coana failures and are not retried. - Toggle with SOCKET_CLI_COANA_FORCE_NPM_INSTALL and SOCKET_CLI_COANA_DISABLE_NPM_FALLBACK. - Strip npm_package_* env vars before spawning coana to avoid E2BIG in large monorepos. Kept on version 2.4.7 (same unreleased version as the pin change). * Bump pinned @coana-tech/cli to 15.3.24 * Address PR review: per-version fallback cache, node prereq, accurate npx wording - M2: cache the npm-install fallback's resolved script path per version for the process lifetime (mirrors the Node CLI's installedCoanaScriptPathsByVersion), so a repeated fallback installs once instead of re-installing + leaking a temp dir each call. - M3: surface a clear error when `node` is missing in the fallback (instead of an opaque FileNotFoundError after a costly npm install), and add `node` to the up-front prereq check. - M1: correct the overstated 'npx --force disables the cache' wording in docstrings, docs, and CHANGELOG. The code already matches the Node CLI exactly (npx --yes --force); --force does not force a re-download of an already-cached pinned version, so the docs now describe what the flags actually do rather than claiming a cache bypass. Adds tests for per-version caching, node-missing, and real _resolve_coana_bin / _build_coana_node_cmd parsing. * Address review comments: Final annotation, atexit tmp cleanup, parametrized tests - Annotate DEFAULT_COANA_CLI_VERSION with typing.Final. - Register an atexit handler to remove the npm-install fallback's temp dirs. - Trim the over-long --force explanation in _spawn_coana's docstring and drop the inline comment that duplicated it. - Use try/finally in the cache-clearing test fixture. - Parametrize the spec-resolution, npx-version, and launcher-failure-heuristic tests. * Move launch-strategy rationale from the spec resolver to _spawn_coana The 'why npx, not npm install -g' explanation describes how coana is launched, not how a package spec string is built, so it belongs on _spawn_coana (per review). Leaves _resolve_coana_package_spec with a minimal docstring. * docs: show the real --reach-version default (15.3.24) in the Default column * docs: show real reach-flag defaults from the Coana CLI implementation Fill in the Default column for the flags whose defaults come from coana, verified against the @coana-tech/cli source (coana-package-manager/packages/cli): - --reach-analysis-timeout -> 600 (cli-core.ts: defaults to 600s when unset) - --reach-analysis-memory-limit -> 8192 (index.ts --memory-limit default) - --reach-concurrency -> 1 (index.ts --concurrency default) - --reach-min-severity -> info (no coana default = analyze all; info is the effective floor)
1 parent 405fdc9 commit f5ae591

9 files changed

Lines changed: 575 additions & 130 deletions

File tree

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## 2.4.7
4+
5+
### Changed: pin @coana-tech/cli version; auto-update is now opt-in
6+
7+
- Reachability analysis now runs a fixed `@coana-tech/cli` version pinned to this CLI release
8+
(`15.3.24`) via `npx`, instead of silently pulling the latest published version on every run.
9+
Engine version changes now ride with the Socket Python CLI release (standard `pip` upgrade),
10+
giving advance notice of analysis-engine changes.
11+
- The CLI no longer runs `npm install -g @coana-tech/cli`; an existing global install is left
12+
untouched (never auto-updated or downgraded).
13+
- Opt into always-newest with `--reach-version latest`; pin an explicit version with
14+
`--reach-version <semver>` (unchanged).
15+
- Runs the engine via `npx --yes --force` (the same flags the Socket Node CLI passes for
16+
coana); `--yes` skips npx's interactive install prompt so non-interactive/CI runs don't hang.
17+
- Added an `npm install` + `node` fallback for when the `npx` launcher is missing or fails
18+
before the engine starts. The installed engine is cached per version for the process
19+
lifetime (installs once). Tunable via `SOCKET_CLI_COANA_FORCE_NPM_INSTALL` (use the fallback
20+
as the primary path) and `SOCKET_CLI_COANA_DISABLE_NPM_FALLBACK` (never fall back). `node` is
21+
now part of the up-front prerequisite check. Also strips `npm_package_*` env vars before
22+
spawning the engine to avoid `E2BIG` in large monorepos.
23+
324
## 2.4.6
425

526
### Docs: reachability reference corrections

docs/cli-reference.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ If you don't want to provide the Socket API Token every time then you can use th
240240
| Parameter | Required | Default | Description |
241241
|:---------------------------------|:---------|:--------|:---------------------------------------------------------------------------------------------------------------------------|
242242
| `--reach` | False | False | Enable reachability analysis to identify which vulnerable functions are actually called by your code. Creates a tier-1 full-application reachability scan (`scan_type=socket_tier1`). |
243-
| `--reach-version` | False | latest | Version of @coana-tech/cli to use for analysis |
244-
| `--reach-analysis-timeout` | False | *coana* | Timeout in seconds for the reachability analysis. Omitted by default, so coana applies its own (currently 600s). Alias: `--reach-timeout` |
245-
| `--reach-analysis-memory-limit` | False | *coana* | Memory limit in MB for the reachability analysis. Omitted by default, so coana applies its own (currently 8192). Alias: `--reach-memory-limit` |
246-
| `--reach-concurrency` | False | *coana* | Control parallel analysis execution (must be >= 1). Omitted by default, so coana applies its own (currently 1) |
243+
| `--reach-version` | False | 15.3.24 | Version of @coana-tech/cli to use. Defaults to the pinned version that ships with this CLI release, so the engine only changes when you upgrade the Socket CLI. Pass `latest` to always use the newest published version (opt-in auto-update), or an explicit version (e.g. `1.2.3`) to pin it. |
244+
| `--reach-analysis-timeout` | False | 600 | Timeout in seconds for the reachability analysis. Omitted by default, so coana applies its own default. Alias: `--reach-timeout` |
245+
| `--reach-analysis-memory-limit` | False | 8192 | Memory limit in MB for the reachability analysis. Omitted by default, so coana applies its own default. Alias: `--reach-memory-limit` |
246+
| `--reach-concurrency` | False | 1 | Control parallel analysis execution (must be >= 1). Omitted by default, so coana applies its own default. |
247247
| `--reach-additional-params` | False | | Pass custom parameters to the coana CLI tool |
248248
| `--reach-ecosystems` | False | | Comma-separated list of ecosystems to analyze (e.g., "npm,pypi"). If not specified, all supported ecosystems are analyzed |
249-
| `--reach-min-severity` | False | | Minimum severity level for reporting reachability results (info, low, moderate, high, critical) |
249+
| `--reach-min-severity` | False | info | Minimum severity of vulnerabilities to analyze (info, low, moderate, high, critical). Omitted by default, so coana analyzes all severities — equivalent to `info`, the lowest. |
250250
| `--reach-skip-cache` | False | False | Skip cache and force fresh reachability analysis |
251251
| `--reach-disable-analytics` | False | False | Disable analytics collection during reachability analysis |
252252
| `--reach-enable-analysis-splitting` | False | False | Enable analysis splitting/bucketing (a legacy performance feature). Splitting is disabled by default. |
@@ -262,8 +262,9 @@ If you don't want to provide the Socket API Token every time then you can use th
262262
**Reachability Analysis Requirements:**
263263
264264
The Python CLI verifies the following **up front** (before invoking the analysis engine) and exits with code **3** if any are unmet:
265-
- `npm` - Required to install and run `@coana-tech/cli` (the analysis engine)
266-
- `npx` - Required to execute `@coana-tech/cli`
265+
- `npm` - Required (verified up front; ships alongside `npx`)
266+
- `npx` - Required to fetch (on first use) and run `@coana-tech/cli` (the analysis engine)
267+
- `node` - Required to run the engine (used directly by the `npm install` fallback)
267268
- `uv` - Required by the analysis engine
268269
- An **Enterprise** Socket organization plan (any `enterprise*` plan, including Enterprise trials)
269270
@@ -313,7 +314,11 @@ Sample config files:
313314
314315
For CI-specific examples and guidance, see [`ci-cd.md`](ci-cd.md).
315316
316-
The CLI will automatically install `@coana-tech/cli` if not present. Use `--reach` to enable reachability analysis during a full scan, or add `--only-facts-file` (with `--reach`) to submit only the reachability facts file (`.socket.facts.json`) when creating the full scan.
317+
The CLI runs a pinned `@coana-tech/cli` version via `npx --yes --force` (the same flags the Socket Node CLI passes for coana); it does **not** auto-update the engine or install it globally. `--yes` skips npx's interactive install prompt so non-interactive/CI runs don't hang. If the `npx` launcher is unavailable or fails before the engine starts, the CLI falls back to `npm install`-ing the pinned version into a temp directory and running it via `node`. Pass `--reach-version latest` to opt into the newest published version. Use `--reach` to enable reachability analysis during a full scan, or add `--only-facts-file` (with `--reach`) to submit only the reachability facts file (`.socket.facts.json`) when creating the full scan.
318+
319+
The launcher fallback can be tuned via environment variables:
320+
- `SOCKET_CLI_COANA_FORCE_NPM_INSTALL` — skip `npx` entirely and always use the `npm install` + `node` path (useful where `npx` is known-broken).
321+
- `SOCKET_CLI_COANA_DISABLE_NPM_FALLBACK` — never fall back; surface the `npx` failure directly.
317322
318323
#### Advanced Configuration
319324
| Parameter | Required | Default | Description |

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.4.6"
9+
version = "2.4.7"
1010
requires-python = ">= 3.11"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.4.6'
2+
__version__ = '2.4.7'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,10 @@ def create_argument_parser() -> argparse.ArgumentParser:
943943
reachability_group.add_argument(
944944
"--reach-version",
945945
dest="reach_version",
946-
metavar="<version>",
947-
help="Specific version of @coana-tech/cli to use (e.g., '1.2.3')"
946+
metavar="<version|latest>",
947+
help="Version of @coana-tech/cli to use. Defaults to the version pinned to this CLI "
948+
"release; pass 'latest' to always use the newest published version (opt-in "
949+
"auto-update), or an explicit version (e.g. '1.2.3') to pin it."
948950
)
949951
reachability_group.add_argument(
950952
"--reach-analysis-timeout",

0 commit comments

Comments
 (0)