Skip to content

Pin @coana-tech/cli version; make reachability auto-update opt-in#230

Draft
Martin Torp (mtorp) wants to merge 4 commits into
mainfrom
martin/remove-auto-update-from-the-socket-pytho
Draft

Pin @coana-tech/cli version; make reachability auto-update opt-in#230
Martin Torp (mtorp) wants to merge 4 commits into
mainfrom
martin/remove-auto-update-from-the-socket-pytho

Conversation

@mtorp
Copy link
Copy Markdown
Contributor

@mtorp Martin Torp (mtorp) commented Jun 8, 2026

Why

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 the operator opting in — is undesirable for environments that need to review/approve dependency updates before adopting them. This makes the engine version explicit and opt-in, and aligns the launcher behavior with the Socket Node CLI.

What changed

Pin the engine version (no silent auto-update)

  • Reachability now runs a fixed @coana-tech/cli version baked into the release (DEFAULT_COANA_CLI_VERSION = 15.3.24, matching the Node CLI's pin). The engine version changes only through a standard pip upgrade of this CLI.
  • The npm install -g @coana-tech/cli step (the auto-update) is removed entirely. An existing global install is left untouched — never auto-updated or downgraded.
  • Opt into newest with --reach-version latest; pin an explicit version with --reach-version <semver>.

Launcher (parity with the Socket Node CLI's dlx path)

  • Run the engine via npx --yes --force @coana-tech/cli@<ver> … — the exact flags the Node CLI passes for coana. --yes skips npx's interactive install prompt so non-interactive/CI runs don't hang. (Note: --force does not force a re-download of an already-cached pinned version; it mirrors the Node CLI's flags rather than bypassing the cache.)
  • npm install + node fallback: if the npx launcher is missing or dies before the engine starts (spawn error / signal / exit ≥128), fall back to npm install --no-save --no-package-lock --no-audit --no-fund --prefix <tmpdir> @coana-tech/cli@<ver>, resolve the bin from the installed package.json, and run via node. Small positive exit codes are real engine failures and are not retried. The resolved install is cached per version for the process lifetime (installs once).
  • Tunable via SOCKET_CLI_COANA_FORCE_NPM_INSTALL (use the fallback as the primary path) and SOCKET_CLI_COANA_DISABLE_NPM_FALLBACK (never fall back). node is now part of the up-front prerequisite check. Strips npm_package_* env vars before spawning to avoid E2BIG in large monorepos.

Docs / changelog

  • Updated --reach-version help, docs/cli-reference.md, and CHANGELOG.md (2.4.7).

Tests

tests/unit/test_reachability.py (29 tests): spec resolution, the --yes --force flags, npm_package_* stripping, the launcher-failure heuristic, every fallback branch (launcher failure / missing npx / FORCE_NPM_INSTALL / DISABLE_NPM_FALLBACK), per-version install caching, the node-missing error, and real _resolve_coana_bin / _build_coana_node_cmd parsing. Full unit suite: 282 passed, 2 (pre-existing, unrelated) skips.

Review

A comprehensive automated review was run on this PR; its Major findings (accurate npx-cache wording, a per-version fallback cache to avoid temp-dir leak / re-install, and a clear error + prereq for a missing node) have been addressed in the latest commit.

Maintenance note

DEFAULT_COANA_CLI_VERSION is a deliberate, reviewable bump per release rather than an implicit "always latest". Reviewers should expect to update it (and the currently 15.3.24 references in the docs/CHANGELOG) together.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 8, 2026

🚀 Preview package published!

Install with:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socketsecurity==2.4.7.dev5

Docker image: socketdev/cli:pr-230

@mtorp Martin Torp (mtorp) force-pushed the martin/remove-auto-update-from-the-socket-pytho branch from c92df38 to ee8e107 Compare June 8, 2026 09:41
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.
@mtorp Martin Torp (mtorp) force-pushed the martin/remove-auto-update-from-the-socket-pytho branch from ee8e107 to adb2de7 Compare June 8, 2026 09:42
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).
…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.
@mtorp Martin Torp (mtorp) deployed to socket-firewall June 8, 2026 15:46 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant