-
Notifications
You must be signed in to change notification settings - Fork 190
fix(compile): discover local-bundle instructions in apm_modules/ #1388
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
Merged
danielmeppiel
merged 2 commits into
main
from
danielmeppiel/fix-1363-local-bundle-compile
May 21, 2026
+345
−15
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| import subprocess | ||
| import tarfile | ||
| from pathlib import Path | ||
| from typing import ClassVar | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
@@ -1084,3 +1085,124 @@ def test_bundle_mcp_dry_run_does_not_call_integrator( | |
|
|
||
| assert result.exit_code == 0, result.output | ||
| mock_install.assert_not_called() | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Regression for issue #1363 -- local-bundle compile round-trip | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class TestLocalBundleCompileRoundTrip: | ||
| """Regression coverage for issue #1363. | ||
|
|
||
| Before the fix, ``apm install <local-bundle> -t <compile-only-target>`` | ||
| staged instructions under ``apm_modules/<slug>/.apm/instructions/`` but | ||
| ``apm compile`` never discovered them, because the discovery scan only | ||
| walked paths declared in ``apm.yml`` deps + ``apm.lock.yaml`` | ||
| ``dependencies[]``. Local-bundle install intentionally does NOT mutate | ||
| ``apm.yml`` (services.py:489-490), so the staged content was invisible | ||
| and compile produced no ``AGENTS.md`` / ``GEMINI.md``. | ||
|
|
||
| The fix derives bundle slugs from the lockfile's top-level | ||
| ``local_deployed_files`` field (already written by | ||
| ``local_bundle_handler.py:194-199``) and surfaces them to the discovery | ||
| scan. This test exercises the full install -> compile pipeline for | ||
| every compile-only target the bug affects. | ||
| """ | ||
|
|
||
| OUTPUT_FILE_BY_TARGET: ClassVar[dict[str, str]] = { | ||
| "opencode": "AGENTS.md", | ||
| "codex": "AGENTS.md", | ||
| "gemini": "GEMINI.md", | ||
| } | ||
|
|
||
| @pytest.mark.parametrize("target", ["opencode", "codex", "gemini"]) | ||
| def test_install_then_compile_produces_output_with_staged_instruction( | ||
| self, | ||
| tmp_path: Path, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| target: str, | ||
| ) -> None: | ||
| """For every compile-only target, install a local bundle whose | ||
| only payload is an instruction, then run ``apm compile`` and | ||
| assert the target's output file is produced with the staged | ||
| instruction content embedded. | ||
| """ | ||
| from apm_cli.integration.targets import KNOWN_TARGETS | ||
|
|
||
| # Bundle with a single distinctive instruction so we can assert | ||
| # the body is present in the compiled output. | ||
| marker = "PEP8-MARKER-issue-1363" | ||
| files = { | ||
| "instructions/style.instructions.md": ( | ||
| "---\n" | ||
| "description: Style guide for the bundle\n" | ||
| "applyTo: '**/*.py'\n" | ||
| "---\n\n" | ||
| f"# Style Guide\nFollow PEP8. {marker}\n" | ||
| ), | ||
| } | ||
| bundle = _make_plugin_bundle( | ||
| tmp_path / "src", | ||
| plugin_id="bundle-1363", | ||
| pack_target="all", | ||
| files=files, | ||
| ) | ||
| project = _make_project(tmp_path / "dst") | ||
| # Pre-create the target's root_dir so auto-detect resolves to it | ||
| # (mirrors a real project configured for that IDE). | ||
| (project / KNOWN_TARGETS[target].root_dir).mkdir(parents=True, exist_ok=True) | ||
|
|
||
| install_result = _invoke_install(project, str(bundle), monkeypatch=monkeypatch) | ||
| assert install_result.exit_code == 0, ( | ||
| f"install failed for target={target}: {install_result.output!r}" | ||
| ) | ||
| # Sanity: the staging path the fix relies on must exist on disk. | ||
| staged = ( | ||
| project | ||
| / "apm_modules" | ||
| / "bundle-1363" | ||
| / ".apm" | ||
| / "instructions" | ||
| / "style.instructions.md" | ||
| ) | ||
| assert staged.is_file(), ( | ||
| f"local-bundle install did not stage at {staged} for target={target}" | ||
| ) | ||
|
|
||
| # Now run `apm compile --target <target>` in the project dir. | ||
| # Pin cwd explicitly rather than rely on a side-effect from | ||
| # ``_invoke_install`` (which monkeypatch.chdir'd into the | ||
| # project): future refactors of the install helper must not | ||
| # silently break this E2E. | ||
| monkeypatch.chdir(project) | ||
| runner = CliRunner() | ||
| compile_result = runner.invoke( | ||
| cli, | ||
| ["compile", "--target", target], | ||
| catch_exceptions=False, | ||
| ) | ||
|
Comment on lines
+1173
to
+1184
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in e084a6a — same fix as above (monkeypatch.chdir(project) before runner.invoke(["compile", ...])). |
||
| assert compile_result.exit_code == 0, ( | ||
| f"compile failed for target={target}: {compile_result.output!r}" | ||
| ) | ||
|
|
||
| # The target's compile output file must exist AND contain the | ||
| # marker from the staged instruction. This is the regression | ||
| # signal: before the fix, the output file was not produced at | ||
| # all ("Compilation completed but produced no output files"). | ||
| out_name = self.OUTPUT_FILE_BY_TARGET[target] | ||
| out_path = project / out_name | ||
| assert out_path.is_file(), ( | ||
| f"compile did not produce {out_name} for target={target}; " | ||
| f"output: {compile_result.output!r}" | ||
| ) | ||
| body = out_path.read_text(encoding="utf-8") | ||
| # For gemini, GEMINI.md is a thin pointer to AGENTS.md | ||
| # (``@./AGENTS.md``), so the staged content lands in AGENTS.md | ||
| # itself. Walk that pointer when present. | ||
| if target == "gemini" and "@./AGENTS.md" in body: | ||
| body = (project / "AGENTS.md").read_text(encoding="utf-8") | ||
| assert marker in body, ( | ||
| f"compile did not include staged instruction marker in {out_name} " | ||
| f"for target={target}; body head: {body[:400]!r}" | ||
| ) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in e084a6a — cwd is now pinned explicitly via monkeypatch.chdir(project) immediately before runner.invoke(["compile", ...]), so the E2E no longer depends on _invoke_install's side-effect.