-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
#!/usr/bin/env ruby
# Minimal example demonstrating the bug when calling puts() with no arguments
# in terminalwire/ruby
#
# Expected behavior: Should print a blank line (like standard Ruby puts)
# Actual behavior: Raises an error
#
# To run this example, you need:
# gem install terminalwire-server terminalwire-client
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'terminalwire-server'
gem 'terminalwire-client'
gem 'async'
gem 'async-websocket'
end
require 'terminalwire/server'
require 'terminalwire/client'
# Mock adapter for testing without a real WebSocket connection
class MockAdapter
def initialize
@messages = []
end
def write(message)
@messages << message
puts "Server sent: #{message.inspect}"
end
def read
# Simulate client response based on the command
last_message = @messages.last
if last_message && last_message[:command] == "read" && last_message[:parameters][:name] == "TERMINALWIRE_HOME"
# Return a mock home directory
{ status: "success", response: "/tmp/terminalwire" }
else
# Default success response
{ status: "success", response: nil }
end
end
def close
# No-op
end
end
# Create a mock entitlement
entitlement = {
authority: "example.com",
paths: [],
schemes: [],
environment_variables: []
}
# Create server context with mock adapter
adapter = MockAdapter.new
context = Terminalwire::Server::Context.new(adapter: adapter, entitlement: entitlement)
puts "=" * 60
puts "Testing Terminalwire puts() with no arguments"
puts "=" * 60
puts
# Test 1: puts with content (this works)
puts "Test 1: puts with content (should work)"
begin
context.puts "Hello, World!"
puts "✓ Success: puts with content works"
rescue => e
puts "✗ Error: #{e.class}: #{e.message}"
end
puts
# Test 2: puts with no arguments (this should work but may error)
puts "Test 2: puts with no arguments (should print blank line)"
begin
context.puts
puts "✓ Success: puts with no arguments works"
rescue ArgumentError => e
puts "✗ Error: #{e.class}: #{e.message}"
puts " This is the bug! Ruby's puts() with no args should print a blank line."
rescue => e
puts "✗ Error: #{e.class}: #{e.message}"
end
puts
# Test 3: puts with nil (similar issue)
puts "Test 3: puts with nil (should print blank line)"
begin
context.puts nil
puts "✓ Success: puts with nil works"
rescue => e
puts "✗ Error: #{e.class}: #{e.message}"
end
puts
puts "=" * 60
puts "Expected behavior:"
puts " All three tests should succeed, as Ruby's standard puts() method"
puts " accepts zero or more arguments and prints blank lines for no args."
puts
puts "Suggested fix:"
puts " In terminalwire-server/lib/terminalwire/server/resource.rb,"
puts " change the STDOUT#puts method to:"
puts
puts " def puts(*args)"
puts " data = args.empty? ? \"\" : args.first"
puts " command(\"print_line\", data: data)"
puts " end"
puts "=" * 60
Metadata
Metadata
Assignees
Labels
No labels