@@ -921,10 +921,16 @@ describe("explicit last-human hangup", () => {
921921 type : "participants" ,
922922 participants : [ destination . viewer , destination . viewer , botKey . pubkey ] ,
923923 } ) ;
924- if ( reason === "another human" )
925- h . snapshotRead . mockResolvedValue (
926- records ( [ [ "p" , keypair ( ) . pubkey , "" , "member" ] ] ) ,
927- ) ;
924+ if ( reason === "another human" ) {
925+ const human = keypair ( ) . pubkey ;
926+ h . snapshotRead
927+ . mockResolvedValueOnce ( records ( [ [ "p" , human , "" , "member" ] ] ) )
928+ . mockResolvedValue ( [ ] ) ;
929+ h . receive ( {
930+ type : "participants" ,
931+ participants : [ destination . viewer , botKey . pubkey , human ] ,
932+ } ) ;
933+ }
928934 if ( reason === "unknown peer" )
929935 h . receive ( {
930936 type : "participants" ,
@@ -948,6 +954,70 @@ describe("explicit last-human hangup", () => {
948954 expect ( h . archive ) . not . toHaveBeenCalled ( ) ;
949955 await h . dispose ( ) ;
950956 } ) ;
957+
958+ it . each ( [
959+ "departed human" ,
960+ "legacy agent" ,
961+ "untrusted claim" ,
962+ "failed lookup" ,
963+ ] ) (
964+ "classifies audio attendance while retaining history: %s" ,
965+ async ( scenario ) => {
966+ const h = await connected ( ) ;
967+ const other = keypair ( ) ;
968+ const base = records ( [ [ "p" , other . pubkey , "" , "member" ] ] ) ;
969+ h . snapshotRead . mockResolvedValueOnce ( base ) ;
970+ // Both identities remain members. Only a live audio seat affects hangup.
971+ h . receive ( {
972+ type : "participants" ,
973+ participants : [ destination . viewer , botKey . pubkey , other . pubkey ] ,
974+ } ) ;
975+ if ( scenario === "departed human" )
976+ h . receive ( {
977+ type : "participants" ,
978+ participants : [ destination . viewer , botKey . pubkey ] ,
979+ } ) ;
980+ else if ( scenario === "failed lookup" )
981+ h . snapshotRead . mockRejectedValueOnce (
982+ new Error ( "Agent lookup unavailable" ) ,
983+ ) ;
984+ else
985+ h . snapshotRead . mockResolvedValueOnce ( [
986+ signed ( scenario === "legacy agent" ? viewerKey : other , {
987+ kind : 30177 ,
988+ content : "{}" ,
989+ tags : [ [ "d" , other . pubkey ] ] ,
990+ } ) ,
991+ ] ) ;
992+ await h . service . leave ( ) ;
993+ const ended =
994+ scenario === "departed human" || scenario === "legacy agent" ;
995+ expect ( h . publish ) . toHaveBeenCalledTimes ( ended ? 1 : 0 ) ;
996+ expect ( h . archive ) . toHaveBeenCalledTimes ( ended ? 1 : 0 ) ;
997+ if ( ended )
998+ expect ( h . archive ) . toHaveBeenCalledWith (
999+ "archive" ,
1000+ room ,
1001+ expect . any ( AbortSignal ) ,
1002+ expect . any ( Function ) ,
1003+ ) ;
1004+ if ( scenario !== "departed human" )
1005+ expect ( h . snapshotRead ) . toHaveBeenNthCalledWith (
1006+ 2 ,
1007+ [
1008+ {
1009+ kinds : [ 30177 ] ,
1010+ authors : [ destination . viewer ] ,
1011+ "#d" : [ other . pubkey ] ,
1012+ limit : 1 ,
1013+ consistency : "strong" ,
1014+ } ,
1015+ ] ,
1016+ { signal : expect . any ( AbortSignal ) } ,
1017+ ) ;
1018+ await h . dispose ( ) ;
1019+ } ,
1020+ ) ;
9511021 it ( "does not end after switching communities during the fresh read" , async ( ) => {
9521022 const h = await connected ( ) ;
9531023 const gate = deferred < ReturnType < typeof records > > ( ) ;
0 commit comments