Skip to content

feat: add comprehensive E2E test and idempotency for avatar upload#3

Merged
adnaan merged 1 commit intomainfrom
avatar-upload-improvements
Nov 17, 2025
Merged

feat: add comprehensive E2E test and idempotency for avatar upload#3
adnaan merged 1 commit intomainfrom
avatar-upload-improvements

Conversation

@adnaan
Copy link
Copy Markdown
Contributor

@adnaan adnaan commented Nov 16, 2025

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)

  • Added check to skip processing if temp file already processed
  • Prevents errors when upload is processed by both auto-trigger (upload:avatar:complete) and form submit (UpdateProfile)
  • Logs clearly indicate when file is skipped
if !fileExists(entry.TempPath) {
    log.Printf("DEBUG: Temp file already processed for entry %s, skipping", entry.ID)
    continue
}

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 in UI

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 (position 3)
  • Catches issues that chromedp browser-based E2E tests miss
  • Direct simulation of browser upload behavior without browser overhead

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 via WebSocket
  • ✅ 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

This PR complements #54 which fixes the core library bug that was preventing upload completion messages from appearing.

Test Plan

  • New E2E test passes (TestUploadViaWebSocket)
  • Idempotency fix prevents double-processing errors
  • Template renders success message correctly
  • Manual testing confirms upload flow works end-to-end

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings November 16, 2025 13:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +6 to +7
github.com/chromedp/chromedp v0.14.2
github.com/livetemplate/livetemplate v0.3.0
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@adnaan adnaan merged commit b5475f8 into main Nov 17, 2025
15 checks passed
@adnaan adnaan deleted the avatar-upload-improvements branch November 17, 2025 06:56
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.

2 participants