feat: add comprehensive E2E test and idempotency for avatar upload#3
feat: add comprehensive E2E test and idempotency for avatar upload#3
Conversation
This PR improves the avatar upload example to work correctly with the UploadAware interface removal changes and adds comprehensive E2E testing.
## Changes
### Idempotency Fix (main.go)
- Added check to skip processing if temp file already processed
- Prevents errors when upload is processed by both auto-trigger and form submit
- Logs clearly indicate when file is skipped
### Template Fix (avatar-upload.tmpl)
- Added {{else}} branch to conditional for upload status
- Ensures conditional block always renders content for tree diffing
- Fixes issue where success message wasn't appearing
### Comprehensive E2E Test (upload_ws_e2e_test.go) - NEW
- Tests complete WebSocket upload flow: upload_start → upload_chunk → upload_complete
- Validates tree update structure after upload completion
- Verifies success message appears in tree at correct position
- Catches issues that browser-based E2E tests miss
### Dependencies (go.mod/go.sum)
- Updated to use livetemplate with UploadAware removal changes
## Test Results
All tests pass including new E2E test that validates:
- Upload entries are created correctly
- Tree updates contain full structure for new range items
- Success message appears at position 3 in the tree
- Client receives valid tree updates without null/undefined errors
## Related
See companion PR in livetemplate repository for the core library fix.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the avatar upload example with comprehensive E2E testing and idempotency improvements to handle the removal of the UploadAware interface.
Key Changes:
- Adds WebSocket-based E2E test that simulates browser upload behavior without chromedp overhead
- Implements idempotency check to prevent double-processing of uploads when triggered by both auto-completion and form submission
- Fixes template conditional to ensure success messages render correctly in the UI
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| avatar-upload/upload_ws_e2e_test.go | New comprehensive E2E test using WebSocket protocol to test upload flow and tree updates |
| avatar-upload/main.go | Refactored upload handling with idempotency checks and auto-trigger support for upload:avatar:complete action |
| avatar-upload/avatar-upload.tmpl | Added else branch to upload status conditional and upload-status wrapper div for proper rendering |
| avatar-upload/go.mod | Updated dependencies and Go version (with issues - see comments) |
| avatar-upload/go.sum | Updated dependency checksums to match go.mod changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| github.com/chromedp/chromedp v0.14.2 | ||
| github.com/livetemplate/livetemplate v0.3.0 |
There was a problem hiding this comment.
The github.com/gorilla/websocket package is used directly in the test file upload_ws_e2e_test.go (line 12) but is listed as an indirect dependency (line 47). It should be moved to the direct dependencies section. See counter/go.mod for the correct pattern where github.com/gorilla/websocket is listed as a direct dependency when used in tests.
Summary
This PR improves the avatar upload example to work correctly with the UploadAware interface removal changes and adds comprehensive E2E testing that catches issues missed by browser-based tests.
Changes
Idempotency Fix (main.go)
Template Fix (avatar-upload.tmpl)
Comprehensive E2E Test (upload_ws_e2e_test.go) - NEW
Dependencies (go.mod/go.sum)
Test Results
All tests pass including new E2E test that validates:
Related
This PR complements #54 which fixes the core library bug that was preventing upload completion messages from appearing.
Test Plan
🤖 Generated with Claude Code