fix: make _check() re-entrant safe for nested mock callbacks#74
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: make _check() re-entrant safe for nested mock callbacks#74Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
Save $_last_call_for before dispatching the user callback and restore it (instead of clobbering with undef) when the file argument is a reference. This prevents re-entrant _check() calls — e.g. mock_all_from_stat callbacks that invoke other mocked file tests — from corrupting the filename cache used by stacked -X _ operations. Also improves the filehandle-ref case (GH #179): instead of setting the cache to undef, we restore the pre-callback value so that a valid filename from before the filehandle call remains available for subsequent stacked ops. Closes cpan-authors#68 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
Save and restore
$_last_call_foraround callback dispatch in_check()to prevent re-entrant calls from corrupting the filename cache.Why
When a
mock_all_from_statcallback (or any mock callback) invokes another mocked file test,_check()is called re-entrantly. The inner call overwrites$_last_call_for, corrupting the stacked-X _filename context for the outer call. This could cause stacked ops to test the wrong filename — a subtle correctness issue in complex mock scenarios.How
$_last_call_forbefore dispatching the callbackundefclobber from GH #179)t/reentrant-check.twith 9 tests covering: re-entrant callbacks with stacked ops, andmock_all_from_statwith nested file testsTesting
t/reentrant-check.t— 9 tests, all passCloses #68
🤖 Generated with Claude Code