Skip to content

feat: add Jaro-Winkler typo suggestions for unknown operations (Fixes #43)#44

Merged
andreasronge merged 1 commit intomainfrom
claude/issue-43-20251202
Dec 2, 2025
Merged

feat: add Jaro-Winkler typo suggestions for unknown operations (Fixes #43)#44
andreasronge merged 1 commit intomainfrom
claude/issue-43-20251202

Conversation

@andreasronge
Copy link
Copy Markdown
Owner

Summary

Implements helpful typo suggestions in validation error messages when users provide unknown operation names. Uses the built-in Jaro-Winkler similarity algorithm to suggest the closest matching valid operation when similarity exceeds 0.8.

This directly supports Phase 5 goals for "Error messages optimized for LLM consumption" - typo suggestions help LLMs self-correct their generated programs, reducing roundtrips.

Changes

  • lib/ptc_runner/validator.ex:

    • Added @valid_operations module attribute listing all 34 valid operations
    • Implemented suggest_operation/1 helper function using String.jaro_distance/2
    • Updated unknown operation error to include suggestion suffix when similarity > 0.8
    • Handles case-insensitive matching via String.downcase/1
  • test/ptc_runner_test.exs:

    • Added 5 unit tests covering common typos:
      • Single character typo ("filer" → "filter")
      • Missing letter ("selct" → "select")
      • Extra letter ("filtter" → "filter")
      • Case insensitivity ("FILTER" → "filter")
      • No suggestion for unrelated names ("xyz")
    • Added E2E test demonstrating typo suggestion in complex pipeline

Test Results

  • All 242 tests pass
  • No code style issues detected
  • No compilation warnings

Examples

```
Unknown operation 'filer'. Did you mean 'filter'?
Unknown operation 'selct'. Did you mean 'select'?
Unknown operation 'xyz' (no suggestion, below threshold)
```

Fixes #43

🤖 Generated with Claude Code

Implements helpful typo suggestions in validation error messages when users
provide unknown operation names. Uses Jaro-Winkler similarity algorithm to
find the closest matching valid operation with a threshold of 0.8 to avoid
spurious suggestions.

Fixes #43

- Add suggest_operation/1 helper function in validator.ex with @valid_operations list
- Update unknown operation error to include suggestion suffix when similarity > 0.8
- Add comprehensive unit tests covering common typos (missing letter, extra letter)
- Add case-insensitive handling via String.downcase
- Add E2E test for typo suggestion in complex pipeline
- All existing tests pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 2, 2025

PR Review: feat: add Jaro-Winkler typo suggestions for unknown operations

Summary

Clean implementation of typo suggestions for unknown operation names using Elixir's built-in String.jaro_distance/2. The PR correctly addresses Issue #43 with a minimal, focused approach that directly supports the Phase 5 goal of LLM-friendly error messages.

What's Good

  • Correct algorithm choice: Using String.jaro_distance/2 from stdlib avoids external dependencies
  • Sensible threshold: 0.8 threshold is appropriate - high enough to avoid misleading suggestions, low enough to catch common typos
  • Case-insensitive matching: String.downcase/1 on the unknown op ensures FILTERfilter works
  • Complete @valid_operations list: All 33 defined operations are correctly included (verified against actual validate_operation/2 clauses)
  • Comprehensive test coverage:
    • Common typo patterns (missing letter, extra letter, adjacent letter swap via "filer")
    • Case insensitivity
    • No suggestion for unrelated names
    • E2E test showing suggestion in nested context
  • Clean integration: The change is minimal (14 lines added) and fits well with existing validator patterns

Issues (Must Fix)

None. The implementation is complete and correct.

Suggestions (Optional)

  1. OPTIONAL: Empty string edge case test - Nice-to-have
    • Suggestion: Consider adding a test for {"op": ""} to document behavior
    • Benefit: Documents that empty strings naturally get no suggestion (jaro_distance returns 0.0)
    • Complexity: Trivial (1 test)
    • Recommendation: Not blocking - current validation may reject this earlier anyway

Security

No concerns. The feature only affects validation error messages and uses no external input beyond what's already validated. The @valid_operations list is hardcoded at compile time.

Verdict

Approve - This is a well-implemented, focused enhancement that directly addresses the issue specification. All tests pass, the code follows existing patterns, and the @valid_operations list correctly matches all 33 defined operations. Ready to merge.

@github-actions github-actions bot added the auto-triage-pending Auto-triage in progress label Dec 2, 2025
@andreasronge andreasronge added the ready-to-merge PR is ready to be merged label Dec 2, 2025
@andreasronge
Copy link
Copy Markdown
Owner Author

Auto-Triage Summary

Review Analysis

Reviewed the PR #44 approval comment from github-actions bot. The review gave an APPROVE verdict with zero must-fix issues and one optional suggestion.

Decisions Made

# Issue Decision Reasoning
1 Empty string edge case test IGNORE Reviewer explicitly marked as "OPTIONAL", "nice-to-have", and "not blocking". This is a truly optional stylistic preference with no functional benefit. The PR received an APPROVE verdict and is ready to merge as-is.

Status

  • FIX_NOW items: 0
  • Issues created: 0
  • Items ignored: 1

Conclusion

The PR is approved and ready to merge. All critical functionality is implemented correctly with comprehensive test coverage. The single optional suggestion does not warrant blocking or additional work.

@github-actions github-actions bot added auto-triage-cycle-1 Auto-triage cycle 1 auto-triage-complete Auto-triage completed and removed auto-triage-pending Auto-triage in progress labels Dec 2, 2025
@andreasronge andreasronge enabled auto-merge (squash) December 2, 2025 08:33
@andreasronge andreasronge merged commit 5418cf2 into main Dec 2, 2025
3 checks passed
@andreasronge andreasronge deleted the claude/issue-43-20251202 branch December 2, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-triage-complete Auto-triage completed auto-triage-cycle-1 Auto-triage cycle 1 ready-to-merge PR is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Phase 5] Add typo suggestions for unknown operations

1 participant