test(e2e): split multi-Expect It + drop bare sleep (bookshelf-tr2i) #531

Merged
zombor merged 1 commit from bd-bookshelf-tr2i into main 2026-06-12 16:05:41 +00:00
Owner

Summary

  • Split the single It block in metadata_compare_cover_screenshot_test.go (which had 4 Expect calls) into 4 single-Expect It blocks, each sharing the same BeforeEach/JustBeforeEach per project convention (one Expect per It).
  • Removed the bare time.Sleep(200 * time.Millisecond) "layout settle" — DOM injection via MustEval is synchronous and MustElement already gates on presence; the wall-clock sleep was redundant and a flake risk.
  • Added proper BeforeEach/JustBeforeEach structure: setup (nav, DOM inject, screenshot) in BeforeEach; width reads in JustBeforeEach; assertions in It.
  • No behaviour change — tests verify the same CSS constraints.

Test plan

  • make build — compiles cleanly
  • CI e2e browser tests pass (same assertions, now split across 4 Its)

Closes bead bookshelf-tr2i on merge.

## Summary - Split the single `It` block in `metadata_compare_cover_screenshot_test.go` (which had 4 `Expect` calls) into 4 single-Expect `It` blocks, each sharing the same `BeforeEach`/`JustBeforeEach` per project convention (one Expect per It). - Removed the bare `time.Sleep(200 * time.Millisecond)` "layout settle" — DOM injection via `MustEval` is synchronous and `MustElement` already gates on presence; the wall-clock sleep was redundant and a flake risk. - Added proper `BeforeEach`/`JustBeforeEach` structure: setup (nav, DOM inject, screenshot) in `BeforeEach`; width reads in `JustBeforeEach`; assertions in `It`. - No behaviour change — tests verify the same CSS constraints. ## Test plan - [ ] `make build` — compiles cleanly - [ ] CI e2e browser tests pass (same assertions, now split across 4 Its) Closes bead bookshelf-tr2i on merge.
test(e2e): split multi-Expect It + drop bare sleep (bookshelf-tr2i)
All checks were successful
/ Lint (pull_request) Successful in 2m1s
/ JS Unit Tests (pull_request) Successful in 27s
/ Test (pull_request) Successful in 3m7s
/ E2E Browser (pull_request) Successful in 4m4s
/ Integration (pull_request) Successful in 6m31s
/ E2E API (pull_request) Successful in 9m44s
a07e29d1ed
Split the single It block in metadata_compare_cover_screenshot_test.go
(4 Expects) into 4 single-Expect It blocks sharing BeforeEach/JustBeforeEach.
Remove the bare time.Sleep(200ms) — DOM injection via MustEval is synchronous
and MustElement already gates on presence; the sleep was redundant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
Owner

