Skip to content

Commit

Permalink
riff nit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale committed Sep 5, 2024
1 parent 76cb46b commit eee2b4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/goose/toolkit/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Global dictionary to store the last read timestamps
last_read_timestamps: Dict[str, float] = {}


def keep_unsafe_command_prompt(command: str) -> PromptType:
command_text = Text(command, style="bold red")
message = (
Expand Down
18 changes: 18 additions & 0 deletions tests/toolkit/test_developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,21 @@ def test_write_file(temp_dir, developer_toolkit):
content = "Hello World"
developer_toolkit.write_file(test_file.as_posix(), content)
assert test_file.read_text() == content


def test_write_file_prevent_write_if_changed(temp_dir, developer_toolkit):
test_file = temp_dir / "test.txt"
content = "Hello World"
updated_content = "Hello Universe"

# Initial write to record the timestamp
developer_toolkit.write_file(test_file.as_posix(), content)
developer_toolkit.read_file(test_file.as_posix())

# Modify file externally to simulate change
test_file.write_text(updated_content)

# Try to write through toolkit and check response
result = developer_toolkit.write_file(test_file.as_posix(), content)
assert result.endswith("has been modified since it was last read. Not writing to file.")
assert test_file.read_text() == updated_content

0 comments on commit eee2b4f

Please sign in to comment.