Skip to content

Fix: Ensure write_to_file creates empty files when content is empty #3871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Ruakij
Copy link

@Ruakij Ruakij commented May 22, 2025

Early check for partial-block
Small typo
Missing path normalization

Related GitHub Issue

Closes: #3650

Description

This PR fixes a bug where the write_to_file tool would appear to succeed but fail to create files when the content parameter is empty. The tool now properly creates empty files when requested, ensuring consistent behavior regardless of content length.

Key changes:

  • Modified the file writing logic to handle empty content correctly
  • Enhanced error handling for edge cases
  • Refactor file for simplification and reduced code-duplication
  • Add Unit-Tests for writeToFileTool

Test Procedure

  • Unit-tests
  • Ask model to create an empty file

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Get in Touch

Discord: ruakij


Important

Fixes writeToFileTool to handle empty content correctly, adds error handling, refactors for clarity, and introduces comprehensive unit tests.

  • Behavior:
    • Fixes writeToFileTool to create files even when content is empty in writeToFileTool.ts.
    • Adds early return for missing path or content in partial blocks.
    • Improves error handling for missing parameters and line count discrepancies.
  • Refactoring:
    • Introduces helper functions: validateAccess, checkFileExists, preprocessContent, createMessageProps, and handleDiffViewUpdate in writeToFileTool.ts.
    • Refactors file writing logic for clarity and reduced duplication.
  • Testing:
    • Adds writeToFileTool.test.ts with unit tests for parameter validation, access control, file existence, content preprocessing, file operations, partial block handling, user interaction, and error handling.

This description was created by Ellipsis for 06d8bbb. You can customize this summary. It will automatically update as commits are pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR [Pre Approval Review]
Development

Successfully merging this pull request may close these issues.

Bug: write_to_file with empty content appears to succeed but no file is created
1 participant