Skip to content

Add Jinja2 template validation test and pre-commit hook#45

Merged
ret2libc merged 2 commits intomainfrom
fix-template-again
Feb 24, 2026
Merged

Add Jinja2 template validation test and pre-commit hook#45
ret2libc merged 2 commits intomainfrom
fix-template-again

Conversation

@ret2libc
Copy link
Collaborator

Summary

  • Add unit tests that parse and render the default cloud-init template, catching syntax and variable errors before runtime
  • Add a jinja2-check pre-commit hook that validates all templates in dropkit/templates/ on change
  • Remove escaped Jinja2 chars from template comment that were themselves causing parse issues

Test plan

  • uv run pytest tests/test_cloudinit.py -v — all 3 tests pass
  • prek run --all-files — all hooks pass including new jinja2-check
  • Temporarily break the template (e.g. add {% if %}) and verify both the test and hook catch it

🤖 Generated with Claude Code

ret2libc and others added 2 commits February 24, 2026 11:32
Catch template syntax errors early with a unit test that parses and
renders the default cloud-init template, and a pre-commit hook that
validates all templates in dropkit/templates/ on change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ret2libc ret2libc requested a review from DarkaMaul February 24, 2026 10:41
Copy link
Collaborator

@DarkaMaul DarkaMaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Sorry for the spurious comment before!
Much better this way

@ret2libc ret2libc merged commit 0efeea5 into main Feb 24, 2026
7 checks passed
@ret2libc ret2libc deleted the fix-template-again branch February 24, 2026 13:23
hooks:
- id: jinja2-check
name: jinja2 template syntax
entry: uv run python -c "import sys; from jinja2 import Template; [Template(open(f).read()) for f in sys.argv[1:]]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entry: uv run python -c "import sys; from jinja2 import Template; [Template(open(f).read()) for f in sys.argv[1:]]"
entry: uv run --with jinja2 python -c "import sys; from jinja2 import Template; [Template(open(f).read()) for f in sys.argv[1:]]"

Maybe that's more resilient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants