nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: pulumi/esc
Pull request #555 (2025-07-16 01:09:21)

cli: fix sorting in env ls
Sorting does not take the project name into account. These changes fix
the behavior of `env ls` so that environments are sorted by
organization, then project, then name.



Patch:
diff --git a/cmd/esc/cli/env_ls.go b/cmd/esc/cli/env_ls.go
index b79620f..000aeeb 100644
--- a/cmd/esc/cli/env_ls.go
+++ b/cmd/esc/cli/env_ls.go
@@ -39,10 +39,15 @@ func newEnvLsCmd(env *envCommand) *cobra.Command {
 			}
 
 			sort.Slice(allEnvs, func(i, j int) bool {
-				if allEnvs[i].Organization == allEnvs[j].Organization {
-					return allEnvs[i].Name < allEnvs[j].Name
+				ei, ej := allEnvs[i], allEnvs[j]
+
+				if ei.Organization == ej.Organization {
+					if ei.Project == ej.Project {
+						return ei.Name < ej.Name
+					}
+					return ei.Project < ej.Project
 				}
-				return allEnvs[i].Organization < allEnvs[j].Organization
+				return ei.Organization < ej.Organization
 			})
 
 			for _, e := range allEnvs {


Test patch:
diff --git a/cmd/esc/cli/testdata/env-ls.yaml b/cmd/esc/cli/testdata/env-ls.yaml
index 4a02b93..216a3a4 100644
--- a/cmd/esc/cli/testdata/env-ls.yaml
+++ b/cmd/esc/cli/testdata/env-ls.yaml
@@ -3,6 +3,9 @@ environments:
   test-org-2/default/env: true
   test-org/default/env: true
   test-org/default/env-2: true
+  test-org/project-a/env: true
+  test-org/project-a/env-2: true
+  test-org/project-b/env: true
   test-user/default/env: true
   test-user/default/env-2: true
 
@@ -12,6 +15,9 @@ default/env
 default/env-2
 test-org/default/env
 test-org/default/env-2
+test-org/project-a/env
+test-org/project-a/env-2
+test-org/project-b/env
 test-org-2/default/env
 
 ---
Repository: dominikbraun/graph
Pull request #56 (2022-10-19 19:56:27)

update TopologicalSort to not require PreventCycles and fail if cycle detected
This also adds unit test case for asserting error for graph with cycle.

Fixes: #49 


Patch:
diff --git a/dag.go b/dag.go
index a33be7e..f67cd92 100644
--- a/dag.go
+++ b/dag.go
@@ -12,8 +12,8 @@ import (
 // TopologicalSort only works for directed acyclic graphs. The current implementation works non-
 // recursively and uses Kahn's algorithm.
 func TopologicalSort[K comparable, T any](g Graph[K, T]) ([]K, error) {
-	if !isDAG(g) {
-		return nil, errors.New("topological sort can only be performed on DAGs created with the PreventCycles option")
+	if !g.Traits().IsDirected {
+		return nil, fmt.Errorf("topological sort cannot be computed on undirected graph")
 	}
 
 	predecessorMap, err := g.PredecessorMap()
@@ -52,6 +52,10 @@ func TopologicalSort[K comparable, T any](g Graph[K, T]) ([]K, error) {
 		}
 	}
 
+	if len(order) != g.Order() {
+		return nil, errors.New("topological sort cannot be computed on graph with cycles")
+	}
+
 	return order, nil
 }
 


Test patch:
diff --git a/dag_test.go b/dag_test.go
index 517774f..6d9c996 100644
--- a/dag_test.go
+++ b/dag_test.go
@@ -7,6 +7,7 @@ func TestDirectedTopologicalSort(t *testing.T) {
 		vertices      []int
 		edges         []Edge[int]
 		expectedOrder []int
+		shouldFail    bool
 	}{
 		"graph with 5 vertices": {
 			vertices: []int{1, 2, 3, 4, 5},
@@ -21,10 +22,19 @@ func TestDirectedTopologicalSort(t *testing.T) {
 			},
 			expectedOrder: []int{1, 2, 3, 4, 5},
 		},
+		"graph with cycle": {
+			vertices: []int{1, 2, 3},
+			edges: []Edge[int]{
+				{Source: 1, Target: 2},
+				{Source: 2, Target: 3},
+				{Source: 3, Target: 1},
+			},
+			shouldFail: true,
+		},
 	}
 
 	for name, test := range tests {
-		graph := New(IntHash, Directed(), PreventCycles())
+		graph := New(IntHash, Directed())
 
 		for _, vertex := range test.vertices {
 			_ = graph.AddVertex(vertex)
@@ -37,8 +47,13 @@ func TestDirectedTopologicalSort(t *testing.T) {
 		}
 
 		order, err := TopologicalSort(graph)
-		if err != nil {
-			t.Fatalf("%s: failed to add edge: %s", name, err.Error())
+
+		if test.shouldFail != (err != nil) {
+			t.Errorf("%s: error expectancy doesn't match: expected %v, got %v (error: %v)", name, test.shouldFail, err != nil, err)
+		}
+
+		if test.shouldFail {
+			continue
 		}
 
 		if len(order) != len(test.expectedOrder) {
Repository: theupdateframework/go-tuf
Pull request #641 (2024-06-18 12:24:57)

export API to set RefTime of Updater
This PR exports an API to set the `RefTime` of the trusted metadata of an `Updater`. This is useful for testing time-related cases in the client outside of go-tufs own repository.

kommendorkapten: Thanks for the contribution @AdamKorcz, would you mind also adding a comment describing this, why it may be useful and any consequences of using this in a real life application?
AdamKorcz: > Thanks for the contribution @AdamKorcz, would you mind also adding a comment describing this, why it may be useful and any consequences of using this in a real life application?

https://github.com/theupdateframework/go-tuf/pull/641/commits/faf9792df89ebd60c16f13d49d22d6ea13868b1d - LMK if it needs more context. I have kept it short to align the description with other methods in the file.
kommendorkapten: @rdimitrov @trishankatdatadog any thoughts?
kommendorkapten: I think it's fine w/out get/set? The other fields are lacking this, and I think it's clear with the current design?

Patch:
diff --git a/metadata/updater/updater.go b/metadata/updater/updater.go
index 7d723df..8433cef 100644
--- a/metadata/updater/updater.go
+++ b/metadata/updater/updater.go
@@ -662,6 +662,13 @@ func (update *Updater) GetTrustedMetadataSet() trustedmetadata.TrustedMetadata {
 	return *update.trusted
 }
 
+// UnsafeSetRefTime sets the reference time that the updater uses.
+// This should only be done in tests.
+// Using this function is useful when testing time-related behavior in go-tuf.
+func (update *Updater) UnsafeSetRefTime(t time.Time) {
+	update.trusted.RefTime = t
+}
+
 func IsWindowsPath(path string) bool {
 	match, _ := regexp.MatchString(`^[a-zA-Z]:\\`, path)
 	return match


Test patch:
diff --git a/metadata/updater/updater_top_level_update_test.go b/metadata/updater/updater_top_level_update_test.go
index 42715fb..214105b 100644
--- a/metadata/updater/updater_top_level_update_test.go
+++ b/metadata/updater/updater_top_level_update_test.go
@@ -98,7 +98,7 @@ func runRefresh(updaterConfig *config.UpdaterConfig, moveInTime time.Time) (Upda
 	}
 
 	if moveInTime != time.Now() {
-		updater.trusted.RefTime = moveInTime
+		updater.UnsafeSetRefTime(moveInTime)
 	}
 
 	return *updater, updater.Refresh()
Repository: theupdateframework/go-tuf
Pull request #686 (2025-05-08 20:07:13)

Set a default HTTP client for DefaultFetcher in DownloadFile method if none is set
If someone instantiates a new DefaultFetcher directly with `DefaultFetcher{}` instead of with the new constructor , `DownloadFile` will fail because the `client` field has not been set. This pull request updates `DownloadFile` to check if the `client` field is `nil` and sets a default HTTP client if it is to avoid breaking current usage of `DefaultFetcher`.


Patch:
diff --git a/metadata/fetcher/fetcher.go b/metadata/fetcher/fetcher.go
index 87198bf..71796b7 100644
--- a/metadata/fetcher/fetcher.go
+++ b/metadata/fetcher/fetcher.go
@@ -70,6 +70,11 @@ func (d *DefaultFetcher) DownloadFile(urlPath string, maxLength int64, _ time.Du
 		req.Header.Set("User-Agent", d.httpUserAgent)
 	}
 
+	// For backwards compatibility, if the client is nil, use the default client.
+	if d.client == nil {
+		d.client = http.DefaultClient
+	}
+
 	operation := func() ([]byte, error) {
 		// Execute the request.
 		res, err := d.client.Do(req)


Test patch:
diff --git a/metadata/fetcher/fetcher_test.go b/metadata/fetcher/fetcher_test.go
index 330919d..aab6e91 100644
--- a/metadata/fetcher/fetcher_test.go
+++ b/metadata/fetcher/fetcher_test.go
@@ -170,3 +170,9 @@ func TestDownloadFile_Retry(t *testing.T) {
 		})
 	}
 }
+
+func TestDownloadFile_NoHTTPClientSet(t *testing.T) {
+	fetcher := DefaultFetcher{}
+	_, err := fetcher.DownloadFile("https://jku.github.io/tuf-demo/metadata/1.root.json", 512000, 0)
+	assert.NoError(t, err)
+}
Repository: theupdateframework/go-tuf
Pull request #159 (2021-09-28 17:12:17)

make the updateRoots public
For partial verification, we should be able to update the root without needing the update of the non-root metadata. 
This is because in many implementations of the partial verification, there is no timestamp or snapshot so a general update will fail.


Patch:
diff --git a/client/client.go b/client/client.go
index e918bdc..889f706 100644
--- a/client/client.go
+++ b/client/client.go
@@ -151,7 +151,7 @@ func (c *Client) Init(rootKeys []*data.Key, threshold int) error {
 //
 // https://theupdateframework.github.io/specification/v1.0.19/index.html#load-trusted-root
 func (c *Client) Update() (data.TargetFiles, error) {
-	if err := c.updateRoots(); err != nil {
+	if err := c.UpdateRoots(); err != nil {
 		if _, ok := err.(verify.ErrExpired); ok {
 			// For backward compatibility, we wrap the ErrExpired inside
 			// ErrDecodeFailed.
@@ -216,7 +216,7 @@ func (c *Client) Update() (data.TargetFiles, error) {
 	return updatedTargets, nil
 }
 
-func (c *Client) updateRoots() error {
+func (c *Client) UpdateRoots() error {
 	// https://theupdateframework.github.io/specification/v1.0.19/index.html#load-trusted-root
 	// 5.2 Load the trusted root metadata file. We assume that a good,
 	// trusted copy of this file was shipped with the package manager


Test patch:
diff --git a/client/client_test.go b/client/client_test.go
index 9ffb31f..253fe33 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -515,7 +515,7 @@ func (s *ClientSuite) TestFastForwardAttackRecovery(c *C) {
 	}
 	for _, test := range tests {
 		tufClient, closer := initRootTest(c, test.fixturePath)
-		c.Assert(tufClient.updateRoots(), IsNil)
+		c.Assert(tufClient.UpdateRoots(), IsNil)
 		m, err := tufClient.local.GetMeta()
 		c.Assert(err, IsNil)
 		for md, deleted := range test.expectMetaDeleted {