+func TestWhatsAppImportCutoffUsesEachChatAndBothLogs(t *testing.T) {
+ path := whatsappImportZip(t, "Plans", "[03/01/2025, 09:59:59] Ada: Before\n[03/01/2025, 10:00:00] Ada: Boundary\n[03/01/2025, 10:01:00] Ada: After\n")
+ target := []DatedMessage{{
+ Kind: "work",
+ Text: "[WhatsApp] Plans, group example@g.us, Friday 2025-01-03\n10:00 Ada: Target first\n10:30 Ada: Target last",
+ Date: "2025-01-03T10:30:00Z",
+ }}
+
+ root := []DatedMessage{
+ {
+ Kind: "work",
+ Text: "[WhatsApp] Other, group other@g.us, Wednesday 2025-01-01\n08:00 Bea: Other chat",
+ Date: "2025-01-01T08:00:00Z",
+ },
+ {
+ Kind: "work",
+ Text: "[WhatsApp] Plans, group example@g.us, Saturday 2025-01-04\n10:00 Ada: Later batch",
+ Date: "2025-01-04T10:00:00Z",
+ },
+ }
+
+ testCases := []struct {
+ name string
+ target []DatedMessage
+ root []DatedMessage
+ }{
+ {
+ name: "target holds the first live batch",
+ target: target,
+ root: root,
+ },
+ {
+ name: "root holds the first live batch",
+ target: root,
+ root: target,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ plan, err := whatsappImportPlan(t.Context(), []string{path}, tc.target, tc.root, nil, "", time.UTC)
+ require.NoError(t, err)
+ require.Equal(t, "2025-01-03T10:00:00Z", plan.cutoff.Format(time.RFC3339))
+ require.Len(t, plan.added, 1)
+ require.Contains(t, plan.added[0].Text, "Before")
+ require.NotContains(t, plan.added[0].Text, "Boundary")
+ require.NotContains(t, plan.added[0].Text, "After")
+ })
+ }
+}
+