Skip to content

Commit edb7f84

Browse files
committed
test(cli): pin the Chart.yaml strictCharts channel and the strict-source OR
Config.StrictCharts had no coverage from the Chart.yaml side: a yaml-tag typo would have silently disabled the committed team/CI enforcement while the per-invocation flag kept working. Pin the parse and the OR in surfaceChartDrift — either source alone blocks on drift, neither only warns. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent a44d621 commit edb7f84

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

‎main_test.go‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,83 @@ func TestLoadConfig_EmptyApplyTimeoutResolvesDefault(t *testing.T) {
184184
}
185185
}
186186

187+
// TestLoadConfig_StrictChartsParses pins the Chart.yaml → Config channel
188+
// of strict enforcement: `strictCharts: true` must land in
189+
// commands.Config.StrictCharts. This is the team/CI-wide form the README
190+
// recommends; a yaml-tag typo would silently disable it while the
191+
// per-invocation --strict-charts flag kept working, and no other test
192+
// would notice.
193+
func TestLoadConfig_StrictChartsParses(t *testing.T) {
194+
dir := t.TempDir()
195+
chartPath := filepath.Join(dir, "Chart.yaml")
196+
body := "apiVersion: v2\nname: test\nversion: 0.1.0\nstrictCharts: true\n"
197+
if err := os.WriteFile(chartPath, []byte(body), 0o644); err != nil {
198+
t.Fatalf("write Chart.yaml: %v", err)
199+
}
200+
201+
snapshotConfigState(t)
202+
203+
if err := loadConfig(chartPath); err != nil {
204+
t.Fatalf("loadConfig: %v", err)
205+
}
206+
207+
if !commands.Config.StrictCharts {
208+
t.Error("strictCharts: true in Chart.yaml did not set Config.StrictCharts; the committed enforcement channel is broken")
209+
}
210+
}
211+
212+
// TestSurfaceChartDrift_StrictSources pins the OR between the two strict
213+
// opt-ins consumed by surfaceChartDrift: the committed Chart.yaml field
214+
// (Config.StrictCharts) and the per-invocation --strict-charts flag. Either
215+
// alone must block on a drifted project; with both off the same project
216+
// must only warn.
217+
func TestSurfaceChartDrift_StrictSources(t *testing.T) {
218+
snapshot := func(t *testing.T, root string) {
219+
t.Helper()
220+
snapshotConfigState(t)
221+
222+
savedVersion := Version
223+
savedFlag := strictChartsFlag
224+
t.Cleanup(func() {
225+
Version = savedVersion
226+
strictChartsFlag = savedFlag
227+
})
228+
229+
Version = "0.30.0"
230+
commands.Config.RootDir = root
231+
}
232+
233+
t.Run("Chart.yaml strictCharts alone blocks", func(t *testing.T) {
234+
snapshot(t, writeDriftedTalmProject(t))
235+
commands.Config.StrictCharts = true
236+
strictChartsFlag = false
237+
238+
if err := surfaceChartDrift(); err == nil {
239+
t.Error("strictCharts: true from Chart.yaml must block on drift without the flag")
240+
}
241+
})
242+
243+
t.Run("--strict-charts flag alone blocks", func(t *testing.T) {
244+
snapshot(t, writeDriftedTalmProject(t))
245+
commands.Config.StrictCharts = false
246+
strictChartsFlag = true
247+
248+
if err := surfaceChartDrift(); err == nil {
249+
t.Error("--strict-charts must block on drift without the Chart.yaml field")
250+
}
251+
})
252+
253+
t.Run("neither source set only warns", func(t *testing.T) {
254+
snapshot(t, writeDriftedTalmProject(t))
255+
commands.Config.StrictCharts = false
256+
strictChartsFlag = false
257+
258+
if err := surfaceChartDrift(); err != nil {
259+
t.Errorf("drift without strict opt-in must warn, not block: %v", err)
260+
}
261+
})
262+
}
263+
187264
// TestRegisterRootFlags_NodesHasNoShorthand pins that talm's
188265
// root `--nodes` does NOT claim the `-n` shorthand. With `-n`
189266
// registered as the alias for `--nodes`, the global captures any

0 commit comments

Comments
 (0)