test(common): cover hex/log-summary/request-context; fix Utf8Validator dead code (#84, #85)

Reimplements PR #86 independently (author abandoned it after change-requests),
with the review feedback applied — the original tests asserted behavior the
code never had.

#84 — add @snowluma/common unit tests:
- hex: toHex/toHexUpper/hexPreview boundary + fromHex round-trip & odd-length throw
- log-summary: summarizeParams (top-level primitive is String()'d WITHOUT quotes;
  fields quoted; nested collapsed; total cap) and renderParamsVerbose (redaction,
  long-string marker is the Unicode ellipsis '…<N B>' not ASCII '...', circular guard)
- request-context: nextRequestId monotonic; runWithRequestId sync/async + nested scopes
- root scripts test:common/test:all/coverage; coverage/ gitignored

#85 — Utf8Validator: the second surrogate check was unreachable (within the
0x80–0xBF continuation-byte guard, 'b & 0x20' is true iff 'b >= 0xA0'); merge to
one check. No behavior change.

common suite green (26 tests).
This commit is contained in:
DrSmoothl committed 2026-06-22 22:53:21 +08:00
1 parent b918450483
commit 2b3d1c67c2
6 files changed
+132 -4

No files matched your search

+5 -4
View File
@@ -82,10 +82,11 @@ class Utf8Validator {
}
} else {
if (b < this.minNext || b > 0xBF) return false;
if (this.state === 2 && this.codepoint === 0xD && (b & 0x20)) {
return false;
}
if (this.codepoint === 0xD && this.state === 2 && b >= 0xA0) {
// Reject UTF-16 surrogates (U+D800–U+DFFF), encoded as 0xED 0xA0–0xBF ….
// Here b is already constrained to 0x80–0xBF by the guard above, and in
// that range `b & 0x20` is true iff `b >= 0xA0` — so a single check
// covers it (the former second `if` was unreachable dead code).
if (this.state === 2 && this.codepoint === 0xD && b >= 0xA0) {
return false;
}
this.codepoint = (this.codepoint << 6) | (b & 0x3F);