Commit 383eb12
authored
feat(promo-codes): Track 1 telemetry + lookup-build for DA discover (#546)
* feat(promo-codes): add AllowedEmailDomainsLookup DTO + builder for Track 1
* test(promo-codes): move AllowedEmailDomainsLookupBuilderTest to Unit/Services + cover malformed-drop
* test(promo-codes): align test namespace + drop tautological hash assert + cover malformed silent-drop
* feat(promo-codes): add matchesEmailDomainViaLookup parity matcher
* feat(promo-codes): Track 1 repo-decouple + lookup-driven discover + metric
* docs(promo-codes): mark getDiscoverableByEmailForSummit @deprecated for Track 2 cleanup
* fix(promo-codes): unrestricted flag preserves legacy parity for malformed-only arrays
* fix(promo-codes): trim email before empty guard in aggregator (CodeRabbit)
* fix(promo-codes): apply smarcet review on discoverPromoCodes (PR #546)
Addresses all 5 review findings from @smarcet on the Track-1 discover hot
path in SummitPromoCodeService::discoverPromoCodes.
1. Whitespace-only email bypassed the empty() guard (empty(" ") === false),
causing strtolower(trim(...)) -> "" to flow into the email-linked repo
query and potentially match codes with NULL/empty email columns. Guard
now normalizes first: if (empty(trim($email))) return [].
2. Per-code lookup rebuild defeated the SDS-promised "per-request micro-opt"
— N codes meant N full normalize+sort+sha1 passes. Added $lookupCache
keyed by sha1(implode("\0", $patterns)) so sibling codes sharing
byte-identical pattern arrays reuse a single built lookup. Cache pre-hash
is order- and case-sensitive (acceptable for upstream-generated arrays;
future T1-Sanity can surface lower-than-expected hit rate if needed).
3. new \DateTime() replaced with new \DateTime('now', new DateTimeZone('UTC'))
to match the repository convention at DoctrineSummitRegistrationPromoCode
Repository.php:699. Note: config/app.php sets timezone => 'UTC' and PHP
DateTime comparison normalizes via Unix timestamp, so runtime behavior
is unchanged — change is defensive consistency.
4. valid_until_date_passed had two semantic bugs at the metric emit:
- empty($candidates) short-circuited to true (zero DA codes != all expired)
- open-ended codes (null valid_until_date) collapsed the reduce
accumulator to false, masking the all-finite-expired case
Filter to finite candidates first via array_filter; default empty-finite
case to false; simplify reduce predicate since filter pre-enforces the
invariants.
5. Test coverage gaps: all 4 existing discover tests mocked
matchesEmailDomainViaLookup -> true, so a regression there would
silently leak all in-date DA codes to every member. Added two tests:
- testDomainNonMatchingDACodeIsExcluded — uses real
AllowedEmailDomainsLookupBuilder + makePartial() so the real
matchesEmailDomainViaLookup trait method fires; member email
user@other.com against a code allowing @acme.com asserts exclusion.
- testDiscoverReturnsEmptyForWhitespaceOnlyEmail — pins fix 1 with
shouldNotReceive on both repo methods so any guard regression fails.
vendor/bin/phpunit tests/Unit/Services -> 30/30 passing (was 28; +2 from
the new discovery tests). Builder 12 + parity 11 + Discovery 7 = 30.1 parent 12a29e2 commit 383eb12
11 files changed
Lines changed: 666 additions & 53 deletions
File tree
- app
- Models/Foundation/Summit
- Registration/PromoCodes
- Repositories
- Repositories/Summit
- Services
- Model/Imp
- tests/Unit/Services
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
113 | 148 | | |
114 | 149 | | |
115 | 150 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
40 | 54 | | |
41 | 55 | | |
42 | 56 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
84 | 88 | | |
85 | | - | |
86 | 89 | | |
87 | 90 | | |
88 | | - | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
Lines changed: 22 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
661 | 661 | | |
662 | 662 | | |
663 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
664 | 670 | | |
665 | 671 | | |
666 | 672 | | |
667 | 673 | | |
668 | 674 | | |
669 | 675 | | |
670 | | - | |
| 676 | + | |
| 677 | + | |
671 | 678 | | |
672 | | - | |
| 679 | + | |
673 | 680 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
678 | 690 | | |
679 | 691 | | |
680 | 692 | | |
681 | 693 | | |
682 | | - | |
683 | 694 | | |
684 | 695 | | |
685 | | - | |
| 696 | + | |
686 | 697 | | |
687 | | - | |
| 698 | + | |
688 | 699 | | |
689 | | - | |
| 700 | + | |
690 | 701 | | |
691 | 702 | | |
692 | 703 | | |
| |||
702 | 713 | | |
703 | 714 | | |
704 | 715 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
| 716 | + | |
715 | 717 | | |
716 | 718 | | |
717 | 719 | | |
| |||
Lines changed: 87 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
0 commit comments