Fix missing build metadata in reactive charm artifacts
Metadata
Current evaluation
No evaluation has been recorded for this issue yet.
Issue body
This PR addresses missing valuable build metadata in charm artifacts built with charmcraft's reactive plugin.
## Description
When a reactive charm is built with `charm build .` directly, the resulting artifact includes a `.build.manifest` file with commit hashes for each charm layer and installed pip packages from the wheelhouse. Additionally, the manifest should include the charm-tools version used for the build. This PR ensures both features are preserved when building reactive charms through charmcraft.
## Changes Made
1. **`.build.manifest` file preservation**:
- Added logic in the reactive plugin to copy `.build.manifest` from the current working directory to the install directory after charm build completes
- The file now appears in the final charm artifact, preserving valuable build metadata
2. **`charmtool-version` in `manifest.yaml`**:
- Added `charmtool_version` field to the Manifest model
- Implemented `_get_charmtool_version()` method in PackageService that detects reactive plugin usage and extracts version info by running `charm version --format json`
- The manifest.yaml now includes charm-tools version information when building reactive charms
3. **Code quality improvements**:
- Separated exception handling for better debugging and error messages
- Fixed trailing whitespace
- Fixed ruff formatting issues
- Added comprehensive test coverage
4. **Spread test enhancement**:
- Modified the reactive spread test to verify that `.build.manifest` file is present in the resulting charm artifact
- Added unzip package installation to the test preparation phase
## Testing
- ✅ All existing tests pass (37 tests)
- ✅ Added new unit test `test_build_copies_build_manifest` to verify `.build.manifest` preservation
- ✅ Modified reactive spread test to verify `.build.manifest` in charm artifact using `unzip -l` and `MATCH` assertion
- ✅ Linting passes with ruff and prettier
- ✅ Security scanning completed with no vulnerabilities found
- ✅ Code review feedback addressed
---
- [x] I've followed the [contribution guidelines](https://github.com/canonical/charmcraft/blob/main/CONTRIBUTING.md).
- [ ] I've signed the [CLA](http://www.ubuntu.com/legal/contributors/).
- [x] I've successfully run `make lint && make test`.
- [ ] I've added or updated any relevant documentation.
- [ ] I've updated the relevant release notes.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>charm artifacts from reactive plugin are missing valuable build metadata</issue_title>
> <issue_description>when a reactive charm is built with `charm build .` the resulting artifact has a file in the top level with the title `.build.manifest`
>
> This file is generated by the `charm` snap and lists the commit hash for each charm layer, installed pip from the wheelhouse
>
> 1) It seems when i build a reactive charm using the charmcraft reactive plugin, this file is missing from the `.charm` artifact.
>
> 2) it would also be REALLY nice if the `manifest.yaml` generated would also list the `charmtool-version` used to build the charm.
> the plugin can determine this version by running `/snap/bin/charm version --format json` and extracting the output</issue_description>
>
> <agent_instructions>1. Write a test for this that fails when run from the 4.0.1 tag.
> 2. Check whether it succeeds on the `hotfix/3.5` branch.
> 3. Check whether it succeeds on the `hotfix/2.7` branch.
> 4. Check whether it succeeds on the main branch.
>
> If the test fails on `hotfix/3.5`, target your fix PR at that branch. If it succeeds on both `hotfix/3.5` and `main` but fails on `hotfix/2.7`, write a fix for that branch.
>
> If it fails on the 4.0.1 tag but succeeds everywhere else, write a comment that this will be resolved in version 4.1.0 and close the issue. Otherwise, write a fix.</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes canonical/charmcraft#872
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for you](https://github.com/canonical/charmcraft/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
Evaluation history
No evaluation history available.