Skip to content

Fix/anthropic native tools#39

Merged
omarluq merged 3 commits into
mainfrom
fix/anthropic-native-tools
May 22, 2026
Merged

Fix/anthropic native tools#39
omarluq merged 3 commits into
mainfrom
fix/anthropic-native-tools

Conversation

@omarluq

@omarluq omarluq commented May 22, 2026

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c769708-7218-48fb-92d4-9addbc1dc7e2

📥 Commits

Reviewing files that changed from the base of the PR and between 291dd4d and 4bfae88.

📒 Files selected for processing (2)
  • internal/assistant/anthropic_internal_test.go
  • internal/tool/registry_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Write operations now validate and reject empty or whitespace-only content.
  • Tests
    • Improved test coverage for tool name mapping and payload handling (including tool identity and streaming behavior).
    • Added tests ensuring write requests fail when content is missing or invalid.

Walkthrough

WriteTool now rejects empty write content and the write schema uses the jsonContentKey constant. Registry and Anthropic-focused tests were added/extended, plus a JSON helper to assert encoded tool payloads and tool-name mapping behavior.

Changes

Write Tool Content Validation and Testing

Layer / File(s) Summary
Write content validation and schema update
internal/tool/write.go, internal/assistant/tool_schema.go, internal/tool/registry_test.go
WriteTool.Write trims and requires non-empty input.Content, returning a write_content_required error when blank. writeToolSchema() uses jsonContentKey for the content property and required list. New TestRegistry_ExecuteJSONRejectsEmptyWriteContent verifies ExecuteJSON rejects empty/whitespace write content.
Anthropic tool-name tests and JSON helper
internal/assistant/anthropic_internal_test.go
Adds encoding/json import and encodeTestJSON helper. Extends TestAnthropicOAuthPayloadAddsClaudeCodeIdentity to assert encoded tools and eager_input_streaming. Adds TestAnthropicToolNameMapping to assert API-key payload uses local tool-name constants and that anthropicToolCall maps Claude Code "Write" to the local tool name while preserving arguments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • omarluq/librecode#34: Overlaps on Anthropic tool-name mapping and rejecting empty write operations.

Poem

A rabbit tests with JSON cheer,
Trims empty content, keeps intent clear,
Names mapped tidy so tools appear,
Constants fixed and errors near—
Hops, asserts, and a happy ear 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix/anthropic native tools' is vague and uses a slash-based format resembling a branch name. It lacks clarity about the specific fix being made. Consider a more descriptive title that explains the actual fix, such as 'Add write content validation and tool name mapping for Anthropic native tools'.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess relatedness to the changeset. Add a description explaining the purpose of the changes, such as addressing the Anthropic review feedback and the specific tool validation fixes being implemented.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/anthropic-native-tools

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

codecov-commenter commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.16%. Comparing base (82d7364) to head (4bfae88).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #39      +/-   ##
==========================================
+ Coverage   60.13%   60.16%   +0.02%     
==========================================
  Files         168      168              
  Lines       16663    16665       +2     
==========================================
+ Hits        10021    10027       +6     
+ Misses       5632     5628       -4     
  Partials     1010     1010              
Flag Coverage Δ
unittests 60.16% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/assistant/anthropic_internal_test.go (1)

81-103: ⚡ Quick win

Prefer table-driven coverage for tool-name mapping cases.

These mapping checks are core behavior and will be easier to extend/maintain as table-driven cases in one test function.

As per coding guidelines, "**/*_test.go: Prefer table-driven tests for core behavior and regression tests for terminal rendering bugs".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/assistant/anthropic_internal_test.go` around lines 81 - 103, Combine
the two existing tests into a single table-driven test that exercises the
mapping between Claude/Anthropic tool names and local tool names: create a
TestAnthropicToolNameMapping test that defines cases (e.g., payload-encoding
case and tool-call mapping case) with fields for input (use
testCompletionRequestAuth/API key or testAnthropicToolUseID, action like
"Write"/"Read", and args) and expected outputs (expected encoded tool names or
call.Name and call.Arguments); iterate cases with t.Run and t.Parallel(),
invoking anthropicPayload or anthropicToolCall as appropriate, and assert
expected name mappings (jsonWriteToolName/jsonReadToolName vs
anthropicReadToolName) and argument passthrough using the same helpers
encodeTestJSON and assert.Equal/assert.Contains as before so coverage is
equivalent but now table-driven for easier extension.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/tool/registry_test.go`:
- Around line 69-80: Update the test
TestRegistry_ExecuteJSONRejectsEmptyWriteContent to be table-driven and include
a whitespace-only content case (e.g. "   \n\t") in addition to the empty string;
for each table entry call registry.ExecuteJSON(context.Background(), "write",
payload) and assert an error whose message contains "write content is required"
to ensure the trim-based validation in Write is covered. Use the existing
registry := tool.NewRegistry(t.TempDir()) setup and json.Marshal per case to
build payloads and iterate assertions.

---

Nitpick comments:
In `@internal/assistant/anthropic_internal_test.go`:
- Around line 81-103: Combine the two existing tests into a single table-driven
test that exercises the mapping between Claude/Anthropic tool names and local
tool names: create a TestAnthropicToolNameMapping test that defines cases (e.g.,
payload-encoding case and tool-call mapping case) with fields for input (use
testCompletionRequestAuth/API key or testAnthropicToolUseID, action like
"Write"/"Read", and args) and expected outputs (expected encoded tool names or
call.Name and call.Arguments); iterate cases with t.Run and t.Parallel(),
invoking anthropicPayload or anthropicToolCall as appropriate, and assert
expected name mappings (jsonWriteToolName/jsonReadToolName vs
anthropicReadToolName) and argument passthrough using the same helpers
encodeTestJSON and assert.Equal/assert.Contains as before so coverage is
equivalent but now table-driven for easier extension.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 01337f9a-ace1-4e77-a0d3-ba482c0c2c51

📥 Commits

Reviewing files that changed from the base of the PR and between 82d7364 and 291dd4d.

📒 Files selected for processing (4)
  • internal/assistant/anthropic_internal_test.go
  • internal/assistant/tool_schema.go
  • internal/tool/registry_test.go
  • internal/tool/write.go

Comment thread internal/tool/registry_test.go
@sonarqubecloud

Copy link
Copy Markdown

@omarluq
omarluq merged commit ec4b5d5 into main May 22, 2026
13 checks passed
@omarluq
omarluq deleted the fix/anthropic-native-tools branch May 23, 2026 04:40
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
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