Skip to content

Commit 06f02e9

Browse files
committed
config: make WorkerRootPath a derived method, not a parsed field
Addresses review feedback: WorkerRootPath isn't something a user provides, so it doesn't belong in Config as a settable/parsed field (and isn't documented in config/README.md). Move the <workspaces_root_path>/.workers derivation into a ServiceConfig method with its own test, so it can't drift from what's documented on WorkspacesRootPath, and Parse no longer computes or stores it.
1 parent 76e272b commit 06f02e9

3 files changed

Lines changed: 15 additions & 39 deletions

File tree

config/config_test.go

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,41 +70,11 @@ repository:
7070
}
7171
}
7272

73-
func TestParse_ServiceDefaults(t *testing.T) {
74-
tests := []struct {
75-
name string
76-
give string
77-
wantWorkerRootPath string
78-
}{
79-
{
80-
name: "worker_root_path defaults when unset",
81-
give: _baseServiceYAML + `
82-
repository:
83-
- remote: "r1"
84-
`,
85-
wantWorkerRootPath: filepath.Join("/tmp/x", ".workers"),
86-
},
87-
{
88-
name: "worker_root_path explicit value preserved",
89-
give: `
90-
service:
91-
workspaces_root_path: "/tmp/x"
92-
worker_root_path: "/tmp/custom-workers"
93-
max_worker_pool_size: 1
94-
repository:
95-
- remote: "r1"
96-
`,
97-
wantWorkerRootPath: "/tmp/custom-workers",
98-
},
99-
}
100-
101-
for _, tt := range tests {
102-
t.Run(tt.name, func(t *testing.T) {
103-
cfg, err := Parse(writeConfig(t, tt.give))
104-
require.NoError(t, err)
105-
assert.Equal(t, tt.wantWorkerRootPath, cfg.Service.WorkerRootPath)
106-
})
107-
}
73+
func TestServiceConfig_WorkerRootPath(t *testing.T) {
74+
// Guards the layout documented on ServiceConfig.WorkspacesRootPath:
75+
// <workspaces_root_path>/.workers for worker checkouts.
76+
svc := ServiceConfig{WorkspacesRootPath: "/tmp/x"}
77+
assert.Equal(t, filepath.Join("/tmp/x", ".workers"), svc.WorkerRootPath())
10878
}
10979

11080
func TestParse_RepositoryDefaults(t *testing.T) {

config/service_config.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package config
1616

17+
import "path/filepath"
18+
1719
// ServiceConfig holds operational configuration for the Tango service.
1820
type ServiceConfig struct {
1921
// MaxWorkerPoolSize is the max number of concurrent requests per repository.
@@ -26,10 +28,14 @@ type ServiceConfig struct {
2628
// worker checkouts.
2729
WorkspacesRootPath string `yaml:"workspaces_root_path"`
2830
Streaming ChunkConfig `yaml:"streaming"` // streaming chunk sizes; zero values fall back to package defaults
31+
}
2932

30-
// WorkerRootPath is the root directory for worker workspace checkouts,
31-
// set by Parse to <workspaces_root_path>/.workers. Not settable via YAML.
32-
WorkerRootPath string `yaml:"-"`
33+
// WorkerRootPath returns the root directory for worker workspace checkouts, as
34+
// documented on WorkspacesRootPath: <workspaces_root_path>/.workers. It is a
35+
// derived value, not something a user provides, so it's a method rather than
36+
// a parsed field.
37+
func (s ServiceConfig) WorkerRootPath() string {
38+
return filepath.Join(s.WorkspacesRootPath, ".workers")
3339
}
3440

3541
// ChunkConfig controls the number of entries per gRPC stream message.

example/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func run() error {
7272

7373
// Repo manager and orchestrator
7474
repoManagerClonePath := cfg.Service.WorkspacesRootPath
75-
workerRootPath := cfg.Service.WorkerRootPath
75+
workerRootPath := cfg.Service.WorkerRootPath()
7676
if err := os.MkdirAll(repoManagerClonePath, 0o755); err != nil {
7777
return fmt.Errorf("failed to create repo manager clone path: %w", err)
7878
}

0 commit comments

Comments
 (0)