1- import type {
2- ConversationEntity ,
3- InboxPlanningOutput ,
4- PendingWriteOperation ,
5- RoutedTurn ,
6- TurnInterpretationType ,
7- TurnPolicyAction ,
1+ import {
2+ buildCapturedTask ,
3+ type ConversationEntity ,
4+ type InboxPlanningOutput ,
5+ type PendingWriteOperation ,
6+ type RoutedTurn ,
7+ type TurnInterpretationType ,
8+ type TurnPolicyAction ,
89} from "@atlas/core" ;
910
1011import {
@@ -1030,6 +1031,20 @@ describe("telegram webhook route", () => {
10301031 buildRoutedTurn ( {
10311032 turnType : "planning_request" ,
10321033 action : "execute_mutation" ,
1034+ resolvedOperation : {
1035+ operationKind : "plan" ,
1036+ targetRef : null ,
1037+ resolvedFields : {
1038+ scheduleFields : {
1039+ time : { kind : "absolute" as const , hour : 14 , minute : 0 } ,
1040+ day : "tomorrow" ,
1041+ duration : 30 ,
1042+ } ,
1043+ } ,
1044+ missingFields : [ ] ,
1045+ originatingText : "Review launch checklist" ,
1046+ startedAt : new Date ( ) . toISOString ( ) ,
1047+ } ,
10331048 } ) ,
10341049 } ,
10351050 ) ;
@@ -1039,14 +1054,13 @@ describe("telegram webhook route", () => {
10391054 accepted : true ,
10401055 turnRoute : "mutation" ,
10411056 processing : {
1042- outcome : "planned " ,
1057+ outcome : "created " ,
10431058 } ,
10441059 outboundDelivery : {
10451060 status : "edited" ,
10461061 attempts : 1 ,
10471062 } ,
10481063 } ) ;
1049- expect ( listPlannerRunsForTests ( ) ) . toHaveLength ( 1 ) ;
10501064 expect ( listTasksForTests ( ) ) . toHaveLength ( 1 ) ;
10511065 expect ( listScheduleBlocksForTests ( ) ) . toHaveLength ( 1 ) ;
10521066 expect ( sendTelegramMessageMock ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -1116,7 +1130,7 @@ describe("telegram webhook route", () => {
11161130 } ,
11171131 } ,
11181132 processing : {
1119- outcome : "planned " ,
1133+ outcome : "created " ,
11201134 } ,
11211135 } ) ;
11221136 expect ( sendTelegramMessageMock ) . toHaveBeenCalledWith ( {
@@ -1220,29 +1234,21 @@ describe("telegram webhook route", () => {
12201234 accepted : true ,
12211235 turnRoute : "mutation" ,
12221236 processing : {
1223- outcome : "planned " ,
1237+ outcome : "created " ,
12241238 } ,
12251239 } ) ;
1226- expect ( planner ) . toHaveBeenCalledWith (
1227- expect . objectContaining ( {
1228- inboxItem : expect . objectContaining ( {
1229- rawText : "Schedule the dentist reminder at 3pm" ,
1230- normalizedText : "Schedule the dentist reminder at 3pm" ,
1231- } ) ,
1232- } ) ,
1233- ) ;
1234- expect ( listPlannerRunsForTests ( ) ) . toHaveLength ( 1 ) ;
1240+ expect ( planner ) . not . toHaveBeenCalled ( ) ;
12351241 expect ( listTasksForTests ( ) ) . toHaveLength ( 1 ) ;
12361242 expect ( sendTelegramMessageMock ) . toHaveBeenCalledTimes ( 1 ) ;
12371243 expect ( sendTelegramMessageMock ) . toHaveBeenCalledWith ( {
12381244 chatId : "999" ,
1239- text : "Applying that " ,
1245+ text : "Checking your schedule " ,
12401246 } ) ;
12411247 expect ( editTelegramMessageMock ) . toHaveBeenCalledWith (
12421248 expect . objectContaining ( {
12431249 chatId : "999" ,
12441250 messageId : 88 ,
1245- text : expect . stringContaining ( "Scheduled 'Dentist reminder' " ) ,
1251+ text : expect . stringContaining ( "Scheduled '" ) ,
12461252 } ) ,
12471253 ) ;
12481254 } ) ;
@@ -1379,61 +1385,37 @@ describe("telegram webhook route", () => {
13791385 it ( "completes a recent task from a confirmed mutation recovery turn" , async ( ) => {
13801386 process . env . TELEGRAM_WEBHOOK_SECRET = "test-webhook-secret" ;
13811387
1382- await handleTelegramWebhook (
1383- buildRequest ( {
1384- update_id : 56 ,
1385- message : {
1386- message_id : 21 ,
1387- date : 1_700_000_014 ,
1388- text : "Journaling session" ,
1389- chat : {
1390- id : 999 ,
1391- type : "private" ,
1392- } ,
1393- from : {
1394- id : 123 ,
1395- is_bot : false ,
1396- first_name : "Max" ,
1397- last_name : "Lin" ,
1398- } ,
1388+ // Seed the task directly instead of relying on the old planner flow
1389+ const store = getDefaultInboxProcessingStore ( ) ;
1390+ seedInboxItemForProcessingTests ( {
1391+ id : "inbox-seed-journal" ,
1392+ userId : "123" ,
1393+ sourceEventId : "event-seed-journal" ,
1394+ rawText : "Journaling session" ,
1395+ normalizedText : "Journaling session" ,
1396+ processingStatus : "received" ,
1397+ linkedTaskIds : [ ] ,
1398+ } ) ;
1399+ await store . saveTaskCaptureResult ( {
1400+ inboxItemId : "inbox-seed-journal" ,
1401+ confidence : 1 ,
1402+ tasks : [
1403+ {
1404+ alias : "new_task_1" ,
1405+ task : buildCapturedTask ( {
1406+ userId : "123" ,
1407+ inboxItemId : "inbox-seed-journal" ,
1408+ title : "Journaling session" ,
1409+ priority : "medium" ,
1410+ urgency : "medium" ,
1411+ } ) ,
13991412 } ,
1400- } ) ,
1401- {
1402- store : getDefaultInboxProcessingStore ( ) ,
1403- calendar : getDefaultCalendarAdapter ( ) ,
1404- primeProcessingStore : seedInboxItemForProcessingTests ,
1405- planner : async ( ) : Promise < InboxPlanningOutput > => ( {
1406- confidence : 0.9 ,
1407- summary : "Scheduled Journaling session." ,
1408- actions : [
1409- {
1410- type : "create_task" ,
1411- alias : "new_task_1" ,
1412- title : "Journaling session" ,
1413- priority : "medium" ,
1414- urgency : "medium" ,
1415- } ,
1416- {
1417- type : "create_schedule_block" ,
1418- taskRef : {
1419- kind : "created_task" ,
1420- alias : "new_task_1" ,
1421- } ,
1422- scheduleConstraint : {
1423- dayReference : null ,
1424- weekday : null ,
1425- weekOffset : null ,
1426- explicitHour : 9 ,
1427- minute : 0 ,
1428- preferredWindow : null ,
1429- sourceText : "default next slot" ,
1430- } ,
1431- reason : "Schedule the new task in the next slot." ,
1432- } ,
1433- ] ,
1434- } ) ,
1435- } ,
1436- ) ;
1413+ ] ,
1414+ scheduleBlocks : [ ] ,
1415+ followUpMessage : "Captured Journaling session." ,
1416+ } ) ;
1417+
1418+ const seededTaskId = listTasksForTests ( ) [ 0 ] ! . id ;
14371419 sendTelegramMessageMock . mockClear ( ) ;
14381420 editTelegramMessageMock . mockClear ( ) ;
14391421
@@ -1462,31 +1444,17 @@ describe("telegram webhook route", () => {
14621444 } ,
14631445 } ) ,
14641446 {
1465- store : getDefaultInboxProcessingStore ( ) ,
1447+ store,
14661448 calendar : getDefaultCalendarAdapter ( ) ,
14671449 primeProcessingStore : seedInboxItemForProcessingTests ,
1468- planner : async ( ) : Promise < InboxPlanningOutput > => ( {
1469- confidence : 0.92 ,
1470- summary : "Marked the journaling session as done." ,
1471- actions : [
1472- {
1473- type : "complete_task" ,
1474- taskRef : {
1475- kind : "existing_task" ,
1476- alias : "existing_task_1" ,
1477- } ,
1478- reason : "The user said the journaling session is done." ,
1479- } ,
1480- ] ,
1481- } ) ,
14821450 turnRouter : async ( ) =>
14831451 buildRoutedTurn ( {
14841452 turnType : "confirmation" ,
14851453 action : "execute_mutation" ,
14861454 resolvedProposalId : "proposal-1" ,
14871455 resolvedOperation : {
14881456 operationKind : "complete" ,
1489- targetRef : { entityId : undefined , description : "Journaling session" , entityKind : undefined } ,
1457+ targetRef : { entityId : seededTaskId , description : "Journaling session" } ,
14901458 resolvedFields : { } ,
14911459 missingFields : [ ] ,
14921460 originatingText : "Mark journaling as done" ,
@@ -2177,7 +2145,7 @@ describe("telegram webhook route", () => {
21772145 expect ( response . body ) . toMatchObject ( {
21782146 accepted : true ,
21792147 processing : {
2180- outcome : "planned " ,
2148+ outcome : "created " ,
21812149 } ,
21822150 outboundDelivery : {
21832151 status : "failed" ,
0 commit comments