← Back to issue list

fix(models): allow project variables in app commands

View original Github issue

Metadata

Project
snapcraft
Number
#6464
Type
pull request
State
open
Author
Mohil-Ahuja
Labels
—
Created
Updated
Closed
—

Current evaluation

Allows well-formed ${SNAPCRAFT_*}/${CRAFT_*} project-variable references in app command fields by stripping them before snapd character validation; adds unit tests. Awaiting maintainer re-review after feedback.

Suggested action: needs review

Reason: The author's latest comment says the pattern now only matches ${SNAPCRAFT_*} and ${CRAFT_*}, with malformed cases added as tests, indicating prior feedback from @mr-cal was addressed. CI shows only the Canonical CLA check passing and no failing checks, but one unresolved review comment remains and full lint/test boxes are unchecked, so it is ready for maintainer re-review rather than immediate merge.

Evaluated by: mr-cal-bot

Impact: 55 Quick Win: 25 Complexity: 30 Confidence: 75 Actionability: 65

Issue body

Project variables with curly braces are rejected in app commands: ```yaml apps: my-app: command: bin/${SNAPCRAFT_PROJECT_NAME} ``` ``` App commands must consist of only alphanumeric characters, spaces, and the following characters: / . _ # : $ - ``` This is a regression from #5183, which widened the `bus_name` validator to also cover `command`, `stop_command`, `post_stop_command` and `reload_command`. The character class it uses is taken from snapd's `appContentWhitelist`, and that class is right for snapd — but snapd only ever sees these fields *after* Snapcraft has expanded them, so `{` and `}` never reach it. The model validates while the reference is still literal, so the braces are rejected. Fixes #5500 ## Approach Well-formed `${VAR}` references are removed before snapd's character class is applied. Simply adding `{` and `}` to the class would also fix the reported case, but it would let genuinely malformed values through to snapd, which rejects them later with a less helpful error. Stripping only the variable references keeps the original guard intact: `bin/mkbird{5}`, `bin/${}` and `bin/${SNAPCRAFT PROJECT NAME}` are all still rejected here. `command-chain` has a similar validator, but it predates #5183 and isn't part of this regression, so I've left it alone — happy to include it if you'd prefer. ## Tests - `test_app_command_lexicon_project_variable` covers all five validated fields against a braced reference, a leading reference, two references in one value, and the brace-less `$VAR` form. - `test_app_command_lexicon_bad` gains the three malformed-brace cases above, so the narrowing can't silently regress into "braces are always fine". I didn't add a release-note entry since there's no unreleased notes file on `main` — glad to add one wherever you'd like it. --- - [x] I've followed the [contribution guidelines](https://github.com/canonical/snapcraft/blob/main/CONTRIBUTING.md). - [x] I've signed the [CLA](http://www.ubuntu.com/legal/contributors/). - [ ] I've successfully run `make lint && make test`. - [ ] I've added or updated any relevant documentation. - [ ] In documents I changed, I [added a meta description](https://canonical-starflow.readthedocs-hosted.com/how-to/add-a-page-meta-description/) if one was missing. - [ ] I've updated the relevant release notes. On the unchecked boxes, to be precise about what I did run: `ruff check` and `ruff format` are clean on both files, and `tests/unit/models/test_projects.py` passes. I haven't completed a full `make lint && make test` locally — `make setup` doesn't finish on my machine because it installs `shfmt` via snap. No documentation changes seemed warranted for a validator fix, so the last three boxes are untouched rather than skipped; say the word if you'd like any of them addressed.

Evaluation history

Date Model Scores Action Summary
~deepseek/deepseek-pro-latest
Impact: 55
Quick Win: 25
Complexity: 30
Confidence: 75
Actionability: 65
needs review Allows well-formed ${SNAPCRAFT_*}/${CRAFT_*} project-variable references in app command fields by stripping them before snapd character validation; adds unit tests. Awaiting maintainer re-review after feedback.
~deepseek/deepseek-pro-latest
Impact: 58
Quick Win: 22
Complexity: 45
Confidence: 72
Actionability: 68
needs review Allows well-formed ${VAR} project-variable references in app command fields by stripping them before snapd character validation; adds unit tests for valid and malformed braces. Awaiting maintainer review.
stealth/space-bunny-alpha
Impact: 50
Quick Win: 24
Complexity: 32
Confidence: 89
Actionability: 72
needs review Strips well-formed ${VAR} references before validating four lifecycle commands and bus_name, restoring braced project-variable support while rejecting malformed references; ready for review.

Update history

Date Change
updated
updated
created

Related work

  • Caused By: snapcraft#5500 (confidence 95%)

    PR explicitly fixes #5500, the open regression report for braced project variables in app commands.

  • Related To: snapcraft#5183 (confidence 90%)

    PR body identifies #5183 as the merge that introduced the regression by widening the bus_name validator to command fields.

Related issues

Issue Project State Summary Similarity
#5500 Handle project variables with curly braces in app commands snapcraft open Triaged regression: since Snapcraft 8.5.1 (merged via #5183), app commands containing braced project variables like ${SNAPCRAFT_PROJECT_NAME} fail validation. Root cause identified; volunteer ready to PR a fix.
78%
#5499 fix: evaluate variables in project file snapcraft merged Merged in canonical/snapcraft#5499 (commit abd5db829), restoring project-variable expansion and fixing #5491 in Snapcraft 8.9.2.
72%
#5727 docs: document custom project vars (SNAPCRAFT-1053) snapcraft merged Merged in canonical/snapcraft#5727 as cba259a0d, documenting custom project variables for SNAPCRAFT-1053 after the work moved from canonical/craft-parts#1216.
72%