Skip to content

Conversation

@ashwin-ant
Copy link
Collaborator

@ashwin-ant ashwin-ant commented Jan 16, 2026

Summary

Fix the flaky test_permission_callback_gets_called e2e test.

Root Cause

The CLI auto-allows certain read-only commands (like echo 'hello') without consulting the SDK's can_use_tool callback. The original test used echo, which matched the CLI's read-only command pattern:

// In readOnlyValidation.ts line 1737
/^echo(?:\s+(?:'[^']*'|"[^"$<>\n\r]*"|[^|;&\`$(){}><#\\\!"'\s]+))*(?:\s+2>&1)?\s*$/

When a command is classified as read-only, the CLI returns behavior: 'allow' immediately and skips the SDK callback entirely.

Fix

Changed the test to use touch instead of echo. The touch command is NOT in the CLI's read-only command list, so it requires permission approval and correctly invokes the SDK callback.

Changes

  • Use touch command instead of echo (not auto-allowed)
  • Use unique file paths (with UUID) to avoid conflicts
  • Clean up test files after test completes
  • Updated docstring to explain the read-only command behavior

Testing

Ran the test 5+ times locally, all passed.

- Use unique file paths (with UUID) to avoid conflicts with existing files
- Explicitly instruct Claude to create a new file without reading first
- Clean up test files before and after the test
- Store both tool name and input data in callback invocations

This fixes flaky test failures that occurred when /tmp/test.txt already
existed, causing Claude to read the file first and potentially skip the
write if content was identical.

Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%)
Claude-Steers: 0
Claude-Permission-Prompts: 8
Claude-Escapes: 0
The CLI auto-allows certain read-only commands (like 'echo') without
consulting the SDK's can_use_tool callback. This caused the test to fail
because the callback was never invoked.

Changed the test to use 'touch' instead of 'echo', which is NOT in the
CLI's read-only command list and requires permission approval.

Also:
- Use unique file paths (with UUID) to avoid conflicts
- Clean up test files after test completes
- Updated docstring to explain the read-only command behavior

Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%)
Claude-Steers: 9
Claude-Permission-Prompts: 27
Claude-Escapes: 0
@ashwin-ant ashwin-ant merged commit c13f94a into main Jan 16, 2026
28 checks passed
@ashwin-ant ashwin-ant deleted the fix/permission-callback-e2e-test branch January 16, 2026 21:07
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.

3 participants