Commit 42c9894
committed
refactor(sqs): drop unused alias + name decoder offsets + extra tests
Round 1 Claude review nits on PR #724:
1) Dropped sqsReceiptHandleVersion alias
Round 1 added sqsReceiptHandleVersion as an alias of v1 "for
existing call sites". In practice every call site now uses
sqsReceiptHandleVersion1 explicitly, so the alias's only
reference was a self-test. Dropped both the alias and the
test assertion. The two version-byte constants
(sqsReceiptHandleVersion1 / sqsReceiptHandleVersion2) are now
the single source of truth.
2) Named per-field offset constants
decodeReceiptHandleV1 / decodeReceiptHandleV2 used numeric
offsets (1, 9, 13, 1+sqsMessageIDBytes, …) derived from layout
arithmetic. Replaced with named constants:
v1: V1VersionOffset, V1GenOffset, V1IDOffset,
V1TokenOffset, V1Size
v2: V2VersionOffset, V2PartitionOffset, V2GenOffset,
V2IDOffset, V2TokenOffset, V2Size
A future field-shape change touches the constants in one
place instead of scattering numeric arithmetic through
encoders / decoders.
3) Explicit upper bound on token slice
bytes.Clone(b[start:]) → bytes.Clone(b[start:end]). The
length check above guarantees the open-ended form would have
read the right bytes, but the explicit upper bound is
self-documenting and protects against a future refactor that
forgets the length precondition.
4) Doc note on cross-version rejection
decodedReceiptHandle's doc described the cross-version
rejection contract ("a v1 handle against a partitioned queue
→ ReceiptHandleIsInvalid") that this scaffold PR does NOT
enforce — that's PR 5b's gate-and-lift. Added an explicit
note that enforcement is wired by PR 5b so future review of
that PR doesn't go looking for the contract here.
5) New test case: v2 / v1 oversized
TestDecodeReceiptHandle_RejectsLengthMismatch grew two cases
(v2 + 1 byte, v1 + 1 byte) so the exact-length check on each
decoder branch is independently exercised. The previous
table covered "byte mismatch" and "truncated" but not "too
long for the version".
Audit per the lessons-learned discipline
The semantic change here is the alias removal. grep -rn
sqsReceiptHandleVersion across the repo confirmed zero
remaining references after the test assertion was dropped.
The named-offset refactor preserves byte-for-byte the same
on-wire format; the constants ARE the layout.
go test -race ./adapter/... and golangci-lint clean.1 parent 0206a1c commit 42c9894
2 files changed
Lines changed: 58 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
61 | 62 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | 63 | | |
68 | 64 | | |
69 | 65 | | |
| |||
231 | 227 | | |
232 | 228 | | |
233 | 229 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
243 | 252 | | |
244 | 253 | | |
245 | 254 | | |
| |||
348 | 357 | | |
349 | 358 | | |
350 | 359 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
356 | 368 | | |
357 | 369 | | |
358 | 370 | | |
| |||
361 | 373 | | |
362 | 374 | | |
363 | 375 | | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
369 | 385 | | |
370 | 386 | | |
371 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
162 | 178 | | |
163 | 179 | | |
164 | 180 | | |
| |||
229 | 245 | | |
230 | 246 | | |
231 | 247 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | 248 | | |
236 | 249 | | |
237 | 250 | | |
| |||
0 commit comments