imap: skip InvestEngine emails via BROKER_SYNC_IMAP_EXCLUDE_PROVIDERS
The IMAP IE parser and the bearer-token IE API path generate different external_ids for the same fill, so running both produces duplicate BUYs in Wealthfolio. With IE now served by the API path (broker-sync invest-engine), we keep the IMAP path live for Schwab and gate IE off via env var. Setting BROKER_SYNC_IMAP_EXCLUDE_PROVIDERS=invest-engine on the imap CronJob stops new dupes; Schwab routing is unaffected. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
d5dbeb96af
commit
68d4832c2e
2 changed files with 51 additions and 2 deletions
|
|
@ -101,6 +101,42 @@ def test_non_ie_activities_passed_through_unchanged() -> None:
|
|||
assert routed[0].account_type is AccountType.GIA
|
||||
|
||||
|
||||
def test_exclude_invest_engine_skips_ie_emails(monkeypatch) -> None:
|
||||
"""BROKER_SYNC_IMAP_EXCLUDE_PROVIDERS=invest-engine should skip IE messages
|
||||
so we don't duplicate IE buys already ingested via the bearer-token API path.
|
||||
Schwab routing must remain unaffected."""
|
||||
from broker_sync.providers import imap as imap_mod
|
||||
|
||||
ie_email = (
|
||||
b"From: noreply@investengine.com\r\n"
|
||||
b"Subject: VUAG Bought\r\n"
|
||||
b"Content-Type: text/plain\r\n\r\n"
|
||||
b"Vanguard S&P 500: VUAG Bought 10.0 @ 100.0 per share Total: 1000.00\r\n"
|
||||
)
|
||||
schwab_email = (
|
||||
b"From: donotreply@schwab.com\r\n"
|
||||
b"Subject: Order Confirmed\r\n"
|
||||
b"Content-Type: text/html\r\n\r\n"
|
||||
b"<html><body>no-op</body></html>\r\n"
|
||||
)
|
||||
monkeypatch.setattr(imap_mod, "_fetch_all", lambda _: [ie_email, schwab_email])
|
||||
monkeypatch.setattr(imap_mod.ie_parser, "parse_invest_engine_email",
|
||||
lambda raw: [object()])
|
||||
monkeypatch.setattr(imap_mod, "parse_schwab_email", lambda html: [object()])
|
||||
|
||||
creds = imap_mod.ImapCreds(host="h", user="u", password="p", directory="d")
|
||||
|
||||
monkeypatch.setenv("BROKER_SYNC_IMAP_EXCLUDE_PROVIDERS", "invest-engine")
|
||||
out_excluded = imap_mod.fetch_activities(creds)
|
||||
# IE skipped → only the schwab activity is emitted
|
||||
assert len(out_excluded) == 1
|
||||
|
||||
monkeypatch.delenv("BROKER_SYNC_IMAP_EXCLUDE_PROVIDERS", raising=False)
|
||||
out_default = imap_mod.fetch_activities(creds)
|
||||
# Both providers fire when env unset
|
||||
assert len(out_default) == 2
|
||||
|
||||
|
||||
def test_schwab_subdomain_sender_matches() -> None:
|
||||
"""Real Schwab trade emails come from `donotreply@mail.schwab.com`
|
||||
(subdomain), not just `donotreply@schwab.com`. The matcher must
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue