@@ -6,7 +6,12 @@ import { createRoot, type Root } from "react-dom/client";
66import { afterEach , beforeEach , expect , it , vi } from "vite-plus/test" ;
77
88const fixture = vi . hoisted ( ( ) => ( {
9- search : { state : "open" , involvement : "all" , sort : "updated" } ,
9+ search : {
10+ state : "open" ,
11+ involvement : "all" ,
12+ sort : "updated" ,
13+ environmentId : undefined as string | undefined ,
14+ } ,
1015 primaryConfigured : false ,
1116 remoteConfigured : true ,
1217 revision : 1 ,
@@ -54,6 +59,9 @@ vi.mock(import("../../state/environments"), async (original) => ({
5459} ) ) ;
5560vi . mock ( import ( "../../state/pullRequests" ) , async ( original ) => {
5661 const actual = await original ( ) ;
62+ const { AsyncResult } = await import ( "effect/reactivity" ) ;
63+ const Cause = await import ( "effect/Cause" ) ;
64+ const { PullRequestUnavailableError } = await import ( "@t3tools/contracts" ) ;
5765 const { mergePullRequestLists } = await import ( "./pullRequestList.logic" ) ;
5866 const cache = new Map < string , ReturnType < typeof actual . usePullRequestList > > ( ) ;
5967 const refresh = vi . fn ( ) ;
@@ -67,15 +75,33 @@ vi.mock(import("../../state/pullRequests"), async (original) => {
6775 const key = JSON . stringify ( [ fixture . revision , targets ] ) ;
6876 const cached = cache . get ( key ) ;
6977 if ( cached ) return cached ;
70- const values = targets . map ( ( { environmentId } ) => {
78+ const values : Array < readonly [ EnvironmentId , PullRequestListResult ] > = [ ] ;
79+ const observations : Array < readonly [ EnvironmentId , PullRequestListResult , number ] > = [ ] ;
80+ let error : string | null = null ;
81+ for ( const { environmentId } of targets ) {
7182 fixture . targets . add ( environmentId ) ;
72- return [ environmentId , answer ( environmentId ) ] as const ;
73- } ) ;
83+ const value = answer ( environmentId ) ;
84+ if ( value . providers [ 0 ] ! . configured ) {
85+ values . push ( [ environmentId , value ] ) ;
86+ observations . push ( [ environmentId , value , Date . now ( ) ] ) ;
87+ } else {
88+ const failure = new PullRequestUnavailableError ( {
89+ reason : "cli-unauthenticated" ,
90+ provider : "bitbucket" as never ,
91+ listResult : value ,
92+ } ) ;
93+ const observation = actual . observeFailedPullRequestList (
94+ AsyncResult . failure ( Cause . fail ( failure ) ) ,
95+ ) ! ;
96+ observations . push ( [ environmentId , observation . value , observation . observedAt ] ) ;
97+ error ??= failure . message ;
98+ }
99+ }
74100 const result = {
75101 data : mergePullRequestLists ( values ) ,
76- error : null ,
102+ error,
77103 isPending : false ,
78- observations : values . map ( ( [ id , value ] ) => [ id , value , fixture . revision ] as const ) ,
104+ observations,
79105 refresh,
80106 } ;
81107 cache . set ( key , result ) ;
@@ -116,7 +142,6 @@ function answer(environmentId: EnvironmentId): PullRequestListResult {
116142 kind : "bitbucket" as never ,
117143 searchesOnHost : false ,
118144 projectCount : 1 ,
119- projectIds : [ projectId ] ,
120145 configured,
121146 detail : configured ? null : "Bitbucket rejected the configured credentials." ,
122147 } ,
@@ -162,6 +187,8 @@ await View.preload?.();
162187
163188beforeEach ( ( ) => {
164189 vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
190+ fixture . search . environmentId = undefined ;
191+ vi . spyOn ( Date , "now" ) . mockImplementation ( ( ) => fixture . revision * 1000 ) ;
165192 fixture . primaryConfigured = false ;
166193 fixture . remoteConfigured = true ;
167194 fixture . revision ++ ;
@@ -175,6 +202,7 @@ beforeEach(() => {
175202afterEach ( async ( ) => {
176203 await act ( async ( ) => root . unmount ( ) ) ;
177204 container . remove ( ) ;
205+ vi . restoreAllMocks ( ) ;
178206} ) ;
179207
180208it ( "shows the shared repository from the server that can read it" , async ( ) => {
@@ -187,6 +215,7 @@ it("shows the shared repository from the server that can read it", async () => {
187215it ( "stops falling back when neither server can read the host" , async ( ) => {
188216 fixture . remoteConfigured = false ;
189217 await act ( async ( ) => root . render ( < View /> ) ) ;
218+ expect ( container . textContent ) . toContain ( "Bitbucket rejected" ) ;
190219 expect ( container . textContent ) . not . toContain ( "Handle reconnects without dropping pending work" ) ;
191220 expect ( [ ...fixture . targets ] ) . toEqual ( [ "env-1" , "env-2" ] ) ;
192221} ) ;
@@ -204,3 +233,11 @@ it("retries the preferred server on refresh after its credentials are fixed", as
204233 expect ( container . textContent ) . toContain ( "Local server" ) ;
205234 expect ( container . textContent ) . not . toContain ( "Remote server" ) ;
206235} ) ;
236+
237+ it ( "keeps the setup error visible when a failing server is explicitly selected" , async ( ) => {
238+ fixture . search . environmentId = "env-1" ;
239+ await act ( async ( ) => root . render ( < View /> ) ) ;
240+ expect ( container . textContent ) . toContain ( "Bitbucket rejected" ) ;
241+ expect ( container . textContent ) . not . toContain ( "No pull requests" ) ;
242+ expect ( [ ...fixture . targets ] ) . toEqual ( [ "env-1" ] ) ;
243+ } ) ;
0 commit comments