@@ -697,6 +697,105 @@ func TestDoltHubProvider_ListPendingWantedIDs_CompletionQueryFails_GracefulDegra
697697 }
698698}
699699
700+ func TestDoltHubProvider_ListPendingWantedIDs_StaleEntriesFiltered (t * testing.T ) {
701+ // Stale fork state should be filtered:
702+ // 1. status "open" = untouched item
703+ // 2. claimed_by someone other than PR author = inherited claim
704+ // Only intentional actions (claimed_by == author) pass through.
705+ mux := http .NewServeMux ()
706+ mux .HandleFunc ("/org/db/pulls" , func (w http.ResponseWriter , r * http.Request ) {
707+ if strings .Contains (r .URL .Path , "/pulls/" ) {
708+ return
709+ }
710+ w .Header ().Set ("Content-Type" , "application/json" )
711+ _ = json .NewEncoder (w ).Encode (map [string ]any {
712+ "pulls" : []map [string ]any {
713+ {"pull_id" : "1" , "state" : "open" },
714+ {"pull_id" : "2" , "state" : "open" },
715+ {"pull_id" : "3" , "state" : "open" },
716+ },
717+ })
718+ })
719+ mux .HandleFunc ("/org/db/pulls/1" , func (w http.ResponseWriter , _ * http.Request ) {
720+ w .Header ().Set ("Content-Type" , "application/json" )
721+ _ = json .NewEncoder (w ).Encode (map [string ]any {
722+ "from_branch" : "wl/register/stale-user" ,
723+ "from_branch_owner" : "stale-fork" ,
724+ "author" : "stale-user" ,
725+ })
726+ })
727+ mux .HandleFunc ("/org/db/pulls/2" , func (w http.ResponseWriter , _ * http.Request ) {
728+ w .Header ().Set ("Content-Type" , "application/json" )
729+ _ = json .NewEncoder (w ).Encode (map [string ]any {
730+ "from_branch" : "wl/bob/w-001" ,
731+ "from_branch_owner" : "bob-fork" ,
732+ "author" : "bob" ,
733+ })
734+ })
735+ mux .HandleFunc ("/org/db/pulls/3" , func (w http.ResponseWriter , _ * http.Request ) {
736+ w .Header ().Set ("Content-Type" , "application/json" )
737+ _ = json .NewEncoder (w ).Encode (map [string ]any {
738+ "from_branch" : "wl/register/charlie" ,
739+ "from_branch_owner" : "charlie-fork" ,
740+ "author" : "charlie" ,
741+ })
742+ })
743+ // stale-user: dolt_diff shows w-001 at "open" (stale untouched).
744+ mux .HandleFunc ("/stale-fork/db/" , func (w http.ResponseWriter , _ * http.Request ) {
745+ w .Header ().Set ("Content-Type" , "application/json" )
746+ _ = json .NewEncoder (w ).Encode (map [string ]any {
747+ "rows" : []map [string ]string {
748+ {"id" : "w-001" , "status" : "open" , "claimed_by" : "" , "diff_type" : "modified" },
749+ },
750+ })
751+ })
752+ // bob: dolt_diff shows w-001 at "claimed" by bob (intentional action).
753+ mux .HandleFunc ("/bob-fork/db/" , func (w http.ResponseWriter , _ * http.Request ) {
754+ w .Header ().Set ("Content-Type" , "application/json" )
755+ _ = json .NewEncoder (w ).Encode (map [string ]any {
756+ "rows" : []map [string ]string {
757+ {"id" : "w-001" , "status" : "claimed" , "claimed_by" : "bob" , "diff_type" : "modified" },
758+ },
759+ })
760+ })
761+ // charlie: dolt_diff shows w-001 at "claimed" by alice (inherited, not charlie's).
762+ mux .HandleFunc ("/charlie-fork/db/" , func (w http.ResponseWriter , _ * http.Request ) {
763+ w .Header ().Set ("Content-Type" , "application/json" )
764+ _ = json .NewEncoder (w ).Encode (map [string ]any {
765+ "rows" : []map [string ]string {
766+ {"id" : "w-001" , "status" : "claimed" , "claimed_by" : "alice" , "diff_type" : "modified" },
767+ },
768+ })
769+ })
770+
771+ server := httptest .NewServer (mux )
772+ defer server .Close ()
773+ dolthubAPIBase = server .URL
774+ dolthubRepoBase = server .URL + "/repositories"
775+
776+ provider := NewDoltHubProvider ("token" )
777+ ids , err := provider .ListPendingWantedIDs ("org" , "db" )
778+ if err != nil {
779+ t .Fatalf ("ListPendingWantedIDs() error: %v" , err )
780+ }
781+ // Only bob's "claimed" entry should appear:
782+ // - stale-user filtered (status "open")
783+ // - charlie filtered (claimed_by "alice" != author "charlie")
784+ if len (ids ) != 1 {
785+ t .Fatalf ("expected 1 pending ID (stale filtered), got %d: %v" , len (ids ), ids )
786+ }
787+ pending := ids ["w-001" ]
788+ if len (pending ) != 1 {
789+ t .Fatalf ("expected 1 entry for w-001, got %d" , len (pending ))
790+ }
791+ if pending [0 ].RigHandle != "bob" {
792+ t .Errorf ("expected rig_handle=bob, got %s" , pending [0 ].RigHandle )
793+ }
794+ if pending [0 ].Status != "claimed" {
795+ t .Errorf ("expected status=claimed, got %s" , pending [0 ].Status )
796+ }
797+ }
798+
700799func TestDoltHubProvider_ListPendingWantedIDs_NoDiffs (t * testing.T ) {
701800 mux := http .NewServeMux ()
702801 mux .HandleFunc ("/org/db/pulls" , func (w http.ResponseWriter , r * http.Request ) {
0 commit comments