[agent/codex:gpt-5.3-codex-spark] Read ~/spec/code/core/go/config/RFC.md fully. Find features ... #4

Merged
Virgil merged 1 commit from agent/read---spec-code-core-go-config-rfc-md-f into dev 2026-04-03 07:34:14 +00:00
2 changed files with 27 additions and 0 deletions

View file

@ -1,12 +1,14 @@
package config
import (
"context"
"fmt"
"maps"
"os"
"testing"
coreio "forge.lthn.ai/core/go-io"
core "forge.lthn.ai/core/go/pkg/core"
"github.com/stretchr/testify/assert"
)
@ -409,6 +411,26 @@ func TestConfig_WithEnvPrefix_TrailingUnderscore_Good(t *testing.T) {
assert.Equal(t, "secret", setting)
}
func TestService_OnStartup_WithEnvPrefix_Good(t *testing.T) {
t.Setenv("MYAPP_SETTING", "secret")
m := coreio.NewMockMedium()
svc := &Service{
ServiceRuntime: core.NewServiceRuntime(nil, ServiceOptions{
EnvPrefix: "MYAPP",
Medium: m,
}),
}
err := svc.OnStartup(context.Background())
assert.NoError(t, err)
var setting string
err = svc.Get("setting", &setting)
assert.NoError(t, err)
assert.Equal(t, "secret", setting)
}
func TestConfig_Get_EmptyKey(t *testing.T) {
m := coreio.NewMockMedium()
m.Files["/config.yaml"] = "app:\n name: test\nversion: 1"

View file

@ -18,6 +18,8 @@ type Service struct {
type ServiceOptions struct {
// Path overrides the default config file path.
Path string
// EnvPrefix overrides the default environment variable prefix.
EnvPrefix string
// Medium overrides the default storage medium.
Medium coreio.Medium
}
@ -39,6 +41,9 @@ func (s *Service) OnStartup(_ context.Context) error {
if opts.Path != "" {
configOpts = append(configOpts, WithPath(opts.Path))
}
if opts.EnvPrefix != "" {
configOpts = append(configOpts, WithEnvPrefix(opts.EnvPrefix))
}
if opts.Medium != nil {
configOpts = append(configOpts, WithMedium(opts.Medium))
}