From eabf5ae9abfda724134f1810aef96702a7938576 Mon Sep 17 00:00:00 2001 From: danielmeppiel Date: Sat, 21 Nov 2026 20:27:04 +0100 Subject: [PATCH 1/3] fix(install): pass the install path to the approval check of an LSP-declaring package After `apm approve` pinned a package that declares both a hook and an LSP server, the next `apm install` failed with "'types.SimpleNamespace' object has no attribute 'install_path'". The trusted-LSP graph check (install/lsp/integration.py) asked check_executable_approval about the package with a stand-in carrying only its dependency_ref; pinned-hook admission (security/trust.py hooks_package_admissible) reads the package's hook files from install_path. The stand-in now carries the install path, so the approved hook and LSP server deploy. Approval decisions are unchanged. Regression: tests/lifecycle/security/test_gate_removal.py:: test_approved_package_with_hook_and_lsp_installs_both (fails before: exit 1 with the AttributeError; after: exit 0, hook and LSP deployed, lock row records the hook, repeat install is a byte no-op). Ledger row 4658. Fixes #4658 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 1 + src/apm_cli/install/lsp/integration.py | 7 ++- .../lifecycle_bug_ledger/bugs/4658.json | 14 +++++ tests/lifecycle/security/test_gate_removal.py | 57 +++++++++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/lifecycle_bug_ledger/bugs/4658.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d00256657d..59ce1f7c75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `apm unpack` into a project leaves `apm.lock.yaml` unchanged when it already records the unpacked files with the same content, so restores keep tracked files clean. (closes #4556, #4580) - The first `apm install` after a dependency moves from git to a registry removes its stale `.apm-pin`; repeat installs and `install --update` change no bytes. (closes #4572, #4597) - `apm uninstall` refuses before any change when a shared bundle's shrinking skill selection would delete an edited or unproven file. (closes #4313, #4588) +- `apm install` deploys an approved package that declares both hooks and LSP servers instead of failing with `'types.SimpleNamespace' object has no attribute 'install_path'`. (closes #4658, #PR) ### Security diff --git a/src/apm_cli/install/lsp/integration.py b/src/apm_cli/install/lsp/integration.py index 3a146297c3..712066d409 100644 --- a/src/apm_cli/install/lsp/integration.py +++ b/src/apm_cli/install/lsp/integration.py @@ -145,7 +145,8 @@ def _graph_declares_trusted_lsp(ctx: "InstallContext") -> bool: allow_map = closed_exec_map(None) allow_resolved = False for dep_ref in dependencies: - manifest = manifest_file(dep_ref.get_install_path(ctx.apm_modules_dir)) + install_path = dep_ref.get_install_path(ctx.apm_modules_dir) + manifest = manifest_file(install_path) try: declared = ( manifest.is_file() and APMPackage.from_apm_yml(manifest).get_lsp_dependencies() @@ -157,7 +158,9 @@ def _graph_declares_trusted_lsp(ctx: "InstallContext") -> bool: continue if not allow_resolved: allow_map, allow_resolved = effective_allow_map(ctx), True - package_info = SimpleNamespace(dependency_ref=dep_ref) + # Pinned-hook admission reads the package's files, so the approval owner + # needs its install path as well as its identity (#4658). + package_info = SimpleNamespace(dependency_ref=dep_ref, install_path=install_path) if check_executable_approval(dep_ref.get_unique_key(), package_info, allow_map)[4]: return True return False diff --git a/tests/fixtures/lifecycle_bug_ledger/bugs/4658.json b/tests/fixtures/lifecycle_bug_ledger/bugs/4658.json new file mode 100644 index 0000000000..b38c215289 --- /dev/null +++ b/tests/fixtures/lifecycle_bug_ledger/bugs/4658.json @@ -0,0 +1,14 @@ +{ + "issue": 4658, + "fixed_in": "Unreleased", + "summary": "After apm approve pinned a package that declares both a hook and an LSP server, the next apm install failed before writing anything; the trusted-LSP graph check now hands the approval owner the package's install path, so the approved hook and LSP server deploy.", + "failure_modes": [ + "outcome" + ], + "properties": [ + "outcome.status_matches_state" + ], + "regression_tests": [ + "tests/lifecycle/security/test_gate_removal.py::test_approved_package_with_hook_and_lsp_installs_both" + ] +} diff --git a/tests/lifecycle/security/test_gate_removal.py b/tests/lifecycle/security/test_gate_removal.py index 18ea08806a..1f152f68cd 100644 --- a/tests/lifecycle/security/test_gate_removal.py +++ b/tests/lifecycle/security/test_gate_removal.py @@ -63,10 +63,12 @@ from tests.lifecycle.security.gate_slices import GateRow, GateSlice, slices from tests.lifecycle.snapshot import LifecycleSurfaceRoots from tests.lifecycle.world import use_policy +from tests.lifecycle.world.packages import _SESSION_HOOK, INERT_COMMAND from tests.lifecycle.world.services import DENIED_PACKAGE, ORG, policy_org from tests.utils.apm_lifecycle_runner import ApmLifecycleRunner, CommandResult from tests.utils.artifact_snapshot import ArtifactSnapshotSet from tests.utils.lifecycle_state import LifecycleStateSnapshot +from tests.utils.local_package import LocalPackageFactory pytestmark = [ pytest.mark.integration, @@ -834,3 +836,58 @@ def test_user_scope_deny_by_identity_retires_hook_and_mcp(lifecycle_world) -> No assert result.returncode == 0, result.stdout + result.stderr assert not (world.home / _USER_HOOK).exists(), "deny -g by identity must retire the hook" assert _MCP_SERVER not in _user_mcp_servers(world), "deny -g must retire the MCP server" + + +# -- #4658: one approved package with a hook and an LSP server --------------------- +# The trusted-LSP graph check (install/lsp/integration.py) asked the approval owner +# about a package declaring LSP servers. Pinned-hook admission then read the package's +# install path from a stand-in that had none, so the install crashed after approval. + + +def _hook_and_lsp_package(world, name: str) -> Path: + factory = LocalPackageFactory(world.root / "hook-lsp-packages") + package = factory.create( + name, + version="1.0.0", + lsp_dependencies=[ + { + "name": f"{name}-server", + "command": INERT_COMMAND, + "args": ["--stdio"], + "extensionToLanguage": {".fixture": "fixture"}, + } + ], + ) + factory.add_hook(package, "session", _SESSION_HOOK) + return package.root + + +def test_approved_package_with_hook_and_lsp_installs_both(lifecycle_world) -> None: + """PROMISE P-INV-I7: after `apm approve`, `apm install` deploys the approved hook and + LSP server of one package (#4658), and repeats as a byte no-op (I2).""" + world = lifecycle_world + name = "p-hook-lsp" + root = _hook_and_lsp_package(world, name) + hook = world.project / ".github" / "hooks" / f"{name}-session.json" + lsp = world.project / ".github" / "lsp.json" + parked = driver.run(world, ("install", str(root))) + assert parked.returncode == 0, parked.stdout + parked.stderr + assert not hook.exists(), "an unapproved hook must park" + assert not lsp.is_file() or f'"{name}-server"' not in lsp.read_text(encoding="utf-8") + approved = driver.run(world, ("approve", str(root))) + assert approved.returncode == 0, approved.stdout + approved.stderr + installed = driver.run(world, ("install",)) + output = installed.stdout + installed.stderr + assert installed.returncode == 0, output + assert "Traceback" not in output and "has no attribute" not in output, output + assert hook.is_file(), f"the approved hook must deploy\n{output}" + assert f'"{name}-server"' in lsp.read_text(encoding="utf-8"), output + lock = LockFile.from_yaml((world.project / "apm.lock.yaml").read_text(encoding="utf-8")) + rows = [d for d in lock.get_package_dependencies() if name in (d.repo_url or "")] + assert len(rows) == 1, [d.repo_url for d in lock.get_package_dependencies()] + deployed = set(rows[0].deployed_files or ()) + assert f".github/hooks/{name}-session.json" in deployed, sorted(deployed) + before = {p: p.read_bytes() for p in (hook, lsp, world.project / "apm.lock.yaml")} + again = driver.run(world, ("install",)) + assert again.returncode == 0, again.stdout + again.stderr + assert {p: p.read_bytes() for p in before} == before, "a converged install changed bytes" From 1169425ca7d75a5a03cd91455d070684cedfffef Mon Sep 17 00:00:00 2001 From: danielmeppiel Date: Sat, 21 Nov 2026 20:27:39 +0100 Subject: [PATCH 2/3] docs(changelog): reference #4680 for the hooks + LSP approval fix Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ce1f7c75..52f593f48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `apm unpack` into a project leaves `apm.lock.yaml` unchanged when it already records the unpacked files with the same content, so restores keep tracked files clean. (closes #4556, #4580) - The first `apm install` after a dependency moves from git to a registry removes its stale `.apm-pin`; repeat installs and `install --update` change no bytes. (closes #4572, #4597) - `apm uninstall` refuses before any change when a shared bundle's shrinking skill selection would delete an edited or unproven file. (closes #4313, #4588) -- `apm install` deploys an approved package that declares both hooks and LSP servers instead of failing with `'types.SimpleNamespace' object has no attribute 'install_path'`. (closes #4658, #PR) +- `apm install` deploys an approved package that declares both hooks and LSP servers instead of failing with `'types.SimpleNamespace' object has no attribute 'install_path'`. (closes #4658, #4680) ### Security From 3332a80e6989da4905fc55c166a9d83f581c5102 Mon Sep 17 00:00:00 2001 From: danielmeppiel Date: Sat, 21 Nov 2026 20:46:53 +0100 Subject: [PATCH 3/3] docs(changelog): move the #4680 entry to a changelog.d fragment Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 1 - changelog.d/4680.fixed.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 changelog.d/4680.fixed.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 52f593f48e..d00256657d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `apm unpack` into a project leaves `apm.lock.yaml` unchanged when it already records the unpacked files with the same content, so restores keep tracked files clean. (closes #4556, #4580) - The first `apm install` after a dependency moves from git to a registry removes its stale `.apm-pin`; repeat installs and `install --update` change no bytes. (closes #4572, #4597) - `apm uninstall` refuses before any change when a shared bundle's shrinking skill selection would delete an edited or unproven file. (closes #4313, #4588) -- `apm install` deploys an approved package that declares both hooks and LSP servers instead of failing with `'types.SimpleNamespace' object has no attribute 'install_path'`. (closes #4658, #4680) ### Security diff --git a/changelog.d/4680.fixed.md b/changelog.d/4680.fixed.md new file mode 100644 index 0000000000..897b09e060 --- /dev/null +++ b/changelog.d/4680.fixed.md @@ -0,0 +1 @@ +- `apm install` deploys an approved package that declares both hooks and LSP servers instead of failing. (closes #4658, #4680)