feat: Validate tool function arities at registration time (#42)#68
feat: Validate tool function arities at registration time (#42)#68andreasronge merged 2 commits intomainfrom
Conversation
Move tool function arity validation from call-time to registration-time
(when tools are passed to PtcRunner.run/2). This provides earlier error
detection, better error messages, and fail-fast behavior for library users.
Changes:
- Add validate_tools/1 private function in PtcRunner to check all tools
have arity 1 at registration time
- Update run/2 to validate tools before creating context
- Return {:error, {:validation_error, msg}} for invalid tools
- Error message identifies which tools have wrong arity
- Update existing test at line 3214 to expect validation_error
- Add 6 new tests covering:
- Arity-0 and arity-2 function detection
- Non-function value detection
- Multiple invalid tools reporting
- Valid arity-1 functions passing validation
- Empty tools map handling
Fixes #42
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
PR Review: feat: Validate tool function arities at registration time (#42)SummaryThis PR moves tool arity validation from call-time to registration-time, providing fail-fast behavior and better developer experience. The implementation is clean and well-tested. What's Good
Issues (Must Fix)
Suggestions (Optional)
SecurityNo concerns. The change improves validation without introducing any security risks. VerdictRequest Changes - The implementation correctly achieves the goal, but the dead code in |
|
@claude please fix these issues from PR review: Issue 1: Remove dead code in operations.exLocation:
This leaves only two branches:
Please fix this issue in a SINGLE commit. Make minimal changes to resolve the dead code. |
Auto-Triage SummaryDecisions Made
ReasoningIssue 1: Dead code removal (FIX_NOW)
The optional suggestion about defense-in-depth was not actioned because:
Status
All review findings have been addressed. Awaiting claude.yml workflow to apply the fix. |
Remove unreachable catch-all branch that checked for non-arity-1 functions. Since tools are now validated at registration time via validate_tools/1, all tools in the registry are guaranteed to be arity-1 functions. Changes: - Remove guard clause 'when is_function(tool_fn, 1)' from pattern match - Remove catch-all '_tool_fn' branch that is now unreachable - Simplify case statement to only handle nil (not found) and tool_fn (execute) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
Fixed Dead Code Issue in operations.exThe dead code in Changes Made
Verification
The fix removes the unreachable dead code since tools are now validated at registration time via the new |
PR Review: feat: Validate tool function arities at registration time (#42)SummaryThis PR moves tool arity validation from call-time to registration-time, providing fail-fast validation when tools are passed to What's Good
Issues (Must Fix)None. The implementation is complete and consistent. Suggestions (Optional)
SecurityNo concerns. The change improves security by catching misconfigurations earlier. VerdictApprove - The implementation is clean, complete, and well-tested. The PR correctly addresses issue #42 by moving tool validation from call-time to registration-time, with proper error handling and comprehensive test coverage. |
Auto-Triage Summary (Cycle 2/3)Latest Review AnalysisThe latest review (2025-12-02T15:44:34Z) gave Approve verdict with no must-fix issues. Decisions Made
ReasoningIssue 1: Sort tool names (IGNORE)
Per the triage guidelines, this falls under "Truly optional stylistic preference with no functional benefit" → IGNORE. Status
Next StepsAll review findings have been addressed. The PR has been approved with no required changes. Adding the |
Summary
This PR implements tool function arity validation at registration time rather than call-time, providing:
run/2Changes
Core Implementation
validate_tools/1private function inPtcRunnermodulerun/2{:error, {:validation_error, msg}}for invalid toolsTest Updates
validation_errorinstead ofexecution_error(since validation now happens earlier)Verification
mix precommitpasses (format, credo, compile checks)Fixes #42