Skip to content

cli: pin every config env var name in a golden - #3059

Open
momosh-ssv wants to merge 5 commits into
stagefrom
config-env-name-golden
Open

momosh-ssv wants to merge 5 commits into
stagefrom
config-env-name-golden

Conversation

@momosh-ssv

Copy link
Copy Markdown
Contributor

Follow-up from #3044 (comment).

Config env var names live only in struct tags. A typo or rename there makes an operator's env var silently do nothing, and a test that reads the name back from the tag reads the typo too.

  • testdata/envnames.golden.json (operator and bootnode) snapshots yamlPath -> env name through the same describer as defaults.golden.json, so any env name change shows up as a reviewed golden diff. assertDefaultsGolden becomes column-generic assertDescribeGolden.
  • Test_config_fields_wellFormed asserts no two fields share an env var and every env-backed field has an env-description (both hold today).

Checked: misspelling PROPOSER_DELAY_EPBS in its tag fails Test_config_envNames_golden. Regenerate intentionally with UPDATE_GOLDEN=1 go test ./cli/operator -run Test_config_envNames_golden.

When #3044 merges, its LEGACY_PROPOSER_ROUND_TIMEOUT needs one line in the operator golden; whichever lands second regenerates it.

  • E2E passed - [action log](put link here)

@momosh-ssv
momosh-ssv requested review from a team as code owners September 28, 2026 14:58
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.6%. Comparing base (f0e0453) to head (7fd63cf).

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds golden tests to pin environment variable names.

The PR appears safe to merge; no actionable issue was established.

Summary

The PR adds reviewed env-name snapshots for operator and bootnode configuration, plus tests for duplicate env names and missing descriptions. It also generalizes the existing defaults-golden helper without changing its defaults selection.

Reviews (1) · Last reviewed commit: "cli: pin every config env var name in a ..."

Comment thread cli/operator/testdata/envnames.golden.json
Comment thread cli/operator/config_golden_test.go Outdated
Comment thread cli/operator/config_golden_test.go
Comment thread cli/operator/config_golden_test.go
Comment thread cli/operator/config_golden_test.go Outdated
Base automatically changed from epbs-gloas to stage September 29, 2026 09:13
@momosh-ssv
momosh-ssv force-pushed the config-env-name-golden branch from d97da78 to 5455b09 Compare October 2, 2026 06:49
@momosh-ssv
momosh-ssv requested a review from iurii-ssv October 3, 2026 09:30

@iurii-ssv iurii-ssv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small thing about the PR description: it was written before the follow-ups. It still says #3044's line needs adding, it gives the old -run Test_config_envNames_golden regen command, and it doesn't mention Test_config_envNames_matchCleanenv.

Plus couple suggestions below.

for _, d := range globalcfg.Describe(cfg) {
if d.EnvName != "" { // skip nested-struct container rows
snapshot[d.YAMLPath] = d.Default
snapshot[d.YAMLPath] = column(d)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snapshot is keyed by YAMLPath, and that key isn't unique for a field that has an env tag but no yaml tag: describeStruct gives such a field its parent's path. If two of them sit in one struct, they get the same key and the second overwrites the first, so the first one's env name is never pinned. matchCleanenv and fields_wellFormed loop over Describe directly, so neither of them notices.

Nothing hits this today (80 env-backed rows, 80 keys). To check it, I added ProbeA string `env:"PROBE_A"` and ProbeB string `env:"PROBE_B"` to KeyStore and regenerated. The golden has only "KeyStore": "PROBE_B". Retagging ProbeA as PROBE_TYPO then passes Test_config_envNames_golden, matchCleanenv and fields_wellFormed.

Failing on a repeated key here would close the gap, and it also protects the defaults golden:

require.NotContainsf(t, snapshot, d.YAMLPath, "%s is the YAML path of more than one env-backed field (missing yaml tag?)", d.YAMLPath)

Same in cli/bootnode/boot_node_golden_test.go.

// cleanenvEnvNames lists the env vars cleanenv reads for cfg. cleanenv doesn't export its field
// metadata, so the names are parsed out of its help text, where each variable is a two-space
// indented "NAME kind" line.
func cleanenvEnvNames(t *testing.T, cfg any) []string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: after this PR the two golden test files share four functions word for word: assertDescribeGolden, cleanenvEnvNames, and the bodies of matchCleanenv and fields_wellFormed. That's about 75 lines in each file. Keeping them self-contained was cheap when it was one 20-line helper. Now any fix, like the one above or a cleanenv bump that changes the help format this function parses, has to be made twice, and the copies can drift apart.

Both packages already import cli/config. A small test-helper package next to it (e.g. cli/config/configtest) wouldn't tie operator and bootnode to each other, and each test here would shrink to a single call.

Base automatically changed from stage to main October 13, 2026 13:18
Env var names lived only in struct tags, so a typo or rename silently stopped an
operator's env var from applying, and nothing failed. Snapshot yamlPath -> env name
into envnames.golden.json for both operator and bootnode, through the same describer
the defaults golden uses (now a column-generic assertDescribeGolden).

Also assert two invariants the goldens don't: no two fields share an env var, and
every env-backed field has an env-description.
@momosh-ssv
momosh-ssv force-pushed the config-env-name-golden branch from 5455b09 to 7fd63cf Compare October 15, 2026 07:31
@momosh-ssv
momosh-ssv changed the base branch from main to stage October 15, 2026 07:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants