@@ -13,57 +13,51 @@ const secondRun = RunId.make("run-2");
1313const idle = (
1414 runId : RunId | null ,
1515 runStatus : ThreadActivitySnapshot [ "runStatus" ] ,
16- ) : ThreadActivitySnapshot => ( { status : "idle" , activity : null , runId, runStatus } ) ;
17- const working = ( activity : string | null , runId : RunId | null = secondRun ) =>
18- ( { status : "working" , activity, runId, runStatus : "running" } ) as const ;
16+ ) : ThreadActivitySnapshot => ( { status : "idle" , runId, runStatus } ) ;
17+ const busy = (
18+ status : Exclude < ThreadActivitySnapshot [ "status" ] , "idle" > = "working" ,
19+ runId : RunId | null = secondRun ,
20+ runStatus : ThreadActivitySnapshot [ "runStatus" ] = "running" ,
21+ ) : ThreadActivitySnapshot => ( { status, runId, runStatus } ) ;
1922
2023function speak ( snapshots : ReadonlyArray < ThreadActivitySnapshot > ) {
2124 let memory : ThreadAnnouncementMemory | null = null ;
2225 const spoken : string [ ] = [ ] ;
2326 for ( const snapshot of snapshots ) {
2427 const result = nextThreadAnnouncement ( memory , snapshot ) ;
2528 memory = result . memory ;
26- spoken . push ( ... result . announcements . map ( ( announcement ) => announcement . text ) ) ;
29+ if ( result . announcement !== null ) spoken . push ( result . announcement ) ;
2730 }
2831 return spoken ;
2932}
3033
3134describe ( "nextThreadAnnouncement" , ( ) => {
3235 it ( "follows a turn from start to finish" , ( ) => {
3336 expect (
34- speak ( [
35- idle ( firstRun , "completed" ) ,
36- working ( null , firstRun ) ,
37- working ( "Thinking" ) ,
38- working ( "Reading ChatView.tsx" ) ,
39- working ( "Reading ChatView.tsx" ) ,
40- working ( "Running vp" ) ,
41- idle ( secondRun , "completed" ) ,
42- ] ) ,
43- ) . toEqual ( [ "Working" , "Thinking" , "Reading ChatView.tsx" , "Running vp" , "Done" ] ) ;
37+ speak ( [ idle ( firstRun , "completed" ) , busy ( ) , busy ( ) , idle ( secondRun , "completed" ) ] ) ,
38+ ) . toEqual ( [ "Working" , "Done" ] ) ;
4439 } ) ;
4540
46- it ( "announces the label that is already live when a turn starts" , ( ) => {
47- expect ( speak ( [ idle ( firstRun , "completed" ) , working ( "Running vp" ) ] ) ) . toEqual ( [
48- "Working" ,
49- "Running vp" ,
50- ] ) ;
41+ it ( "says Working once when a send looks idle before its run appears" , ( ) => {
42+ expect (
43+ speak ( [ idle ( null , null ) , busy ( ) , idle ( null , null ) , busy ( ) , idle ( secondRun , "completed" ) ] ) ,
44+ ) . toEqual ( [ "Working" , "Done" ] ) ;
5145 } ) ;
5246
5347 it ( "stays silent when a thread opens mid-turn or after one" , ( ) => {
5448 expect ( speak ( [ idle ( firstRun , "completed" ) , idle ( firstRun , "completed" ) ] ) ) . toEqual ( [ ] ) ;
55- expect ( speak ( [ working ( "Running vp" ) , working ( "Running vp" ) ] ) ) . toEqual ( [ ] ) ;
49+ expect ( speak ( [ busy ( ) , busy ( ) ] ) ) . toEqual ( [ ] ) ;
5650 } ) ;
5751
5852 it ( "announces the end of a turn that was already running when the thread opened" , ( ) => {
59- expect ( speak ( [ working ( "Running vp" ) , idle ( secondRun , "failed" ) ] ) ) . toEqual ( [ "Failed" ] ) ;
53+ expect ( speak ( [ busy ( ) , idle ( secondRun , "failed" ) ] ) ) . toEqual ( [ "Failed" ] ) ;
6054 } ) ;
6155
6256 it ( "waits for the run to settle before announcing how the turn ended" , ( ) => {
6357 expect (
6458 speak ( [
6559 idle ( firstRun , "completed" ) ,
66- working ( null ) ,
60+ busy ( ) ,
6761 idle ( secondRun , "running" ) ,
6862 idle ( secondRun , "interrupted" ) ,
6963 ] ) ,
@@ -72,32 +66,33 @@ describe("nextThreadAnnouncement", () => {
7266
7367 it ( "does not report the previous turn's ending when work stops before a new run exists" , ( ) => {
7468 expect (
75- speak ( [ idle ( firstRun , "completed" ) , working ( null , firstRun ) , idle ( firstRun , "completed" ) ] ) ,
69+ speak ( [
70+ idle ( firstRun , "completed" ) ,
71+ busy ( "working" , firstRun , "completed" ) ,
72+ idle ( firstRun , "completed" ) ,
73+ ] ) ,
7674 ) . toEqual ( [ "Working" ] ) ;
7775 // The previous run finished while this client looked idle.
7876 expect (
7977 speak ( [
8078 idle ( firstRun , "completed" ) ,
8179 idle ( secondRun , "completed" ) ,
82- { ... working ( null ) , runStatus : "completed" } ,
80+ busy ( "working" , secondRun , "completed" ) ,
8381 idle ( secondRun , "completed" ) ,
8482 ] ) ,
8583 ) . toEqual ( [ "Working" ] ) ;
8684 } ) ;
8785
88- it ( "announces requests once and resumes activity after them" , ( ) => {
89- const approval = { ...working ( "Running vp" ) , status : "approval" } as const ;
90- const input = { ...working ( null ) , status : "input" } as const ;
86+ it ( "announces each request once without repeating that work resumed" , ( ) => {
9187 expect (
9288 speak ( [
93- working ( "Running vp" ) ,
94- approval ,
95- approval ,
96- working ( "Running vp" ) ,
97- working ( "Editing ChatView.tsx" ) ,
98- input ,
89+ busy ( ) ,
90+ busy ( "approval" ) ,
91+ busy ( "approval" ) ,
92+ busy ( ) ,
93+ busy ( "input" ) ,
9994 idle ( secondRun , "completed" ) ,
10095 ] ) ,
101- ) . toEqual ( [ "Needs approval" , "Editing ChatView.tsx" , " Needs your input", "Done" ] ) ;
96+ ) . toEqual ( [ "Needs approval" , "Needs your input" , "Done" ] ) ;
10297 } ) ;
10398} ) ;
0 commit comments