refactor: centralize runtime feature flag bindings (#2142)

This commit is contained in:
Carlos Florêncio
2026-08-02 15:36:21 +01:00
committed by GitHub
parent 443e9c89cc
commit e077658a61
29 changed files with 1495 additions and 506 deletions
+2 -1
View File
@@ -24,7 +24,8 @@
#
# Set its `prod` value to `true`. Ship the next release. Once the
# feature has been on by default for a release or two and is
# permanent, rip the flag out of the codebase entirely.
# permanent, remove its live wiring and move its key/environment pair
# to runtimeflags' append-only retired-identity set.
#
# ── See also ───────────────────────────────────────────────────────
#
@@ -13,6 +13,10 @@ import (
func TestApplyProfile_DefaultsToProd(t *testing.T) {
clearProfileSelectors(t)
clearProfilesYAMLVars(t)
defaults, err := FeatureFlagDefaults()
if err != nil {
t.Fatalf("FeatureFlagDefaults: %v", err)
}
count, env, err := ApplyProfile()
if err != nil {
@@ -21,9 +25,16 @@ func TestApplyProfile_DefaultsToProd(t *testing.T) {
if env != EnvProd {
t.Errorf("env = %q, want %q (no selector env vars set)", env, EnvProd)
}
// Prod writes each registered feature flag with its safe shipped default.
if count != 4 {
t.Errorf("ApplyProfile wrote %d vars in prod; want 4", count)
// Prod writes every declared feature flag with its shipped default. Derive
// the count so adding a flag cannot require another hard-coded update here.
if count != len(defaults) {
t.Errorf("ApplyProfile wrote %d vars in prod; want %d profile feature defaults", count, len(defaults))
}
for shortName, want := range defaults {
envVar := featurePrefix + strings.ToUpper(shortName)
if got := os.Getenv(envVar); got != want {
t.Errorf("%s = %q after prod ApplyProfile; want %q", envVar, got, want)
}
}
if v := os.Getenv("KANDEV_FEATURES_OFFICE"); v != "false" {
t.Errorf("KANDEV_FEATURES_OFFICE = %q after prod ApplyProfile; want %q", v, "false")
@@ -175,6 +186,18 @@ func TestFeatureFlagDefaults_LowercasesShortName(t *testing.T) {
}
}
func TestProfilesYAMLFeatureKeysUseRequiredPrefix(t *testing.T) {
file, err := parse(profilesYAML)
if err != nil {
t.Fatalf("parse profiles YAML: %v", err)
}
for envVar := range file["features"] {
if _, ok := stripFeaturePrefix(envVar); !ok {
t.Errorf("profiles.yaml feature key %q must start with %q and include a name", envVar, featurePrefix)
}
}
}
func TestMarkApplied_OnlyAllowsKnownDerivedEnvVars(t *testing.T) {
clearAppliedEnvVars(t)