Remove guard mode: proxy interception is now the only flow (#386)

* refactor: remove guard mode execution paths and guard-only packages

Guard (non-proxy) mode is removed; all package-manager commands now
always run the proxy flow. Removes the guard engine, the common flow,
the extractor package, the npm/pypi dependency resolvers and the
PackageResolver plumbing that only guard mode consumed.

The guard package retains only PackageManagerGuardInteraction, which
the proxy flow and confirmation interceptors reuse for user prompts.
Proxy behavior is unchanged.

* refactor: remove proxy opt-out surfaces, guard references in config, action and docs

Removes Config.ProxyMode, ProxyConfig.Enabled, IsProxyModeEnabled, the
proxy_mode legacy fallback, PMG_PROXY_ENABLED handling and the
--proxy-mode / --include-dev-dependencies flags. Proxy interception can
no longer be disabled.

Also removes the proxy-mode input from the GitHub Action, the
proxy-mode doctor check and setup info row, updates the E2E workflow to
stop passing --proxy-mode=false, and sweeps guard-mode wording from
docs and the config template.

The legacy proxy_install_only flat key and PMG_PROXY_INSTALL_ONLY env
var remain supported. audit.FlowTypeGuard is kept so previously
recorded audit events still translate for cloud sync.

* feat: fail loudly when a removed proxy opt-out is still configured

A leftover proxy.enabled: false / proxy_mode: false config key or
PMG_PROXY_ENABLED=false / PMG_PROXY_MODE=false env var previously meant
guard mode; silently ignoring it would switch those users to proxy
interception without notice. PMG now exits with an actionable error
naming the exact source. Precedence mirrors the old resolution order:
env (ignored under lockdown) > proxy.enabled > legacy proxy_mode.

The pmg config subtree is exempt so the config file can still be fixed
with pmg config edit/set. The GitHub Action's proxy-mode input is kept
as a tombstone that fails the action when set to false and warns
otherwise.

* refactor: extract flows.RunProxy and address review findings

Collapses the identical parse-then-run body duplicated across the 12
package manager commands into flows.RunProxy. Documents the cache-hit /
offline analysis trade-off versus the removed guard manifest path,
fixes a stale non-proxy label in the E2E workflow and a stale guard
reference in the uvx parser comment.

* fix(config): mirror old proxy opt-out precedence exactly

PMG_PROXY_MODE only ever took effect through the legacy fallback, which
was gated on the presence of a proxy: key in the config file (even a
null one). Promoting it to the top env tier caused two inversions: a
stale PMG_PROXY_MODE=false hard-failed configs that resolved to proxy
mode, and PMG_PROXY_MODE=true silently overrode an explicit
proxy.enabled: false file opt-out. The check now resolves in the old
order: PMG_PROXY_ENABLED > proxy: section (presence gates the legacy
tier) > PMG_PROXY_MODE > flat proxy_mode.

parseOptOutBool also accepts numeric values (0 = false) to match
viper's WeaklyTypedInput/cast.ToBool coercion, so proxy.enabled: 0 and
proxy_mode: 0 are detected as opt-outs.

* refactor: move package manager interaction out of guard

* refactor: trim package manager interaction

* fix(config): normalize config keys viper-style in proxy opt-out check

Viper resolved config file keys case-insensitively and expanded dotted
keys, so spellings like Proxy:, Enabled:, a literal proxy.enabled key or
Proxy_Mode selected guard mode before the removal. The opt-out check now
lowercases keys recursively and nests dotted keys before matching, so
those existing opt-outs fail loudly instead of being silently ignored.

* refactor: remove inert transitive controls, dead parser state and guard audit variant

transitive / transitive_depth lost their only consumers with the
dependency resolvers; remove the config fields, flags, template and doc
entries, and the report/audit plumbing that misreported transitive
analysis as enabled.

Remove write-only parser state (PackageInstallTarget.Extras,
ParsedCommand.ManifestFiles, ShouldExtractFromManifest); IsManifestInstall
stays as it feeds sandbox gating via IsInstallationCommand.

Remove audit.FlowTypeGuard and its cloud mapping; guard events recorded
by pre-removal versions in an unsynced WAL translate to UNSPECIFIED.

* fix: address review findings on the opt-out wiring and cleanups

Move the removed-opt-out rejection from the CLI PersistentPreRun into
proxyFlow.Run: the check now fires exactly for package-manager runs, so
non-install commands (pmg setup remove, doctor, config, version) stay
usable to fix or remove an opted-out installation, and future commands
inherit or avoid the check by construction instead of by exemption list.

Also: make the e2e malicious-package assertion actually fail the job
when an install is not blocked, route pmg go through flows.RunProxy,
and drop the dead extras return from pypiParsePackageInfo (extras are
still stripped from package names).

* fix(config): make the removed opt-out check faithful to the old resolution

The gate that silenced the legacy proxy_mode surfaces matched the raw
proxy key case-sensitively in the old code, while values resolved
viper-style (case-insensitive, dotted keys); applying each semantic
where the old code did fixes both divergences: a case-variant Proxy:
section no longer hides a flat proxy_mode: false opt-out, and a dotted
proxy.enabled: false overridden by proxy_mode: true no longer errors.

Replace the generic key-tree normalization with two targeted lookups
(the check only ever resolves proxy.enabled and proxy_mode), which also
makes colliding spellings resolve deterministically. Coerce legacy-tier
values cast.ToBool-style so PMG_PROXY_MODE=off style opt-outs are
detected, log the config read error instead of swallowing it, and
shorten the error to a one-line statement with the specific remedy in
the help text.

Add lockdown coverage (env inert both directions) and a repeated-run
determinism test.

* fix(config): fall back to defaults for unrecognized proxy opt-out values

The old loader swallowed viper errors and ran on defaults, so values
like proxy.enabled: yes or PMG_PROXY_ENABLED=banana silently discarded
the whole config and defaulted to proxy. Treat them the same way now:
unrecognized values mean the default (proxy on) instead of a hard
error, and the doc comment no longer claims the old loader failed
loudly. Only values that actually meant guard mode fail.

Also check the removed opt-out before the CA trust check in pmg go,
restoring the old error precedence: a config problem must not steer
the user into an unnecessary OS trust store change.

* fix(e2e): PMG_PROXY_MODE assertion must match the legacy gate semantics

The runner's setup step writes the template config, which has a proxy:
section — and with one present the legacy PMG_PROXY_MODE was always
inert, so expecting a loud failure there asserts pre-fidelity-fix
behavior. Assert both sides instead: inert (command succeeds) with the
standard config, loud failure against an empty config dir where the
legacy fallback actually applied.

* refactor(config): collapse parseOptOutBool to ParseBool over the string form

YAML hands us typed values (bool, int), so route them through
fmt.Sprintf %v and strconv.ParseBool instead of a per-type switch.
Identical behavior for every recognized value; numbers other than 0/1
now read as no opinion instead of cast.ToBool's nonzero-true, which no
real config relies on.
This commit is contained in:
Sahil Bansal
2026-07-22 15:19:19 +05:30
committed by GitHub
parent 3031665ac7
commit 94781d6bda
80 changed files with 669 additions and 3036 deletions
+80 -58
View File
@@ -91,9 +91,9 @@ jobs:
run: |
echo "Testing NPM single package installation..."
mkdir npm-test && cd npm-test
pmg --proxy-mode=false npm init -y
pmg --proxy-mode=false npm install express@5.2.1
pmg --proxy-mode=false npm install lodash@4.17.21
pmg npm init -y
pmg npm install express@5.2.1
pmg npm install lodash@4.17.21
# Verification: npm added packages present and manifest updated
test -d node_modules/express
@@ -103,7 +103,7 @@ jobs:
echo "Testing NPM manifest installation..."
rm -rf node_modules package-lock.json
pmg --proxy-mode=false npm install
pmg npm install
# Verification: npm lockfile and installed modules exist after manifest install
test -f package-lock.json
@@ -293,8 +293,8 @@ jobs:
# onFail:download, and the following `pnpm add` then crashes with
# "Cannot use 'in' operator to search for 'integrity' in undefined".
npm init -y
pmg --proxy-mode=false pnpm add express@5.2.1
pmg --proxy-mode=false pnpm add lodash@4.17.21
pmg pnpm add express@5.2.1
pmg pnpm add lodash@4.17.21
# Verification: pnpm packages installed and lockfile created
test -d node_modules/express
@@ -303,7 +303,7 @@ jobs:
echo "Testing PNPM manifest installation..."
rm -rf node_modules pnpm-lock.yaml
pmg --proxy-mode=false pnpm install
pmg pnpm install
# Verification: pnpm lockfile and modules exist after manifest install
test -f pnpm-lock.yaml
@@ -315,9 +315,9 @@ jobs:
run: |
echo "Testing Bun single package installation..."
mkdir bun-test && cd bun-test
pmg --proxy-mode=false bun init -y
pmg --proxy-mode=false bun add express@5.2.1
pmg --proxy-mode=false bun add lodash@4.17.21
pmg bun init -y
pmg bun add express@5.2.1
pmg bun add lodash@4.17.21
# Verification: bun packages installed and lockfile created
test -d node_modules/express
@@ -326,7 +326,7 @@ jobs:
echo "Testing Bun manifest installation..."
rm -rf node_modules bun.lock
pmg --proxy-mode=false bun install
pmg bun install
# Verification: bun lockfile and modules exist after manifest install
test -f bun.lock
@@ -335,7 +335,7 @@ jobs:
echo "Testing Bun frozen manifest installation with bun ci..."
rm -rf node_modules
pmg --proxy-mode=false bun ci
pmg bun ci
# Verification: bun lockfile and modules exist after frozen manifest install
test -f bun.lock
@@ -392,9 +392,9 @@ jobs:
yarn --version
YARN_TESTDIR=$(mktemp -d) && cd "$YARN_TESTDIR"
pmg --proxy-mode=false yarn init -y
pmg --proxy-mode=false yarn add express@5.2.1
pmg --proxy-mode=false yarn add lodash@4.17.21
pmg yarn init -y
pmg yarn add express@5.2.1
pmg yarn add lodash@4.17.21
# Verification: yarn packages installed and lockfile created
test -d node_modules/express
@@ -403,7 +403,7 @@ jobs:
echo "Testing Yarn manifest installation..."
rm -rf node_modules yarn.lock
pmg --proxy-mode=false yarn install
pmg yarn install
# Verification: yarn lockfile and modules exist after manifest install
test -f yarn.lock
@@ -417,19 +417,19 @@ jobs:
mkdir npx-test && cd npx-test
echo "Testing npx with a simple package..."
pmg --proxy-mode=false npx cowsay@1.6.0 "Hello from pmg npx" | tee npx-output.txt
pmg npx cowsay@1.6.0 "Hello from pmg npx" | tee npx-output.txt
# Verification: cowsay output contains our message
grep -q "Hello from pmg npx" npx-output.txt
echo "Testing npx with --package flag..."
pmg --proxy-mode=false npx --package cowsay@1.6.0 -- cowsay "Hello with package flag" | tee npx-pkg-output.txt
pmg npx --package cowsay@1.6.0 -- cowsay "Hello with package flag" | tee npx-pkg-output.txt
# Verification: package flag execution produces expected output
grep -q "Hello with package flag" npx-pkg-output.txt
echo "Testing npx dry-run mode..."
pmg --proxy-mode=false --dry-run npx cowsay@1.6.0 "This should not execute" | tee npx-dry-output.txt
pmg --dry-run npx cowsay@1.6.0 "This should not execute" | tee npx-dry-output.txt
# Verification: dry-run should NOT produce cowsay ASCII art (cow face ^__^ should not appear)
! grep -q '\^__\^' npx-dry-output.txt
@@ -442,19 +442,19 @@ jobs:
PNPX_TESTDIR=$(mktemp -d) && cd "$PNPX_TESTDIR"
echo "Testing pnpx with a simple package..."
pmg --proxy-mode=false pnpx cowsay@1.6.0 "Hello from pmg pnpx" | tee pnpx-output.txt
pmg pnpx cowsay@1.6.0 "Hello from pmg pnpx" | tee pnpx-output.txt
# Verification: cowsay output contains our message
grep -q "Hello from pmg pnpx" pnpx-output.txt
echo "Testing pnpx with --package flag..."
pmg --proxy-mode=false pnpx --package cowsay@1.6.0 -- cowsay "Hello with package flag" | tee pnpx-pkg-output.txt
pmg pnpx --package cowsay@1.6.0 -- cowsay "Hello with package flag" | tee pnpx-pkg-output.txt
# Verification: package flag execution produces expected output
grep -q "Hello with package flag" pnpx-pkg-output.txt
echo "Testing pnpx dry-run mode..."
pmg --proxy-mode=false --dry-run pnpx cowsay@1.6.0 "This should not execute" | tee pnpx-dry-output.txt
pmg --dry-run pnpx cowsay@1.6.0 "This should not execute" | tee pnpx-dry-output.txt
# Verification: dry-run should NOT produce cowsay ASCII art (cow face ^__^ should not appear)
! grep -q '\^__\^' pnpx-dry-output.txt
@@ -471,18 +471,18 @@ jobs:
# Verification: pinned version is resolved and executed via the proxy
grep -q "0.6.9" uvx-output.txt
echo "Testing uvx version pin via @ syntax (non-proxy)..."
pmg --proxy-mode=false uvx ruff@0.6.9 --version | tee uvx-pin-output.txt
echo "Testing uvx version pin via @ syntax..."
pmg uvx ruff@0.6.9 --version | tee uvx-pin-output.txt
grep -q "0.6.9" uvx-pin-output.txt
echo "Testing uvx with --from (command name differs from package)..."
pmg --proxy-mode=false uvx --from cowsay cowsay -t "Hello from pmg uvx" | tee uvx-from-output.txt
pmg uvx --from cowsay cowsay -t "Hello from pmg uvx" | tee uvx-from-output.txt
# Verification: cowsay output contains our message and cow art
grep -q "Hello from pmg uvx" uvx-from-output.txt
grep -q '\^__\^' uvx-from-output.txt
echo "Testing uvx dry-run mode..."
pmg --proxy-mode=false --dry-run uvx --from cowsay cowsay -t "This should not execute" | tee uvx-dry-output.txt
pmg --dry-run uvx --from cowsay cowsay -t "This should not execute" | tee uvx-dry-output.txt
# Verification: dry-run should NOT produce cowsay ASCII art (cow face ^__^)
! grep -q '\^__\^' uvx-dry-output.txt
@@ -493,9 +493,9 @@ jobs:
echo "Testing Pip single package installation..."
mkdir pip-test && cd pip-test
python -m venv venv && source venv/bin/activate
pmg --proxy-mode=false pip install requests==2.32.4
pmg --proxy-mode=false pip install numpy==2.3.5
pmg --proxy-mode=false pip freeze > requirements.txt
pmg pip install requests==2.32.4
pmg pip install numpy==2.3.5
pmg pip freeze > requirements.txt
# Verification: requirements.txt contains expected packages
test -s requirements.txt
@@ -503,8 +503,8 @@ jobs:
grep -E '^numpy==' requirements.txt
echo "Testing Pip manifest installation..."
pmg --proxy-mode=false pip uninstall -y requests numpy
pmg --proxy-mode=false pip install -r requirements.txt
pmg pip uninstall -y requests numpy
pmg pip install -r requirements.txt
# Verification: imported packages are available in the environment
python -c "import requests, numpy; print(requests.__version__); print(numpy.__version__)"
@@ -516,9 +516,9 @@ jobs:
echo "Testing Pip3 single package installation..."
mkdir pip3-test && cd pip3-test
python -m venv venv && source venv/bin/activate
pmg --proxy-mode=false pip3 install requests==2.32.4
pmg --proxy-mode=false pip3 install numpy==2.3.5
pmg --proxy-mode=false pip3 freeze > requirements.txt
pmg pip3 install requests==2.32.4
pmg pip3 install numpy==2.3.5
pmg pip3 freeze > requirements.txt
# Verification: requirements.txt contains expected packages
test -s requirements.txt
@@ -526,8 +526,8 @@ jobs:
grep -E '^numpy==' requirements.txt
echo "Testing Pip3 manifest installation..."
pmg --proxy-mode=false pip3 uninstall -y requests numpy
pmg --proxy-mode=false pip3 install -r requirements.txt
pmg pip3 uninstall -y requests numpy
pmg pip3 install -r requirements.txt
# Verification: imported packages are available in the environment
python -c "import requests, numpy; print(requests.__version__); print(numpy.__version__)"
@@ -538,9 +538,9 @@ jobs:
run: |
echo "Testing UV single package installation..."
mkdir uv-test && cd uv-test
pmg --proxy-mode=false uv init --no-readme
pmg --proxy-mode=false uv add requests==2.32.4
pmg --proxy-mode=false uv add numpy==2.3.5
pmg uv init --no-readme
pmg uv add requests==2.32.4
pmg uv add numpy==2.3.5
# Verification: pyproject.toml lists expected dependencies
test -f pyproject.toml
@@ -549,31 +549,31 @@ jobs:
echo "Testing UV manifest installation..."
rm -rf .venv uv.lock
pmg --proxy-mode=false uv sync
pmg uv sync
# Verification: uv lockfile and virtualenv created; packages present
test -d .venv
test -f uv.lock
pmg --proxy-mode=false uv pip show requests >/dev/null
pmg --proxy-mode=false uv pip show numpy >/dev/null
pmg uv pip show requests >/dev/null
pmg uv pip show numpy >/dev/null
echo "Testing UV pip commands..."
pmg --proxy-mode=false uv pip freeze > requirements.txt
pmg --proxy-mode=false uv pip install -r requirements.txt
pmg --proxy-mode=false uv pip sync requirements.txt
pmg uv pip freeze > requirements.txt
pmg uv pip install -r requirements.txt
pmg uv pip sync requirements.txt
# Verification: uv pip can show installed packages after requirements sync
pmg --proxy-mode=false uv pip show requests >/dev/null
pmg --proxy-mode=false uv pip show numpy >/dev/null
pmg uv pip show requests >/dev/null
pmg uv pip show numpy >/dev/null
cd .. && rm -rf uv-test
- name: Test Poetry - Single Package & Manifest
run: |
echo "Testing Poetry single package installation..."
mkdir poetry-test && cd poetry-test
pmg --proxy-mode=false poetry init --name poetry-test --no-interaction --quiet
pmg --proxy-mode=false poetry add requests==2.32.4
pmg --proxy-mode=false poetry add numpy==2.3.5
pmg poetry init --name poetry-test --no-interaction --quiet
pmg poetry add requests==2.32.4
pmg poetry add numpy==2.3.5
# Verification: pyproject.toml dependencies updated
test -f pyproject.toml
@@ -582,15 +582,19 @@ jobs:
echo "Testing Poetry manifest installation..."
rm -rf .venv poetry.lock
pmg --proxy-mode=false poetry install --no-root
pmg poetry install --no-root
cd .. && rm -rf poetry-test
- name: Test Malicious Package Detection
run: |
echo "Testing malicious package detection..."
mkdir malicious-test && cd malicious-test
pmg --proxy-mode=false npm init -y
! pmg --proxy-mode=false npm install nyc-config@10.0.0 || echo "Malicious package correctly blocked"
pmg npm init -y
if pmg npm install nyc-config@10.0.0; then
echo "ERROR: malicious package was not blocked!"
exit 1
fi
echo "Malicious package correctly blocked"
cd .. && rm -rf malicious-test
- name: Test safedep-test-pkg is Blocked using Proxy mode
@@ -620,29 +624,47 @@ jobs:
mkdir pmg-modes-test && cd pmg-modes-test
pmg npm init -y
# Mode: --dry-run should not create node_modules or lockfiles
pmg --proxy-mode=false --dry-run npm install express
pmg --dry-run npm install express
# Verification: no files created during dry-run
test ! -d node_modules
test ! -f package-lock.json
# Mode: --silent should install without noisy output
pmg --proxy-mode=false --silent npm install express
pmg --silent npm install express
# Verification: package installed
test -d node_modules/express
# Clean and test --verbose installation
rm -rf node_modules package-lock.json
pmg --proxy-mode=false --verbose npm install express
pmg --verbose npm install express
# Verification: package installed
test -d node_modules/express
# Clean and test --debug with log output
rm -rf node_modules package-lock.json
pmg --proxy-mode=false --debug --log debug.json npm install express
pmg --debug --log debug.json npm install express
# Verification: debug log written
test -f debug.json
# Mode: --paranoid may require cloud credentials; run non-blocking with dry-run
pmg --proxy-mode=false --paranoid --dry-run npm install express || true
pmg --paranoid --dry-run npm install express || true
# Removed proxy opt-outs must fail loudly, not silently proxy
if PMG_PROXY_ENABLED=false pmg --dry-run npm install express; then
echo "ERROR: PMG_PROXY_ENABLED=false should fail loudly"
exit 1
fi
# Legacy PMG_PROXY_MODE only selected guard mode when the config has
# no proxy: section; with the standard (template) config it was inert
# and must keep working.
PMG_PROXY_MODE=false pmg --dry-run npm install express
if PMG_CONFIG_DIR=$(mktemp -d) PMG_PROXY_MODE=false pmg --dry-run npm install express; then
echo "ERROR: PMG_PROXY_MODE=false without a proxy: section should fail loudly"
exit 1
fi
if pmg --proxy-mode=false --dry-run npm install express; then
echo "ERROR: --proxy-mode should be an unknown flag"
exit 1
fi
cd .. && rm -rf pmg-modes-test
sandbox-e2e-macos: