@@ -765,6 +765,33 @@ describe('authorized live retrieval', () => {
765765 expect ( previewedIds ( ) ) . toEqual ( [ 'a' , 'd' , 'b' ] )
766766 } )
767767
768+ it ( 'reads no preview until a verification that spends the same request budget finishes' , async ( ) => {
769+ const googleDoc = 'application/vnd.google-apps.document'
770+ vi . mocked ( livePolicyFor ) . mockReturnValue ( {
771+ ...defaultLiveSearchPolicy ( ) ,
772+ fileTypes : [ googleDoc ] ,
773+ } )
774+ mocks . search . mockResolvedValue ( { documents : excerpts } )
775+ const pendingB = createDeferred < unknown > ( )
776+ mocks . json . mockReset ( ) . mockImplementation ( async ( path : string ) => {
777+ const id = path . split ( '/' ) . at ( - 1 )
778+ return id === 'b' ? pendingB . promise : { id, mimeType : googleDoc }
779+ } )
780+ mocks . preview . mockImplementation (
781+ async ( _provider , _client , { id } : { id : string } ) => `Full ${ id } launch text`
782+ )
783+ const pending = searchLiveKnowledge . execute ( { principal, input } )
784+ await vi . waitFor ( ( ) => expect ( mocks . json ) . toHaveBeenCalledTimes ( 4 ) )
785+ expect ( mocks . preview ) . not . toHaveBeenCalled ( )
786+ pendingB . resolve ( { id : 'b' , mimeType : googleDoc } )
787+ expect ( contents ( await pending ) ) . toEqual ( [
788+ 'Full a launch text' ,
789+ 'Full b launch text' ,
790+ 'Full c launch text' ,
791+ 'Excerpt d' ,
792+ ] )
793+ } )
794+
768795 it ( 'never surfaces the preview text of a candidate verification denies' , async ( ) => {
769796 mocks . search . mockResolvedValue ( { documents : excerpts } )
770797 mocks . service . mockResolvedValue ( {
@@ -1262,6 +1289,17 @@ describe('authorized live retrieval', () => {
12621289 await pending
12631290 } )
12641291
1292+ it ( 'times an account out at its deadline when its session never opens' , async ( ) => {
1293+ mocks . service . mockReturnValue ( new Promise ( ( ) => { } ) )
1294+ let result : Awaited < ReturnType < typeof searchLiveKnowledge . execute > > | undefined
1295+ void searchLiveKnowledge . execute ( { principal, input } ) . then ( ( value ) => {
1296+ result = value
1297+ } )
1298+ await vi . advanceTimersByTimeAsync ( 12_000 )
1299+ expect ( result ?. live ?. accounts [ 0 ] ?. status ) . toBe ( 'timeout' )
1300+ expect ( mocks . search ) . not . toHaveBeenCalled ( )
1301+ } )
1302+
12651303 it ( 'gives each account its own deadline from its slot, and skips one the search left no time' , async ( ) => {
12661304 mocks . accounts . mockResolvedValue ( accounts ( 13 ) )
12671305 mocks . resolveAccount . mockImplementation ( ( ) =>
0 commit comments