fix: tolerate partial delivery config

This commit is contained in:
eding 2026-08-23 19:01:18 +02:00
parent e0bc2a34b0
commit 5c7bbf6e21
4 changed files with 41 additions and 21 deletions

View file

@ -33,7 +33,7 @@ func TestPublishAppRequiresDeliveryConfigBeforeCheckout(t *testing.T) {
bootstrapConfigPath = "test-config.yaml" bootstrapConfigPath = "test-config.yaml"
bootstrapPublishAppFrom = "app-checkout" bootstrapPublishAppFrom = "app-checkout"
loadPublishAppConfig = func(string) (config.Config, error) { loadPublishAppConfig = func(string) (config.Config, error) {
return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}}, nil return config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}}, nil
} }
ensurePublishAppCheckoutClean = func(string) error { ensurePublishAppCheckoutClean = func(string) error {
t.Fatal("publish inspected the checkout before validating delivery config") t.Fatal("publish inspected the checkout before validating delivery config")

View file

@ -80,7 +80,7 @@ func TestGeneratedDeliveryIsGenericAndUsesSafePreviewCleanupContract(t *testing.
func TestGenerateAppDeliveryRequiresCompleteConfig(t *testing.T) { func TestGenerateAppDeliveryRequiresCompleteConfig(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
err := GenerateAppDelivery(dir, config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}}) err := GenerateAppDelivery(dir, config.Config{Git: config.GitConfig{BaseURL: "https://git.example.test"}, Delivery: config.DeliveryConfig{AppName: "legacy-app"}})
if err == nil || !strings.Contains(err.Error(), "delivery appName") { if err == nil || !strings.Contains(err.Error(), "delivery appName") {
t.Fatalf("GenerateAppDelivery() error = %v, want incomplete delivery error", err) t.Fatalf("GenerateAppDelivery() error = %v, want incomplete delivery error", err)
} }
@ -710,6 +710,16 @@ func TestRunnerRegisterWebhookSkipsTemplateRevisions(t *testing.T) {
Nodes: []config.TalosNode{{Name: "cp-01", VMID: 100, Role: "controlplane", Networks: []config.TalosNetwork{{IP: "192.168.45.3", CIDR: "192.168.45.0/28", Gateway: "192.168.45.1", VLANID: 45}, {IP: "192.168.45.18", CIDR: "192.168.45.16/28", VLANID: 451}}}}, Nodes: []config.TalosNode{{Name: "cp-01", VMID: 100, Role: "controlplane", Networks: []config.TalosNetwork{{IP: "192.168.45.3", CIDR: "192.168.45.0/28", Gateway: "192.168.45.1", VLANID: 45}, {IP: "192.168.45.18", CIDR: "192.168.45.16/28", VLANID: 451}}}},
}, },
} }
partial := cfg
partial.Delivery.ImageRepository = ""
preflight = func(config.Config) error {
t.Fatal("webhook registration accepted incomplete delivery config")
return nil
}
if err := (Runner{Config: partial, RegisterWebhook: true}).Run(); err == nil || !strings.Contains(err.Error(), "imageRepository") {
t.Fatalf("webhook registration error = %v, want incomplete delivery error", err)
}
preflight = func(config.Config) error { return nil }
if err := (Runner{Config: cfg, RegisterWebhook: true}).Run(); err != nil { if err := (Runner{Config: cfg, RegisterWebhook: true}).Run(); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -28,23 +28,33 @@ func validConfig(t *testing.T) Config {
} }
} }
func TestResolveAcceptsPlatformOnlyConfig(t *testing.T) { func TestResolveDeliveryStates(t *testing.T) {
cfg := validConfig(t) platformOnly := validConfig(t)
cfg.Delivery.AppName = "" platformOnly.Delivery = DeliveryConfig{}
cfg.Delivery.AppRepoURL = "" partialLegacy := platformOnly
cfg.Delivery.AppRepoRef = "" partialLegacy.Delivery.AppName = "legacy-app"
cfg.Delivery.ProductionBranch = ""
cfg.Delivery.ImageRepository = "" for _, test := range []struct {
cfg.Delivery.BuildOutputDirectory = "" name string
cfg.Delivery.BuildConfiguration = "" cfg Config
cfg.Delivery.WebhookHostname = "" configured bool
cfg.Delivery.WebhookPath = "" }{
resolved, err := Resolve(cfg) {name: "absent", cfg: platformOnly},
{name: "partial legacy", cfg: partialLegacy},
{name: "complete", cfg: validConfig(t), configured: true},
} {
t.Run(test.name, func(t *testing.T) {
resolved, err := Resolve(test.cfg)
if err != nil { if err != nil {
t.Fatalf("Resolve() rejected platform-only config: %v", err) t.Fatalf("Resolve() error = %v", err)
} }
if resolved.Delivery.Configured() { if resolved.Delivery.Configured() != test.configured {
t.Fatal("Resolve() invented delivery settings for a platform-only config") t.Fatalf("Configured() = %t, want %t", resolved.Delivery.Configured(), test.configured)
}
if !test.configured && resolved.Delivery.AppRepoRef != "" {
t.Fatal("Resolve() defaulted delivery configuration treated as absent")
}
})
} }
} }

View file

@ -40,9 +40,9 @@ type DeliveryConfig struct {
WebhookPath string `yaml:"webhookPath"` WebhookPath string `yaml:"webhookPath"`
} }
// Configured reports whether the configuration contains any app-delivery setting. // Configured reports whether the non-default app-delivery settings are complete.
func (c DeliveryConfig) Configured() bool { func (c DeliveryConfig) Configured() bool {
return c.AppName != "" || c.AppRepoURL != "" || c.AppRepoRef != "" || c.ProductionBranch != "" || c.ImageRepository != "" || c.BuildOutputDirectory != "" || c.BuildConfiguration != "" || c.WebhookHostname != "" || c.WebhookPath != "" return c.AppName != "" && c.AppRepoURL != "" && c.ProductionBranch != "" && c.ImageRepository != ""
} }
func (c DeliveryConfig) WebhookURL() string { func (c DeliveryConfig) WebhookURL() string {