Skip to content

Fix initial_sync for existing watch files#13728

Open
trinhchien wants to merge 1 commit intodocker:mainfrom
trinhchien:fix/watch-initial-sync-existing-files
Open

Fix initial_sync for existing watch files#13728
trinhchien wants to merge 1 commit intodocker:mainfrom
trinhchien:fix/watch-initial-sync-existing-files

Conversation

@trinhchien
Copy link
Copy Markdown

Summary

  • make initial_sync copy existing files regardless of image creation time
  • add tests covering both directory and single-file watch paths

Repro

Fixes #13725. Before this change, initial_sync: true could skip files that already existed on the host if their mtime was older than the service image creation time. Change-triggered syncs still worked, but the initial startup sync could be empty.

Testing

  • go test ./pkg/compose -run TestInitialSyncFiles_ -v

AI usage

Used AI assistance to help analyze the repro, shape the initial patch, and draft the tests. I reviewed and validated the final code and test results manually.

Copy link
Copy Markdown
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

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

Hey @trinhchien
Thanks for the contribution, there is few details to adapt in your PR. Can you take a look?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the change this function is now deadcode and should be removed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the changes this is no longer accurate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ctx and project aren't used anymore

Suggested change
func (s *composeService) initialSyncFiles(service types.ServiceConfig, trigger types.Trigger, ignore watch.PathMatcher) ([]*sync.PathMapping, error) {

Comment on lines +203 to +204
apiClient := mocks.NewMockAPIClient(mockCtrl)
cli.EXPECT().Client().Return(apiClient).AnyTimes()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No more reference to the api client, so we don't need the mock

Comment on lines +238 to +239
apiClient := mocks.NewMockAPIClient(mockCtrl)
cli.EXPECT().Client().Return(apiClient).AnyTimes()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

hostFile := filepath.Join(dir, "test.txt")
assert.NilError(t, os.WriteFile(hostFile, []byte("hello"), 0o644))

fileTime := time.Date(2026, 4, 1, 10, 0, 0, 0, time.UTC)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fileTime := time.Date(2026, 4, 1, 10, 0, 0, 0, time.UTC)
fileTime := time.Now().Add(-24*time.Hour)

hostFile := filepath.Join(hostDir, "test.txt")
assert.NilError(t, os.WriteFile(hostFile, []byte("hello"), 0o644))

fileTime := time.Date(2026, 4, 1, 10, 0, 0, 0, time.UTC)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fileTime := time.Date(2026, 4, 1, 10, 0, 0, 0, time.UTC)
fileTime := time.Now().Add(-24*time.Hour)

@trinhchien trinhchien force-pushed the fix/watch-initial-sync-existing-files branch from 6bd0f8b to f523966 Compare April 13, 2026 10:12
@trinhchien
Copy link
Copy Markdown
Author

Thanks for the review — I addressed the cleanup comments, simplified the tests as suggested, and updated the commit with a proper DCO sign-off.

Copy link
Copy Markdown
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

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

You need to sign-off your commit for legal reasons otherwise I won't be able to merge your contribution

// Syncs files from develop.watch.path if thy have been modified after the image has been created
// Syncs files from develop.watch.path, ignoring bind-mounted and excluded paths.
//
//nolint:gocyclo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: not needed anymore

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/compose/watch.go 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@trinhchien trinhchien force-pushed the fix/watch-initial-sync-existing-files branch from f523966 to 792f8be Compare April 13, 2026 12:41
Signed-off-by: trinhchien <trinhdacchien1598@gmail.com>
@trinhchien
Copy link
Copy Markdown
Author

Thanks — I added a small regression test to cover the initialSync path as well, and updated the branch.

@trinhchien trinhchien force-pushed the fix/watch-initial-sync-existing-files branch from 792f8be to 275cad2 Compare April 13, 2026 16:13
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.

[BUG] develop.watch initial_sync: true does not fire at container start

2 participants