Skip to content

Commit 99acf9f

Browse files
trlyampagent
andcommitted
Fix env file discovery by using project working directory
The SpecProcessor was using the repository base directory instead of the project-specific working directory for env file discovery. This caused FindEnvFiles() to look in the wrong location. Fix: Use project.WorkingDir (set by compose reader) in Process() to create the converter with the correct directory context. This ensures .env files are discovered from the compose project directory. - Moved working directory detection from constructor to Process() - Maintains testability by using mocked ComposeProcessor - All tests pass Amp-Thread-ID: https://ampcode.com/threads/T-b185b0a5-0079-46ce-ae1d-8c3e80bba402 Co-authored-by: Amp <amp@ampcode.com>
1 parent 1bf7c38 commit 99acf9f

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

cmd/app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (a *App) IsPlatformAvailable() bool {
143143
return a.platformErr == nil
144144
}
145145

146-
// newComposeProcessor creates a new compose processor with the repository directory.
147-
func newComposeProcessor(cfg *config.Settings) ComposeProcessorInterface {
148-
return compose.NewSpecProcessor(cfg.RepositoryDir)
146+
// newComposeProcessor creates a new compose processor.
147+
func newComposeProcessor(_ *config.Settings) ComposeProcessorInterface {
148+
return compose.NewSpecProcessor()
149149
}

internal/compose/processor.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,21 @@ import (
1010
)
1111

1212
// SpecProcessor processes Docker Compose projects into service specs.
13-
// It wraps Converter to provide the standard Process interface.
14-
type SpecProcessor struct {
15-
converter *Converter
16-
}
13+
type SpecProcessor struct{}
1714

18-
// NewSpecProcessor creates a new SpecProcessor with the given working directory.
19-
func NewSpecProcessor(workingDir string) *SpecProcessor {
20-
return &SpecProcessor{
21-
converter: NewConverter(workingDir),
22-
}
15+
// NewSpecProcessor creates a new SpecProcessor.
16+
func NewSpecProcessor() *SpecProcessor {
17+
return &SpecProcessor{}
2318
}
2419

2520
// Process converts a Docker Compose project to service specs.
21+
// Uses project.WorkingDir for env file discovery.
2622
func (p *SpecProcessor) Process(_ context.Context, project *types.Project) ([]service.Spec, error) {
2723
if project == nil {
2824
return nil, fmt.Errorf("project is nil")
2925
}
3026

31-
return p.converter.ConvertProject(project)
27+
// Use project's working directory for env file discovery
28+
converter := NewConverter(project.WorkingDir)
29+
return converter.ConvertProject(project)
3230
}

0 commit comments

Comments
 (0)