30380a59f4
Operator sets a minimum controller version (FLOOR), per-customer defaulting to a
global floor; the report ACK returns the effective floor + latest_version so the
controller auto-updates to the floor when below it (latest stays the opt-in button).
- store: min_controller_version column + hub_settings global floor + Effective/
Get/SetGlobal/SetMin resolution + config/env DEFAULT_MIN_CONTROLLER_VERSION
- handler: report ACK {min_controller_version, latest_version}; LatestVersionProvider
- web: global floor editor + per-customer override form + Floor column (English)
- tests: floor resolution + ACK + render; override-precedence red-proof verified
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FSZmmSFVzGwEzhYmxbkgBK
112 lines
3.8 KiB
Go
112 lines
3.8 KiB
Go
package store
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func newFloorTestStore(t *testing.T) *Store {
|
|
t.Helper()
|
|
s, err := New(filepath.Join(t.TempDir(), "floor.db"), log.New(io.Discard, "", 0))
|
|
if err != nil {
|
|
t.Fatalf("store.New: %v", err)
|
|
}
|
|
t.Cleanup(func() { s.Close() })
|
|
return s
|
|
}
|
|
|
|
func mkCustomer(t *testing.T, s *Store, id, floor string) {
|
|
t.Helper()
|
|
if err := s.SaveCustomerConfig(&CustomerConfig{
|
|
CustomerID: id,
|
|
RetrievalPassword: "pw",
|
|
APIKey: "key-" + id,
|
|
ConfigJSON: "{}",
|
|
MinControllerVersion: floor,
|
|
}); err != nil {
|
|
t.Fatalf("SaveCustomerConfig(%s): %v", id, err)
|
|
}
|
|
}
|
|
|
|
// EffectiveMinControllerVersion: empty when nothing is set.
|
|
func TestEffectiveFloor_EmptyWhenUnset(t *testing.T) {
|
|
s := newFloorTestStore(t)
|
|
mkCustomer(t, s, "c", "")
|
|
if got := s.EffectiveMinControllerVersion("c"); got != "" {
|
|
t.Errorf("effective floor = %q, want empty (no override, no global)", got)
|
|
}
|
|
// Also empty for a customer with no config at all.
|
|
if got := s.EffectiveMinControllerVersion("ghost"); got != "" {
|
|
t.Errorf("effective floor for unknown customer = %q, want empty", got)
|
|
}
|
|
}
|
|
|
|
// The config/env default is the fallback global floor.
|
|
func TestEffectiveFloor_GlobalDefaultFallback(t *testing.T) {
|
|
s := newFloorTestStore(t)
|
|
s.SetDefaultMinControllerVersion("0.85.0")
|
|
mkCustomer(t, s, "c", "")
|
|
if got := s.EffectiveMinControllerVersion("c"); got != "0.85.0" {
|
|
t.Errorf("effective floor = %q, want 0.85.0 (global default)", got)
|
|
}
|
|
}
|
|
|
|
// A hub_settings row overrides the config/env default.
|
|
func TestGlobalFloor_DBOverridesDefault(t *testing.T) {
|
|
s := newFloorTestStore(t)
|
|
s.SetDefaultMinControllerVersion("0.85.0")
|
|
if err := s.SetGlobalMinControllerVersion("0.86.0"); err != nil {
|
|
t.Fatalf("SetGlobalMinControllerVersion: %v", err)
|
|
}
|
|
if got := s.GetGlobalMinControllerVersion(); got != "0.86.0" {
|
|
t.Errorf("global floor = %q, want 0.86.0 (DB beats default)", got)
|
|
}
|
|
// Clearing the row falls back to the default.
|
|
if err := s.SetGlobalMinControllerVersion(""); err != nil {
|
|
t.Fatalf("clear global floor: %v", err)
|
|
}
|
|
if got := s.GetGlobalMinControllerVersion(); got != "0.85.0" {
|
|
t.Errorf("global floor after clear = %q, want 0.85.0 (default)", got)
|
|
}
|
|
}
|
|
|
|
// Scenario C — per-customer override beats global. This is the companion RED-PROOF: it must FAIL if
|
|
// EffectiveMinControllerVersion ever returns the global when an override is set.
|
|
func TestEffectiveFloor_OverrideBeatsGlobal(t *testing.T) {
|
|
s := newFloorTestStore(t)
|
|
s.SetDefaultMinControllerVersion("0.85.0") // global
|
|
mkCustomer(t, s, "c", "0.87.0") // per-customer override
|
|
mkCustomer(t, s, "other", "") // no override → uses global
|
|
|
|
if got := s.EffectiveMinControllerVersion("c"); got != "0.87.0" {
|
|
t.Errorf("effective floor for c = %q, want 0.87.0 (override beats global)", got)
|
|
}
|
|
if got := s.EffectiveMinControllerVersion("other"); got != "0.85.0" {
|
|
t.Errorf("effective floor for other = %q, want 0.85.0 (global, no override)", got)
|
|
}
|
|
}
|
|
|
|
// SetMinControllerVersion round-trips and is preserved across an unrelated SaveCustomerConfig.
|
|
func TestSetMinControllerVersion_PreservedOnSave(t *testing.T) {
|
|
s := newFloorTestStore(t)
|
|
mkCustomer(t, s, "c", "")
|
|
if err := s.SetMinControllerVersion("c", "0.88.0"); err != nil {
|
|
t.Fatalf("SetMinControllerVersion: %v", err)
|
|
}
|
|
// A typical edit path: load, mutate an unrelated field, save.
|
|
cfg, _ := s.GetCustomerConfig("c")
|
|
if cfg.MinControllerVersion != "0.88.0" {
|
|
t.Fatalf("after Set, MinControllerVersion = %q, want 0.88.0", cfg.MinControllerVersion)
|
|
}
|
|
cfg.Email = "x@example.com"
|
|
if err := s.SaveCustomerConfig(cfg); err != nil {
|
|
t.Fatalf("SaveCustomerConfig: %v", err)
|
|
}
|
|
cfg2, _ := s.GetCustomerConfig("c")
|
|
if cfg2.MinControllerVersion != "0.88.0" {
|
|
t.Errorf("floor lost across save: %q, want 0.88.0", cfg2.MinControllerVersion)
|
|
}
|
|
}
|