@yasaswy.nagavolu/agents 0.33.0 → 0.34.0
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/README.md +11 -0
- package/content/manifest.json +36 -0
- package/content/manifest.schema.json +23 -0
- package/content/skills/gmail-reader/SKILL.md +1 -0
- package/content/skills/gmail-reader/gmail_reader/htmltext.py +23 -3
- package/content/skills/gmail-reader/gmail_reader/purchases/data/vendors.json +3 -0
- package/content/skills/gmail-reader/gmail_reader/purchases/parse.py +51 -5
- package/content/skills/gmail-reader/gmail_reader/purchases/proof.py +27 -3
- package/content/skills/gmail-reader/gmail_reader/purchases/scan.py +3 -1
- package/content/skills/gmail-reader/gmail_reader/version.py +1 -1
- package/content/skills/gmail-reader/tests/conftest.py +1 -19
- package/content/skills/gmail-reader/tests/gmail_home_guard.py +19 -0
- package/content/skills/gmail-reader/tests/test_purchase_parsers.py +35 -0
- package/content/skills/gmail-reader/tests/test_returns.py +106 -0
- package/content/skills/gmail-reader/tests/test_scan.py +1 -1
- package/content/skills/gmail-reader/tests/test_secrets_isolation.py +3 -3
- package/content/skills/html-mocker/audit.js +10 -4
- package/content/skills/html-mocker/tests/test_audit.py +15 -0
- package/content/skills/make-space/tests/conftest.py +1 -96
- package/content/skills/make-space/tests/make_space_support.py +99 -0
- package/content/skills/make-space/tests/test_make_space.py +2 -2
- package/content/skills/make-space/tests/test_scratch_cleanup.py +1 -1
- package/content/skills/make-space/tests/test_worktree_audit.py +1 -1
- package/content/skills/resale/CONTRACTS.md +43 -7
- package/content/skills/resale/README.md +104 -8
- package/content/skills/resale/SKILL.md +12 -4
- package/content/skills/resale/container/docker-compose.yml +14 -1
- package/content/skills/resale/prompts/comps_review.md +19 -0
- package/content/skills/resale/resale/analysis/bundle.py +63 -0
- package/content/skills/resale/resale/analysis/commands.py +30 -1
- package/content/skills/resale/resale/analysis/gather.py +8 -6
- package/content/skills/resale/resale/analysis/runner.py +19 -2
- package/content/skills/resale/resale/analysis/stats.py +15 -0
- package/content/skills/resale/resale/api_client.py +34 -0
- package/content/skills/resale/resale/cadence/__init__.py +2 -2
- package/content/skills/resale/resale/cadence/budget.py +37 -6
- package/content/skills/resale/resale/comps/commands.py +86 -0
- package/content/skills/resale/resale/comps/market_value.py +8 -4
- package/content/skills/resale/resale/comps/ranking.py +4 -2
- package/content/skills/resale/resale/comps/relevance.py +53 -2
- package/content/skills/resale/resale/comps/review_runner.py +200 -0
- package/content/skills/resale/resale/comps/specs.py +122 -0
- package/content/skills/resale/resale/conditions.py +12 -0
- package/content/skills/resale/resale/contracts/__init__.py +7 -1
- package/content/skills/resale/resale/contracts/comp_decisions.schema.json +22 -0
- package/content/skills/resale/resale/contracts/item_specs.schema.json +29 -0
- package/content/skills/resale/resale/db/migrations/0011_item_images.sql +25 -0
- package/content/skills/resale/resale/db/migrations/0012_page_images.sql +6 -0
- package/content/skills/resale/resale/db/migrations/0013_display_name_inbox.sql +9 -0
- package/content/skills/resale/resale/db/migrations/0014_listing_drafts.sql +16 -0
- package/content/skills/resale/resale/db/migrations/0015_post_kit.sql +14 -0
- package/content/skills/resale/resale/db/migrations/0016_comps_review.sql +12 -0
- package/content/skills/resale/resale/db/migrations/0017_search_terms.sql +1 -0
- package/content/skills/resale/resale/db/single_writer.py +2 -1
- package/content/skills/resale/resale/http_util.py +22 -0
- package/content/skills/resale/resale/portal/bundles.py +25 -9
- package/content/skills/resale/resale/portal/layout.py +108 -10
- package/content/skills/resale/resale/portal/market_cells.py +62 -8
- package/content/skills/resale/resale/portal/names.py +35 -0
- package/content/skills/resale/resale/portal/panel.py +65 -0
- package/content/skills/resale/resale/portal/photos.py +111 -0
- package/content/skills/resale/resale/portal/tablesort.py +3 -2
- package/content/skills/resale/resale/portal/views_analysis.py +82 -9
- package/content/skills/resale/resale/portal/views_items.py +210 -96
- package/content/skills/resale/resale/portal/views_misc.py +35 -3
- package/content/skills/resale/resale/portal/views_postkit.py +237 -0
- package/content/skills/resale/resale/portal/views_reader.py +7 -3
- package/content/skills/resale/resale/portal/views_search.py +5 -4
- package/content/skills/resale/resale/postkit/__init__.py +5 -0
- package/content/skills/resale/resale/postkit/drafts.py +222 -0
- package/content/skills/resale/resale/postkit/groups.py +45 -0
- package/content/skills/resale/resale/postkit/platforms.py +113 -0
- package/content/skills/resale/resale/postkit/posting.py +65 -0
- package/content/skills/resale/resale/postkit/pricing.py +87 -0
- package/content/skills/resale/resale/postkit/text.py +224 -0
- package/content/skills/resale/resale/publisher/pricing.py +2 -0
- package/content/skills/resale/resale/publisher/review.py +8 -1
- package/content/skills/resale/resale/receipts/links.py +50 -0
- package/content/skills/resale/resale/receipts/store.py +106 -10
- package/content/skills/resale/resale/service/app.py +10 -3
- package/content/skills/resale/resale/service/backup.py +362 -52
- package/content/skills/resale/resale/service/commands.py +98 -5
- package/content/skills/resale/resale/service/comp_gate.py +98 -0
- package/content/skills/resale/resale/service/comps_refresh.py +16 -0
- package/content/skills/resale/resale/service/comps_review.py +191 -0
- package/content/skills/resale/resale/service/comps_sanity.py +31 -0
- package/content/skills/resale/resale/service/comps_service.py +18 -10
- package/content/skills/resale/resale/service/display_names.py +69 -0
- package/content/skills/resale/resale/service/drafts.py +170 -0
- package/content/skills/resale/resale/service/ebay_follow.py +19 -0
- package/content/skills/resale/resale/service/ebay_poller.py +73 -21
- package/content/skills/resale/resale/service/fetch.py +80 -0
- package/content/skills/resale/resale/service/inventory_ops.py +38 -13
- package/content/skills/resale/resale/service/market.py +23 -14
- package/content/skills/resale/resale/service/multipart.py +13 -7
- package/content/skills/resale/resale/service/pageimage.py +83 -0
- package/content/skills/resale/resale/service/photo_inbox.py +141 -0
- package/content/skills/resale/resale/service/photos.py +138 -0
- package/content/skills/resale/resale/service/queries.py +94 -2
- package/content/skills/resale/resale/service/scheduler.py +46 -3
- package/content/skills/resale/resale/service/search_terms_plan.py +80 -0
- package/content/skills/resale/resale/service/server.py +241 -21
- package/content/skills/resale/resale/service/stock_photos.py +207 -0
- package/content/skills/resale/resale/settings.py +27 -0
- package/content/skills/resale/resale/sources/commands.py +1 -1
- package/content/skills/resale/resale/sources/craigslist.py +8 -2
- package/content/skills/resale/resale/sources/ebay.py +8 -4
- package/content/skills/resale/resale/sources/guards.py +3 -3
- package/content/skills/resale/resale/sources/model.py +4 -0
- package/content/skills/resale/resale/sources/runner.py +35 -9
- package/content/skills/resale/settings.example.env +13 -1
- package/content/skills/resale/tasks/comps_review_task.py +21 -0
- package/content/skills/resale/tasks/task_items.json +21 -2
- package/content/skills/resale/tests/conftest.py +1 -19
- package/content/skills/resale/tests/postkit_support.py +58 -0
- package/content/skills/resale/tests/resale_home_guard.py +19 -0
- package/content/skills/resale/tests/service_support.py +18 -2
- package/content/skills/resale/tests/test_analysis_service.py +7 -5
- package/content/skills/resale/tests/test_backup.py +351 -0
- package/content/skills/resale/tests/test_bundle.py +332 -0
- package/content/skills/resale/tests/test_cadence.py +29 -0
- package/content/skills/resale/tests/test_comps_relevance.py +10 -0
- package/content/skills/resale/tests/test_comps_review.py +443 -0
- package/content/skills/resale/tests/test_comps_review_task.py +221 -0
- package/content/skills/resale/tests/test_comps_specs.py +74 -0
- package/content/skills/resale/tests/test_conditions.py +7 -0
- package/content/skills/resale/tests/test_db.py +15 -0
- package/content/skills/resale/tests/test_display_names_apply.py +79 -0
- package/content/skills/resale/tests/test_ebay_live_quality.py +224 -0
- package/content/skills/resale/tests/test_isolation.py +3 -3
- package/content/skills/resale/tests/test_market_service.py +9 -6
- package/content/skills/resale/tests/test_market_trust.py +7 -4
- package/content/skills/resale/tests/test_market_value.py +11 -1
- package/content/skills/resale/tests/test_photo_inbox.py +147 -0
- package/content/skills/resale/tests/test_photos_fetch.py +84 -0
- package/content/skills/resale/tests/test_photos_service.py +264 -0
- package/content/skills/resale/tests/test_portal_bundle_fold.py +95 -0
- package/content/skills/resale/tests/test_portal_bundles.py +3 -3
- package/content/skills/resale/tests/test_portal_candidates.py +2 -2
- package/content/skills/resale/tests/test_portal_inplace.py +126 -0
- package/content/skills/resale/tests/test_portal_market.py +37 -11
- package/content/skills/resale/tests/test_portal_names.py +86 -0
- package/content/skills/resale/tests/test_portal_photos.py +150 -0
- package/content/skills/resale/tests/test_portal_postkit.py +181 -0
- package/content/skills/resale/tests/test_portal_split.py +211 -0
- package/content/skills/resale/tests/test_portal_theme.py +11 -3
- package/content/skills/resale/tests/test_postkit.py +528 -0
- package/content/skills/resale/tests/test_publisher_api.py +3 -1
- package/content/skills/resale/tests/test_publisher_commands.py +2 -0
- package/content/skills/resale/tests/test_publisher_pricing.py +5 -2
- package/content/skills/resale/tests/test_publisher_review.py +23 -1
- package/content/skills/resale/tests/test_reader_notify.py +1 -1
- package/content/skills/resale/tests/test_reader_parsers.py +17 -0
- package/content/skills/resale/tests/test_reader_query.py +63 -0
- package/content/skills/resale/tests/test_reader_runner.py +56 -0
- package/content/skills/resale/tests/test_reader_state_portal.py +14 -1
- package/content/skills/resale/tests/test_receipts_intake.py +95 -0
- package/content/skills/resale/tests/test_returns_intake.py +69 -0
- package/content/skills/resale/tests/test_search_terms.py +71 -0
- package/content/skills/resale/tests/test_search_terms_apply.py +76 -0
- package/content/skills/resale/tests/test_service_ebay.py +5 -4
- package/content/skills/resale/tests/test_service_http.py +76 -1
- package/content/skills/resale/tests/test_single_writer.py +9 -2
- package/content/skills/ship-the-code/SKILL.md +1 -1
- package/content/skills/ship-the-code/ship.py +47 -12
- package/content/skills/ship-the-code/tests/test_ship_worktree_push.py +191 -0
- package/lib/bundleBackup.js +84 -0
- package/lib/bundleHeartbeat.js +41 -0
- package/lib/bundleRuntime.js +11 -2
- package/lib/bundleRuntimeStep.js +1 -0
- package/lib/containerItems.js +15 -3
- package/lib/manifest.js +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -457,6 +457,17 @@ values exist. The compose process sees the install base as
|
|
|
457
457
|
every secret the bundle declares as an environment variable, so a compose file
|
|
458
458
|
can use `${NAME}` interpolation.
|
|
459
459
|
|
|
460
|
+
**Backup.** A bundle whose service writes a nightly backup declares
|
|
461
|
+
`"backup": {"dirSetting", "defaultDir", "pattern", "maxAgeHours"}` in the manifest. `dirSetting` is the key in the bundle's
|
|
462
|
+
settings file that holds the host folder (`~` expands; empty falls back to `<install base>/<defaultDir>`). Install creates
|
|
463
|
+
the folder (default install only) and compose receives it as `AGENTS_BUNDLE_BACKUP_DIR` to bind-mount; compose also gets
|
|
464
|
+
the PC's IANA time zone as `AGENTS_HOST_TZ`. `doctor` reports a finding when the folder is missing, holds no file matching
|
|
465
|
+
`pattern`, or the newest match is older than `maxAgeHours`.
|
|
466
|
+
|
|
467
|
+
**Heartbeat.** A bundle whose hidden task keeps a state file declares
|
|
468
|
+
`"heartbeat": {"label", "file", "maxAgeHours"}` (`file` relative to the install base). `doctor` reports a finding when
|
|
469
|
+
the file is missing, older than `maxAgeHours`, or its `last_status` is `failed` (with `last_error`).
|
|
470
|
+
|
|
460
471
|
**Switches.** `--no-containers` (or `AGENTS_CLI_NO_CONTAINERS=1`) and
|
|
461
472
|
`--no-scheduled-tasks` (or `AGENTS_CLI_NO_SCHEDULED_TASKS=1`). Containers and
|
|
462
473
|
tasks are machine-wide, so they are only managed for the default `~/.claude`
|
package/content/manifest.json
CHANGED
|
@@ -2599,6 +2599,22 @@
|
|
|
2599
2599
|
},
|
|
2600
2600
|
"note": "Hidden Windows logon task; the script is shipped by the skill item above."
|
|
2601
2601
|
},
|
|
2602
|
+
{
|
|
2603
|
+
"path": "skills/resale/tasks/comps_review_task.py",
|
|
2604
|
+
"kind": "task",
|
|
2605
|
+
"wiring": {
|
|
2606
|
+
"name": "ResaleCompsReview",
|
|
2607
|
+
"exe": "pythonw",
|
|
2608
|
+
"args": [
|
|
2609
|
+
"{{TARGET}}/skills/resale/tasks/comps_review_task.py"
|
|
2610
|
+
],
|
|
2611
|
+
"workingDirectory": "{{TARGET}}/skills/resale",
|
|
2612
|
+
"description": "Resale comps review: headless Claude (no tools) judges new comps after each reader run, only when comps wait (hidden)",
|
|
2613
|
+
"logonDelay": "PT5M",
|
|
2614
|
+
"repeat": "PT15M"
|
|
2615
|
+
},
|
|
2616
|
+
"note": "Hidden Windows logon task; the script is shipped by the skill item above. Needs the claude CLI on PATH; without it comps stay awaiting review and prices stay pending."
|
|
2617
|
+
},
|
|
2602
2618
|
{
|
|
2603
2619
|
"path": "skills/resale/tasks/notifier_task.py",
|
|
2604
2620
|
"kind": "task",
|
|
@@ -2727,6 +2743,17 @@
|
|
|
2727
2743
|
"example": "skills/resale/settings.example.env",
|
|
2728
2744
|
"target": "resale/settings.env"
|
|
2729
2745
|
},
|
|
2746
|
+
"backup": {
|
|
2747
|
+
"dirSetting": "RESALE_BACKUP_DIR",
|
|
2748
|
+
"defaultDir": "resale/backups",
|
|
2749
|
+
"pattern": "^resale-\\d{8}-\\d{4}\\.zip$",
|
|
2750
|
+
"maxAgeHours": 26
|
|
2751
|
+
},
|
|
2752
|
+
"heartbeat": {
|
|
2753
|
+
"label": "resale comps review task (ResaleCompsReview)",
|
|
2754
|
+
"file": "resale/data/comps_review.json",
|
|
2755
|
+
"maxAgeHours": 3
|
|
2756
|
+
},
|
|
2730
2757
|
"prerequisites": [
|
|
2731
2758
|
{
|
|
2732
2759
|
"name": "Python with the Playwright package (the host reader and edit script)",
|
|
@@ -2737,6 +2764,15 @@
|
|
|
2737
2764
|
],
|
|
2738
2765
|
"hint": "python -m pip install playwright"
|
|
2739
2766
|
},
|
|
2767
|
+
{
|
|
2768
|
+
"name": "Claude Code CLI (the comps review task runs headless claude)",
|
|
2769
|
+
"anyPath": [
|
|
2770
|
+
"%APPDATA%\\npm\\claude.cmd",
|
|
2771
|
+
"%USERPROFILE%\\.local\\bin\\claude.exe",
|
|
2772
|
+
"%USERPROFILE%\\.local\\bin\\claude"
|
|
2773
|
+
],
|
|
2774
|
+
"hint": "install Claude Code (npm install -g @anthropic-ai/claude-code) so claude is on PATH"
|
|
2775
|
+
},
|
|
2740
2776
|
{
|
|
2741
2777
|
"name": "Google Chrome installed (the reader drives the installed Chrome)",
|
|
2742
2778
|
"platforms": [
|
|
@@ -74,6 +74,29 @@
|
|
|
74
74
|
"target": { "type": "string", "minLength": 1, "description": "Path relative to the install base, POSIX separators, e.g. resale/settings.env." }
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
+
"backup": {
|
|
78
|
+
"description": "Nightly backup the bundle's service writes into a host folder. `dirSetting` is the key in the bundle's settings file that holds the folder (default `defaultDir` under the install base); install creates the folder and the compose file bind-mounts it through AGENTS_BUNDLE_BACKUP_DIR; doctor warns when no file matching `pattern` is newer than `maxAgeHours`.",
|
|
79
|
+
"type": "object",
|
|
80
|
+
"additionalProperties": false,
|
|
81
|
+
"required": ["dirSetting", "defaultDir", "pattern", "maxAgeHours"],
|
|
82
|
+
"properties": {
|
|
83
|
+
"dirSetting": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
|
84
|
+
"defaultDir": { "type": "string", "minLength": 1, "description": "Path relative to the install base, POSIX separators, e.g. resale/backups." },
|
|
85
|
+
"pattern": { "type": "string", "minLength": 1, "description": "Regular expression a backup file name must match." },
|
|
86
|
+
"maxAgeHours": { "type": "number", "exclusiveMinimum": 0 }
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"heartbeat": {
|
|
90
|
+
"description": "A host task that rewrites a small JSON state file on every tick; doctor warns when the file is missing, older than `maxAgeHours`, or its `last_status` is failed.",
|
|
91
|
+
"type": "object",
|
|
92
|
+
"additionalProperties": false,
|
|
93
|
+
"required": ["label", "file", "maxAgeHours"],
|
|
94
|
+
"properties": {
|
|
95
|
+
"label": { "type": "string", "minLength": 1 },
|
|
96
|
+
"file": { "type": "string", "minLength": 1, "description": "Path relative to the install base, POSIX separators, e.g. resale/data/comps_review.json." },
|
|
97
|
+
"maxAgeHours": { "type": "number", "exclusiveMinimum": 0 }
|
|
98
|
+
}
|
|
99
|
+
},
|
|
77
100
|
"prerequisites": {
|
|
78
101
|
"description": "Machine requirements the install checks and doctor re-checks, reported with the hint, never installed or blocking: each is a `command` (+ `args`) that must exit 0, or `anyPath` (any one existing file; %VAR% expanded). `platforms` limits it to process.platform values.",
|
|
79
102
|
"type": "array",
|
|
@@ -30,6 +30,7 @@ Gmail access is read-only. Scope `gmail.readonly` only, a three-call allowlist (
|
|
|
30
30
|
| Rule | Where | Test |
|
|
31
31
|
|---|---|---|
|
|
32
32
|
| Proof of purchase: a message is a purchase only when it is an order confirmation, receipt or invoice with an order number and a total or payment line; a PDF invoice attachment counts as proof. Promos, newsletters, carts, review requests, price drops, quotes and shipping mail without a confirmed order are not purchases; cancelled, returned or refunded orders are voided by order number | `purchases/proof.py`, `proof` block in `vendors.json` | `test_proof.py` (real subjects) |
|
|
33
|
+
| Returns and refunds: a vendor's `void_senders` (Amazon `return@amazon.com`) are always void mail and always fetched (own search query, counted as an order sender); the order number is read from the `orderId=` link of the plain-text part when the visible text names none; `proof.void_product(subject)` returns the product a return, refund or cancellation subject names (None for an order-level notice or a multi-item cancellation) so a consumer voids only that item | `purchases/proof.py`, `purchases/parse.py`, `purchases/scan.py`, `void_senders` in `vendors.json` | `test_returns.py` (real subjects and bodies) |
|
|
33
34
|
| Filter at the source: the Gmail query leaves out promotions, social and forums and asks each vendor for its order senders only (`order_senders` in `vendors.json`); marketing senders are skipped with a counted reason; `scan_purchases` returns one `OrderRecord` per proven order (merchant, order number, date, total, items, proof type, message id) and `PurchaseScan.skipped` counts what was left out; `proven_only=True` hands nothing unproven to the caller | `purchases/scan.py`, `purchases/proof.py` | `test_source_filter.py` |
|
|
34
35
|
| Paid is the net after discounts: item discount line, or the order discount when one item's list price equals the subtotal; any other order-level discount leaves it unverified | `purchases/parse.py` | `test_prices.py` |
|
|
35
36
|
| Recall: storefront order mail (`Order #X confirmed`, `<name> × N` summary, `x 1` and `Quantity:` layouts, `$net $list` sale line, unclosed `<head>`, invoice PDF named after the order) is fetched and named from the product line, not the variant or SKU | `scan.py` queries, `parse.py`, `htmltext.py`, `proof.py`, vendors `order_senders` | `test_recall.py` |
|
|
@@ -18,12 +18,20 @@ class Image:
|
|
|
18
18
|
alt: str = ""
|
|
19
19
|
width: int | None = None
|
|
20
20
|
height: int | None = None
|
|
21
|
+
href: str | None = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Link:
|
|
26
|
+
href: str
|
|
27
|
+
text: str
|
|
21
28
|
|
|
22
29
|
|
|
23
30
|
@dataclass
|
|
24
31
|
class Line:
|
|
25
32
|
text: str
|
|
26
33
|
images: list[Image] = field(default_factory=list)
|
|
34
|
+
links: list[Link] = field(default_factory=list)
|
|
27
35
|
|
|
28
36
|
|
|
29
37
|
def _size(value: str | None) -> int | None:
|
|
@@ -37,6 +45,9 @@ class _Flattener(HTMLParser):
|
|
|
37
45
|
self.lines: list[Line] = []
|
|
38
46
|
self._buffer: list[str] = []
|
|
39
47
|
self._images: list[Image] = []
|
|
48
|
+
self._links: list[Link] = []
|
|
49
|
+
self._href: str | None = None
|
|
50
|
+
self._href_text: list[str] = []
|
|
40
51
|
self._skip = 0
|
|
41
52
|
self._amount_tag: str | None = None
|
|
42
53
|
self._amount_depth = 0
|
|
@@ -45,8 +56,8 @@ class _Flattener(HTMLParser):
|
|
|
45
56
|
text = SPACE.sub(" ", "".join(self._buffer)).strip(" |")
|
|
46
57
|
text = re.sub(r"(\s*\|\s*)+", " | ", text).strip(" |")
|
|
47
58
|
if text or self._images:
|
|
48
|
-
self.lines.append(Line(text, self._images))
|
|
49
|
-
self._buffer, self._images = [], []
|
|
59
|
+
self.lines.append(Line(text, self._images, self._links))
|
|
60
|
+
self._buffer, self._images, self._links = [], [], []
|
|
50
61
|
|
|
51
62
|
def handle_starttag(self, tag, attrs):
|
|
52
63
|
if self._amount_tag:
|
|
@@ -68,10 +79,13 @@ class _Flattener(HTMLParser):
|
|
|
68
79
|
self._flush()
|
|
69
80
|
elif tag in CELL_TAGS:
|
|
70
81
|
self._buffer.append(" | ")
|
|
82
|
+
elif tag == "a":
|
|
83
|
+
href = (dict(attrs).get("href") or "").strip()
|
|
84
|
+
self._href, self._href_text = (href if href.lower().startswith("https://") else None), []
|
|
71
85
|
elif tag == "img":
|
|
72
86
|
attr = dict(attrs)
|
|
73
87
|
if attr.get("src"):
|
|
74
|
-
self._images.append(Image(attr["src"].strip(), attr.get("alt") or "", _size(attr.get("width")), _size(attr.get("height"))))
|
|
88
|
+
self._images.append(Image(attr["src"].strip(), attr.get("alt") or "", _size(attr.get("width")), _size(attr.get("height")), self._href))
|
|
75
89
|
|
|
76
90
|
def handle_endtag(self, tag):
|
|
77
91
|
if self._amount_tag:
|
|
@@ -82,12 +96,18 @@ class _Flattener(HTMLParser):
|
|
|
82
96
|
return
|
|
83
97
|
if tag in SKIP_TAGS:
|
|
84
98
|
self._skip = max(0, self._skip - 1)
|
|
99
|
+
elif tag == "a" and not self._skip:
|
|
100
|
+
if self._href:
|
|
101
|
+
self._links.append(Link(self._href, SPACE.sub(" ", "".join(self._href_text)).strip()))
|
|
102
|
+
self._href = None
|
|
85
103
|
elif not self._skip and tag in BLOCK_TAGS:
|
|
86
104
|
self._flush()
|
|
87
105
|
|
|
88
106
|
def handle_data(self, data):
|
|
89
107
|
if not self._skip and not self._amount_tag:
|
|
90
108
|
self._buffer.append(data.replace("\n", " "))
|
|
109
|
+
if self._href:
|
|
110
|
+
self._href_text.append(data.replace("\n", " "))
|
|
91
111
|
|
|
92
112
|
|
|
93
113
|
def html_lines(html: str) -> list[Line]:
|
|
@@ -47,7 +47,7 @@ QTY = re.compile(r"(?:\bqty\b|\bquantity\b)\s*[:.]?\s*(\d{1,2})|\b(\d{1,2})\s*[x
|
|
|
47
47
|
WAS = re.compile(r"\b(was|reg(?:ular)?|orig(?:inal)?|list)\b", re.I)
|
|
48
48
|
JUNK_IMAGE = re.compile(
|
|
49
49
|
r"logo|spacer|pixel|track|beacon|badge|icon|facebook|twitter|instagram|pinterest|footer|banner|button|arrow|"
|
|
50
|
-
r"social|open\.gif|blank|1x1|transparent|header|app-store|googleplay|youtube|barcode",
|
|
50
|
+
r"social|open\.gif|blank|1x1|transparent|header|app-store|googleplay|youtube|barcode|discounttag|themes_support",
|
|
51
51
|
re.I,
|
|
52
52
|
)
|
|
53
53
|
MODEL_TOKEN = re.compile(r"\b(?=[A-Za-z0-9-]*\d)(?=[A-Za-z0-9-]*[A-Za-z])[A-Za-z0-9][A-Za-z0-9-]{2,}\b")
|
|
@@ -72,6 +72,7 @@ class LineItem:
|
|
|
72
72
|
brand: str | None = None
|
|
73
73
|
model: str | None = None
|
|
74
74
|
image_url: str | None = None
|
|
75
|
+
product_url: str | None = None
|
|
75
76
|
hidden_reason: str | None = None
|
|
76
77
|
list_price_cents: int | None = None
|
|
77
78
|
discount_cents: int | None = None
|
|
@@ -188,6 +189,32 @@ def _find_image(lines: list[Line], start: int, end: int, used: set[str]) -> str
|
|
|
188
189
|
return None
|
|
189
190
|
|
|
190
191
|
|
|
192
|
+
JUNK_LINK = re.compile(r"unsubscribe|privacy|terms|mailto:|/help|support|survey|returns?\b|track|invoice|order[-_/ ]?(status|details?|history)|your[-_]?orders?|signin|sign-in|login|account", re.I)
|
|
193
|
+
LINK_WORD = re.compile(r"[a-z0-9]{3,}")
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _good_link(href: str | None) -> bool:
|
|
197
|
+
return bool(href) and href.lower().startswith("https://") and not JUNK_LINK.search(href)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _find_link(lines: list[Line], start: int, end: int, name: str, image: str | None) -> str | None:
|
|
201
|
+
"""The product page of an item: the link around its picture, else the link in its rows whose text shares the most words with the name."""
|
|
202
|
+
window = range(max(0, start - 1), min(end, len(lines) - 1) + 1)
|
|
203
|
+
if image:
|
|
204
|
+
for index in window:
|
|
205
|
+
for picture in lines[index].images:
|
|
206
|
+
if picture.src == image and _good_link(picture.href):
|
|
207
|
+
return picture.href
|
|
208
|
+
words = set(LINK_WORD.findall(name.lower()))
|
|
209
|
+
best, best_score = None, 0
|
|
210
|
+
for index in window:
|
|
211
|
+
for link in lines[index].links:
|
|
212
|
+
score = len(words & set(LINK_WORD.findall(link.text.lower())))
|
|
213
|
+
if _good_link(link.href) and score > best_score and (score >= 2 or (len(words) <= 2 and score >= 1)):
|
|
214
|
+
best, best_score = link.href, score
|
|
215
|
+
return best
|
|
216
|
+
|
|
217
|
+
|
|
191
218
|
def brand_and_model(name: str, store_brand: str | None = None) -> tuple[str | None, str | None]:
|
|
192
219
|
lowered = name.lower()
|
|
193
220
|
brand = None
|
|
@@ -237,7 +264,8 @@ def _shopify_items(lines: list[Line], store_brand: str | None) -> list[LineItem]
|
|
|
237
264
|
list_total = _money(coded.text.rsplit("|", 1)[-1]) if coded else net_total
|
|
238
265
|
brand, model = brand_and_model(name, store_brand)
|
|
239
266
|
unit = lambda total: (total + qty // 2) // qty
|
|
240
|
-
|
|
267
|
+
picture = _find_image(lines, start, start + 1, set())
|
|
268
|
+
item = LineItem(name, unit(net_total), qty, brand, model, picture, _find_link(lines, start, start + 1, name, picture),
|
|
241
269
|
list_price_cents=unit(list_total), net_cents=unit(net_total))
|
|
242
270
|
item._variant = next((t for t in variant if not STOCK_VARIANT.match(t)), "")
|
|
243
271
|
if coded is not None and list_total > net_total:
|
|
@@ -304,7 +332,8 @@ def _extract_items(lines: list[Line], store_brand: str | None = None) -> list[Li
|
|
|
304
332
|
if image:
|
|
305
333
|
used_images.add(image)
|
|
306
334
|
brand, model = brand_and_model(name, store_brand)
|
|
307
|
-
item = LineItem(name, price, qty, brand, model, image,
|
|
335
|
+
item = LineItem(name, price, qty, brand, model, image, _find_link(lines, name_index, index, name, image),
|
|
336
|
+
list_price_cents=price, net_cents=price)
|
|
308
337
|
item.proof_lines = [t for t in dict.fromkeys([lines[name_index].text, line.text]) if t]
|
|
309
338
|
items.append(item)
|
|
310
339
|
placed.append((item, name_index, index))
|
|
@@ -467,7 +496,8 @@ def _unpriced_items(lines: list[Line], total: int | None, store_brand: str | Non
|
|
|
467
496
|
used.add(image)
|
|
468
497
|
brand, model = brand_and_model(name, store_brand)
|
|
469
498
|
single = len(found) == 1
|
|
470
|
-
item = LineItem(name, total if single else None, qty, brand, model, image,
|
|
499
|
+
item = LineItem(name, total if single else None, qty, brand, model, image, _find_link(lines, line_index, line_index, name, image),
|
|
500
|
+
list_price_cents=total if single else None,
|
|
471
501
|
net_cents=total if single else None, price_basis="order_total" if single else "unpriced")
|
|
472
502
|
item.proof_lines = [lines[line_index].text]
|
|
473
503
|
items.append(item)
|
|
@@ -502,6 +532,21 @@ def _order_ref(subject: str, text: str, vendor: dict | None) -> str | None:
|
|
|
502
532
|
return None
|
|
503
533
|
|
|
504
534
|
|
|
535
|
+
ORDER_LINK = re.compile(r"order[_-]?id=", re.I)
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def _order_ref_from_links(raw: str, vendor: dict | None) -> str | None:
|
|
539
|
+
"""The order number in an `orderId=` link of the raw mail, for messages whose visible text names none (Amazon return and refund mail)."""
|
|
540
|
+
if not (vendor and vendor.get("order_ref")):
|
|
541
|
+
return None
|
|
542
|
+
pattern = re.compile(vendor["order_ref"])
|
|
543
|
+
for link in ORDER_LINK.finditer(raw):
|
|
544
|
+
hit = pattern.match(raw, link.end())
|
|
545
|
+
if hit:
|
|
546
|
+
return hit.group(0)
|
|
547
|
+
return None
|
|
548
|
+
|
|
549
|
+
|
|
505
550
|
def parse_receipt(message: Message) -> ParsedReceipt:
|
|
506
551
|
merchant, key = merchant_of(message.headers.get("from", ""))
|
|
507
552
|
vendor = data.vendor_for_domain(sender_domain(message.headers.get("from", ""))) if key else None
|
|
@@ -529,7 +574,8 @@ def parse_receipt(message: Message) -> ParsedReceipt:
|
|
|
529
574
|
if key == "paypal":
|
|
530
575
|
items = [i for i in items if any("qty" in t.lower() for t in i.proof_lines) and i.name.lower() != merchant.lower()
|
|
531
576
|
and not re.match(r"you (?:sent|authori[sz]ed|paid)\b", i.name, re.I) and "@" not in i.name]
|
|
532
|
-
|
|
577
|
+
order_ref = _order_ref(subject, text, vendor) or _order_ref_from_links((message.text or "") + " " + (message.html or ""), vendor)
|
|
578
|
+
parsed = ParsedReceipt(merchant, key, order_ref, total, items)
|
|
533
579
|
finalize_prices(parsed, lines)
|
|
534
580
|
found = proof_rules.classify(subject, message.headers.get("from", ""), text, parsed.order_ref, total, message.attachments)
|
|
535
581
|
parsed.proof, parsed.proof_reason, parsed.attachment = found.type, found.reason, found.attachment
|
|
@@ -40,7 +40,24 @@ def is_void(subject: str, from_header: str = "") -> bool:
|
|
|
40
40
|
vendor_rules = _vendor_rules(from_header)
|
|
41
41
|
if sender_address(from_header) in vendor_rules.get("confirmation_senders", []):
|
|
42
42
|
return False
|
|
43
|
-
return _void_subject(clean_subject(subject))
|
|
43
|
+
return is_void_sender(from_header) or _void_subject(clean_subject(subject))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
VOID_PRODUCT = re.compile(
|
|
47
|
+
r"^(?:your\s+(?:return|refund)\s+(?:of|for)|return received for|return request confirmed for|dropoff confirmed for|advance refund issued for)\s+(?P<name>.+)$"
|
|
48
|
+
r'|\border of\s+"(?P<quoted>[^"]+)"',
|
|
49
|
+
re.I,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def void_product(subject: str) -> str | None:
|
|
54
|
+
"""The product a return, refund or cancellation mail names in its subject (cut where Amazon adds its ellipsis), or None for an order-level notice."""
|
|
55
|
+
subject = re.sub(r"\s+", " ", clean_subject(subject).replace("\N{REPLACEMENT CHARACTER}", " ")).strip()
|
|
56
|
+
found = VOID_PRODUCT.search(subject)
|
|
57
|
+
if not found or re.search(r"\band \d+ more items?\b", subject, re.I):
|
|
58
|
+
return None
|
|
59
|
+
name = (found.group("name") or found.group("quoted")).strip(" .\N{HORIZONTAL ELLIPSIS}")
|
|
60
|
+
return None if len(name) < 6 or re.match(r"amazon(?:\.com)? order\b", name, re.I) else name
|
|
44
61
|
|
|
45
62
|
|
|
46
63
|
def _void_subject(subject: str) -> bool:
|
|
@@ -54,8 +71,15 @@ def _vendor_rules(from_header: str) -> dict:
|
|
|
54
71
|
return (vendor or {}).get("proof", {})
|
|
55
72
|
|
|
56
73
|
|
|
74
|
+
def is_void_sender(from_header: str) -> bool:
|
|
75
|
+
"""True for a sender that only mails returns, refunds and cancellations (listed as `void_senders`), whatever the subject says."""
|
|
76
|
+
return sender_address(from_header) in _vendor_rules(from_header).get("void_senders", [])
|
|
77
|
+
|
|
78
|
+
|
|
57
79
|
def is_order_sender(from_header: str) -> bool:
|
|
58
|
-
"""False when the vendor lists its order senders and this is another of its senders (marketing); vendors without a list accept any sender."""
|
|
80
|
+
"""False when the vendor lists its order senders and this is another of its senders (marketing); vendors without a list accept any sender. A void sender always counts."""
|
|
81
|
+
if is_void_sender(from_header):
|
|
82
|
+
return True
|
|
59
83
|
allowed = _vendor_rules(from_header).get("order_senders")
|
|
60
84
|
if not allowed:
|
|
61
85
|
return True
|
|
@@ -93,7 +117,7 @@ def classify(subject: str, from_header: str, body_text: str, order_ref: str | No
|
|
|
93
117
|
confirmation_sender = address in vendor.get("confirmation_senders", [])
|
|
94
118
|
attachment = invoice_attachment(attachments or [], order_ref, subject)
|
|
95
119
|
if not confirmation_sender:
|
|
96
|
-
if _void_subject(subject):
|
|
120
|
+
if is_void_sender(from_header) or _void_subject(subject):
|
|
97
121
|
return Proof("void", "cancelled, returned or refunded")
|
|
98
122
|
if rules["promo_subject"].search(subject) or rules["promo_sender"].search(address):
|
|
99
123
|
return Proof("none", "promotional or marketing mail")
|
|
@@ -89,7 +89,9 @@ def receipt_queries(since_epoch: int, vendor_data: dict | None = None) -> list[s
|
|
|
89
89
|
sender_listed = exclude
|
|
90
90
|
exclude += " -category:promotions -category:social -category:forums"
|
|
91
91
|
words = _any(vendor_data["subject_words"])
|
|
92
|
-
|
|
92
|
+
void_senders = [s for v in vendor_data["vendors"] for s in v.get("proof", {}).get("void_senders", [])]
|
|
93
|
+
queries = [f"from:{_any(group)} {after}" for group in _group(void_senders, DOMAINS_PER_QUERY)]
|
|
94
|
+
queries += [f"from:{_any(group)} subject:{words} {sender_listed} {after}" for group in _group(listed, DOMAINS_PER_QUERY)]
|
|
93
95
|
queries += [f"from:{_any(group)} subject:{words} {exclude} {after}" for group in _group(unlisted, DOMAINS_PER_QUERY)]
|
|
94
96
|
queries.append(f"subject:{_any(vendor_data['generic_subject_phrases'])} {exclude} {after}")
|
|
95
97
|
queries.append(f"subject:(order confirmed) {exclude} {after}")
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import io
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
|
-
import tempfile
|
|
5
4
|
from pathlib import Path
|
|
6
5
|
|
|
7
6
|
import pytest
|
|
@@ -10,6 +9,7 @@ ROOT = Path(__file__).resolve().parent.parent
|
|
|
10
9
|
sys.path.insert(0, str(ROOT))
|
|
11
10
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
12
11
|
|
|
12
|
+
from gmail_home_guard import under_real_claude # noqa: E402
|
|
13
13
|
from gmail_reader import credentials # noqa: E402
|
|
14
14
|
|
|
15
15
|
|
|
@@ -21,24 +21,6 @@ def hermetic_secrets(monkeypatch, tmp_path):
|
|
|
21
21
|
monkeypatch.delenv("GOOGLE_OAUTH_TOKEN_FILE", raising=False)
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
REAL_HOME = Path.home().resolve()
|
|
25
|
-
REAL_CLAUDE = REAL_HOME / ".claude"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
TEMP_ROOT = Path(tempfile.gettempdir()).resolve()
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def under_real_claude(target) -> bool:
|
|
32
|
-
"""True for a path in the real ~/.claude, except inside the temp folder (a heavy gate keeps its temp dir there)."""
|
|
33
|
-
try:
|
|
34
|
-
path = Path(target).resolve()
|
|
35
|
-
except (OSError, TypeError, ValueError):
|
|
36
|
-
return False
|
|
37
|
-
if TEMP_ROOT != REAL_CLAUDE and (path == TEMP_ROOT or TEMP_ROOT in path.parents):
|
|
38
|
-
return False
|
|
39
|
-
return path == REAL_CLAUDE or REAL_CLAUDE in path.parents
|
|
40
|
-
|
|
41
|
-
|
|
42
24
|
@pytest.fixture(autouse=True)
|
|
43
25
|
def isolated_home(monkeypatch, tmp_path_factory):
|
|
44
26
|
"""No test reads the founder's secrets or token: home points into a temporary folder."""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import tempfile
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
REAL_HOME = Path.home().resolve()
|
|
5
|
+
REAL_CLAUDE = REAL_HOME / ".claude"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
TEMP_ROOT = Path(tempfile.gettempdir()).resolve()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def under_real_claude(target) -> bool:
|
|
12
|
+
"""True for a path in the real ~/.claude, except inside the temp folder (a heavy gate keeps its temp dir there)."""
|
|
13
|
+
try:
|
|
14
|
+
path = Path(target).resolve()
|
|
15
|
+
except (OSError, TypeError, ValueError):
|
|
16
|
+
return False
|
|
17
|
+
if TEMP_ROOT != REAL_CLAUDE and (path == TEMP_ROOT or TEMP_ROOT in path.parents):
|
|
18
|
+
return False
|
|
19
|
+
return path == REAL_CLAUDE or REAL_CLAUDE in path.parents
|
|
@@ -186,3 +186,38 @@ def test_sams_club_receipt_transaction_number_is_the_order_number():
|
|
|
186
186
|
text = "Here's your Sam's Club receipt\nTC# 81843753112199447885\nRL TEE\n$10.98\nTotal | $66.84"
|
|
187
187
|
parsed = parse_receipt(message("s1", "Sam's Club <transaction@info.samsclub.com>", "Your Sam's Club Receipt", text=text))
|
|
188
188
|
assert parsed.order_ref == "81843753112199447885" and parsed.proof == "receipt"
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def test_product_link_is_the_link_around_the_picture():
|
|
192
|
+
html = (
|
|
193
|
+
'<div><a href="https://shop.example-cdn.test/p/orion-starblast"><img src="https://img.example-cdn.test/t.jpg" alt="Telescope" width="100"></a>'
|
|
194
|
+
'<a href="https://shop.example-cdn.test/account/orders">View your orders</a>'
|
|
195
|
+
"<div>Orion StarBlast 4.5 Astro Telescope</div><div>$229.99</div></div>"
|
|
196
|
+
)
|
|
197
|
+
parsed = parse_receipt(message("m1c", "Shop <a@shop-example.test>", "Your order", html=html))
|
|
198
|
+
assert parsed.items[0].product_url == "https://shop.example-cdn.test/p/orion-starblast"
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def test_product_link_falls_back_to_the_link_whose_text_names_the_item_and_never_takes_account_links():
|
|
202
|
+
html = (
|
|
203
|
+
'<div><a href="https://shop.example-cdn.test/track/123">Track your package</a>'
|
|
204
|
+
'<div><a href="https://shop.example-cdn.test/p/starblast">Orion StarBlast 4.5 Astro Telescope</a></div><div>$229.99</div></div>'
|
|
205
|
+
)
|
|
206
|
+
parsed = parse_receipt(message("m1d", "Shop <a@shop-example.test>", "Your order", html=html))
|
|
207
|
+
assert parsed.items[0].product_url == "https://shop.example-cdn.test/p/starblast"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def test_item_without_a_product_link_has_none_and_http_links_are_ignored():
|
|
211
|
+
html = ('<div><a href="http://shop.example-cdn.test/p/starblast">Orion StarBlast 4.5 Astro Telescope</a></div><div>$229.99</div>')
|
|
212
|
+
parsed = parse_receipt(message("m1e", "Shop <a@shop-example.test>", "Your order", html=html))
|
|
213
|
+
assert parsed.status == "parsed" and parsed.items[0].product_url is None
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_storefront_notification_badge_images_are_never_the_item_picture():
|
|
217
|
+
html = (
|
|
218
|
+
'<div><img src="https://cdn.shopify.com/shopifycloud/shopify/assets/themes_support/notifications/discounttag-d1f7c6d9.png" width="20">'
|
|
219
|
+
'<img src="https://img.example-cdn.test/t.jpg" alt="Telescope" width="100">'
|
|
220
|
+
"<div>Orion StarBlast 4.5 Astro Telescope</div><div>$229.99</div></div>"
|
|
221
|
+
)
|
|
222
|
+
parsed = parse_receipt(message("m1f", "Shop <a@shop-example.test>", "Your order", html=html))
|
|
223
|
+
assert parsed.items[0].image_url == "https://img.example-cdn.test/t.jpg"
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from receipt_fixtures import message
|
|
3
|
+
|
|
4
|
+
from gmail_reader.purchases import proof, scan_purchases
|
|
5
|
+
from gmail_reader.purchases.scan import receipt_queries
|
|
6
|
+
from gmail_reader.testing import FakeGmail
|
|
7
|
+
|
|
8
|
+
NOW = 1_763_100_000
|
|
9
|
+
RETURN = '"return@amazon.com" <return@amazon.com>'
|
|
10
|
+
|
|
11
|
+
REFUND_BODY = """Hello Founder,
|
|
12
|
+
|
|
13
|
+
We've received the item below and have issued your refund. Thank you for sending the item back. Your return is now complete.
|
|
14
|
+
|
|
15
|
+
View return & refund status :
|
|
16
|
+
https://www.amazon.com/gp/your-account/order-details?orderID=111-5095344-6551466&ref_=E_CReturnsRefundConfirmation_OrderDetail
|
|
17
|
+
|
|
18
|
+
Item details:
|
|
19
|
+
Tripod for Camera, 72" Tall...
|
|
20
|
+
|
|
21
|
+
Refund total: $38.96*
|
|
22
|
+
Refund will appear on your Visa in 3-5 business days.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
RETURN_BODY = """Hello Founder,
|
|
26
|
+
|
|
27
|
+
We've accepted your return request. Once we receive the item below, we'll issue your refund.
|
|
28
|
+
|
|
29
|
+
Check return & refund status:
|
|
30
|
+
https://www.amazon.com/spr/returns/cart?orderId=111-9840370-6048264&ref_=E_RRT_status
|
|
31
|
+
|
|
32
|
+
Item details:
|
|
33
|
+
- BARSKA Binocular Tripod Adaptor...
|
|
34
|
+
|
|
35
|
+
Estimated refund: $15.14*
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
# the HTML part of Amazon's return mails carries no order number (tracked links); only the plain-text part names it
|
|
39
|
+
HTML = "<div>Your return is now complete</div><div>Item details</div><div>Refund total: $38.96</div>"
|
|
40
|
+
|
|
41
|
+
# real subjects from return@amazon.com (the sender mails nothing but returns and refunds)
|
|
42
|
+
REAL_RETURN_SUBJECTS = [
|
|
43
|
+
'Your return of Tripod for Camera, 72" Tall...',
|
|
44
|
+
'Your refund for Tripod for Camera, 72" Tall....',
|
|
45
|
+
"Your return of BARSKA Binocular Tripod Adaptor...",
|
|
46
|
+
"Your refund for BARSKA Binocular Tripod Adaptor....",
|
|
47
|
+
"Your refund for Lightdow T/T2 Mount Lens Adapter....",
|
|
48
|
+
"Return received for CAP Barbell 40 LB Coated Hex....",
|
|
49
|
+
"Return request confirmed for Govee Smart Plug 15A, WiFi...",
|
|
50
|
+
"Dropoff confirmed for Govee Smart Plug 15A, WiFi...",
|
|
51
|
+
"Advance refund issued for Govee Smart Plug 15A, WiFi....",
|
|
52
|
+
"Your return summary",
|
|
53
|
+
"Your refund confirmation",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
# Amazon's own wording for the same events
|
|
57
|
+
PATTERN_SUBJECTS = ["Your return is complete", "Your refund has been issued", "Return request confirmation"]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.mark.parametrize("subject", REAL_RETURN_SUBJECTS + PATTERN_SUBJECTS)
|
|
61
|
+
def test_every_mail_from_the_return_sender_voids_its_order(subject):
|
|
62
|
+
assert proof.is_void(subject, RETURN) and proof.classify(subject, RETURN, "", None, None).type == "void"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.mark.parametrize("subject", PATTERN_SUBJECTS)
|
|
66
|
+
def test_return_and_refund_wording_voids_an_order_even_from_another_amazon_sender(subject):
|
|
67
|
+
assert proof.classify(subject, "Amazon <order-update@amazon.com>", "", "111-5095344-6551466", None).type == "void"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_the_return_sender_counts_as_an_order_sender_and_amazon_marketing_still_does_not():
|
|
71
|
+
assert proof.is_order_sender(RETURN)
|
|
72
|
+
assert not proof.is_order_sender("Amazon <store-news@amazon.com>")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.parametrize("subject, product", [
|
|
76
|
+
('Your return of Tripod for Camera, 72" Tall...', 'Tripod for Camera, 72" Tall'),
|
|
77
|
+
('Your refund for Tripod for Camera, 72" Tall....', 'Tripod for Camera, 72" Tall'),
|
|
78
|
+
("Your return of Ethernet Cable � 100ft ...", "Ethernet Cable 100ft"),
|
|
79
|
+
("Return received for CAP Barbell 40 LB Coated Hex....", "CAP Barbell 40 LB Coated Hex"),
|
|
80
|
+
("Dropoff confirmed for Govee Smart Plug 15A, WiFi...", "Govee Smart Plug 15A, WiFi"),
|
|
81
|
+
('Your Amazon.com order of "SVBONY SV240 Telescope..." has been cancelled', "SVBONY SV240 Telescope"),
|
|
82
|
+
("Your return summary", None),
|
|
83
|
+
("Your refund confirmation", None),
|
|
84
|
+
("Refund on order 111-8549465-7005845", None),
|
|
85
|
+
("Your return for Amazon order 114-7983065-4049840", None),
|
|
86
|
+
('Your Amazon.com order of "LEGO Botanicals..." and 1 more item(s) has been canceled.', None),
|
|
87
|
+
])
|
|
88
|
+
def test_the_product_a_void_mail_names_is_read_from_its_subject(subject, product):
|
|
89
|
+
assert proof.void_product(subject) == product
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_a_refund_mail_is_stored_as_a_void_receipt_with_the_order_number_from_its_status_link():
|
|
93
|
+
refund = message("r1", RETURN, 'Your refund for Tripod for Camera, 72" Tall....', html=HTML, text=REFUND_BODY, date=NOW - 100)
|
|
94
|
+
result = scan_purchases(FakeGmail([refund]), now=NOW, discover=False)
|
|
95
|
+
parsed = result.receipts[0].parsed
|
|
96
|
+
assert (parsed.proof, parsed.order_ref, parsed.items) == ("void", "111-5095344-6551466", [])
|
|
97
|
+
assert result.skipped == {"voided_order_notice": 1} and result.excluded == 0
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_a_return_request_mail_gives_its_order_number_too():
|
|
101
|
+
request = message("r2", RETURN, "Your return of BARSKA Binocular Tripod Adaptor...", html=HTML, text=RETURN_BODY, date=NOW - 100)
|
|
102
|
+
assert scan_purchases(FakeGmail([request]), now=NOW, discover=False).receipts[0].parsed.order_ref == "111-9840370-6048264"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_the_receipt_search_asks_for_everything_the_return_sender_mails():
|
|
106
|
+
assert any(q.startswith("from:(return@amazon.com) after:") for q in receipt_queries(NOW))
|
|
@@ -81,7 +81,7 @@ def test_queries_cover_every_vendor_domain_and_exclude_non_purchases():
|
|
|
81
81
|
for vendor in data.vendors()["vendors"]:
|
|
82
82
|
for domain in vendor["domains"]:
|
|
83
83
|
assert domain in joined
|
|
84
|
-
assert all("after:1700000000" in q for q in queries) and all("-subject:" in q for q in queries[:-1])
|
|
84
|
+
assert all("after:1700000000" in q for q in queries) and all("-subject:" in q for q in queries[1:-1])
|
|
85
85
|
assert any(q.startswith("category:purchases") for q in queries)
|
|
86
86
|
assert all(len(q) < 1500 for q in queries)
|
|
87
87
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
|
-
from
|
|
4
|
+
from gmail_home_guard import REAL_CLAUDE, REAL_HOME, under_real_claude
|
|
5
5
|
|
|
6
6
|
from gmail_reader import credentials
|
|
7
7
|
|
|
@@ -29,7 +29,7 @@ def test_helper_recognises_paths(tmp_path):
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def test_a_temp_folder_inside_the_real_claude_folder_is_not_the_real_home(monkeypatch):
|
|
32
|
-
import
|
|
33
|
-
monkeypatch.setattr(
|
|
32
|
+
import gmail_home_guard
|
|
33
|
+
monkeypatch.setattr(gmail_home_guard, "TEMP_ROOT", REAL_CLAUDE / "logs" / "heavy_gates" / "run" / "tmp")
|
|
34
34
|
assert not under_real_claude(REAL_CLAUDE / "logs" / "heavy_gates" / "run" / "tmp" / "pytest" / "x.db")
|
|
35
35
|
assert under_real_claude(REAL_CLAUDE / "agents.env") and under_real_claude(REAL_CLAUDE / "logs" / "other")
|