Skip to content

Comments

Final refactoring before v1.1.0 release.#38

Merged
yulmwu merged 10 commits intomainfrom
refactor/v1.1.0
Feb 18, 2026
Merged

Final refactoring before v1.1.0 release.#38
yulmwu merged 10 commits intomainfrom
refactor/v1.1.0

Conversation

@yulmwu
Copy link
Member

@yulmwu yulmwu commented Feb 17, 2026

The following refactoring and improvements have been made:

  1. Fixed missing UTC normalization in the current time logic (Now()).

  2. Skipped logging for endpoints that handle sensitive data, such as:

    • /api/auth/login
    • /api/auth/register
    • /api/auth/refresh
    • /api/auth/logout
    • /api/challenges/{id}/submit
  3. Removed the window parameter from the Timeline API and optimized Redis cache key unification and invalidation. (Cache keys are now unified as timeline:users, timeline:teams, leaderboard:users, leaderboard:teams.)

  4. Previously, if deletion of the old file failed during file upload, the database had already been updated with the new key but still returned an error. We determined that orphaned files are acceptable in this case and updated the logic as follows:

    if previousKey != nil && *previousKey != "" && s.fileStore != nil {
        if err := s.fileStore.Delete(ctx, *previousKey); err != nil {
            return nil, storage.PresignedPost{}, fmt.Errorf("ctf.RequestChallengeFileUpload delete: %w", err)
        }
        // Best-effort cleanup. Keep the new file active even if cleanup fails.
        _ = s.fileStore.Delete(ctx, *previousKey)
    }
  5. Cache invalidation was missing in scenarios such as username changes, team transfers, and challenge point updates. This has now been addressed.

Additional refactoring may be added later and will be noted in the comments.

@yulmwu yulmwu self-assigned this Feb 17, 2026
@yulmwu yulmwu added bug Something isn't working enhancement New feature or request labels Feb 17, 2026
@yulmwu
Copy link
Member Author

yulmwu commented Feb 17, 2026

There was also a suggestion to remove fields from the stack DB schema that are updated by the Container Provisioner, such as stack status, target port, ttl, node port, and public IP. However, we decided to keep them as-is, as the trade-offs introduced by refactoring were considered greater than the potential benefits.

@yulmwu
Copy link
Member Author

yulmwu commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 7 lines in your changes missing coverage. Please review.

Upon review, no additional tests are required.

@yulmwu yulmwu changed the title Final refactoring before v1.1.0 release Final refactoring before v1.1.0 release. Feb 17, 2026
@yulmwu
Copy link
Member Author

yulmwu commented Feb 18, 2026

Additionally, the Handler-Service–Repository backend pattern has been further clarified through refactoring, and parts of the test code have also been refactored.

@yulmwu
Copy link
Member Author

yulmwu commented Feb 18, 2026

PostgreSQL testcontainers(for Go) appear to be unstable. We will consider improving this in the future by adopting a different testing library or container library.

Copy link
Contributor

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 implements several refactoring improvements and bug fixes in preparation for the v1.1.0 release:

Changes:

  • Introduced UserService and ScoreboardService layers to separate business logic from handlers
  • Unified Redis cache keys (timeline:users, timeline:teams, leaderboard:users, leaderboard:teams) and removed window parameter from Timeline API
  • Added comprehensive cache invalidation for username changes, team transfers, and challenge point updates
  • Implemented skip-logging for sensitive endpoints (auth endpoints and challenge submissions)
  • Changed file upload cleanup to best-effort (orphaned files acceptable if cleanup fails)
  • Added ProvisionerMock for stack testing to replace inline test stubs
  • Added UTC normalization in logging
  • Added coverage check scripts

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/coverage_check/main.py New coverage calculation script excluding specific files
scripts/coverage_check.sh Bash wrapper for coverage check script
internal/stack/mock.go New ProvisionerMock implementation for easier testing
internal/stack/mock_test.go Tests for ProvisionerMock
internal/service/user_service.go New UserService layer for user operations
internal/service/user_service_test.go Tests for UserService
internal/service/scoreboard_service.go New ScoreboardService layer with timeline aggregation
internal/service/scoreboard_service_test.go Tests for ScoreboardService
internal/service/errors.go Added service.ErrNotFound
internal/service/ctf_service.go Changed file cleanup to best-effort
internal/service/ctf_service_test.go Updated test to reflect new file cleanup behavior
internal/service/team_service.go Updated to return service.ErrNotFound instead of repo.ErrNotFound
internal/service/team_service_test.go Updated to use service.ErrNotFound
internal/service/testenv_test.go Added new service instances to test environment
internal/service/stack_service_test.go Refactored to use ProvisionerMock
internal/logging/logging.go Added UTC normalization for time.Now() calls
internal/http/router.go Updated to use UserService and ScoreboardService
internal/http/middleware/request_logger.go Added sensitive path skipping and UTC normalization
internal/http/middleware/request_logger_test.go Tests for sensitive path skipping
internal/http/handlers/handler.go Major refactoring: service delegation, cache invalidation, timeline simplification
internal/http/handlers/handler_test.go Tests for cache invalidation behavior
internal/http/handlers/testenv_test.go Added new service instances to test environment
internal/http/handlers/errors.go Updated to use service.ErrNotFound
internal/http/handlers/errors_test.go Updated error mapping test
internal/http/integration/*.go Updated to use ProvisionerMock and new services
docs/docs/scoreboard.md Removed window parameter documentation
cmd/server/main.go Wired up new services

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +113 to 116
`GET /api/timeline/teams`

Response 200

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The error section "Errors: - 400 invalid input" should be removed from the Team Timeline documentation since the window parameter was removed and there are no validation errors for this endpoint anymore.

Copilot uses AI. Check for mistakes.
yulmwu and others added 2 commits February 18, 2026 13:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@yulmwu yulmwu merged commit 88ddb9b into main Feb 18, 2026
2 checks passed
@yulmwu yulmwu deleted the refactor/v1.1.0 branch February 18, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant