Repository navigation
fix(install): preserve refused skill files when deployment receipts are missing #3440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tyce Herrman (TyceHerrman)
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
TyceHerrman:fix/preserve-skills-without-receipts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e5af56
fix(install): preserve refused skill files when deployment receipts a…
TyceHerrman a474915
fix: preserve missing-receipt skills on secondary targets
TyceHerrman 9c2a649
test: use canonical CLI and secondary target ordering
TyceHerrman 0cfe764
test: expect refusal before historical claim cleanup
TyceHerrman a92a7c6
chore: remove duplicate safety comments to meet module limit
TyceHerrman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """Run the source CLI in a disposable home; never touch live APM state.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
| import shutil | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.apm_lifecycle_runner import ApmLifecycleRunner | ||
| from tests.utils.isolated_apm_environment import IsolatedApmEnvironment | ||
|
|
||
| pytestmark = [pytest.mark.integration] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("user_scope", [False, True]) | ||
| @pytest.mark.parametrize("edited", [False, True]) | ||
| @pytest.mark.parametrize("package_kind", ["apm_package", "claude_skill", "skill_bundle"]) | ||
| @pytest.mark.parametrize("secondary_only", [False, True]) | ||
| def test_missing_receipt_cannot_turn_refused_writes_into_stale_deletions( | ||
| tmp_path: Path, | ||
| apm_engine_command, | ||
| user_scope: bool, | ||
| edited: bool, | ||
| package_kind: str, | ||
| secondary_only: bool, | ||
| ): | ||
| isolated = IsolatedApmEnvironment.create(tmp_path / "environment", base_env=dict(os.environ)) | ||
| env = isolated.subprocess_env() | ||
| project = isolated.work_root / "consumer" | ||
| project.mkdir(parents=True) | ||
| root = isolated.config_root if user_scope else project | ||
| root.mkdir(parents=True, exist_ok=True) | ||
| package = isolated.work_root / "package" | ||
| source = ( | ||
| package | ||
| / {"apm_package": ".apm/skills/demo", "claude_skill": "", "skill_bundle": "skills/demo"}[ | ||
| package_kind | ||
| ] | ||
| ) | ||
| source.mkdir(parents=True) | ||
| if package_kind != "claude_skill": | ||
| (package / "apm.yml").write_text("name: demo-pkg\nversion: 1.0.0\n") | ||
| (source / "SKILL.md").write_text("---\nname: demo\ndescription: Receipt fixture\n---\nv1\n") | ||
| (source / "a.md").write_text("v1\n") | ||
| (source / "b.md").write_text("v1\n") | ||
| targets = "agent-skills,claude" if secondary_only else "agent-skills" | ||
| target_manifest = "\n".join(f"- {target}" for target in targets.split(",")) | ||
| (root / "apm.yml").write_text( | ||
| f"name: consumer\nversion: 1.0.0\ndependencies:\n apm:\n - path: {package}\ntargets:\n{target_manifest}\n" | ||
| ) | ||
| runner = ApmLifecycleRunner(apm_engine_command) | ||
| args = ("install", *(("-g",) if user_scope else ()), "--target", targets, "--no-policy") | ||
| first = runner.run(args, cwd=project, env=env) | ||
| assert first.returncode == 0, first.stdout + first.stderr | ||
| deploy_root = isolated.home if user_scope else project | ||
| secondary_root = ".claude/skills" if secondary_only else ".agents/skills" | ||
| deployed_skills = list((deploy_root / secondary_root).glob("*/SKILL.md")) | ||
| assert len(deployed_skills) == 1 | ||
| deployed = deployed_skills[0].parent | ||
| if secondary_only: | ||
| # Only the secondary target retains old-lock files. The primary can | ||
| # install successfully, so its diagnostics cannot mask a lost error. | ||
| primary = deploy_root / ".agents/skills" | ||
| assert len(list(primary.glob("*/SKILL.md"))) == 1 | ||
| shutil.rmtree(primary) | ||
| if edited: | ||
| (deployed / "SKILL.md").write_text("my local edits\n") | ||
| before = {p.name: p.read_bytes() for p in deployed.iterdir()} | ||
| lock_before = (root / "apm.lock.yaml").read_bytes() | ||
| receipts = list((isolated.home / ".apm").glob("deployment-receipts*/*.json")) | ||
| assert len(receipts) == 1 | ||
| assert json.loads(receipts[0].read_text())["version"] in (1, 2) | ||
| receipts[0].unlink() | ||
| if package_kind != "claude_skill": | ||
| (package / "apm.yml").write_text("name: demo-pkg\nversion: 1.1.0\n") | ||
| (source / "a.md").write_text("v2\n") | ||
| (source / "b.md").unlink() | ||
| (source / "c.md").write_text("v2\n") | ||
| for _ in range(2): | ||
| result = runner.run(args, cwd=project, env=env) | ||
| assert result.returncode != 0, result.stdout + result.stderr | ||
| assert "no trustworthy local deployment baseline" in " ".join( | ||
| (result.stdout + result.stderr).split() | ||
| ) | ||
| assert "stale files cleaned" not in result.stdout | ||
| for name, content in before.items(): | ||
| assert (deployed / name).read_bytes() == content | ||
| assert (root / "apm.lock.yaml").read_bytes() == lock_before |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.