Skip to content

fix: eliminate -B double-dispatch through mock system#91

Merged
atoomic merged 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-B-double-dispatch
Apr 23, 2026
Merged

fix: eliminate -B double-dispatch through mock system#91
atoomic merged 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-B-double-dispatch

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Apr 18, 2026

What

Fix the -B handler in _check_from_stat to avoid re-entering the mock system.

Why

The -B handler called -d $f_or_fh to check if the target is a directory. Since -d is also mocked under mock_all_from_stat, this triggered a full second round-trip through the mock dispatch — calling the user's stat callback again. This is wasteful and risks inconsistency if the callback has side effects or returns different results on subsequent calls.

Additionally, -B and -T were using lstat instead of stat, which is incorrect — both operators follow symlinks in Perl.

How

  • Replace -d $f_or_fh with an inline mode-bit check (_S_IFMT mask against S_IFDIR) on the already-cached @stat array — zero mock re-entry.
  • Add B and T to the $can_use_stat character class so the stat cache (not lstat) is used, matching Perl's symlink-following semantics.

Testing

  • New t/B-no-double-dispatch.t verifies the stat callback is called exactly once per -B check (regular file, directory, non-existent file).
  • Full test suite passes.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 63 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

@atoomic
Copy link
Copy Markdown
Contributor

atoomic commented Apr 23, 2026

@Koan-Bot rebase

The -B handler in _check_from_stat called `-d $f_or_fh` to check for
directories, which re-entered the mock system and triggered a redundant
second call to the user's stat callback. Replace with an inline mode-bit
check on the already-cached @stat array.

Also add B and T to the $can_use_stat set so they use stat (not lstat),
matching Perl's symlink-following behavior for these operators.

Co-Authored-By: Claude <noreply@anthropic.com>
@Koan-Bot
Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan.atoomic/fix-B-double-dispatch was rebased onto main and review feedback was applied.

Stats

2 files changed, 62 insertions(+), 1 deletion(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=None of the recent commits on main address the -B double-dispatch issue or the -B/-T lstat-vs-stat c)
  • Resolved merge conflicts (1 round(s))
  • Rebased koan.atoomic/fix-B-double-dispatch onto upstream/main
  • Pre-push CI check: previous run passed
  • Force-pushed koan.atoomic/fix-B-double-dispatch to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-B-double-dispatch branch from 059d872 to dd81d31 Compare April 23, 2026 08:20
@atoomic atoomic marked this pull request as ready for review April 23, 2026 14:31
@atoomic atoomic merged commit de06278 into cpan-authors:main Apr 23, 2026
21 checks passed
@Koan-Bot Koan-Bot deleted the koan.atoomic/fix-B-double-dispatch branch April 24, 2026 08:02
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.

2 participants