nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: creachadair/jrpc2
Pull request #34 (2020-11-24 17:17:26)

jhttp: Plumb HTTP request into client context.
This allows the client's context hooks to recover the HTTP request so that it can inspect headers or other properties of the request.

Allows a client to address #33.



Patch:
diff --git a/jhttp/bridge.go b/jhttp/bridge.go
index 535f1aa..f537da0 100644
--- a/jhttp/bridge.go
+++ b/jhttp/bridge.go
@@ -3,6 +3,7 @@
 package jhttp
 
 import (
+	"context"
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
@@ -25,6 +26,10 @@ import (
 // If the HTTP request method is not "POST", the bridge reports 405 (Method Not
 // Allowed). If the Content-Type is not application/json, the bridge reports
 // 415 (Unsupported Media Type).
+//
+// The bridge attaches the inbound HTTP request to the context passed to the
+// client, allowing an EncodeContext callback to retrieve state from the HTTP
+// headers. Use jhttp.HTTPRequest to retrieve the request from the context.
 type Bridge struct {
 	cli *jrpc2.Client
 }
@@ -82,7 +87,8 @@ func (b *Bridge) serveInternal(w http.ResponseWriter, req *http.Request) error {
 		}
 	}
 
-	rsps, err := b.cli.Batch(req.Context(), spec)
+	ctx := context.WithValue(req.Context(), httpReqKey{}, req)
+	rsps, err := b.cli.Batch(ctx, spec)
 	if err != nil {
 		return err
 	}
@@ -124,3 +130,15 @@ func (b *Bridge) Close() error { return b.cli.Close() }
 // safe for the caller to continue to use c concurrently with the bridge, as
 // long as it does not close the client.
 func NewBridge(c *jrpc2.Client) *Bridge { return &Bridge{cli: c} }
+
+type httpReqKey struct{}
+
+// HTTPRequest returns the HTTP request associated with ctx, or nil. The
+// context passed to the JSON-RPC client by the Bridge will contain this value.
+func HTTPRequest(ctx context.Context) *http.Request {
+	req, ok := ctx.Value(httpReqKey{}).(*http.Request)
+	if ok {
+		return req
+	}
+	return nil
+}


Test patch:
diff --git a/jhttp/jhttp_test.go b/jhttp/jhttp_test.go
index 7a6d742..99ca115 100644
--- a/jhttp/jhttp_test.go
+++ b/jhttp/jhttp_test.go
@@ -3,6 +3,7 @@ package jhttp
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"io"
 	"io/ioutil"
 	"net/http"
@@ -21,7 +22,16 @@ func TestBridge(t *testing.T) {
 		"Test": handler.New(func(ctx context.Context, ss ...string) (string, error) {
 			return strings.Join(ss, " "), nil
 		}),
-	}, nil)
+	}, &server.LocalOptions{
+		Client: &jrpc2.ClientOptions{
+			EncodeContext: func(ctx context.Context, _ string, p json.RawMessage) (json.RawMessage, error) {
+				if HTTPRequest(ctx) == nil {
+					return nil, errors.New("no HTTP request in context")
+				}
+				return p, nil
+			},
+		},
+	})
 	defer loc.Close()
 
 	// Bridge HTTP to the JSON-RPC server.
Repository: jupyter/qtconsole
Pull request #575 (2023-04-04 22:34:15)

Add missing `closed` method to `QtInProcessChannel`
In PR #574, a new function, `closed()` was added to the `QtZMQSocketChannel` class in order to check whether a channel was closed before flushing the stream. This must also be added to the `QtInProcessChannel` to ensure compatibility. Since in-process channels are never closed, this function should always return the value `False`.

This PR corrects the NeXpy issue [#378](https://github.com/nexpy/nexpy/issues/398) using the latest development version of qtconsole.


Patch:
diff --git a/.gitignore b/.gitignore
index 5ed2aa3..c18177c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,3 +21,4 @@ __pycache__
 .#*
 .coverage
 .pytest_cache
+.vscode
diff --git a/qtconsole/inprocess.py b/qtconsole/inprocess.py
index ca686bd..33d6fde 100644
--- a/qtconsole/inprocess.py
+++ b/qtconsole/inprocess.py
@@ -56,6 +56,10 @@ class QtInProcessChannel(SuperQObject, InProcessChannel):
         super().flush()
         self.process_events()
 
+    def closed(self):
+        """ Function to ensure compatibility with the QtZMQSocketChannel."""
+        return False
+
 
 class QtInProcessHBChannel(SuperQObject, InProcessHBChannel):
     # This signal will never be fired, but it needs to exist


Test patch:
diff --git a/qtconsole/tests/test_inprocess_kernel.py b/qtconsole/tests/test_inprocess_kernel.py
new file mode 100644
index 0000000..a6f9d86
--- /dev/null
+++ b/qtconsole/tests/test_inprocess_kernel.py
@@ -0,0 +1,31 @@
+"""Test QtInProcessKernel"""
+
+# Copyright (c) Jupyter Development Team.
+# Distributed under the terms of the Modified BSD License.
+
+import unittest
+
+from qtconsole.inprocess import QtInProcessKernelManager
+
+
+class InProcessTests(unittest.TestCase):
+
+    def setUp(self):
+        """Open an in-process kernel."""
+        self.kernel_manager = QtInProcessKernelManager()
+        self.kernel_manager.start_kernel()
+        self.kernel_client = self.kernel_manager.client()
+
+    def tearDown(self):
+        """Shutdown the in-process kernel. """
+        self.kernel_client.stop_channels()
+        self.kernel_manager.shutdown_kernel()
+
+    def test_execute(self):
+        """Test execution of shell commands."""
+        # check that closed works as expected
+        assert not self.kernel_client.iopub_channel.closed()
+        
+        # check that running code works
+        self.kernel_client.execute('a=1')
+        assert self.kernel_manager.kernel.shell.user_ns.get('a') == 1