@remit/mailbox-service 0.0.111 → 0.0.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account-credentials.d.ts +83 -0
- package/dist/account-credentials.js +104 -0
- package/dist/attribute-mapper.d.ts +36 -0
- package/dist/attribute-mapper.js +119 -0
- package/dist/body-parse.d.ts +28 -0
- package/{src/body-parse.ts → dist/body-parse.js} +18 -26
- package/dist/body-part-mapper.d.ts +92 -0
- package/dist/body-part-mapper.js +301 -0
- package/dist/body-sync-queue.d.ts +59 -0
- package/dist/body-sync-queue.js +56 -0
- package/dist/body-sync-terminal.d.ts +58 -0
- package/dist/body-sync-terminal.js +95 -0
- package/dist/body-sync.d.ts +351 -0
- package/dist/body-sync.js +1204 -0
- package/dist/calendar-parts.d.ts +23 -0
- package/dist/calendar-parts.js +18 -0
- package/dist/classification-backfill.d.ts +91 -0
- package/dist/classification-backfill.js +180 -0
- package/dist/classify-message.d.ts +31 -0
- package/dist/classify-message.js +89 -0
- package/dist/connection-factory.d.ts +54 -0
- package/dist/connection-factory.js +54 -0
- package/dist/connection-test.d.ts +41 -0
- package/dist/connection-test.js +152 -0
- package/dist/external-move.d.ts +94 -0
- package/dist/external-move.js +173 -0
- package/dist/filter-operations.d.ts +42 -0
- package/dist/filter-operations.js +211 -0
- package/dist/filters/filter-config.d.ts +14 -0
- package/dist/filters/filter-config.js +10 -0
- package/{src/filters/list-id.ts → dist/filters/list-id.d.ts} +2 -16
- package/dist/filters/list-id.js +26 -0
- package/dist/filters/match.d.ts +69 -0
- package/dist/filters/match.js +165 -0
- package/dist/filters/pipeline.d.ts +64 -0
- package/dist/filters/pipeline.js +100 -0
- package/{src/flag-push-terminal.ts → dist/flag-push-terminal.d.ts} +19 -77
- package/dist/flag-push-terminal.js +63 -0
- package/dist/flag-push.d.ts +69 -0
- package/dist/flag-push.js +111 -0
- package/dist/flag-queue.d.ts +175 -0
- package/dist/flag-queue.js +291 -0
- package/dist/folder-operations.d.ts +39 -0
- package/dist/folder-operations.js +112 -0
- package/dist/folder-placement.d.ts +13 -0
- package/dist/folder-placement.js +23 -0
- package/dist/heuristics/authenticationResults.d.ts +10 -0
- package/dist/heuristics/authenticationResults.js +187 -0
- package/dist/heuristics/classifyByHeaders.d.ts +82 -0
- package/dist/heuristics/classifyByHeaders.js +365 -0
- package/dist/heuristics/classifyPlacement.d.ts +67 -0
- package/dist/heuristics/classifyPlacement.js +153 -0
- package/dist/heuristics/machineSenders.d.ts +21 -0
- package/{src/heuristics/machineSenders.ts → dist/heuristics/machineSenders.js} +34 -40
- package/dist/heuristics/senderMismatch.d.ts +81 -0
- package/dist/heuristics/senderMismatch.js +192 -0
- package/dist/heuristics/socialDomains.d.ts +14 -0
- package/{src/heuristics/socialDomains.ts → dist/heuristics/socialDomains.js} +9 -9
- package/dist/heuristics/transactionalDomains.d.ts +18 -0
- package/{src/heuristics/transactionalDomains.ts → dist/heuristics/transactionalDomains.js} +8 -8
- package/dist/imapflow-connection.d.ts +377 -0
- package/dist/imapflow-connection.js +1147 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +65 -0
- package/dist/list-id-backfill.d.ts +83 -0
- package/dist/list-id-backfill.js +132 -0
- package/dist/mailbox-cursor-rebuild.d.ts +74 -0
- package/dist/mailbox-cursor-rebuild.js +71 -0
- package/{src/mailbox-cursor.ts → dist/mailbox-cursor.d.ts} +20 -98
- package/dist/mailbox-cursor.js +102 -0
- package/dist/mailbox-intent.d.ts +41 -0
- package/{src/mailbox-intent.ts → dist/mailbox-intent.js} +39 -63
- package/dist/mailbox-management.d.ts +240 -0
- package/dist/mailbox-management.js +576 -0
- package/dist/mailbox-presence.d.ts +52 -0
- package/{src/mailbox-presence.ts → dist/mailbox-presence.js} +19 -30
- package/dist/mailbox-queue.d.ts +126 -0
- package/dist/mailbox-queue.js +214 -0
- package/dist/mailbox-sync.d.ts +93 -0
- package/dist/mailbox-sync.js +490 -0
- package/dist/mailbox-upstream.d.ts +38 -0
- package/{src/mailbox-upstream.ts → dist/mailbox-upstream.js} +37 -47
- package/dist/message-category.d.ts +51 -0
- package/{src/message-category.ts → dist/message-category.js} +28 -71
- package/dist/message-move.d.ts +285 -0
- package/dist/message-move.js +858 -0
- package/dist/message-parser.d.ts +14 -0
- package/dist/message-parser.js +17 -0
- package/{src/message-presence.ts → dist/message-presence.d.ts} +1 -13
- package/dist/message-presence.js +29 -0
- package/dist/message-read.d.ts +51 -0
- package/dist/message-read.js +31 -0
- package/dist/message-sync.d.ts +345 -0
- package/dist/message-sync.js +1358 -0
- package/dist/mime-walker.d.ts +102 -0
- package/dist/mime-walker.js +198 -0
- package/dist/organize-job.d.ts +20 -0
- package/dist/organize-job.js +37 -0
- package/dist/outbox-attachment-content.d.ts +37 -0
- package/dist/outbox-attachment-content.js +50 -0
- package/dist/outbox-attachment-filename.d.ts +19 -0
- package/dist/outbox-attachment-filename.js +64 -0
- package/dist/outbox-attachment.d.ts +148 -0
- package/dist/outbox-attachment.js +273 -0
- package/dist/outbox-queue.d.ts +73 -0
- package/dist/outbox-queue.js +284 -0
- package/{src/outbox-status.ts → dist/outbox-status.d.ts} +1 -6
- package/dist/outbox-status.js +18 -0
- package/dist/ownership.d.ts +24 -0
- package/dist/ownership.js +83 -0
- package/dist/placement-move-terminal.d.ts +67 -0
- package/dist/placement-move-terminal.js +88 -0
- package/dist/placement-move.d.ts +83 -0
- package/dist/placement-move.js +216 -0
- package/{src/placement-settled.ts → dist/placement-settled.d.ts} +19 -50
- package/dist/placement-settled.js +75 -0
- package/dist/quarantine.d.ts +95 -0
- package/dist/quarantine.js +131 -0
- package/dist/refusal.d.ts +31 -0
- package/dist/refusal.js +3 -0
- package/{src/restore-source-placement.ts → dist/restore-source-placement.d.ts} +29 -101
- package/dist/restore-source-placement.js +79 -0
- package/dist/search-text-backfill.d.ts +15 -0
- package/dist/search-text-backfill.js +33 -0
- package/dist/snippet.d.ts +61 -0
- package/dist/snippet.js +129 -0
- package/dist/spam-report.d.ts +86 -0
- package/dist/spam-report.js +241 -0
- package/dist/sync-warning.d.ts +21 -0
- package/dist/sync-warning.js +26 -0
- package/dist/sync-watermarks.d.ts +138 -0
- package/dist/sync-watermarks.js +205 -0
- package/dist/test-helpers/fake-imap.d.ts +151 -0
- package/dist/test-helpers/fake-imap.js +508 -0
- package/dist/test-helpers/folder-roles.d.ts +34 -0
- package/dist/test-helpers/folder-roles.js +47 -0
- package/dist/test-helpers/mime-tree-generator.d.ts +82 -0
- package/dist/test-helpers/mime-tree-generator.js +329 -0
- package/dist/test-helpers/test-store.d.ts +69 -0
- package/dist/test-helpers/test-store.js +193 -0
- package/dist/text/normalizer.d.ts +20 -0
- package/dist/text/normalizer.js +102 -0
- package/dist/thread-message-rows.d.ts +69 -0
- package/dist/thread-message-rows.js +40 -0
- package/dist/thread-root.d.ts +7 -0
- package/dist/thread-root.js +25 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +19 -0
- package/package.json +86 -73
- package/src/account-credentials.ts +0 -210
- package/src/adversarial-mime.e2e.test.ts +0 -307
- package/src/attribute-mapper.test.ts +0 -104
- package/src/attribute-mapper.ts +0 -148
- package/src/body-parse.test.ts +0 -55
- package/src/body-part-mapper.property.test.ts +0 -354
- package/src/body-part-mapper.ts +0 -360
- package/src/body-sync-auto-read-writeonce.test.ts +0 -219
- package/src/body-sync-calendar-suggestion.test.ts +0 -433
- package/src/body-sync-category-denormalize.test.ts +0 -352
- package/src/body-sync-category-override.test.ts +0 -501
- package/src/body-sync-category-writeonce.test.ts +0 -234
- package/src/body-sync-filter.test.ts +0 -237
- package/src/body-sync-message-gone.test.ts +0 -139
- package/src/body-sync-placement-flags.test.ts +0 -347
- package/src/body-sync-placement-writeonce.test.ts +0 -337
- package/src/body-sync-quarantine.test.ts +0 -276
- package/src/body-sync-queue.test.ts +0 -124
- package/src/body-sync-queue.ts +0 -131
- package/src/body-sync-resync.test.ts +0 -605
- package/src/body-sync-terminal.test.ts +0 -310
- package/src/body-sync-terminal.ts +0 -176
- package/src/body-sync-unclassifiable-once.test.ts +0 -260
- package/src/body-sync-unsubscribed-auto-read.test.ts +0 -176
- package/src/body-sync.ts +0 -1970
- package/src/calendar-parts.ts +0 -41
- package/src/classification-backfill.test.ts +0 -615
- package/src/classification-backfill.ts +0 -363
- package/src/classify-message.test.ts +0 -205
- package/src/classify-message.ts +0 -116
- package/src/connection-factory.ts +0 -102
- package/src/connection-test.ts +0 -208
- package/src/credentials.test.ts +0 -181
- package/src/external-move.test.ts +0 -369
- package/src/external-move.ts +0 -272
- package/src/filters/anchor-drift.ts +0 -55
- package/src/filters/filter-config.test.ts +0 -229
- package/src/filters/filter-config.ts +0 -69
- package/src/filters/list-id.test.ts +0 -50
- package/src/filters/match.test.ts +0 -429
- package/src/filters/match.ts +0 -274
- package/src/filters/message-embedder.test.ts +0 -39
- package/src/filters/message-embedder.ts +0 -33
- package/src/filters/pipeline.test.ts +0 -330
- package/src/filters/pipeline.ts +0 -284
- package/src/flag-push-terminal.test.ts +0 -209
- package/src/flag-push.test.ts +0 -408
- package/src/flag-push.ts +0 -198
- package/src/flag-queue-stars.test.ts +0 -171
- package/src/flag-queue.ts +0 -509
- package/src/folder-placement.ts +0 -56
- package/src/heuristics/authenticationResults.test.ts +0 -189
- package/src/heuristics/authenticationResults.ts +0 -212
- package/src/heuristics/classifyByHeaders.test.ts +0 -889
- package/src/heuristics/classifyByHeaders.ts +0 -467
- package/src/heuristics/classifyPlacement.test.ts +0 -366
- package/src/heuristics/classifyPlacement.ts +0 -211
- package/src/heuristics/classifyRealMail.test.ts +0 -242
- package/src/heuristics/machineSenders.test.ts +0 -101
- package/src/heuristics/senderMismatch.test.ts +0 -346
- package/src/heuristics/senderMismatch.ts +0 -259
- package/src/imapflow-connect-retry.test.ts +0 -134
- package/src/imapflow-connection.e2e.test.ts +0 -335
- package/src/imapflow-connection.integ.test.ts +0 -316
- package/src/imapflow-connection.test.ts +0 -469
- package/src/imapflow-connection.ts +0 -1475
- package/src/index.ts +0 -350
- package/src/list-id-backfill.test.ts +0 -573
- package/src/list-id-backfill.ts +0 -274
- package/src/mailbox-cursor-rebuild.test.ts +0 -171
- package/src/mailbox-cursor-rebuild.ts +0 -146
- package/src/mailbox-cursor.test.ts +0 -249
- package/src/mailbox-delete-intent.test.ts +0 -246
- package/src/mailbox-management.test.ts +0 -356
- package/src/mailbox-management.ts +0 -839
- package/src/mailbox-presence.test.ts +0 -72
- package/src/mailbox-queue.ts +0 -415
- package/src/mailbox-rename-intent.test.ts +0 -389
- package/src/mailbox-rename-subtree.test.ts +0 -664
- package/src/mailbox-sync.test.ts +0 -848
- package/src/mailbox-sync.ts +0 -724
- package/src/message-delete-junk-reconcile.test.ts +0 -117
- package/src/message-delete-no-trash.test.ts +0 -245
- package/src/message-delete-unsettled-placement.test.ts +0 -396
- package/src/message-move-copy.test.ts +0 -562
- package/src/message-move-empty-trash.test.ts +0 -326
- package/src/message-move-same-mailbox.test.ts +0 -139
- package/src/message-move-unsettled-placement.test.ts +0 -378
- package/src/message-move.ts +0 -1348
- package/src/message-parser.ts +0 -26
- package/src/message-presence.test.ts +0 -50
- package/src/message-sync-address-spoof.test.ts +0 -293
- package/src/message-sync-category.test.ts +0 -142
- package/src/message-sync-changedsince.test.ts +0 -840
- package/src/message-sync-flags.test.ts +0 -158
- package/src/message-sync-junk-harvest.test.ts +0 -244
- package/src/message-sync-quarantine.test.ts +0 -416
- package/src/message-sync-repoint.test.ts +0 -419
- package/src/message-sync.ts +0 -1963
- package/src/mime-walker.test.ts +0 -311
- package/src/mime-walker.ts +0 -305
- package/src/outbox-attachment-content.test.ts +0 -153
- package/src/outbox-attachment-content.ts +0 -104
- package/src/outbox-attachment-filename.test.ts +0 -132
- package/src/outbox-attachment-filename.ts +0 -76
- package/src/outbox-attachment.test.ts +0 -738
- package/src/outbox-attachment.ts +0 -536
- package/src/outbox-failed-recovery.test.ts +0 -370
- package/src/outbox-queue-settled-row.test.ts +0 -140
- package/src/outbox-queue.test.ts +0 -291
- package/src/outbox-queue.ts +0 -508
- package/src/pass-through-unit-of-work.ts +0 -17
- package/src/placement-move-terminal.test.ts +0 -300
- package/src/placement-move-terminal.ts +0 -148
- package/src/placement-move-unsettled.test.ts +0 -275
- package/src/placement-move.ts +0 -336
- package/src/placement-settled.test.ts +0 -147
- package/src/placement-transition-race.test.ts +0 -482
- package/src/quarantine.test.ts +0 -191
- package/src/quarantine.ts +0 -228
- package/src/snippet.test.ts +0 -213
- package/src/snippet.ts +0 -152
- package/src/spam-report.test.ts +0 -801
- package/src/spam-report.ts +0 -357
- package/src/stale-message-reconcile.test.ts +0 -82
- package/src/stale-message-reconcile.ts +0 -55
- package/src/sync-watermarks.test.ts +0 -409
- package/src/sync-watermarks.ts +0 -319
- package/src/system-flag-wire-format.test.ts +0 -77
- package/src/test-helpers/folder-roles.ts +0 -66
- package/src/test-helpers/isolated-mailbox.ts +0 -44
- package/src/test-helpers/mailfuzz-connection.ts +0 -27
- package/src/test-helpers/mime-tree-generator.ts +0 -461
- package/src/text/normalizer.test.ts +0 -223
- package/src/text/normalizer.ts +0 -140
- package/src/thread-message-rows.ts +0 -77
- package/src/types/mailparser-augment.d.ts +0 -15
- package/src/types/natural-porter-stemmer.d.ts +0 -50
- package/src/types/stopword.d.ts +0 -69
- package/src/types.ts +0 -371
- package/test/fixtures/mime-adversarial-e2e/01-octet-stream-pdf.eml +0 -21
- package/test/fixtures/mime-adversarial-e2e/02-nested-related-cid-image.eml +0 -31
- package/test/fixtures/mime-adversarial-e2e/03-calendar-invite.eml +0 -33
- package/test/fixtures/mime-adversarial-e2e/04-forwarded-rfc822-with-attachments.eml +0 -42
- package/test/fixtures/mime-adversarial-e2e/05-tnef-winmail.eml +0 -25
- package/test/fixtures/mime-adversarial-e2e/06-8bit-non-ascii.eml +0 -15
- package/test/fixtures/mime-adversarial-e2e/07-quoted-printable-soft-breaks.eml +0 -17
- package/test/fixtures/mime-adversarial-e2e/08-alternative-empty-text.eml +0 -18
- package/tsconfig.json +0 -8
package/src/calendar-parts.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/// <reference path="./types/mailparser-augment.d.ts" />
|
|
2
|
-
|
|
3
|
-
import { ROOT_PART_PATH } from "@remit/data-ports/id";
|
|
4
|
-
import { CalendarSuggestionSource } from "@remit/domain-enums";
|
|
5
|
-
import type { Attachment, ParsedMail } from "mailparser";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* One `text/calendar` part of a message, and where it sat.
|
|
9
|
-
*
|
|
10
|
-
* The distinction between an inline part and an attached one is not cosmetic:
|
|
11
|
-
* a scheduling client sends the invitation inline as part of a
|
|
12
|
-
* `multipart/alternative`, while a client that cannot speak iTIP attaches an
|
|
13
|
-
* `.ics` file. Both carry the same bytes, and a card says which it read.
|
|
14
|
-
*/
|
|
15
|
-
export interface CalendarPart {
|
|
16
|
-
partPath: string;
|
|
17
|
-
source:
|
|
18
|
-
| typeof CalendarSuggestionSource.IcalendarPart
|
|
19
|
-
| typeof CalendarSuggestionSource.IcalendarAttachment;
|
|
20
|
-
icalData: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const isCalendar = (attachment: Attachment): boolean =>
|
|
24
|
-
(attachment.contentType ?? "").toLowerCase().startsWith("text/calendar");
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Every `text/calendar` part of a parsed message, in declaration order.
|
|
28
|
-
*
|
|
29
|
-
* Reads mailparser's `attachments[]`, which is where every non-`text/plain`,
|
|
30
|
-
* non-`text/html` leaf lands — the same list the header classifier already
|
|
31
|
-
* looks at to route an invitation to `transactional`.
|
|
32
|
-
*/
|
|
33
|
-
export const calendarParts = (parsed: ParsedMail): CalendarPart[] =>
|
|
34
|
-
(parsed.attachments ?? []).filter(isCalendar).map((attachment) => ({
|
|
35
|
-
partPath: attachment.partId ?? ROOT_PART_PATH,
|
|
36
|
-
source:
|
|
37
|
-
attachment.contentDisposition === "attachment"
|
|
38
|
-
? CalendarSuggestionSource.IcalendarAttachment
|
|
39
|
-
: CalendarSuggestionSource.IcalendarPart,
|
|
40
|
-
icalData: attachment.content.toString("utf8"),
|
|
41
|
-
}));
|
|
@@ -1,615 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the `backfillClassifications` pass (issue #1197) — the resumable,
|
|
3
|
-
* checkpointed full-corpus pass that classifies rows still carrying the
|
|
4
|
-
* `NotExamined` sentinel on `Message.classificationState`, from their stored
|
|
5
|
-
* bodies, and marks them `Examined`.
|
|
6
|
-
*
|
|
7
|
-
* Mirrors `list-id-backfill.test.ts`: per-account pages, checkpoint after
|
|
8
|
-
* every page, resume by account-id order, and per-message failure
|
|
9
|
-
* containment via `.then(fulfilled, rejected)`.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import assert from "node:assert/strict";
|
|
13
|
-
import { describe, it } from "node:test";
|
|
14
|
-
import type {
|
|
15
|
-
AccountConfigItem,
|
|
16
|
-
AccountItem,
|
|
17
|
-
AddressItem,
|
|
18
|
-
IAccountConfigRepository,
|
|
19
|
-
IAccountRepository,
|
|
20
|
-
IAddressRepository,
|
|
21
|
-
IMessageRepository,
|
|
22
|
-
IThreadMessageRepository,
|
|
23
|
-
MessageItem,
|
|
24
|
-
ResultList,
|
|
25
|
-
ThreadMessageItem,
|
|
26
|
-
UpdateMessageInput,
|
|
27
|
-
UpdateThreadMessageInput,
|
|
28
|
-
} from "@remit/data-ports";
|
|
29
|
-
import { NotFoundError } from "@remit/data-ports/errors";
|
|
30
|
-
import { DisplayNameCorrespondence } from "@remit/domain-enums";
|
|
31
|
-
import type { StorageService } from "@remit/storage-service";
|
|
32
|
-
import { backfillClassifications } from "./classification-backfill.js";
|
|
33
|
-
import type { FolderPlacementLookup } from "./folder-placement.js";
|
|
34
|
-
|
|
35
|
-
const PLAIN_EML = Buffer.from(
|
|
36
|
-
[
|
|
37
|
-
"From: Alice <alice@example.com>",
|
|
38
|
-
"To: me@example.com",
|
|
39
|
-
"Subject: Hi",
|
|
40
|
-
"Content-Type: text/plain",
|
|
41
|
-
"",
|
|
42
|
-
"hi",
|
|
43
|
-
].join("\r\n"),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const LIST_EML = Buffer.from(
|
|
47
|
-
[
|
|
48
|
-
"From: Alice <alice@example.com>",
|
|
49
|
-
"To: me@example.com",
|
|
50
|
-
"Subject: Newsletter",
|
|
51
|
-
"List-Id: <news.example.com>",
|
|
52
|
-
"List-Unsubscribe: <https://example.com/unsub>",
|
|
53
|
-
"Content-Type: text/plain",
|
|
54
|
-
"",
|
|
55
|
-
"this week in news",
|
|
56
|
-
].join("\r\n"),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const IMPERSONATION_EML = Buffer.from(
|
|
60
|
-
[
|
|
61
|
-
"From: InfoMedics <billing@serviceupdatebank.atlassian.net>",
|
|
62
|
-
"To: me@example.com",
|
|
63
|
-
"Subject: Openstaande factuur",
|
|
64
|
-
"DKIM-Signature: v=1; a=rsa-sha256; d=atlassian.net; s=sel; b=xxx",
|
|
65
|
-
"Content-Type: text/plain",
|
|
66
|
-
"",
|
|
67
|
-
"Betaal uw factuur",
|
|
68
|
-
].join("\r\n"),
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const JUNK_MAILBOX_ID = "mb-junk";
|
|
72
|
-
|
|
73
|
-
const row = (overrides: Partial<ThreadMessageItem>): ThreadMessageItem =>
|
|
74
|
-
({
|
|
75
|
-
threadMessageId: "tm-1",
|
|
76
|
-
accountConfigId: "acc-1",
|
|
77
|
-
threadId: "thread-1",
|
|
78
|
-
messageId: "m-1",
|
|
79
|
-
mailboxId: "mb-1",
|
|
80
|
-
uid: 1,
|
|
81
|
-
referenceOrder: 0,
|
|
82
|
-
internalDate: 1,
|
|
83
|
-
sentDate: 1,
|
|
84
|
-
isRead: false,
|
|
85
|
-
hasAttachment: false,
|
|
86
|
-
star: "none",
|
|
87
|
-
hasStars: false,
|
|
88
|
-
isDeleted: false,
|
|
89
|
-
category: "uncategorized",
|
|
90
|
-
createdAt: 1,
|
|
91
|
-
updatedAt: 1,
|
|
92
|
-
...overrides,
|
|
93
|
-
}) as unknown as ThreadMessageItem;
|
|
94
|
-
|
|
95
|
-
const message = (overrides: Partial<MessageItem>): MessageItem =>
|
|
96
|
-
({
|
|
97
|
-
messageId: "m-1",
|
|
98
|
-
mailboxId: "mb-1",
|
|
99
|
-
uid: 1,
|
|
100
|
-
status: "active",
|
|
101
|
-
syncStatus: "synced",
|
|
102
|
-
category: "uncategorized",
|
|
103
|
-
classificationState: "NotExamined",
|
|
104
|
-
hasListUnsubscribe: false,
|
|
105
|
-
movedByRemit: false,
|
|
106
|
-
bodyStorageKey: "s3://m-1",
|
|
107
|
-
authenticityVerdict: "NotEvaluated",
|
|
108
|
-
createdAt: 1,
|
|
109
|
-
updatedAt: 1,
|
|
110
|
-
...overrides,
|
|
111
|
-
}) as unknown as MessageItem;
|
|
112
|
-
|
|
113
|
-
const asAccount = (accountConfigId: string): AccountConfigItem =>
|
|
114
|
-
({ accountConfigId }) as unknown as AccountConfigItem;
|
|
115
|
-
|
|
116
|
-
interface Harness {
|
|
117
|
-
accountConfigService: Pick<IAccountConfigRepository, "listAll">;
|
|
118
|
-
accountService: Pick<IAccountRepository, "listAllByAccountConfig">;
|
|
119
|
-
mailboxSpecialUseService: FolderPlacementLookup;
|
|
120
|
-
addressService: Pick<IAddressRepository, "getAddress">;
|
|
121
|
-
threadMessageService: Pick<
|
|
122
|
-
IThreadMessageRepository,
|
|
123
|
-
"listByAccount" | "findAllByMessageId" | "update"
|
|
124
|
-
>;
|
|
125
|
-
messageService: Pick<IMessageRepository, "get" | "update">;
|
|
126
|
-
storageService: Pick<StorageService, "retrieve">;
|
|
127
|
-
messageUpdates: Array<{ messageId: string; input: UpdateMessageInput }>;
|
|
128
|
-
threadUpdates: Array<{
|
|
129
|
-
accountConfigId: string;
|
|
130
|
-
threadMessageId: string;
|
|
131
|
-
input: UpdateThreadMessageInput;
|
|
132
|
-
}>;
|
|
133
|
-
retrieved: string[];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const buildHarness = (options: {
|
|
137
|
-
accounts?: AccountConfigItem[];
|
|
138
|
-
rows: ThreadMessageItem[];
|
|
139
|
-
messages: MessageItem[];
|
|
140
|
-
retrieve?: (key: string) => Promise<Buffer>;
|
|
141
|
-
pageSize?: number;
|
|
142
|
-
addressFlags?: AddressItem["flags"];
|
|
143
|
-
}): Harness => {
|
|
144
|
-
const accounts = options.accounts ?? [
|
|
145
|
-
{ accountConfigId: "acc-1" } as unknown as AccountConfigItem,
|
|
146
|
-
];
|
|
147
|
-
const messagesById = new Map(options.messages.map((m) => [m.messageId, m]));
|
|
148
|
-
const messageUpdates: Harness["messageUpdates"] = [];
|
|
149
|
-
const threadUpdates: Harness["threadUpdates"] = [];
|
|
150
|
-
const retrieved: string[] = [];
|
|
151
|
-
const pageSize = options.pageSize ?? 200;
|
|
152
|
-
|
|
153
|
-
const accountConfigService: Pick<IAccountConfigRepository, "listAll"> = {
|
|
154
|
-
listAll: async () => accounts,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const accountService: Pick<IAccountRepository, "listAllByAccountConfig"> = {
|
|
158
|
-
listAllByAccountConfig: async (accountConfigId: string) => [
|
|
159
|
-
{ accountId: `account-${accountConfigId}` } as unknown as AccountItem,
|
|
160
|
-
],
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const mailboxSpecialUseService: FolderPlacementLookup = {
|
|
164
|
-
findJunkMailbox: async () => ({
|
|
165
|
-
mailboxId: JUNK_MAILBOX_ID,
|
|
166
|
-
fullPath: "Junk",
|
|
167
|
-
}),
|
|
168
|
-
findInboxMailbox: async () => ({ mailboxId: "mb-1", fullPath: "INBOX" }),
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const addressService = {
|
|
172
|
-
getAddress: (async () => {
|
|
173
|
-
if (options.addressFlags === undefined)
|
|
174
|
-
throw new NotFoundError("no Address row for this sender");
|
|
175
|
-
return { flags: options.addressFlags } as AddressItem;
|
|
176
|
-
}) as unknown as IAddressRepository["getAddress"],
|
|
177
|
-
} as Pick<IAddressRepository, "getAddress">;
|
|
178
|
-
|
|
179
|
-
const threadMessageService: Pick<
|
|
180
|
-
IThreadMessageRepository,
|
|
181
|
-
"listByAccount" | "findAllByMessageId" | "update"
|
|
182
|
-
> = {
|
|
183
|
-
listByAccount: async (
|
|
184
|
-
accountConfigId: string,
|
|
185
|
-
opts?: { limit?: number; continuationToken?: string },
|
|
186
|
-
): Promise<ResultList<ThreadMessageItem>> => {
|
|
187
|
-
const scoped = options.rows.filter(
|
|
188
|
-
(r) => r.accountConfigId === accountConfigId,
|
|
189
|
-
);
|
|
190
|
-
const start = opts?.continuationToken
|
|
191
|
-
? Number(opts.continuationToken)
|
|
192
|
-
: 0;
|
|
193
|
-
const limit = opts?.limit ?? pageSize;
|
|
194
|
-
const page = scoped.slice(start, start + limit);
|
|
195
|
-
const nextStart = start + page.length;
|
|
196
|
-
return {
|
|
197
|
-
items: page,
|
|
198
|
-
continuationToken:
|
|
199
|
-
nextStart < scoped.length ? String(nextStart) : undefined,
|
|
200
|
-
};
|
|
201
|
-
},
|
|
202
|
-
findAllByMessageId: async (_accountConfigId, messageId) =>
|
|
203
|
-
options.rows.filter((r) => r.messageId === messageId),
|
|
204
|
-
update: async (accountConfigId, threadMessageId, input) => {
|
|
205
|
-
threadUpdates.push({ accountConfigId, threadMessageId, input });
|
|
206
|
-
const existing = options.rows.find(
|
|
207
|
-
(r) => r.threadMessageId === threadMessageId,
|
|
208
|
-
);
|
|
209
|
-
return { ...existing, ...input } as ThreadMessageItem;
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const messageService: Pick<IMessageRepository, "get" | "update"> = {
|
|
214
|
-
get: (async (messageIds: string | string[]) => {
|
|
215
|
-
if (Array.isArray(messageIds)) {
|
|
216
|
-
return messageIds
|
|
217
|
-
.map((id) => messagesById.get(id))
|
|
218
|
-
.filter((m): m is MessageItem => m !== undefined);
|
|
219
|
-
}
|
|
220
|
-
const found = messagesById.get(messageIds);
|
|
221
|
-
if (!found) throw new Error(`no fixture for ${messageIds}`);
|
|
222
|
-
return found;
|
|
223
|
-
}) as IMessageRepository["get"],
|
|
224
|
-
update: async (messageId, input) => {
|
|
225
|
-
messageUpdates.push({ messageId, input });
|
|
226
|
-
const existing = messagesById.get(messageId);
|
|
227
|
-
return { ...existing, ...input } as MessageItem;
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const storageService: Pick<StorageService, "retrieve"> = {
|
|
232
|
-
retrieve: async (key: string) => {
|
|
233
|
-
retrieved.push(key);
|
|
234
|
-
return options.retrieve ? options.retrieve(key) : PLAIN_EML;
|
|
235
|
-
},
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
return {
|
|
239
|
-
accountConfigService,
|
|
240
|
-
accountService,
|
|
241
|
-
mailboxSpecialUseService,
|
|
242
|
-
addressService,
|
|
243
|
-
threadMessageService,
|
|
244
|
-
messageService,
|
|
245
|
-
storageService,
|
|
246
|
-
messageUpdates,
|
|
247
|
-
threadUpdates,
|
|
248
|
-
retrieved,
|
|
249
|
-
};
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
describe("backfillClassifications", () => {
|
|
253
|
-
it("classifies a NotExamined candidate from its stored body and marks it Examined", async () => {
|
|
254
|
-
const harness = buildHarness({
|
|
255
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
256
|
-
messages: [message({ messageId: "m-1" })],
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
const result = await backfillClassifications(harness);
|
|
260
|
-
|
|
261
|
-
assert.equal(result.backfilled, 1);
|
|
262
|
-
assert.equal(result.failed, 0);
|
|
263
|
-
assert.equal(result.alreadyExamined, 0);
|
|
264
|
-
assert.deepEqual(harness.retrieved, ["s3://m-1"]);
|
|
265
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
266
|
-
assert.equal(harness.messageUpdates[0].messageId, "m-1");
|
|
267
|
-
// The plain fixture carries no bulk markers, so the header rule table
|
|
268
|
-
// answers `personal`.
|
|
269
|
-
assert.equal(harness.messageUpdates[0].input.category, "personal");
|
|
270
|
-
assert.equal(
|
|
271
|
-
harness.messageUpdates[0].input.classificationState,
|
|
272
|
-
"Examined",
|
|
273
|
-
);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("compares the sender of a Junk row the provider rated clean, and not of an inbox row", async () => {
|
|
277
|
-
const harness = buildHarness({
|
|
278
|
-
rows: [
|
|
279
|
-
row({
|
|
280
|
-
threadMessageId: "tm-junk",
|
|
281
|
-
messageId: "m-junk",
|
|
282
|
-
mailboxId: JUNK_MAILBOX_ID,
|
|
283
|
-
}),
|
|
284
|
-
row({ threadMessageId: "tm-inbox", messageId: "m-inbox" }),
|
|
285
|
-
],
|
|
286
|
-
messages: [
|
|
287
|
-
message({
|
|
288
|
-
messageId: "m-junk",
|
|
289
|
-
mailboxId: JUNK_MAILBOX_ID,
|
|
290
|
-
bodyStorageKey: "s3://m-junk",
|
|
291
|
-
}),
|
|
292
|
-
message({ messageId: "m-inbox", bodyStorageKey: "s3://m-inbox" }),
|
|
293
|
-
],
|
|
294
|
-
retrieve: async () => IMPERSONATION_EML,
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
await backfillClassifications(harness);
|
|
298
|
-
|
|
299
|
-
const correspondence = new Map(
|
|
300
|
-
harness.messageUpdates.map((update) => [
|
|
301
|
-
update.messageId,
|
|
302
|
-
update.input.authenticity?.displayNameCorrespondence,
|
|
303
|
-
]),
|
|
304
|
-
);
|
|
305
|
-
assert.equal(
|
|
306
|
-
correspondence.get("m-junk"),
|
|
307
|
-
DisplayNameCorrespondence.Unrelated,
|
|
308
|
-
);
|
|
309
|
-
assert.equal(correspondence.get("m-inbox"), undefined);
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
it("denormalizes the classifier's answer onto the thread row", async () => {
|
|
313
|
-
const harness = buildHarness({
|
|
314
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
315
|
-
messages: [message({ messageId: "m-1" })],
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
await backfillClassifications(harness);
|
|
319
|
-
|
|
320
|
-
// The thread row is written BEFORE the Message update, so a failure
|
|
321
|
-
// between the two leaves both undone for the rerun (issue #320).
|
|
322
|
-
assert.equal(harness.threadUpdates.length, 1);
|
|
323
|
-
assert.equal(harness.threadUpdates[0].threadMessageId, "tm-1");
|
|
324
|
-
assert.equal(harness.threadUpdates[0].input.category, "personal");
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it("writes the derived bulk fields and the row's List-Id, from the same bytes", async () => {
|
|
328
|
-
const harness = buildHarness({
|
|
329
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
330
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: "s3://list" })],
|
|
331
|
-
retrieve: async () => LIST_EML,
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
const result = await backfillClassifications(harness);
|
|
335
|
-
|
|
336
|
-
assert.equal(result.backfilled, 1);
|
|
337
|
-
assert.equal(harness.messageUpdates[0].input.category, "newsletter");
|
|
338
|
-
assert.equal(harness.messageUpdates[0].input.hasListUnsubscribe, true);
|
|
339
|
-
assert.equal(harness.threadUpdates[0].input.listId, "news.example.com");
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
it("applies the sender's Address.flags.category override over the header category", async () => {
|
|
343
|
-
const harness = buildHarness({
|
|
344
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
345
|
-
messages: [message({ messageId: "m-1" })],
|
|
346
|
-
addressFlags: {
|
|
347
|
-
category: { value: "marketing", setAt: 1 },
|
|
348
|
-
} as AddressItem["flags"],
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
const result = await backfillClassifications(harness);
|
|
352
|
-
|
|
353
|
-
assert.equal(result.backfilled, 1);
|
|
354
|
-
assert.equal(harness.messageUpdates[0].input.category, "marketing");
|
|
355
|
-
assert.equal(harness.threadUpdates[0].input.category, "marketing");
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it("marks an already-categorized candidate Examined without re-deriving its category", async () => {
|
|
359
|
-
const harness = buildHarness({
|
|
360
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
361
|
-
messages: [
|
|
362
|
-
message({
|
|
363
|
-
messageId: "m-1",
|
|
364
|
-
category: "newsletter",
|
|
365
|
-
classificationState: "NotExamined",
|
|
366
|
-
}),
|
|
367
|
-
],
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
const result = await backfillClassifications(harness);
|
|
371
|
-
|
|
372
|
-
// Those rows were classified by a pass that predates the field; the
|
|
373
|
-
// write-once category is carried forward, never recomputed (#355).
|
|
374
|
-
assert.equal(result.alreadyCategorized, 1);
|
|
375
|
-
assert.equal(result.backfilled, 0);
|
|
376
|
-
assert.deepEqual(harness.retrieved, []);
|
|
377
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
378
|
-
assert.deepEqual(harness.messageUpdates[0].input, {
|
|
379
|
-
classificationState: "Examined",
|
|
380
|
-
});
|
|
381
|
-
assert.deepEqual(harness.threadUpdates, []);
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it("skips a row already Examined, without reading storage", async () => {
|
|
385
|
-
const harness = buildHarness({
|
|
386
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
387
|
-
messages: [
|
|
388
|
-
message({ messageId: "m-1", classificationState: "Examined" }),
|
|
389
|
-
],
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
const result = await backfillClassifications(harness);
|
|
393
|
-
|
|
394
|
-
assert.equal(result.alreadyExamined, 1);
|
|
395
|
-
assert.equal(result.backfilled, 0);
|
|
396
|
-
assert.deepEqual(harness.retrieved, []);
|
|
397
|
-
assert.deepEqual(harness.messageUpdates, []);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it("skips a candidate whose body was never synced, without reading storage", async () => {
|
|
401
|
-
const harness = buildHarness({
|
|
402
|
-
rows: [row({ threadMessageId: "tm-1", messageId: "m-1" })],
|
|
403
|
-
messages: [message({ messageId: "m-1", bodyStorageKey: undefined })],
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
const result = await backfillClassifications(harness);
|
|
407
|
-
|
|
408
|
-
assert.equal(result.skippedNoBody, 1);
|
|
409
|
-
assert.deepEqual(harness.retrieved, []);
|
|
410
|
-
assert.deepEqual(harness.messageUpdates, []);
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
it("examines a message once, however many thread rows index it", async () => {
|
|
414
|
-
const harness = buildHarness({
|
|
415
|
-
rows: [
|
|
416
|
-
row({ threadMessageId: "tm-1", messageId: "m-1" }),
|
|
417
|
-
row({
|
|
418
|
-
threadMessageId: "tm-2",
|
|
419
|
-
messageId: "m-1",
|
|
420
|
-
threadId: "thread-2",
|
|
421
|
-
}),
|
|
422
|
-
],
|
|
423
|
-
messages: [message({ messageId: "m-1" })],
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
const result = await backfillClassifications(harness);
|
|
427
|
-
|
|
428
|
-
assert.equal(result.backfilled, 1);
|
|
429
|
-
assert.equal(result.alreadyExamined, 1);
|
|
430
|
-
assert.deepEqual(harness.retrieved, ["s3://m-1"]);
|
|
431
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
it("contains a classify failure to the one message and keeps going", async () => {
|
|
435
|
-
const harness = buildHarness({
|
|
436
|
-
rows: [
|
|
437
|
-
row({ threadMessageId: "tm-bad", messageId: "m-bad" }),
|
|
438
|
-
row({ threadMessageId: "tm-good", messageId: "m-good" }),
|
|
439
|
-
],
|
|
440
|
-
messages: [
|
|
441
|
-
message({ messageId: "m-bad", bodyStorageKey: "s3://m-bad" }),
|
|
442
|
-
message({ messageId: "m-good", bodyStorageKey: "s3://m-good" }),
|
|
443
|
-
],
|
|
444
|
-
retrieve: async (key) => {
|
|
445
|
-
if (key === "s3://m-bad") throw new Error("AccessDenied");
|
|
446
|
-
return PLAIN_EML;
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
const result = await backfillClassifications(harness);
|
|
451
|
-
|
|
452
|
-
assert.equal(result.failed, 1);
|
|
453
|
-
assert.deepEqual(result.failedThreadMessageIds, ["tm-bad"]);
|
|
454
|
-
assert.equal(result.backfilled, 1);
|
|
455
|
-
assert.equal(harness.messageUpdates.length, 1);
|
|
456
|
-
assert.equal(harness.messageUpdates[0].messageId, "m-good");
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it("reports progress as pages are processed", async () => {
|
|
460
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
461
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
462
|
-
);
|
|
463
|
-
const messages = rows.map((r) =>
|
|
464
|
-
message({
|
|
465
|
-
messageId: r.messageId,
|
|
466
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
467
|
-
}),
|
|
468
|
-
);
|
|
469
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
470
|
-
const progress: Array<{ accountConfigId: string; scanned: number }> = [];
|
|
471
|
-
|
|
472
|
-
const result = await backfillClassifications(harness, {
|
|
473
|
-
batchSize: 2,
|
|
474
|
-
onProgress: (p) => progress.push({ ...p }),
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
assert.equal(result.backfilled, 3);
|
|
478
|
-
assert.equal(progress.length, 2);
|
|
479
|
-
assert.equal(progress[0].scanned, 2);
|
|
480
|
-
assert.equal(progress[1].scanned, 3);
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
it("scans every account returned by listAll, in account-id order", async () => {
|
|
484
|
-
const accountIds = ["acc-1", "acc-2", "acc-3"];
|
|
485
|
-
const rows = accountIds.map((accountConfigId) =>
|
|
486
|
-
row({
|
|
487
|
-
threadMessageId: `tm-${accountConfigId}`,
|
|
488
|
-
messageId: `m-${accountConfigId}`,
|
|
489
|
-
accountConfigId,
|
|
490
|
-
}),
|
|
491
|
-
);
|
|
492
|
-
const harness = buildHarness({
|
|
493
|
-
accounts: ["acc-3", "acc-1", "acc-2"].map(asAccount),
|
|
494
|
-
rows,
|
|
495
|
-
messages: rows.map((r) =>
|
|
496
|
-
message({
|
|
497
|
-
messageId: r.messageId,
|
|
498
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
499
|
-
}),
|
|
500
|
-
),
|
|
501
|
-
});
|
|
502
|
-
const progress: Array<{ accountConfigId: string; scanned: number }> = [];
|
|
503
|
-
|
|
504
|
-
const result = await backfillClassifications(harness, {
|
|
505
|
-
onProgress: (p) => progress.push({ ...p }),
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
assert.equal(result.backfilled, 3);
|
|
509
|
-
assert.deepEqual(
|
|
510
|
-
progress.map((p) => p.accountConfigId),
|
|
511
|
-
accountIds,
|
|
512
|
-
);
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
it("checkpoints after each page and clears it on completion", async () => {
|
|
516
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
517
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
518
|
-
);
|
|
519
|
-
const messages = rows.map((r) =>
|
|
520
|
-
message({
|
|
521
|
-
messageId: r.messageId,
|
|
522
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
523
|
-
}),
|
|
524
|
-
);
|
|
525
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
526
|
-
|
|
527
|
-
const saved: Array<{
|
|
528
|
-
accountConfigId: string;
|
|
529
|
-
continuationToken?: string;
|
|
530
|
-
}> = [];
|
|
531
|
-
let cleared = false;
|
|
532
|
-
|
|
533
|
-
await backfillClassifications(harness, {
|
|
534
|
-
batchSize: 2,
|
|
535
|
-
checkpointStore: {
|
|
536
|
-
load: async () => undefined,
|
|
537
|
-
save: async (checkpoint) => {
|
|
538
|
-
saved.push(checkpoint);
|
|
539
|
-
},
|
|
540
|
-
clear: async () => {
|
|
541
|
-
cleared = true;
|
|
542
|
-
},
|
|
543
|
-
},
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
assert.equal(saved.length, 2);
|
|
547
|
-
assert.equal(saved[0].accountConfigId, "acc-1");
|
|
548
|
-
assert.equal(saved[0].continuationToken, "2");
|
|
549
|
-
assert.equal(saved[1].continuationToken, undefined);
|
|
550
|
-
assert.equal(cleared, true);
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
it("resumes from a saved checkpoint instead of rescanning from the start", async () => {
|
|
554
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
555
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
556
|
-
);
|
|
557
|
-
const messages = rows.map((r) =>
|
|
558
|
-
message({
|
|
559
|
-
messageId: r.messageId,
|
|
560
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
561
|
-
}),
|
|
562
|
-
);
|
|
563
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
564
|
-
|
|
565
|
-
const result = await backfillClassifications(harness, {
|
|
566
|
-
batchSize: 2,
|
|
567
|
-
checkpointStore: {
|
|
568
|
-
load: async () => ({
|
|
569
|
-
accountConfigId: "acc-1",
|
|
570
|
-
continuationToken: "2",
|
|
571
|
-
}),
|
|
572
|
-
save: async () => {},
|
|
573
|
-
clear: async () => {},
|
|
574
|
-
},
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
assert.equal(result.scanned, 1);
|
|
578
|
-
assert.equal(result.backfilled, 1);
|
|
579
|
-
assert.deepEqual(
|
|
580
|
-
harness.messageUpdates.map((u) => u.messageId),
|
|
581
|
-
["m-2"],
|
|
582
|
-
);
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
it("restarts the pass when the checkpointed account no longer exists", async () => {
|
|
586
|
-
const rows = Array.from({ length: 3 }, (_, i) =>
|
|
587
|
-
row({ threadMessageId: `tm-${i}`, messageId: `m-${i}` }),
|
|
588
|
-
);
|
|
589
|
-
const messages = rows.map((r) =>
|
|
590
|
-
message({
|
|
591
|
-
messageId: r.messageId,
|
|
592
|
-
bodyStorageKey: `s3://${r.messageId}`,
|
|
593
|
-
}),
|
|
594
|
-
);
|
|
595
|
-
const harness = buildHarness({ rows, messages, pageSize: 2 });
|
|
596
|
-
|
|
597
|
-
const result = await backfillClassifications(harness, {
|
|
598
|
-
batchSize: 2,
|
|
599
|
-
checkpointStore: {
|
|
600
|
-
load: async () => ({
|
|
601
|
-
accountConfigId: "acc-removed",
|
|
602
|
-
continuationToken: "2",
|
|
603
|
-
}),
|
|
604
|
-
save: async () => {},
|
|
605
|
-
clear: async () => {},
|
|
606
|
-
},
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
assert.equal(result.scanned, 3);
|
|
610
|
-
assert.deepEqual(
|
|
611
|
-
harness.messageUpdates.map((u) => u.messageId),
|
|
612
|
-
["m-0", "m-1", "m-2"],
|
|
613
|
-
);
|
|
614
|
-
});
|
|
615
|
-
});
|