Skip to content

Add template render tester#24

Merged
ethanholz merged 2 commits intoomsf:mainfrom
dwhswenson:add-template-render-tester
Feb 25, 2026
Merged

Add template render tester#24
ethanholz merged 2 commits intoomsf:mainfrom
dwhswenson:add-template-render-tester

Conversation

@dwhswenson
Copy link
Copy Markdown
Member

This adds:

  • FileTemplateProvider, which serves as another way to load templates (previously env vars were the only way implemented). Expect other options in the future: load from an S3 bucket, URL, etc.
  • render.py, which serves as a simple tool / manual test for rendering templates. The idea is that (after added a main guard that calls the lambda), you can do python my_lambda.py | python -m lambdacron.render -t template.txt -r RESULT_TYPE and see the rendered result.

This adds:

* `FileTemplateProvider`, which serves as another way to load templates
  (previously env vars were the only way implemented). Expect other
  options in the future: load from an S3 bucket, URL, etc.
* `render.py`, which serves as a simple tool / manual test for rendering
  templates. The idea is that (after added a main guard that calls the
  lambda), you can do `python my_lambda.py | python -m lambdacron.render
  -t template.txt -r RESULT_TYPE` and see the rendered result.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a file-based template provider and a small CLI-style renderer to manually render notification templates using LambdaCron task output payloads, with accompanying tests.

Changes:

  • Added FileTemplateProvider to load Jinja2 templates from disk.
  • Introduced lambdacron.render as a CLI/module entrypoint to render templates from task-output JSON (file or stdin).
  • Added pytest coverage for the new renderer behavior and the file-based provider.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/lambdacron/notifications/base.py Adds FileTemplateProvider to read template strings from a Path.
src/lambdacron/notifications/__init__.py Re-exports FileTemplateProvider for public API usage.
src/lambdacron/render.py New CLI/module to render templates from task output JSON via existing notification rendering logic.
tests/test_render.py New tests validating CLI parsing, stdin support, strict undefined behavior, and payload extraction.
tests/notifications/test_base.py Adds tests for FileTemplateProvider.
.gitignore Ignores additional Python packaging artifacts (*.egg, .eggs/, *.egg-info/).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +12
import argparse
import json
import sys
from pathlib import Path
from typing import Any, Mapping, TextIO

from jinja2 import TemplateError

from lambdacron.notifications.base import (
FileTemplateProvider,
RenderedTemplateNotificationHandler,
)
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This module is intended to be run as python -m lambdacron.render, but src/lambdacron/ is an implicit namespace package (no __init__.py). With the current pyproject.toml using tool.setuptools.packages.find, top-level modules under lambdacron/ (like render.py) may not be included in built distributions unless namespace packages are explicitly enabled or a package lambdacron is created. Please ensure the packaging config includes this module in wheels/sdists (e.g., enable namespace package discovery or add src/lambdacron/__init__.py).

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +79
def render_payload(self, *, payload_json: str, result_type: str) -> None:
event = {
"Records": [
{
"body": payload_json,
"eventSource": "aws:sqs",
"messageAttributes": {
"result_type": {
"DataType": "String",
"StringValue": result_type,
}
},
}
]
}
self.lambda_handler(event=event, context=None)

Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

render_payload() builds a synthetic SQS record without messageId. In RenderedTemplateNotificationHandler.lambda_handler, exceptions are only converted into batchItemFailures when messageId is present; otherwise they are re-raised. This makes the CLI tool’s success/failure behavior depend on an artificial omission and diverge from real SQS events. Consider adding a dummy messageId and then checking the returned batchItemFailures (treat any failures as a non-zero exit), or bypass lambda_handler and call the parsing/rendering path in a way that deterministically raises on render failures.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@ethanholz ethanholz left a comment

Choose a reason for hiding this comment

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

I like the design but would make sure to include details cautioning the use of untrusted templates and that templates should be vetted before use. Want to get ahead of security issues with arbitrary template usage.

@ethanholz ethanholz merged commit 7447135 into omsf:main Feb 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants