Skip to content

Bug: Missing Error Test for Memory Deletion

Metadata

  • Date: 2026-05-27
  • Author: Claude
  • Status: In Progress
  • Root Cause: Missing test coverage for deleteMemory.error-ui path specified in the plan

Issue Statement

The delete memory feature implementation is missing a test case for the error UI path. The plan document docs/plans/delete-memory-api.md line 156 specifies:

| `deleteMemory.error-ui` | Error response from API | Error message displayed in toast/alert, menu remains open or closes with error shown | `error` | User can retry or dismiss error |

However, main/app/__tests__/components/memory-viewer-delete.test.tsx only tests the success path (line 139-171) and does not test: 1. When the API returns an error 2. That the error alert is shown 3. That the user can retry deletion

Impact

  • Test coverage gap for error handling path
  • Plan contract not fully validated by tests
  • Users might encounter unhandled errors when deletion fails

Reproduction Test

Add to main/app/__tests__/components/memory-viewer-delete.test.tsx:

it("displays error alert when deleteMemory API fails", async () => {
  jest.mocked(deleteMemory).mockRejectedValue(new Error("Network error"));

  const alertSpy = jest
    .spyOn(Alert, "alert")
    .mockImplementation((_title, _msg, buttons) => {
      // Don't auto-confirm on error case
    });

  const { getByTestId } = render(
    <MemoryViewerModal
      visible
      initialIndex={0}
      onClose={mockOnClose}
      onMemoryDeleted={mockOnMemoryDeleted}
      memories={[MEMORY]}
    />,
  );

  fireEvent.press(getByTestId("memory-menu-button"));
  fireEvent.press(getByTestId("memory-menu-delete"));

  // Confirm the delete in the initial alert
  const deleteButtons = alertSpy.mock.calls[0]?.[2];
  const confirmButton = deleteButtons?.find((b) => b.style === "destructive");
  confirmButton?.onPress?.();

  await waitFor(() => {
    expect(jest.mocked(deleteMemory)).toHaveBeenCalledWith("mem-delete-1");
  });

  // Verify error alert was shown
  await waitFor(() => {
    expect(Alert.alert).toHaveBeenCalledWith(
      "Error",
      "Could not delete memory. Please try again."
    );
  });

  alertSpy.mockRestore();
});

Fix

Add the missing test case to validate the error UI path as specified in the plan.

Verification

  • [ ] Error test added and passing
  • [ ] Behavior matches plan specification
  • [ ] Code review passed