修复初始化分区配置代次同步
Some checks are pending
Security Checks / security (push) Waiting to run

同步初始化候选配置的分区 generation,避免数据库设置提交被分区代次校验拒绝,并补充回归测试。
This commit is contained in:
smail 2026-09-29 22:54:17 +08:00
parent feade20360
commit 0a7167eac0
2 changed files with 41 additions and 0 deletions

View File

@ -44,6 +44,46 @@ func TestPartitionedDatabaseConnectionPreservesMigrationTimezone(t *testing.T) {
}
}
func TestSetupRuntimeFromConfigSynchronizesSectionGeneration(t *testing.T) {
root := t.TempDir()
oldRoot := ROOT_PATH
ROOT_PATH = root
t.Cleanup(func() { ROOT_PATH = oldRoot })
current := validRuntimeConfig()
cfg := &Config{
SetupState: SetupStateBootstrap,
DbType: DBTypeSQLite,
DbDSN: "smail.db",
Domain: "mail.example.com",
Domains: []string{"mail.example.com"},
WebDomain: "mail.example.com",
SSLType: "0",
HttpsEnabled: 1,
HttpPort: 80,
HttpsPort: 443,
}
candidate, err := setupRuntimeFromConfig(current, cfg)
if err != nil {
t.Fatal(err)
}
if candidate.Generation != current.Generation+1 {
t.Fatalf("candidate generation = %d, want %d", candidate.Generation, current.Generation+1)
}
for section, generation := range map[Section]uint64{
SectionSMTP: candidate.SMTP.Meta.Generation,
SectionEmail: candidate.Email.Meta.Generation,
SectionSSL: candidate.SSL.Meta.Generation,
SectionPlugins: candidate.Plugins.Meta.Generation,
} {
if generation != candidate.Generation {
t.Fatalf("%s generation = %d, want %d", section, generation, candidate.Generation)
}
if candidate.Root.Sections[section].Generation != candidate.Generation {
t.Fatalf("%s reference generation = %d, want %d", section, candidate.Root.Sections[section].Generation, candidate.Generation)
}
}
}
func TestPartitionedCompatibilityStartupAndWriteProtection(t *testing.T) {
root := t.TempDir()
oldRoot, oldArgs, oldDevelopment := ROOT_PATH, os.Args, DevelopmentMode

View File

@ -135,6 +135,7 @@ func setupRuntimeFromConfig(current RuntimeConfig, cfg *Config) (RuntimeConfig,
candidate.Email.Policy.ExternalRecoveryEnabled = cfg.ExternalRecoveryEnabled
candidate.SSL.TLS = ssl
candidate.Root.UpdatedAt = time.Now().UTC()
setCandidateGeneration(&candidate, candidate.Generation)
return candidate, nil
}