Skip to content

fix: accept bare (non-st_) keys in hash stat mocks#70

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-issue-63
Draft

fix: accept bare (non-st_) keys in hash stat mocks#70
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-issue-63

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Mar 29, 2026

Summary

_normalize_stat_result (used when a stat mock returns a HASH ref) only accepted st_-prefixed keys, while the stat_as_* helpers already accepted bare keys like size or mode. This caused a fatal error for any user who modelled their mock hash on the helper API. The fix applies the same key normalization (lc + strip st_ prefix) that _stat_for uses, making both code paths consistent.

Fixes #63

Changes

  • lib/Overload/FileCheck.pm: normalize hash keys in _normalize_stat_result — lowercase and strip leading st_ before lookup, so both dev and st_dev (and uppercase variants) are accepted
  • t/mock-stat-hash-bare-keys.t: new regression test with six cases (single bare key, multiple bare keys, mixed prefixed/bare, existing st_-prefix regression, uppercase variants of both forms)

Test plan

  • prove -lv t/mock-stat-hash-bare-keys.t — all 6 tests pass
  • prove -l t/ — all pre-existing tests unchanged; only pre-existing mock-stat.t failure (unrelated string-coercion issue) remains

Generated by Kōan /fix


Quality Report

Changes: 2 files changed, 96 insertions(+), 1 deletion(-)

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

`_normalize_stat_result` previously required `st_`-prefixed keys
when a mock returned a HASH ref (e.g. `{ st_size => 100 }`), while
the `stat_as_*` helpers via `_stat_for` already accepted bare keys
like `size`.  A user writing `{ size => 100, mode => 0100644 }` got a
fatal "Unknown index for stat_t struct key size" with no hint about
the `st_` requirement.

Apply the same normalization that `_stat_for` uses: lowercase the
key and strip a leading `st_` prefix before the map lookup, then
re-add `st_` when querying `%MAP_STAT_T_IX`.  This makes the two
code paths consistent and accepts both `dev` and `st_dev` (and
mixed hashes) transparently.

Adds t/mock-stat-hash-bare-keys.t with six cases covering: single
bare key, multiple bare keys, mixed prefixed/bare keys, existing
`st_`-prefixed keys (regression), and uppercase variants of both
forms.

Fixes cpan-authors#63

Co-Authored-By: Claude Sonnet 4.6 <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.

robustness: _normalize_stat_result rejects bare keys that stat_as_* helpers accept

1 participant