@@ -20,12 +20,15 @@ import {
2020 clearAgentAwarenessRegistrationRecord ,
2121 loadAgentAwarenessRegistrationRecord ,
2222 loadOrCreateAgentAwarenessDeviceId ,
23+ loadPreferences ,
2324 saveAgentAwarenessRegistrationRecord ,
2425} from "../../persistence/imperative" ;
26+ import type { Preferences } from "../../persistence/mobile-preferences" ;
2527import { makeRelayDeviceRegistrationRequest , resolveApsEnvironment } from "./registrationPayload" ;
2628import {
2729 AgentAwarenessOperationError ,
2830 __resetAgentAwarenessRemoteRegistrationForTest ,
31+ armAgentAwarenessLiveActivityForLocalWork ,
2932 getAgentAwarenessRegistrationStatus ,
3033 mergeAgentAwarenessRegistrationPreferences ,
3134 refreshActiveLiveActivityRemoteRegistration ,
@@ -43,6 +46,13 @@ import * as Notifications from "expo-notifications";
4346const secureStore = vi . hoisted ( ( ) => new Map < string , string > ( ) ) ;
4447const widgetMocks = vi . hoisted ( ( ) => ( {
4548 getInstances : vi . fn ( ( ) => [ ] ) ,
49+ start : vi . fn ( ( ) => ( { } ) ) ,
50+ } ) ) ;
51+ const environmentConfigsMock = vi . hoisted ( ( ) => ( {
52+ configs : new Map <
53+ string ,
54+ { environment : { capabilities : { agentActivityPublishing ?: boolean } } }
55+ > ( ) ,
4656} ) ) ;
4757const backgroundRuntime = vi . hoisted ( ( ) => ( {
4858 pending : [ ] as Array < {
@@ -77,9 +87,22 @@ vi.mock("expo-widgets", () => ({
7787vi . mock ( "../../widgets/AgentActivity" , ( ) => ( {
7888 default : {
7989 getInstances : widgetMocks . getInstances ,
90+ start : widgetMocks . start ,
8091 } ,
8192} ) ) ;
8293
94+ // The state modules pull the whole connection stack (and native expo modules)
95+ // into the import graph; the arming gate only needs the configs map.
96+ vi . mock ( "../../state/atom-registry" , ( ) => ( {
97+ appAtomRegistry : {
98+ get : ( ) => environmentConfigsMock . configs ,
99+ } ,
100+ } ) ) ;
101+
102+ vi . mock ( "../../state/server" , ( ) => ( {
103+ environmentServerConfigsAtom : Symbol ( "environmentServerConfigsAtom" ) ,
104+ } ) ) ;
105+
83106vi . mock ( "expo-notifications" , ( ) => ( {
84107 addPushTokenListener : vi . fn ( ( ) => ( { remove : vi . fn ( ) } ) ) ,
85108 getDevicePushTokenAsync : vi . fn ( ( ) => Promise . resolve ( { type : "ios" , data : "apns-token" } ) ) ,
@@ -227,6 +250,8 @@ describe("makeRelayDeviceRegistrationRequest", () => {
227250 vi . mocked ( loadOrCreateAgentAwarenessDeviceId ) . mockResolvedValue ( "device-1" ) ;
228251 widgetMocks . getInstances . mockReset ( ) ;
229252 widgetMocks . getInstances . mockReturnValue ( [ ] ) ;
253+ widgetMocks . start . mockClear ( ) ;
254+ environmentConfigsMock . configs . clear ( ) ;
230255 } ) ;
231256
232257 it ( "preserves disabled Live Activity preferences in relay registrations" , ( ) => {
@@ -856,4 +881,55 @@ describe("makeRelayDeviceRegistrationRequest", () => {
856881 } ) . pipe ( Effect . provide ( relayTestLayer ) ) ;
857882 } ,
858883 ) ;
884+
885+ it ( "skips the Live Activity seed when the environment reports publishing disabled" , async ( ) => {
886+ setAgentAwarenessRelayTokenProvider ( ( ) => Promise . resolve ( "clerk-token-user-a" ) ) ;
887+ vi . mocked ( loadPreferences ) . mockResolvedValueOnce ( {
888+ liveActivitiesEnabled : true ,
889+ } as Preferences ) ;
890+ environmentConfigsMock . configs . set ( "env-1" , {
891+ environment : { capabilities : { agentActivityPublishing : false } } ,
892+ } ) ;
893+
894+ armAgentAwarenessLiveActivityForLocalWork ( {
895+ environmentId : "env-1" as EnvironmentId ,
896+ threadTitle : "Fix the flaky test" ,
897+ projectTitle : "t3code" ,
898+ } ) ;
899+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
900+
901+ expect ( widgetMocks . start ) . not . toHaveBeenCalled ( ) ;
902+ } ) ;
903+
904+ it ( "seeds the Live Activity for publishing and pre-capability environments" , async ( ) => {
905+ setAgentAwarenessRelayTokenProvider ( ( ) => Promise . resolve ( "clerk-token-user-a" ) ) ;
906+ environmentConfigsMock . configs . set ( "env-publishing" , {
907+ environment : { capabilities : { agentActivityPublishing : true } } ,
908+ } ) ;
909+
910+ vi . mocked ( loadPreferences ) . mockResolvedValueOnce ( {
911+ liveActivitiesEnabled : true ,
912+ } as Preferences ) ;
913+ armAgentAwarenessLiveActivityForLocalWork ( {
914+ environmentId : "env-publishing" as EnvironmentId ,
915+ threadTitle : "Fix the flaky test" ,
916+ projectTitle : "t3code" ,
917+ } ) ;
918+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
919+ expect ( widgetMocks . start ) . toHaveBeenCalledTimes ( 1 ) ;
920+
921+ // An environment without the capability may run an older server that
922+ // still publishes; only an explicit false skips the seed.
923+ widgetMocks . start . mockClear ( ) ;
924+ vi . mocked ( loadPreferences ) . mockResolvedValueOnce ( {
925+ liveActivitiesEnabled : true ,
926+ } as Preferences ) ;
927+ armAgentAwarenessLiveActivityForLocalWork ( {
928+ environmentId : "env-pre-capability" as EnvironmentId ,
929+ threadTitle : "Fix the flaky test" ,
930+ projectTitle : "t3code" ,
931+ } ) ;
932+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
933+ expect ( widgetMocks . start ) . toHaveBeenCalledTimes ( 1 ) ;
934+ } ) ;
859935} ) ;
0 commit comments