PrimeIntellect/SWE-rebench-V2-Filtered-Easy-Verified huggingface dataset:
Repository: istio/fortio (go)
Issue: fortio /debug : sort the headers
would make it easier to find
Pull request description: Fix #143 : sort the headers alphabetically for `fortio server` /debug endpoint
fixes #143 

Patch:
diff --git a/fhttp/http.go b/fhttp/http.go
index bee5d42..0f57110 100644
--- a/fhttp/http.go
+++ b/fhttp/http.go
@@ -27,6 +27,7 @@ import (
 	"net/http/httputil"
 	"net/url"
 	"os"
+	"sort"
 	"strconv"
 	"strings"
 	"sync/atomic"
@@ -1232,11 +1233,18 @@ func DebugHandler(w http.ResponseWriter, r *http.Request) {
 	// Host is removed from headers map and put here (!)
 	buf.WriteString("Host: ")
 	buf.WriteString(r.Host)
-	for name, headers := range r.Header {
+
+	var keys []string
+	for k := range r.Header {
+		keys = append(keys, k)
+	}
+	sort.Strings(keys)
+	for _, name := range keys {
 		buf.WriteByte('\n')
 		buf.WriteString(name)
 		buf.WriteString(": ")
 		first := true
+		headers := r.Header[name]
 		for _, h := range headers {
 			if !first {
 				buf.WriteByte(',')


Test patch:
diff --git a/fhttp/http_test.go b/fhttp/http_test.go
index ab0ee41..883bbff 100644
--- a/fhttp/http_test.go
+++ b/fhttp/http_test.go
@@ -597,6 +597,39 @@ func TestPayloadSizeLarge(t *testing.T) {
 	}
 }
 
+func TestDebugHandlerSortedHeaders(t *testing.T) {
+	p, m := DynamicHTTPServer(false)
+	m.HandleFunc("/debug", DebugHandler)
+	url := fmt.Sprintf("http://localhost:%d/debug", p)
+	o := HTTPOptions{URL: url, DisableFastClient: true}
+	o.AddAndValidateExtraHeader("BBB: bbb")
+	o.AddAndValidateExtraHeader("CCC: ccc")
+	o.AddAndValidateExtraHeader("ZZZ: zzz")
+	o.AddAndValidateExtraHeader("AAA: aaa")
+	client := NewClient(&o)
+	code, data, header := client.Fetch() // used to panic/bug #127
+	t.Logf("TestDebugHandlerSortedHeaders result code %d, data len %d, headerlen %d", code, len(data), header)
+	if code != http.StatusOK {
+		t.Errorf("Got %d instead of 200", code)
+	}
+	//remove the first line ('Φορτίο version...') from the body
+	body := string(data)
+	i := strings.Index(body, "\n")
+	body = body[i+1:]
+	expected := fmt.Sprintf("\nGET /debug HTTP/1.1\n\n"+
+		"headers:\n\n"+
+		"Host: localhost:%d\n"+
+		"Aaa: aaa\n"+
+		"Bbb: bbb\n"+
+		"Ccc: ccc\n"+
+		"User-Agent: %s\n"+
+		"Zzz: zzz\n\n"+
+		"body:\n\n\n", p, userAgent)
+	if body != expected {
+		t.Errorf("Get body: %s not as expected: %s", body, expected)
+	}
+}
+
 // --- for bench mark/comparaison
 
 func asciiFold0(str string) []byte {
Repository: awslabs/aws-embedded-metrics-node (ts)
Issue: Calling flush would reset the namespace as well
Documentation for flush()

>flush()
Flushes the current MetricsContext to the configured sink and resets all properties, dimensions and metric values. The namespace and default dimensions will be preserved across flushes.

Namespace is set on the context and at the end of flush, context is set back to empty.

Either the documentation or the behavior of flush should be updated.
Pull request description: fix(#15): preserve the logger context across flushes
Closes #15

Patch:
diff --git a/src/logger/MetricsLogger.ts b/src/logger/MetricsLogger.ts
index d9a86be..fe5ee84 100644
--- a/src/logger/MetricsLogger.ts
+++ b/src/logger/MetricsLogger.ts
@@ -48,7 +48,7 @@ export class MetricsLogger {
 
     // accept and reset the context
     sink.accept(this.context);
-    this.context = MetricsContext.empty();
+    this.context = this.context.createCopyWithContext();
   }
 
   /**


Test patch:
diff --git a/src/logger/__tests__/MetricsLogger.test.ts b/src/logger/__tests__/MetricsLogger.test.ts
index 0d5ecb9..984ca79 100644
--- a/src/logger/__tests__/MetricsLogger.test.ts
+++ b/src/logger/__tests__/MetricsLogger.test.ts
@@ -261,6 +261,42 @@ test('flush() delegates context configuration to the environment by calling conf
   expect(environment.configureContext).toBeCalled();
 });
 
+test('context is preserved across flush() calls', async () => {
+  // arrange
+  const expectedNamespace = 'Namespace';
+  const metricKey = 'Metric';
+  const expectedDimensionKey = 'Dim';
+  const expectedPropertyKey = 'Prop';
+  const expectedValues = 'Value';
+
+  const dimensions: Record<string, string> = {};
+  dimensions[expectedDimensionKey] = expectedValues;
+
+  logger.setNamespace(expectedNamespace);
+  logger.setProperty(expectedPropertyKey, expectedValues);
+  logger.setDimensions(dimensions);
+
+  // act
+  logger.putMetric(metricKey, 0);
+  await logger.flush();
+
+  logger.putMetric(metricKey, 1);
+  await logger.flush();
+
+  // assert
+  expect(sink.events).toHaveLength(2);
+  for (let i = 0; i < sink.events.length; i++) {
+    const evt = sink.events[i];
+    // namespace, properties, dimensions should survive flushes
+    expect(evt.namespace).toBe(expectedNamespace);
+    expect(evt.getDimensions()[0][expectedDimensionKey]).toBe(expectedValues);
+    expect(evt.properties[expectedPropertyKey]).toBe(expectedValues);
+    // metric values should not survive flushes
+    // @ts-ignore
+    expect(evt.metrics.get(metricKey).values).toStrictEqual([i]);
+  }
+});
+
 const expectDimension = (key: string, value: string) => {
   expect(sink.events).toHaveLength(1);
   const dimensionSets = sink.events[0].getDimensions();