Skip to content

fix: Assert plugin always throws on defined values (GH #300)#338

Draft
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/fix-assert-plugin
Draft

fix: Assert plugin always throws on defined values (GH #300)#338
Koan-Bot wants to merge 1 commit intoabw:masterfrom
atoomic:koan.atoomic/fix-assert-plugin

Conversation

@Koan-Bot
Copy link
Contributor

Summary

Fixes the Template::Plugin::Assert vmethod which always threw "undefined value" errors even when the asserted value was defined.

Root cause: Template::Monad::Assert::AUTOLOAD passed $stash instead of $this to dotop(), causing lookups to search the root stash rather than the hash/list being asserted on.

# Before (broken):
my $value = $stash->dotop($stash, $item, \@args);

# After (fixed):
my $value = $stash->dotop($this, $item, \@args);

Example: [% foo.assert.bar %] where foo = { bar => 999 } would incorrectly throw because it looked for bar in the stash root instead of in foo.

Changes

  • lib/Template/Plugin/Assert.pm: One-character fix in Template::Monad::Assert::AUTOLOAD
  • t/assert.t: 6 new tests covering defined-value pass-through:
    • Hash value access (hash.assert.foo)
    • Nested hash access (nested.assert.name, nested.assert.deep.value)
    • Array vmethod (items.assert.size, items.assert.first)
    • Direct stash variable (assert.name)

Test plan

  • All 6 new assert tests pass
  • Full test suite: 2973 tests, all pass

Fixes #300


🤖 Generated by Kōan

Template::Monad::Assert::AUTOLOAD was passing $stash instead of $this
to dotop(), causing it to look up the item in the root stash rather
than in the actual hash/list being asserted on.

For example, [% foo.assert.bar %] would look for 'bar' in the stash
root (where it doesn't exist) instead of in foo, always throwing
"undefined value for bar" even when foo.bar is defined.

Added 6 tests covering defined-value pass-through for hashes, nested
hashes, arrays, and direct stash variable access.

Fixes abw#300

Co-Authored-By: Kōan <noreply@anthropic.com>
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.

Assert always throws

1 participant