fix: use stat (not lstat) for -p/-S/-b/-c in mock_all_from_stat#92
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
Conversation
In Perl, only -l uses lstat. All other file test operators follow symlinks via stat. The $can_use_stat whitelist regex missed -p, -S, -b, and -c, causing mock_all_from_stat to call the user callback with 'lstat' instead of 'stat' for these ops. This meant mocking a symlink-to-socket (for example) would incorrectly fail -S because lstat sees symlink mode bits, not the target's socket mode bits. Replace the fragile whitelist with a simple blacklist: only -l uses lstat. Also fix the dispatch table entries to read from @stat (not @Lstat) for -p/-S/-b/-c, and convert two remaining die calls to Carp::croak for consistency with the public API convention. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Corrects the stat/lstat dispatch for
-p,-S,-b,-cin themock_all_from_statcode path.Why
In Perl, only
-luses lstat — all other file test ops follow symlinks via stat. The$can_use_statwhitelist regex missed these four ops, so mocking a symlink that points to a socket/pipe/block/char device would incorrectly fail the corresponding check (e.g.,-Swould see symlink mode bits from lstat instead of socket mode bits from stat).How
$can_use_stat) with a blacklist: only-ltriggers lstat.-p,-S,-b,-cto read from@statinstead of@lstat.diecalls toCarp::croakfor consistency with the public API convention.Testing
New test
t/stat-dispatch-special-types.twith 6 subtests:-p/-S/-b/-creceive'stat'(not'lstat') as callback argument-lstill uses lstat correctlyFull test suite passes (1440+ subtests).
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 162 insertions(+), 15 deletions(-)
Code scan: clean
Tests: passed (0 Tests)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline