Repository navigation
chore(purchase): drop maskActor's dead guard and inert commitmentopts helpers - #1224
Conversation
… helpers maskActor rejects an empty actor before its `len(actor)-1 >= 0` check, so that `if` always held and its variable was never read. Replace the guard and loop with strings.Index, which returns the same first-'@' byte offset for every input, including invalid UTF-8. In commitmentopts, collectWithService was a pass-through to collect, and dedupeRaw's (durationSeconds, payment) dedupe is subsumed by collect's first-occurrence dedupe on the normalized (term, payment) key: both normalizers are pure functions of those two fields. probeOnePlanType now calls collect directly. Add TestSavingsPlansProber_DuplicatesAndNormalizedCollisionsPinned, which pins the exact ordered Probe output across two pages with raw duplicates, normalized collisions and dropped pairs, and TestMaskActor, which pins the log mask. Both pass before and after the change. Closes LeanerCloud#325 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 4 billable files and costs up to $1.00. Or wait 58 minutes for your next included review. View limit details
Comment |
|
Independent review 2 (claude-fleet, cold): APPROVE 14e5222 This is a removal with no behaviour change. The guard is dead, both helpers had a single caller, and the merged tree builds and passes. Findings: none. Attacked:
Beyond the table,
Verified locally:
Reviewed by an independent agent with no author context (second reviewer). Review only: nothing was pushed, and the GitHub review state is unchanged. |
|
VERDICT: APPROVE 14e5222 Base: main (not stacked). Fixes #325: yes, both checkboxes.
Findings: none blocking.
Attacked:
|
|
Independent review (IAmJSD's agent, fresh context, given only the diff, the issue and the PR text): VERDICT: APPROVE Blocking:
Non-blocking:
Attacked:
Body-stale: none Reviewer: rB3. Bar while the maintainers are away (set by IAmJSD as acting owner): one approving independent review on the head, two for money, auth and security paths. |
|
Local verification at |
|
Merged by IAmJSD's agent at IAmJSD's request (IAmJSD is acting owner while the maintainers are away), under the bar IAmJSD set: 2 approving independent review(s) on |
Root cause and fix
Both items are dead code. Deleting them changes no output. Neither was referenced by any test by name, so no existing test had to move.
maskActor(internal/purchase/approvals.go):actor == ""returns early, solen(actor)-1 >= 0was always true andatwas never read. I replaced the guard and therangeloop withstrings.Index(actor, "@").rangeyields the byte offset of each rune start, and'@'(0x40) can never be part of a multi-byte UTF-8 sequence or get swallowed by an invalid one, so the offset is the same for every input, including invalid UTF-8.collectWithService/dedupeRaw(internal/commitmentopts/probe.go):collectWithServicewas a one-line pass-through tocollect.dedupeRawkept the first occurrence of each raw(durationSeconds, payment)pair.collectkeeps the first occurrence of each normalized(term, payment)pair and drops pairs that don't normalize.durationToTermandnormalizePaymentdepend only on those two raw fields, so a later copy of a raw pair always maps to a key that is already seen, or it is dropped. Removing it earlier therefore never changescollect's output or its order.probeOnePlanTypenow returnscollect(serviceKey, raw)directly. Both helpers and their comments are gone.Closes #325
Verification
All of this is unit, mock and fixture evidence. The SP prober runs against a fake
DescribeSavingsPlansOfferings, and nothing calls AWS. Tests ran withAWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/nullbecause this machine's default AWS profile is invalid.Pin tests: pass before and after. This change preserves behavior, so there is no fail-before. The new tests pin the output, and they passed on unchanged
origin/main(2f1dbca) before the deletion.TestSavingsPlansProber_DuplicatesAndNormalizedCollisionsPinnedgoes through the publicSavingsPlansProber.Probeacross two Compute pages. The pages contain exact raw duplicates (within a page and across pages), raw spellings that normalize to the same pair (All Upfront/ALL_UPFRONT,No Upfront/no-upfront/NO_UPFRONT,Partial Upfront/partial_upfront), duplicated unknown-term pairs and duplicatedHeavy Utilizationpairs. The test asserts the exact ordered[]Combo.TestMaskActorpins the log mask for these cases: empty, plain email, leading/trailing@, multiple@, a non-ASCII local part, an invalid-UTF-8 local part, and short and long non-emails.Exhaustive equivalence on origin/main (one-off, not committed). On main, a temporary in-package test checked
reflect.DeepEqual(collect(s, dedupeRaw(raw)), collect(s, raw)). The alphabet was 55 raw offers: 5 durations (1y, 3y, 0, 2y, -1) × 11 payment spellings, including invalid and legacy ones. The test covered nil, the empty slice, every sequence up to length 3, and 300k random sequences up to length 40 drawn from small sub-alphabets to force repeats. Result: 469,457 checks, all equal. A second temporary test compared the oldmaskActorwith the new one: exhaustive over a 16-byte pool that includes@, UTF-8 lead and continuation bytes and 0xff, up to length 4, plus 500k random byte strings. Result: 569,905 checks, all equal.Mutation probes (reverted afterward):
seencheck incollect:TestSavingsPlansProber_Probe,_DedupedAcrossProductTypesand the new pin test fail.collecton the raw payment instead of the normalized one: only the new pin test fails. The existing suite did not cover normalized collisions.strings.LastIndexinmaskActor:TestMaskActorfails onfirst@second@example.com.Commands (run on this head, from the repo root):
The existing tests in
internal/commitmentopts,internal/purchaseandinternal/mockspass unchanged.Out of scope
sortCombosinprobe_test.gohas a comment saying probers dedupe "by map keys so iteration order is otherwise nondeterministic".collectactually iterates the input slice, so its order is deterministic, and the new test relies on that. I left the helper and its comment alone.Maintainer: please mirror the issue's triage labels onto this PR:
impact/internal,type/chore,triaged,priority/p3,severity/low,urgency/eventually,effort/xs.🤖 Generated with Claude Code