Skip to content

Commit 31eb434

Browse files
committed
Merge branch 'main' into production
2 parents 3f4a492 + 0240beb commit 31eb434

8 files changed

Lines changed: 1356 additions & 212 deletions

File tree

internal/api/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import (
55
"github.com/gastownhall/wasteland/internal/sdk"
66
)
77

8+
func allowsPendingSubmissionState(status string) bool {
9+
switch status {
10+
case "open", "claimed", "in_review":
11+
return true
12+
default:
13+
return false
14+
}
15+
}
16+
817
// --- Response types ---
918

1019
// PendingItemJSON is a summary of a pending upstream PR for browse list hover cards.
@@ -370,6 +379,9 @@ func toDetailResponse(d *sdk.DetailResult, mode string) *DetailResponse {
370379
}
371380

372381
itemJSON := toWantedItemJSON(d.Item)
382+
if itemJSON != nil && !allowsPendingSubmissionState(itemJSON.Status) {
383+
upstreamPRs = nil
384+
}
373385
// If there are competing upstream submissions, overlay claimed_by to
374386
// reflect the full set of candidates (main claimer + upstream PRs).
375387
if itemJSON != nil && len(upstreamPRs) > 0 {

internal/api/types_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package api
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gastownhall/wasteland/internal/commons"
7+
"github.com/gastownhall/wasteland/internal/sdk"
8+
)
9+
10+
func TestToDetailResponse_SuppressesTerminalUpstreamSubmissions(t *testing.T) {
11+
resp := toDetailResponse(&sdk.DetailResult{
12+
Item: &commons.WantedItem{
13+
ID: "w-1",
14+
Title: "Done task",
15+
Status: "completed",
16+
ClaimedBy: "winner",
17+
},
18+
UpstreamPRs: []sdk.PendingItem{{
19+
RigHandle: "charlie",
20+
Status: "in_review",
21+
ClaimedBy: "charlie",
22+
PRURL: "https://example.com/pr/1",
23+
}},
24+
}, "pr")
25+
26+
if resp == nil {
27+
t.Fatal("expected response")
28+
}
29+
if len(resp.UpstreamPRs) != 0 {
30+
t.Fatalf("upstream PRs = %+v, want none for completed item", resp.UpstreamPRs)
31+
}
32+
if resp.Item == nil || resp.Item.ClaimedBy != "winner" {
33+
t.Fatalf("item = %+v, want completed winner preserved", resp.Item)
34+
}
35+
}
36+
37+
func TestToDetailResponse_PreservesActiveUpstreamSubmissions(t *testing.T) {
38+
resp := toDetailResponse(&sdk.DetailResult{
39+
Item: &commons.WantedItem{
40+
ID: "w-1",
41+
Title: "Open task",
42+
Status: "open",
43+
ClaimedBy: "alice",
44+
},
45+
UpstreamPRs: []sdk.PendingItem{{
46+
RigHandle: "charlie",
47+
Status: "in_review",
48+
ClaimedBy: "charlie",
49+
PRURL: "https://example.com/pr/1",
50+
}},
51+
}, "pr")
52+
53+
if resp == nil {
54+
t.Fatal("expected response")
55+
}
56+
if len(resp.UpstreamPRs) != 1 {
57+
t.Fatalf("upstream PRs = %+v, want 1 active submission", resp.UpstreamPRs)
58+
}
59+
if resp.Item == nil || resp.Item.ClaimedBy != "Multiple (pending)" {
60+
t.Fatalf("item = %+v, want pending overlay for active item", resp.Item)
61+
}
62+
}

internal/hosted/authservice_resolver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func (wr *AuthServiceWorkspaceResolver) buildClient(
259259

260260
db := backend.NewRemoteDBWithClient(proxyClient, upOrg, upDB, wl.ForkOrg, wl.ForkDB, mode)
261261
provider := remote.NewDoltHubProviderWithClient(proxyClient)
262+
pendingCache := wr.getOrCreatePendingCache(session.ConnectionID, provider, upOrg, upDB)
262263

263264
branchURL := func(branch string) string {
264265
return fmt.Sprintf("https://www.dolthub.com/repositories/%s/%s/data/%s",
@@ -322,9 +323,9 @@ func (wr *AuthServiceWorkspaceResolver) buildClient(
322323
}
323324
return provider.ClosePR(upOrg, upDB, prID)
324325
},
325-
ListPendingItems: wr.getOrCreatePendingCache(session.ConnectionID, provider, upOrg, upDB).Get,
326+
ListPendingItems: pendingCache.Get,
326327
ListPendingItemsContext: func(ctx context.Context) (map[string][]sdk.PendingItem, error) {
327-
return wr.getOrCreatePendingCache(session.ConnectionID, provider, upOrg, upDB).GetContext(ctx)
328+
return pendingCache.GetContext(ctx)
328329
},
329330
BranchURL: branchURL,
330331
Signing: wl.Signing,

internal/hosted/authservice_resolver_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package hosted
22

33
import (
4+
"context"
5+
"net/http"
46
"testing"
57
"time"
8+
9+
"github.com/gastownhall/wasteland/internal/dolthubauth"
610
)
711

12+
type roundTripFunc func(*http.Request) (*http.Response, error)
13+
14+
func (fn roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
15+
return fn(req)
16+
}
17+
818
func TestAuthServiceWorkspaceResolver_InvalidateConnectionClearsPendingCaches(t *testing.T) {
919
resolver := NewAuthServiceWorkspaceResolver(nil, NewSessionStore())
1020
cache1 := newPendingUpstreamCache(nil, "hop", "wl-commons", time.Hour)
@@ -24,3 +34,37 @@ func TestAuthServiceWorkspaceResolver_InvalidateConnectionClearsPendingCaches(t
2434
t.Fatal("expected unrelated pending cache to remain")
2535
}
2636
}
37+
38+
func TestAuthServiceWorkspaceResolver_BuildClientWarmsPendingCache(t *testing.T) {
39+
resolver := NewAuthServiceWorkspaceResolver(nil, NewSessionStore())
40+
session := &UserSession{
41+
SubjectID: "subject-1",
42+
ConnectionID: "conn-1",
43+
}
44+
conn := &dolthubauth.ConnectionResponse{
45+
ConnectionID: "conn-1",
46+
SubjectID: "subject-1",
47+
RigHandle: "alice",
48+
}
49+
wl := dolthubauth.WastelandConfig{
50+
Upstream: "hop/wl-commons",
51+
ForkOrg: "alice",
52+
ForkDB: "wl-commons",
53+
Mode: "pr",
54+
}
55+
56+
client := &http.Client{Transport: roundTripFunc(func(*http.Request) (*http.Response, error) {
57+
return nil, context.Canceled
58+
})}
59+
60+
if _, err := resolver.buildClient(session, conn, client, wl); err != nil {
61+
t.Fatalf("buildClient() error = %v", err)
62+
}
63+
64+
key := "conn-1:hop/wl-commons"
65+
cache, ok := resolver.pendingCache[key]
66+
if !ok {
67+
t.Fatalf("expected pending cache %q to be created during build", key)
68+
}
69+
cache.Stop()
70+
}

0 commit comments

Comments
 (0)