Security Review — bookshelf-tr2i (PR #531)

Scope: e2e/browser/metadata_compare_cover_screenshot_test.go only.

Checks performed:

  • Secrets/credentials: No tokens, API keys, passwords, or credentials introduced. The only external interaction is the existing uploadMetadataCoverScreenshotToPR call, unchanged.
  • Insecure TLS / NoSandbox: No TLS configuration changes. NoSandbox not referenced; launcher config is untouched.
  • Network egress: No new outbound endpoints introduced. The screenshot-upload call to the Forgejo PR was already present; diff merely moves it from the It block into BeforeEach.
  • Command/HTML injection via test inputs: Test inputs are hard-coded string literals ("Cover Thumbnail Test Book") and integer IDs. No user-controlled or externally sourced data flows into shell commands or HTML template contexts.
  • Test harness weakening: The change improves harness structure (one Expect per It, DeferCleanup over bare defer, removal of a wall-clock time.Sleep). No assertion is removed — the four assertions from the original It are preserved across four new It blocks. The BeforeEach/JustBeforeEach split is correct per project conventions.
  • Temp file write (/tmp/...): Pre-existing pattern, unchanged in risk profile. Fixed-name suffix is process-indexed (GinkgoParallelProcess()), preventing parallel-test clobber.

Findings: None.

REVIEW VERDICT: 0 blocker, 0 major, 0 minor

## Security Review — bookshelf-tr2i (PR #531) **Scope:** `e2e/browser/metadata_compare_cover_screenshot_test.go` only. **Checks performed:** - **Secrets/credentials:** No tokens, API keys, passwords, or credentials introduced. The only external interaction is the existing `uploadMetadataCoverScreenshotToPR` call, unchanged. - **Insecure TLS / NoSandbox:** No TLS configuration changes. `NoSandbox` not referenced; launcher config is untouched. - **Network egress:** No new outbound endpoints introduced. The screenshot-upload call to the Forgejo PR was already present; diff merely moves it from the `It` block into `BeforeEach`. - **Command/HTML injection via test inputs:** Test inputs are hard-coded string literals (`"Cover Thumbnail Test Book"`) and integer IDs. No user-controlled or externally sourced data flows into shell commands or HTML template contexts. - **Test harness weakening:** The change improves harness structure (one `Expect` per `It`, `DeferCleanup` over bare `defer`, removal of a wall-clock `time.Sleep`). No assertion is removed — the four assertions from the original `It` are preserved across four new `It` blocks. The `BeforeEach`/`JustBeforeEach` split is correct per project conventions. - **Temp file write (`/tmp/...`):** Pre-existing pattern, unchanged in risk profile. Fixed-name suffix is process-indexed (`GinkgoParallelProcess()`), preventing parallel-test clobber. **Findings:** None. REVIEW VERDICT: 0 blocker, 0 major, 0 minor
Author
Owner

Code Review — bookshelf-tr2i

Reviewed: git diff origin/main...origin/bd-bookshelf-tr2i

Phase 0: DEMO verification

No DEMO block. This is a test-hygiene refactor (no new behavior); no runnable demo is applicable. Proceeding directly to code quality.

Phase 1: Spec compliance

All three bead requirements met:

  • 4-Expect It split into 4 single-Expect Its with shared BeforeEach/JustBeforeEach
  • time.Sleep(200ms) removed ✓
  • BeforeEach/JustBeforeEach structure added ✓

Phase 2: Code quality

Structure:

  • BeforeEach is pure setup: page creation, DeferCleanup, seedBook, setAuthCookies, navigation, DOM injection via MustEval, MustElement presence wait, screenshot + upload. Correct.
  • JustBeforeEach captures the two getBoundingClientRect() width readings. Correct separation.
  • 4 It blocks each have exactly 1 Expect. Correct.

Sleep removal safety:
MustEval is a synchronous round-trip (JS runs to completion before the Go call returns). MustElement("[data-mf-modal]") confirms DOM presence before the width-reading MustEval calls in JustBeforeEach. getBoundingClientRect() is itself synchronous JS — the browser's layout engine computes it before returning. The 200ms sleep was not masking a real async gate; its removal does not introduce a race.

DeferCleanup vs defer:
The old code used defer page.MustClose() inside a single It. The new code correctly uses DeferCleanup(page.MustClose) inside BeforeEach — the Ginkgo-idiomatic way to ensure cleanup runs after each It when setup lives in BeforeEach. Improvement.

Imports:
"time" removed (no longer used). "github.com/go-rod/rod" added and used for the *rod.Page type in the outer var block. Clean.

bookID scoping:
bookID is correctly kept as a var bookID int64 local to BeforeEach since it is only needed within that block to construct the navigation URL.

Findings

No blockers, majors, or minors.

REVIEW VERDICT: 0 blocker, 0 major, 0 minor

## Code Review — bookshelf-tr2i **Reviewed:** `git diff origin/main...origin/bd-bookshelf-tr2i` ### Phase 0: DEMO verification No DEMO block. This is a test-hygiene refactor (no new behavior); no runnable demo is applicable. Proceeding directly to code quality. ### Phase 1: Spec compliance All three bead requirements met: - 4-Expect `It` split into 4 single-Expect `Its` with shared `BeforeEach`/`JustBeforeEach` ✓ - `time.Sleep(200ms)` removed ✓ - `BeforeEach`/`JustBeforeEach` structure added ✓ ### Phase 2: Code quality **Structure:** - `BeforeEach` is pure setup: page creation, `DeferCleanup`, `seedBook`, `setAuthCookies`, navigation, DOM injection via `MustEval`, `MustElement` presence wait, screenshot + upload. Correct. - `JustBeforeEach` captures the two `getBoundingClientRect()` width readings. Correct separation. - 4 `It` blocks each have exactly 1 `Expect`. Correct. **Sleep removal safety:** `MustEval` is a synchronous round-trip (JS runs to completion before the Go call returns). `MustElement("[data-mf-modal]")` confirms DOM presence before the width-reading `MustEval` calls in `JustBeforeEach`. `getBoundingClientRect()` is itself synchronous JS — the browser's layout engine computes it before returning. The 200ms sleep was not masking a real async gate; its removal does not introduce a race. **`DeferCleanup` vs `defer`:** The old code used `defer page.MustClose()` inside a single `It`. The new code correctly uses `DeferCleanup(page.MustClose)` inside `BeforeEach` — the Ginkgo-idiomatic way to ensure cleanup runs after each `It` when setup lives in `BeforeEach`. Improvement. **Imports:** `"time"` removed (no longer used). `"github.com/go-rod/rod"` added and used for the `*rod.Page` type in the outer `var` block. Clean. **`bookID` scoping:** `bookID` is correctly kept as a `var bookID int64` local to `BeforeEach` since it is only needed within that block to construct the navigation URL. ### Findings No blockers, majors, or minors. REVIEW VERDICT: 0 blocker, 0 major, 0 minor
zombor force-pushed bd-bookshelf-tr2i from a07e29d1ed
All checks were successful
/ Lint (pull_request) Successful in 2m1s
/ JS Unit Tests (pull_request) Successful in 27s
/ Test (pull_request) Successful in 3m7s
/ E2E Browser (pull_request) Successful in 4m4s
/ Integration (pull_request) Successful in 6m31s
/ E2E API (pull_request) Successful in 9m44s
to 2206945ac7
All checks were successful
/ JS Unit Tests (pull_request) Successful in 46s
/ Lint (pull_request) Successful in 2m7s
/ Test (pull_request) Successful in 2m22s
/ E2E Browser (pull_request) Successful in 3m42s
/ E2E API (pull_request) Successful in 5m2s
/ Integration (pull_request) Successful in 5m12s
2026-06-12 15:44:18 +00:00
Compare
zombor merged commit e4b713fb4a into main 2026-06-12 16:05:41 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zombor/pergamum!531
No description provided.