fix: preserve document pages during playback - #4
Conversation
kolkov
left a comment
There was a problem hiding this comment.
This is the most architecturally significant PR in the batch. The core problem: Document.NewPage creates a page on the document's creator, but Recording.Playback calls Begin() which creates a second page on a new creator — losing the document-owned one.
The fix is correct: pageBackend.Begin() validates instead of recreating, and pageBackend.End() is idempotent (safe for both playback and Document.Finish to call). The newPage callback for error injection in tests is a nice touch.
Lifecycle guards (finished document, dimension mismatch, double-end) are thorough. 231 lines of tests covering ownership, multi-page, and failure paths.
LGTM, merging.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Beginvalidates instead of replacing the pageDocument.FinishWhy
Document.NewPagealready creates a document-owned page and pushes its coordinate transform.Recording.Playbackthen called the promotedBackend.Begin, which replaced that page's creator/page/surface with a standalone creator. Playback popped the replacement surface, andDocument.Finishpopped it again, deterministically panicking with:A document page now validates the page prepared by
NewPage, retains creator ownership, and makes finalization idempotent.Verification
PoppanicRecording.Playback(doc.NewPage(...))Document.Playbackwith multiple pagesFinisherrorsEnd/Finishsafetygo test -count=1 ./...go test -race -count=1 ./...go test -count=1 -coverprofile=coverage.out ./...go build ./...go vet ./...go mod tidy -diffgofmtandgit diff --checkUpstream GitHub Actions and
codecov/patchare configured but await maintainer approval of the fork workflow run.This is independent of #2 (Y-axis transform order) and #3 (custom page dimensions), but touches the same page-initialization lines. Rebase simulations with each PR and their combined state pass all tests, race, vet, and build checks.