-
Notifications
You must be signed in to change notification settings - Fork 286
fix(compile): run orphan cleanup on --clean when last primitive removed (closes #2130) #2134
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f42588
fix(compile): clean after last primitive removal
danielmeppiel cf8c807
Merge origin/main for CI parity
danielmeppiel 959127c
fix(compile): fold cleanup review findings
danielmeppiel d366a8c
fix(compile): align empty-output guards
danielmeppiel 077fd20
fix(compile): clarify clean-only completion
danielmeppiel 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
78 changes: 78 additions & 0 deletions
78
tests/unit/compilation/test_compile_clean_last_primitive_2130.py
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,78 @@ | ||
| """Regression test for orphan cleanup after the last primitive is removed.""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from click.testing import CliRunner | ||
|
|
||
| from apm_cli.cli import cli | ||
|
|
||
|
|
||
| def test_clean_removes_claude_md_after_last_primitive_is_removed( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """--clean reaches orphan removal when the project has no primitives left.""" | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "apm.yml").write_text( | ||
| "name: clean-last-primitive\nversion: 1.0.0\ntargets:\n - claude\n", | ||
| encoding="utf-8", | ||
| ) | ||
| instructions_dir = tmp_path / ".apm" / "instructions" | ||
| instructions_dir.mkdir(parents=True) | ||
| instruction = instructions_dir / "base.instructions.md" | ||
| instruction.write_text( | ||
| "---\ndescription: Test instruction\n---\nKeep responses concise.\n", | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| runner = CliRunner() | ||
| initial = runner.invoke(cli, ["compile", "--target", "claude"]) | ||
| assert initial.exit_code == 0, initial.output | ||
| claude_md = tmp_path / "CLAUDE.md" | ||
| assert claude_md.is_file() | ||
|
|
||
| instruction.unlink() | ||
| cleaned = runner.invoke(cli, ["compile", "--target", "claude", "--clean"]) | ||
|
|
||
| assert cleaned.exit_code == 0, cleaned.output | ||
| assert not claude_md.exists() | ||
| assert "no source primitives remain" in cleaned.output | ||
| assert "produced no output files" not in cleaned.output | ||
|
|
||
|
|
||
| def test_clean_validate_still_rejects_project_without_primitives( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """--validate keeps requiring project content when combined with --clean.""" | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "apm.yml").write_text( | ||
| "name: clean-validate-empty\nversion: 1.0.0\ntargets:\n - claude\n", | ||
| encoding="utf-8", | ||
| ) | ||
| (tmp_path / ".apm" / "instructions").mkdir(parents=True) | ||
|
|
||
| result = CliRunner().invoke(cli, ["compile", "--target", "claude", "--clean", "--validate"]) | ||
|
|
||
| assert result.exit_code == 1 | ||
| assert "No instruction files found in .apm/ directory" in result.output | ||
|
|
||
|
|
||
| def test_clean_preserves_hand_authored_claude_md_without_duplicate_guidance( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| """Empty-project cleanup preserves user content without irrelevant advice.""" | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "apm.yml").write_text( | ||
| "name: clean-hand-authored\nversion: 1.0.0\ntargets:\n - claude\n", | ||
| encoding="utf-8", | ||
| ) | ||
| (tmp_path / ".apm" / "instructions").mkdir(parents=True) | ||
| claude_md = tmp_path / "CLAUDE.md" | ||
| claude_md.write_text("# User-authored context\n", encoding="utf-8") | ||
|
|
||
| result = CliRunner().invoke(cli, ["compile", "--target", "claude", "--clean"]) | ||
|
|
||
| assert result.exit_code == 0, result.output | ||
| assert claude_md.read_text(encoding="utf-8") == "# User-authored context\n" | ||
| assert "hand-authored file will not be deleted" in result.output | ||
| assert "duplicate context" not in result.output | ||
Oops, something went wrong.
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.