feat: enhance configuration management with main and route configs

- Added `main_config` and `route_config` fields to ActiveConfigResponse and AgentConfigResponse for better configuration handling.
- Updated NginxManager interface to accept separate main and route configurations.
- Modified sync service to apply main and route configurations correctly.
- Enhanced tests to validate new configuration fields and their application.
- Updated ConfigVersion model to include main configuration.
- Improved rendering logic for main and route configurations in the service layer.
- Added UI components to display main configuration changes and OpenResty parameter changes.
This commit is contained in:
ryan
2026-03-12 22:26:06 +08:00
parent 88b99c5cd9
commit 4c0466a92b
16 changed files with 713 additions and 180 deletions
+23
View File
@@ -51,6 +51,9 @@ func TestCreateTLSCertificateAndRenderHTTPSConfig(t *testing.T) {
if err != nil {
t.Fatalf("PublishConfigVersion failed: %v", err)
}
if !strings.Contains(result.Version.MainConfig, "include __ATSF_ROUTE_CONFIG__;") {
t.Fatal("expected main config to include managed route config placeholder")
}
if !strings.Contains(result.Version.RenderedConfig, "listen 443 ssl;") {
t.Fatal("expected rendered config to include https server block")
}
@@ -178,6 +181,9 @@ func TestPreviewAndDiffConfigVersion(t *testing.T) {
if err != nil {
t.Fatalf("PreviewConfigVersion failed: %v", err)
}
if !strings.Contains(preview.MainConfig, "include __ATSF_ROUTE_CONFIG__;") {
t.Fatal("expected preview main config to include managed route config placeholder")
}
if !strings.Contains(preview.RenderedConfig, `proxy_set_header X-Release "candidate";`) {
t.Fatal("expected preview config to include modified custom header")
}
@@ -198,6 +204,23 @@ func TestPreviewAndDiffConfigVersion(t *testing.T) {
if len(diff.ModifiedDomains) != 1 || diff.ModifiedDomains[0] != "api.example.com" {
t.Fatalf("unexpected modified domains: %#v", diff.ModifiedDomains)
}
if diff.MainConfigChanged {
t.Fatal("expected main config to remain unchanged when only routes change")
}
if err = model.UpdateOption("OpenRestyProxyReadTimeout", "120"); err != nil {
t.Fatalf("UpdateOption failed: %v", err)
}
diff, err = DiffConfigVersion()
if err != nil {
t.Fatalf("DiffConfigVersion after option change failed: %v", err)
}
if !diff.MainConfigChanged {
t.Fatal("expected main config change after OpenResty option update")
}
if len(diff.ChangedOptionKeys) == 0 || diff.ChangedOptionKeys[0] == "" {
t.Fatal("expected changed OpenResty option keys to be reported")
}
}
func TestCreateTLSCertificateRejectsInvalidPEM(t *testing.T) {