Skip to content

fix: Instrumentation and templatespec#1

Merged
regularkevvv merged 4 commits into
mainfrom
fix/instrumentation-and-templatespec
Jan 19, 2026
Merged

fix: Instrumentation and templatespec#1
regularkevvv merged 4 commits into
mainfrom
fix/instrumentation-and-templatespec

Conversation

@regularkevvv

Copy link
Copy Markdown
Collaborator

Summary

  • Fix TemplateSpec.from_file() path stripping bug when using a pre-configured environment
  • Add comment-based markers ({#jt:anchor:name#}, {#jt:trace:name#}) as an alternative to function call syntax

Bug Fix: from_file Path Stripping

When TemplateSpec.from_file() was called with a pre-configured environment, the directory portion of the path was incorrectly stripped, causing template loading to fail for nested paths.

Before (broken):

env = Environment(loader=FileSystemLoader("prompts/"))
spec = TemplateSpec.from_file("resume_v2/sections/system.prompt", env=env)
# Error: TemplateNotFound: system.prompt
# Tried to load "prompts/system.prompt" instead of "prompts/resume_v2/sections/system.prompt"

After (fixed):

env = Environment(loader=FileSystemLoader("prompts/"))
spec = TemplateSpec.from_file("resume_v2/sections/system.prompt", env=env)
# Works correctly - loads "prompts/resume_v2/sections/system.prompt"

Changes

┌─────────────────────────────────────────┬───────────────────────────────────┬─────────────────────────────────┐
│                Scenario                 │              Before               │              After              │
├─────────────────────────────────────────┼───────────────────────────────────┼─────────────────────────────────┤
│ from_file("a/b/c.j2", env=my_env)       │ Loads "c.j2" (fails)              │ Loads "a/b/c.j2" (works)        │
├─────────────────────────────────────────┼───────────────────────────────────┼─────────────────────────────────┤
│ from_file("a/b/c.j2")                   │ Creates env at a/b/, loads "c.j2" │ Same (unchanged)                │
├─────────────────────────────────────────┼───────────────────────────────────┼─────────────────────────────────┤
│ from_file("c.j2", env=instrumented_env) │ Re-instruments env                │ Reuses existing instrumentation │
└─────────────────────────────────────────┴───────────────────────────────────┴─────────────────────────────────┘

New Feature: Comment-Based Markers

Added support for comment-based markers that allow jinjatest to be a dev-only dependency:

{#jt:anchor:system#}
System prompt content here.

{#jt:anchor:user#}
User: {{ user_input }}
{#jt:trace:user_rendered#}

These are automatically transformed to {{ jt.anchor("system") }} calls when test_mode=True.

Test Plan

  • Added 8 new tests for from_file with provided environment
  • Added tests for template_dir parameter behavior
  • Added tests for comment markers with provided env
  • All 487 tests passing

@regularkevvv regularkevvv merged commit acb3bac into main Jan 19, 2026
6 checks passed
@regularkevvv regularkevvv deleted the fix/instrumentation-and-templatespec branch January 19, 2026 14:50
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.

1 participant