fix: tolerate partial delivery config #15

Merged
eding merged 1 commit from fix/partial-delivery-reconcile into main 2026-08-23 19:06:39 +02:00
4 changed files with 41 additions and 21 deletions

View file

@ -33,7 +33,7 @@ func TestPublishAppRequiresDeliveryConfigBeforeCheckout(t *testing.T) {
bootstrapConfigPath = "test-config.yaml"
bootstrapPublishAppFrom = "app-checkout"
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 {
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) {
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") {
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}}}},
},
}
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 {
t.Fatal(err)
}

View file

@ -28,23 +28,33 @@ func validConfig(t *testing.T) Config {
}
}
func TestResolveAcceptsPlatformOnlyConfig(t *testing.T) {
cfg := validConfig(t)
cfg.Delivery.AppName = ""
cfg.Delivery.AppRepoURL = ""
cfg.Delivery.AppRepoRef = ""
cfg.Delivery.ProductionBranch = ""
cfg.Delivery.ImageRepository = ""
cfg.Delivery.BuildOutputDirectory = ""
cfg.Delivery.BuildConfiguration = ""
cfg.Delivery.WebhookHostname = ""
cfg.Delivery.WebhookPath = ""
resolved, err := Resolve(cfg)
func TestResolveDeliveryStates(t *testing.T) {
platformOnly := validConfig(t)
platformOnly.Delivery = DeliveryConfig{}
partialLegacy := platformOnly
partialLegacy.Delivery.AppName = "legacy-app"
for _, test := range []struct {
name string
cfg Config
configured bool
}{
{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 {
t.Fatalf("Resolve() rejected platform-only config: %v", err)
t.Fatalf("Resolve() error = %v", err)
}
if resolved.Delivery.Configured() {
t.Fatal("Resolve() invented delivery settings for a platform-only config")
if resolved.Delivery.Configured() != test.configured {
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"`
}
// 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 {
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 {