From 3396c50aac8b7892fe703991d159e8e1836bf0ff Mon Sep 17 00:00:00 2001 From: Sulthan Zaki Date: Tue, 11 Aug 2026 13:32:14 +0700 Subject: [PATCH] =?UTF-8?q?#88:=20review=20=E2=80=94=20drop=20dead=20ancho?= =?UTF-8?q?r=20branch,=20single=20marker=20scan=20in=20canary=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/latest/smoke_lnw_test.go | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/backend/internal/latest/smoke_lnw_test.go b/backend/internal/latest/smoke_lnw_test.go index dae69cd..cd3e589 100644 --- a/backend/internal/latest/smoke_lnw_test.go +++ b/backend/internal/latest/smoke_lnw_test.go @@ -63,10 +63,11 @@ func TestSmokeLnwCommentBoundary(t *testing.T) { if !lnwChapterRe.MatchString(body) { t.Fatalf("no chapter anchor in %d bytes — not a lightnovelworld Series page; not a marker failure, likely a Cloudflare challenge or a non-Series response", len(body)) } + markerIdx := strings.Index(body, lnwCommentMarker) if failures := checkLnwCommentBoundary(body); len(failures) > 0 { t.Fatalf("%s (body %d bytes)", strings.Join(failures, "; "), len(body)) } - t.Logf("ok: %q once at byte %d, body %d bytes", lnwCommentMarker, strings.Index(body, lnwCommentMarker), len(body)) + t.Logf("ok: %q once at byte %d, body %d bytes", lnwCommentMarker, markerIdx, len(body)) } // checkLnwCommentBoundary verifies the three marker assertions against a @@ -75,29 +76,25 @@ func TestSmokeLnwCommentBoundary(t *testing.T) { // human-readable failure per broken assertion — with observed offsets and body // length — and empty when the page is healthy. func checkLnwCommentBoundary(body string) []string { - n := strings.Count(body, lnwCommentMarker) - if n == 0 { - return []string{fmt.Sprintf("%q occurs 0 times in %d bytes, want exactly 1", lnwCommentMarker, len(body))} - } - if n != 1 { - return []string{fmt.Sprintf("%q occurs %d times in %d bytes (first at byte %d), want exactly 1", lnwCommentMarker, n, len(body), strings.Index(body, lnwCommentMarker))} - } markerIdx := strings.Index(body, lnwCommentMarker) - lastAnchor, before := -1, 0 + switch n := strings.Count(body, lnwCommentMarker); { + case n == 0: + return []string{fmt.Sprintf("%q occurs 0 times in %d bytes, want exactly 1", lnwCommentMarker, len(body))} + case n != 1: + return []string{fmt.Sprintf("%q occurs %d times in %d bytes (first at byte %d), want exactly 1", lnwCommentMarker, n, len(body), markerIdx)} + } + lastAnchor, anchorsBefore := -1, 0 for _, m := range lnwChapterRe.FindAllStringIndex(body, -1) { if m[0] < markerIdx { - before++ + anchorsBefore++ } lastAnchor = m[0] } - if lastAnchor == -1 { - return []string{fmt.Sprintf("no chapter anchor in the %d-byte body", len(body))} - } var failures []string if lastAnchor >= markerIdx { failures = append(failures, fmt.Sprintf("last chapter anchor at byte %d does not precede the marker at byte %d", lastAnchor, markerIdx)) } - if before == 0 { + if anchorsBefore == 0 { failures = append(failures, fmt.Sprintf("no chapter anchor before the marker at byte %d — the truncated prefix the scan sees yields nothing", markerIdx)) } return failures