diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 0e0441dde..5203b470c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -30,10 +30,15 @@ jobs: steps: - uses: actions/checkout@v5 + # No `cache: pip` here: this repository is Go and has no + # requirements.txt or pyproject.toml for setup-python to hash. Asking for + # a pip cache makes the step fail outright with "No file ... matched to + # [**/requirements.txt or **/pyproject.toml]", so every docs-touching PR + # failed before `mkdocs build --strict` ever ran -- which also meant the + # strict link/config check silently stopped guarding anything. - uses: actions/setup-python@v6 with: python-version: "3.13" - cache: pip - run: pip install mkdocs-material diff --git a/internal/infrastructure/configuration/apply_test.go b/internal/infrastructure/configuration/apply_test.go index aef59645c..d0b03ebca 100644 --- a/internal/infrastructure/configuration/apply_test.go +++ b/internal/infrastructure/configuration/apply_test.go @@ -30,6 +30,55 @@ func TestApplyOverlayValuesFieldLevelMerge(t *testing.T) { } } +// TestApplyOverlayValuesPreservesOmittedNestedFields pins ApplyOverlayValues' +// documented promise -- "only the keys present are replaced, every field the +// overlay omits keeps its existing value" -- at the depth where it matters. +// +// The concrete risk is services.state: an overlay that changes only the target +// must not clear target_token, because dropping the token silently removes +// authentication for a non-loopback State Store. The existing field-level test +// only covers one level (budgets.max_steps); these cases go two levels deep into +// a struct of structs, which is the shape Services has. +func TestApplyOverlayValuesPreservesOmittedNestedFields(t *testing.T) { + tests := []struct { + name string + start config.Services + overlay map[string]any + want config.Services + }{ + { + name: "target-only overlay keeps the token", + start: config.Services{State: config.ServiceConnection{Target: "127.0.0.1:50051", TargetToken: "secret"}}, + overlay: map[string]any{"services": map[string]any{"state": map[string]any{"target": "10.0.0.5:50051"}}}, + want: config.Services{State: config.ServiceConnection{Target: "10.0.0.5:50051", TargetToken: "secret"}}, + }, + { + name: "token-only overlay keeps the target", + start: config.Services{State: config.ServiceConnection{Target: "10.0.0.5:50051", TargetToken: "old"}}, + overlay: map[string]any{"services": map[string]any{"state": map[string]any{"target_token": "rotated"}}}, + want: config.Services{State: config.ServiceConnection{Target: "10.0.0.5:50051", TargetToken: "rotated"}}, + }, + { + name: "sibling service is untouched", + start: config.Services{Gateway: config.ServiceConnection{Target: "127.0.0.1:50052"}, State: config.ServiceConnection{Target: "a", TargetToken: "t"}}, + overlay: map[string]any{"services": map[string]any{"state": map[string]any{"target": "b"}}}, + want: config.Services{Gateway: config.ServiceConnection{Target: "127.0.0.1:50052"}, State: config.ServiceConnection{Target: "b", TargetToken: "t"}}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := config.Config{Services: tt.start} + if err := ApplyOverlayValues(&cfg, tt.overlay); err != nil { + t.Fatalf("ApplyOverlayValues: %v", err) + } + if cfg.Services != tt.want { + t.Errorf("Services = %+v, want %+v", cfg.Services, tt.want) + } + }) + } +} + func TestLoaderApplyOverlayLayersDefaultsValidatesAndRecordsProvenance(t *testing.T) { path := filepath.Join(t.TempDir(), "config.toml") if err := os.WriteFile(path, []byte("bot_user = \"widget\"\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"), 0o600); err != nil {