1- import { describe , expect , it , vi } from "vite-plus/test" ;
1+ import { describe , expect , it } from "vite-plus/test" ;
22
33import type { EnvironmentId , ThreadId } from "@t3tools/contracts" ;
44import type { RelayAgentActivityAggregateState } from "@t3tools/contracts/relay" ;
@@ -7,11 +7,6 @@ import {
77 AGENT_ACTIVITY_WIDGET_STALE_AFTER_MS ,
88 agentActivityWidgetTimeline ,
99} from "./agentActivityWidgetTimeline" ;
10- import { publishAgentActivityWidget } from "./publishAgentActivityWidget.ios" ;
11-
12- const nativeWidget = vi . hoisted ( ( ) => ( { getTimeline : vi . fn ( ) , updateTimeline : vi . fn ( ) } ) ) ;
13- vi . mock ( "expo" , ( ) => ( { requireOptionalNativeModule : ( ) => ( { } ) } ) ) ;
14- vi . mock ( "./AgentActivityWidget" , ( ) => ( { default : nativeWidget } ) ) ;
1510
1611const now = Date . parse ( "2026-10-18T10:00:00.000Z" ) ;
1712
@@ -42,104 +37,6 @@ function aggregate(activities: ReadonlyArray<Row>): RelayAgentActivityAggregateS
4237}
4338
4439describe ( "agentActivityWidgetTimeline" , ( ) => {
45- it ( "persists the snapshot owner and clears rows on sign-out" , async ( ) => {
46- nativeWidget . updateTimeline . mockClear ( ) ;
47- await publishAgentActivityWidget (
48- { kind : "snapshot" , aggregate : aggregate ( [ row ( "running" , "Working" ) ] ) } ,
49- "user-a" ,
50- ) ;
51- expect ( nativeWidget . updateTimeline ) . toHaveBeenLastCalledWith ( [
52- expect . objectContaining ( { props : expect . objectContaining ( { accountId : "user-a" } ) } ) ,
53- expect . objectContaining ( { props : expect . objectContaining ( { accountId : "user-a" } ) } ) ,
54- ] ) ;
55-
56- await publishAgentActivityWidget ( { kind : "signed-out" } , null ) ;
57- expect ( nativeWidget . updateTimeline ) . toHaveBeenLastCalledWith ( [
58- expect . objectContaining ( {
59- props : expect . objectContaining ( { activities : [ ] } ) ,
60- } ) ,
61- ] ) ;
62- expect ( nativeWidget . updateTimeline . mock . lastCall ?. [ 0 ] [ 0 ] . props ) . not . toHaveProperty ( "accountId" ) ;
63- } ) ;
64-
65- it ( "keeps sign-out last when an earlier cached timeline read is delayed" , async ( ) => {
66- let release = ( _entries : unknown [ ] ) => { } ;
67- let requested = ( ) => { } ;
68- const started = new Promise < void > ( ( resolve ) => {
69- requested = resolve ;
70- } ) ;
71- nativeWidget . getTimeline . mockImplementationOnce (
72- ( ) =>
73- new Promise ( ( resolve ) => {
74- release = resolve ;
75- requested ( ) ;
76- } ) ,
77- ) ;
78- nativeWidget . updateTimeline . mockClear ( ) ;
79-
80- const loading = publishAgentActivityWidget ( { kind : "loading" } , "user-a" ) ;
81- await started ;
82- const signOut = publishAgentActivityWidget ( { kind : "signed-out" } , null ) ;
83- release ( [ ] ) ;
84- await Promise . all ( [ loading , signOut ] ) ;
85-
86- expect ( nativeWidget . updateTimeline ) . toHaveBeenLastCalledWith ( [
87- expect . objectContaining ( {
88- props : expect . objectContaining ( {
89- subtitle : "Sign in to T3 Connect to see agents" ,
90- activities : [ ] ,
91- } ) ,
92- } ) ,
93- ] ) ;
94- } ) ;
95-
96- it ( "keeps persisted account rows and their stale deadline after a cold-start read failure" , async ( ) => {
97- const cached = agentActivityWidgetTimeline (
98- { kind : "snapshot" , aggregate : aggregate ( [ row ( "running" , "Working" ) ] ) } ,
99- now ,
100- ) . map ( ( entry ) => ( { ...entry , props : { ...entry . props , accountId : "user-a" } } ) ) ;
101- nativeWidget . getTimeline . mockResolvedValue ( cached ) ;
102- nativeWidget . updateTimeline . mockClear ( ) ;
103-
104- await publishAgentActivityWidget ( { kind : "loading" } , "user-a" ) ;
105- await publishAgentActivityWidget ( { kind : "unavailable" } , "user-a" ) ;
106-
107- expect ( nativeWidget . updateTimeline ) . not . toHaveBeenCalled ( ) ;
108- } ) ;
109-
110- it ( "replaces another account's persisted rows before its first relay read" , async ( ) => {
111- nativeWidget . getTimeline . mockResolvedValue (
112- agentActivityWidgetTimeline (
113- { kind : "snapshot" , aggregate : aggregate ( [ row ( "running" , "Working" ) ] ) } ,
114- now ,
115- ) . map ( ( entry ) => ( { ...entry , props : { ...entry . props , accountId : "user-a" } } ) ) ,
116- ) ;
117- nativeWidget . updateTimeline . mockClear ( ) ;
118-
119- await publishAgentActivityWidget ( { kind : "loading" } , "user-b" ) ;
120-
121- expect ( nativeWidget . updateTimeline ) . toHaveBeenLastCalledWith ( [
122- expect . objectContaining ( {
123- props : expect . objectContaining ( { subtitle : "Loading agents…" , activities : [ ] } ) ,
124- } ) ,
125- ] ) ;
126- } ) ;
127-
128- it ( "replaces persisted placeholders after a failed relay read" , async ( ) => {
129- nativeWidget . getTimeline . mockResolvedValue (
130- agentActivityWidgetTimeline ( { kind : "signed-out" } , now ) ,
131- ) ;
132- nativeWidget . updateTimeline . mockClear ( ) ;
133-
134- await publishAgentActivityWidget ( { kind : "unavailable" } , "user-a" ) ;
135-
136- expect ( nativeWidget . updateTimeline ) . toHaveBeenLastCalledWith ( [
137- expect . objectContaining ( {
138- props : expect . objectContaining ( { subtitle : "Couldn't reach T3 Connect" , activities : [ ] } ) ,
139- } ) ,
140- ] ) ;
141- } ) ;
142-
14340 it ( "marks unfinished rows out of date once the widget can no longer vouch for them" , ( ) => {
14441 const timeline = agentActivityWidgetTimeline (
14542 {
@@ -172,25 +69,4 @@ describe("agentActivityWidgetTimeline", () => {
17269 expect ( timeline ) . toHaveLength ( 1 ) ;
17370 expect ( timeline [ 0 ] ?. props . activities [ 0 ] ?. phase ) . toBe ( "failed" ) ;
17471 } ) ;
175-
176- it ( "says no agents are active when the relay has no activity" , ( ) => {
177- const [ entry ] = agentActivityWidgetTimeline ( { kind : "snapshot" , aggregate : null } , now ) ;
178-
179- expect ( entry ?. props ) . toMatchObject ( { subtitle : "No active agents" , activities : [ ] } ) ;
180- } ) ;
181-
182- it ( "asks the user to sign in instead of showing a previous account's agents" , ( ) => {
183- const [ entry ] = agentActivityWidgetTimeline ( { kind : "signed-out" } , now ) ;
184-
185- expect ( entry ?. props ) . toMatchObject ( {
186- subtitle : "Sign in to T3 Connect to see agents" ,
187- activities : [ ] ,
188- } ) ;
189- } ) ;
190-
191- it ( "says T3 Connect is unreachable instead of asking a signed-in user to sign in" , ( ) => {
192- const [ entry ] = agentActivityWidgetTimeline ( { kind : "unavailable" } , now ) ;
193-
194- expect ( entry ?. props ) . toMatchObject ( { subtitle : "Couldn't reach T3 Connect" , activities : [ ] } ) ;
195- } ) ;
19672} ) ;
0 commit comments