@@ -16,6 +16,8 @@ import {
1616 type PreviewAutomationStatus ,
1717} from "@t3tools/contracts" ;
1818import * as Effect from "effect/Effect" ;
19+ import * as Exit from "effect/Exit" ;
20+ import * as Scope from "effect/Scope" ;
1921import * as Fiber from "effect/Fiber" ;
2022import * as FileSystem from "effect/FileSystem" ;
2123import * as Layer from "effect/Layer" ;
@@ -614,8 +616,9 @@ it.live.each([
614616 Effect . scoped (
615617 Effect . gen ( function * ( ) {
616618 const { browser, broker, tabId } = yield * ready ;
619+ const reportProfiles = yield * browser . profileReporter ;
617620 for ( const recordingFrameRate of reports ) {
618- yield * browser . reportProfiles ( {
621+ yield * reportProfiles ( {
619622 profiles : [ ] ,
620623 defaultProfileId : "default" ,
621624 ...( recordingFrameRate === undefined ? { } : { recordingFrameRate } ) ,
@@ -1453,7 +1456,8 @@ it.live(
14531456 const broker = yield * Broker . PreviewAutomationBroker ;
14541457 const manager = yield * Manager . PreviewManager ;
14551458 yield * Effect . yieldNow ;
1456- yield * browser . reportProfiles ( {
1459+ const reportProfiles = yield * browser . profileReporter ;
1460+ yield * reportProfiles ( {
14571461 profiles : [ { id : "profile-work" , name : "Work" , kind : "persistent" } ] ,
14581462 defaultProfileId : "profile-work" ,
14591463 } ) ;
@@ -1498,3 +1502,46 @@ it.live(
14981502 } ) ,
14991503 ) . pipe ( Effect . provide ( layer ) ) ,
15001504) ;
1505+
1506+ it . live ( "profiles reported by one client survive another client's report" , ( ) =>
1507+ Effect . scoped (
1508+ Effect . gen ( function * ( ) {
1509+ const { browser, broker } = yield * ready ;
1510+ contextRequests . length = 0 ;
1511+ const work = { id : "profile-work" , name : "Work" , kind : "persistent" } as const ;
1512+ const shared = { id : "profile-shared" , name : "Shared" , kind : "persistent" } as const ;
1513+ const openWork = ( ) =>
1514+ broker . invoke < PreviewAutomationStatus > ( {
1515+ scope,
1516+ operation : "open" ,
1517+ input : { reuseExistingTab : false , show : false , profileId : work . id } ,
1518+ } ) ;
1519+ const reportFromA = yield * browser . profileReporter ;
1520+ const clientB = yield * Scope . make ( ) ;
1521+ const reportFromB = yield * browser . profileReporter . pipe (
1522+ Effect . provideService ( Scope . Scope , clientB ) ,
1523+ ) ;
1524+ yield * reportFromA ( { profiles : [ work , shared ] , defaultProfileId : work . id } ) ;
1525+ yield * reportFromB ( { profiles : [ shared ] , defaultProfileId : shared . id } ) ;
1526+ expect ( yield * openWork ( ) ) . toMatchObject ( {
1527+ defaultProfileId : shared . id ,
1528+ profiles : [
1529+ { id : "default" , name : "Default" } ,
1530+ { id : "incognito" , name : "Incognito" , incognito : true } ,
1531+ { id : work . id , name : work . name } ,
1532+ { id : shared . id , name : shared . name } ,
1533+ ] ,
1534+ } ) ;
1535+ expect ( contextRequests ) . toEqual ( [ { profileId : work . id , isolated : false } ] ) ;
1536+ yield * Scope . close ( clientB , Exit . void ) ;
1537+ expect ( yield * openWork ( ) ) . toMatchObject ( { defaultProfileId : work . id } ) ;
1538+ yield * reportFromA ( { profiles : [ shared ] , defaultProfileId : shared . id } ) ;
1539+ const removed = yield * openWork ( ) . pipe ( Effect . flip ) ;
1540+ expect ( removed ) . toMatchObject ( {
1541+ _tag : "PreviewAutomationExecutionError" ,
1542+ reason :
1543+ 'No browser profile is named "profile-work". Use one of: Default (id default), Incognito (id incognito), Shared (id profile-shared).' ,
1544+ } ) ;
1545+ } ) ,
1546+ ) . pipe ( Effect . provide ( layer ) ) ,
1547+ ) ;
0 commit comments