Skip to content

fix: refresh is incorrect in v1.17#1360

Merged
hwbrzzl merged 6 commits intomasterfrom
bowen/fix-refresh
Jan 28, 2026
Merged

fix: refresh is incorrect in v1.17#1360
hwbrzzl merged 6 commits intomasterfrom
bowen/fix-refresh

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Jan 26, 2026

📑 Description

Summary by CodeRabbit

Release Notes

  • New Features

    • Added explicit Build step in application lifecycle
    • Added Restart method for graceful application restart
    • SetBuilder method for custom configuration injection
  • Improvements

    • Shutdown now returns error for better error handling
    • Simplified Start method signature
    • Enhanced application lifecycle management with improved runner control and error handling

✏️ Tip: You can customize this high-level summary in your review settings.

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl marked this pull request as ready for review January 27, 2026 09:10
@hwbrzzl hwbrzzl requested a review from a team as a code owner January 27, 2026 09:10
@hwbrzzl
Copy link
Contributor Author

hwbrzzl commented Jan 27, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 43.72093% with 121 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.01%. Comparing base (ec87b76) to head (d0a2806).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
foundation/application.go 43.92% 108 Missing and 12 partials ⚠️
foundation/application_builder.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1360      +/-   ##
==========================================
- Coverage   70.64%   70.01%   -0.63%     
==========================================
  Files         286      286              
  Lines       17650    17690      +40     
==========================================
- Hits        12468    12386      -82     
- Misses       4654     4767     +113     
- Partials      528      537       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

This PR restructures the Application lifecycle by moving configuration logic from ApplicationBuilder to Application, simplifies the Start() signature to accept no parameters, adds error returns to Shutdown(), and introduces Build(), Restart(), and SetBuilder() methods for managing initialization and restart operations.

Changes

Cohort / File(s) Summary
Interface Contracts
contracts/foundation/application.go, contracts/foundation/application_builder.go
Application interface: removed AddServiceProviders(), BootServiceProviders(), Wait(); modified Start(runners ...Runner) to Start(), Shutdown() to Shutdown() error; added Build(), Restart() error, SetBuilder(). ApplicationBuilder interface: removed Start() method.
Core Implementation
foundation/application.go
Introduced RunnerWithInfo type for runner lifecycle management. Added builder field and configuration logic migration from ApplicationBuilder. Implemented new public methods: Build(), Start(), Restart() error, SetBuilder(), and error-returning Shutdown(). Added 15 private configuration methods (e.g., configureGrpc, configureJobs, configureValidation) to modularize bootstrapping.
Builder Implementation
foundation/application_builder.go
Stripped down ApplicationBuilder by removing Start() and all 17 internal configuration methods (moved to Application). Removed imports for color utilities and configuration hooks. Builder now focuses solely on configuration methods with no internal bootstrap logic.
Test Coverage
foundation/application_builder_test.go
Removed extensive test cases for Create() and Start() flows including WithX method scenarios; retained simpler configuration API tests (TestWithConfig, TestWithMiddleware, etc.). Eliminated 739 lines of integration-style test coverage.
Application Tests
foundation/application_test.go
Added 15 new TestConfigureXxx test suites validating individual configuration methods. Expanded path methods and Start/Shutdown flow tests. Added 783 lines covering nil/empty builder hook scenarios and runner lifecycle interactions.
Mock Objects
mocks/foundation/Application.go, mocks/foundation/ApplicationBuilder.go
Application mock: added Build(), Restart(), SetBuilder(); modified Start() signature (no runners); updated Shutdown() to return error; removed AddServiceProviders(), BootServiceProviders(), Wait(). ApplicationBuilder mock: removed Start() method and associated call types.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant App as Application
    participant Builder as ApplicationBuilder
    participant Runners as Runner Collection
    participant Providers as Service Providers

    Client->>App: SetBuilder(builder)
    App->>App: store builder
    App-->>Client: return self

    Client->>App: Build()
    App->>Builder: access configuration
    App->>Providers: RegisterBaseServiceProviders()
    Providers-->>App: ready
    App->>App: configurePaths()
    App->>App: configureServiceProviders()
    App->>App: configureRoutes()
    App->>App: configureGrpc()
    App->>App: configureJobs()
    App->>App: configureValidation()
    App->>Runners: collect runners
    Runners-->>App: RunnerWithInfo[]
    App-->>Client: return self

    Client->>App: Start()
    App->>Runners: execute all runners
    Runners->>Runners: wait/block
    Runners-->>App: running...

    Client->>App: Shutdown()
    App->>Runners: signal stop
    Runners->>Runners: graceful shutdown
    App->>App: wait with timeout
    App-->>Client: error or nil

    Client->>App: Restart()
    App->>App: Shutdown()
    App->>App: Build()
    App->>App: Start()
    App-->>Client: error or nil
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • fix: dependency error #659: Modifies the Application interface in contracts/foundation/application.go, changing its public method set in parallel with this PR's interface changes.
  • chore: upgrade mockery #778: Updates mocks for foundation.Application in mocks/foundation/Application.go, modifying the same mock signatures related to Application lifecycle methods.

