Skip to content

[AI:zf-builder] refactor(server): dedup WebSocket upgrade-error classification across websocket.go and migrate.go (Ponytail Rung 2) - #191

Merged
ntsd merged 2 commits into
mainfrom
task/zf-z-aaaf65bb
Nov 21, 2026
Merged

ntsd merged 2 commits into
mainfrom
task/zf-z-aaaf65bb

Conversation

@ntsd

@ntsd ntsd commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

[AI:zf-builder] Task: zf-z-aaaf65bb

Automated PR for task zf-z-aaaf65bb

Completed by: @zf-builder

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying zerohub with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2df84c6
Status: ✅  Deploy successful!
Preview URL: https://f1716ac7.zerohub.pages.dev
Branch Preview URL: https://task-zf-z-aaaf65bb.zerohub.pages.dev

View logs

@ntsd ntsd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI:zf-reviewer] [Reviewer Feedback] Round 1: Approved for human review.

Scope verified against the real diff (git diff origin/main...HEAD): exactly 3 files, no lockfile churn, no drive-by reformatting, no unrelated files. The pre-digested diff matches the committed change byte-for-byte.

Correctness / dedup

  • websocket.HandshakeError now appears in exactly one place: the new unexported helper wrapUpgradeError in websocket.go (grep over pkg/+cmd/ non-test confirms a single remaining occurrence). Both call sites (websocket.go Upgrade and migrate.go ForwardMigrate) delegate to it.
  • Error message strings are preserved verbatim ("websocket handshake: " / "websocket upgrade error: "), so no observable behavior change.
  • The out-of-scope finishUpgradeFailure log site (websocket.go ~line 262, log.Error().Err(fmt.Errorf("websocket upgrade error: %w", err))) was correctly left untouched — it has a different context (logging with %w vs returning to caller), exactly as the task specified not to fold it in.

Tests

  • New wrap_upgrade_error_test.go pins all three behaviors: the HandshakeError branch (prefix "websocket handshake: "), the generic non-HandshakeError branch (exact full-string match, so the original message is preserved), and the nil boundary. These are real assertions on distinct branches, not tautological/mock-only.
  • Full server suite green: go build ./... && go vet ./... && go test ./... all pass; the 3 new tests pass under -run TestWrapUpgradeError -v.

Ponytail / diff hygiene

  • Rung 2 (codebase reuse): a genuine in-package dedup with net LOC reduction — ~10 duplicated lines become one 5-line helper plus two one-line call sites.
  • Rungs 1/6 (YAGNI/simplicity): the helper is justified by exactly 2 real call sites with non-trivial classification (type assertion + two distinct labels); not a premature abstraction, not a single-caller factory.
  • Rungs 3/5: no new external dependencies (only errors/strings/testing + already-imported github.com/fasthttp/websocket in the test).
  • No leftover debug code.

PR #191 is mergeable and not a draft. No changes requested.

CONVENTION: For dedup refactors in pkg/handler, keep the classification helper local (unexported, single package) and add a focused unit test pinning each branch (handshake vs generic vs nil boundary); leave logging-context %w sites out of scope.

@ntsd
ntsd merged commit 0eecb71 into main Nov 21, 2026
3 checks passed
@ntsd
ntsd deleted the task/zf-z-aaaf65bb branch November 21, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant