From efd0dfe9cdefbbec2a3406892b74b687c26b99f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Cano=20Rodr=C3=ADguez?= Date: Thu, 22 Oct 2026 18:24:58 +0200 Subject: [PATCH] ci: run the template tests on GitHub Actions The template ships a pytest suite (pytest-copie) that was only run locally; two tests had drifted from the pin design and failed: - source-tag is seeded by the initial_source_tag answer (recorded), not derived from an ephemeral secret version question - the answers file records initial_source_tag Update those to the current design and add a workflow: ruff check + format on the repo and pytest on every PR touching template files and on pushes to main. Assisted-by: OpenRouter:z-ai/glm-5.3-flash pi --- .github/workflows/test.yaml | 28 ++++++++++++++++++++++++++++ tests/test_template.py | 32 +++++++++++++++++--------------- 2 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..e096545 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,28 @@ +name: Test template + +on: + pull_request: + paths: + - "copier.yaml" + - "template/**" + - "tests/**" + - "pyproject.toml" + push: + branches: [main] + +jobs: + test: + name: Test template + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7 + + - name: Install uv + uses: astral-sh/setup-uv@v7 + + - name: Run lint + run: uv run ruff check . && uv run ruff format --check . + + - name: Run tests + run: uv run pytest tests/ -v diff --git a/tests/test_template.py b/tests/test_template.py index 9ed53a4..39364d6 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -50,9 +50,8 @@ def test_answers_file_content(copie): # Computed values are not recorded. assert "snap_name" not in recorded assert "title" not in recorded - # The version changes on every release, so it is a secret question: - # prompted and rendered, but never persisted to the answers file. - assert "version" not in recorded + # The bootstrap pin is recorded (it seeds the source-tag pin). + assert recorded["initial_source_tag"] == "0.1.0" def test_snap_name_appends_suffix(copie): @@ -67,15 +66,16 @@ def test_title_is_derived(copie): assert "title: Advanced Masks (OBS plugin)" in snapcraft_yaml(result) -def test_version_defaults_to_placeholder(copie): - """The version question feeds the source-tag pin, not a static version.""" +def test_initial_source_tag_defaults_to_placeholder(copie): + """The initial_source_tag question feeds the source-tag pin.""" assert "source-tag: '0.1.0'" in snapcraft_yaml(make_project(copie)) -def test_source_tag_is_derived_from_version(copie): - """The source tag is not a question: it is derived from the version.""" - assert "source-tag: '0.1.0'" in snapcraft_yaml(make_project(copie)) - assert "source-tag: '0.4.8'" in snapcraft_yaml(make_project(copie, version="0.4.8")) +def test_initial_source_tag_is_recorded_and_rendered(copie): + """The bootstrap pin is recorded and rendered from the answer.""" + result = make_project(copie, initial_source_tag="0.4.8") + assert "source-tag: '0.4.8'" in snapcraft_yaml(result) + assert answers_file(result)["initial_source_tag"] == "0.4.8" def test_adopt_info_replaces_static_version(copie): @@ -86,14 +86,16 @@ def test_adopt_info_replaces_static_version(copie): assert 'craftctl set version="$(git describe' in content -def test_version_is_used_verbatim(copie): - """An explicit version is rendered as-is, without any sanitization.""" - assert "source-tag: '0.4.8'" in snapcraft_yaml(make_project(copie, version="0.4.8")) +def test_initial_source_tag_is_used_verbatim(copie): + """An explicit bootstrap pin is rendered as-is, without any sanitization.""" + result = make_project(copie, initial_source_tag="0.4.8") + assert "source-tag: '0.4.8'" in snapcraft_yaml(result) -def test_version_is_not_recorded_in_answers(copie): - """The version is a secret question: not persisted for future updates.""" - assert "version" not in answers_file(make_project(copie, version="0.4.8")) +def test_initial_source_tag_is_recorded_in_answers(copie): + """The bootstrap pin is persisted for future updates.""" + result = make_project(copie, initial_source_tag="0.4.8") + assert answers_file(result)["initial_source_tag"] == "0.4.8" def test_license_defaults_to_omitted(copie):