X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/0e57dcfc96cd95268d5dd00af7ce0594721d3ded..6c7859cfea123479aba046614ee81028651ddaf5:/whatsapp_import_test.go?ds=inline diff --git a/whatsapp_import_test.go b/whatsapp_import_test.go index 1f9c9af..eed22fd 100644 --- a/whatsapp_import_test.go +++ b/whatsapp_import_test.go @@ -486,6 +486,7 @@ func TestWhatsAppImportChildPlanReadsRootCutoffButNotRootImportedDays(t *testing Date: "2025-01-03T10:20:00Z", }, }) + rebuildTestLog(t, childDir, []DatedMessage{ { Kind: "work", @@ -529,6 +530,7 @@ func TestWhatsAppImportChildRebuildUsesOwnPromptAndCache(t *testing.T) { Text: "Keep the root history.", Date: "2025-02-01T00:00:00Z", }}) + rebuildTestLog(t, childDir, []DatedMessage{{ Kind: "user", Text: "Keep the child history.", @@ -563,7 +565,7 @@ func TestWhatsAppImportChildRebuildUsesOwnPromptAndCache(t *testing.T) { } client := newModelClient(server.URL, ModelAPIKey(modelTestKey), child.CacheKey(), filepath.Join(t.TempDir(), "usage.jsonl")) - backup, err := rebuild(t.Context(), child, plan.added, client, newCompactor(client, child.Prompt, defaultConfig().Compactor, child.Tools()), &strings.Builder{}) + backup, err := rebuild(t.Context(), child, plan.added, client, newCompactor(client, child.Prompt, defaultConfig().Compactor, child.Tools(), child.Images()), &strings.Builder{}) require.NoError(t, err) require.Equal(t, before, rebuildTestSnapshot(t, backup)) require.Equal(t, root.dir, filepath.Dir(backup)) @@ -613,7 +615,7 @@ func TestWhatsAppImportChildFailureKeepsConfiguredChildren(t *testing.T) { Kind: "work", Text: strings.Repeat("The plan is ready. ", 80), Date: "2025-01-01T08:00:00Z", - }}, client, newCompactor(client, child.Prompt, defaultConfig().Compactor, child.Tools()), &strings.Builder{}) + }}, client, newCompactor(client, child.Prompt, defaultConfig().Compactor, child.Tools(), child.Images()), &strings.Builder{}) require.ErrorContains(t, err, "rebuild") require.Equal(t, before, rebuildTestSnapshot(t, root.dir)) @@ -702,6 +704,49 @@ func TestWhatsAppImportRefusesPendingDeliveriesAndKeepsRestartSafe(t *testing.T) } } +func TestWhatsAppImportBlocksPendingNotificationsButNotCompletedReceipts(t *testing.T) { + testCases := []struct { + name string + index int + }{ + { + name: "blocks only pending root notifications", + }, + { + name: "blocks only pending child notifications", + index: 1, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + server := newModelFake(t) + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { + modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5)) + } + + test := newDaemonMessageTest(t, t.TempDir(), server) + _, err := test.messages.Notify(&NotifyInput{ + AgentID: test.agents[tc.index].agent.config.ID, + Source: "check", + ID: "1", + Text: "A result.", + }) + require.NoError(t, err) + + target := test.agents[tc.index].agent + directory := test.agents[0].agent.dir + require.ErrorContains(t, whatsappImportIdle(directory, target), "pending deliveries") + require.NoError(t, whatsappImportIdle(directory, test.agents[tc.index^1].agent)) + require.NoError(t, test.messages.Notifications(test.loops[tc.index])) + require.NoError(t, test.loops[tc.index].turn(t.Context())) + require.Len(t, test.Queue(t).Notifications, 1) + require.Empty(t, test.Queue(t).Pending) + require.NoError(t, whatsappImportIdle(directory, target)) + }) + } +} + func TestWhatsAppImportPendingDeliveriesBlockOnlyTheirTarget(t *testing.T) { dir := t.TempDir() t.Setenv("ONECHAT_DIR", dir)