mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
mcp_server: fix EOF handling.
We need to handle when `stdin` is closed but there's no interrupt signal. Without this, the server will be stuck an in infinite busy loop.
This commit is contained in:
parent
c19f08b3e8
commit
818662352c
@ -155,6 +155,8 @@ module Homebrew
|
|||||||
input = if ping_switch?
|
input = if ping_switch?
|
||||||
{ jsonrpc: JSON_RPC_VERSION, id: 1, method: "ping" }.to_json
|
{ jsonrpc: JSON_RPC_VERSION, id: 1, method: "ping" }.to_json
|
||||||
else
|
else
|
||||||
|
break if @stdin.eof?
|
||||||
|
|
||||||
@stdin.gets
|
@stdin.gets
|
||||||
end
|
end
|
||||||
next if input.nil? || input.strip.empty?
|
next if input.nil? || input.strip.empty?
|
||||||
|
@ -228,6 +228,8 @@ RSpec.describe Homebrew::McpServer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "exits on Interrupt" do
|
it "exits on Interrupt" do
|
||||||
|
stdin.puts
|
||||||
|
stdin.rewind
|
||||||
allow(stdin).to receive(:gets).and_raise(Interrupt)
|
allow(stdin).to receive(:gets).and_raise(Interrupt)
|
||||||
expect do
|
expect do
|
||||||
server.run
|
server.run
|
||||||
@ -237,6 +239,8 @@ RSpec.describe Homebrew::McpServer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "exits on error" do
|
it "exits on error" do
|
||||||
|
stdin.puts
|
||||||
|
stdin.rewind
|
||||||
allow(stdin).to receive(:gets).and_raise(StandardError, "fail")
|
allow(stdin).to receive(:gets).and_raise(StandardError, "fail")
|
||||||
expect do
|
expect do
|
||||||
server.run
|
server.run
|
||||||
|
Loading…
x
Reference in New Issue
Block a user