Skip to content

Commit 507bb74

Browse files
authored
Merge pull request #51 from davidweterings/fix/inheritance-bug
Fix/inheritance bug
2 parents afa166f + 7b76ec3 commit 507bb74

File tree

5 files changed

+144
-3
lines changed

5 files changed

+144
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixed
2+
body: Inheritance when partially bool was set
3+
time: 2025-06-30T22:54:41.038341+02:00

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ mach-composer-plugin-*
33

44
# Coverage file
55
*.out
6+
7+
.idea/
8+
.claude/

internal/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (c *VercelConfig) extendConfig(o *VercelConfig) *VercelConfig {
5858
type ProjectConfig struct {
5959
Name string `mapstructure:"name"`
6060
Framework string `mapstructure:"framework"`
61-
ManualProductionDeployment bool `mapstructure:"manual_production_deployment"`
61+
ManualProductionDeployment *bool `mapstructure:"manual_production_deployment"`
6262
ServerlessFunctionRegion string `mapstructure:"serverless_function_region"`
6363
EnvironmentVariables []ProjectEnvironmentVariable `mapstructure:"environment_variables"`
6464
GitRepository GitRepository `mapstructure:"git_repository"`
@@ -113,7 +113,7 @@ func (c *ProjectConfig) extendConfig(o *ProjectConfig) *ProjectConfig {
113113
cfg.RootDirectory = c.RootDirectory
114114
}
115115

116-
if c.ManualProductionDeployment != o.ManualProductionDeployment {
116+
if c.ManualProductionDeployment != nil {
117117
cfg.ManualProductionDeployment = c.ManualProductionDeployment
118118
}
119119

internal/plugin.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ func (p *VercelPlugin) getSiteConfig(site string) (*VercelConfig, error) {
138138
}
139139

140140
func (p *VercelPlugin) getConfig(site string, component string) *VercelConfig {
141-
142141
cfg, err := p.getComponentConfig(site, component)
143142
if err != nil {
144143
cfg, err = p.getSiteConfig(site)
@@ -163,6 +162,12 @@ func (p *VercelPlugin) getConfig(site string, component string) *VercelConfig {
163162
}
164163
}
165164

165+
// keep existing behavior to false when omitted
166+
if cfg.ProjectConfig.ManualProductionDeployment == nil {
167+
defaultFalse := false
168+
cfg.ProjectConfig.ManualProductionDeployment = &defaultFalse
169+
}
170+
166171
return cfg
167172
}
168173

internal/plugin_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,133 @@ func TestCompleteInheritance(t *testing.T) {
585585
assert.Contains(t, component.Variables, "production_branch = \"production\"")
586586
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = true")
587587
}
588+
589+
func TestManualProductionDeploymentBehavior(t *testing.T) {
590+
t.Run("defaults to false when not specified", func(t *testing.T) {
591+
plugin := NewVercelPlugin()
592+
593+
data := map[string]any{
594+
"team_id": "test-team",
595+
"api_token": "test-token",
596+
"project_config": map[string]any{
597+
"framework": "nextjs",
598+
},
599+
}
600+
601+
err := plugin.SetSiteConfig("my-site", data)
602+
require.NoError(t, err)
603+
604+
component, err := plugin.RenderTerraformComponent("my-site", "test-component")
605+
require.NoError(t, err)
606+
607+
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = false")
608+
})
609+
610+
t.Run("explicit false is preserved", func(t *testing.T) {
611+
plugin := NewVercelPlugin()
612+
613+
data := map[string]any{
614+
"team_id": "test-team",
615+
"api_token": "test-token",
616+
"project_config": map[string]any{
617+
"framework": "nextjs",
618+
"manual_production_deployment": false,
619+
},
620+
}
621+
622+
err := plugin.SetSiteConfig("my-site", data)
623+
require.NoError(t, err)
624+
625+
component, err := plugin.RenderTerraformComponent("my-site", "test-component")
626+
require.NoError(t, err)
627+
628+
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = false")
629+
})
630+
631+
t.Run("inheritance: child overrides parent", func(t *testing.T) {
632+
plugin := NewVercelPlugin()
633+
634+
globalData := map[string]any{
635+
"team_id": "test-team",
636+
"api_token": "test-token",
637+
"project_config": map[string]any{
638+
"manual_production_deployment": false,
639+
},
640+
}
641+
642+
siteData := map[string]any{
643+
"project_config": map[string]any{
644+
"manual_production_deployment": true,
645+
},
646+
}
647+
648+
err := plugin.SetGlobalConfig(globalData)
649+
require.NoError(t, err)
650+
651+
err = plugin.SetSiteConfig("my-site", siteData)
652+
require.NoError(t, err)
653+
654+
component, err := plugin.RenderTerraformComponent("my-site", "test-component")
655+
require.NoError(t, err)
656+
657+
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = true")
658+
})
659+
660+
t.Run("inheritance: inherits false when not specified", func(t *testing.T) {
661+
plugin := NewVercelPlugin()
662+
663+
globalData := map[string]any{
664+
"team_id": "test-team",
665+
"api_token": "test-token",
666+
"project_config": map[string]any{
667+
"manual_production_deployment": false,
668+
},
669+
}
670+
671+
siteData := map[string]any{
672+
"project_config": map[string]any{
673+
"framework": "nextjs",
674+
},
675+
}
676+
677+
err := plugin.SetGlobalConfig(globalData)
678+
require.NoError(t, err)
679+
680+
err = plugin.SetSiteConfig("my-site", siteData)
681+
require.NoError(t, err)
682+
683+
component, err := plugin.RenderTerraformComponent("my-site", "test-component")
684+
require.NoError(t, err)
685+
686+
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = false")
687+
})
688+
689+
t.Run("inheritance: inherits true when not specified", func(t *testing.T) {
690+
plugin := NewVercelPlugin()
691+
692+
globalData := map[string]any{
693+
"team_id": "test-team",
694+
"api_token": "test-token",
695+
"project_config": map[string]any{
696+
"manual_production_deployment": true,
697+
},
698+
}
699+
700+
siteData := map[string]any{
701+
"project_config": map[string]any{
702+
"framework": "nextjs",
703+
},
704+
}
705+
706+
err := plugin.SetGlobalConfig(globalData)
707+
require.NoError(t, err)
708+
709+
err = plugin.SetSiteConfig("my-site", siteData)
710+
require.NoError(t, err)
711+
712+
component, err := plugin.RenderTerraformComponent("my-site", "test-component")
713+
require.NoError(t, err)
714+
715+
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = true")
716+
})
717+
}

0 commit comments

Comments
 (0)