Suggested reviewers

  • krishankumar01
  • devhaozi

Poem

🐰 hops excitedly

Build, start, and restart with grace,
New flows bring order to the space,
Configuration spreads its wings so wide,
The Application now leads with pride! 🎉

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title 'fix: refresh is incorrect in v1.17' does not accurately reflect the substantial changes made. The changeset involves a comprehensive refactoring of the Application and ApplicationBuilder lifecycle—moving from a provider-based model to a builder-based model with new Build(), Start(), Shutdown(error), and Restart() methods. While the summary mentions 'Updated Refresh() to reflect a clarified operational meaning', this is a minor comment update unrelated to the core architectural changes. Revise the title to reflect the main architectural changes, such as 'refactor: restructure application lifecycle with builder-based initialization' or 'refactor: migrate application to builder-based architecture with new lifecycle methods'.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@foundation/application.go`:
- Around line 212-230: The lint S1006 flags the use of `for true {}` in two
loops; update both loops that iterate waiting for runners (the loop using
r.runnersToRun and the second occurrence around line 297) to the idiomatic
infinite loop form `for {}`; locate the loops that reference r.runnersToRun, the
local variables `failed`, `runner.running`, and the timeout check (`i > 100`)
and replace `for true {` with `for {` in both places.
- Around line 40-44: The RunnerWithInfo.running field is accessed from multiple
goroutines unsafely and runnerWg.Done() can be called twice; change running to
an atomic.Bool (replace reads/writes in Start(), Restart(), Shutdown() with
atomic load/store), replace any for true loops with for { } to satisfy S1006,
and protect the single Done call with a sync.Once to ensure runnerWg.Done() is
only invoked once; additionally, in SetBuilder() perform a safe type check
(e.g., a type assertion with ok) before casting to the concrete builder type (or
document the required type) to avoid panics. Ensure all references to
RunnerWithInfo.running, Start(), Restart(), Shutdown(), runnerWg.Done(), and
SetBuilder() are updated to use atomic operations, sync.Once, and safe type
handling, then run the race detector (go test -race ./...) to validate.
🧹 Nitpick comments (1)
foundation/application.go (1)

271-274: Avoid unsafe type assertion in SetBuilder.

SetBuilder panics for any ApplicationBuilder implementation that isn’t *ApplicationBuilder. Consider guarding with a safe assertion (or narrowing the signature to the concrete type) so the failure is explicit and easier to debug. Also consider a nil-builder fallback in Build() to avoid nil deref if Build() is called directly.

🔍 Safer assertion
 func (r *Application) SetBuilder(builder foundation.ApplicationBuilder) foundation.Application {
-	r.builder = builder.(*ApplicationBuilder)
+	b, ok := builder.(*ApplicationBuilder)
+	if !ok {
+		panic("SetBuilder expects *foundation.ApplicationBuilder")
+	}
+	r.builder = b

 	return r
 }

@hwbrzzl hwbrzzl merged commit 73b29d7 into master Jan 28, 2026
16 of 18 checks passed
@hwbrzzl hwbrzzl deleted the bowen/fix-refresh branch January 28, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant